summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2024-10-06 14:32:19 -0400
committerDavid Robillard <d@drobilla.net>2024-10-11 14:10:27 -0400
commit9cbd0b8e24e752c509164ea52deea09e7ca7a695 (patch)
treeda2094a2c410a7e5af0f9f0293b3eb3caab98517 /test
parent0cf4d59c77f1d077a27cb5363de313681216a47a (diff)
downloadlilv-9cbd0b8e24e752c509164ea52deea09e7ca7a695.tar.gz
lilv-9cbd0b8e24e752c509164ea52deea09e7ca7a695.tar.bz2
lilv-9cbd0b8e24e752c509164ea52deea09e7ca7a695.zip
Clean up lilv_expand() unit tests
Factor out the pattern of checking an expansion for an expected result, and eliminate mutation.
Diffstat (limited to 'test')
-rw-r--r--test/test_string.c31
1 files changed, 17 insertions, 14 deletions
diff --git a/test/test_string.c b/test/test_string.c
index 028b7da..1ed387c 100644
--- a/test/test_string.c
+++ b/test/test_string.c
@@ -1,4 +1,4 @@
-// Copyright 2007-2020 David Robillard <d@drobilla.net>
+// Copyright 2007-2024 David Robillard <d@drobilla.net>
// SPDX-License-Identifier: ISC
#undef NDEBUG
@@ -15,32 +15,35 @@
#include <stdlib.h>
#include <string.h>
+#ifndef _WIN32
+static void
+check_expansion(const char* const path, const char* const expected)
+{
+ char* const expanded = lilv_expand(path);
+ assert(!strcmp(expanded, expected));
+ free(expanded);
+}
+#endif
+
int
main(void)
{
#ifndef _WIN32
- char* s = NULL;
-
setenv("LILV_TEST_1", "test", 1);
const char* const home = getenv("HOME");
- assert(!strcmp((s = lilv_expand("$LILV_TEST_1")), "test"));
- free(s);
- if (home) {
- assert(!strcmp((s = lilv_expand("~")), home));
- free(s);
- assert(!strcmp((s = lilv_expand("~foo")), "~foo"));
- free(s);
+ check_expansion("$LILV_TEST_1", "test");
+ if (home) {
char* const home_foo = lilv_strjoin(home, "/foo", NULL);
- assert(!strcmp((s = lilv_expand("~/foo")), home_foo));
- free(s);
+ check_expansion("~", home);
+ check_expansion("~foo", "~foo");
+ check_expansion("~/foo", home_foo);
free(home_foo);
}
- assert(!strcmp((s = lilv_expand("$NOT_A_VAR")), "$NOT_A_VAR"));
- free(s);
+ check_expansion("$NOT_A_VAR", "$NOT_A_VAR");
unsetenv("LILV_TEST_1");
#endif