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

XML test failure output broken using legacy assertions ([(] should be [-853413863] but was [8096]) #291

Closed
DaStoned opened this issue Mar 7, 2022 · 2 comments

Comments

@DaStoned
Copy link

DaStoned commented Mar 7, 2022

XML output from a simple test with one OK and one broken results in XML files where output seems to be badly formatted. Jenkins JUnit plugin fails to parse the XML output below.

This is the unit test ut.c, compiled with gcc -o ut ut.c -I../cgreen/include -L$(pwd)/cgreen/src -lcgreen

#include <cgreen/cgreen.h>
#include <cgreen/xml_reporter.h>

// Entirely fake unit test

Describe(test_ps_observer);
BeforeEach(test_ps_observer) { }
AfterEach(test_ps_observer) { }

Ensure(test_ps_observer, AllIsGood) {
    assert_true(true);
}

Ensure(test_ps_observer, AllIsBad) {
    assert_equal(2, 3);
}

TestSuite *observer_test() {
    TestSuite *suite = create_test_suite();
    add_test_with_context(suite, test_ps_observer, AllIsGood);
    add_test_with_context(suite, test_ps_observer, AllIsBad);
    return suite;
}

int main(int argc, char* argv[]) {
    TestSuite *suite = create_test_suite();
    add_suite(suite, observer_test());
    return run_test_suite(suite, create_xml_reporter("foo"));
}

Resulting XML files are

$ cat foo-main.xml 
<?xml version="1.0" encoding="ISO-8859-1" ?>
<testsuite name="main">
</testsuite>
$ cat foo-main-observer_test.xml 
<?xml version="1.0" encoding="ISO-8859-1" ?>
        <testsuite name="main-observer_test">
                <testcase classname="main/observer_test" name="AllIsGood" time="0.00100">
                </testcase>
                <testcase classname="main/observer_test" name="AllIsBad" time="0.00100">
                        <failure message="[(] should be [-853413863] but was [8096]
">
                                <location file="ut.c" line="15"/>
                        </failure>
                </testcase>
        </testsuite>

There is a faulty line feed near the end of the 5th line, and it should probably look more like the text output:

ut.c:15: Failure: observer_test -> AllIsBad 
        [2] should be [3] but was [2]


  "observer_test": 1 pass, 1 failure in 2ms.
Completed "main": 1 pass, 1 failure in 2ms.

Built on Debian using gcc (Debian 11.2.0-16) 11.2.0 and Cgreen 1.4.1 from source.

@DaStoned DaStoned changed the title XML error output broken ([(] should be [-853413863] but was [8096]) XML test failure output broken ([(] should be [-853413863] but was [8096]) Mar 7, 2022
@thoni56
Copy link
Contributor

thoni56 commented Mar 7, 2022

Thanks for reporting this!

Not to say that this should not be fixed, if possible, but if you use the modern, and recommended, assertions:

Ensure(test_ps_observer, AllIsGood) {
    assert_that(true);
}

Ensure(test_ps_observer, AllIsBad) {
    assert_that(2, is_equal_to(3));
}

Then the XML-file seems to be generated as expected.

I'm unsure why this happens, but I'd recommend not using the legacy assertions. Testing is focused on the modern API since many years.

@thoni56 thoni56 changed the title XML test failure output broken ([(] should be [-853413863] but was [8096]) XML test failure output broken using legacy assertions ([(] should be [-853413863] but was [8096]) Mar 7, 2022
@DaStoned
Copy link
Author

DaStoned commented Mar 8, 2022

Ah, didn't notice that there are different generations. I just used the first thing that looked like a googletest assertion.

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

No branches or pull requests

2 participants