From 6560116b67caa927b80b9c8c737f3ec0619847f4 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 2 Aug 2019 09:23:03 +0200 Subject: [PATCH] TestSuite: Hijack the ASSERT macros during unit tests. Instead of aborting the program when we hit an assertion, just print a message and keep going. This allows us to write tests that provoke assertions on purpose. --- AK/Assertions.h | 4 ++++ AK/TestSuite.h | 13 ++++++++++++- AK/Tests/TestHashMap.cpp | 1 + AK/Tests/TestJSON.cpp | 1 + AK/Tests/TestQueue.cpp | 1 + AK/Tests/TestString.cpp | 1 + AK/Tests/TestVector.cpp | 3 ++- 7 files changed, 22 insertions(+), 2 deletions(-) diff --git a/AK/Assertions.h b/AK/Assertions.h index af055bf42d..bced43f658 100644 --- a/AK/Assertions.h +++ b/AK/Assertions.h @@ -1,5 +1,7 @@ #pragma once +#ifndef AK_TEST_SUITE + #ifdef KERNEL # include #else @@ -11,6 +13,8 @@ # endif #endif +#endif + namespace AK { inline void not_implemented() { ASSERT(false); } diff --git a/AK/TestSuite.h b/AK/TestSuite.h index 655d073070..47b9ef58ae 100644 --- a/AK/TestSuite.h +++ b/AK/TestSuite.h @@ -1,10 +1,21 @@ #pragma once +#define AK_TEST_SUITE + +#include + +#define ASSERT(x) \ + if (!(x)) { \ + fprintf(stderr, "\033[33;1mASSERT\033[0m: " #x "\n"); \ + } + +#define ASSERT_NOT_REACHED() fprintf(stderr, "\033[31;1mASSERT_NOT_REACHED\033[0m\n"); +#define RELEASE_ASSERT ASSERT + #include "AKString.h" #include "Function.h" #include "NonnullRefPtrVector.h" #include -#include namespace AK { diff --git a/AK/Tests/TestHashMap.cpp b/AK/Tests/TestHashMap.cpp index 06ada64459..1c17eab5ff 100644 --- a/AK/Tests/TestHashMap.cpp +++ b/AK/Tests/TestHashMap.cpp @@ -1,4 +1,5 @@ #include + #include #include diff --git a/AK/Tests/TestJSON.cpp b/AK/Tests/TestJSON.cpp index 875ba6b99a..f101dd38a6 100644 --- a/AK/Tests/TestJSON.cpp +++ b/AK/Tests/TestJSON.cpp @@ -1,4 +1,5 @@ #include + #include #include #include diff --git a/AK/Tests/TestQueue.cpp b/AK/Tests/TestQueue.cpp index 23d30f5de2..620f7f9634 100644 --- a/AK/Tests/TestQueue.cpp +++ b/AK/Tests/TestQueue.cpp @@ -1,4 +1,5 @@ #include + #include #include diff --git a/AK/Tests/TestString.cpp b/AK/Tests/TestString.cpp index a8a926d1ec..db0d1d947a 100644 --- a/AK/Tests/TestString.cpp +++ b/AK/Tests/TestString.cpp @@ -1,4 +1,5 @@ #include + #include TEST_CASE(construct_empty) diff --git a/AK/Tests/TestVector.cpp b/AK/Tests/TestVector.cpp index c2a5736f85..1405ccfb4a 100644 --- a/AK/Tests/TestVector.cpp +++ b/AK/Tests/TestVector.cpp @@ -1,6 +1,7 @@ +#include + #include #include -#include #include TEST_CASE(construct)