diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2020-04-17 09:38:43 +0200 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2020-04-17 09:38:43 +0200 |
commit | 15250710c63a2c3d230304e46a03532f787759fb (patch) | |
tree | 9fda47ad94248d133b7b48c67eba20d357c6694e /tests/filename_sane.c | |
parent | 6b3e6d299d5298a5936dbba57f67cdfc4a406789 (diff) |
tests: improve diagnostics output & make "release builds" work
This commit adds a few macros and helper functions for the unit test
programs. Those are used instead of asserts to provide more fine
grained diagnostics on the one hand and on the other hand because
they also work if NDEBUG is defined, unlike asserts that get eliminated
in that case.
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'tests/filename_sane.c')
-rw-r--r-- | tests/filename_sane.c | 48 |
1 files changed, 37 insertions, 11 deletions
diff --git a/tests/filename_sane.c b/tests/filename_sane.c index a9f7224..3c1fd4f 100644 --- a/tests/filename_sane.c +++ b/tests/filename_sane.c @@ -6,11 +6,7 @@ */ #include "config.h" #include "fstree.h" - -#include <string.h> -#include <stdlib.h> -#include <assert.h> -#include <stdio.h> +#include "test.h" static const char *must_work[] = { "foobar", @@ -48,18 +44,48 @@ int main(void) size_t i; for (i = 0; must_work[i] != NULL; ++i) { - assert(is_filename_sane(must_work[i], false)); - assert(is_filename_sane(must_work[i], true)); + if (!is_filename_sane(must_work[i], false)) { + fprintf(stderr, "%s was rejected!\n", must_work[i]); + return EXIT_FAILURE; + } + + if (!is_filename_sane(must_work[i], true)) { + fprintf(stderr, + "%s was rejected when testing for " + "OS specific stuff!\n", must_work[i]); + return EXIT_FAILURE; + } } for (i = 0; must_not_work[i] != NULL; ++i) { - assert(!is_filename_sane(must_not_work[i], false)); - assert(!is_filename_sane(must_not_work[i], true)); + if (is_filename_sane(must_not_work[i], false)) { + fprintf(stderr, "%s was accepted!\n", + must_not_work[i]); + return EXIT_FAILURE; + } + + if (is_filename_sane(must_not_work[i], true)) { + fprintf(stderr, + "%s was accepted when testing for " + "OS specific stuff!\n", must_not_work[i]); + return EXIT_FAILURE; + } } for (i = 0; must_not_work_here[i] != NULL; ++i) { - assert( is_filename_sane(must_not_work_here[i], false)); - assert(!is_filename_sane(must_not_work_here[i], true)); + if (!is_filename_sane(must_not_work_here[i], false)) { + fprintf(stderr, + "%s was rejected in the generic test!\n", + must_not_work_here[i]); + return EXIT_FAILURE; + } + + if (is_filename_sane(must_not_work_here[i], true)) { + fprintf(stderr, + "%s was accepted when testing for " + "OS specific stuff!\n", must_not_work_here[i]); + return EXIT_FAILURE; + } } return EXIT_SUCCESS; |