summaryrefslogtreecommitdiff
path: root/tests/fstree_init.c
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-04-17 09:38:43 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-04-17 09:38:43 +0200
commit15250710c63a2c3d230304e46a03532f787759fb (patch)
tree9fda47ad94248d133b7b48c67eba20d357c6694e /tests/fstree_init.c
parent6b3e6d299d5298a5936dbba57f67cdfc4a406789 (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/fstree_init.c')
-rw-r--r--tests/fstree_init.c39
1 files changed, 18 insertions, 21 deletions
diff --git a/tests/fstree_init.c b/tests/fstree_init.c
index 3a526d1..5970159 100644
--- a/tests/fstree_init.c
+++ b/tests/fstree_init.c
@@ -8,11 +8,7 @@
#include "fstree.h"
#include "internal.h"
-
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-#include <stdio.h>
+#include "test.h"
int main(void)
{
@@ -20,32 +16,33 @@ int main(void)
char *str;
str = strdup("mtime=1337,uid=1000,gid=100,mode=0321");
- assert(str != NULL);
- assert(fstree_init(&fs, str) == 0);
+ TEST_NOT_NULL(str);
+ TEST_ASSERT(fstree_init(&fs, str) == 0);
free(str);
- assert(fs.defaults.st_mtime == 1337);
- assert(fs.defaults.st_uid == 1000);
- assert(fs.defaults.st_gid == 100);
- assert(fs.defaults.st_mode == (S_IFDIR | 0321));
+ TEST_EQUAL_UI(fs.defaults.st_mtime, 1337);
+ TEST_EQUAL_UI(fs.defaults.st_uid, 1000);
+ TEST_EQUAL_UI(fs.defaults.st_gid, 100);
+ TEST_EQUAL_UI(fs.defaults.st_mode, S_IFDIR | 0321);
fstree_cleanup(&fs);
- assert(fstree_init(&fs, NULL) == 0);
- assert(fs.defaults.st_mtime == 0 ||
- fs.defaults.st_mtime == get_source_date_epoch());
- assert(fs.defaults.st_uid == 0);
- assert(fs.defaults.st_gid == 0);
- assert(fs.defaults.st_mode == (S_IFDIR | 0755));
+ TEST_ASSERT(fstree_init(&fs, NULL) == 0);
+ if (fs.defaults.st_mtime != 0) {
+ TEST_EQUAL_UI(fs.defaults.st_mtime, get_source_date_epoch());
+ }
+ TEST_EQUAL_UI(fs.defaults.st_uid, 0);
+ TEST_EQUAL_UI(fs.defaults.st_gid, 0);
+ TEST_EQUAL_UI(fs.defaults.st_mode, S_IFDIR | 0755);
fstree_cleanup(&fs);
str = strdup("mode=07777");
- assert(str != NULL);
- assert(fstree_init(&fs, str) == 0);
+ TEST_NOT_NULL(str);
+ TEST_ASSERT(fstree_init(&fs, str) == 0);
free(str);
fstree_cleanup(&fs);
str = strdup("mode=017777");
- assert(str != NULL);
- assert(fstree_init(&fs, str) != 0);
+ TEST_NOT_NULL(str);
+ TEST_ASSERT(fstree_init(&fs, str) != 0);
free(str);
return EXIT_SUCCESS;