Skip to content

Commit

Permalink
reduced usage of mutable of settings in executor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave committed Oct 5, 2023
1 parent 638bcd3 commit f36dde4
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 34 deletions.
22 changes: 10 additions & 12 deletions test/testprocessexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class TestProcessExecutorBase : public TestFixture {
SHOWTIME_MODES showtime = SHOWTIME_MODES::SHOWTIME_NONE;
const char* plistOutput = nullptr;
std::vector<std::string> filesList;
bool clangTidy = false;
bool executeCommandCalled = false;
std::string exe;
std::vector<std::string> args;
Expand All @@ -68,17 +69,18 @@ class TestProcessExecutorBase : public TestFixture {
void check(unsigned int jobs, int files, int result, const std::string &data, const CheckOptions& opt = make_default_obj{}) {
errout.str("");
output.str("");
settings.project.fileSettings.clear();

Settings s = settings;

std::map<std::string, std::size_t> filemap;
if (opt.filesList.empty()) {
for (int i = 1; i <= files; ++i) {
std::string s = fprefix() + "_" + std::to_string(i) + ".cpp";
filemap[s] = data.size();
std::string f_s = fprefix() + "_" + std::to_string(i) + ".cpp";
filemap[f_s] = data.size();
if (useFS) {
ImportProject::FileSettings fs;
fs.filename = std::move(s);
settings.project.fileSettings.emplace_back(std::move(fs));
fs.filename = std::move(f_s);
s.project.fileSettings.emplace_back(std::move(fs));
}
}
}
Expand All @@ -89,12 +91,11 @@ class TestProcessExecutorBase : public TestFixture {
if (useFS) {
ImportProject::FileSettings fs;
fs.filename = f;
settings.project.fileSettings.emplace_back(std::move(fs));
s.project.fileSettings.emplace_back(std::move(fs));
}
}
}

Settings s = settings;
s.jobs = jobs;
s.showtime = opt.showtime;
s.quiet = opt.quiet;
Expand Down Expand Up @@ -285,9 +286,6 @@ class TestProcessExecutorBase : public TestFixture {
if (!useFS)
return;

const Settings settingsOld = settings;
settings.clangTidy = true;

#ifdef _WIN32
const char exe[] = "clang-tidy.exe";
#else
Expand All @@ -303,12 +301,12 @@ class TestProcessExecutorBase : public TestFixture {
" return 0;\n"
"}",
dinit(CheckOptions,
$.quiet = false/*,
$.quiet = false,
$.clangTidy = true/*,
$.executeCommandCalled = true,
$.exe = exe,
$.args = {"-quiet", "-checks=*,-clang-analyzer-*,-llvm*", file, "--"}*/));
ASSERT_EQUALS("Checking " + file + " ...\n", output.str());
settings = settingsOld;
}

// TODO: provide data which actually shows values above 0
Expand Down
21 changes: 10 additions & 11 deletions test/testsingleexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class TestSingleExecutorBase : public TestFixture {
SHOWTIME_MODES showtime = SHOWTIME_MODES::SHOWTIME_NONE;
const char* plistOutput = nullptr;
std::vector<std::string> filesList;
bool clangTidy = false;
bool executeCommandCalled = false;
std::string exe;
std::vector<std::string> args;
Expand All @@ -76,17 +77,18 @@ class TestSingleExecutorBase : public TestFixture {
void check(int files, int result, const std::string &data, const CheckOptions& opt = make_default_obj{}) {
errout.str("");
output.str("");
settings.project.fileSettings.clear();

Settings s = settings;

std::map<std::string, std::size_t> filemap;
if (opt.filesList.empty()) {
for (int i = 1; i <= files; ++i) {
std::string s = fprefix() + "_" + zpad3(i) + ".cpp";
filemap[s] = data.size();
std::string f_s = fprefix() + "_" + zpad3(i) + ".cpp";
filemap[f_s] = data.size();
if (useFS) {
ImportProject::FileSettings fs;
fs.filename = std::move(s);
settings.project.fileSettings.emplace_back(std::move(fs));
fs.filename = std::move(f_s);
s.project.fileSettings.emplace_back(std::move(fs));
}
}
}
Expand All @@ -97,16 +99,16 @@ class TestSingleExecutorBase : public TestFixture {
if (useFS) {
ImportProject::FileSettings fs;
fs.filename = f;
settings.project.fileSettings.emplace_back(std::move(fs));
s.project.fileSettings.emplace_back(std::move(fs));
}
}
}

Settings s = settings;
s.showtime = opt.showtime;
s.quiet = opt.quiet;
if (opt.plistOutput)
s.plistOutput = opt.plistOutput;
s.clangTidy = opt.clangTidy;

bool executeCommandCalled = false;
std::string exe;
Expand Down Expand Up @@ -274,9 +276,6 @@ class TestSingleExecutorBase : public TestFixture {
if (!useFS)
return;

const Settings settingsOld = settings;
settings.clangTidy = true;

#ifdef _WIN32
const char exe[] = "clang-tidy.exe";
#else
Expand All @@ -291,11 +290,11 @@ class TestSingleExecutorBase : public TestFixture {
"}",
dinit(CheckOptions,
$.quiet = false,
$.clangTidy = true,
$.executeCommandCalled = true,
$.exe = exe,
$.args = {"-quiet", "-checks=*,-clang-analyzer-*,-llvm*", file, "--"}));
ASSERT_EQUALS("Checking " + file + " ...\n", output.str());
settings = settingsOld;
}

// TODO: provide data which actually shows values above 0
Expand Down
21 changes: 10 additions & 11 deletions test/testthreadexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class TestThreadExecutorBase : public TestFixture {
SHOWTIME_MODES showtime = SHOWTIME_MODES::SHOWTIME_NONE;
const char* plistOutput = nullptr;
std::vector<std::string> filesList;
bool clangTidy = false;
bool executeCommandCalled = false;
std::string exe;
std::vector<std::string> args;
Expand All @@ -68,17 +69,18 @@ class TestThreadExecutorBase : public TestFixture {
void check(unsigned int jobs, int files, int result, const std::string &data, const CheckOptions& opt = make_default_obj{}) {
errout.str("");
output.str("");
settings.project.fileSettings.clear();

Settings s = settings;

std::map<std::string, std::size_t> filemap;
if (opt.filesList.empty()) {
for (int i = 1; i <= files; ++i) {
std::string s = fprefix() + "_" + std::to_string(i) + ".cpp";
filemap[s] = data.size();
std::string f_s = fprefix() + "_" + std::to_string(i) + ".cpp";
filemap[f_s] = data.size();
if (useFS) {
ImportProject::FileSettings fs;
fs.filename = std::move(s);
settings.project.fileSettings.emplace_back(std::move(fs));
fs.filename = std::move(f_s);
s.project.fileSettings.emplace_back(std::move(fs));
}
}
}
Expand All @@ -89,17 +91,17 @@ class TestThreadExecutorBase : public TestFixture {
if (useFS) {
ImportProject::FileSettings fs;
fs.filename = f;
settings.project.fileSettings.emplace_back(std::move(fs));
s.project.fileSettings.emplace_back(std::move(fs));
}
}
}

Settings s = settings;
s.jobs = jobs;
s.showtime = opt.showtime;
s.quiet = opt.quiet;
if (opt.plistOutput)
s.plistOutput = opt.plistOutput;
s.clangTidy = opt.clangTidy;

bool executeCommandCalled = false;
std::string exe;
Expand Down Expand Up @@ -283,9 +285,6 @@ class TestThreadExecutorBase : public TestFixture {
if (!useFS)
return;

const Settings settingsOld = settings;
settings.clangTidy = true;

#ifdef _WIN32
const char exe[] = "clang-tidy.exe";
#else
Expand All @@ -300,11 +299,11 @@ class TestThreadExecutorBase : public TestFixture {
"}",
dinit(CheckOptions,
$.quiet = false,
$.clangTidy = true,
$.executeCommandCalled = true,
$.exe = exe,
$.args = {"-quiet", "-checks=*,-clang-analyzer-*,-llvm*", file, "--"}));
ASSERT_EQUALS("Checking " + file + " ...\n", output.str());
settings = settingsOld;
}

// TODO: provide data which actually shows values above 0
Expand Down

0 comments on commit f36dde4

Please sign in to comment.