diff options
Diffstat (limited to 'test/test_string.c')
-rw-r--r-- | test/test_string.c | 43 |
1 files changed, 18 insertions, 25 deletions
diff --git a/test/test_string.c b/test/test_string.c index 2d610bb..48021ed 100644 --- a/test/test_string.c +++ b/test/test_string.c @@ -1,20 +1,5 @@ -/* - Copyright 2007-2020 David Robillard <d@drobilla.net> - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ - -#define _POSIX_C_SOURCE 200809L /* for setenv */ +// Copyright 2007-2020 David Robillard <d@drobilla.net> +// SPDX-License-Identifier: ISC #undef NDEBUG @@ -36,19 +21,27 @@ main(void) #ifndef _WIN32 char* s = NULL; + const char* const home = getenv("HOME"); + setenv("LILV_TEST_1", "test", 1); - char* home_foo = lilv_strjoin(getenv("HOME"), "/foo", NULL); + assert(!strcmp((s = lilv_expand("$LILV_TEST_1")), "test")); free(s); - assert(!strcmp((s = lilv_expand("~")), getenv("HOME"))); - free(s); - assert(!strcmp((s = lilv_expand("~foo")), "~foo")); - free(s); - assert(!strcmp((s = lilv_expand("~/foo")), home_foo)); - free(s); + if (home) { + assert(!strcmp((s = lilv_expand("~")), home)); + free(s); + assert(!strcmp((s = lilv_expand("~foo")), "~foo")); + free(s); + + char* const home_foo = lilv_strjoin(home, "/foo", NULL); + assert(!strcmp((s = lilv_expand("~/foo")), home_foo)); + free(s); + free(home_foo); + } + assert(!strcmp((s = lilv_expand("$NOT_A_VAR")), "$NOT_A_VAR")); free(s); - free(home_foo); + unsetenv("LILV_TEST_1"); #endif |