diff --git a/test/testunusedfunctions.cpp b/test/testunusedfunctions.cpp index 9fc1ea9140d..48e24d4757e 100644 --- a/test/testunusedfunctions.cpp +++ b/test/testunusedfunctions.cpp @@ -90,14 +90,22 @@ class TestUnusedFunctions : public TestFixture { TEST_CASE(attributeMaybeUnused); } + struct CheckOptions + { + CheckOptions() = default; + Platform::Type platform = Platform::Type::Native; + const Settings* s = nullptr; + bool cpp = true; + }; + #define check(...) check_(__FILE__, __LINE__, __VA_ARGS__) template - void check_(const char* file, int line, const char (&code)[size], Platform::Type platform = Platform::Type::Native, const Settings *s = nullptr, bool cpp = true) { - const Settings settings1 = settingsBuilder(s ? *s : settings).platform(platform).build(); + void check_(const char* file, int line, const char (&code)[size], const CheckOptions& options = make_default_obj()) { + const Settings settings1 = settingsBuilder(options.s ? *options.s : settings).platform(options.platform).build(); // Tokenize.. SimpleTokenizer tokenizer(settings1, *this); - ASSERT_LOC(tokenizer.tokenize(code, cpp), file, line); + ASSERT_LOC(tokenizer.tokenize(code, options.cpp), file, line); // Check for unused functions.. CheckUnusedFunctions checkUnusedFunctions; @@ -691,10 +699,10 @@ class TestUnusedFunctions : public TestFixture { const Settings s = settingsBuilder(settings).library("windows.cfg").build(); - check("int WinMain() { }", Platform::Type::Native, &s); + check("int WinMain() { }", dinit(CheckOptions, $.s = &s)); ASSERT_EQUALS("", errout_str()); - check("int _tmain() { }", Platform::Type::Native, &s); + check("int _tmain() { }", dinit(CheckOptions, $.s = &s)); ASSERT_EQUALS("", errout_str()); } @@ -707,10 +715,10 @@ class TestUnusedFunctions : public TestFixture { const Settings s = settingsBuilder(settings).library("windows.cfg").build(); - check("int wWinMain() { }", Platform::Type::Native, &s); + check("int wWinMain() { }", dinit(CheckOptions, $.s = &s)); ASSERT_EQUALS("", errout_str()); - check("int _tmain() { }", Platform::Type::Native, &s); + check("int _tmain() { }", dinit(CheckOptions, $.s = &s)); ASSERT_EQUALS("", errout_str()); } @@ -723,7 +731,7 @@ class TestUnusedFunctions : public TestFixture { const Settings s = settingsBuilder(settings).library("gnu.cfg").build(); check("int _init() { }\n" - "int _fini() { }\n", Platform::Type::Native, &s); + "int _fini() { }\n", dinit(CheckOptions, $.s = &s)); ASSERT_EQUALS("", errout_str()); } @@ -811,10 +819,10 @@ class TestUnusedFunctions : public TestFixture { void attributeMaybeUnused() { - check("[[__maybe_unused__]] void f() {}\n", Platform::Type::Native, nullptr, false); + check("[[__maybe_unused__]] void f() {}\n", dinit(CheckOptions, $.cpp = false)); ASSERT_EQUALS("", errout_str()); - check("[[maybe_unused]] void f() {}\n", Platform::Type::Native, nullptr, false); + check("[[maybe_unused]] void f() {}\n", dinit(CheckOptions, $.cpp = false)); ASSERT_EQUALS("", errout_str()); check("[[maybe_unused]] void f() {}\n");