Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compilation error when using #define TEST_NO_MAIN #75

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

manugoyal
Copy link

I noticed the following compilation error when utilizing the TEST_NO_MAIN macro to split test definitions over multiple files:

../third_party/acutest/include/acutest.h:1991:5: error: extraneous closing brace ('}')
    }  /* extern "C" */
    ^
1 error generated.

To reproduce, create the following files in one directory.

tests.h

#pragma once

void test_failure();

tests.cc

#include "tests.h"

#define TEST_NO_MAIN
#include "acutest.h"

void test_failure() {
    TEST_CHECK(1 == 2);
}

test_runner.cc

#include "acutest.h"

#include "tests.h"

TEST_LIST = {
    { "test_failure", test_failure },
    { NULL, NULL },
};

Before this change, I see the error:

$ c++ -I ../third_party/acutest/include tests.cc test_runner.cc
In file included from tests.cc:4:
../third_party/acutest/include/acutest.h:1991:5: error: extraneous closing brace ('}')
    }  /* extern "C" */
    ^
1 error generated.

Afterwards, I get the desired output:

$ c++ -I ../third_party/acutest/include tests.cc test_runner.cc
$ ./a.out
Test test_failure...                            [ FAILED ]
  tests.cc:7: 1 == 2... failed
FAILED: 1 of 1 unit tests has failed.

I noticed the following compilation error when utilizing the
`TEST_NO_MAIN` macro to split test definitions over multiple files:

```
../third_party/acutest/include/acutest.h:1991:5: error: extraneous closing brace ('}')
    }  /* extern "C" */
    ^
1 error generated.
```

To reproduce, create the following files in one directory.

`tests.h`
```
#pragma once

void test_failure();
```

`tests.cc`
```
#include "tests.h"

#define TEST_NO_MAIN
#include "acutest.h"

void test_failure() {
    TEST_CHECK(1 == 2);
}
```

`test_runner.cc`
```
#include "acutest.h"

#include "tests.h"

TEST_LIST = {
    { "test_failure", test_failure },
    { NULL, NULL },
};
```

Before this change, I see the error:

```
$ c++ -I ../third_party/acutest/include tests.cc test_runner.cc
In file included from tests.cc:4:
../third_party/acutest/include/acutest.h:1991:5: error: extraneous closing brace ('}')
    }  /* extern "C" */
    ^
1 error generated.
```

Afterwards, I get the desired output:

```
$ c++ -I ../third_party/acutest/include tests.cc test_runner.cc
$ ./a.out
Test test_failure...                            [ FAILED ]
  tests.cc:7: 1 == 2... failed
FAILED: 1 of 1 unit tests has failed.
```
@amgross
Copy link
Contributor

amgross commented Sep 12, 2024

Seems like my bug in #70

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants