From 49ed1a82b45cc65c965857ed9dd982d350455ea4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 27 Dec 2019 19:25:06 +0100 Subject: [PATCH] Verification; save report in custom file --- cli/cmdlineparser.cpp | 6 ++++-- cli/cppcheckexecutor.cpp | 4 +++- lib/exprengine.cpp | 8 ++++---- lib/settings.cpp | 1 - lib/settings.h | 4 ++-- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index 448fddcf4..9c096e9e1 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -192,8 +192,10 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) // Experimental: Verify else if (std::strcmp(argv[i], "--verify") == 0) mSettings->verification = true; - else if (std::strcmp(argv[i], "--verify-report") == 0) - mSettings->verification = mSettings->verificationReport = true; + else if (std::strncmp(argv[i], "--verify-report=", 16) == 0) { + mSettings->verification = true; + mSettings->verificationReport = argv[i] + 16; + } else if (std::strcmp(argv[i], "--debug-verify") == 0) mSettings->debugVerification = true; diff --git a/cli/cppcheckexecutor.cpp b/cli/cppcheckexecutor.cpp index 061d5106f..ea5d89767 100644 --- a/cli/cppcheckexecutor.cpp +++ b/cli/cppcheckexecutor.cpp @@ -1066,8 +1066,10 @@ void CppCheckExecutor::reportErr(const ErrorLogger::ErrorMessage &msg) void CppCheckExecutor::reportVerification(const std::string &str) { + if (!mSettings || str.empty()) + return; if (!mVerificationOutput) - mVerificationOutput = new std::ofstream("verification-report.txt"); + mVerificationOutput = new std::ofstream(mSettings->verificationReport); (*mVerificationOutput) << str << std::endl; } diff --git a/lib/exprengine.cpp b/lib/exprengine.cpp index 6c2c02b15..c9bccf7d9 100644 --- a/lib/exprengine.cpp +++ b/lib/exprengine.cpp @@ -1578,16 +1578,16 @@ void ExprEngine::executeFunction(const Scope *functionScope, const Tokenizer *to } if (settings->debugVerification && !trackExecution.isAllOk()) { - if (settings->verificationReport) + if (!settings->verificationReport.empty()) report << "[debug]" << std::endl; trackExecution.print(report); - if (settings->verificationReport) + if (!settings->verificationReport.empty()) report << "[details]" << std::endl; trackExecution.report(report, functionScope); } // Write a verification report - if (settings->verificationReport) { + if (!settings->verificationReport.empty()) { report << "[function-report] " << Path::stripDirectoryPart(tokenizer->list.getFiles().at(functionScope->bodyStart->fileIndex())) << ":" << functionScope->bodyStart->linenr() << ":" @@ -1766,6 +1766,6 @@ void ExprEngine::runChecks(ErrorLogger *errorLogger, const Tokenizer *tokenizer, std::ostringstream report; ExprEngine::executeAllFunctions(tokenizer, settings, callbacks, report); - if (errorLogger && settings->verificationReport && !report.str().empty()) + if (errorLogger && !settings->verificationReport.empty() && !report.str().empty()) errorLogger->reportVerification(report.str()); } diff --git a/lib/settings.cpp b/lib/settings.cpp index 290b1f0c6..f291dd923 100644 --- a/lib/settings.cpp +++ b/lib/settings.cpp @@ -46,7 +46,6 @@ Settings::Settings() force(false), inconclusive(false), verification(false), - verificationReport(false), debugVerification(false), inlineSuppressions(false), jobs(1), diff --git a/lib/settings.h b/lib/settings.h index 7fb81df56..675125788 100644 --- a/lib/settings.h +++ b/lib/settings.h @@ -191,8 +191,8 @@ public: /** @brief Enable verification analysis */ bool verification; - /** @brief Generate verification report */ - bool verificationReport; + /** @brief Verification report filename */ + std::string verificationReport; /** @brief Generate verification debug output */ bool debugVerification;