Skip to content

Commit

Permalink
TestUnusedFunctions: cleaned up by using an object to pass the options
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave committed Jan 7, 2025
1 parent 0fdc470 commit 7b77918
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions test/testunusedfunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<size_t size>
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;
Expand Down Expand Up @@ -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());
}

Expand All @@ -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());
}

Expand All @@ -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());
}

Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 7b77918

Please sign in to comment.