Skip to content

Commit bf0ec84

Browse files
committed
test(cargo-config): print array of any types
This demonstrates what we have supported today: no nested arrays
1 parent 284eefc commit bf0ec84

File tree

1 file changed

+180
-0
lines changed
  • tests/testsuite/cargo_config

1 file changed

+180
-0
lines changed

tests/testsuite/cargo_config/mod.rs

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,48 @@ fn common_setup() -> PathBuf {
6868
sub_folder
6969
}
7070

71+
fn array_setup() -> PathBuf {
72+
let home = paths::home();
73+
write_config_at(
74+
home.join(".cargo/config.toml"),
75+
r#"
76+
ints = [1, 2, 3]
77+
78+
bools = [true, false, true]
79+
80+
strings = ["hello", "world", "test"]
81+
82+
nested_ints = [[1, 2], [3, 4]]
83+
nested_bools = [[true], [false, true]]
84+
nested_strings = [["a", "b"], ["3", "4"]]
85+
nested_tables = [
86+
[
87+
{ x = "a" },
88+
{ x = "b" },
89+
],
90+
[
91+
{ x = "c" },
92+
{ x = "d" },
93+
],
94+
]
95+
deeply_nested = [[
96+
{ x = [[[ { x = [], y = 2 } ]]], y = 1 },
97+
]]
98+
99+
mixed = [{ x = 1 }, true, [false], "hello", 123]
100+
101+
[[tables]]
102+
name = "first"
103+
value = 1
104+
[[tables]]
105+
name = "second"
106+
value = 2
107+
108+
"#,
109+
);
110+
home
111+
}
112+
71113
#[cargo_test]
72114
fn get_toml() {
73115
// Notes:
@@ -171,6 +213,51 @@ profile.dev.opt-level = 3
171213
.run();
172214
}
173215

216+
#[cargo_test]
217+
fn get_toml_with_array_any_types() {
218+
let cwd = &array_setup();
219+
cargo_process("config get -Zunstable-options")
220+
.cwd(cwd)
221+
.masquerade_as_nightly_cargo(&["cargo-config"])
222+
.with_status(101)
223+
.with_stdout_data(str![""])
224+
.with_stderr_data(str![[r#"
225+
[ERROR] could not load Cargo configuration
226+
227+
Caused by:
228+
failed to load TOML configuration from `[ROOT]/home/.cargo/config.toml`
229+
230+
Caused by:
231+
failed to parse config at `ints[0]`
232+
233+
Caused by:
234+
expected string but found integer at index 0
235+
236+
"#]])
237+
.run();
238+
239+
// Unfortunately there is no TOML syntax to index an array item.
240+
cargo_process("config get tables -Zunstable-options")
241+
.cwd(cwd)
242+
.masquerade_as_nightly_cargo(&["cargo-config"])
243+
.with_status(101)
244+
.with_stdout_data(str![""])
245+
.with_stderr_data(str![[r#"
246+
[ERROR] could not load Cargo configuration
247+
248+
Caused by:
249+
failed to load TOML configuration from `[ROOT]/home/.cargo/config.toml`
250+
251+
Caused by:
252+
failed to parse config at `ints[0]`
253+
254+
Caused by:
255+
expected string but found integer at index 0
256+
257+
"#]])
258+
.run();
259+
}
260+
174261
#[cargo_test]
175262
fn get_json() {
176263
let sub_folder = common_setup();
@@ -300,6 +387,54 @@ CARGO_HOME=[ROOT]/home/.cargo
300387
.run();
301388
}
302389

390+
#[cargo_test]
391+
fn get_json_with_array_any_types() {
392+
let cwd = &array_setup();
393+
cargo_process("config get --format=json -Zunstable-options")
394+
.cwd(cwd)
395+
.masquerade_as_nightly_cargo(&["cargo-config"])
396+
.with_status(101)
397+
.with_stdout_data(str![""].is_json())
398+
.with_stderr_data(
399+
str![[r#"
400+
[ERROR] could not load Cargo configuration
401+
402+
Caused by:
403+
failed to load TOML configuration from `[ROOT]/home/.cargo/config.toml`
404+
405+
Caused by:
406+
failed to parse config at `ints[0]`
407+
408+
Caused by:
409+
expected string but found integer at index 0
410+
411+
"#]]
412+
.is_json(),
413+
)
414+
.run();
415+
416+
// Unfortunately there is no TOML syntax to index an array item.
417+
cargo_process("config get tables --format=json -Zunstable-options")
418+
.cwd(cwd)
419+
.masquerade_as_nightly_cargo(&["cargo-config"])
420+
.with_status(101)
421+
.with_stdout_data(str![""].is_json())
422+
.with_stderr_data(str![[r#"
423+
[ERROR] could not load Cargo configuration
424+
425+
Caused by:
426+
failed to load TOML configuration from `[ROOT]/home/.cargo/config.toml`
427+
428+
Caused by:
429+
failed to parse config at `ints[0]`
430+
431+
Caused by:
432+
expected string but found integer at index 0
433+
434+
"#]])
435+
.run();
436+
}
437+
303438
#[cargo_test]
304439
fn show_origin_toml() {
305440
let sub_folder = common_setup();
@@ -345,6 +480,51 @@ build.rustflags = [
345480
.run();
346481
}
347482

483+
#[cargo_test]
484+
fn show_origin_toml_with_array_any_types() {
485+
let cwd = &array_setup();
486+
cargo_process("config get --show-origin -Zunstable-options")
487+
.cwd(cwd)
488+
.masquerade_as_nightly_cargo(&["cargo-config"])
489+
.with_status(101)
490+
.with_stdout_data(str![""])
491+
.with_stderr_data(str![[r#"
492+
[ERROR] could not load Cargo configuration
493+
494+
Caused by:
495+
failed to load TOML configuration from `[ROOT]/home/.cargo/config.toml`
496+
497+
Caused by:
498+
failed to parse config at `ints[0]`
499+
500+
Caused by:
501+
expected string but found integer at index 0
502+
503+
"#]])
504+
.run();
505+
506+
// Unfortunately there is no TOML syntax to index an array item.
507+
cargo_process("config get tables --show-origin -Zunstable-options")
508+
.cwd(cwd)
509+
.masquerade_as_nightly_cargo(&["cargo-config"])
510+
.with_status(101)
511+
.with_stdout_data(str![""])
512+
.with_stderr_data(str![[r#"
513+
[ERROR] could not load Cargo configuration
514+
515+
Caused by:
516+
failed to load TOML configuration from `[ROOT]/home/.cargo/config.toml`
517+
518+
Caused by:
519+
failed to parse config at `ints[0]`
520+
521+
Caused by:
522+
expected string but found integer at index 0
523+
524+
"#]])
525+
.run();
526+
}
527+
348528
#[cargo_test]
349529
fn show_origin_toml_cli() {
350530
let sub_folder = common_setup();

0 commit comments

Comments
 (0)