Skip to content

Commit 018403c

Browse files
ehusspietroalbini
authored andcommitted
Add test for config Value in TOML array.
1 parent cf716fc commit 018403c

File tree

1 file changed

+57
-1
lines changed

1 file changed

+57
-1
lines changed

tests/testsuite/config.rs

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Tests for config settings.
22
33
use cargo::core::{PackageIdSpec, Shell};
4-
use cargo::util::config::{self, Config, SslVersionConfig, StringList};
4+
use cargo::util::config::{self, Config, Definition, SslVersionConfig, StringList};
55
use cargo::util::interning::InternedString;
66
use cargo::util::toml::{self, VecStringOrBool as VSOB};
77
use cargo::CargoResult;
@@ -1508,3 +1508,59 @@ fn all_profile_options() {
15081508
let roundtrip_toml = toml_edit::easy::to_string(&roundtrip).unwrap();
15091509
compare::assert_match_exact(&profile_toml, &roundtrip_toml);
15101510
}
1511+
1512+
#[cargo_test]
1513+
fn value_in_array() {
1514+
// Value<String> in an array should work
1515+
let root_path = paths::root().join(".cargo/config.toml");
1516+
write_config_at(
1517+
&root_path,
1518+
"\
1519+
[net.ssh]
1520+
known-hosts = [
1521+
\"example.com ...\",
1522+
\"example.net ...\",
1523+
]
1524+
",
1525+
);
1526+
1527+
let foo_path = paths::root().join("foo/.cargo/config.toml");
1528+
write_config_at(
1529+
&foo_path,
1530+
"\
1531+
[net.ssh]
1532+
known-hosts = [
1533+
\"example.org ...\",
1534+
]
1535+
",
1536+
);
1537+
1538+
let config = ConfigBuilder::new()
1539+
.cwd("foo")
1540+
// environment variables don't actually work for known-hosts due to
1541+
// space splitting, but this is included here just to validate that
1542+
// they work (particularly if other Vec<Value> config vars are added
1543+
// in the future).
1544+
.env("CARGO_NET_SSH_KNOWN_HOSTS", "env-example")
1545+
.build();
1546+
let net_config = config.net_config().unwrap();
1547+
let kh = net_config
1548+
.ssh
1549+
.as_ref()
1550+
.unwrap()
1551+
.known_hosts
1552+
.as_ref()
1553+
.unwrap();
1554+
assert_eq!(kh.len(), 4);
1555+
assert_eq!(kh[0].val, "example.org ...");
1556+
assert_eq!(kh[0].definition, Definition::Path(foo_path.clone()));
1557+
assert_eq!(kh[1].val, "example.com ...");
1558+
assert_eq!(kh[1].definition, Definition::Path(root_path.clone()));
1559+
assert_eq!(kh[2].val, "example.net ...");
1560+
assert_eq!(kh[2].definition, Definition::Path(root_path.clone()));
1561+
assert_eq!(kh[3].val, "env-example");
1562+
assert_eq!(
1563+
kh[3].definition,
1564+
Definition::Environment("CARGO_NET_SSH_KNOWN_HOSTS".to_string())
1565+
);
1566+
}

0 commit comments

Comments
 (0)