diff options
author | EuAndreh <eu@euandre.org> | 2021-06-27 10:42:57 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2021-06-27 10:46:06 -0300 |
commit | 757c8963101a0bce5dbb5ad389acdcf7ceb2ecc4 (patch) | |
tree | 12e61b5eabb5be8634c506aeb37267041aa3390a /src/unit-test.h | |
parent | src/remembering-c.c: Add get_profile_file() (diff) | |
download | remembering-757c8963101a0bce5dbb5ad389acdcf7ceb2ecc4.tar.gz remembering-757c8963101a0bce5dbb5ad389acdcf7ceb2ecc4.tar.xz |
src/remembering-c.c: Add unit tests for get_profile_file()
Those tests led me to handling the case where $XDG_DATA_HOME was set,
but as an empty string. This is the equivalent of the "[ -z ".." ]"
test.
I also parameterized get_profile_file() to receive the stream where it
should write to in case of failing to getenv("HOME"). Even though this
makes the arguments of functions that print longer, it looks like an
overall good pattern. It is the equivalent of every sh function
printing to STDOUT, and let the caller decide if it should go to STDOUT
or STDERR.
Diffstat (limited to '')
-rw-r--r-- | src/unit-test.h | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/unit-test.h b/src/unit-test.h new file mode 100644 index 0000000..1dcd53c --- /dev/null +++ b/src/unit-test.h @@ -0,0 +1,23 @@ +#ifndef UNIT_TEST_H +#define UNIT_TEST_H + +#include <assert.h> + +#define COLOUR_RESET "\033[0m" +#define COLOUR_RED "\033[0;31m" +#define COLOUR_GREEN "\033[0;32m" +#define COLOUR_YELLOW "\033[0;33m" + +void testing(const char *const message) { + fprintf(stderr, "testing: " COLOUR_YELLOW "%s" COLOUR_RESET "...", message); +} + +void test_ok() { + fprintf(stderr, " " COLOUR_GREEN "OK" COLOUR_RESET ".\n"); +} + +#define ASSERT_MSG "\n" COLOUR_RED "ERROR" COLOUR_RESET ": " +#define assertf(A, M, ...) if (!(A)) { fprintf(stderr, (ASSERT_MSG M "\n"), __VA_ARGS__); assert(A); } +#define asserte(A) if (!(A)) { fprintf(stderr, ASSERT_MSG "\n"); assert(A); } + +#endif |