From 26cbfecadef262189655588008ee7cfe764007e9 Mon Sep 17 00:00:00 2001 From: firewave Date: Thu, 3 Apr 2025 10:36:23 +0200 Subject: [PATCH] testrunner: cleaned up some test options --- test/testbufferoverrun.cpp | 4 ++-- test/testcondition.cpp | 6 +++--- test/testother.cpp | 14 ++++++++++---- test/teststring.cpp | 22 +++++++++++----------- test/testtype.cpp | 8 ++++---- test/testvarid.cpp | 4 ++-- 6 files changed, 32 insertions(+), 26 deletions(-) diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index 21a911fdbec..9d630916ea5 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -72,11 +72,11 @@ class TestBufferOverrun : public TestFixture { } #define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__) - void checkP_(const char* file, int line, const char code[], const char* filename = "test.cpp") + void checkP_(const char* file, int line, const char code[]) { const Settings settings = settingsBuilder(settings0).severity(Severity::performance).certainty(Certainty::inconclusive).build(); - std::vector files(1, filename); + std::vector files(1, "test.cpp"); Tokenizer tokenizer(settings, *this); PreprocessorHelper::preprocess(code, files, tokenizer, *this); diff --git a/test/testcondition.cpp b/test/testcondition.cpp index 46d998fc8bb..f3927925329 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -132,7 +132,7 @@ class TestCondition : public TestFixture { { CheckOptions() = default; const Settings* s = nullptr; - const char* filename = "test.cpp"; + bool cpp = true; bool inconclusive = false; }; @@ -140,7 +140,7 @@ class TestCondition : public TestFixture { void check_(const char* file, int line, const char code[], const CheckOptions& options = make_default_obj()) { const Settings settings = settingsBuilder(options.s ? *options.s : settings0).certainty(Certainty::inconclusive, options.inconclusive).build(); Tokenizer tokenizer(settings, *this); - std::vector files(1, options.filename); + std::vector files(1, options.cpp ? "test.cpp" : "test.c"); PreprocessorHelper::preprocess(code, files, tokenizer, *this); // Tokenizer.. @@ -3162,7 +3162,7 @@ class TestCondition : public TestFixture { check("void f() { A a; }"); ASSERT_EQUALS("", errout_str()); - check("void f() { a(x there are never templates + check("void f() { a(x there are never templates ASSERT_EQUALS("[test.c:1]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses.\n", errout_str()); check("class A;"); diff --git a/test/testother.cpp b/test/testother.cpp index 607b8075e33..1798322bdb2 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -336,9 +336,15 @@ class TestOther : public TestFixture { check_(file, line, code, true, true, true, false, s); } + struct CheckPOptions + { + CheckPOptions() = default; + bool cpp = true; + }; + #define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__) template - void checkP_(const char* file, int line, const char (&code)[size], const char *filename = "test.cpp") { + void checkP_(const char* file, int line, const char (&code)[size], const CheckPOptions& options = make_default_obj()) { Settings* settings = &_settings; settings->severity.enable(Severity::style); settings->severity.enable(Severity::warning); @@ -348,7 +354,7 @@ class TestOther : public TestFixture { settings->standards.cpp = Standards::CPPLatest; settings->certainty.enable(Certainty::inconclusive); - std::vector files(1, filename); + std::vector files(1, options.cpp ? "test.cpp" : "test.c"); Tokenizer tokenizer(*settings, *this); PreprocessorHelper::preprocess(code, files, tokenizer, *this); @@ -5601,7 +5607,7 @@ class TestOther : public TestFixture { " }\n" " OUTB(index, port_0);\n" " return INB(port_1);\n" - "}\n", "test.c"); + "}\n", dinit(CheckPOptions, $.cpp = false)); ASSERT_EQUALS("", errout_str()); check("[[noreturn]] void n();\n" @@ -11672,7 +11678,7 @@ class TestOther : public TestFixture { checkP("#define X x\n" "void f(int x) {\n" " return x + X++;\n" - "}", "test.c"); + "}", dinit(CheckPOptions, $.cpp = false)); ASSERT_EQUALS("[test.c:3]: (error) Expression 'x+x++' depends on order of evaluation of side effects\n", errout_str()); } diff --git a/test/teststring.cpp b/test/teststring.cpp index 876a8243a20..9a8ec9b55ab 100644 --- a/test/teststring.cpp +++ b/test/teststring.cpp @@ -64,12 +64,12 @@ class TestString : public TestFixture { struct CheckOptions { CheckOptions() = default; - const char* filename = "test.cpp"; + bool cpp = true; }; #define check(...) check_(__FILE__, __LINE__, __VA_ARGS__) void check_(const char* file, int line, const char code[], const CheckOptions& options = make_default_obj()) { - std::vector files(1, options.filename); + std::vector files(1, options.cpp ? "test.cpp" : "test.c"); Tokenizer tokenizer(settings, *this); PreprocessorHelper::preprocess(code, files, tokenizer, *this); @@ -337,7 +337,7 @@ class TestString : public TestFixture { check("bool foo(char* c) {\n" " return \"x\" == c+foo;\n" - "}", dinit(CheckOptions, $.filename = "test.c")); + "}", dinit(CheckOptions, $.cpp = false)); ASSERT_EQUALS("[test.c:2]: (warning) String literal compared with variable 'c+foo'. Did you intend to use strcmp() instead?\n", errout_str()); check("bool foo(Foo c) {\n" @@ -347,7 +347,7 @@ class TestString : public TestFixture { check("bool foo(Foo c) {\n" " return \"x\" == c.foo;\n" - "}", dinit(CheckOptions, $.filename = "test.c")); + "}", dinit(CheckOptions, $.cpp = false)); ASSERT_EQUALS("[test.c:2]: (warning) String literal compared with variable 'c.foo'. Did you intend to use strcmp() instead?\n", errout_str()); check("bool foo(const std::string& c) {\n" @@ -363,7 +363,7 @@ class TestString : public TestFixture { // Ticket #4257 check("bool foo() {\n" "MyString *str=Getter();\n" - "return *str==\"bug\"; }\n", dinit(CheckOptions, $.filename = "test.c")); + "return *str==\"bug\"; }\n", dinit(CheckOptions, $.cpp = false)); ASSERT_EQUALS("[test.c:3]: (warning) String literal compared with variable '*str'. Did you intend to use strcmp() instead?\n", errout_str()); // Ticket #4257 @@ -375,13 +375,13 @@ class TestString : public TestFixture { // Ticket #4257 check("bool foo() {\n" "MyString **str=OtherGetter();\n" - "return *str==\"bug\"; }", dinit(CheckOptions, $.filename = "test.c")); + "return *str==\"bug\"; }", dinit(CheckOptions, $.cpp = false)); ASSERT_EQUALS("[test.c:3]: (warning) String literal compared with variable '*str'. Did you intend to use strcmp() instead?\n", errout_str()); // Ticket #4257 check("bool foo() {\n" "MyString str=OtherGetter2();\n" - "return &str==\"bug\"; }", dinit(CheckOptions, $.filename = "test.c")); + "return &str==\"bug\"; }", dinit(CheckOptions, $.cpp = false)); ASSERT_EQUALS("[test.c:3]: (warning) String literal compared with variable '&str'. Did you intend to use strcmp() instead?\n", errout_str()); // Ticket #5734 @@ -389,13 +389,13 @@ class TestString : public TestFixture { "return c == '4';}"); ASSERT_EQUALS("", errout_str()); check("int foo(char c) {\n" - "return c == '4';}", dinit(CheckOptions, $.filename = "test.c")); + "return c == '4';}", dinit(CheckOptions, $.cpp = false)); ASSERT_EQUALS("", errout_str()); check("int foo(char c) {\n" "return c == \"42\"[0];}"); ASSERT_EQUALS("", errout_str()); check("int foo(char c) {\n" - "return c == \"42\"[0];}", dinit(CheckOptions, $.filename = "test.c")); + "return c == \"42\"[0];}", dinit(CheckOptions, $.cpp = false)); ASSERT_EQUALS("", errout_str()); // 5639 String literal compared with char buffer in a struct @@ -413,7 +413,7 @@ class TestString : public TestFixture { "void foo() {\n" " struct Example example;\n" " if (example.buffer == \"test\") ;\n" - "}\n", dinit(CheckOptions, $.filename = "test.c")); + "}\n", dinit(CheckOptions, $.cpp = false)); ASSERT_EQUALS("[test.c:6]: (warning) String literal compared with variable 'example.buffer'. Did you intend to use strcmp() instead?\n", errout_str()); // #9726 @@ -467,7 +467,7 @@ class TestString : public TestFixture { check("bool foo(char* c) {\n" " return *c == 0;\n" - "}", dinit(CheckOptions, $.filename = "test.c")); + "}", dinit(CheckOptions, $.cpp = false)); ASSERT_EQUALS("", errout_str()); check("bool foo(char* c) {\n" diff --git a/test/testtype.cpp b/test/testtype.cpp index 22323e5206d..2d94c4afbb3 100644 --- a/test/testtype.cpp +++ b/test/testtype.cpp @@ -81,7 +81,7 @@ class TestType : public TestFixture { struct CheckPOptions { CheckPOptions() = default; - const char* filename = "test.cpp"; + bool cpp = true; }; #define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__) @@ -89,7 +89,7 @@ class TestType : public TestFixture { void checkP_(const char* file, int line, const char (&code)[size], const Settings& settings, const CheckPOptions& options = make_default_obj()) { const Settings settings1 = settingsBuilder(settings).severity(Severity::warning).severity(Severity::portability).build(); - std::vector files(1, options.filename); + std::vector files(1, options.cpp ? "test.cpp" : "test.c"); Tokenizer tokenizer(settings1, *this); PreprocessorHelper::preprocess(code, files, tokenizer, *this); @@ -566,14 +566,14 @@ class TestType : public TestFixture { "void f()\n" "{\n" " unsigned short u = TEST(true, 75000.0);\n" - "}\n", settingsDefault, dinit(CheckPOptions, $.filename = "test.c")); + "}\n", settingsDefault, dinit(CheckPOptions, $.cpp = false)); ASSERT_EQUALS("", errout_str()); checkP("#define TEST(b, f) b ? 5000 : (unsigned short)f\n" "void f()\n" "{\n" " unsigned short u = TEST(false, 75000.0);\n" - "}\n", settingsDefault, dinit(CheckPOptions, $.filename = "test.c")); + "}\n", settingsDefault, dinit(CheckPOptions, $.cpp = false)); ASSERT_EQUALS("[test.c:4]: (error) Undefined behaviour: float () to integer conversion overflow.\n", removeFloat(errout_str())); } diff --git a/test/testvarid.cpp b/test/testvarid.cpp index 89223842b49..a82010e74e1 100644 --- a/test/testvarid.cpp +++ b/test/testvarid.cpp @@ -298,8 +298,8 @@ class TestVarID : public TestFixture { #define tokenizeExpr(...) tokenizeExpr_(__FILE__, __LINE__, __VA_ARGS__) template - std::string tokenizeExpr_(const char* file, int line, const char (&code)[size], const char filename[] = "test.cpp") { - std::vector files(1, filename); + std::string tokenizeExpr_(const char* file, int line, const char (&code)[size]) { + std::vector files(1, "test.cpp"); Tokenizer tokenizer(settings, *this); PreprocessorHelper::preprocess(code, files, tokenizer, *this);