Skip to content

Commit bf662f7

Browse files
committed
tests: always unlink created config files
While our tests in config::include create a plethora of configuration files, most of them do not get removed at the end of each test. This can cause weird interactions with tests that are being run at a later stage if these later tests try to create files or directories with the same name as any of the created configuration files. Fix the issue by unlinking all created files at the end of these tests.
1 parent b95c79a commit bf662f7

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

tests/config/include.c

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ void test_config_include__absolute(void)
3535

3636
cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar.baz"));
3737
cl_assert_equal_s("huzzah", git_buf_cstr(&buf));
38+
39+
cl_git_pass(p_unlink("config-include-absolute"));
3840
}
3941

4042
void test_config_include__homedir(void)
@@ -48,6 +50,8 @@ void test_config_include__homedir(void)
4850
cl_assert_equal_s("huzzah", git_buf_cstr(&buf));
4951

5052
cl_sandbox_set_search_path_defaults();
53+
54+
cl_git_pass(p_unlink("config-include-homedir"));
5155
}
5256

5357
/* We need to pretend that the variables were defined where the file was included */
@@ -66,6 +70,9 @@ void test_config_include__ordering(void)
6670
git_buf_clear(&buf);
6771
cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar.baz"));
6872
cl_assert_equal_s("huzzah", git_buf_cstr(&buf));
73+
74+
cl_git_pass(p_unlink("included"));
75+
cl_git_pass(p_unlink("including"));
6976
}
7077

7178
/* We need to pretend that the variables were defined where the file was included */
@@ -76,8 +83,8 @@ void test_config_include__depth(void)
7683

7784
cl_git_fail(git_config_open_ondisk(&cfg, "a"));
7885

79-
p_unlink("a");
80-
p_unlink("b");
86+
cl_git_pass(p_unlink("a"));
87+
cl_git_pass(p_unlink("b"));
8188
}
8289

8390
void test_config_include__missing(void)
@@ -89,6 +96,8 @@ void test_config_include__missing(void)
8996
cl_assert(giterr_last() == NULL);
9097
cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar"));
9198
cl_assert_equal_s("baz", git_buf_cstr(&buf));
99+
100+
cl_git_pass(p_unlink("including"));
92101
}
93102

94103
void test_config_include__missing_homedir(void)
@@ -103,6 +112,7 @@ void test_config_include__missing_homedir(void)
103112
cl_assert_equal_s("baz", git_buf_cstr(&buf));
104113

105114
cl_sandbox_set_search_path_defaults();
115+
cl_git_pass(p_unlink("including"));
106116
}
107117

108118
#define replicate10(s) s s s s s s s s s s
@@ -122,6 +132,10 @@ void test_config_include__depth2(void)
122132
git_buf_clear(&buf);
123133
cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar2"));
124134
cl_assert_equal_s("baz2", git_buf_cstr(&buf));
135+
136+
cl_git_pass(p_unlink("top-level"));
137+
cl_git_pass(p_unlink("middle"));
138+
cl_git_pass(p_unlink("bottom"));
125139
}
126140

127141
void test_config_include__removing_include_removes_values(void)
@@ -132,6 +146,9 @@ void test_config_include__removing_include_removes_values(void)
132146
cl_git_pass(git_config_open_ondisk(&cfg, "top-level"));
133147
cl_git_mkfile("top-level", "");
134148
cl_git_fail(git_config_get_string_buf(&buf, cfg, "foo.bar"));
149+
150+
cl_git_pass(p_unlink("top-level"));
151+
cl_git_pass(p_unlink("included"));
135152
}
136153

137154
void test_config_include__rewriting_include_refreshes_values(void)
@@ -145,6 +162,10 @@ void test_config_include__rewriting_include_refreshes_values(void)
145162
cl_git_fail(git_config_get_string_buf(&buf, cfg, "foo.bar"));
146163
cl_git_pass(git_config_get_string_buf(&buf, cfg, "first.other"));
147164
cl_assert_equal_s(buf.ptr, "value");
165+
166+
cl_git_pass(p_unlink("top-level"));
167+
cl_git_pass(p_unlink("first"));
168+
cl_git_pass(p_unlink("second"));
148169
}
149170

150171
void test_config_include__included_variables_cannot_be_deleted(void)
@@ -154,13 +175,20 @@ void test_config_include__included_variables_cannot_be_deleted(void)
154175

155176
cl_git_pass(git_config_open_ondisk(&cfg, "top-level"));
156177
cl_git_fail(git_config_delete_entry(cfg, "foo.bar"));
178+
179+
cl_git_pass(p_unlink("top-level"));
180+
cl_git_pass(p_unlink("included"));
157181
}
158182

159183
void test_config_include__included_variables_cannot_be_modified(void)
160184
{
161185
cl_git_mkfile("top-level", "[include]\npath = included\n");
186+
162187
cl_git_mkfile("included", "[foo]\nbar = value");
163188

164189
cl_git_pass(git_config_open_ondisk(&cfg, "top-level"));
165190
cl_git_fail(git_config_set_string(cfg, "foo.bar", "other-value"));
191+
192+
cl_git_pass(p_unlink("top-level"));
193+
cl_git_pass(p_unlink("included"));
166194
}

0 commit comments

Comments
 (0)