fixed #11783 (Remove .plist files generated by unit tests) (#5312)

This commit is contained in:
Oliver Stöneberg 2023-08-22 15:25:28 +02:00 committed by GitHub
parent 18b526b08a
commit d6beccc445
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 32 additions and 11 deletions

View File

@ -671,7 +671,7 @@ cli/threadexecutor.o: cli/threadexecutor.cpp cli/cppcheckexecutor.h cli/executor
test/fixture.o: test/fixture.cpp externals/tinyxml2/tinyxml2.h lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/utils.h test/fixture.h test/options.h test/redirect.h
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/fixture.cpp
test/helpers.o: test/helpers.cpp externals/simplecpp/simplecpp.h lib/config.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/preprocessor.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/helpers.h
test/helpers.o: test/helpers.cpp cli/filelister.h externals/simplecpp/simplecpp.h lib/config.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/path.h lib/pathmatch.h lib/platform.h lib/preprocessor.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/helpers.h
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/helpers.cpp
test/main.o: test/main.cpp externals/simplecpp/simplecpp.h lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/preprocessor.h lib/settings.h lib/standards.h lib/suppressions.h lib/utils.h test/fixture.h test/options.h

View File

@ -18,7 +18,9 @@
#include "helpers.h"
#include "filelister.h"
#include "path.h"
#include "pathmatch.h"
#include "preprocessor.h"
#include <cerrno>
@ -26,6 +28,7 @@
#include <iostream>
#include <fstream> // IWYU pragma: keep
#include <list>
#include <map>
#include <stdexcept>
#include <utility>
#include <vector>
@ -41,6 +44,7 @@
class Suppressions;
// TODO: better path-only usage
ScopedFile::ScopedFile(std::string name, const std::string &content, std::string path)
: mName(std::move(name))
, mPath(Path::toNativeSeparators(std::move(path)))
@ -65,18 +69,35 @@ ScopedFile::ScopedFile(std::string name, const std::string &content, std::string
ScopedFile::~ScopedFile() {
const int remove_res = std::remove(mFullPath.c_str());
if (remove_res != 0) {
std::cout << "ScopedFile(" << mFullPath + ") - could not delete file (" << remove_res << ")";
std::cout << "ScopedFile(" << mFullPath + ") - could not delete file (" << remove_res << ")" << std::endl;
}
if (!mPath.empty() && mPath != Path::getCurrentPath()) {
// TODO: remove all files
// TODO: simplify the function call
// hack to be able to delete *.plist output files
std::map<std::string, std::size_t> files;
const std::string res = FileLister::addFiles(files, mPath, {".plist"}, false, PathMatch({}));
if (!res.empty()) {
std::cout << "ScopedFile(" << mPath + ") - generating file list failed (" << res << ")" << std::endl;
}
for (const auto &f : files)
{
const std::string &file = f.first;
const int rm_f_res = std::remove(file.c_str());
if (rm_f_res != 0) {
std::cout << "ScopedFile(" << mPath + ") - could not delete '" << file << "' (" << rm_f_res << ")" << std::endl;
}
}
#ifdef _WIN32
if (!RemoveDirectoryA(mPath.c_str())) {
std::cout << "ScopedFile(" << mFullPath + ") - could not delete folder (" << GetLastError() << ")";
std::cout << "ScopedFile(" << mFullPath + ") - could not delete folder (" << GetLastError() << ")" << std::endl;
}
#else
const int rmdir_res = rmdir(mPath.c_str());
if (rmdir_res == -1) {
const int err = errno;
std::cout << "ScopedFile(" << mFullPath + ") - could not delete folder (" << err << ")";
std::cout << "ScopedFile(" << mFullPath + ") - could not delete folder (" << err << ")" << std::endl;
}
#endif
}

View File

@ -140,8 +140,8 @@ private:
}
void many_threads_plist() {
const char plistOutput[] = "plist";
ScopedFile plistFile("dummy", plistOutput);
const char plistOutput[] = "plist_process/";
ScopedFile plistFile("dummy", "", plistOutput);
check(16, 100, 100,
"int main()\n"

View File

@ -182,15 +182,15 @@ private:
}
void many_files_plist() {
const char plistOutput[] = "plist";
ScopedFile plistFile("dummy", plistOutput);
const std::string plistOutput = "plist_" + fprefix() + "/";
ScopedFile plistFile("dummy", "", plistOutput);
check(100, 100,
"int main()\n"
"{\n"
" char *a = malloc(10);\n"
" return 0;\n"
"}", dinit(CheckOptions, $.plistOutput = plistOutput));
"}", dinit(CheckOptions, $.plistOutput = plistOutput.c_str()));
}
void no_errors_more_files() {

View File

@ -138,8 +138,8 @@ private:
}
void many_threads_plist() {
const char plistOutput[] = "plist";
ScopedFile plistFile("dummy", plistOutput);
const char plistOutput[] = "plist_thread/";
ScopedFile plistFile("dummy", "", plistOutput);
check(16, 100, 100,
"int main()\n"