diff options
author | Steven Le Rouzic <steven.lerouzic@gmail.com> | 2024-10-28 23:52:48 +0100 |
---|---|---|
committer | Steven Le Rouzic <steven.lerouzic@gmail.com> | 2024-12-20 15:35:58 +0100 |
commit | 2a10eaae094e48a157d55ec886aaa07b0d0be6c9 (patch) | |
tree | e334ce5d2de1604eb168a3269be887bbc078df70 /asl/testing | |
parent | 46cc6bfc5f62bb45427ef7778ba5fc04d7a546da (diff) |
Some work on test framework & option
Diffstat (limited to 'asl/testing')
-rw-r--r-- | asl/testing/testing.cpp | 20 | ||||
-rw-r--r-- | asl/testing/testing.hpp | 8 |
2 files changed, 18 insertions, 10 deletions
diff --git a/asl/testing/testing.cpp b/asl/testing/testing.cpp index f0c4fb5..405df34 100644 --- a/asl/testing/testing.cpp +++ b/asl/testing/testing.cpp @@ -25,14 +25,14 @@ void asl::testing::report_failure(const char* msg, const char* file, int line) {
asl::eprint("--------------------------------------------------------------\n");
asl::eprint("Test assertion failed at {}, line {}:\n", file, line);
- asl::eprint(" {}:\n", msg);
+ asl::eprint(" {}\n", msg);
asl::eprint("--------------------------------------------------------------\n");
g_current_test_fail = true;
}
#define RESET "\x1b[0m"
-#define RED "\x1b[0;31m"
-#define GREEN "\x1b[0;32m"
+#define RED(S) "\x1b[0;31m" S RESET
+#define GREEN(S) "\x1b[0;32m" S RESET
int main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[])
{
@@ -41,33 +41,33 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[]) for (auto* it = g_head; it != nullptr; it = it->m_next)
{
- asl::eprint(GREEN "[ RUN ]" RESET " {}\n", it->m_case_name);
+ asl::eprint(GREEN("[ RUN ]") " {}\n", it->m_case_name);
g_current_test_fail = false;
it->m_fn();
if (!g_current_test_fail)
{
- asl::eprint(GREEN "[ OK ]" RESET " {}\n", it->m_case_name);
+ asl::eprint(GREEN("[ OK ]") " {}\n", it->m_case_name);
pass += 1;
}
else
{
- asl::eprint(RED "[ FAILED ]" RESET " {}\n", it->m_case_name);
+ asl::eprint(RED("[ FAILED ]") " {}\n", it->m_case_name);
fail += 1;
}
}
- asl::eprint(GREEN "[----------]" RESET " {} test(s) run\n", fail + pass);
+ asl::eprint(GREEN("[----------]") " {} test(s) run\n", fail + pass);
if (fail == 0)
{
- asl::eprint(GREEN "[ PASSED ]" RESET " Good job!\n");
+ asl::eprint(GREEN("[ PASSED ]") " Good job!\n");
}
else
{
- asl::eprint(RED "[ FAILED ]" RESET " {} test(s) failed\n", fail);
+ asl::eprint(RED("[ FAILED ]") " {} test(s) failed\n", fail);
}
- return 0;
+ return fail;
}
diff --git a/asl/testing/testing.hpp b/asl/testing/testing.hpp index 4fe44df..bf8f54e 100644 --- a/asl/testing/testing.hpp +++ b/asl/testing/testing.hpp @@ -36,3 +36,11 @@ struct Test #CASE, \
asl_test_fn_##CASE); \
void asl_test_fn_##CASE()
+
+#define ASL_TEST_ASSERT(EXPR) \
+ if (EXPR) {} \
+ else { ::asl::testing::report_failure(#EXPR, __FILE__, __LINE__); return; }
+
+#define ASL_TEST_EXPECT(EXPR) \
+ if (EXPR) {} \
+ else { ::asl::testing::report_failure(#EXPR, __FILE__, __LINE__); }
|