[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

unit_test_teardown


Hi,

I'm trying to create a unit test with no setup and a teardown function.
Like in the code below:

static void teardown_testing(void **state)
{
        free(*state);
}

static void testing(void **state)
{
        *state = malloc(1);
        assert_non_null(*state);
}

int main(int argc, char *argv[])
{
        (void)argc;
        (void)argv;

        const UnitTest tests[] = {
                unit_test_teardown(testing, teardown_testing),
        };

        return run_tests(tests);
}

This code fails to compile, however this is the way I exepected cmocka
to work. Please correct me if I'm wrong.
However I think the problem is with the definition of the
unit_test_teardown macro.
Examining the macro shows that unit_test_teardown(test, teardown) is
expanded to:
_unit_test_setup(test, setup), \
unit_test(test), \
_unit_test_teardown(test, teardown)

However, there is no setup in the unit_test_teardown macro arguments,
causing gcc to give an error about missing setup.

Regards,

Jan


Follow-Ups:
Re: unit_test_teardownAndreas Schneider <asn@xxxxxxxxxxxxxx>