diff options
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | include/moslib.h | 2 | ||||
| -rw-r--r-- | include/moslib/tester.h | 64 |
3 files changed, 58 insertions, 10 deletions
@@ -17,7 +17,7 @@ headers: sudo cp -r include/* /usr/local/include compile: memory structures - $(CC) $(CFLAGS) -c src/tests.c + $(CC) $(CFLAGS) -c src/tester.c memory: $(CC) $(CFLAGS) -c src/mem/alloc.c diff --git a/include/moslib.h b/include/moslib.h index a781a34..341db7e 100644 --- a/include/moslib.h +++ b/include/moslib.h @@ -4,4 +4,4 @@ #include "moslib/ds/array.h" #include "moslib/mem/alloc.h" -#include "moslib/tests.h" +#include "moslib/tester.h" diff --git a/include/moslib/tester.h b/include/moslib/tester.h index 1a548bc..0165257 100644 --- a/include/moslib/tester.h +++ b/include/moslib/tester.h @@ -1,19 +1,67 @@ // moslib/tester.h // Helper functions for writing and running tests +// ======================================== QUICK USAGE GUIDE ========================================= +// ---------------------------------------------------------------------------------------------------- +// +// Define the tester: +// +// Tester *tester = NULL; +// +// It will initialize on first operation. +// +// You can also initialize a tester from the get go: +// +// Tester *tester = new_tester(); +// +// ---------------------------------------------------------------------------------------------------- +// +// Add test groups: +// +// TestGroup *test_group = add_test_group(tester, group_name); +// +// ---------------------------------------------------------------------------------------------------- +// +// Create tests. +// Tests are of type TestFn (Test (*)()). +// They should use test_assert functions to check correctness. +// +// Example: +// Test test_fn() { +// int result1 = 1 + 2; +// int result2 = 3 + 5; +// +// test_assert(result1 == 3, "1 + 2 should equal 3"); +// test_assert(result2 == 8, "3 + 5 should equal 8"); +// } +// +// ---------------------------------------------------------------------------------------------------- +// +// Add tests to test group: +// +// add_test(test_group, test_fn); +// +// ---------------------------------------------------------------------------------------------------- +// +// Run tests: +// +// run_tests(tester); +// +// ---------------------------------------------------------------------------------------------------- +// +// Free tester: +// +// free_tester(tester); +// +// ---------------------------------------------------------------------------------------------------- +// ===================================== END OF QUICK USAGE GUIDE ===================================== + #ifndef MOSLIB_TESTER_H #define MOSLIB_TESTER_H typedef void Test; // this is just for nice indication that a function is a test typedef struct Tester Tester; typedef struct TestGroup TestGroup; -typedef Test (*TestFn)(TestGroup *); - -// Tester *tester = NULL; (new_tester()) -// TestGroup *test_group = add_test_group(Tester *tester, const char *group_name); -// add_test(TestGroup *test_group, TestFn test); -// test_assert(int expression, const char *error_message); -// run_tests(Tester *tester); -// free_tester(Tester *tester); +typedef Test (*TestFn)(); #endif // MOSLIB_TESTER_H |
