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