3 #include <darwintest.h>
5 T_DECL(setenv_getenv
, "getenv returns value set by setenv")
9 int setenv_rc
= setenv(name
, value
, 0);
10 T_EXPECT_EQ(0, setenv_rc
, "setenv must succeed with 0 return code");
11 char *getenv_result
= getenv(name
);
12 T_EXPECT_EQ_STR(value
, getenv_result
, "getenv must return setenv argument");
15 T_DECL(setenv_overwrite
, "getenv returns the latest setenv argument")
18 char *first_value
= "bar";
19 char *second_value
= "baz";
21 setenv_rc
= setenv(name
, first_value
, 0);
22 T_EXPECT_EQ(0, setenv_rc
, "setenv must succeed with 0 return code");
23 setenv_rc
= setenv(name
, second_value
, 1);
24 T_EXPECT_EQ(0, setenv_rc
, "setenv must succeed with 0 return code");
25 char *getenv_result
= getenv(name
);
26 T_EXPECT_EQ_STR(second_value
, getenv_result
, "getenv must return the latest setenv argument");
29 T_DECL(setenv_dont_overwrite
, "setenv respects overwrite")
32 char *first_value
= "bar";
33 char *second_value
= "baz";
35 setenv_rc
= setenv(name
, first_value
, 0);
36 T_EXPECT_EQ(0, setenv_rc
, "setenv must succeed with 0 return code");
37 setenv_rc
= setenv(name
, second_value
, 0);
38 T_EXPECT_EQ(0, setenv_rc
, "setenv must succeed with 0 return code");
39 char *getenv_result
= getenv(name
);
40 T_EXPECT_EQ_STR(first_value
, getenv_result
, "the second setenv must not overwrite the first one");
43 /* There are tests for leading '=' in values because BSDs used to strip them off: rdar://problem/19342460 */
45 T_DECL(setenv_accepts_leading_eq_sign
, "setenv accepts values starting with '='")
49 int setenv_rc
= setenv(name
, value
, 0);
50 T_EXPECT_EQ(0, setenv_rc
, "setenv must succeed with 0 return code");
51 char *getenv_result
= getenv(name
);
52 T_EXPECT_EQ_STR(value
, getenv_result
, "getenv must return setenv argument");
55 T_DECL(setenv_accepts_leading_eq_sign_overwrite
, "setenv accepts values starting with '=' when overwriting an existing value")
58 char *first_value
= "bar";
59 char *second_value
= "=baz";
61 setenv_rc
= setenv(name
, first_value
, 0);
62 T_EXPECT_EQ(0, setenv_rc
, "setenv must succeed with 0 return code");
63 setenv_rc
= setenv(name
, second_value
, 1);
64 T_EXPECT_EQ(0, setenv_rc
, "setenv must succeed with 0 return code");
65 char *getenv_result
= getenv(name
);
66 T_EXPECT_EQ_STR(second_value
, getenv_result
, "getenv must return the latest setenv argument");