Skip to content

Commit

Permalink
Merge pull request #823 from mull-project/element-without-compdb
Browse files Browse the repository at this point in the history
mull-cxx: raise error if Elements reporter is used without compilation DB
  • Loading branch information
AlexDenisov committed Jan 7, 2021
2 parents 8aea5fb + 575a82d commit b9e6f76
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[
{
"arguments": [
"cc",
"-c",
"-fembed-bitcode",
"-g",
"-O0",
"-o",
"%PWD/sample.cpp.exe",
"%PWD/sample.cpp"
],
"directory": "/",
"file": "%PWD/sample.cpp"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
int sum(int a, int b) {
return a + b;
}

int main() {
return sum(-2, 2);
}

// clang-format off

/**
RUN: cd / && %CLANG_EXEC -fembed-bitcode -g -O0 %s -o %s.exe
RUN: sed -e "s:%PWD:%s:g" %S/compile_commands.json.template > %S/compile_commands.json
RUN: cd %CURRENT_DIR
RUN: (unset TERM; %MULL_EXEC -linker=%clang_cxx -workers=1 -mutators=cxx_add_to_sub -reporters=Elements "%s.exe" 2>&1; test $? = 1) | %FILECHECK_EXEC "%s" --dump-input=fail --strict-whitespace --match-full-lines --check-prefix=WITHOUT-COMPDB-PROVIDED
WITHOUT-COMPDB-PROVIDED:[error] Mutation Testing Elements Reporter requires compilation database. Please provide it using flags -compdb-path and -compdb-flags.
RUN: (unset TERM; %MULL_EXEC -linker=%clang_cxx -workers=1 -mutators=cxx_add_to_sub -reporters=Elements -reporters=IDE -ide-reporter-show-killed -compdb-path %S/compile_commands.json "%s.exe" 2>&1; test $? = 0) | %FILECHECK_EXEC %s --dump-input=fail --strict-whitespace --match-full-lines --check-prefix=WITH-COMPDB-PROVIDED
WITH-COMPDB-PROVIDED:{{^.*}}[info] Running mutants (threads: 1){{$}}
WITH-COMPDB-PROVIDED:[info] Killed mutants (1/1):
WITH-COMPDB-PROVIDED:{{^.*}}/sample.cpp:2:12: warning: Killed: Replaced + with - [cxx_add_to_sub]{{$}}
WITH-COMPDB-PROVIDED: return a + b;
WITH-COMPDB-PROVIDED: ^
WITH-COMPDB-PROVIDED:[info] All mutations have been killed
WITH-COMPDB-PROVIDED:[info] Mutation score: 100%
**/
5 changes: 5 additions & 0 deletions tools/mull-cxx/CLIOptions.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "CLIOptions.h"
#include <mull/Config/Configuration.h>
#include <mull/Diagnostics/Diagnostics.h>
#include <mull/Mutators/Mutator.h>
#include <mull/Reporters/IDEReporter.h>
#include <mull/Reporters/MutationTestingElementsReporter.h>
Expand Down Expand Up @@ -257,6 +258,10 @@ std::vector<std::unique_ptr<Reporter>> ReportersCLIOptions::reporters(ReporterPa
reporters.emplace_back(new mull::SQLiteReporter(diagnostics, directory, name));
} break;
case ReporterKind::Elements: {
if (!params.compilationDatabaseAvailable) {
diagnostics.error("Mutation Testing Elements Reporter requires compilation database."
" Please provide it using flags -compdb-path and -compdb-flags.");
}
reporters.emplace_back(
new mull::MutationTestingElementsReporter(diagnostics, directory, name, provider));
} break;
Expand Down
1 change: 1 addition & 0 deletions tools/mull-cxx/CLIOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ struct ReporterParameters {
std::string reporterName;
std::string reporterDirectory;
SourceInfoProvider &sourceInfoProvider;
bool compilationDatabaseAvailable;
};

class ReportersCLIOptions {
Expand Down
15 changes: 8 additions & 7 deletions tools/mull-cxx/mull-cxx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,14 @@ int main(int argc, char **argv) {
diagnostics, cxxCompilationDatabasePath, cxxCompilationFlags, bitcodeCompilationFlags);

mull::ASTSourceInfoProvider sourceInfoProvider(astStorage);
tool::ReporterParameters params{
.reporterName = tool::ReportName.getValue(),
.reporterDirectory = tool::ReportDirectory.getValue(),
.sourceInfoProvider = sourceInfoProvider,
.compilationDatabaseAvailable = compilationDatabaseInfoAvailable
};
std::vector<std::unique_ptr<mull::Reporter>> reporters = reportersOption.reporters(params);

mull::CXXJunkDetector junkDetector(astStorage);

mull::MutationsFinder mutationsFinder(mutatorsOptions.mutators(), configuration);
Expand Down Expand Up @@ -225,13 +233,6 @@ int main(int argc, char **argv) {
mull::Driver driver(diagnostics, configuration, program, toolchain, filters, mutationsFinder);
auto result = driver.run();

tool::ReporterParameters params{
.reporterName = tool::ReportName.getValue(),
.reporterDirectory = tool::ReportDirectory.getValue(),
.sourceInfoProvider = sourceInfoProvider,
};
std::vector<std::unique_ptr<mull::Reporter>> reporters = reportersOption.reporters(params);

for (auto &reporter : reporters) {
reporter->reportResults(*result);
}
Expand Down

0 comments on commit b9e6f76

Please sign in to comment.