Skip to content

Commit a982bcc

Browse files
committed
add more debuginfo tests
1 parent 8a9db7a commit a982bcc

File tree

1 file changed

+58
-1
lines changed

1 file changed

+58
-1
lines changed

tests/testsuite/config.rs

+58-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use cargo::core::{PackageIdSpec, Shell};
44
use cargo::util::config::{self, Config, Definition, SslVersionConfig, StringList};
55
use cargo::util::interning::InternedString;
6-
use cargo::util::toml::{self as cargo_toml, VecStringOrBool as VSOB};
6+
use cargo::util::toml::{self as cargo_toml, TomlDebugInfo, VecStringOrBool as VSOB};
77
use cargo::CargoResult;
88
use cargo_test_support::compare;
99
use cargo_test_support::{panic_error, paths, project, symlink_supported, t};
@@ -1594,3 +1594,60 @@ known-hosts = [
15941594
Definition::Environment("CARGO_NET_SSH_KNOWN_HOSTS".to_string())
15951595
);
15961596
}
1597+
1598+
#[cargo_test]
1599+
fn debuginfo_parsing() {
1600+
let config = ConfigBuilder::new().build();
1601+
let p: cargo_toml::TomlProfile = config.get("profile.dev").unwrap();
1602+
assert_eq!(p.debug, None);
1603+
1604+
let env_test_cases = [
1605+
(TomlDebugInfo::None, ["false", "0", "none"].as_slice()),
1606+
(TomlDebugInfo::LineDirectivesOnly, &["line-directives-only"]),
1607+
(TomlDebugInfo::LineTablesOnly, &["line-tables-only"]),
1608+
(TomlDebugInfo::Limited, &["1", "limited"]),
1609+
(TomlDebugInfo::Full, &["true", "2", "full"]),
1610+
];
1611+
for (expected, config_strs) in env_test_cases {
1612+
for &val in config_strs {
1613+
let config = ConfigBuilder::new()
1614+
.env("CARGO_PROFILE_DEV_DEBUG", val)
1615+
.build();
1616+
let debug: TomlDebugInfo = config.get("profile.dev.debug").unwrap();
1617+
assert_eq!(debug, expected, "failed to parse {val}");
1618+
}
1619+
}
1620+
1621+
let toml_test_cases = [
1622+
(TomlDebugInfo::None, ["false", "0", "\"none\""].as_slice()),
1623+
(
1624+
TomlDebugInfo::LineDirectivesOnly,
1625+
&["\"line-directives-only\""],
1626+
),
1627+
(TomlDebugInfo::LineTablesOnly, &["\"line-tables-only\""]),
1628+
(TomlDebugInfo::Limited, &["1", "\"limited\""]),
1629+
(TomlDebugInfo::Full, &["true", "2", "\"full\""]),
1630+
];
1631+
for (expected, config_strs) in toml_test_cases {
1632+
for &val in config_strs {
1633+
let config = ConfigBuilder::new()
1634+
.config_arg(format!("profile.dev.debug={val}"))
1635+
.build();
1636+
let debug: TomlDebugInfo = config.get("profile.dev.debug").unwrap();
1637+
assert_eq!(debug, expected, "failed to parse {val}");
1638+
}
1639+
}
1640+
1641+
let toml_err_cases = ["\"\"", "\"unrecognized\"", "3"];
1642+
for err_val in toml_err_cases {
1643+
let config = ConfigBuilder::new()
1644+
.config_arg(format!("profile.dev.debug={err_val}"))
1645+
.build();
1646+
let err = config
1647+
.get::<TomlDebugInfo>("profile.dev.debug")
1648+
.unwrap_err();
1649+
assert!(err
1650+
.to_string()
1651+
.ends_with("could not load config key `profile.dev.debug`"));
1652+
}
1653+
}

0 commit comments

Comments
 (0)