556 |
16 Jan 08 |
peter |
// $Id$ |
556 |
16 Jan 08 |
peter |
2 |
|
556 |
16 Jan 08 |
peter |
3 |
/* |
978 |
12 Dec 09 |
peter |
Copyright (C) 2008 Jari Häkkinen, Peter Johansson |
1635 |
30 Mar 23 |
peter |
Copyright (C) 2009, 2010, 2023 Peter Johansson |
556 |
16 Jan 08 |
peter |
6 |
|
687 |
04 Aug 08 |
peter |
This file is part of svndigest, http://dev.thep.lu.se/svndigest |
556 |
16 Jan 08 |
peter |
8 |
|
556 |
16 Jan 08 |
peter |
svndigest is free software; you can redistribute it and/or modify it |
556 |
16 Jan 08 |
peter |
under the terms of the GNU General Public License as published by |
693 |
11 Sep 08 |
jari |
the Free Software Foundation; either version 3 of the License, or |
556 |
16 Jan 08 |
peter |
(at your option) any later version. |
556 |
16 Jan 08 |
peter |
13 |
|
556 |
16 Jan 08 |
peter |
svndigest is distributed in the hope that it will be useful, but |
556 |
16 Jan 08 |
peter |
WITHOUT ANY WARRANTY; without even the implied warranty of |
556 |
16 Jan 08 |
peter |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
556 |
16 Jan 08 |
peter |
General Public License for more details. |
556 |
16 Jan 08 |
peter |
18 |
|
556 |
16 Jan 08 |
peter |
You should have received a copy of the GNU General Public License |
693 |
11 Sep 08 |
jari |
along with svndigest. If not, see <http://www.gnu.org/licenses/>. |
556 |
16 Jan 08 |
peter |
21 |
*/ |
556 |
16 Jan 08 |
peter |
22 |
|
1619 |
12 Mar 23 |
peter |
23 |
#include <config.h> |
1619 |
12 Mar 23 |
peter |
24 |
|
596 |
14 Apr 08 |
peter |
25 |
#include "Suite.h" |
596 |
14 Apr 08 |
peter |
26 |
|
1119 |
04 Jul 10 |
peter |
27 |
#include "lib/AddStats.h" |
1119 |
04 Jul 10 |
peter |
28 |
#include "lib/BlameStats.h" |
1119 |
04 Jul 10 |
peter |
29 |
#include "lib/ClassicStats.h" |
1119 |
04 Jul 10 |
peter |
30 |
#include "lib/Configuration.h" |
1119 |
04 Jul 10 |
peter |
31 |
#include "lib/Stats.h" |
1119 |
04 Jul 10 |
peter |
32 |
#include "lib/SVN.h" |
556 |
16 Jan 08 |
peter |
33 |
|
556 |
16 Jan 08 |
peter |
34 |
#include <algorithm> |
556 |
16 Jan 08 |
peter |
35 |
#include <cassert> |
603 |
16 Apr 08 |
peter |
36 |
#include <cstddef> |
556 |
16 Jan 08 |
peter |
37 |
#include <iterator> |
556 |
16 Jan 08 |
peter |
38 |
#include <iostream> |
556 |
16 Jan 08 |
peter |
39 |
#include <numeric> |
556 |
16 Jan 08 |
peter |
40 |
#include <string> |
649 |
08 Jun 08 |
peter |
41 |
#include <sstream> |
603 |
16 Apr 08 |
peter |
42 |
#include <vector> |
556 |
16 Jan 08 |
peter |
43 |
|
981 |
12 Dec 09 |
peter |
44 |
using namespace theplu::svndigest; |
981 |
12 Dec 09 |
peter |
45 |
|
556 |
16 Jan 08 |
peter |
46 |
namespace theplu{ |
556 |
16 Jan 08 |
peter |
47 |
namespace svndigest{ |
556 |
16 Jan 08 |
peter |
48 |
|
718 |
30 Nov 08 |
peter |
49 |
bool check(const Stats& stats, const std::vector<int>& correct, |
603 |
16 Apr 08 |
peter |
50 |
int linetype, const std::string& descr, const std::string& author); |
604 |
16 Apr 08 |
peter |
51 |
std::string path(void); |
981 |
12 Dec 09 |
peter |
52 |
bool test_add(test::Suite&); |
981 |
12 Dec 09 |
peter |
53 |
bool test_blame(test::Suite&); |
981 |
12 Dec 09 |
peter |
54 |
bool test_classic(test::Suite&); |
604 |
16 Apr 08 |
peter |
55 |
bool test_base_class(const Stats&); |
649 |
08 Jun 08 |
peter |
56 |
bool test_cache(const Stats&); |
556 |
16 Jan 08 |
peter |
57 |
|
556 |
16 Jan 08 |
peter |
58 |
}} // end of namespace svndigest and theplu |
556 |
16 Jan 08 |
peter |
59 |
|
556 |
16 Jan 08 |
peter |
60 |
|
556 |
16 Jan 08 |
peter |
61 |
int main( int argc, char* argv[]) |
556 |
16 Jan 08 |
peter |
62 |
{ |
744 |
08 Jan 09 |
peter |
63 |
test::Suite suite(argc, argv, true); |
744 |
08 Jan 09 |
peter |
64 |
|
1092 |
12 Jun 10 |
peter |
65 |
SVN* svn=SVN::instance("toy_project"); |
556 |
16 Jan 08 |
peter |
66 |
if (!svn){ |
556 |
16 Jan 08 |
peter |
67 |
std::cerr << "error: cannot create SVN instance\n"; |
556 |
16 Jan 08 |
peter |
68 |
return 1; |
556 |
16 Jan 08 |
peter |
69 |
} |
556 |
16 Jan 08 |
peter |
70 |
|
1162 |
13 Aug 10 |
peter |
71 |
suite.add(test_add(suite)); |
1162 |
13 Aug 10 |
peter |
72 |
suite.add(test_blame(suite)); |
1162 |
13 Aug 10 |
peter |
73 |
suite.add(test_classic(suite)); |
556 |
16 Jan 08 |
peter |
74 |
|
1162 |
13 Aug 10 |
peter |
75 |
return suite.exit_status(); |
556 |
16 Jan 08 |
peter |
76 |
} |
556 |
16 Jan 08 |
peter |
77 |
|
556 |
16 Jan 08 |
peter |
78 |
|
556 |
16 Jan 08 |
peter |
79 |
namespace theplu{ |
556 |
16 Jan 08 |
peter |
80 |
namespace svndigest{ |
556 |
16 Jan 08 |
peter |
81 |
|
604 |
16 Apr 08 |
peter |
82 |
std::string path(void) |
604 |
16 Apr 08 |
peter |
83 |
{ |
1092 |
12 Jun 10 |
peter |
84 |
return "toy_project/bin/svnstat.cc"; |
604 |
16 Apr 08 |
peter |
85 |
} |
604 |
16 Apr 08 |
peter |
86 |
|
981 |
12 Dec 09 |
peter |
87 |
bool test_add(test::Suite& suite) |
556 |
16 Jan 08 |
peter |
88 |
{ |
981 |
12 Dec 09 |
peter |
89 |
suite.out() << "testing add\n"; |
604 |
16 Apr 08 |
peter |
90 |
bool ok =true; |
604 |
16 Apr 08 |
peter |
91 |
AddStats cs(path()); |
604 |
16 Apr 08 |
peter |
92 |
cs.parse(path()); |
604 |
16 Apr 08 |
peter |
93 |
ok &= test_base_class(cs); |
717 |
30 Nov 08 |
peter |
94 |
|
718 |
30 Nov 08 |
peter |
95 |
std::vector<int> correct(62,0); |
717 |
30 Nov 08 |
peter |
96 |
correct[15] = 71; |
717 |
30 Nov 08 |
peter |
97 |
correct[16] = 3; |
717 |
30 Nov 08 |
peter |
98 |
correct[17] = 7; |
717 |
30 Nov 08 |
peter |
99 |
correct[28] = 35; |
717 |
30 Nov 08 |
peter |
100 |
correct[30] = 63; |
717 |
30 Nov 08 |
peter |
101 |
ok &= check(cs, correct, LineTypeParser::total, "total", "jari"); |
717 |
30 Nov 08 |
peter |
102 |
correct[42] = 1; |
717 |
30 Nov 08 |
peter |
103 |
correct[43] = 1; |
717 |
30 Nov 08 |
peter |
104 |
correct[44] = 2; |
717 |
30 Nov 08 |
peter |
105 |
correct[47] = 2; |
717 |
30 Nov 08 |
peter |
106 |
ok &= check(cs, correct, LineTypeParser::total, "total", "all"); |
1611 |
12 Feb 23 |
peter |
107 |
|
717 |
30 Nov 08 |
peter |
108 |
std::fill(correct.begin(), correct.end(), 0); |
717 |
30 Nov 08 |
peter |
109 |
correct[15] = 49; |
717 |
30 Nov 08 |
peter |
110 |
correct[16] = 3; |
717 |
30 Nov 08 |
peter |
111 |
correct[17] = 7; |
717 |
30 Nov 08 |
peter |
112 |
correct[28] = 11; |
717 |
30 Nov 08 |
peter |
113 |
correct[30] = 54; |
717 |
30 Nov 08 |
peter |
114 |
ok &= check(cs, correct, LineTypeParser::code, "code", "jari"); |
717 |
30 Nov 08 |
peter |
115 |
std::fill(correct.begin(), correct.end(), 0); |
717 |
30 Nov 08 |
peter |
116 |
correct[15] = 5; |
1611 |
12 Feb 23 |
peter |
117 |
correct[28] = 14; |
717 |
30 Nov 08 |
peter |
118 |
correct[30] = 7; |
1611 |
12 Feb 23 |
peter |
119 |
ok &= check(cs, correct, LineTypeParser::comment_or_copy,"comment","jari"); |
717 |
30 Nov 08 |
peter |
120 |
std::fill(correct.begin(), correct.end(), 0); |
717 |
30 Nov 08 |
peter |
121 |
correct[15] = 17; |
717 |
30 Nov 08 |
peter |
122 |
correct[28] = 10; |
717 |
30 Nov 08 |
peter |
123 |
correct[30] = 2; |
717 |
30 Nov 08 |
peter |
124 |
ok &= check(cs, correct, LineTypeParser::other, "other", "jari"); |
717 |
30 Nov 08 |
peter |
125 |
|
604 |
16 Apr 08 |
peter |
126 |
return ok; |
556 |
16 Jan 08 |
peter |
127 |
} |
1611 |
12 Feb 23 |
peter |
128 |
|
1611 |
12 Feb 23 |
peter |
129 |
|
981 |
12 Dec 09 |
peter |
130 |
bool test_blame(test::Suite& suite) |
556 |
16 Jan 08 |
peter |
131 |
{ |
981 |
12 Dec 09 |
peter |
132 |
suite.out() << "testing blame\n"; |
604 |
16 Apr 08 |
peter |
133 |
bool ok =true; |
604 |
16 Apr 08 |
peter |
134 |
BlameStats cs(path()); |
604 |
16 Apr 08 |
peter |
135 |
cs.parse(path()); |
604 |
16 Apr 08 |
peter |
136 |
ok &= test_base_class(cs); |
717 |
30 Nov 08 |
peter |
137 |
|
718 |
30 Nov 08 |
peter |
138 |
std::vector<int> correct(62,0); |
718 |
30 Nov 08 |
peter |
139 |
correct[15] = 71; |
718 |
30 Nov 08 |
peter |
140 |
correct[16] = -1; |
718 |
30 Nov 08 |
peter |
141 |
correct[17] = 2; |
718 |
30 Nov 08 |
peter |
142 |
correct[28] = 31; |
718 |
30 Nov 08 |
peter |
143 |
correct[30] = 25; |
718 |
30 Nov 08 |
peter |
144 |
correct[42] = -1; |
718 |
30 Nov 08 |
peter |
145 |
ok &= check(cs, correct, LineTypeParser::total, "total", "jari"); |
718 |
30 Nov 08 |
peter |
146 |
correct[42] = 0; |
718 |
30 Nov 08 |
peter |
147 |
correct[43] = 1; |
718 |
30 Nov 08 |
peter |
148 |
ok &= check(cs, correct, LineTypeParser::total, "total", "all"); |
1611 |
12 Feb 23 |
peter |
149 |
|
718 |
30 Nov 08 |
peter |
150 |
std::fill(correct.begin(), correct.end(), 0); |
718 |
30 Nov 08 |
peter |
151 |
correct[15] = 49; |
718 |
30 Nov 08 |
peter |
152 |
correct[17] = 2; |
718 |
30 Nov 08 |
peter |
153 |
correct[28] = 8; |
718 |
30 Nov 08 |
peter |
154 |
correct[30] = 54-29; |
718 |
30 Nov 08 |
peter |
155 |
ok &= check(cs, correct, LineTypeParser::code, "code", "jari"); |
718 |
30 Nov 08 |
peter |
156 |
std::fill(correct.begin(), correct.end(), 0); |
718 |
30 Nov 08 |
peter |
157 |
correct[15] = 5; |
718 |
30 Nov 08 |
peter |
158 |
correct[16] = -1; |
1611 |
12 Feb 23 |
peter |
159 |
correct[28] = 14; |
718 |
30 Nov 08 |
peter |
160 |
correct[30] = 7-3; |
1611 |
12 Feb 23 |
peter |
161 |
correct[42] = -1; |
1611 |
12 Feb 23 |
peter |
162 |
ok &= check(cs, correct, LineTypeParser::comment_or_copy,"comment","jari"); |
718 |
30 Nov 08 |
peter |
163 |
std::fill(correct.begin(), correct.end(), 0); |
718 |
30 Nov 08 |
peter |
164 |
correct[15] = 17; |
718 |
30 Nov 08 |
peter |
165 |
correct[28] = 10-1; |
718 |
30 Nov 08 |
peter |
166 |
correct[30] = 2-6; |
718 |
30 Nov 08 |
peter |
167 |
ok &= check(cs, correct, LineTypeParser::other, "other", "jari"); |
718 |
30 Nov 08 |
peter |
168 |
|
604 |
16 Apr 08 |
peter |
169 |
return ok; |
556 |
16 Jan 08 |
peter |
170 |
} |
556 |
16 Jan 08 |
peter |
171 |
|
1611 |
12 Feb 23 |
peter |
172 |
|
649 |
08 Jun 08 |
peter |
173 |
bool test_cache(const Stats& stats) |
649 |
08 Jun 08 |
peter |
174 |
{ |
649 |
08 Jun 08 |
peter |
175 |
std::stringstream out; |
649 |
08 Jun 08 |
peter |
176 |
stats.print(out); |
649 |
08 Jun 08 |
peter |
177 |
std::stringstream in(out.str()); |
649 |
08 Jun 08 |
peter |
178 |
ClassicStats stats2(path()); |
649 |
08 Jun 08 |
peter |
179 |
assert(in.good()); |
1124 |
07 Jul 10 |
peter |
180 |
bool new_cache=true; |
1124 |
07 Jul 10 |
peter |
181 |
if (!stats2.load_cache(in, new_cache)){ |
649 |
08 Jun 08 |
peter |
182 |
std::cout << "load_cache() failed\n"; |
649 |
08 Jun 08 |
peter |
183 |
return false; |
649 |
08 Jun 08 |
peter |
184 |
} |
649 |
08 Jun 08 |
peter |
185 |
|
649 |
08 Jun 08 |
peter |
186 |
std::stringstream out2; |
649 |
08 Jun 08 |
peter |
187 |
stats2.print(out2); |
1611 |
12 Feb 23 |
peter |
188 |
|
1208 |
07 Oct 10 |
peter |
189 |
if ( test::diff(out.str(),out2.str()) ) { |
649 |
08 Jun 08 |
peter |
190 |
std::cout << "test_cache() failed\n"; |
649 |
08 Jun 08 |
peter |
191 |
return false; |
649 |
08 Jun 08 |
peter |
192 |
} |
649 |
08 Jun 08 |
peter |
193 |
return true; |
649 |
08 Jun 08 |
peter |
194 |
} |
649 |
08 Jun 08 |
peter |
195 |
|
649 |
08 Jun 08 |
peter |
196 |
|
981 |
12 Dec 09 |
peter |
197 |
bool test_classic(test::Suite& suite) |
556 |
16 Jan 08 |
peter |
198 |
{ |
981 |
12 Dec 09 |
peter |
199 |
suite.out() << "testing classic\n"; |
556 |
16 Jan 08 |
peter |
200 |
bool ok =true; |
604 |
16 Apr 08 |
peter |
201 |
ClassicStats cs(path()); |
604 |
16 Apr 08 |
peter |
202 |
cs.parse(path()); |
634 |
09 May 08 |
peter |
203 |
ok &= test_base_class(cs); |
556 |
16 Jan 08 |
peter |
204 |
|
1611 |
12 Feb 23 |
peter |
// testing code lines for jari |
718 |
30 Nov 08 |
peter |
206 |
std::vector<int> correct(48,0); |
556 |
16 Jan 08 |
peter |
207 |
correct[15]=20; |
556 |
16 Jan 08 |
peter |
208 |
correct[16]=1; |
556 |
16 Jan 08 |
peter |
209 |
correct[17]=1; |
556 |
16 Jan 08 |
peter |
210 |
correct[28]=8; |
556 |
16 Jan 08 |
peter |
211 |
correct[30]=54; |
603 |
16 Apr 08 |
peter |
212 |
ok &= check(cs, correct, LineTypeParser::code, "code", "jari"); |
556 |
16 Jan 08 |
peter |
213 |
|
556 |
16 Jan 08 |
peter |
// testing comment lines for jari |
603 |
16 Apr 08 |
peter |
215 |
correct.resize(0); |
603 |
16 Apr 08 |
peter |
216 |
correct.resize(48,0); |
556 |
16 Jan 08 |
peter |
217 |
correct[15]=1; |
556 |
16 Jan 08 |
peter |
218 |
correct[28]=13; |
556 |
16 Jan 08 |
peter |
219 |
correct[30]=7; |
1611 |
12 Feb 23 |
peter |
220 |
ok &= check(cs, correct, LineTypeParser::comment_or_copy,"comment","jari"); |
556 |
16 Jan 08 |
peter |
221 |
|
556 |
16 Jan 08 |
peter |
// testing blank lines for jari |
603 |
16 Apr 08 |
peter |
223 |
correct.resize(0); |
603 |
16 Apr 08 |
peter |
224 |
correct.resize(48,0); |
556 |
16 Jan 08 |
peter |
225 |
correct[15]=10; |
556 |
16 Jan 08 |
peter |
226 |
correct[28]=10; |
556 |
16 Jan 08 |
peter |
227 |
correct[30]=2; |
603 |
16 Apr 08 |
peter |
228 |
ok &= check(cs, correct, LineTypeParser::other, "other", "jari"); |
556 |
16 Jan 08 |
peter |
229 |
|
556 |
16 Jan 08 |
peter |
// testing code all lines for total |
603 |
16 Apr 08 |
peter |
231 |
correct.resize(0); |
603 |
16 Apr 08 |
peter |
232 |
correct.resize(48,0); |
556 |
16 Jan 08 |
peter |
233 |
correct[15]=31; |
556 |
16 Jan 08 |
peter |
234 |
correct[16]=1; |
556 |
16 Jan 08 |
peter |
235 |
correct[17]=1; |
556 |
16 Jan 08 |
peter |
236 |
correct[28]=31; |
556 |
16 Jan 08 |
peter |
237 |
correct[30]=63; |
981 |
12 Dec 09 |
peter |
238 |
correct[47]=1; |
603 |
16 Apr 08 |
peter |
239 |
ok &= check(cs, correct, LineTypeParser::total, "total", "all"); |
556 |
16 Jan 08 |
peter |
240 |
|
603 |
16 Apr 08 |
peter |
241 |
return ok; |
603 |
16 Apr 08 |
peter |
242 |
} |
603 |
16 Apr 08 |
peter |
243 |
|
718 |
30 Nov 08 |
peter |
244 |
bool check(const Stats& stats, const std::vector<int>& correct, |
603 |
16 Apr 08 |
peter |
245 |
int linetype, const std::string& descr, const std::string& author) |
603 |
16 Apr 08 |
peter |
246 |
{ |
603 |
16 Apr 08 |
peter |
247 |
bool ok=true; |
603 |
16 Apr 08 |
peter |
248 |
std::vector<size_t> sum(correct.size()); |
603 |
16 Apr 08 |
peter |
249 |
std::partial_sum(correct.begin(), correct.end(), sum.begin()); |
603 |
16 Apr 08 |
peter |
250 |
for (size_t rev=0; rev<sum.size(); ++rev){ |
603 |
16 Apr 08 |
peter |
251 |
size_t n = stats(linetype, author, rev); |
603 |
16 Apr 08 |
peter |
252 |
if (n != sum[rev]){ |
718 |
30 Nov 08 |
peter |
253 |
std::cout << "error: " << descr << " " << author << " rev:" << rev |
603 |
16 Apr 08 |
peter |
254 |
<< ": found " << n << " expected " << sum[rev] << "\n"; |
556 |
16 Jan 08 |
peter |
255 |
ok = false; |
556 |
16 Jan 08 |
peter |
256 |
} |
603 |
16 Apr 08 |
peter |
257 |
} |
717 |
30 Nov 08 |
peter |
258 |
return ok; |
603 |
16 Apr 08 |
peter |
259 |
} |
556 |
16 Jan 08 |
peter |
260 |
|
604 |
16 Apr 08 |
peter |
261 |
bool test_base_class(const Stats& s) |
604 |
16 Apr 08 |
peter |
262 |
{ |
649 |
08 Jun 08 |
peter |
263 |
if (!test_cache(s)) |
649 |
08 Jun 08 |
peter |
264 |
return false; |
604 |
16 Apr 08 |
peter |
265 |
if (s.code()+s.comments()+s.empty()!=s.lines()){ |
604 |
16 Apr 08 |
peter |
266 |
std::cerr << "Code plus comments plus empty do not add up to lines\n"; |
604 |
16 Apr 08 |
peter |
267 |
std::cerr << "code: " << s.code() << "\n"; |
604 |
16 Apr 08 |
peter |
268 |
std::cerr << "comment: " << s.comments() << "\n"; |
604 |
16 Apr 08 |
peter |
269 |
std::cerr << "empty: " << s.empty() << "\n"; |
604 |
16 Apr 08 |
peter |
270 |
std::cerr << "lines: " << s.lines() << "\n"; |
604 |
16 Apr 08 |
peter |
271 |
return false; |
604 |
16 Apr 08 |
peter |
272 |
} |
604 |
16 Apr 08 |
peter |
273 |
return true; |
604 |
16 Apr 08 |
peter |
274 |
} |
604 |
16 Apr 08 |
peter |
275 |
|
556 |
16 Jan 08 |
peter |
276 |
}} // end of namespace svndigest and theplu |