From dc79f9630f82c6e5c9e3d22957209ddf67dabc09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 30 May 2017 15:53:54 +0200 Subject: [PATCH] Fixed unit tests --- cli/cppcheckexecutor.cpp | 10 +++++++--- cli/cppcheckexecutor.h | 4 ++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/cli/cppcheckexecutor.cpp b/cli/cppcheckexecutor.cpp index 3412aa79b..8d2a3e8c2 100644 --- a/cli/cppcheckexecutor.cpp +++ b/cli/cppcheckexecutor.cpp @@ -78,12 +78,13 @@ /*static*/ FILE* CppCheckExecutor::exceptionOutput = stdout; CppCheckExecutor::CppCheckExecutor() - : _settings(0), time1(0), errorOutput(stderr), errorlist(false) + : _settings(0), time1(0), errorOutput(nullptr), errorlist(false) { } CppCheckExecutor::~CppCheckExecutor() { + delete errorOutput; } bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* const argv[]) @@ -809,7 +810,7 @@ int CppCheckExecutor::check_internal(CppCheck& cppcheck, int /*argc*/, const cha time1 = std::time(0); if (!settings.outputFile.empty()) { - errorOutput = fopen(settings.outputFile.c_str(), "wt"); + errorOutput = new std::ofstream(settings.outputFile); } if (settings.xml) { @@ -927,7 +928,10 @@ void CppCheckExecutor::reportErr(const std::string &errmsg) return; _errorList.insert(errmsg); - std::fprintf(errorOutput, "%s\n", errmsg.c_str()); + if (errorOutput) + *errorOutput << errmsg << std::endl; + else + std::cerr << errmsg << std::endl; } void CppCheckExecutor::reportOut(const std::string &outmsg) diff --git a/cli/cppcheckexecutor.h b/cli/cppcheckexecutor.h index 50ae1a76e..1707b4af9 100644 --- a/cli/cppcheckexecutor.h +++ b/cli/cppcheckexecutor.h @@ -177,9 +177,9 @@ private: static FILE* exceptionOutput; /** - * Error output (default stderr) + * Error output */ - FILE* errorOutput; + std::ofstream *errorOutput; /** * Has --errorlist been given?