Skip to content

Commit e766fba

Browse files
authored
fixed tests by adjusting results for picojson update (#5729)
The tests which are failing were in introduced in #5712. Those were not included in #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
1 parent 347b188 commit e766fba

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

test/helpers.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ ScopedFile::ScopedFile(std::string name, const std::string &content, std::string
5151
, mFullPath(Path::join(mPath, mName))
5252
{
5353
if (!mPath.empty() && mPath != Path::getCurrentPath()) {
54+
if (Path::isDirectory(mPath))
55+
throw std::runtime_error("ScopedFile(" + mFullPath + ") - directory already exists");
5456
#ifdef _WIN32
5557
if (!CreateDirectoryA(mPath.c_str(), nullptr))
5658
throw std::runtime_error("ScopedFile(" + mFullPath + ") - could not create directory");
@@ -60,6 +62,9 @@ ScopedFile::ScopedFile(std::string name, const std::string &content, std::string
6062
#endif
6163
}
6264

65+
if (Path::isFile(mFullPath))
66+
throw std::runtime_error("ScopedFile(" + mFullPath + ") - file already exists");
67+
6368
std::ofstream of(mFullPath);
6469
if (!of.is_open())
6570
throw std::runtime_error("ScopedFile(" + mFullPath + ") - could not open file");

test/testcmdlineparser.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ class TestCmdlineParser : public TestFixture {
436436
"{\n");
437437
const char * const argv[] = {"cppcheck", "--version"};
438438
ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(2, argv));
439-
ASSERT_EQUALS("cppcheck: error: could not load cppcheck.cfg - not a valid JSON - syntax error at line 1 near: \n", logger->str());
439+
ASSERT_EQUALS("cppcheck: error: could not load cppcheck.cfg - not a valid JSON - syntax error at line 2 near: \n", logger->str());
440440
}
441441

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

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

test/testsettings.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class TestSettings : public TestFixture {
104104
Settings s;
105105
ScopedFile file("cppcheck.cfg",
106106
"{\n");
107-
ASSERT_EQUALS("not a valid JSON - syntax error at line 1 near: ", s.loadCppcheckCfg());
107+
ASSERT_EQUALS("not a valid JSON - syntax error at line 2 near: ", s.loadCppcheckCfg());
108108
}
109109
{
110110
Settings s;

0 commit comments

Comments
 (0)