2010-09-06 21:31:06 +02:00
/*
* Cppcheck - A tool for static C / C + + code analysis
2023-01-28 10:16:34 +01:00
* Copyright ( C ) 2007 - 2023 Cppcheck team .
2010-09-06 21:31:06 +02:00
*
* This program is free software : you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation , either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < http : //www.gnu.org/licenses/>.
*/
# include "cmdlineparser.h"
2022-08-20 20:54:31 +02:00
# include "cppcheckexecutor.h"
2022-01-27 19:03:20 +01:00
# include "errortypes.h"
2017-05-27 04:33:47 +02:00
# include "platform.h"
2010-09-26 05:19:30 +02:00
# include "redirect.h"
2017-05-27 04:33:47 +02:00
# include "settings.h"
# include "standards.h"
# include "suppressions.h"
2023-01-27 08:18:32 +01:00
# include "fixture.h"
2013-08-15 11:09:40 +02:00
# include "timer.h"
2010-09-06 21:31:06 +02:00
2022-09-16 07:15:49 +02:00
# include <cstdio>
2017-05-27 04:33:47 +02:00
# include <list>
# include <set>
# include <string>
# include <vector>
2015-03-11 22:26:33 +01:00
2011-10-13 20:53:06 +02:00
class TestCmdlineParser : public TestFixture {
2010-09-06 21:31:06 +02:00
public :
2013-08-07 18:24:18 +02:00
TestCmdlineParser ( )
: TestFixture ( " TestCmdlineParser " )
2023-01-27 10:46:48 +01:00
, defParser ( & settings ) {
# if defined(_WIN64) || defined(_WIN32)
CmdLineParser : : SHOW_DEF_PLATFORM_MSG = false ;
# endif
}
~ TestCmdlineParser ( ) override {
# if defined(_WIN64) || defined(_WIN32)
CmdLineParser : : SHOW_DEF_PLATFORM_MSG = true ;
# endif
}
2010-09-06 21:31:06 +02:00
private :
2022-09-17 18:50:25 +02:00
Settings settings ; // TODO: reset after each test
2022-12-19 22:28:36 +01:00
CmdLineParser defParser ; // TODO: reset after each test
2010-09-06 21:31:06 +02:00
2022-02-10 23:02:24 +01:00
void run ( ) override {
2010-09-06 21:31:06 +02:00
TEST_CASE ( nooptions ) ;
TEST_CASE ( helpshort ) ;
TEST_CASE ( helplong ) ;
TEST_CASE ( showversion ) ;
2010-09-06 22:16:52 +02:00
TEST_CASE ( onefile ) ;
TEST_CASE ( onepath ) ;
TEST_CASE ( optionwithoutfile ) ;
TEST_CASE ( verboseshort ) ;
TEST_CASE ( verboselong ) ;
2020-05-30 11:23:22 +02:00
TEST_CASE ( debugSimplified ) ;
2010-09-06 22:16:52 +02:00
TEST_CASE ( debugwarnings ) ;
TEST_CASE ( forceshort ) ;
TEST_CASE ( forcelong ) ;
2012-04-06 10:49:21 +02:00
TEST_CASE ( relativePaths ) ;
2010-09-06 22:16:52 +02:00
TEST_CASE ( quietshort ) ;
TEST_CASE ( quietlong ) ;
2011-01-17 20:03:22 +01:00
TEST_CASE ( defines_noarg ) ;
2011-01-17 20:19:27 +01:00
TEST_CASE ( defines_noarg2 ) ;
TEST_CASE ( defines_noarg3 ) ;
2010-09-08 17:02:22 +02:00
TEST_CASE ( defines ) ;
TEST_CASE ( defines2 ) ;
2010-09-08 17:42:28 +02:00
TEST_CASE ( defines3 ) ;
2012-09-14 06:58:14 +02:00
TEST_CASE ( defines4 ) ;
2012-09-10 18:51:32 +02:00
TEST_CASE ( enforceLanguage ) ;
2010-09-08 17:02:22 +02:00
TEST_CASE ( includesnopath ) ;
TEST_CASE ( includes ) ;
2011-01-11 20:03:18 +01:00
TEST_CASE ( includesslash ) ;
TEST_CASE ( includesbackslash ) ;
TEST_CASE ( includesnospace ) ;
2010-09-08 17:02:22 +02:00
TEST_CASE ( includes2 ) ;
2011-10-22 21:24:23 +02:00
TEST_CASE ( includesFile ) ;
2022-09-17 18:50:25 +02:00
TEST_CASE ( includesFileNoFile ) ;
2018-09-04 16:37:43 +02:00
TEST_CASE ( configExcludesFile ) ;
2022-09-17 18:50:25 +02:00
TEST_CASE ( configExcludesFileNoFile ) ;
2010-12-04 13:13:44 +01:00
TEST_CASE ( enabledAll ) ;
TEST_CASE ( enabledStyle ) ;
2011-09-04 20:42:35 +02:00
TEST_CASE ( enabledPerformance ) ;
TEST_CASE ( enabledPortability ) ;
2010-12-04 13:13:44 +01:00
TEST_CASE ( enabledUnusedFunction ) ;
TEST_CASE ( enabledMissingInclude ) ;
2014-05-18 19:48:43 +02:00
# ifdef CHECK_INTERNAL
2011-10-28 22:39:46 +02:00
TEST_CASE ( enabledInternal ) ;
2011-10-29 12:47:12 +02:00
# endif
2013-04-01 13:15:05 +02:00
TEST_CASE ( enabledMultiple ) ;
2023-01-21 10:39:44 +01:00
TEST_CASE ( enabledInvalid ) ;
TEST_CASE ( enabledError ) ;
TEST_CASE ( enabledEmpty ) ;
TEST_CASE ( disableAll ) ;
TEST_CASE ( disableMultiple ) ;
TEST_CASE ( disableStylePartial ) ;
TEST_CASE ( disableInvalid ) ;
TEST_CASE ( disableError ) ;
TEST_CASE ( disableEmpty ) ;
2013-08-15 11:09:40 +02:00
TEST_CASE ( inconclusive ) ;
2010-12-04 13:13:44 +01:00
TEST_CASE ( errorExitcode ) ;
TEST_CASE ( errorExitcodeMissing ) ;
TEST_CASE ( errorExitcodeStr ) ;
2022-09-17 18:50:25 +02:00
TEST_CASE ( exitcodeSuppressionsOld ) ;
2011-01-29 18:04:52 +01:00
TEST_CASE ( exitcodeSuppressions ) ;
TEST_CASE ( exitcodeSuppressionsNoFile ) ;
2022-12-19 22:28:36 +01:00
TEST_CASE ( fileList ) ;
TEST_CASE ( fileListNoFile ) ;
2011-09-30 07:35:23 +02:00
// TEST_CASE(fileListStdin); // Disabled since hangs the test run
2022-09-17 18:50:25 +02:00
TEST_CASE ( fileListInvalid ) ;
2010-12-04 13:13:44 +01:00
TEST_CASE ( inlineSuppr ) ;
TEST_CASE ( jobs ) ;
TEST_CASE ( jobsMissingCount ) ;
TEST_CASE ( jobsInvalid ) ;
2011-10-05 07:37:43 +02:00
TEST_CASE ( maxConfigs ) ;
TEST_CASE ( maxConfigsMissingCount ) ;
TEST_CASE ( maxConfigsInvalid ) ;
TEST_CASE ( maxConfigsTooSmall ) ;
2011-09-17 16:55:59 +02:00
TEST_CASE ( reportProgressTest ) ; // "Test" suffix to avoid hiding the parent's reportProgress
2011-10-06 08:10:51 +02:00
TEST_CASE ( stdc99 ) ;
2011-10-16 12:54:58 +02:00
TEST_CASE ( stdcpp11 ) ;
2022-04-15 16:17:36 +02:00
TEST_CASE ( stdunknown ) ;
2022-09-17 18:50:25 +02:00
TEST_CASE ( platformWin64 ) ;
TEST_CASE ( platformWin32A ) ;
TEST_CASE ( platformWin32W ) ;
TEST_CASE ( platformUnix32 ) ;
2023-01-26 22:05:40 +01:00
TEST_CASE ( platformUnix32Unsigned ) ;
2022-09-17 18:50:25 +02:00
TEST_CASE ( platformUnix64 ) ;
2023-01-26 22:05:40 +01:00
TEST_CASE ( platformUnix64Unsigned ) ;
2022-09-17 18:50:25 +02:00
TEST_CASE ( platformNative ) ;
TEST_CASE ( platformUnspecified ) ;
2023-01-26 22:05:40 +01:00
TEST_CASE ( platformPlatformFile ) ;
2022-09-17 18:50:25 +02:00
TEST_CASE ( platformUnknown ) ;
2023-01-27 10:46:48 +01:00
# if defined(_WIN64) || defined(_WIN32)
TEST_CASE ( platformDefault ) ;
TEST_CASE ( platformDefault2 ) ;
# endif
2020-11-13 15:52:24 +01:00
TEST_CASE ( plistEmpty ) ;
TEST_CASE ( plistDoesNotExist ) ;
2022-09-17 18:50:25 +02:00
TEST_CASE ( suppressionsOld ) ;
2011-07-29 21:00:24 +02:00
TEST_CASE ( suppressions ) ;
TEST_CASE ( suppressionsNoFile ) ;
TEST_CASE ( suppressionSingle ) ;
TEST_CASE ( suppressionSingleFile ) ;
2011-09-13 16:55:00 +02:00
TEST_CASE ( suppressionTwo ) ;
TEST_CASE ( suppressionTwoSeparate ) ;
2010-12-04 13:13:44 +01:00
TEST_CASE ( templates ) ;
TEST_CASE ( templatesGcc ) ;
TEST_CASE ( templatesVs ) ;
2011-10-29 23:26:35 +02:00
TEST_CASE ( templatesEdit ) ;
2010-12-04 13:13:44 +01:00
TEST_CASE ( xml ) ;
2011-01-27 13:25:10 +01:00
TEST_CASE ( xmlver2 ) ;
TEST_CASE ( xmlver2both ) ;
TEST_CASE ( xmlver2both2 ) ;
2011-02-02 12:33:57 +01:00
TEST_CASE ( xmlverunknown ) ;
TEST_CASE ( xmlverinvalid ) ;
2013-08-15 11:09:40 +02:00
TEST_CASE ( doc ) ;
TEST_CASE ( showtime ) ;
2011-01-27 10:14:08 +01:00
TEST_CASE ( errorlist1 ) ;
2011-07-29 21:00:24 +02:00
TEST_CASE ( errorlistverbose1 ) ;
TEST_CASE ( errorlistverbose2 ) ;
TEST_CASE ( ignorepathsnopath ) ;
2022-08-20 20:54:31 +02:00
TEST_CASE ( exceptionhandling ) ;
TEST_CASE ( exceptionhandling2 ) ;
TEST_CASE ( exceptionhandling3 ) ;
TEST_CASE ( exceptionhandlingInvalid ) ;
TEST_CASE ( exceptionhandlingInvalid2 ) ;
TEST_CASE ( clang ) ;
TEST_CASE ( clang2 ) ;
TEST_CASE ( clangInvalid ) ;
2022-12-20 20:51:08 +01:00
TEST_CASE ( valueFlowMaxIterations ) ;
TEST_CASE ( valueFlowMaxIterations2 ) ;
TEST_CASE ( valueFlowMaxIterationsInvalid ) ;
TEST_CASE ( valueFlowMaxIterationsInvalid2 ) ;
TEST_CASE ( valueFlowMaxIterationsInvalid3 ) ;
2011-08-06 18:18:20 +02:00
2023-01-01 15:32:37 +01:00
TEST_CASE ( ignorepaths1 ) ;
TEST_CASE ( ignorepaths2 ) ;
TEST_CASE ( ignorepaths3 ) ;
TEST_CASE ( ignorepaths4 ) ;
TEST_CASE ( ignorefilepaths1 ) ;
TEST_CASE ( ignorefilepaths2 ) ;
2011-08-06 18:18:20 +02:00
2011-07-29 21:00:24 +02:00
TEST_CASE ( checkconfig ) ;
2010-12-04 13:13:44 +01:00
TEST_CASE ( unknownParam ) ;
2011-11-30 20:24:01 +01:00
TEST_CASE ( undefs_noarg ) ;
TEST_CASE ( undefs_noarg2 ) ;
TEST_CASE ( undefs_noarg3 ) ;
TEST_CASE ( undefs ) ;
TEST_CASE ( undefs2 ) ;
2010-09-06 21:31:06 +02:00
}
2010-12-04 13:13:44 +01:00
2014-11-20 14:20:09 +01:00
void nooptions ( ) {
2010-09-06 21:31:06 +02:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " } ;
2010-09-06 21:31:06 +02:00
CmdLineParser parser ( & settings ) ;
2018-04-23 12:39:47 +02:00
ASSERT ( parser . parseFromArgs ( 1 , argv ) ) ;
ASSERT_EQUALS ( true , parser . getShowHelp ( ) ) ;
2022-09-17 18:50:25 +02:00
ASSERT ( GET_REDIRECT_OUTPUT . find ( " Cppcheck - A tool for static C/C++ code analysis " ) = = 0 ) ;
2010-09-06 21:31:06 +02:00
}
2014-11-20 14:20:09 +01:00
void helpshort ( ) {
2010-09-06 21:31:06 +02:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " -h " } ;
2010-09-06 21:31:06 +02:00
CmdLineParser parser ( & settings ) ;
2018-04-23 12:39:47 +02:00
ASSERT ( parser . parseFromArgs ( 2 , argv ) ) ;
ASSERT_EQUALS ( true , parser . getShowHelp ( ) ) ;
2022-09-17 18:50:25 +02:00
ASSERT ( GET_REDIRECT_OUTPUT . find ( " Cppcheck - A tool for static C/C++ code analysis " ) = = 0 ) ;
2010-09-06 21:31:06 +02:00
}
2014-11-20 14:20:09 +01:00
void helplong ( ) {
2010-09-06 21:31:06 +02:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " --help " } ;
2010-09-06 21:31:06 +02:00
CmdLineParser parser ( & settings ) ;
2018-04-23 12:39:47 +02:00
ASSERT ( parser . parseFromArgs ( 2 , argv ) ) ;
ASSERT_EQUALS ( true , parser . getShowHelp ( ) ) ;
2022-09-17 18:50:25 +02:00
ASSERT ( GET_REDIRECT_OUTPUT . find ( " Cppcheck - A tool for static C/C++ code analysis " ) = = 0 ) ;
2010-09-06 21:31:06 +02:00
}
2014-11-20 14:20:09 +01:00
void showversion ( ) {
2010-09-06 21:31:06 +02:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " --version " } ;
2010-09-06 21:31:06 +02:00
CmdLineParser parser ( & settings ) ;
2018-04-23 12:39:47 +02:00
ASSERT ( parser . parseFromArgs ( 2 , argv ) ) ;
ASSERT_EQUALS ( true , parser . getShowVersion ( ) ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ; // version is not actually shown
2010-09-06 21:31:06 +02:00
}
2010-09-06 22:16:52 +02:00
2014-11-20 14:20:09 +01:00
void onefile ( ) {
2010-09-06 22:16:52 +02:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " file.cpp " } ;
2010-09-06 22:16:52 +02:00
CmdLineParser parser ( & settings ) ;
2018-04-23 12:39:47 +02:00
ASSERT ( parser . parseFromArgs ( 2 , argv ) ) ;
ASSERT_EQUALS ( 1 , ( int ) parser . getPathNames ( ) . size ( ) ) ;
ASSERT_EQUALS ( " file.cpp " , parser . getPathNames ( ) . at ( 0 ) ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2010-09-06 22:16:52 +02:00
}
2014-11-20 14:20:09 +01:00
void onepath ( ) {
2010-09-06 22:16:52 +02:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " src " } ;
2010-09-06 22:16:52 +02:00
CmdLineParser parser ( & settings ) ;
2018-04-23 12:39:47 +02:00
ASSERT ( parser . parseFromArgs ( 2 , argv ) ) ;
ASSERT_EQUALS ( 1 , ( int ) parser . getPathNames ( ) . size ( ) ) ;
ASSERT_EQUALS ( " src " , parser . getPathNames ( ) . at ( 0 ) ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2010-09-06 22:16:52 +02:00
}
2014-11-20 14:20:09 +01:00
void optionwithoutfile ( ) {
2010-09-06 22:16:52 +02:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " -v " } ;
2010-09-06 22:16:52 +02:00
CmdLineParser parser ( & settings ) ;
2018-04-23 12:39:47 +02:00
ASSERT_EQUALS ( false , parser . parseFromArgs ( 2 , argv ) ) ;
ASSERT_EQUALS ( 0 , ( int ) parser . getPathNames ( ) . size ( ) ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " cppcheck: error: no C or C++ source files found. \n " , GET_REDIRECT_OUTPUT ) ;
2010-09-06 22:16:52 +02:00
}
2014-11-20 14:20:09 +01:00
void verboseshort ( ) {
2010-09-06 22:16:52 +02:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " -v " , " file.cpp " } ;
2016-01-03 16:18:17 +01:00
settings . verbose = false ;
2018-04-23 12:39:47 +02:00
ASSERT ( defParser . parseFromArgs ( 3 , argv ) ) ;
2016-01-03 16:18:17 +01:00
ASSERT_EQUALS ( true , settings . verbose ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2010-09-06 22:16:52 +02:00
}
2014-11-20 14:20:09 +01:00
void verboselong ( ) {
2010-09-06 22:16:52 +02:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " --verbose " , " file.cpp " } ;
2016-01-03 16:18:17 +01:00
settings . verbose = false ;
2018-04-23 12:39:47 +02:00
ASSERT ( defParser . parseFromArgs ( 3 , argv ) ) ;
2016-01-03 16:18:17 +01:00
ASSERT_EQUALS ( true , settings . verbose ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2010-09-06 22:16:52 +02:00
}
2020-05-30 11:23:22 +02:00
void debugSimplified ( ) {
REDIRECT ;
const char * const argv [ ] = { " cppcheck " , " --debug-simplified " , " file.cpp " } ;
settings . debugSimplified = false ;
ASSERT ( defParser . parseFromArgs ( 3 , argv ) ) ;
ASSERT_EQUALS ( true , settings . debugSimplified ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2020-05-30 11:23:22 +02:00
}
2014-11-20 14:20:09 +01:00
void debugwarnings ( ) {
2010-09-06 22:16:52 +02:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " --debug-warnings " , " file.cpp " } ;
2013-04-01 13:12:56 +02:00
settings . debugwarnings = false ;
2018-04-23 12:39:47 +02:00
ASSERT ( defParser . parseFromArgs ( 3 , argv ) ) ;
2010-09-06 22:16:52 +02:00
ASSERT_EQUALS ( true , settings . debugwarnings ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2010-09-06 22:16:52 +02:00
}
2014-11-20 14:20:09 +01:00
void forceshort ( ) {
2010-09-06 22:16:52 +02:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " -f " , " file.cpp " } ;
2016-01-03 16:18:17 +01:00
settings . force = false ;
2018-04-23 12:39:47 +02:00
ASSERT ( defParser . parseFromArgs ( 3 , argv ) ) ;
2016-01-03 16:18:17 +01:00
ASSERT_EQUALS ( true , settings . force ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2010-09-06 22:16:52 +02:00
}
2014-11-20 14:20:09 +01:00
void forcelong ( ) {
2010-09-06 22:16:52 +02:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " --force " , " file.cpp " } ;
2016-01-03 16:18:17 +01:00
settings . force = false ;
2018-04-23 12:39:47 +02:00
ASSERT ( defParser . parseFromArgs ( 3 , argv ) ) ;
2016-01-03 16:18:17 +01:00
ASSERT_EQUALS ( true , settings . force ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2010-09-06 22:16:52 +02:00
}
2014-11-20 14:20:09 +01:00
void relativePaths ( ) {
2012-04-06 10:49:21 +02:00
REDIRECT ;
2016-01-03 16:18:17 +01:00
settings . relativePaths = false ;
2012-04-06 10:49:21 +02:00
2018-09-24 15:08:16 +02:00
const char * const argvs [ ] = { " cppcheck " , " -rp " , " file.cpp " } ;
2018-04-23 12:39:47 +02:00
ASSERT ( defParser . parseFromArgs ( 3 , argvs ) ) ;
2016-01-03 16:18:17 +01:00
ASSERT_EQUALS ( true , settings . relativePaths ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2012-04-06 10:49:21 +02:00
2022-09-17 18:50:25 +02:00
CLEAR_REDIRECT_OUTPUT ;
2016-01-03 16:18:17 +01:00
settings . relativePaths = false ;
2012-04-06 10:49:21 +02:00
2018-09-24 15:08:16 +02:00
const char * const argvl [ ] = { " cppcheck " , " --relative-paths " , " file.cpp " } ;
2018-04-23 12:39:47 +02:00
ASSERT ( defParser . parseFromArgs ( 3 , argvl ) ) ;
2016-01-03 16:18:17 +01:00
ASSERT_EQUALS ( true , settings . relativePaths ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2012-04-06 10:49:21 +02:00
2022-09-17 18:50:25 +02:00
CLEAR_REDIRECT_OUTPUT ;
2016-01-03 16:18:17 +01:00
settings . relativePaths = false ;
settings . basePaths . clear ( ) ;
2012-04-06 10:49:21 +02:00
2018-09-24 15:08:16 +02:00
const char * const argvsp [ ] = { " cppcheck " , " -rp=C:/foo;C: \\ bar " , " file.cpp " } ;
2018-04-23 12:39:47 +02:00
ASSERT ( defParser . parseFromArgs ( 3 , argvsp ) ) ;
2016-01-03 16:18:17 +01:00
ASSERT_EQUALS ( true , settings . relativePaths ) ;
ASSERT_EQUALS ( 2 , settings . basePaths . size ( ) ) ;
ASSERT_EQUALS ( " C:/foo " , settings . basePaths [ 0 ] ) ;
ASSERT_EQUALS ( " C:/bar " , settings . basePaths [ 1 ] ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2012-04-06 10:49:21 +02:00
2022-09-17 18:50:25 +02:00
CLEAR_REDIRECT_OUTPUT ;
2016-01-03 16:18:17 +01:00
settings . relativePaths = false ;
settings . basePaths . clear ( ) ;
2012-04-06 10:49:21 +02:00
2018-09-24 15:08:16 +02:00
const char * const argvlp [ ] = { " cppcheck " , " --relative-paths=C:/foo;C: \\ bar " , " file.cpp " } ;
2018-04-23 12:39:47 +02:00
ASSERT ( defParser . parseFromArgs ( 3 , argvlp ) ) ;
2016-01-03 16:18:17 +01:00
ASSERT_EQUALS ( true , settings . relativePaths ) ;
ASSERT_EQUALS ( 2 , settings . basePaths . size ( ) ) ;
ASSERT_EQUALS ( " C:/foo " , settings . basePaths [ 0 ] ) ;
ASSERT_EQUALS ( " C:/bar " , settings . basePaths [ 1 ] ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2012-04-06 10:49:21 +02:00
}
2014-11-20 14:20:09 +01:00
void quietshort ( ) {
2010-09-06 22:16:52 +02:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " -q " , " file.cpp " } ;
2015-07-25 17:39:44 +02:00
settings . quiet = false ;
2018-04-23 12:39:47 +02:00
ASSERT ( defParser . parseFromArgs ( 3 , argv ) ) ;
2015-07-25 17:39:44 +02:00
ASSERT_EQUALS ( true , settings . quiet ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2010-09-06 22:16:52 +02:00
}
2014-11-20 14:20:09 +01:00
void quietlong ( ) {
2010-09-06 22:16:52 +02:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " --quiet " , " file.cpp " } ;
2015-07-25 17:39:44 +02:00
settings . quiet = false ;
2018-04-23 12:39:47 +02:00
ASSERT ( defParser . parseFromArgs ( 3 , argv ) ) ;
2015-07-25 17:39:44 +02:00
ASSERT_EQUALS ( true , settings . quiet ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2010-09-06 22:16:52 +02:00
}
2010-09-08 17:02:22 +02:00
2014-11-20 14:20:09 +01:00
void defines_noarg ( ) {
2011-01-17 20:03:22 +01:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " -D " } ;
2011-05-04 20:00:22 +02:00
// Fails since -D has no param
2018-04-23 12:39:47 +02:00
ASSERT_EQUALS ( false , defParser . parseFromArgs ( 2 , argv ) ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " cppcheck: error: argument to '-D' is missing. \n " , GET_REDIRECT_OUTPUT ) ;
2011-01-17 20:03:22 +01:00
}
2014-11-20 14:20:09 +01:00
void defines_noarg2 ( ) {
2011-01-17 20:19:27 +01:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " -D " , " -v " , " file.cpp " } ;
2011-05-04 20:00:22 +02:00
// Fails since -D has no param
2018-04-23 12:39:47 +02:00
ASSERT_EQUALS ( false , defParser . parseFromArgs ( 4 , argv ) ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " cppcheck: error: argument to '-D' is missing. \n " , GET_REDIRECT_OUTPUT ) ;
2011-01-17 20:19:27 +01:00
}
2014-11-20 14:20:09 +01:00
void defines_noarg3 ( ) {
2011-01-17 20:19:27 +01:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " -D " , " --quiet " , " file.cpp " } ;
2011-05-04 20:00:22 +02:00
// Fails since -D has no param
2018-04-23 12:39:47 +02:00
ASSERT_EQUALS ( false , defParser . parseFromArgs ( 4 , argv ) ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " cppcheck: error: argument to '-D' is missing. \n " , GET_REDIRECT_OUTPUT ) ;
2011-01-17 20:19:27 +01:00
}
2014-11-20 14:20:09 +01:00
void defines ( ) {
2010-09-08 17:02:22 +02:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " -D_WIN32 " , " file.cpp " } ;
2013-04-01 13:12:56 +02:00
settings . userDefines . clear ( ) ;
2018-04-23 12:39:47 +02:00
ASSERT ( defParser . parseFromArgs ( 3 , argv ) ) ;
2012-07-05 19:35:41 +02:00
ASSERT_EQUALS ( " _WIN32=1 " , settings . userDefines ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2010-09-08 17:02:22 +02:00
}
2014-11-20 14:20:09 +01:00
void defines2 ( ) {
2010-09-08 17:02:22 +02:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " -D_WIN32 " , " -DNODEBUG " , " file.cpp " } ;
2020-04-21 17:27:51 +02:00
settings . userDefines . clear ( ) ;
2018-04-23 12:39:47 +02:00
ASSERT ( defParser . parseFromArgs ( 4 , argv ) ) ;
2012-07-05 19:35:41 +02:00
ASSERT_EQUALS ( " _WIN32=1;NODEBUG=1 " , settings . userDefines ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2010-09-08 17:02:22 +02:00
}
2010-09-08 17:42:28 +02:00
2014-11-20 14:20:09 +01:00
void defines3 ( ) {
2010-09-08 17:42:28 +02:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " -D " , " DEBUG " , " file.cpp " } ;
2013-04-01 13:12:56 +02:00
settings . userDefines . clear ( ) ;
2018-04-23 12:39:47 +02:00
ASSERT ( defParser . parseFromArgs ( 4 , argv ) ) ;
2012-07-05 19:35:41 +02:00
ASSERT_EQUALS ( " DEBUG=1 " , settings . userDefines ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2012-07-05 19:35:41 +02:00
}
2014-11-20 14:20:09 +01:00
void defines4 ( ) {
2012-07-05 19:35:41 +02:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " -DDEBUG= " , " file.cpp " } ; // #5137 - defining empty macro
2013-04-01 13:12:56 +02:00
settings . userDefines . clear ( ) ;
2018-04-23 12:39:47 +02:00
ASSERT ( defParser . parseFromArgs ( 3 , argv ) ) ;
2013-11-03 09:46:03 +01:00
ASSERT_EQUALS ( " DEBUG= " , settings . userDefines ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2010-09-08 17:42:28 +02:00
}
2010-09-08 17:02:22 +02:00
2014-11-20 14:20:09 +01:00
void enforceLanguage ( ) {
2012-09-10 18:51:32 +02:00
REDIRECT ;
{
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " file.cpp " } ;
2022-11-20 12:29:56 +01:00
settings . enforcedLang = Settings : : Language : : None ;
2018-04-23 12:39:47 +02:00
ASSERT ( defParser . parseFromArgs ( 2 , argv ) ) ;
2022-11-20 12:29:56 +01:00
ASSERT_EQUALS ( Settings : : Language : : None , settings . enforcedLang ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2012-09-10 18:51:32 +02:00
}
2022-09-17 18:50:25 +02:00
CLEAR_REDIRECT_OUTPUT ;
2012-09-10 18:51:32 +02:00
{
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " -x " , " c++ " , " file.cpp " } ;
2022-11-20 12:29:56 +01:00
settings . enforcedLang = Settings : : Language : : None ;
2018-04-23 12:39:47 +02:00
ASSERT ( defParser . parseFromArgs ( 4 , argv ) ) ;
2022-11-20 12:29:56 +01:00
ASSERT_EQUALS ( Settings : : Language : : CPP , settings . enforcedLang ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2012-09-10 18:51:32 +02:00
}
2022-09-17 18:50:25 +02:00
CLEAR_REDIRECT_OUTPUT ;
2012-09-10 18:51:32 +02:00
{
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " -x " } ;
2018-04-23 12:39:47 +02:00
ASSERT ( ! defParser . parseFromArgs ( 2 , argv ) ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " cppcheck: error: no language given to '-x' option. \n " , GET_REDIRECT_OUTPUT ) ;
2012-09-10 18:51:32 +02:00
}
2022-09-17 18:50:25 +02:00
CLEAR_REDIRECT_OUTPUT ;
2012-09-10 18:51:32 +02:00
{
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " -x " , " --inconclusive " , " file.cpp " } ;
2018-04-23 12:39:47 +02:00
ASSERT ( ! defParser . parseFromArgs ( 4 , argv ) ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " cppcheck: error: no language given to '-x' option. \n " , GET_REDIRECT_OUTPUT ) ;
2012-09-10 18:51:32 +02:00
}
2022-09-17 18:50:25 +02:00
CLEAR_REDIRECT_OUTPUT ;
2012-09-10 18:51:32 +02:00
{
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " --language=c++ " , " file.cpp " } ;
2022-11-20 12:29:56 +01:00
settings . enforcedLang = Settings : : Language : : None ;
2018-04-23 12:39:47 +02:00
ASSERT ( defParser . parseFromArgs ( 3 , argv ) ) ;
2022-11-20 12:29:56 +01:00
ASSERT_EQUALS ( Settings : : Language : : CPP , settings . enforcedLang ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2012-09-10 18:51:32 +02:00
}
2022-09-17 18:50:25 +02:00
CLEAR_REDIRECT_OUTPUT ;
2012-09-10 18:51:32 +02:00
{
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " --language=c " , " file.cpp " } ;
2022-11-20 12:29:56 +01:00
settings . enforcedLang = Settings : : Language : : None ;
2018-04-23 12:39:47 +02:00
ASSERT ( defParser . parseFromArgs ( 3 , argv ) ) ;
2022-11-20 12:29:56 +01:00
ASSERT_EQUALS ( Settings : : Language : : C , settings . enforcedLang ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2012-09-10 18:51:32 +02:00
}
2022-09-17 18:50:25 +02:00
CLEAR_REDIRECT_OUTPUT ;
2012-09-10 18:51:32 +02:00
{
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " --language=unknownLanguage " , " file.cpp " } ;
2018-04-23 12:39:47 +02:00
ASSERT ( ! defParser . parseFromArgs ( 3 , argv ) ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " cppcheck: error: unknown language 'unknownLanguage' enforced. \n " , GET_REDIRECT_OUTPUT ) ;
2012-09-10 18:51:32 +02:00
}
}
2014-11-20 14:20:09 +01:00
void includesnopath ( ) {
2010-09-08 17:02:22 +02:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " -I " } ;
2013-08-08 15:50:45 +02:00
// Fails since -I has no param
2018-04-23 12:39:47 +02:00
ASSERT_EQUALS ( false , defParser . parseFromArgs ( 2 , argv ) ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " cppcheck: error: argument to '-I' is missing. \n " , GET_REDIRECT_OUTPUT ) ;
2010-09-08 17:02:22 +02:00
}
2014-11-20 14:20:09 +01:00
void includes ( ) {
2010-09-08 17:02:22 +02:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " -I " , " include " , " file.cpp " } ;
2016-01-03 16:18:17 +01:00
settings . includePaths . clear ( ) ;
2018-04-23 12:39:47 +02:00
ASSERT ( defParser . parseFromArgs ( 4 , argv ) ) ;
2016-01-03 16:18:17 +01:00
ASSERT_EQUALS ( " include/ " , settings . includePaths . front ( ) ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2010-09-08 17:02:22 +02:00
}
2014-11-20 14:20:09 +01:00
void includesslash ( ) {
2011-01-11 20:03:18 +01:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " -I " , " include/ " , " file.cpp " } ;
2016-01-03 16:18:17 +01:00
settings . includePaths . clear ( ) ;
2018-04-23 12:39:47 +02:00
ASSERT ( defParser . parseFromArgs ( 4 , argv ) ) ;
2016-01-03 16:18:17 +01:00
ASSERT_EQUALS ( " include/ " , settings . includePaths . front ( ) ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2011-01-11 20:03:18 +01:00
}
2014-11-20 14:20:09 +01:00
void includesbackslash ( ) {
2011-01-11 20:03:18 +01:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " -I " , " include \\ " , " file.cpp " } ;
2016-01-03 16:18:17 +01:00
settings . includePaths . clear ( ) ;
2018-04-23 12:39:47 +02:00
ASSERT ( defParser . parseFromArgs ( 4 , argv ) ) ;
2016-01-03 16:18:17 +01:00
ASSERT_EQUALS ( " include/ " , settings . includePaths . front ( ) ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2011-01-11 20:03:18 +01:00
}
2014-11-20 14:20:09 +01:00
void includesnospace ( ) {
2011-01-11 20:03:18 +01:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " -Iinclude " , " file.cpp " } ;
2016-01-03 16:18:17 +01:00
settings . includePaths . clear ( ) ;
2018-04-23 12:39:47 +02:00
ASSERT ( defParser . parseFromArgs ( 3 , argv ) ) ;
2016-01-03 16:18:17 +01:00
ASSERT_EQUALS ( " include/ " , settings . includePaths . front ( ) ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2011-01-11 20:03:18 +01:00
}
2014-11-20 14:20:09 +01:00
void includes2 ( ) {
2010-09-08 17:02:22 +02:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " -I " , " include/ " , " -I " , " framework/ " , " file.cpp " } ;
2016-01-03 16:18:17 +01:00
settings . includePaths . clear ( ) ;
2018-04-23 12:39:47 +02:00
ASSERT ( defParser . parseFromArgs ( 6 , argv ) ) ;
2016-01-03 16:18:17 +01:00
ASSERT_EQUALS ( " include/ " , settings . includePaths . front ( ) ) ;
settings . includePaths . pop_front ( ) ;
ASSERT_EQUALS ( " framework/ " , settings . includePaths . front ( ) ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2010-09-08 17:02:22 +02:00
}
2010-12-04 13:13:44 +01:00
2022-09-17 18:50:25 +02:00
// TODO: fails since the file is not found
2014-11-20 14:20:09 +01:00
void includesFile ( ) {
2022-09-17 18:50:25 +02:00
REDIRECT ;
const char * const argv [ ] = { " cppcheck " , " --includes-file=fileThatDoesNotExist.txt " , " file.cpp " } ;
TODO_ASSERT_EQUALS ( true , false , defParser . parseFromArgs ( 3 , argv ) ) ;
TODO_ASSERT_EQUALS ( " " , " cppcheck: error: unable to open includes file at 'fileThatDoesNotExist.txt' \n " , GET_REDIRECT_OUTPUT ) ;
}
void includesFileNoFile ( ) {
2011-10-22 21:24:23 +02:00
REDIRECT ;
2018-09-04 16:37:43 +02:00
const char * const argv [ ] = { " cppcheck " , " --includes-file=fileThatDoesNotExist.txt " , " file.cpp " } ;
ASSERT_EQUALS ( false , defParser . parseFromArgs ( 3 , argv ) ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " cppcheck: error: unable to open includes file at 'fileThatDoesNotExist.txt' \n " , GET_REDIRECT_OUTPUT ) ;
2018-09-04 16:37:43 +02:00
}
2022-09-17 18:50:25 +02:00
// TODO: fails since the file is not found
2018-09-04 16:37:43 +02:00
void configExcludesFile ( ) {
REDIRECT ;
const char * const argv [ ] = { " cppcheck " , " --config-excludes-file=fileThatDoesNotExist.txt " , " file.cpp " } ;
settings . includePaths . clear ( ) ;
2022-09-17 18:50:25 +02:00
TODO_ASSERT_EQUALS ( true , false , defParser . parseFromArgs ( 3 , argv ) ) ;
// TODO: add checks
TODO_ASSERT_EQUALS ( " " , " cppcheck: error: unable to open config excludes file at 'fileThatDoesNotExist.txt' \n " , GET_REDIRECT_OUTPUT ) ;
}
void configExcludesFileNoFile ( ) {
REDIRECT ;
const char * const argv [ ] = { " cppcheck " , " --config-excludes-file=fileThatDoesNotExist.txt " , " file.cpp " } ;
ASSERT_EQUALS ( false , defParser . parseFromArgs ( 3 , argv ) ) ;
ASSERT_EQUALS ( " cppcheck: error: unable to open config excludes file at 'fileThatDoesNotExist.txt' \n " , GET_REDIRECT_OUTPUT ) ;
2011-10-22 21:24:23 +02:00
}
2014-11-20 14:20:09 +01:00
void enabledAll ( ) {
2010-12-04 13:13:44 +01:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " --enable=all " , " file.cpp " } ;
2013-04-01 13:12:56 +02:00
settings = Settings ( ) ;
2018-04-23 12:39:47 +02:00
ASSERT ( defParser . parseFromArgs ( 3 , argv ) ) ;
2021-02-24 22:00:06 +01:00
ASSERT ( settings . severity . isEnabled ( Severity : : style ) ) ;
ASSERT ( settings . severity . isEnabled ( Severity : : warning ) ) ;
ASSERT ( settings . checks . isEnabled ( Checks : : unusedFunction ) ) ;
ASSERT ( settings . checks . isEnabled ( Checks : : missingInclude ) ) ;
ASSERT ( ! settings . checks . isEnabled ( Checks : : internalCheck ) ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2010-12-04 13:13:44 +01:00
}
2014-11-20 14:20:09 +01:00
void enabledStyle ( ) {
2010-12-04 13:13:44 +01:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " --enable=style " , " file.cpp " } ;
2013-04-01 13:12:56 +02:00
settings = Settings ( ) ;
2018-04-23 12:39:47 +02:00
ASSERT ( defParser . parseFromArgs ( 3 , argv ) ) ;
2021-02-24 22:00:06 +01:00
ASSERT ( settings . severity . isEnabled ( Severity : : style ) ) ;
ASSERT ( settings . severity . isEnabled ( Severity : : warning ) ) ;
ASSERT ( settings . severity . isEnabled ( Severity : : performance ) ) ;
ASSERT ( settings . severity . isEnabled ( Severity : : portability ) ) ;
ASSERT ( ! settings . checks . isEnabled ( Checks : : unusedFunction ) ) ;
ASSERT ( ! settings . checks . isEnabled ( Checks : : internalCheck ) ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2011-09-04 20:42:35 +02:00
}
2014-11-20 14:20:09 +01:00
void enabledPerformance ( ) {
2011-09-04 20:42:35 +02:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " --enable=performance " , " file.cpp " } ;
2013-04-01 13:12:56 +02:00
settings = Settings ( ) ;
2018-04-23 12:39:47 +02:00
ASSERT ( defParser . parseFromArgs ( 3 , argv ) ) ;
2021-02-24 22:00:06 +01:00
ASSERT ( ! settings . severity . isEnabled ( Severity : : style ) ) ;
ASSERT ( ! settings . severity . isEnabled ( Severity : : warning ) ) ;
ASSERT ( settings . severity . isEnabled ( Severity : : performance ) ) ;
ASSERT ( ! settings . severity . isEnabled ( Severity : : portability ) ) ;
ASSERT ( ! settings . checks . isEnabled ( Checks : : unusedFunction ) ) ;
ASSERT ( ! settings . checks . isEnabled ( Checks : : missingInclude ) ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2011-09-04 20:42:35 +02:00
}
2014-11-20 14:20:09 +01:00
void enabledPortability ( ) {
2011-09-04 20:42:35 +02:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " --enable=portability " , " file.cpp " } ;
2013-04-01 13:12:56 +02:00
settings = Settings ( ) ;
2018-04-23 12:39:47 +02:00
ASSERT ( defParser . parseFromArgs ( 3 , argv ) ) ;
2021-02-24 22:00:06 +01:00
ASSERT ( ! settings . severity . isEnabled ( Severity : : style ) ) ;
ASSERT ( ! settings . severity . isEnabled ( Severity : : warning ) ) ;
ASSERT ( ! settings . severity . isEnabled ( Severity : : performance ) ) ;
ASSERT ( settings . severity . isEnabled ( Severity : : portability ) ) ;
ASSERT ( ! settings . checks . isEnabled ( Checks : : unusedFunction ) ) ;
ASSERT ( ! settings . checks . isEnabled ( Checks : : missingInclude ) ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2010-12-04 13:13:44 +01:00
}
2014-11-20 14:20:09 +01:00
void enabledUnusedFunction ( ) {
2010-12-04 13:13:44 +01:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " --enable=unusedFunction " , " file.cpp " } ;
2013-04-01 13:12:56 +02:00
settings = Settings ( ) ;
2018-04-23 12:39:47 +02:00
ASSERT ( defParser . parseFromArgs ( 3 , argv ) ) ;
2021-02-24 22:00:06 +01:00
ASSERT ( settings . checks . isEnabled ( Checks : : unusedFunction ) ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2010-12-04 13:13:44 +01:00
}
2014-11-20 14:20:09 +01:00
void enabledMissingInclude ( ) {
2010-12-04 13:13:44 +01:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " --enable=missingInclude " , " file.cpp " } ;
2013-04-01 13:12:56 +02:00
settings = Settings ( ) ;
2018-04-23 12:39:47 +02:00
ASSERT ( defParser . parseFromArgs ( 3 , argv ) ) ;
2021-02-24 22:00:06 +01:00
ASSERT ( settings . checks . isEnabled ( Checks : : missingInclude ) ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2010-12-04 13:13:44 +01:00
}
2014-05-18 19:48:43 +02:00
# ifdef CHECK_INTERNAL
2014-11-20 14:20:09 +01:00
void enabledInternal ( ) {
2011-10-28 22:39:46 +02:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " --enable=internal " , " file.cpp " } ;
2013-04-01 13:12:56 +02:00
settings = Settings ( ) ;
2018-04-23 12:39:47 +02:00
ASSERT ( defParser . parseFromArgs ( 3 , argv ) ) ;
2021-02-24 22:31:46 +01:00
ASSERT ( settings . checks . isEnabled ( Checks : : internalCheck ) ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2011-10-28 22:39:46 +02:00
}
2011-10-29 12:47:12 +02:00
# endif
2011-10-28 22:39:46 +02:00
2014-11-20 14:20:09 +01:00
void enabledMultiple ( ) {
2013-04-01 13:15:05 +02:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " --enable=missingInclude,portability,warning " , " file.cpp " } ;
2013-04-01 13:15:05 +02:00
settings = Settings ( ) ;
2018-04-23 12:39:47 +02:00
ASSERT ( defParser . parseFromArgs ( 3 , argv ) ) ;
2021-02-24 22:00:06 +01:00
ASSERT ( ! settings . severity . isEnabled ( Severity : : style ) ) ;
ASSERT ( settings . severity . isEnabled ( Severity : : warning ) ) ;
ASSERT ( ! settings . severity . isEnabled ( Severity : : performance ) ) ;
ASSERT ( settings . severity . isEnabled ( Severity : : portability ) ) ;
ASSERT ( ! settings . checks . isEnabled ( Checks : : unusedFunction ) ) ;
ASSERT ( settings . checks . isEnabled ( Checks : : missingInclude ) ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2013-04-01 13:15:05 +02:00
}
2023-01-21 10:39:44 +01:00
void enabledInvalid ( ) {
REDIRECT ;
const char * const argv [ ] = { " cppcheck " , " --enable=warning,missingIncludeSystem,style " , " file.cpp " } ;
settings = Settings ( ) ;
ASSERT ( ! defParser . parseFromArgs ( 3 , argv ) ) ;
ASSERT_EQUALS ( " cppcheck: error: --enable parameter with the unknown name 'missingIncludeSystem' \n " , GET_REDIRECT_OUTPUT ) ;
}
void enabledError ( ) {
REDIRECT ;
const char * const argv [ ] = { " cppcheck " , " --enable=error " , " file.cpp " } ;
settings = Settings ( ) ;
ASSERT ( ! defParser . parseFromArgs ( 3 , argv ) ) ;
ASSERT_EQUALS ( " cppcheck: error: --enable parameter with the unknown name 'error' \n " , GET_REDIRECT_OUTPUT ) ;
}
void enabledEmpty ( ) {
REDIRECT ;
const char * const argv [ ] = { " cppcheck " , " --enable= " , " file.cpp " } ;
settings = Settings ( ) ;
ASSERT ( ! defParser . parseFromArgs ( 3 , argv ) ) ;
ASSERT_EQUALS ( " cppcheck: error: --enable parameter is empty \n " , GET_REDIRECT_OUTPUT ) ;
}
void disableAll ( ) {
REDIRECT ;
const char * const argv [ ] = { " cppcheck " , " --enable=all " , " --disable=all " } ;
settings . severity . clear ( ) ;
settings . checks . clear ( ) ;
ASSERT ( defParser . parseFromArgs ( 3 , argv ) ) ;
ASSERT_EQUALS ( true , settings . severity . isEnabled ( Severity : : error ) ) ;
ASSERT_EQUALS ( false , settings . severity . isEnabled ( Severity : : warning ) ) ;
ASSERT_EQUALS ( false , settings . severity . isEnabled ( Severity : : style ) ) ;
ASSERT_EQUALS ( false , settings . severity . isEnabled ( Severity : : performance ) ) ;
ASSERT_EQUALS ( false , settings . severity . isEnabled ( Severity : : portability ) ) ;
ASSERT_EQUALS ( false , settings . severity . isEnabled ( Severity : : debug ) ) ;
ASSERT_EQUALS ( false , settings . checks . isEnabled ( Checks : : unusedFunction ) ) ;
ASSERT_EQUALS ( false , settings . checks . isEnabled ( Checks : : missingInclude ) ) ;
ASSERT_EQUALS ( false , settings . checks . isEnabled ( Checks : : internalCheck ) ) ;
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
}
void disableMultiple ( ) {
REDIRECT ;
const char * const argv [ ] = { " cppcheck " , " --enable=all " , " --disable=style " , " --disable=unusedFunction " } ;
settings . severity . clear ( ) ;
settings . checks . clear ( ) ;
ASSERT ( defParser . parseFromArgs ( 4 , argv ) ) ;
ASSERT_EQUALS ( true , settings . severity . isEnabled ( Severity : : error ) ) ;
ASSERT_EQUALS ( true , settings . severity . isEnabled ( Severity : : warning ) ) ;
ASSERT_EQUALS ( false , settings . severity . isEnabled ( Severity : : style ) ) ;
ASSERT_EQUALS ( true , settings . severity . isEnabled ( Severity : : performance ) ) ;
ASSERT_EQUALS ( true , settings . severity . isEnabled ( Severity : : portability ) ) ;
ASSERT_EQUALS ( true , settings . severity . isEnabled ( Severity : : debug ) ) ;
ASSERT_EQUALS ( false , settings . checks . isEnabled ( Checks : : unusedFunction ) ) ;
ASSERT_EQUALS ( true , settings . checks . isEnabled ( Checks : : missingInclude ) ) ;
ASSERT_EQUALS ( false , settings . checks . isEnabled ( Checks : : internalCheck ) ) ;
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
}
// make sure the implied "style" checks are not added when "--enable=style" is specified
void disableStylePartial ( ) {
REDIRECT ;
const char * const argv [ ] = { " cppcheck " , " --enable=style " , " --disable=performance " , " --enable=unusedFunction " } ;
settings . severity . clear ( ) ;
settings . checks . clear ( ) ;
ASSERT ( defParser . parseFromArgs ( 4 , argv ) ) ;
ASSERT_EQUALS ( true , settings . severity . isEnabled ( Severity : : error ) ) ;
ASSERT_EQUALS ( true , settings . severity . isEnabled ( Severity : : warning ) ) ;
ASSERT_EQUALS ( true , settings . severity . isEnabled ( Severity : : style ) ) ;
ASSERT_EQUALS ( false , settings . severity . isEnabled ( Severity : : performance ) ) ;
ASSERT_EQUALS ( true , settings . severity . isEnabled ( Severity : : portability ) ) ;
ASSERT_EQUALS ( false , settings . severity . isEnabled ( Severity : : debug ) ) ;
ASSERT_EQUALS ( true , settings . checks . isEnabled ( Checks : : unusedFunction ) ) ;
ASSERT_EQUALS ( false , settings . checks . isEnabled ( Checks : : missingInclude ) ) ;
ASSERT_EQUALS ( false , settings . checks . isEnabled ( Checks : : internalCheck ) ) ;
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
}
void disableInvalid ( ) {
REDIRECT ;
const char * const argv [ ] = { " cppcheck " , " --disable=leaks " , " file.cpp " } ;
settings = Settings ( ) ;
ASSERT ( ! defParser . parseFromArgs ( 3 , argv ) ) ;
ASSERT_EQUALS ( " cppcheck: error: --disable parameter with the unknown name 'leaks' \n " , GET_REDIRECT_OUTPUT ) ;
}
void disableError ( ) {
REDIRECT ;
const char * const argv [ ] = { " cppcheck " , " --disable=error " , " file.cpp " } ;
settings = Settings ( ) ;
ASSERT ( ! defParser . parseFromArgs ( 3 , argv ) ) ;
ASSERT_EQUALS ( " cppcheck: error: --disable parameter with the unknown name 'error' \n " , GET_REDIRECT_OUTPUT ) ;
}
void disableEmpty ( ) {
REDIRECT ;
const char * const argv [ ] = { " cppcheck " , " --disable= " , " file.cpp " } ;
settings = Settings ( ) ;
ASSERT ( ! defParser . parseFromArgs ( 3 , argv ) ) ;
ASSERT_EQUALS ( " cppcheck: error: --disable parameter is empty \n " , GET_REDIRECT_OUTPUT ) ;
}
2014-11-20 14:20:09 +01:00
void inconclusive ( ) {
2013-08-15 11:09:40 +02:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " --inconclusive " } ;
2021-02-24 22:00:06 +01:00
settings . certainty . clear ( ) ;
2018-04-23 12:39:47 +02:00
ASSERT ( defParser . parseFromArgs ( 2 , argv ) ) ;
2021-02-24 22:00:06 +01:00
ASSERT_EQUALS ( true , settings . certainty . isEnabled ( Certainty : : inconclusive ) ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2013-08-15 11:09:40 +02:00
}
2014-11-20 14:20:09 +01:00
void errorExitcode ( ) {
2010-12-04 13:13:44 +01:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " --error-exitcode=5 " , " file.cpp " } ;
2016-01-03 16:18:17 +01:00
settings . exitCode = 0 ;
2018-04-23 12:39:47 +02:00
ASSERT ( defParser . parseFromArgs ( 3 , argv ) ) ;
2016-01-03 16:18:17 +01:00
ASSERT_EQUALS ( 5 , settings . exitCode ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2010-12-04 13:13:44 +01:00
}
2014-11-20 14:20:09 +01:00
void errorExitcodeMissing ( ) {
2010-12-04 13:13:44 +01:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " --error-exitcode= " , " file.cpp " } ;
2011-05-04 20:00:22 +02:00
// Fails since exit code not given
2018-04-23 12:39:47 +02:00
ASSERT_EQUALS ( false , defParser . parseFromArgs ( 3 , argv ) ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " cppcheck: error: argument must be an integer. Try something like '--error-exitcode=1'. \n " , GET_REDIRECT_OUTPUT ) ;
2010-12-04 13:13:44 +01:00
}
2014-11-20 14:20:09 +01:00
void errorExitcodeStr ( ) {
2010-12-04 13:13:44 +01:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " --error-exitcode=foo " , " file.cpp " } ;
2011-05-04 20:00:22 +02:00
// Fails since invalid exit code
2018-04-23 12:39:47 +02:00
ASSERT_EQUALS ( false , defParser . parseFromArgs ( 3 , argv ) ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " cppcheck: error: argument must be an integer. Try something like '--error-exitcode=1'. \n " , GET_REDIRECT_OUTPUT ) ;
2010-12-04 13:13:44 +01:00
}
2014-11-20 14:20:09 +01:00
void exitcodeSuppressionsOld ( ) {
2011-01-29 18:04:52 +01:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " --exitcode-suppressions " , " suppr.txt " , " file.cpp " } ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( false , defParser . parseFromArgs ( 4 , argv ) ) ;
ASSERT_EQUALS ( " cppcheck: error: unrecognized command line option: \" --exitcode-suppressions \" . \n " , GET_REDIRECT_OUTPUT ) ;
2011-01-29 18:04:52 +01:00
}
2014-11-20 14:20:09 +01:00
void exitcodeSuppressions ( ) {
2011-05-04 20:00:22 +02:00
// TODO: Fails since cannot open the file
2010-12-04 13:13:44 +01:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " --exitcode-suppressions=suppr.txt " , " file.cpp " } ;
2018-04-23 12:39:47 +02:00
TODO_ASSERT_EQUALS ( true , false , defParser . parseFromArgs ( 3 , argv ) ) ;
2022-09-17 18:50:25 +02:00
TODO_ASSERT_EQUALS ( " " , " cppcheck: error: couldn't open the file: \" suppr.txt \" . \n " , GET_REDIRECT_OUTPUT ) ;
2011-01-29 18:04:52 +01:00
}
2014-11-20 14:20:09 +01:00
void exitcodeSuppressionsNoFile ( ) {
2011-01-29 18:04:52 +01:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " --exitcode-suppressions " , " file.cpp " } ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( false , defParser . parseFromArgs ( 3 , argv ) ) ;
ASSERT_EQUALS ( " cppcheck: error: unrecognized command line option: \" --exitcode-suppressions \" . \n " , GET_REDIRECT_OUTPUT ) ;
2010-12-04 13:13:44 +01:00
}
2022-12-19 22:28:36 +01:00
// TODO: file does not exist
void fileList ( ) {
2010-12-04 13:13:44 +01:00
REDIRECT ;
2022-09-17 18:50:25 +02:00
const char * const argv [ ] = { " cppcheck " , " --file-list=files.txt " , " file.cpp " } ;
2022-12-19 22:28:36 +01:00
TODO_ASSERT_EQUALS ( true , false , defParser . parseFromArgs ( 3 , argv ) ) ;
2022-09-17 18:50:25 +02:00
// TODO: settings are not being reset after each test
//TODO_ASSERT_EQUALS(4, 1, defParser.getPathNames().size());
2022-12-19 22:28:36 +01:00
TODO_ASSERT_EQUALS ( " " , " cppcheck: error: couldn't open the file: \" files.txt \" . \n " , GET_REDIRECT_OUTPUT ) ;
}
2022-09-17 18:50:25 +02:00
2022-12-19 22:28:36 +01:00
void fileListNoFile ( ) {
2022-09-17 18:50:25 +02:00
REDIRECT ;
const char * const argv [ ] = { " cppcheck " , " --file-list=files.txt " , " file.cpp " } ;
2022-12-19 22:28:36 +01:00
ASSERT_EQUALS ( false , defParser . parseFromArgs ( 3 , argv ) ) ;
ASSERT_EQUALS ( " cppcheck: error: couldn't open the file: \" files.txt \" . \n " , GET_REDIRECT_OUTPUT ) ;
}
2011-09-30 01:23:30 +02:00
2014-01-11 07:54:06 +01:00
/* void fileListStdin() {
// TODO: Give it some stdin to read from, fails because the list of
// files in stdin (_pathnames) is empty
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " --file-list=- " , " file.cpp " } ;
2018-04-23 12:39:47 +02:00
TODO_ASSERT_EQUALS ( true , false , defParser . parseFromArgs ( 3 , argv ) ) ;
2022-09-17 18:50:25 +02:00
TODO_ASSERT_EQUALS ( " " , " " , GET_REDIRECT_OUTPUT ) ;
2014-01-11 07:54:06 +01:00
} */
2010-12-04 13:13:44 +01:00
2022-09-17 18:50:25 +02:00
void fileListInvalid ( ) {
REDIRECT ;
const char * const argv [ ] = { " cppcheck " , " --file-list " , " files.txt " , " file.cpp " } ;
ASSERT_EQUALS ( false , defParser . parseFromArgs ( 4 , argv ) ) ;
ASSERT_EQUALS ( " cppcheck: error: unrecognized command line option: \" --file-list \" . \n " , GET_REDIRECT_OUTPUT ) ;
}
2014-11-20 14:20:09 +01:00
void inlineSuppr ( ) {
2010-12-04 13:13:44 +01:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " --inline-suppr " , " file.cpp " } ;
2022-12-19 22:28:36 +01:00
settings . inlineSuppressions = false ;
2018-04-23 12:39:47 +02:00
ASSERT ( defParser . parseFromArgs ( 3 , argv ) ) ;
2022-12-19 22:28:36 +01:00
ASSERT ( settings . inlineSuppressions ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2010-12-04 13:13:44 +01:00
}
2014-11-20 14:20:09 +01:00
void jobs ( ) {
2010-12-04 13:13:44 +01:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " -j " , " 3 " , " file.cpp " } ;
2016-01-03 16:18:17 +01:00
settings . jobs = 0 ;
2018-04-23 12:39:47 +02:00
ASSERT ( defParser . parseFromArgs ( 4 , argv ) ) ;
2016-01-03 16:18:17 +01:00
ASSERT_EQUALS ( 3 , settings . jobs ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2010-12-04 13:13:44 +01:00
}
2014-11-20 14:20:09 +01:00
void jobsMissingCount ( ) {
2010-12-04 13:13:44 +01:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " -j " , " file.cpp " } ;
2011-05-04 20:00:22 +02:00
// Fails since -j is missing thread count
2018-04-23 12:39:47 +02:00
ASSERT_EQUALS ( false , defParser . parseFromArgs ( 3 , argv ) ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " cppcheck: error: argument to '-j' is not a number. \n " , GET_REDIRECT_OUTPUT ) ;
2010-12-04 13:13:44 +01:00
}
2014-11-20 14:20:09 +01:00
void jobsInvalid ( ) {
2010-12-04 13:13:44 +01:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " -j " , " e " , " file.cpp " } ;
2011-05-04 20:00:22 +02:00
// Fails since invalid count given for -j
2018-04-23 12:39:47 +02:00
ASSERT_EQUALS ( false , defParser . parseFromArgs ( 4 , argv ) ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " cppcheck: error: argument to '-j' is not a number. \n " , GET_REDIRECT_OUTPUT ) ;
2010-12-04 13:13:44 +01:00
}
2014-11-20 14:20:09 +01:00
void maxConfigs ( ) {
2011-10-05 07:37:43 +02:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " -f " , " --max-configs=12 " , " file.cpp " } ;
2016-01-03 16:18:17 +01:00
settings . force = false ;
2022-12-19 22:28:36 +01:00
settings . maxConfigs = 0 ;
2018-04-23 12:39:47 +02:00
ASSERT ( defParser . parseFromArgs ( 4 , argv ) ) ;
2016-01-03 16:18:17 +01:00
ASSERT_EQUALS ( 12 , settings . maxConfigs ) ;
ASSERT_EQUALS ( false , settings . force ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2011-10-05 07:37:43 +02:00
}
2014-11-20 14:20:09 +01:00
void maxConfigsMissingCount ( ) {
2011-10-05 07:37:43 +02:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " --max-configs= " , " file.cpp " } ;
2011-10-05 07:37:43 +02:00
// Fails since --max-configs= is missing limit
2018-04-23 12:39:47 +02:00
ASSERT_EQUALS ( false , defParser . parseFromArgs ( 3 , argv ) ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " cppcheck: error: argument to '--max-configs=' is not a number. \n " , GET_REDIRECT_OUTPUT ) ;
2011-10-05 07:37:43 +02:00
}
2014-11-20 14:20:09 +01:00
void maxConfigsInvalid ( ) {
2011-10-05 07:37:43 +02:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " --max-configs=e " , " file.cpp " } ;
2011-10-05 07:37:43 +02:00
// Fails since invalid count given for --max-configs=
2018-04-23 12:39:47 +02:00
ASSERT_EQUALS ( false , defParser . parseFromArgs ( 3 , argv ) ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " cppcheck: error: argument to '--max-configs=' is not a number. \n " , GET_REDIRECT_OUTPUT ) ;
2011-10-05 07:37:43 +02:00
}
2014-11-20 14:20:09 +01:00
void maxConfigsTooSmall ( ) {
2011-10-05 07:37:43 +02:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " --max-configs=0 " , " file.cpp " } ;
2011-10-05 07:37:43 +02:00
// Fails since limit must be greater than 0
2018-04-23 12:39:47 +02:00
ASSERT_EQUALS ( false , defParser . parseFromArgs ( 3 , argv ) ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " cppcheck: error: argument to '--max-configs=' must be greater than 0. \n " , GET_REDIRECT_OUTPUT ) ;
2011-10-22 11:11:54 +02:00
}
2011-10-05 07:37:43 +02:00
2014-11-20 14:20:09 +01:00
void reportProgressTest ( ) {
2010-12-04 13:13:44 +01:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " --report-progress " , " file.cpp " } ;
2013-04-01 13:12:56 +02:00
settings . reportProgress = false ;
2018-04-23 12:39:47 +02:00
ASSERT ( defParser . parseFromArgs ( 3 , argv ) ) ;
2012-01-02 07:42:39 +01:00
ASSERT ( settings . reportProgress ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2010-12-04 13:13:44 +01:00
}
2014-11-20 14:20:09 +01:00
void stdc99 ( ) {
2011-10-06 08:10:51 +02:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " --std=c99 " , " file.cpp " } ;
2013-04-01 13:12:56 +02:00
settings . standards . c = Standards : : C89 ;
2018-04-23 12:39:47 +02:00
ASSERT ( defParser . parseFromArgs ( 3 , argv ) ) ;
2012-08-25 21:57:45 +02:00
ASSERT ( settings . standards . c = = Standards : : C99 ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2011-10-06 08:10:51 +02:00
}
2014-11-20 14:20:09 +01:00
void stdcpp11 ( ) {
2011-10-16 12:54:58 +02:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " --std=c++11 " , " file.cpp " } ;
2013-04-01 13:12:56 +02:00
settings . standards . cpp = Standards : : CPP03 ;
2018-04-23 12:39:47 +02:00
ASSERT ( defParser . parseFromArgs ( 3 , argv ) ) ;
2012-08-25 21:57:45 +02:00
ASSERT ( settings . standards . cpp = = Standards : : CPP11 ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2011-10-16 12:54:58 +02:00
}
2022-04-15 16:17:36 +02:00
void stdunknown ( ) {
REDIRECT ;
{
const char * const argv [ ] = { " cppcheck " , " --std=d++11 " , " file.cpp " } ;
ASSERT ( ! defParser . parseFromArgs ( 3 , argv ) ) ;
ASSERT_EQUALS ( " cppcheck: error: unknown --std value 'd++11' \n " , GET_REDIRECT_OUTPUT ) ;
}
2022-09-17 18:50:25 +02:00
CLEAR_REDIRECT_OUTPUT ;
2022-04-15 16:17:36 +02:00
{
const char * const argv [ ] = { " cppcheck " , " --std=cplusplus11 " , " file.cpp " } ;
TODO_ASSERT ( ! defParser . parseFromArgs ( 3 , argv ) ) ;
TODO_ASSERT_EQUALS ( " cppcheck: error: unknown --std value 'cplusplus11' \n " , " " , GET_REDIRECT_OUTPUT ) ;
}
}
2011-10-16 12:54:58 +02:00
2022-09-17 18:50:25 +02:00
void platformWin64 ( ) {
2013-08-15 11:09:40 +02:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " --platform=win64 " , " file.cpp " } ;
2022-09-17 18:50:25 +02:00
ASSERT ( settings . platform ( Settings : : Unspecified ) ) ;
2018-04-23 12:39:47 +02:00
ASSERT ( defParser . parseFromArgs ( 3 , argv ) ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( Settings : : Win64 , settings . platformType ) ;
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
}
void platformWin32A ( ) {
REDIRECT ;
const char * const argv [ ] = { " cppcheck " , " --platform=win32A " , " file.cpp " } ;
ASSERT ( settings . platform ( Settings : : Unspecified ) ) ;
ASSERT ( defParser . parseFromArgs ( 3 , argv ) ) ;
ASSERT_EQUALS ( Settings : : Win32A , settings . platformType ) ;
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
}
void platformWin32W ( ) {
REDIRECT ;
const char * const argv [ ] = { " cppcheck " , " --platform=win32W " , " file.cpp " } ;
ASSERT ( settings . platform ( Settings : : Unspecified ) ) ;
ASSERT ( defParser . parseFromArgs ( 3 , argv ) ) ;
ASSERT_EQUALS ( Settings : : Win32W , settings . platformType ) ;
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
}
void platformUnix32 ( ) {
REDIRECT ;
const char * const argv [ ] = { " cppcheck " , " --platform=unix32 " , " file.cpp " } ;
ASSERT ( settings . platform ( Settings : : Unspecified ) ) ;
ASSERT ( defParser . parseFromArgs ( 3 , argv ) ) ;
ASSERT_EQUALS ( Settings : : Unix32 , settings . platformType ) ;
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
}
2023-01-26 22:05:40 +01:00
void platformUnix32Unsigned ( ) {
REDIRECT ;
const char * const argv [ ] = { " cppcheck " , " --platform=unix32-unsigned " , " file.cpp " } ;
ASSERT ( settings . platform ( Settings : : Unspecified ) ) ;
ASSERT ( defParser . parseFromArgs ( 3 , argv ) ) ;
ASSERT ( settings . platformType = = Settings : : Unix32 ) ;
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
}
2022-09-17 18:50:25 +02:00
void platformUnix64 ( ) {
REDIRECT ;
const char * const argv [ ] = { " cppcheck " , " --platform=unix64 " , " file.cpp " } ;
ASSERT ( settings . platform ( Settings : : Unspecified ) ) ;
ASSERT ( defParser . parseFromArgs ( 3 , argv ) ) ;
ASSERT_EQUALS ( Settings : : Unix64 , settings . platformType ) ;
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
}
2023-01-26 22:05:40 +01:00
void platformUnix64Unsigned ( ) {
REDIRECT ;
const char * const argv [ ] = { " cppcheck " , " --platform=unix64-unsigned " , " file.cpp " } ;
ASSERT ( settings . platform ( Settings : : Unspecified ) ) ;
ASSERT ( defParser . parseFromArgs ( 3 , argv ) ) ;
ASSERT ( settings . platformType = = Settings : : Unix64 ) ;
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
}
2022-09-17 18:50:25 +02:00
void platformNative ( ) {
REDIRECT ;
const char * const argv [ ] = { " cppcheck " , " --platform=native " , " file.cpp " } ;
ASSERT ( settings . platform ( Settings : : Unspecified ) ) ;
ASSERT ( defParser . parseFromArgs ( 3 , argv ) ) ;
ASSERT_EQUALS ( Settings : : Native , settings . platformType ) ;
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
}
void platformUnspecified ( ) {
REDIRECT ;
const char * const argv [ ] = { " cppcheck " , " --platform=unspecified " , " file.cpp " } ;
ASSERT ( settings . platform ( Settings : : Native ) ) ;
ASSERT ( defParser . parseFromArgs ( 3 , argv ) ) ;
ASSERT_EQUALS ( Settings : : Unspecified , settings . platformType ) ;
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
}
2023-01-26 22:05:40 +01:00
void platformPlatformFile ( ) {
2022-09-17 18:50:25 +02:00
REDIRECT ;
const char * const argv [ ] = { " cppcheck " , " --platform=avr8 " , " file.cpp " } ;
ASSERT ( settings . platform ( Settings : : Unspecified ) ) ;
2023-01-26 22:05:40 +01:00
ASSERT_EQUALS ( true , defParser . parseFromArgs ( 3 , argv ) ) ;
ASSERT_EQUALS ( Settings : : PlatformFile , settings . platformType ) ;
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
}
2022-09-17 18:50:25 +02:00
void platformUnknown ( ) {
REDIRECT ;
const char * const argv [ ] = { " cppcheck " , " --platform=win128 " , " file.cpp " } ;
ASSERT ( ! defParser . parseFromArgs ( 3 , argv ) ) ;
ASSERT_EQUALS ( " cppcheck: error: unrecognized platform: \" win128 \" . \n " , GET_REDIRECT_OUTPUT ) ;
2013-08-15 11:09:40 +02:00
}
2023-01-27 10:46:48 +01:00
# if defined(_WIN64) || defined(_WIN32)
void platformDefault ( ) {
REDIRECT ;
CmdLineParser : : SHOW_DEF_PLATFORM_MSG = true ;
const char * const argv [ ] = { " cppcheck " , " file.cpp " } ;
settings = Settings ( ) ;
ASSERT ( defParser . parseFromArgs ( 2 , argv ) ) ;
# if defined(_WIN64)
ASSERT_EQUALS ( Settings : : Win64 , settings . platformType ) ;
ASSERT_EQUALS ( " cppcheck: Windows 64-bit binaries currently default to the 'win64' platform. Starting with Cppcheck 2.13 they will default to 'native' instead. Please specify '--platform=win64' explicitly if you rely on this. \n " , GET_REDIRECT_OUTPUT ) ;
# elif defined(_WIN32)
ASSERT_EQUALS ( Settings : : Win32A , settings . platformType ) ;
ASSERT_EQUALS ( " cppcheck: Windows 32-bit binaries currently default to the 'win32A' platform. Starting with Cppcheck 2.13 they will default to 'native' instead. Please specify '--platform=win32A' explicitly if you rely on this. \n " , GET_REDIRECT_OUTPUT ) ;
# endif
CmdLineParser : : SHOW_DEF_PLATFORM_MSG = false ;
}
void platformDefault2 ( ) {
REDIRECT ;
CmdLineParser : : SHOW_DEF_PLATFORM_MSG = true ;
const char * const argv [ ] = { " cppcheck " , " --platform=unix64 " , " file.cpp " } ;
settings = Settings ( ) ;
ASSERT ( defParser . parseFromArgs ( 3 , argv ) ) ;
ASSERT_EQUALS ( Settings : : Unix64 , settings . platformType ) ;
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
CmdLineParser : : SHOW_DEF_PLATFORM_MSG = false ;
}
# endif
2020-11-13 15:52:24 +01:00
void plistEmpty ( ) {
REDIRECT ;
const char * const argv [ ] = { " cppcheck " , " --plist-output= " , " file.cpp " } ;
settings . plistOutput = " " ;
ASSERT ( defParser . parseFromArgs ( 3 , argv ) ) ;
ASSERT ( settings . plistOutput = = " ./ " ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2020-11-13 15:52:24 +01:00
}
void plistDoesNotExist ( ) {
REDIRECT ;
const char * const argv [ ] = { " cppcheck " , " --plist-output=./cppcheck_reports " , " file.cpp " } ;
// Fails since folder pointed by --plist-output= does not exist
ASSERT_EQUALS ( false , defParser . parseFromArgs ( 3 , argv ) ) ;
2022-09-17 18:50:25 +02:00
// TODO: output contains non-native separator
//ASSERT_EQUALS("cppcheck: error: plist folder does not exist: \"cppcheck_reports/\".\n", GET_REDIRECT_OUTPUT);
2020-11-13 15:52:24 +01:00
}
2014-11-20 14:20:09 +01:00
void suppressionsOld ( ) {
2010-12-04 13:13:44 +01:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " --suppressions " , " suppr.txt " , " file.cpp " } ;
2018-04-23 12:39:47 +02:00
ASSERT ( ! defParser . parseFromArgs ( 4 , argv ) ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " cppcheck: error: unrecognized command line option: \" --suppressions \" . \n " , GET_REDIRECT_OUTPUT ) ;
2010-12-04 13:13:44 +01:00
}
2014-11-20 14:20:09 +01:00
void suppressions ( ) {
2011-01-28 12:18:07 +01:00
// TODO: Fails because there is no suppr.txt file!
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " --suppressions-list=suppr.txt " , " file.cpp " } ;
2018-04-23 12:39:47 +02:00
TODO_ASSERT_EQUALS ( true , false , defParser . parseFromArgs ( 3 , argv ) ) ;
2022-09-17 18:50:25 +02:00
TODO_ASSERT_EQUALS ( " " , " cppcheck: error: couldn't open the file: \" suppr.txt \" . \n " , GET_REDIRECT_OUTPUT ) ;
2011-01-28 12:18:07 +01:00
}
2014-11-20 14:20:09 +01:00
void suppressionsNoFile ( ) {
2011-01-28 12:18:07 +01:00
REDIRECT ;
2012-01-12 21:21:51 +01:00
{
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " --suppressions-list= " , " file.cpp " } ;
2018-04-23 12:39:47 +02:00
ASSERT_EQUALS ( false , defParser . parseFromArgs ( 3 , argv ) ) ;
2012-01-12 21:21:51 +01:00
ASSERT_EQUALS ( false , GET_REDIRECT_OUTPUT . find ( " If you want to pass two files " ) ! = std : : string : : npos ) ;
}
2022-09-17 18:50:25 +02:00
CLEAR_REDIRECT_OUTPUT ;
2012-01-12 21:21:51 +01:00
{
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " --suppressions-list=a.suppr,b.suppr " , " file.cpp " } ;
2018-04-23 12:39:47 +02:00
ASSERT_EQUALS ( false , defParser . parseFromArgs ( 3 , argv ) ) ;
2012-01-12 21:21:51 +01:00
ASSERT_EQUALS ( true , GET_REDIRECT_OUTPUT . find ( " If you want to pass two files " ) ! = std : : string : : npos ) ;
}
2022-09-17 18:50:25 +02:00
CLEAR_REDIRECT_OUTPUT ;
2012-01-12 21:21:51 +01:00
{
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " --suppressions-list=a.suppr b.suppr " , " file.cpp " } ;
2018-04-23 12:39:47 +02:00
ASSERT_EQUALS ( false , defParser . parseFromArgs ( 3 , argv ) ) ;
2012-01-12 21:21:51 +01:00
ASSERT_EQUALS ( true , GET_REDIRECT_OUTPUT . find ( " If you want to pass two files " ) ! = std : : string : : npos ) ;
}
2011-01-28 12:18:07 +01:00
}
2018-04-09 06:43:48 +02:00
static Suppressions : : ErrorMessage errorMessage ( const std : : string & errorId , const std : : string & fileName , int lineNumber ) {
Suppressions : : ErrorMessage e ;
e . errorId = errorId ;
e . setFileName ( fileName ) ;
e . lineNumber = lineNumber ;
return e ;
}
2014-11-20 14:20:09 +01:00
void suppressionSingle ( ) {
2011-02-16 10:26:40 +01:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " --suppress=uninitvar " , " file.cpp " } ;
2013-04-01 13:12:56 +02:00
settings = Settings ( ) ;
2018-04-23 12:39:47 +02:00
ASSERT ( defParser . parseFromArgs ( 3 , argv ) ) ;
2018-04-09 06:43:48 +02:00
ASSERT_EQUALS ( true , settings . nomsg . isSuppressed ( errorMessage ( " uninitvar " , " file.cpp " , 1 ) ) ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2011-02-16 10:26:40 +01:00
}
2014-11-20 14:20:09 +01:00
void suppressionSingleFile ( ) {
2011-02-16 10:26:40 +01:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " --suppress=uninitvar:file.cpp " , " file.cpp " } ;
2013-04-01 13:12:56 +02:00
settings = Settings ( ) ;
2018-04-23 12:39:47 +02:00
ASSERT ( defParser . parseFromArgs ( 3 , argv ) ) ;
2018-04-09 06:43:48 +02:00
ASSERT_EQUALS ( true , settings . nomsg . isSuppressed ( errorMessage ( " uninitvar " , " file.cpp " , 1U ) ) ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2011-02-16 10:26:40 +01:00
}
2014-11-20 14:20:09 +01:00
void suppressionTwo ( ) {
2011-09-13 16:55:00 +02:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " --suppress=uninitvar,noConstructor " , " file.cpp " } ;
2013-04-01 13:12:56 +02:00
settings = Settings ( ) ;
2018-04-23 12:39:47 +02:00
TODO_ASSERT_EQUALS ( true , false , defParser . parseFromArgs ( 3 , argv ) ) ;
2018-04-09 06:43:48 +02:00
TODO_ASSERT_EQUALS ( true , false , settings . nomsg . isSuppressed ( errorMessage ( " uninitvar " , " file.cpp " , 1U ) ) ) ;
TODO_ASSERT_EQUALS ( true , false , settings . nomsg . isSuppressed ( errorMessage ( " noConstructor " , " file.cpp " , 1U ) ) ) ;
2022-09-17 18:50:25 +02:00
TODO_ASSERT_EQUALS ( " " , " cppcheck: error: Failed to add suppression. Invalid id \" uninitvar,noConstructor \" \n " , GET_REDIRECT_OUTPUT ) ;
2011-09-13 16:55:00 +02:00
}
2014-11-20 14:20:09 +01:00
void suppressionTwoSeparate ( ) {
2011-09-13 16:55:00 +02:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " --suppress=uninitvar " , " --suppress=noConstructor " , " file.cpp " } ;
2013-04-01 13:12:56 +02:00
settings = Settings ( ) ;
2018-04-23 12:39:47 +02:00
ASSERT ( defParser . parseFromArgs ( 4 , argv ) ) ;
2018-04-09 06:43:48 +02:00
ASSERT_EQUALS ( true , settings . nomsg . isSuppressed ( errorMessage ( " uninitvar " , " file.cpp " , 1U ) ) ) ;
ASSERT_EQUALS ( true , settings . nomsg . isSuppressed ( errorMessage ( " noConstructor " , " file.cpp " , 1U ) ) ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2011-09-13 16:55:00 +02:00
}
2014-11-20 14:20:09 +01:00
void templates ( ) {
2010-12-04 13:13:44 +01:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " --template " , " {file}:{line},{severity},{id},{message} " , " file.cpp " } ;
2018-04-23 12:21:18 +02:00
settings . templateFormat . clear ( ) ;
2018-04-23 12:39:47 +02:00
ASSERT ( defParser . parseFromArgs ( 4 , argv ) ) ;
2018-04-23 12:21:18 +02:00
ASSERT_EQUALS ( " {file}:{line},{severity},{id},{message} " , settings . templateFormat ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2010-12-04 13:13:44 +01:00
}
2014-11-20 14:20:09 +01:00
void templatesGcc ( ) {
2010-12-04 13:13:44 +01:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " --template " , " gcc " , " file.cpp " } ;
2018-04-23 12:21:18 +02:00
settings . templateFormat . clear ( ) ;
2018-04-23 12:39:47 +02:00
ASSERT ( defParser . parseFromArgs ( 4 , argv ) ) ;
2021-07-08 21:21:35 +02:00
ASSERT_EQUALS ( " {bold}{file}:{line}:{column}: {magenta}warning:{default} {message} [{id}]{reset} \\ n{code} " , settings . templateFormat ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2010-12-04 13:13:44 +01:00
}
2014-11-20 14:20:09 +01:00
void templatesVs ( ) {
2010-12-04 13:13:44 +01:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " --template " , " vs " , " file.cpp " } ;
2018-04-23 12:21:18 +02:00
settings . templateFormat . clear ( ) ;
2018-04-23 12:39:47 +02:00
ASSERT ( defParser . parseFromArgs ( 4 , argv ) ) ;
2018-04-23 12:21:18 +02:00
ASSERT_EQUALS ( " {file}({line}): {severity}: {message} " , settings . templateFormat ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2010-12-04 13:13:44 +01:00
}
2014-11-20 14:20:09 +01:00
void templatesEdit ( ) {
2011-10-29 23:26:35 +02:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " --template " , " edit " , " file.cpp " } ;
2018-04-23 12:21:18 +02:00
settings . templateFormat . clear ( ) ;
2018-04-23 12:39:47 +02:00
ASSERT ( defParser . parseFromArgs ( 4 , argv ) ) ;
2018-04-23 12:21:18 +02:00
ASSERT_EQUALS ( " {file} +{line}: {severity}: {message} " , settings . templateFormat ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2011-10-29 23:26:35 +02:00
}
2014-11-20 14:20:09 +01:00
void xml ( ) {
2010-12-04 13:13:44 +01:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " --xml " , " file.cpp " } ;
2016-01-03 16:18:17 +01:00
settings . xml_version = 1 ;
settings . xml = false ;
2018-04-23 12:39:47 +02:00
ASSERT ( defParser . parseFromArgs ( 3 , argv ) ) ;
2016-01-03 16:18:17 +01:00
ASSERT ( settings . xml ) ;
ASSERT_EQUALS ( 1 , settings . xml_version ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2011-02-02 13:04:50 +01:00
}
2014-11-20 14:20:09 +01:00
void xmlver2 ( ) {
2011-01-27 13:25:10 +01:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " --xml-version=2 " , " file.cpp " } ;
2016-01-03 16:18:17 +01:00
settings . xml_version = 1 ;
settings . xml = false ;
2018-04-23 12:39:47 +02:00
ASSERT ( defParser . parseFromArgs ( 3 , argv ) ) ;
2016-01-03 16:18:17 +01:00
ASSERT ( settings . xml ) ;
ASSERT_EQUALS ( 2 , settings . xml_version ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2011-01-27 13:25:10 +01:00
}
2014-11-20 14:20:09 +01:00
void xmlver2both ( ) {
2011-01-27 13:25:10 +01:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " --xml " , " --xml-version=2 " , " file.cpp " } ;
2016-01-03 16:18:17 +01:00
settings . xml_version = 1 ;
settings . xml = false ;
2018-04-23 12:39:47 +02:00
ASSERT ( defParser . parseFromArgs ( 4 , argv ) ) ;
2016-01-03 16:18:17 +01:00
ASSERT ( settings . xml ) ;
ASSERT_EQUALS ( 2 , settings . xml_version ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2011-01-27 13:25:10 +01:00
}
2014-11-20 14:20:09 +01:00
void xmlver2both2 ( ) {
2011-01-27 13:25:10 +01:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " --xml-version=2 " , " --xml " , " file.cpp " } ;
2016-01-03 16:18:17 +01:00
settings . xml_version = 1 ;
settings . xml = false ;
2018-04-23 12:39:47 +02:00
ASSERT ( defParser . parseFromArgs ( 4 , argv ) ) ;
2016-01-03 16:18:17 +01:00
ASSERT ( settings . xml ) ;
ASSERT_EQUALS ( 2 , settings . xml_version ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2010-12-04 13:13:44 +01:00
}
2014-11-20 14:20:09 +01:00
void xmlverunknown ( ) {
2011-02-02 12:33:57 +01:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " --xml " , " --xml-version=3 " , " file.cpp " } ;
2011-05-04 20:00:22 +02:00
// FAils since unknown XML format version
2018-04-23 12:39:47 +02:00
ASSERT_EQUALS ( false , defParser . parseFromArgs ( 4 , argv ) ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " cppcheck: error: '--xml-version' can only be 2. \n " , GET_REDIRECT_OUTPUT ) ;
2011-02-02 12:33:57 +01:00
}
2014-11-20 14:20:09 +01:00
void xmlverinvalid ( ) {
2011-02-02 12:33:57 +01:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " --xml " , " --xml-version=a " , " file.cpp " } ;
2011-05-04 20:00:22 +02:00
// FAils since unknown XML format version
2018-04-23 12:39:47 +02:00
ASSERT_EQUALS ( false , defParser . parseFromArgs ( 4 , argv ) ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " cppcheck: error: argument to '--xml-version' is not a number. \n " , GET_REDIRECT_OUTPUT ) ;
2011-02-02 12:33:57 +01:00
}
2014-11-20 14:20:09 +01:00
void doc ( ) {
2013-08-15 11:09:40 +02:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " --doc " } ;
2018-04-23 12:39:47 +02:00
ASSERT ( defParser . parseFromArgs ( 2 , argv ) ) ;
ASSERT ( defParser . exitAfterPrinting ( ) ) ;
2022-09-17 18:50:25 +02:00
ASSERT ( GET_REDIRECT_OUTPUT . find ( " ## " ) = = 0 ) ;
2013-08-15 11:09:40 +02:00
}
2014-11-20 14:20:09 +01:00
void showtime ( ) {
2013-08-15 11:09:40 +02:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " --showtime=summary " } ;
2019-07-31 22:35:51 +02:00
settings . showtime = SHOWTIME_MODES : : SHOWTIME_NONE ;
2018-04-23 12:39:47 +02:00
ASSERT ( defParser . parseFromArgs ( 2 , argv ) ) ;
2019-07-31 22:35:51 +02:00
ASSERT ( settings . showtime = = SHOWTIME_MODES : : SHOWTIME_SUMMARY ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2013-08-15 11:09:40 +02:00
}
2014-11-20 14:20:09 +01:00
void errorlist1 ( ) {
2011-01-27 10:14:08 +01:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " --errorlist " } ;
2018-04-23 12:39:47 +02:00
ASSERT ( defParser . parseFromArgs ( 2 , argv ) ) ;
ASSERT ( defParser . getShowErrorMessages ( ) ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2011-01-27 10:14:08 +01:00
}
2014-11-20 14:20:09 +01:00
void errorlistverbose1 ( ) {
2011-01-27 10:14:08 +01:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " --verbose " , " --errorlist " } ;
2016-01-03 16:18:17 +01:00
settings . verbose = false ;
2018-04-23 12:39:47 +02:00
ASSERT ( defParser . parseFromArgs ( 3 , argv ) ) ;
2016-01-03 16:18:17 +01:00
ASSERT ( settings . verbose ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2011-01-27 10:14:08 +01:00
}
2014-11-20 14:20:09 +01:00
void errorlistverbose2 ( ) {
2011-01-27 10:14:08 +01:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " --errorlist " , " --verbose " } ;
2016-01-03 16:18:17 +01:00
settings . verbose = false ;
2018-04-23 12:39:47 +02:00
ASSERT ( defParser . parseFromArgs ( 3 , argv ) ) ;
2016-01-03 16:18:17 +01:00
ASSERT ( settings . verbose ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2011-01-27 10:14:08 +01:00
}
2014-11-20 14:20:09 +01:00
void ignorepathsnopath ( ) {
2011-01-31 14:25:51 +01:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " -i " } ;
2011-01-31 14:25:51 +01:00
CmdLineParser parser ( & settings ) ;
2011-05-04 20:00:22 +02:00
// Fails since no ignored path given
2018-04-23 12:39:47 +02:00
ASSERT_EQUALS ( false , parser . parseFromArgs ( 2 , argv ) ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " cppcheck: error: argument to '-i' is missing. \n " , GET_REDIRECT_OUTPUT ) ;
2011-01-31 14:25:51 +01:00
}
2022-08-20 20:54:31 +02:00
void exceptionhandling ( ) {
REDIRECT ;
const char * const argv [ ] = { " cppcheck " , " --exception-handling " } ;
settings . exceptionHandling = false ;
CppCheckExecutor : : setExceptionOutput ( stderr ) ;
ASSERT ( defParser . parseFromArgs ( 2 , argv ) ) ;
ASSERT ( settings . exceptionHandling ) ;
ASSERT_EQUALS ( stderr , CppCheckExecutor : : getExceptionOutput ( ) ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2022-08-20 20:54:31 +02:00
}
void exceptionhandling2 ( ) {
REDIRECT ;
const char * const argv [ ] = { " cppcheck " , " --exception-handling=stderr " } ;
settings . exceptionHandling = false ;
CppCheckExecutor : : setExceptionOutput ( stdout ) ;
ASSERT ( defParser . parseFromArgs ( 2 , argv ) ) ;
ASSERT ( settings . exceptionHandling ) ;
ASSERT_EQUALS ( stderr , CppCheckExecutor : : getExceptionOutput ( ) ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2022-08-20 20:54:31 +02:00
}
void exceptionhandling3 ( ) {
REDIRECT ;
const char * const argv [ ] = { " cppcheck " , " --exception-handling=stdout " } ;
settings . exceptionHandling = false ;
CppCheckExecutor : : setExceptionOutput ( stderr ) ;
ASSERT ( defParser . parseFromArgs ( 2 , argv ) ) ;
ASSERT ( settings . exceptionHandling ) ;
ASSERT_EQUALS ( stdout , CppCheckExecutor : : getExceptionOutput ( ) ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2022-08-20 20:54:31 +02:00
}
void exceptionhandlingInvalid ( ) {
REDIRECT ;
const char * const argv [ ] = { " cppcheck " , " --exception-handling=exfile " } ;
ASSERT_EQUALS ( false , defParser . parseFromArgs ( 2 , argv ) ) ;
ASSERT_EQUALS ( " cppcheck: error: invalid '--exception-handling' argument \n " , GET_REDIRECT_OUTPUT ) ;
}
void exceptionhandlingInvalid2 ( ) {
REDIRECT ;
const char * const argv [ ] = { " cppcheck " , " --exception-handling-foo " } ;
ASSERT_EQUALS ( false , defParser . parseFromArgs ( 2 , argv ) ) ;
ASSERT_EQUALS ( " cppcheck: error: unrecognized command line option: \" --exception-handling-foo \" . \n " , GET_REDIRECT_OUTPUT ) ;
}
void clang ( ) {
REDIRECT ;
const char * const argv [ ] = { " cppcheck " , " --clang " } ;
settings . clang = false ;
settings . clangExecutable = " exe " ;
ASSERT ( defParser . parseFromArgs ( 2 , argv ) ) ;
ASSERT ( settings . clang ) ;
ASSERT_EQUALS ( " exe " , settings . clangExecutable ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2022-08-20 20:54:31 +02:00
}
void clang2 ( ) {
REDIRECT ;
const char * const argv [ ] = { " cppcheck " , " --clang=clang-14 " } ;
settings . clang = false ;
settings . clangExecutable = " " ;
ASSERT ( defParser . parseFromArgs ( 2 , argv ) ) ;
ASSERT ( settings . clang ) ;
ASSERT_EQUALS ( " clang-14 " , settings . clangExecutable ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2022-08-20 20:54:31 +02:00
}
void clangInvalid ( ) {
REDIRECT ;
const char * const argv [ ] = { " cppcheck " , " --clang-foo " } ;
ASSERT_EQUALS ( false , defParser . parseFromArgs ( 2 , argv ) ) ;
ASSERT_EQUALS ( " cppcheck: error: unrecognized command line option: \" --clang-foo \" . \n " , GET_REDIRECT_OUTPUT ) ;
2022-12-20 20:51:08 +01:00
}
void valueFlowMaxIterations ( ) {
REDIRECT ;
const char * const argv [ ] = { " cppcheck " , " --valueflow-max-iterations=0 " } ;
2023-01-02 17:44:17 +01:00
settings . valueFlowMaxIterations = SIZE_MAX ;
2022-12-20 20:51:08 +01:00
ASSERT ( defParser . parseFromArgs ( 2 , argv ) ) ;
ASSERT_EQUALS ( 0 , settings . valueFlowMaxIterations ) ;
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
}
void valueFlowMaxIterations2 ( ) {
REDIRECT ;
const char * const argv [ ] = { " cppcheck " , " --valueflow-max-iterations=11 " } ;
2023-01-02 17:44:17 +01:00
settings . valueFlowMaxIterations = SIZE_MAX ;
2022-12-20 20:51:08 +01:00
ASSERT ( defParser . parseFromArgs ( 2 , argv ) ) ;
ASSERT_EQUALS ( 11 , settings . valueFlowMaxIterations ) ;
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
}
void valueFlowMaxIterationsInvalid ( ) {
REDIRECT ;
const char * const argv [ ] = { " cppcheck " , " --valueflow-max-iterations " } ;
ASSERT ( ! defParser . parseFromArgs ( 2 , argv ) ) ;
ASSERT_EQUALS ( " cppcheck: error: unrecognized command line option: \" --valueflow-max-iterations \" . \n " , GET_REDIRECT_OUTPUT ) ;
}
void valueFlowMaxIterationsInvalid2 ( ) {
REDIRECT ;
const char * const argv [ ] = { " cppcheck " , " --valueflow-max-iterations=seven " } ;
ASSERT ( ! defParser . parseFromArgs ( 2 , argv ) ) ;
ASSERT_EQUALS ( " cppcheck: error: argument to '--valueflow-max-iteration' is invalid. \n " , GET_REDIRECT_OUTPUT ) ;
}
void valueFlowMaxIterationsInvalid3 ( ) {
REDIRECT ;
const char * const argv [ ] = { " cppcheck " , " --valueflow-max-iterations=-1 " } ;
ASSERT ( ! defParser . parseFromArgs ( 2 , argv ) ) ;
ASSERT_EQUALS ( " cppcheck: error: argument to '--valueflow-max-iteration' needs to be at least 0. \n " , GET_REDIRECT_OUTPUT ) ;
2022-08-20 20:54:31 +02:00
}
2023-01-01 15:32:37 +01:00
void ignorepaths1 ( ) {
REDIRECT ;
const char * const argv [ ] = { " cppcheck " , " -isrc " , " file.cpp " } ;
CmdLineParser parser ( & settings ) ;
ASSERT ( parser . parseFromArgs ( 3 , argv ) ) ;
ASSERT_EQUALS ( 1 , parser . getIgnoredPaths ( ) . size ( ) ) ;
ASSERT_EQUALS ( " src " , parser . getIgnoredPaths ( ) [ 0 ] ) ;
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
}
2022-08-20 20:54:31 +02:00
2023-01-01 15:32:37 +01:00
void ignorepaths2 ( ) {
REDIRECT ;
const char * const argv [ ] = { " cppcheck " , " -i " , " src " , " file.cpp " } ;
CmdLineParser parser ( & settings ) ;
ASSERT ( parser . parseFromArgs ( 4 , argv ) ) ;
ASSERT_EQUALS ( 1 , parser . getIgnoredPaths ( ) . size ( ) ) ;
ASSERT_EQUALS ( " src " , parser . getIgnoredPaths ( ) [ 0 ] ) ;
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
}
2011-01-31 14:25:51 +01:00
2023-01-01 15:32:37 +01:00
void ignorepaths3 ( ) {
REDIRECT ;
const char * const argv [ ] = { " cppcheck " , " -isrc " , " -imodule " , " file.cpp " } ;
CmdLineParser parser ( & settings ) ;
ASSERT ( parser . parseFromArgs ( 4 , argv ) ) ;
ASSERT_EQUALS ( 2 , parser . getIgnoredPaths ( ) . size ( ) ) ;
ASSERT_EQUALS ( " src " , parser . getIgnoredPaths ( ) [ 0 ] ) ;
ASSERT_EQUALS ( " module " , parser . getIgnoredPaths ( ) [ 1 ] ) ;
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
}
2022-01-04 15:48:08 +01:00
2023-01-01 15:32:37 +01:00
void ignorepaths4 ( ) {
2014-01-12 12:34:05 +01:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " -i " , " src " , " -i " , " module " , " file.cpp " } ;
2014-01-12 12:34:05 +01:00
CmdLineParser parser ( & settings ) ;
2018-04-23 12:39:47 +02:00
ASSERT ( parser . parseFromArgs ( 6 , argv ) ) ;
ASSERT_EQUALS ( 2 , parser . getIgnoredPaths ( ) . size ( ) ) ;
2023-01-01 15:32:37 +01:00
ASSERT_EQUALS ( " src " , parser . getIgnoredPaths ( ) [ 0 ] ) ;
ASSERT_EQUALS ( " module " , parser . getIgnoredPaths ( ) [ 1 ] ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2023-01-01 15:32:37 +01:00
}
2022-01-04 15:48:08 +01:00
2023-01-01 15:32:37 +01:00
void ignorefilepaths1 ( ) {
REDIRECT ;
const char * const argv [ ] = { " cppcheck " , " -ifoo.cpp " , " file.cpp " } ;
CmdLineParser parser ( & settings ) ;
ASSERT ( parser . parseFromArgs ( 3 , argv ) ) ;
ASSERT_EQUALS ( 1 , parser . getIgnoredPaths ( ) . size ( ) ) ;
ASSERT_EQUALS ( " foo.cpp " , parser . getIgnoredPaths ( ) [ 0 ] ) ;
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
}
2022-01-04 15:48:08 +01:00
2023-01-01 15:32:37 +01:00
void ignorefilepaths2 ( ) {
2014-01-12 12:34:05 +01:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " -isrc/foo.cpp " , " file.cpp " } ;
2014-01-12 12:34:05 +01:00
CmdLineParser parser ( & settings ) ;
2018-04-23 12:39:47 +02:00
ASSERT ( parser . parseFromArgs ( 3 , argv ) ) ;
ASSERT_EQUALS ( 1 , parser . getIgnoredPaths ( ) . size ( ) ) ;
ASSERT_EQUALS ( " src/foo.cpp " , parser . getIgnoredPaths ( ) [ 0 ] ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2023-01-01 15:32:37 +01:00
}
2011-02-03 13:43:42 +01:00
2014-11-20 14:20:09 +01:00
void checkconfig ( ) {
2011-05-04 20:07:02 +02:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " --check-config " , " file.cpp " } ;
2013-04-01 13:12:56 +02:00
settings . checkConfiguration = false ;
2018-04-23 12:39:47 +02:00
ASSERT ( defParser . parseFromArgs ( 3 , argv ) ) ;
2011-05-04 20:07:02 +02:00
ASSERT_EQUALS ( true , settings . checkConfiguration ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2011-05-04 20:07:02 +02:00
}
2014-11-20 14:20:09 +01:00
void unknownParam ( ) {
2010-12-04 13:13:44 +01:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " --foo " , " file.cpp " } ;
2018-04-23 12:39:47 +02:00
ASSERT ( ! defParser . parseFromArgs ( 3 , argv ) ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " cppcheck: error: unrecognized command line option: \" --foo \" . \n " , GET_REDIRECT_OUTPUT ) ;
2010-12-04 13:13:44 +01:00
}
2011-11-30 20:24:01 +01:00
2014-11-20 14:20:09 +01:00
void undefs ( ) {
2011-11-30 20:24:01 +01:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " -U_WIN32 " , " file.cpp " } ;
2013-04-01 13:12:56 +02:00
settings = Settings ( ) ;
2018-04-23 12:39:47 +02:00
ASSERT ( defParser . parseFromArgs ( 3 , argv ) ) ;
2011-11-30 20:24:01 +01:00
ASSERT_EQUALS ( 1 , settings . userUndefs . size ( ) ) ;
ASSERT ( settings . userUndefs . find ( " _WIN32 " ) ! = settings . userUndefs . end ( ) ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2011-11-30 20:24:01 +01:00
}
2014-11-20 14:20:09 +01:00
void undefs2 ( ) {
2011-11-30 20:24:01 +01:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " -U_WIN32 " , " -UNODEBUG " , " file.cpp " } ;
2013-04-01 13:12:56 +02:00
settings = Settings ( ) ;
2018-04-23 12:39:47 +02:00
ASSERT ( defParser . parseFromArgs ( 4 , argv ) ) ;
2011-11-30 20:24:01 +01:00
ASSERT_EQUALS ( 2 , settings . userUndefs . size ( ) ) ;
ASSERT ( settings . userUndefs . find ( " _WIN32 " ) ! = settings . userUndefs . end ( ) ) ;
ASSERT ( settings . userUndefs . find ( " NODEBUG " ) ! = settings . userUndefs . end ( ) ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " " , GET_REDIRECT_OUTPUT ) ;
2011-11-30 20:24:01 +01:00
}
2014-11-20 14:20:09 +01:00
void undefs_noarg ( ) {
2011-11-30 20:24:01 +01:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " -U " } ;
2011-11-30 20:24:01 +01:00
// Fails since -U has no param
2018-04-23 12:39:47 +02:00
ASSERT_EQUALS ( false , defParser . parseFromArgs ( 2 , argv ) ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " cppcheck: error: argument to '-U' is missing. \n " , GET_REDIRECT_OUTPUT ) ;
2011-11-30 20:24:01 +01:00
}
2014-11-20 14:20:09 +01:00
void undefs_noarg2 ( ) {
2011-11-30 20:24:01 +01:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " -U " , " -v " , " file.cpp " } ;
2011-11-30 20:24:01 +01:00
// Fails since -U has no param
2018-04-23 12:39:47 +02:00
ASSERT_EQUALS ( false , defParser . parseFromArgs ( 4 , argv ) ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " cppcheck: error: argument to '-U' is missing. \n " , GET_REDIRECT_OUTPUT ) ;
2011-11-30 20:24:01 +01:00
}
2014-11-20 14:20:09 +01:00
void undefs_noarg3 ( ) {
2011-11-30 20:24:01 +01:00
REDIRECT ;
2018-09-24 15:08:16 +02:00
const char * const argv [ ] = { " cppcheck " , " -U " , " --quiet " , " file.cpp " } ;
2011-11-30 20:24:01 +01:00
// Fails since -U has no param
2018-04-23 12:39:47 +02:00
ASSERT_EQUALS ( false , defParser . parseFromArgs ( 4 , argv ) ) ;
2022-09-17 18:50:25 +02:00
ASSERT_EQUALS ( " cppcheck: error: argument to '-U' is missing. \n " , GET_REDIRECT_OUTPUT ) ;
2011-11-30 20:24:01 +01:00
}
2010-09-06 21:31:06 +02:00
} ;
REGISTER_TEST ( TestCmdlineParser )