1478 |
29 May 12 |
peter |
// $Id$ |
1478 |
29 May 12 |
peter |
2 |
|
1478 |
29 May 12 |
peter |
3 |
/* |
1635 |
30 Mar 23 |
peter |
Copyright (C) 2012, 2023 Peter Johansson |
1478 |
29 May 12 |
peter |
5 |
|
1478 |
29 May 12 |
peter |
This file is part of svndigest, http://dev.thep.lu.se/svndigest |
1478 |
29 May 12 |
peter |
7 |
|
1478 |
29 May 12 |
peter |
svndigest is free software; you can redistribute it and/or modify it |
1478 |
29 May 12 |
peter |
under the terms of the GNU General Public License as published by |
1478 |
29 May 12 |
peter |
the Free Software Foundation; either version 3 of the License, or |
1478 |
29 May 12 |
peter |
(at your option) any later version. |
1478 |
29 May 12 |
peter |
12 |
|
1478 |
29 May 12 |
peter |
svndigest is distributed in the hope that it will be useful, but |
1478 |
29 May 12 |
peter |
WITHOUT ANY WARRANTY; without even the implied warranty of |
1478 |
29 May 12 |
peter |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
1478 |
29 May 12 |
peter |
General Public License for more details. |
1478 |
29 May 12 |
peter |
17 |
|
1478 |
29 May 12 |
peter |
You should have received a copy of the GNU General Public License |
1478 |
29 May 12 |
peter |
along with svndigest. If not, see <http://www.gnu.org/licenses/>. |
1478 |
29 May 12 |
peter |
20 |
*/ |
1478 |
29 May 12 |
peter |
21 |
|
1478 |
29 May 12 |
peter |
// Testing that partial ignore works |
1478 |
29 May 12 |
peter |
23 |
|
1619 |
12 Mar 23 |
peter |
24 |
#include <config.h> |
1619 |
12 Mar 23 |
peter |
25 |
|
1478 |
29 May 12 |
peter |
26 |
#include "Suite.h" |
1478 |
29 May 12 |
peter |
27 |
|
1478 |
29 May 12 |
peter |
28 |
#include "lib/Configuration.h" |
1478 |
29 May 12 |
peter |
29 |
#include "lib/File.h" |
1478 |
29 May 12 |
peter |
30 |
#include "lib/SVN.h" |
1478 |
29 May 12 |
peter |
31 |
#include "lib/Stats.h" |
1478 |
29 May 12 |
peter |
32 |
#include "lib/StatsCollection.h" |
1478 |
29 May 12 |
peter |
33 |
#include "lib/utility.h" |
1478 |
29 May 12 |
peter |
34 |
|
1478 |
29 May 12 |
peter |
35 |
#include <fstream> |
1478 |
29 May 12 |
peter |
36 |
#include <iostream> |
1478 |
29 May 12 |
peter |
37 |
#include <sstream> |
1478 |
29 May 12 |
peter |
38 |
#include <vector> |
1478 |
29 May 12 |
peter |
39 |
|
1478 |
29 May 12 |
peter |
40 |
using namespace theplu::svndigest; |
1478 |
29 May 12 |
peter |
41 |
|
1478 |
29 May 12 |
peter |
42 |
void compare(const Stats& stats, const std::vector<int>& jari, |
1478 |
29 May 12 |
peter |
43 |
const std::vector<int>& peter, test::Suite& suite); |
1478 |
29 May 12 |
peter |
44 |
|
1478 |
29 May 12 |
peter |
45 |
void test_ignore(svn_revnum_t ignore_rev, const std::string& filename, |
1478 |
29 May 12 |
peter |
46 |
test::Suite& suite); |
1478 |
29 May 12 |
peter |
47 |
|
1478 |
29 May 12 |
peter |
48 |
int main( int argc, char* argv[]) |
1478 |
29 May 12 |
peter |
49 |
{ |
1478 |
29 May 12 |
peter |
50 |
test::Suite suite(argc, argv, true); |
1478 |
29 May 12 |
peter |
51 |
|
1478 |
29 May 12 |
peter |
52 |
std::string root="toy_project"; |
1478 |
29 May 12 |
peter |
53 |
std::string filename = root + "/AUTHORS"; |
1478 |
29 May 12 |
peter |
54 |
suite.out() << "Create SVN instance" << std::endl; |
1478 |
29 May 12 |
peter |
55 |
SVN* svn=SVN::instance(root); |
1478 |
29 May 12 |
peter |
56 |
if (!svn) |
1478 |
29 May 12 |
peter |
57 |
return 1; |
1478 |
29 May 12 |
peter |
58 |
|
1478 |
29 May 12 |
peter |
59 |
test_ignore(0, filename, suite); |
1478 |
29 May 12 |
peter |
60 |
test_ignore(2, filename, suite); |
1478 |
29 May 12 |
peter |
61 |
test_ignore(48, filename, suite); |
1478 |
29 May 12 |
peter |
62 |
test_ignore(62, filename, suite); |
1478 |
29 May 12 |
peter |
63 |
test_ignore(67, filename, suite); |
1478 |
29 May 12 |
peter |
64 |
return suite.exit_status(); |
1478 |
29 May 12 |
peter |
65 |
} |
1478 |
29 May 12 |
peter |
66 |
|
1478 |
29 May 12 |
peter |
67 |
|
1478 |
29 May 12 |
peter |
68 |
|
1478 |
29 May 12 |
peter |
69 |
void test_ignore(svn_revnum_t ignore_rev, const std::string& filename, |
1478 |
29 May 12 |
peter |
70 |
test::Suite& suite) |
1478 |
29 May 12 |
peter |
71 |
{ |
1478 |
29 May 12 |
peter |
72 |
suite.out() << "svndigest:ignore = " << ignore_rev << "\n"; |
1478 |
29 May 12 |
peter |
// create a config and load it |
1478 |
29 May 12 |
peter |
74 |
std::stringstream ss; |
1478 |
29 May 12 |
peter |
75 |
ss << "[svn-props]\n" << filename << " = " |
1478 |
29 May 12 |
peter |
76 |
<< "svndigest:ignore=" << ignore_rev << "\n"; |
1478 |
29 May 12 |
peter |
77 |
Configuration::instance().load(ss); |
1478 |
29 May 12 |
peter |
78 |
|
1478 |
29 May 12 |
peter |
79 |
File file(0,filename,""); |
1478 |
29 May 12 |
peter |
80 |
const StatsCollection& stats = file.parse(suite.verbose(), false, ignore_rev); |
1478 |
29 May 12 |
peter |
81 |
suite.add(test::consistent(stats, suite)); |
1478 |
29 May 12 |
peter |
82 |
|
1478 |
29 May 12 |
peter |
83 |
suite.out() << "classic:\n"; |
1478 |
29 May 12 |
peter |
84 |
const Stats& classic = stats["classic"]; |
1478 |
29 May 12 |
peter |
85 |
std::vector<int> add_jari(classic.revision()+1,0); |
1478 |
29 May 12 |
peter |
86 |
std::vector<int> add_peter(add_jari); |
1478 |
29 May 12 |
peter |
87 |
std::vector<int> blame_jari(add_jari); |
1478 |
29 May 12 |
peter |
88 |
std::vector<int> blame_peter(add_jari); |
1478 |
29 May 12 |
peter |
89 |
std::vector<int> rm_jari(add_jari); |
1478 |
29 May 12 |
peter |
90 |
std::vector<int> rm_peter(add_jari); |
1478 |
29 May 12 |
peter |
91 |
|
1478 |
29 May 12 |
peter |
92 |
blame_jari[2] = 4; |
1478 |
29 May 12 |
peter |
93 |
blame_peter[62] = 3; |
1478 |
29 May 12 |
peter |
94 |
blame_peter[67] = 1; |
1478 |
29 May 12 |
peter |
95 |
|
1478 |
29 May 12 |
peter |
96 |
add_jari[2] = 14; |
1478 |
29 May 12 |
peter |
97 |
if (ignore_rev<2) { |
1478 |
29 May 12 |
peter |
98 |
rm_jari[48] = 7; |
1478 |
29 May 12 |
peter |
99 |
rm_jari[62] = 2; |
1478 |
29 May 12 |
peter |
100 |
rm_jari[67] = 1; |
1478 |
29 May 12 |
peter |
101 |
} |
1478 |
29 May 12 |
peter |
102 |
add_peter[62] = 3; |
1478 |
29 May 12 |
peter |
103 |
add_peter[67] = 1; |
1478 |
29 May 12 |
peter |
104 |
|
1478 |
29 May 12 |
peter |
105 |
std::vector<int> jari_lines(add_jari.size(), 0); |
1478 |
29 May 12 |
peter |
106 |
std::vector<int> peter_lines(add_jari.size(), 0); |
1478 |
29 May 12 |
peter |
107 |
for (size_t r=ignore_rev+1; r<jari_lines.size(); ++r) { |
1478 |
29 May 12 |
peter |
108 |
jari_lines[r] = jari_lines[r-1] + blame_jari[r]; |
1478 |
29 May 12 |
peter |
109 |
peter_lines[r] = peter_lines[r-1] + blame_peter[r]; |
1478 |
29 May 12 |
peter |
110 |
} |
1478 |
29 May 12 |
peter |
111 |
compare(classic, jari_lines, peter_lines, suite); |
1478 |
29 May 12 |
peter |
112 |
|
1478 |
29 May 12 |
peter |
113 |
suite.out() << "blame:\n"; |
1478 |
29 May 12 |
peter |
114 |
const Stats& blame = stats["blame"]; |
1478 |
29 May 12 |
peter |
115 |
|
1478 |
29 May 12 |
peter |
116 |
for (size_t r=ignore_rev+1; r<jari_lines.size(); ++r) { |
1478 |
29 May 12 |
peter |
117 |
jari_lines[r] = jari_lines[r-1] + add_jari[r] - rm_jari[r]; |
1478 |
29 May 12 |
peter |
118 |
peter_lines[r] = peter_lines[r-1] + add_peter[r] - rm_peter[r]; |
1478 |
29 May 12 |
peter |
119 |
} |
1478 |
29 May 12 |
peter |
120 |
compare(blame, jari_lines, peter_lines, suite); |
1478 |
29 May 12 |
peter |
121 |
|
1478 |
29 May 12 |
peter |
122 |
suite.out() << "add:\n"; |
1478 |
29 May 12 |
peter |
123 |
const Stats& add = stats["add"]; |
1478 |
29 May 12 |
peter |
124 |
for (size_t r=ignore_rev+1; r<jari_lines.size(); ++r) { |
1478 |
29 May 12 |
peter |
125 |
jari_lines[r] = jari_lines[r-1] + add_jari[r]; |
1478 |
29 May 12 |
peter |
126 |
peter_lines[r] = peter_lines[r-1] + add_peter[r]; |
1478 |
29 May 12 |
peter |
127 |
} |
1478 |
29 May 12 |
peter |
128 |
compare(add, jari_lines, peter_lines, suite); |
1478 |
29 May 12 |
peter |
129 |
} |
1478 |
29 May 12 |
peter |
130 |
|
1478 |
29 May 12 |
peter |
131 |
|
1478 |
29 May 12 |
peter |
132 |
void compare(const Stats& stats, const std::vector<int>& expected, |
1478 |
29 May 12 |
peter |
133 |
const std::string& author, test::Suite& suite) |
1478 |
29 May 12 |
peter |
134 |
{ |
1478 |
29 May 12 |
peter |
135 |
bool all_zero=true; |
1478 |
29 May 12 |
peter |
136 |
for (size_t rev=0; rev<expected.size(); ++rev) |
1478 |
29 May 12 |
peter |
137 |
all_zero = all_zero && !expected[rev]; |
1478 |
29 May 12 |
peter |
138 |
if (all_zero) |
1478 |
29 May 12 |
peter |
139 |
return; |
1478 |
29 May 12 |
peter |
140 |
|
1478 |
29 May 12 |
peter |
141 |
for (size_t rev=0; rev<expected.size(); ++rev) { |
1478 |
29 May 12 |
peter |
142 |
int x = stats(LineTypeParser::total, author, rev); |
1478 |
29 May 12 |
peter |
143 |
if (x != expected[rev]) { |
1478 |
29 May 12 |
peter |
144 |
suite.add(false); |
1478 |
29 May 12 |
peter |
145 |
suite.out() << "error: " << author << " rev: " << rev << " " |
1478 |
29 May 12 |
peter |
146 |
<< x << " lines; expected: " << expected[rev] << "\n"; |
1478 |
29 May 12 |
peter |
147 |
} |
1478 |
29 May 12 |
peter |
148 |
} |
1478 |
29 May 12 |
peter |
149 |
} |
1478 |
29 May 12 |
peter |
150 |
|
1478 |
29 May 12 |
peter |
151 |
|
1478 |
29 May 12 |
peter |
152 |
void compare(const Stats& stats, const std::vector<int>& jari, |
1478 |
29 May 12 |
peter |
153 |
const std::vector<int>& peter, test::Suite& suite) |
1478 |
29 May 12 |
peter |
154 |
{ |
1478 |
29 May 12 |
peter |
155 |
compare(stats, jari, "jari", suite); |
1478 |
29 May 12 |
peter |
156 |
compare(stats, peter, "peter", suite); |
1478 |
29 May 12 |
peter |
157 |
} |