source: trunk/test/option.cc @ 1280

Last change on this file since 1280 was 1280, checked in by Peter Johansson, 13 years ago

merged release 0.9 in to trunk

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.8 KB
Line 
1// $Id: option.cc 1280 2010-11-06 14:45:23Z peter $
2
3/*
4  Copyright (C) 2010 Peter Johansson
5
6  This file is part of svndigest, http://dev.thep.lu.se/svndigest
7
8  svndigest is free software; you can redistribute it and/or modify it
9  under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 3 of the License, or
11  (at your option) any later version.
12
13  svndigest is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with svndigest. If not, see <http://www.gnu.org/licenses/>.
20*/
21
22#include "Suite.h"
23#include "environment.h"
24
25#include "bin/svndigestParameter.h"
26#include "lib/utility.h"
27
28#include "yat/Exception.h"
29
30#include <cassert>
31#include <cerrno>
32#include <cstring>
33#include <string>
34#include <vector>
35
36using namespace theplu::svndigest;
37
38void test_root(test::Suite& suite);
39void test_root(test::Suite& suite, const std::string& arg, 
40               const std::string& root, const std::string& root_basename);
41void parse(Parameter&, const std::vector<std::string>& argv);
42
43int main(int argc, char* argv[])
44{
45  test::Suite suite(argc, argv);
46  test_root(suite);
47  if (suite.ok())
48    return 0;
49  return 1;
50}
51
52
53void test_root(test::Suite& suite)
54{
55  suite.out() << "test --root ROOT\n";
56  test_root(suite, ".", "*/test/testSubDir/option.test", "option.test");
57  test_root(suite, "..", "*/test/testSubDir","testSubDir");
58  test_root(suite, "../..", "*/test", "test");
59  // test with absolute path
60  test_root(suite, test::abs_builddir(), "*/test", "test");
61  // test with symbolic link
62  if (!node_exist("symlink")) {
63    if (symlink(".", "symlink")) {
64      suite.add(false);
65      suite.out() << "creating symlink failed: " << strerror(errno) << "\n";
66    }
67  }
68  test_root(suite, "symlink", "*/test/testSubDir/option.test", "symlink");
69  test_root(suite, "symlink/.", "*/test/testSubDir/option.test","option.test");
70  test_root(suite, "symlink/..", "*/test/testSubDir", "testSubDir");
71  test_root(suite, test::abs_builddir()+"/testSubDir/option.test/symlink/..", 
72            "*/test/testSubDir", "testSubDir");
73  test_root(suite, test::abs_builddir()+"/testSubDir/option.test/symlink", 
74            "*/test/testSubDir/option.test", "symlink");
75 
76  try {
77    test_root(suite, "../../Makefile", "*/Makefile", "Makefile");
78    suite.add(false);
79    suite.out() << "error: no exception thrown\n --root ../../Makefile\n";
80  }
81  catch (theplu::yat::utility::cmd_error& e) {
82    suite.out() << "caught expected errno_error: what(): " << e.what();
83  }
84}
85
86void test_root(test::Suite& suite, const std::string& arg, 
87               const std::string& root, const std::string& root_basename)
88{
89  svndigestParameter option;
90  std::vector<std::string> argv;
91  argv.push_back("svndigest");
92  argv.push_back("--no-report");
93  argv.push_back("--root");
94  argv.push_back(arg);
95  parse(option, argv);
96
97  if (!theplu::svndigest::fnmatch(root, option.root())) {
98    suite.add(false);
99    suite.out() << "error:\n";
100    for (size_t i=0; i<argv.size(); ++i)
101      suite.out() << argv[i] << " ";
102    suite.out() << "\n";
103    suite.out() << "root: `" << option.root() << "'\n";
104    suite.out() << "expected pattern: `" << root << "'\n\n";
105  }
106  if (option.root_basename() != root_basename) {
107    suite.add(false);
108    suite.out() << "error\n";
109    for (size_t i=0; i<argv.size(); ++i)
110      suite.out() << argv[i] << " ";
111    suite.out() << "\n";
112    suite.out() << "root: `" << option.root_basename() << "'\n";
113    suite.out() << "expected: `" << root_basename << "'\n\n";
114  }
115}
116
117
118void parse(Parameter& option, const std::vector<std::string>& vec)
119{
120  int argc = vec.size();
121  char** argv = new char*[vec.size()];
122  for (int i = 0; i<argc; ++i) {
123    argv[i] = strdup(vec[i].c_str());
124    assert(argv[i]);
125  }
126  option.parse(argc, argv);
127  for (int i = 0; i<argc; ++i) {
128    free(argv[i]);
129  }
130}
Note: See TracBrowser for help on using the repository browser.