diff options
author | Louis Dionne <ldionne@apple.com> | 2019-03-25 16:44:08 +0000 |
---|---|---|
committer | Louis Dionne <ldionne@apple.com> | 2019-03-25 16:44:08 +0000 |
commit | e63f47549e222f1f446ee81feb846abe527e0173 (patch) | |
tree | 43827f223966ca8f07854d6b0396a849069dee19 /pstl/test | |
parent | 7e8476ddfa778bba17dac22949d81fc22fd944ff (diff) | |
download | llvm-e63f47549e222f1f446ee81feb846abe527e0173.zip llvm-e63f47549e222f1f446ee81feb846abe527e0173.tar.gz llvm-e63f47549e222f1f446ee81feb846abe527e0173.tar.bz2 |
[pstl] Make sure unit tests exit with a non-zero error code when they fail
The previous test system would only print errors to stderr, however CMake
(and lit) detect failure via the program returning a non-zero error code.
So all the tests would always pretend they passed.
llvm-svn: 356921
Diffstat (limited to 'pstl/test')
-rw-r--r-- | pstl/test/utils.h | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/pstl/test/utils.h b/pstl/test/utils.h index 8645ee3..438d453 100644 --- a/pstl/test/utils.h +++ b/pstl/test/utils.h @@ -10,14 +10,15 @@ // File contains common utilities that tests rely on // Do not #include <algorithm>, because if we do we will not detect accidental dependencies. -#include <sstream> -#include <iostream> +#include <atomic> +#include <cstdint> +#include <cstdlib> #include <cstring> +#include <iostream> #include <iterator> -#include <vector> -#include <atomic> #include <memory> -#include <cstdint> +#include <sstream> +#include <vector> #include "pstl_test_config.h" @@ -38,32 +39,30 @@ template <typename T> class Sequence; // Handy macros for error reporting -#define EXPECT_TRUE(condition, message) TestUtils::expect<true>(condition, __FILE__, __LINE__, message) -#define EXPECT_FALSE(condition, message) TestUtils::expect<false>(condition, __FILE__, __LINE__, message) +#define EXPECT_TRUE(condition, message) ::TestUtils::expect(true, condition, __FILE__, __LINE__, message) +#define EXPECT_FALSE(condition, message) ::TestUtils::expect(false, condition, __FILE__, __LINE__, message) // Check that expected and actual are equal and have the same type. -#define EXPECT_EQ(expected, actual, message) TestUtils::expect_equal(expected, actual, __FILE__, __LINE__, message) +#define EXPECT_EQ(expected, actual, message) ::TestUtils::expect_equal(expected, actual, __FILE__, __LINE__, message) // Check that sequences started with expected and actual and have had size n are equal and have the same type. #define EXPECT_EQ_N(expected, actual, n, message) \ - TestUtils::expect_equal(expected, actual, n, __FILE__, __LINE__, message) + ::TestUtils::expect_equal(expected, actual, n, __FILE__, __LINE__, message) // Issue error message from outstr, adding a newline. // Real purpose of this routine is to have a place to hang a breakpoint. -static void +inline void issue_error_message(std::stringstream& outstr) { outstr << std::endl; std::cerr << outstr.str(); + std::exit(EXIT_FAILURE); } -template <bool B> -void -expect(bool condition, const char* file, int32_t line, const char* message) +inline void +expect(bool expected, bool condition, const char* file, int32_t line, const char* message) { - // Templating this function is somewhat silly, but avoids the need to declare it static - // or have a separate translation unit. - if (condition != B) + if (condition != expected) { std::stringstream outstr; outstr << "error at " << file << ":" << line << " - " << message; |