Skip to content

Commit 7b77918

Browse files
committed
TestUnusedFunctions: cleaned up by using an object to pass the options
1 parent 0fdc470 commit 7b77918

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

test/testunusedfunctions.cpp

+18-10
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,22 @@ class TestUnusedFunctions : public TestFixture {
9090
TEST_CASE(attributeMaybeUnused);
9191
}
9292

93+
struct CheckOptions
94+
{
95+
CheckOptions() = default;
96+
Platform::Type platform = Platform::Type::Native;
97+
const Settings* s = nullptr;
98+
bool cpp = true;
99+
};
100+
93101
#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)
94102
template<size_t size>
95-
void check_(const char* file, int line, const char (&code)[size], Platform::Type platform = Platform::Type::Native, const Settings *s = nullptr, bool cpp = true) {
96-
const Settings settings1 = settingsBuilder(s ? *s : settings).platform(platform).build();
103+
void check_(const char* file, int line, const char (&code)[size], const CheckOptions& options = make_default_obj()) {
104+
const Settings settings1 = settingsBuilder(options.s ? *options.s : settings).platform(options.platform).build();
97105

98106
// Tokenize..
99107
SimpleTokenizer tokenizer(settings1, *this);
100-
ASSERT_LOC(tokenizer.tokenize(code, cpp), file, line);
108+
ASSERT_LOC(tokenizer.tokenize(code, options.cpp), file, line);
101109

102110
// Check for unused functions..
103111
CheckUnusedFunctions checkUnusedFunctions;
@@ -691,10 +699,10 @@ class TestUnusedFunctions : public TestFixture {
691699

692700
const Settings s = settingsBuilder(settings).library("windows.cfg").build();
693701

694-
check("int WinMain() { }", Platform::Type::Native, &s);
702+
check("int WinMain() { }", dinit(CheckOptions, $.s = &s));
695703
ASSERT_EQUALS("", errout_str());
696704

697-
check("int _tmain() { }", Platform::Type::Native, &s);
705+
check("int _tmain() { }", dinit(CheckOptions, $.s = &s));
698706
ASSERT_EQUALS("", errout_str());
699707
}
700708

@@ -707,10 +715,10 @@ class TestUnusedFunctions : public TestFixture {
707715

708716
const Settings s = settingsBuilder(settings).library("windows.cfg").build();
709717

710-
check("int wWinMain() { }", Platform::Type::Native, &s);
718+
check("int wWinMain() { }", dinit(CheckOptions, $.s = &s));
711719
ASSERT_EQUALS("", errout_str());
712720

713-
check("int _tmain() { }", Platform::Type::Native, &s);
721+
check("int _tmain() { }", dinit(CheckOptions, $.s = &s));
714722
ASSERT_EQUALS("", errout_str());
715723
}
716724

@@ -723,7 +731,7 @@ class TestUnusedFunctions : public TestFixture {
723731
const Settings s = settingsBuilder(settings).library("gnu.cfg").build();
724732

725733
check("int _init() { }\n"
726-
"int _fini() { }\n", Platform::Type::Native, &s);
734+
"int _fini() { }\n", dinit(CheckOptions, $.s = &s));
727735
ASSERT_EQUALS("", errout_str());
728736
}
729737

@@ -811,10 +819,10 @@ class TestUnusedFunctions : public TestFixture {
811819

812820
void attributeMaybeUnused()
813821
{
814-
check("[[__maybe_unused__]] void f() {}\n", Platform::Type::Native, nullptr, false);
822+
check("[[__maybe_unused__]] void f() {}\n", dinit(CheckOptions, $.cpp = false));
815823
ASSERT_EQUALS("", errout_str());
816824

817-
check("[[maybe_unused]] void f() {}\n", Platform::Type::Native, nullptr, false);
825+
check("[[maybe_unused]] void f() {}\n", dinit(CheckOptions, $.cpp = false));
818826
ASSERT_EQUALS("", errout_str());
819827

820828
check("[[maybe_unused]] void f() {}\n");

0 commit comments

Comments
 (0)