Catch2: Catch Reports Exit Code 0 Even with Failed Tests

Created on 8 Mar 2018  路  7Comments  路  Source: catchorg/Catch2

Description

I am using Catch2 along with CMake to create a unit testing suite for my code. The testing framework itself works very well, but the problem is that catch returns an exit code of 0 even with failed tests (which makes no sense to me)

Steps to reproduce

Here is an example _without_ CMake that illustrates the problem.
I have a file main.cpp:

#define CATCH_CONFIG_MAIN
#include "Catch2.hpp"

int test()
{
    return 7;
}

TEST_CASE("should fail")
{
    REQUIRE(test() == 2);
}

Running this file gets me:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.out is a Catch v2.2.0 host application.
Run with -? for options

-------------------------------------------------------------------------------
should fail
-------------------------------------------------------------------------------
main.cpp:9
...............................................................................

main.cpp:11: FAILED:
  REQUIRE( test() == 2 )
with expansion:
  7 == 2

===============================================================================
test cases: 1 | 1 failed
assertions: 1 | 1 failed

And then:

echo $?

Results in the output 0.

Why isn't the exit code non-zero? I am using CTest, so if there is a failing test, then CTest doesn't report it. This makes the framework particularly useless if failing tests are not reported because otherwise, tests will always pass. How should I fix this so that the correct exit code is shown?

Extra information

  • Catch version: v2.2.0
  • Operating System: Ubuntu (Online on Cloud9 IDE)
  • Compiler+version: G++ 5.2
Serious bug

Most helpful comment

All 7 comments

Sorry, this is caused by incorrect clamping of return values in 355b3f99524.

A patch release fixing this and #1214 will be out late Sunday/Monday.

Well that was quick. Thank you! 馃憤

Hitting this issue, but was hard to find. How is this closed if not solved?

EDIT: Apologies, it is just that the latest single-header catch.hpp doesn't include it yet.

@phcerdan Yeah, we have to wait until Sunday/Monday. 馃榿

@arnavb I copied the fixed line into the old single header catch.hpp :sweat_smile:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Viatorus picture Viatorus  路  3Comments

maiermic picture maiermic  路  7Comments

jmeekhof picture jmeekhof  路  4Comments

aldanor picture aldanor  路  3Comments

RT222 picture RT222  路  4Comments