]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
test: Make subst_env_in_string not depend on existing environment
authorJoel Rosdahl <joel@rosdahl.net>
Wed, 5 Aug 2015 15:38:40 +0000 (17:38 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Wed, 5 Aug 2015 15:47:39 +0000 (17:47 +0200)
test/test_util.c

index 395546fe90a817d410ff7134435fac8ef66bb9f1..ce9ad44862112ef0fbd894ff21b55c7a9e5c3e55 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010-2014 Joel Rosdahl
+ * Copyright (C) 2010-2015 Joel Rosdahl
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by the Free
@@ -93,11 +93,11 @@ TEST(format_hash_as_string)
 TEST(subst_env_in_string)
 {
        char *errmsg;
-       const char *shell = getenv("SHELL");
 
-       errmsg = "";
-       CHECK_STR_EQ_FREE2(shell,
-                          subst_env_in_string("$SHELL", &errmsg));
+       putenv("FOO=bar");
+
+       CHECK_STR_EQ_FREE2("bar",
+                          subst_env_in_string("$FOO", &errmsg));
        CHECK(!errmsg);
 
        errmsg = "";
@@ -106,26 +106,26 @@ TEST(subst_env_in_string)
        CHECK(!errmsg);
 
        errmsg = "";
-       CHECK_STR_EQ_FREE12(format("%s %s:%s", shell, shell, shell),
-                           subst_env_in_string("$SHELL $SHELL:$SHELL", &errmsg));
+       CHECK_STR_EQ_FREE2("bar bar:bar",
+                          subst_env_in_string("$FOO $FOO:$FOO", &errmsg));
        CHECK(!errmsg);
 
        errmsg = "";
-       CHECK_STR_EQ_FREE12(format("x%s", shell),
-                           subst_env_in_string("x$SHELL", &errmsg));
+       CHECK_STR_EQ_FREE2("xbar",
+                          subst_env_in_string("x$FOO", &errmsg));
        CHECK(!errmsg);
 
        errmsg = "";
-       CHECK_STR_EQ_FREE12(format("%sx", shell),
-                           subst_env_in_string("${SHELL}x", &errmsg));
+       CHECK_STR_EQ_FREE2("barx",
+                          subst_env_in_string("${FOO}x", &errmsg));
        CHECK(!errmsg);
 
        CHECK(!subst_env_in_string("$surelydoesntexist", &errmsg));
        CHECK_STR_EQ_FREE2("environment variable \"surelydoesntexist\" not set",
                           errmsg);
 
-       CHECK(!subst_env_in_string("${SHELL", &errmsg));
-       CHECK_STR_EQ_FREE2("syntax error: missing '}' after \"SHELL\"", errmsg);
+       CHECK(!subst_env_in_string("${FOO", &errmsg));
+       CHECK_STR_EQ_FREE2("syntax error: missing '}' after \"FOO\"", errmsg);
 }
 
 TEST(format_human_readable_size)