Skip to content

Commit 4452cc3

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

File tree

1 file changed

+60
-1
lines changed

1 file changed

+60
-1
lines changed

tests/testsuite/config.rs

Lines changed: 60 additions & 1 deletion
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,62 @@ 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()
1601+
// .env("CARGO_PROFILE_DEV_DEBUG_ASSERTIONS", "false")
1602+
.build();
1603+
let p: cargo_toml::TomlProfile = config.get("profile.dev").unwrap();
1604+
assert_eq!(p.debug, None);
1605+
1606+
let env_test_cases = [
1607+
(TomlDebugInfo::None, ["false", "0", "none"].as_slice()),
1608+
(TomlDebugInfo::LineDirectivesOnly, &["line-directives-only"]),
1609+
(TomlDebugInfo::LineTablesOnly, &["line-tables-only"]),
1610+
(TomlDebugInfo::Limited, &["1", "limited"]),
1611+
(TomlDebugInfo::Full, &["true", "2", "full"]),
1612+
];
1613+
for (expected, config_strs) in env_test_cases {
1614+
for &val in config_strs {
1615+
let config = ConfigBuilder::new()
1616+
.env("CARGO_PROFILE_DEV_DEBUG", val)
1617+
.build();
1618+
let debug: TomlDebugInfo = config.get("profile.dev.debug").unwrap();
1619+
assert_eq!(debug, expected, "failed to parse {val}");
1620+
}
1621+
}
1622+
1623+
let toml_test_cases = [
1624+
(TomlDebugInfo::None, ["false", "0", "\"none\""].as_slice()),
1625+
(
1626+
TomlDebugInfo::LineDirectivesOnly,
1627+
&["\"line-directives-only\""],
1628+
),
1629+
(TomlDebugInfo::LineTablesOnly, &["\"line-tables-only\""]),
1630+
(TomlDebugInfo::Limited, &["1", "\"limited\""]),
1631+
(TomlDebugInfo::Full, &["true", "2", "\"full\""]),
1632+
];
1633+
for (expected, config_strs) in toml_test_cases {
1634+
for &val in config_strs {
1635+
let config = ConfigBuilder::new()
1636+
.config_arg(format!("profile.dev.debug={val}"))
1637+
.build();
1638+
let debug: TomlDebugInfo = config.get("profile.dev.debug").unwrap();
1639+
assert_eq!(debug, expected, "failed to parse {val}");
1640+
}
1641+
}
1642+
1643+
let toml_err_cases = ["\"\"", "\"unrecognized\"", "3"];
1644+
for err_val in toml_err_cases {
1645+
let config = ConfigBuilder::new()
1646+
.config_arg(format!("profile.dev.debug={err_val}"))
1647+
.build();
1648+
let err = config
1649+
.get::<TomlDebugInfo>("profile.dev.debug")
1650+
.unwrap_err();
1651+
assert!(err
1652+
.to_string()
1653+
.ends_with("could not load config key `profile.dev.debug`"));
1654+
}
1655+
}

0 commit comments

Comments
 (0)