From: Michael D. Lowis Date: Wed, 22 Feb 2017 01:48:02 +0000 (-0500) Subject: Updated README and removed unnecessary macro from atf.h X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=d62a05f2a5ad8088b43079cd2a6cb94f91ac3f14;p=projs%2Fatf.git Updated README and removed unnecessary macro from atf.h --- diff --git a/README.md b/README.md index 8701224..6cf9234 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,60 @@ -atf -=== +# Aardvark Test Framework + +A minimal unit testing framework for C distributed as a single-header library. + +# License + +This program is distributed under the terms of the ISC license as described in +[LICENSE.md](LICENSE.md) + +# Installation + +Simply copy [atf.h](atf.h) to a suitable include path for the desired project. + +# Macro API + +The framework is controlled through an extremely minimal of C preprocessor +macros. The macros are used to define test suites, define tests within suites, +and to perform actual conditional checks as part of the test. Below is a +comprehensive list of the macros provided and their function. + +```C +TEST_SUITE(name) {} // Define a new test suite with the given name +TEST(desc) {} // Define a new test with the given description +CHECK(cond) // Check that condition is true and mark test is failed if false +IGNORE(msg) // Mark a test as ignored with a message and skip its execution +EXPECT_EXIT {} // Setup test to expect the mock exit function to be called +CHECK_EXITCODE(code) // Checks that the mock exit function received the given exit code +RUN_TEST_SUITE(name) // Runs the specified test suite +RUN_EXTERN_TEST_SUITE(name) // Runs the specified test suite, the suite is externed first +INCLUDE_DEFS // Instructs the header to also include definitions of the API functions on include +``` + +# Example Usage + +```C +#define INCLUDE_DEFS +#include + +TEST_SUITE(ExampleTests) { + TEST(Check that 1 < 2) { + CHECK(1 < 2); + } + + TEST(Check that exit is called with 42) { + EXPECT_EXIT { exit(42); } + CHECK_EXITCODE(42); + } + + TEST(This test is ignored) { + IGNORE("Practice ignore"); + } +} + +int main(int argc, char** argv) { + atf_init(argc, argv); + RUN_TEST_SUITE(ExampleTests); + return atf_print_results(); +} +``` -Aardvark Test Framework diff --git a/atf.h b/atf.h index a486e79..f24e995 100755 --- a/atf.h +++ b/atf.h @@ -52,9 +52,6 @@ int atf_print_results(void); #define RUN_EXTERN_TEST_SUITE(name) \ do { extern TEST_SUITE(name); RUN_TEST_SUITE(name); } while(0) - -#define PRINT_TEST_RESULTS \ - atf_print_results #define EXPECT_EXIT \ if ((ExitExpected = true, 0 == setjmp(ExitPad)))