source: trunk/test/option.cc @ 1525

Last change on this file since 1525 was 1525, checked in by Peter Johansson, 9 years ago

replace recursive Makefile with one single Makefile. Keeping multiple Makefile.ams which are included into main Makefile.am.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.8 KB
Line 
1// $Id: option.cc 1525 2012-10-01 06:31:07Z 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
24#include "bin/svndigestParameter.h"
25#include "lib/utility.h"
26
27#include "yat/Exception.h"
28
29#include <cassert>
30#include <cerrno>
31#include <cstring>
32#include <string>
33#include <vector>
34
35using namespace theplu::svndigest;
36
37void test_root(test::Suite& suite);
38void test_root(test::Suite& suite, const std::string& arg, 
39               const std::string& root, const std::string& root_basename);
40void parse(Parameter&, const std::vector<std::string>& argv);
41
42int main(int argc, char* argv[])
43{
44  test::Suite suite(argc, argv);
45  test_root(suite);
46  if (suite.ok())
47    return 0;
48  return 1;
49}
50
51
52void test_root(test::Suite& suite)
53{
54  suite.out() << "test --root ROOT\n";
55  test_root(suite, ".", "*/test/testSubDir/option.test", "option.test");
56  test_root(suite, "..", "*/test/testSubDir","testSubDir");
57  test_root(suite, "../..", "*/test", "test");
58  // test with absolute path
59  test_root(suite, test::abs_builddir(), "*/test", "test");
60  // test with symbolic link
61  if (!node_exist("symlink")) {
62    if (symlink(".", "symlink")) {
63      suite.add(false);
64      suite.out() << "creating symlink failed: " << strerror(errno) << "\n";
65    }
66  }
67  test_root(suite, "symlink", "*/test/testSubDir/option.test", "symlink");
68  test_root(suite, "symlink/.", "*/test/testSubDir/option.test","option.test");
69  test_root(suite, "symlink/..", "*/test/testSubDir", "testSubDir");
70  test_root(suite, test::abs_builddir()+"/testSubDir/option.test/symlink/..", 
71            "*/test/testSubDir", "testSubDir");
72  test_root(suite, test::abs_builddir()+"/testSubDir/option.test/symlink", 
73            "*/test/testSubDir/option.test", "symlink");
74 
75  try {
76    test_root(suite, "../../Makefile", "*/Makefile", "Makefile");
77    suite.add(false);
78    suite.out() << "error: no exception thrown\n --root ../../Makefile\n";
79  }
80  catch (theplu::yat::utility::cmd_error& e) {
81    suite.out() << "caught expected errno_error: what(): " << e.what();
82  }
83}
84
85void test_root(test::Suite& suite, const std::string& arg, 
86               const std::string& root, const std::string& root_basename)
87{
88  svndigestParameter option;
89  std::vector<std::string> argv;
90  argv.push_back("svndigest");
91  argv.push_back("--no-report");
92  argv.push_back("--root");
93  argv.push_back(arg);
94  parse(option, argv);
95
96  if (!theplu::svndigest::fnmatch(root, option.root())) {
97    suite.add(false);
98    suite.out() << "error:\n";
99    for (size_t i=0; i<argv.size(); ++i)
100      suite.out() << argv[i] << " ";
101    suite.out() << "\n";
102    suite.out() << "root: `" << option.root() << "'\n";
103    suite.out() << "expected pattern: `" << root << "'\n\n";
104  }
105  if (option.root_basename() != root_basename) {
106    suite.add(false);
107    suite.out() << "error\n";
108    for (size_t i=0; i<argv.size(); ++i)
109      suite.out() << argv[i] << " ";
110    suite.out() << "\n";
111    suite.out() << "root: `" << option.root_basename() << "'\n";
112    suite.out() << "expected: `" << root_basename << "'\n\n";
113  }
114}
115
116
117void parse(Parameter& option, const std::vector<std::string>& vec)
118{
119  int argc = vec.size();
120  char** argv = new char*[vec.size()];
121  for (int i = 0; i<argc; ++i) {
122    argv[i] = strdup(vec[i].c_str());
123    assert(argv[i]);
124  }
125  option.parse(argc, argv);
126  for (int i = 0; i<argc; ++i) {
127    free(argv[i]);
128  }
129}
Note: See TracBrowser for help on using the repository browser.