Skip to content

Commit 637da93

Browse files
committed
test(config-include): include always relative to including config
1 parent f3b7ff7 commit 637da93

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

tests/testsuite/config_include.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,46 @@ fn left_to_right_bottom_to_top() {
308308
assert_eq!(gctx.get::<i32>("left-bottom").unwrap(), -3);
309309
}
310310

311+
#[cargo_test]
312+
fn nested_include_resolves_relative_to_including_file() {
313+
write_config_at(
314+
".cargo/config.toml",
315+
"
316+
include = '../config/cargo.toml'
317+
",
318+
);
319+
write_config_at(
320+
"config/cargo.toml",
321+
"
322+
include = 'other.toml'
323+
middle = 10
324+
",
325+
);
326+
write_config_at(
327+
"config/other.toml",
328+
"
329+
nested = 42
330+
",
331+
);
332+
333+
// This should not be included,
334+
// because `include` path is resolved relative to the including config
335+
// (where the `include` is defined)
336+
write_config_at(
337+
".cargo/other.toml",
338+
"
339+
INVALID = SYNTAX
340+
",
341+
);
342+
343+
let gctx = GlobalContextBuilder::new()
344+
.unstable_flag("config-include")
345+
.build();
346+
347+
assert_eq!(gctx.get::<i32>("nested").unwrap(), 42);
348+
assert_eq!(gctx.get::<i32>("middle").unwrap(), 10);
349+
}
350+
311351
#[cargo_test]
312352
fn missing_file() {
313353
// Error when there's a missing file.

0 commit comments

Comments
 (0)