Matthew Murdoch
Matthew Murdoch

Reputation: 31453

How can I remove the duplication between these C macros?

I have the following couple of C pre-processor macros for creating test functions:

// Defines a test function in the active suite
#define test(name)\
    void test_##name();\
    SuiteAppender test_##name##_appender(TestSuite::active(), test_##name);\
    void test_##name()

which is used like this:

test(TestName) {
    // Test code here
}

and

// Defines a test function in the specified suite
#define testInSuite(name, suite)\
    void test_##name();\
    SuiteAppender test_##name##_appender(suite, test_##name);\
    void test_##name()

which is used like this:

test(TestName, TestSuiteName) {
    // Test code here
}

How can I remove the duplication between the two macros?

Upvotes: 1

Views: 172

Answers (2)

Skizz
Skizz

Reputation: 71070

Try:

#define test(name) testInSuite (name, TestSuite::active())

Upvotes: 0

sharptooth
sharptooth

Reputation: 170499

#define test(name) testInSuite( name, TestSuite::active() )

However this doesn't reduce the amount of emitted C and machine code, only removes logical duplication.

Upvotes: 6

Related Questions