Skip to content

Commit

Permalink
fixed tests by adjusting results for picojson update (danmar#5729)
Browse files Browse the repository at this point in the history
The tests which are failing were in introduced in danmar#5712. Those were not
included in danmar#5710 which updated `picojson` that resulted in the
different lines being reported in the error messages.

I also added some checks to `ScopeFile` which will indicate that a
temporary file already exists highlighting multi-threading issues and
leftover files from previously aborted testruns. I ran into his while
looking into these failing tests
  • Loading branch information
firewave committed Dec 5, 2023
1 parent 347b188 commit e766fba
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions test/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ ScopedFile::ScopedFile(std::string name, const std::string &content, std::string
, mFullPath(Path::join(mPath, mName))
{
if (!mPath.empty() && mPath != Path::getCurrentPath()) {
if (Path::isDirectory(mPath))
throw std::runtime_error("ScopedFile(" + mFullPath + ") - directory already exists");
#ifdef _WIN32
if (!CreateDirectoryA(mPath.c_str(), nullptr))
throw std::runtime_error("ScopedFile(" + mFullPath + ") - could not create directory");
Expand All @@ -60,6 +62,9 @@ ScopedFile::ScopedFile(std::string name, const std::string &content, std::string
#endif
}

if (Path::isFile(mFullPath))
throw std::runtime_error("ScopedFile(" + mFullPath + ") - file already exists");

std::ofstream of(mFullPath);
if (!of.is_open())
throw std::runtime_error("ScopedFile(" + mFullPath + ") - could not open file");
Expand Down
6 changes: 3 additions & 3 deletions test/testcmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ class TestCmdlineParser : public TestFixture {
"{\n");
const char * const argv[] = {"cppcheck", "--version"};
ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(2, argv));
ASSERT_EQUALS("cppcheck: error: could not load cppcheck.cfg - not a valid JSON - syntax error at line 1 near: \n", logger->str());
ASSERT_EQUALS("cppcheck: error: could not load cppcheck.cfg - not a valid JSON - syntax error at line 2 near: \n", logger->str());
}

void onefile() {
Expand Down Expand Up @@ -1706,7 +1706,7 @@ class TestCmdlineParser : public TestFixture {
"{\n");
const char * const argv[] = {"cppcheck", "--errorlist"};
ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(2, argv));
ASSERT_EQUALS("cppcheck: error: could not load cppcheck.cfg - not a valid JSON - syntax error at line 1 near: \n", logger->str());
ASSERT_EQUALS("cppcheck: error: could not load cppcheck.cfg - not a valid JSON - syntax error at line 2 near: \n", logger->str());
}

void ignorepathsnopath() {
Expand Down Expand Up @@ -2310,7 +2310,7 @@ class TestCmdlineParser : public TestFixture {
"{\n");
const char * const argv[] = {"cppcheck", "test.cpp"};
ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(2, argv));
ASSERT_EQUALS("cppcheck: error: could not load cppcheck.cfg - not a valid JSON - syntax error at line 1 near: \n", logger->str());
ASSERT_EQUALS("cppcheck: error: could not load cppcheck.cfg - not a valid JSON - syntax error at line 2 near: \n", logger->str());
}
};

Expand Down
2 changes: 1 addition & 1 deletion test/testsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class TestSettings : public TestFixture {
Settings s;
ScopedFile file("cppcheck.cfg",
"{\n");
ASSERT_EQUALS("not a valid JSON - syntax error at line 1 near: ", s.loadCppcheckCfg());
ASSERT_EQUALS("not a valid JSON - syntax error at line 2 near: ", s.loadCppcheckCfg());
}
{
Settings s;
Expand Down

0 comments on commit e766fba

Please sign in to comment.