Skip to content

Commit 01277ac

Browse files
committed
test(config-include): inline-table and array-of-tables formats
Show that config `include` expects a string or list of strings
1 parent 6c0ff91 commit 01277ac

File tree

1 file changed

+146
-0
lines changed

1 file changed

+146
-0
lines changed

tests/testsuite/config_include.rs

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,3 +494,149 @@ fn cli_include_take_priority_over_env() {
494494
.build();
495495
assert_eq!(gctx.get::<String>("k").unwrap(), "include");
496496
}
497+
498+
#[cargo_test]
499+
fn inline_table_style() {
500+
write_config_at(
501+
".cargo/config.toml",
502+
"
503+
include = ['simple.toml', { path = 'other.toml' }]
504+
key1 = 1
505+
key2 = 2
506+
",
507+
);
508+
write_config_at(
509+
".cargo/simple.toml",
510+
"
511+
key2 = 3
512+
key3 = 4
513+
",
514+
);
515+
write_config_at(
516+
".cargo/other.toml",
517+
"
518+
key3 = 5
519+
key4 = 6
520+
",
521+
);
522+
523+
// Currently this fails with an error
524+
let gctx = GlobalContextBuilder::new()
525+
.unstable_flag("config-include")
526+
.build_err();
527+
assert_error(
528+
gctx.unwrap_err(),
529+
str![[r#"
530+
could not load Cargo configuration
531+
532+
Caused by:
533+
`include` expected a string or list of strings, but found table in list
534+
"#]],
535+
);
536+
}
537+
538+
#[cargo_test]
539+
fn array_of_tables_style() {
540+
write_config_at(
541+
".cargo/config.toml",
542+
"
543+
key1 = 1
544+
key2 = 2
545+
546+
[[include]]
547+
path = 'other1.toml'
548+
549+
[[include]]
550+
path = 'other2.toml'
551+
",
552+
);
553+
write_config_at(
554+
".cargo/other1.toml",
555+
"
556+
key2 = 3
557+
key3 = 4
558+
",
559+
);
560+
write_config_at(
561+
".cargo/other2.toml",
562+
"
563+
key3 = 5
564+
key4 = 6
565+
",
566+
);
567+
568+
// Currently this also fails with an error
569+
let gctx = GlobalContextBuilder::new()
570+
.unstable_flag("config-include")
571+
.build_err();
572+
assert_error(
573+
gctx.unwrap_err(),
574+
str![[r#"
575+
could not load Cargo configuration
576+
577+
Caused by:
578+
`include` expected a string or list of strings, but found table in list
579+
"#]],
580+
);
581+
}
582+
583+
#[cargo_test]
584+
fn table_with_unknown_fields() {
585+
// Unknown fields should be ignored for forward compatibility
586+
write_config_at(
587+
".cargo/config.toml",
588+
"
589+
key1 = 1
590+
591+
[[include]]
592+
path = 'other.toml'
593+
unknown_foo = true
594+
unknown_bar = 123
595+
",
596+
);
597+
write_config_at(
598+
".cargo/other.toml",
599+
"
600+
key2 = 2
601+
",
602+
);
603+
604+
let gctx = GlobalContextBuilder::new()
605+
.unstable_flag("config-include")
606+
.build_err();
607+
assert_error(
608+
gctx.unwrap_err(),
609+
str![[r#"
610+
could not load Cargo configuration
611+
612+
Caused by:
613+
`include` expected a string or list of strings, but found table in list
614+
"#]],
615+
);
616+
}
617+
618+
#[cargo_test]
619+
fn table_missing_required_field() {
620+
// Missing required field should fail
621+
write_config_at(
622+
".cargo/config.toml",
623+
"
624+
key1 = 1
625+
[[include]]
626+
random_field = true
627+
",
628+
);
629+
630+
let gctx = GlobalContextBuilder::new()
631+
.unstable_flag("config-include")
632+
.build_err();
633+
assert_error(
634+
gctx.unwrap_err(),
635+
str![[r#"
636+
could not load Cargo configuration
637+
638+
Caused by:
639+
`include` expected a string or list of strings, but found table in list
640+
"#]],
641+
);
642+
}

0 commit comments

Comments
 (0)