|
3 | 3 | use cargo::core::{PackageIdSpec, Shell}; |
4 | 4 | use cargo::util::config::{self, Config, Definition, JobsConfig, SslVersionConfig, StringList}; |
5 | 5 | use cargo::util::interning::InternedString; |
6 | | -use cargo::util::toml::{self as cargo_toml, TomlDebugInfo, VecStringOrBool as VSOB}; |
| 6 | +use cargo::util::toml::{ |
| 7 | + self as cargo_toml, ProfileTrimPaths, TomlDebugInfo, VecStringOrBool as VSOB, |
| 8 | +}; |
7 | 9 | use cargo::CargoResult; |
8 | 10 | use cargo_test_support::compare; |
9 | 11 | use cargo_test_support::{panic_error, paths, project, symlink_supported, t}; |
@@ -1706,3 +1708,35 @@ jobs = 2 |
1706 | 1708 | JobsConfig::Integer(v) => assert_eq!(v, 2), |
1707 | 1709 | } |
1708 | 1710 | } |
| 1711 | + |
| 1712 | +#[cargo_test] |
| 1713 | +fn trim_paths_parsing() { |
| 1714 | + let config = ConfigBuilder::new().build(); |
| 1715 | + let p: cargo_toml::TomlProfile = config.get("profile.dev").unwrap(); |
| 1716 | + assert_eq!(p.trim_paths, None); |
| 1717 | + |
| 1718 | + // .unstable_flag("advanced-env") |
| 1719 | + |
| 1720 | + let test_cases = [ |
| 1721 | + (ProfileTrimPaths::None, "none"), |
| 1722 | + (ProfileTrimPaths::Macro, "macro"), |
| 1723 | + (ProfileTrimPaths::Diagnostics, "diagnostics"), |
| 1724 | + (ProfileTrimPaths::Object, "object"), |
| 1725 | + (ProfileTrimPaths::All, "all"), |
| 1726 | + ]; |
| 1727 | + for (expected, val) in test_cases { |
| 1728 | + // env |
| 1729 | + let config = ConfigBuilder::new() |
| 1730 | + .env("CARGO_PROFILE_DEV_TRIM_PATHS", val) |
| 1731 | + .build(); |
| 1732 | + let trim_paths: ProfileTrimPaths = config.get("profile.dev.trim-paths").unwrap(); |
| 1733 | + assert_eq!(trim_paths, expected, "failed to parse {val}"); |
| 1734 | + |
| 1735 | + // config.toml |
| 1736 | + let config = ConfigBuilder::new() |
| 1737 | + .config_arg(format!("profile.dev.trim-paths='{val}'")) |
| 1738 | + .build(); |
| 1739 | + let trim_paths: ProfileTrimPaths = config.get("profile.dev.trim-paths").unwrap(); |
| 1740 | + assert_eq!(trim_paths, expected, "failed to parse {val}"); |
| 1741 | + } |
| 1742 | +} |
0 commit comments