Verification; save report in custom file

This commit is contained in:
Daniel Marjamäki 2019-12-27 19:25:06 +01:00
parent 4b4f7ea60b
commit 49ed1a82b4
5 changed files with 13 additions and 10 deletions

View File

@ -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;

View File

@ -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;
}

View File

@ -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());
}

View File

@ -46,7 +46,6 @@ Settings::Settings()
force(false),
inconclusive(false),
verification(false),
verificationReport(false),
debugVerification(false),
inlineSuppressions(false),
jobs(1),

View File

@ -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;