592 |
13 Apr 08 |
peter |
// $Id$ |
592 |
13 Apr 08 |
peter |
2 |
|
592 |
13 Apr 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, 2011, 2012, 2023 Peter Johansson |
592 |
13 Apr 08 |
peter |
6 |
|
687 |
04 Aug 08 |
peter |
This file is part of svndigest, http://dev.thep.lu.se/svndigest |
592 |
13 Apr 08 |
peter |
8 |
|
592 |
13 Apr 08 |
peter |
svndigest is free software; you can redistribute it and/or modify it |
592 |
13 Apr 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 |
592 |
13 Apr 08 |
peter |
(at your option) any later version. |
592 |
13 Apr 08 |
peter |
13 |
|
592 |
13 Apr 08 |
peter |
svndigest is distributed in the hope that it will be useful, but |
592 |
13 Apr 08 |
peter |
WITHOUT ANY WARRANTY; without even the implied warranty of |
592 |
13 Apr 08 |
peter |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
592 |
13 Apr 08 |
peter |
General Public License for more details. |
592 |
13 Apr 08 |
peter |
18 |
|
592 |
13 Apr 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/>. |
592 |
13 Apr 08 |
peter |
21 |
*/ |
592 |
13 Apr 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/Configuration.h" |
1119 |
04 Jul 10 |
peter |
28 |
#include "lib/File.h" |
1238 |
23 Oct 10 |
peter |
29 |
#include "lib/main_utility.h" |
1119 |
04 Jul 10 |
peter |
30 |
#include "lib/SVN.h" |
1119 |
04 Jul 10 |
peter |
31 |
#include "lib/SVNinfo.h" |
1321 |
28 Nov 10 |
peter |
32 |
#include "lib/utility.h" |
592 |
13 Apr 08 |
peter |
33 |
|
592 |
13 Apr 08 |
peter |
34 |
#include <cassert> |
592 |
13 Apr 08 |
peter |
35 |
#include <iostream> |
592 |
13 Apr 08 |
peter |
36 |
#include <fstream> |
597 |
14 Apr 08 |
peter |
37 |
#include <sstream> |
592 |
13 Apr 08 |
peter |
38 |
#include <string> |
594 |
14 Apr 08 |
peter |
39 |
#include <vector> |
592 |
13 Apr 08 |
peter |
40 |
|
594 |
14 Apr 08 |
peter |
41 |
std::vector<std::string> copyright_lines(std::istream&); |
594 |
14 Apr 08 |
peter |
42 |
|
592 |
13 Apr 08 |
peter |
43 |
int main( int argc, char* argv[]) |
592 |
13 Apr 08 |
peter |
44 |
{ |
592 |
13 Apr 08 |
peter |
45 |
using namespace theplu::svndigest; |
744 |
08 Jan 09 |
peter |
46 |
test::Suite suite(argc, argv, true); |
592 |
13 Apr 08 |
peter |
47 |
|
1092 |
12 Jun 10 |
peter |
48 |
std::string root="toy_project"; |
594 |
14 Apr 08 |
peter |
49 |
std::string filename = root + "/README"; |
594 |
14 Apr 08 |
peter |
50 |
|
594 |
14 Apr 08 |
peter |
// Saving original file |
594 |
14 Apr 08 |
peter |
52 |
std::ifstream is(filename.c_str()); |
594 |
14 Apr 08 |
peter |
53 |
assert(is.good()); |
594 |
14 Apr 08 |
peter |
54 |
std::string original_file; |
594 |
14 Apr 08 |
peter |
55 |
std::getline(is, original_file, '\0'); |
594 |
14 Apr 08 |
peter |
56 |
is.close(); |
594 |
14 Apr 08 |
peter |
57 |
is.clear(std::ios::goodbit); |
594 |
14 Apr 08 |
peter |
58 |
|
594 |
14 Apr 08 |
peter |
59 |
is.open(filename.c_str()); |
595 |
14 Apr 08 |
peter |
60 |
std::vector<std::string> copyrights_old=copyright_lines(is); |
594 |
14 Apr 08 |
peter |
61 |
is.close(); |
594 |
14 Apr 08 |
peter |
62 |
is.clear(std::ios::goodbit); |
594 |
14 Apr 08 |
peter |
63 |
|
595 |
14 Apr 08 |
peter |
64 |
if (copyrights_old.size()!=1) { |
744 |
08 Jan 09 |
peter |
65 |
suite.out() << copyrights_old.size() << " Copyright lines\n"; |
744 |
08 Jan 09 |
peter |
66 |
for (size_t i=0; i<copyrights_old.size(); ++i) |
744 |
08 Jan 09 |
peter |
67 |
suite.out() << copyrights_old[i] << "\n"; |
744 |
08 Jan 09 |
peter |
68 |
suite.add(false); |
594 |
14 Apr 08 |
peter |
69 |
} |
1551 |
03 Nov 12 |
peter |
70 |
suite.out() << "File contains 1 copyright line.\n"; |
594 |
14 Apr 08 |
peter |
71 |
|
1551 |
03 Nov 12 |
peter |
72 |
std::stringstream ss; |
1551 |
03 Nov 12 |
peter |
73 |
ss << "[copyright]\n" |
1551 |
03 Nov 12 |
peter |
74 |
<< "missing-copyright-warning=yes\n" |
1551 |
03 Nov 12 |
peter |
75 |
<< "[copyright-alias]\n" |
1551 |
03 Nov 12 |
peter |
76 |
<< "jari = jh\n" |
1551 |
03 Nov 12 |
peter |
77 |
<< "peter = pj\n"; |
1551 |
03 Nov 12 |
peter |
78 |
Configuration& config = Configuration::instance(); |
1551 |
03 Nov 12 |
peter |
79 |
config.load(ss); |
597 |
14 Apr 08 |
peter |
80 |
|
744 |
08 Jan 09 |
peter |
81 |
suite.out() << "Create SVN instance" << std::endl; |
592 |
13 Apr 08 |
peter |
82 |
SVN* svn=SVN::instance(root); |
592 |
13 Apr 08 |
peter |
83 |
if (!svn) |
592 |
13 Apr 08 |
peter |
84 |
return 1; |
592 |
13 Apr 08 |
peter |
85 |
|
592 |
13 Apr 08 |
peter |
// Extract repository location |
744 |
08 Jan 09 |
peter |
87 |
suite.out() << "Extract repository location" << std::endl; |
592 |
13 Apr 08 |
peter |
88 |
std::string repo=SVNinfo(root).repos_root_url(); |
744 |
08 Jan 09 |
peter |
89 |
suite.out() << "Create File object" << std::endl; |
594 |
14 Apr 08 |
peter |
90 |
File file(0,filename,""); |
592 |
13 Apr 08 |
peter |
91 |
|
1551 |
03 Nov 12 |
peter |
92 |
update_copyright(file, true, true); |
1551 |
03 Nov 12 |
peter |
93 |
|
595 |
14 Apr 08 |
peter |
94 |
is.open(filename.c_str()); |
595 |
14 Apr 08 |
peter |
95 |
std::vector<std::string> copyrights=copyright_lines(is); |
595 |
14 Apr 08 |
peter |
96 |
is.close(); |
595 |
14 Apr 08 |
peter |
97 |
is.clear(std::ios::goodbit); |
595 |
14 Apr 08 |
peter |
98 |
|
597 |
14 Apr 08 |
peter |
99 |
std::vector<std::string> copyright_correct; |
597 |
14 Apr 08 |
peter |
100 |
copyright_correct.push_back("Copyright (C) 2006 jh"); |
1551 |
03 Nov 12 |
peter |
101 |
copyright_correct.push_back("Copyright (C) 2008 pj"); |
597 |
14 Apr 08 |
peter |
102 |
if (copyrights.size()!=copyright_correct.size()) { |
744 |
08 Jan 09 |
peter |
103 |
suite.add(false); |
744 |
08 Jan 09 |
peter |
104 |
suite.out() << "ERROR: expected " << copyright_correct.size() |
638 |
31 May 08 |
peter |
105 |
<< " lines of Copyright (C)\n" |
638 |
31 May 08 |
peter |
106 |
<< "But found " << copyrights.size() << " lines.\n"; |
1356 |
17 May 11 |
peter |
107 |
for (size_t i=0; i<copyrights.size(); ++i) |
1356 |
17 May 11 |
peter |
108 |
suite.out() << copyrights[i] << "\n"; |
595 |
14 Apr 08 |
peter |
109 |
} |
597 |
14 Apr 08 |
peter |
110 |
else { |
595 |
14 Apr 08 |
peter |
111 |
for (size_t i=0; i<copyrights.size(); ++i) |
597 |
14 Apr 08 |
peter |
112 |
if (copyrights[i]!=copyright_correct[i]){ |
744 |
08 Jan 09 |
peter |
113 |
suite.add(false); |
744 |
08 Jan 09 |
peter |
114 |
suite.out() << "ERROR: found '" << copyrights[i] << "'\n" |
597 |
14 Apr 08 |
peter |
115 |
<< "expected: '" << copyright_correct[i] << "'\n"; |
597 |
14 Apr 08 |
peter |
116 |
} |
597 |
14 Apr 08 |
peter |
117 |
|
595 |
14 Apr 08 |
peter |
118 |
} |
595 |
14 Apr 08 |
peter |
119 |
|
597 |
14 Apr 08 |
peter |
120 |
|
594 |
14 Apr 08 |
peter |
// Restoring file |
594 |
14 Apr 08 |
peter |
122 |
std::ofstream os(filename.c_str()); |
594 |
14 Apr 08 |
peter |
123 |
assert(os.good()); |
594 |
14 Apr 08 |
peter |
124 |
os << original_file; |
599 |
15 Apr 08 |
peter |
125 |
os.close(); |
594 |
14 Apr 08 |
peter |
126 |
|
1162 |
13 Aug 10 |
peter |
127 |
return suite.exit_status(); |
592 |
13 Apr 08 |
peter |
128 |
} |
592 |
13 Apr 08 |
peter |
129 |
|
594 |
14 Apr 08 |
peter |
130 |
std::vector<std::string> copyright_lines(std::istream& is) |
594 |
14 Apr 08 |
peter |
131 |
{ |
594 |
14 Apr 08 |
peter |
132 |
using namespace theplu::svndigest; |
594 |
14 Apr 08 |
peter |
133 |
std::vector<std::string> res; |
594 |
14 Apr 08 |
peter |
134 |
std::string line; |
594 |
14 Apr 08 |
peter |
135 |
while (std::getline(is, line)){ |
594 |
14 Apr 08 |
peter |
136 |
if (match_begin(line.begin(), line.end(), "Copyright (C)")) |
594 |
14 Apr 08 |
peter |
137 |
res.push_back(line); |
594 |
14 Apr 08 |
peter |
138 |
} |
594 |
14 Apr 08 |
peter |
139 |
|
594 |
14 Apr 08 |
peter |
140 |
return res; |
594 |
14 Apr 08 |
peter |
141 |
} |
594 |
14 Apr 08 |
peter |
142 |
|