2626#include " fixture.h"
2727#include " helpers.h"
2828#include " threadexecutor.h"
29+ #include " singleexecutor.h"
2930
3031#include < algorithm>
3132#include < cstddef>
@@ -178,34 +179,35 @@ class TestSuppressions : public TestFixture {
178179 }
179180
180181 // Check the suppression for multiple files
181- unsigned int checkSuppression (std::map<std::string, std::string> &files , const std::string &suppression = emptyString) {
182+ unsigned int checkSuppression (std::map<std::string, std::string> &f , const std::string &suppression = emptyString) {
182183 // Clear the error log
183184 errout.str (" " );
185+ output.str (" " );
186+
187+ std::map<std::string, std::size_t > files;
188+ for (std::map<std::string, std::string>::const_iterator i = f.cbegin (); i != f.cend (); ++i) {
189+ files[i->first ] = i->second .size ();
190+ }
184191
185192 CppCheck cppCheck (*this , true , nullptr );
186193 Settings& settings = cppCheck.settings ();
187194 settings.jobs = 1 ;
188195 settings.inlineSuppressions = true ;
196+ settings.severity .enable (Severity::information);
189197 if (suppression == " unusedFunction" )
190198 settings.checks .setEnabled (Checks::unusedFunction, true );
191- settings.severity .enable (Severity::information);
192199 if (!suppression.empty ()) {
193- std::string r = settings.nomsg .addSuppressionLine (suppression);
194- EXPECT_EQ (" " , r);
200+ EXPECT_EQ (" " , settings.nomsg .addSuppressionLine (suppression));
195201 }
202+ SingleExecutor executor (cppCheck, files, settings, *this );
203+ std::vector<std::unique_ptr<ScopedFile>> scopedfiles;
204+ scopedfiles.reserve (files.size ());
205+ for (std::map<std::string, std::string>::const_iterator i = f.cbegin (); i != f.cend (); ++i)
206+ scopedfiles.emplace_back (new ScopedFile (i->first , i->second ));
196207
197- unsigned int exitCode = std::accumulate (files.cbegin (), files.cend (), 0U , [&](unsigned int v, const std::pair<std::string, std::string>& f) {
198- return v | cppCheck.check (f.first , f.second );
199- });
200-
201- if (cppCheck.analyseWholeProgram ())
202- exitCode |= settings.exitCode ;
203-
204- std::map<std::string, std::size_t > files_for_report;
205- for (std::map<std::string, std::string>::const_iterator file = files.cbegin (); file != files.cend (); ++file)
206- files_for_report[file->first ] = file->second .size ();
208+ const unsigned int exitCode = executor.check ();
207209
208- CppCheckExecutor::reportSuppressions (settings, false , files_for_report , *this );
210+ CppCheckExecutor::reportSuppressions (settings, false , files , *this );
209211
210212 return exitCode;
211213 }
@@ -814,13 +816,13 @@ class TestSuppressions : public TestFixture {
814816 std::map<std::string, std::string> mfiles;
815817 mfiles[" test.cpp" ] = " fi if;" ;
816818 mfiles[" test2.cpp" ] = " fi if" ;
817- ASSERT_EQUALS (1 , checkSuppression (mfiles, " *:test.cpp" ));
819+ ASSERT_EQUALS (2 , checkSuppression (mfiles, " *:test.cpp" ));
818820 ASSERT_EQUALS (" [test2.cpp:1]: (error) syntax error\n " , errout.str ());
819821
820822 // multi error in file, but only suppression one error
821823 const char code2[] = " fi fi\n "
822824 " if if;" ;
823- ASSERT_EQUALS (1 , checkSuppression (code2, " *:test.cpp:1" )); // suppress all error at line 1 of test.cpp
825+ ASSERT_EQUALS (2 , checkSuppression (code2, " *:test.cpp:1" )); // suppress all error at line 1 of test.cpp
824826 ASSERT_EQUALS (" [test.cpp:2]: (error) syntax error\n " , errout.str ());
825827
826828 // multi error in file, but only suppression one error (2)
@@ -829,7 +831,7 @@ class TestSuppressions : public TestFixture {
829831 " int b = y/0;\n "
830832 " }\n "
831833 " f(0, 1);\n " ;
832- ASSERT_EQUALS (1 , checkSuppression (code3, " zerodiv:test.cpp:3" )); // suppress 'errordiv' at line 3 of test.cpp
834+ ASSERT_EQUALS (2 , checkSuppression (code3, " zerodiv:test.cpp:3" )); // suppress 'errordiv' at line 3 of test.cpp
833835 }
834836
835837};
0 commit comments