From de83b76a3dd8bb17febc1b0ce31ab42dc562e746 Mon Sep 17 00:00:00 2001 From: Matthias Bilger Date: Mon, 1 Nov 2021 00:11:33 +0100 Subject: [PATCH] use extra parameter for patch base path --- .../reporter_path_base/main.cpp | 28 +++++++++++++++++++ tools/CLIOptions/CLIOptions.cpp | 2 +- tools/CLIOptions/CLIOptions.h | 11 +++++++- tools/mull-cxx/mull-cxx-cli.h | 2 ++ tools/mull-cxx/mull-cxx.cpp | 5 +++- tools/mull-runner/mull-runner-cli.h | 1 + tools/mull-runner/mull-runner.cpp | 3 ++ 7 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 tests-lit/tests/patch-reporter/reporter_path_base/main.cpp diff --git a/tests-lit/tests/patch-reporter/reporter_path_base/main.cpp b/tests-lit/tests/patch-reporter/reporter_path_base/main.cpp new file mode 100644 index 000000000..2faf5341d --- /dev/null +++ b/tests-lit/tests/patch-reporter/reporter_path_base/main.cpp @@ -0,0 +1,28 @@ +int equal(int a, int b) { + return a == b; +} + +int main() { + return equal(2, 2) != 1; +} + +// clang-format off +/** + +RUN: cd %S +RUN: mkdir -p %S/Output/sandbox +RUN: cp %S/main.cpp %S/Output/sandbox/main.cpp +RUN: cd %S/Output/sandbox + +/// We cd to the the test directory and compile using relative paths. +RUN: cd %S; %clang_cxx %sysroot -fembed-bitcode -g -O0 Output/sandbox/main.cpp -o Output/main.cpp.exe + +RUN: cd %S/Output && echo $PATH; (unset TERM; %mull_cxx -mutators=cxx_eq_to_ne -linker-flags="%sysroot" --git-project-root %S/Output --report-patch-base %S --linker=%clang_cxx -debug main.cpp.exe --report-name test --reporters Patches --reporters IDE; test $? = 0; ls -R %S/Output/test-patches; cat %S/Output/test-patches/killed-Output_sandbox_main_cpp-cxx_eq_to_ne-L2-C12.patch) | %filecheck %s --dump-input=fail --strict-whitespace --match-full-lines + +CHECK:[debug] Writing Patchfile: {{.*}} +CHECK:[info] Patchfiles can be found at './test-patches' +CHECK:{{.*}}main_cpp{{.*}} +CHECK:--- a/Output/sandbox/main.cpp 0 +CHECK:+{{\s+}}return a != b; + +*/ diff --git a/tools/CLIOptions/CLIOptions.cpp b/tools/CLIOptions/CLIOptions.cpp index 2a70d691a..b83b1dcf3 100644 --- a/tools/CLIOptions/CLIOptions.cpp +++ b/tools/CLIOptions/CLIOptions.cpp @@ -70,7 +70,7 @@ std::vector> ReportersCLIOptions::reporters(ReporterPa reporters.emplace_back(new mull::SQLiteReporter(diagnostics, directory, name)); } break; case ReporterKind::Patches: { - reporters.emplace_back(new mull::PatchesReporter(diagnostics, directory, name, params.gitDir)); + reporters.emplace_back(new mull::PatchesReporter(diagnostics, directory, name, params.patchBasePathDir)); } break; case ReporterKind::Elements: { if (!params.compilationDatabaseAvailable) { diff --git a/tools/CLIOptions/CLIOptions.h b/tools/CLIOptions/CLIOptions.h index aee6bf48e..e8516f556 100644 --- a/tools/CLIOptions/CLIOptions.h +++ b/tools/CLIOptions/CLIOptions.h @@ -79,6 +79,15 @@ opt ReportName( \ init(""), \ cat(MullCategory)) +#define ReportPatchBaseDirectory_() \ +opt ReportPatchBaseDirectory( \ + "report-patch-base", \ + desc("Create Patches relative to this directory (defaults to git-project-root if available, else absolute path will be used)"), \ + Optional, \ + value_desc("directory"), \ + init("."), \ + cat(MullCategory)) + #define DisableJunkDetection_() \ opt DisableJunkDetection( \ "disable-junk-detection", \ @@ -311,7 +320,7 @@ class MutatorsCLIOptions { struct ReporterParameters { std::string reporterName; std::string reporterDirectory; - std::string gitDir; + std::string patchBasePathDir; bool compilationDatabaseAvailable; bool IDEReporterShowKilled; }; diff --git a/tools/mull-cxx/mull-cxx-cli.h b/tools/mull-cxx/mull-cxx-cli.h index 5b4bde3c8..d378447a5 100644 --- a/tools/mull-cxx/mull-cxx-cli.h +++ b/tools/mull-cxx/mull-cxx-cli.h @@ -21,6 +21,7 @@ NoTestOutput_(); NoMutantOutput_(); ReportName_(); ReportDirectory_(); +ReportPatchBaseDirectory_(); Mutators_(); DryRunOption_(); Linker_(); @@ -54,6 +55,7 @@ void dumpCLIInterface(Diagnostics &diagnostics) { &ReportName, &ReportDirectory, + &ReportPatchBaseDirectory, reporters, &IDEReporterShowKilled, &DebugEnabled, diff --git a/tools/mull-cxx/mull-cxx.cpp b/tools/mull-cxx/mull-cxx.cpp index fddde145e..5d8133ad8 100644 --- a/tools/mull-cxx/mull-cxx.cpp +++ b/tools/mull-cxx/mull-cxx.cpp @@ -189,9 +189,12 @@ int main(int argc, char **argv) { tool::ReporterParameters params{ .reporterName = tool::ReportName.getValue(), .reporterDirectory = tool::ReportDirectory.getValue(), + .patchBasePathDir = tool::ReportPatchBaseDirectory.getValue(), .compilationDatabaseAvailable = compilationDatabaseInfoAvailable, - .gitDir = tool::GitProjectRoot.getValue(), .IDEReporterShowKilled = tool::IDEReporterShowKilled }; + if(tool::ReportPatchBaseDirectory.getValue() == "." && tool::GitProjectRoot.getValue() != "."){ + params.patchBasePathDir = tool::GitProjectRoot.getValue(); + } std::vector> reporters = reportersOption.reporters(params); mull::CXXJunkDetector junkDetector(diagnostics, astStorage); diff --git a/tools/mull-runner/mull-runner-cli.h b/tools/mull-runner/mull-runner-cli.h index a4168745c..eb2a4e3dd 100644 --- a/tools/mull-runner/mull-runner-cli.h +++ b/tools/mull-runner/mull-runner-cli.h @@ -19,6 +19,7 @@ NoTestOutput_(); NoMutantOutput_(); ReportName_(); ReportDirectory_(); +ReportPatchBaseDirectory_(); IDEReporterShowKilled_(); IncludeNotCovered_(); RunnerArgs_(); diff --git a/tools/mull-runner/mull-runner.cpp b/tools/mull-runner/mull-runner.cpp index 2cc2ef247..5f96ba2f2 100644 --- a/tools/mull-runner/mull-runner.cpp +++ b/tools/mull-runner/mull-runner.cpp @@ -82,10 +82,13 @@ int main(int argc, char **argv) { configuration.captureMutantOutput = false; } + tool::ReporterParameters params{ .reporterName = tool::ReportName.getValue(), .reporterDirectory = tool::ReportDirectory.getValue(), + .patchBasePathDir = tool::ReportPatchBaseDirectory.getValue(), .compilationDatabaseAvailable = false, .IDEReporterShowKilled = tool::IDEReporterShowKilled }; + std::vector> reporters = reportersOption.reporters(params); std::string executable = inputFile;