History

tempdir lives long enough for sure.

Svetlin Stefanov committed 4 years ago

Commit a41002f1 parent 8de6b3d1 file · +31 −17Browse files

Unified · Split

git-config/tests/file/from_paths/includes/conditional/gitdir.rs+31−17
@@ -74,11 +74,10 @@ fn assert_section_value( · 73 unmodified lines
7474 );
7575 }
7676
77−fn git_dir(root_dir: &TempDir, git_dir_suffix: &str) -> Box<Path> {
78− let git_dir = root_dir.path().join(git_dir_suffix).join(".git");
79− let git_dir = git_dir.as_path();
80− fs::create_dir_all(git_dir).unwrap();
81− git_dir.into()
77+fn git_dir(root_dir: &Path, git_dir_suffix: &str) -> PathBuf {
78+ let git_dir = root_dir.join(git_dir_suffix).join(".git");
79+ fs::create_dir_all(&git_dir).unwrap();
80+ git_dir
8281 }
8382
8483 fn write_config(condition: &str, git_dir: &Path, overwrite_config_location: &ConfigLocation) {
@@ -187,9 +186,11 @@ fn home() -> String { · 102 unmodified lines
187186 #[test]
188187 #[serial]
189188 fn relative_path_with_trailing_slash() {
189+ let temp_dir = tempdir().unwrap();
190+ let git_dir = git_dir(temp_dir.path(), "foo");
190191 assert_section_value(Options {
191192 condition: "gitdir:foo/",
192− git_dir: &git_dir(&tempdir().unwrap(), "foo"),
193+ git_dir: &git_dir,
193194 ..Default::default()
194195 });
195196 }
@@ -206,10 +207,11 @@ fn tilde_expansion() { · 10 unmodified lines
206207 .as_os_str()
207208 .to_str()
208209 .unwrap();
210+ let git_dir = git_dir(tmp_dir.path(), "foo");
209211
210212 assert_section_value(Options {
211213 condition: &format!("gitdir:~/{}/foo/", root),
212− git_dir: &git_dir(&tmp_dir, "foo"),
214+ git_dir: &git_dir,
213215 ..Default::default()
214216 });
215217 }
@@ -217,9 +219,11 @@ fn tilde_expansion() { · 1 unmodified line
217219 #[test]
218220 #[serial]
219221 fn star_star_prefix_and_suffix() {
222+ let temp_dir = tempdir().unwrap();
223+ let git_dir = git_dir(temp_dir.path(), "foo");
220224 assert_section_value(Options {
221225 condition: "gitdir:**/foo/**",
222− git_dir: &git_dir(&tempdir().unwrap(), "foo"),
226+ git_dir: &git_dir,
223227 ..Default::default()
224228 });
225229 }
@@ -227,9 +231,11 @@ fn star_star_prefix_and_suffix() { · 1 unmodified line
227231 #[test]
228232 #[serial]
229233 fn dot_path_slash() {
234+ let temp_dir = tempdir().unwrap();
235+ let git_dir = git_dir(temp_dir.path(), "foo");
230236 assert_section_value(Options {
231237 condition: "gitdir:./",
232− git_dir: &git_dir(&tempdir().unwrap(), "foo"),
238+ git_dir: &git_dir,
233239 config_location: ConfigLocation::User,
234240 ..Default::default()
235241 });
@@ -238,9 +244,11 @@ fn dot_path_slash() { · 2 unmodified lines
238244 #[test]
239245 #[serial]
240246 fn dot_path() {
247+ let temp_dir = tempdir().unwrap();
248+ let git_dir = git_dir(temp_dir.path(), "foo");
241249 assert_section_value(Options {
242250 condition: "gitdir:./foo/.git",
243− git_dir: &git_dir(&tempdir().unwrap(), "foo"),
251+ git_dir: &git_dir,
244252 config_location: ConfigLocation::User,
245253 ..Default::default()
246254 });
@@ -249,9 +257,11 @@ fn dot_path() { · 2 unmodified lines
249257 #[test]
250258 #[serial]
251259 fn case_insensitive() {
260+ let temp_dir = tempdir().unwrap();
261+ let git_dir = git_dir(temp_dir.path(), "foo");
252262 assert_section_value(Options {
253263 condition: "gitdir/i:FOO/",
254− git_dir: &git_dir(&tempdir().unwrap(), "foo"),
264+ git_dir: &git_dir,
255265 ..Default::default()
256266 });
257267 }
@@ -260,9 +270,11 @@ fn case_insensitive() { · 2 unmodified lines
260270 #[serial]
261271 #[ignore]
262272 fn pattern_with_backslash() {
273+ let temp_dir = tempdir().unwrap();
274+ let git_dir = git_dir(temp_dir.path(), "foo");
263275 assert_section_value(Options {
264276 condition: "gitdir:\\foo/",
265− git_dir: &git_dir(&tempdir().unwrap(), "foo"),
277+ git_dir: &git_dir,
266278 expected: Value::Original,
267279 ..Default::default()
268280 });
@@ -271,9 +283,11 @@ fn pattern_with_backslash() { · 2 unmodified lines
271283 #[test]
272284 #[serial]
273285 fn star_star_in_the_middle() {
286+ let temp_dir = tempdir().unwrap();
287+ let git_dir = git_dir(temp_dir.path(), "foo/bar");
274288 assert_section_value(Options {
275289 condition: "gitdir:**/foo/**/bar/**",
276− git_dir: &git_dir(&tempdir().unwrap(), "foo/bar"),
290+ git_dir: &git_dir,
277291 ..Default::default()
278292 });
279293 }
@@ -292,7 +306,7 @@ fn tilde_expansion_with_symlink() { · 12 unmodified lines
292306 .to_str()
293307 .unwrap();
294308
295− git_dir(&tmp_dir, "foo");
309+ let _ = git_dir(tmp_dir.path(), "foo");
296310 create_symlink(
297311 tmp_dir.path().join("bar").as_path(),
298312 tmp_dir.path().join("foo").as_path(),
@@ -310,7 +324,7 @@ fn tilde_expansion_with_symlink() { · 11 unmodified lines
310324 #[cfg(not(target_os = "windows"))]
311325 fn dot_path_with_symlink() {
312326 let tmp_dir = tempdir_in(home()).unwrap();
313− git_dir(&tmp_dir, "foo");
327+ git_dir(tmp_dir.path(), "foo");
314328 create_symlink(
315329 tmp_dir.path().join("bar").as_path(),
316330 tmp_dir.path().join("foo").as_path(),
@@ -328,7 +342,7 @@ fn dot_path_with_symlink() { · 11 unmodified lines
328342 #[cfg(not(target_os = "windows"))]
329343 fn dot_path_matching_symlink() {
330344 let tmp_dir = tempdir_in(home()).unwrap();
331− git_dir(&tmp_dir, "foo");
345+ git_dir(tmp_dir.path(), "foo");
332346 create_symlink(
333347 tmp_dir.path().join("bar").as_path(),
334348 tmp_dir.path().join("foo").as_path(),
@@ -346,7 +360,7 @@ fn dot_path_matching_symlink() { · 11 unmodified lines
346360 #[cfg(not(target_os = "windows"))]
347361 fn dot_path_matching_symlink_with_icase() {
348362 let tmp_dir = tempdir_in(home()).unwrap();
349− git_dir(&tmp_dir, "foo");
363+ git_dir(tmp_dir.path(), "foo");
350364 create_symlink(
351365 tmp_dir.path().join("bar").as_path(),
352366 tmp_dir.path().join("foo").as_path(),