dimanche 6 mars 2016

GoogleTest: what does statement mean?

From the documentation for ASSERT_NO_THROW, we find that it is defined as:

ASSERT_NO_THROW(statement);

What I expected was that statement is any valid statement in C++.
In particular, consider the following example:

#include <gtest/gtest.h>

void f() {
    int i;
    i = 0, 0;
}

TEST(Foo, Bar) {
    ASSERT_NO_THROW(f());
}

This example compiles (of course, if you want to try it you have to link both libgtest.a and libgtest_main.a).
In this case, statement is a function call.
Now consider the following example:

#include <gtest/gtest.h>

TEST(Foo, Bar) {
    ASSERT_NO_THROW({
        int i;
        i = 0, 0;
    });
}

This is the example previously shown, even though this time I have written the body of the function f as a statement for the ASSERT_NO_THROW macro.
It results in the following error:

error: macro "ASSERT_NO_THROW" passed 2 arguments, but takes just 1

The question is quite simple indeed: what does GoogleTest consider as a statement for the ASSERT_NO_THROW macro and, more in general, all throughout its macros?

I've already looked over the documentation, but I've not been able to find something that would depict my example as wrong.

Aucun commentaire:

Enregistrer un commentaire