From 9cbd0b8e24e752c509164ea52deea09e7ca7a695 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 6 Oct 2024 14:32:19 -0400 Subject: Clean up lilv_expand() unit tests Factor out the pattern of checking an expansion for an expected result, and eliminate mutation. --- test/test_string.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'test') 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 +// Copyright 2007-2024 David Robillard // SPDX-License-Identifier: ISC #undef NDEBUG @@ -15,32 +15,35 @@ #include #include +#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 -- cgit v1.2.1