2013-10-01 04:30:57 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2013 Kitware, Inc., Insight Software Consortium
|
|
|
|
|
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
|
|
|
|
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the License for more information.
|
|
|
|
============================================================================*/
|
|
|
|
#include "cmRST.h"
|
|
|
|
|
|
|
|
#include "cmSystemTools.h"
|
|
|
|
|
2016-05-26 22:58:51 +03:00
|
|
|
void reportLine(std::ostream& os, bool ret, std::string const& line, bool eol)
|
2013-10-01 04:30:57 +04:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (ret) {
|
|
|
|
os << "\"" << line << "\" (" << (eol ? "with EOL" : "without EOL") << ")";
|
|
|
|
} else {
|
2013-10-01 04:30:57 +04:00
|
|
|
os << "EOF";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-01 04:30:57 +04:00
|
|
|
}
|
|
|
|
|
2014-06-06 18:39:45 +04:00
|
|
|
int testRST(int argc, char* argv[])
|
2013-10-01 04:30:57 +04:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (argc != 2) {
|
2014-06-06 18:39:45 +04:00
|
|
|
std::cerr << "Usage: testRST <dir>" << std::endl;
|
|
|
|
return 1;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-06-06 18:39:45 +04:00
|
|
|
std::string dir = argv[1];
|
2016-05-16 17:34:04 +03:00
|
|
|
if (dir.empty()) {
|
2013-10-01 04:30:57 +04:00
|
|
|
dir = ".";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-01 04:30:57 +04:00
|
|
|
std::string a_name = "testRST.actual";
|
|
|
|
std::string e_name = dir + "/testRST.expect";
|
|
|
|
|
|
|
|
// Process the test RST file.
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string fname = dir + "/testRST.rst";
|
|
|
|
std::ofstream fout(a_name.c_str());
|
|
|
|
if (!fout) {
|
|
|
|
std::cerr << "Could not open output " << a_name << std::endl;
|
|
|
|
return 1;
|
2013-10-01 04:30:57 +04:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
cmRST r(fout, dir);
|
|
|
|
if (!r.ProcessFile(fname)) {
|
|
|
|
std::cerr << "Could not open input " << fname << std::endl;
|
|
|
|
return 1;
|
2013-10-01 04:30:57 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compare expected and actual outputs.
|
|
|
|
std::ifstream e_fin(e_name.c_str());
|
|
|
|
std::ifstream a_fin(a_name.c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!e_fin) {
|
2013-10-01 04:30:57 +04:00
|
|
|
std::cerr << "Could not open input " << e_name << std::endl;
|
|
|
|
return 1;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (!a_fin) {
|
2013-10-01 04:30:57 +04:00
|
|
|
std::cerr << "Could not open input " << a_name << std::endl;
|
|
|
|
return 1;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-01 04:30:57 +04:00
|
|
|
int lineno = 0;
|
|
|
|
bool e_ret;
|
|
|
|
bool a_ret;
|
2016-05-16 17:34:04 +03:00
|
|
|
do {
|
2013-10-01 04:30:57 +04:00
|
|
|
std::string e_line;
|
|
|
|
std::string a_line;
|
|
|
|
bool e_eol;
|
|
|
|
bool a_eol;
|
|
|
|
e_ret = cmSystemTools::GetLineFromStream(e_fin, e_line, &e_eol);
|
|
|
|
a_ret = cmSystemTools::GetLineFromStream(a_fin, a_line, &a_eol);
|
|
|
|
++lineno;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (e_ret != a_ret || e_line != a_line || e_eol != a_eol) {
|
2013-10-01 04:30:57 +04:00
|
|
|
a_fin.seekg(0, std::ios::beg);
|
|
|
|
std::cerr << "Actual output does not match that expected on line "
|
2016-05-16 17:34:04 +03:00
|
|
|
<< lineno << "." << std::endl
|
|
|
|
<< "Expected ";
|
2013-10-01 04:30:57 +04:00
|
|
|
reportLine(std::cerr, e_ret, e_line, e_eol);
|
|
|
|
std::cerr << " but got ";
|
|
|
|
reportLine(std::cerr, a_ret, a_line, a_eol);
|
|
|
|
std::cerr << "." << std::endl
|
|
|
|
<< "Actual output:" << std::endl
|
|
|
|
<< a_fin.rdbuf();
|
|
|
|
return 1;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
} while (e_ret && a_ret);
|
2013-10-01 04:30:57 +04:00
|
|
|
return 0;
|
|
|
|
}
|