Skip to content

Commit f989d5a

Browse files
committed
add tests for LinkSelfContained options parsing
1 parent bb03c04 commit f989d5a

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

compiler/rustc_session/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ pub mod output;
3333

3434
pub use getopts;
3535

36+
#[cfg(test)]
37+
mod tests;
38+
3639
/// Requirements for a `StableHashingContext` to be used in this crate.
3740
/// This is a hack to allow using the `HashStable_Generic` derive macro
3841
/// instead of implementing everything in `rustc_middle`.

compiler/rustc_session/src/tests.rs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
use std::str::FromStr;
2+
3+
use crate::config::{LinkSelfContained, LinkSelfContainedCrt, LinkSelfContainedLinker};
4+
5+
/// When adding support for `-C link-self-contained=linker`, we want to ensure the existing
6+
/// values are still supported as-is: they are option values that can be used on stable.
7+
#[test]
8+
pub fn parse_stable_self_contained() {
9+
// The existing default is when the argument is not used, the behavior depends on the
10+
// target.
11+
assert_eq!(
12+
LinkSelfContained::default(),
13+
LinkSelfContained { crt: LinkSelfContainedCrt::Auto, linker: LinkSelfContainedLinker::Off }
14+
);
15+
16+
// Turning the flag `on` should currently only enable the default on stable.
17+
assert_eq!(
18+
LinkSelfContained::from_str("on"),
19+
Ok(LinkSelfContained {
20+
crt: LinkSelfContainedCrt::On,
21+
linker: LinkSelfContainedLinker::Off
22+
})
23+
);
24+
25+
// Turning the flag `off` applies to both facets.
26+
assert_eq!(
27+
LinkSelfContained::from_str("off"),
28+
Ok(LinkSelfContained {
29+
crt: LinkSelfContainedCrt::Off,
30+
linker: LinkSelfContainedLinker::Off
31+
})
32+
);
33+
34+
assert_eq!(
35+
LinkSelfContained::from_str("crt"),
36+
Ok(LinkSelfContained {
37+
crt: LinkSelfContainedCrt::On,
38+
linker: LinkSelfContainedLinker::Off
39+
})
40+
);
41+
}
42+
43+
#[test]
44+
pub fn parse_self_contained_with_linker() {
45+
// Turning the linker on doesn't change the CRT behavior
46+
assert_eq!(
47+
LinkSelfContained::from_str("linker"),
48+
Ok(LinkSelfContained {
49+
crt: LinkSelfContainedCrt::Auto,
50+
linker: LinkSelfContainedLinker::On
51+
})
52+
);
53+
54+
assert_eq!(
55+
LinkSelfContained::from_str("all"),
56+
Ok(LinkSelfContained {
57+
crt: LinkSelfContainedCrt::On,
58+
linker: LinkSelfContainedLinker::On
59+
})
60+
);
61+
62+
// If `linker` is turned on by default someday, we need to be able to go back to the current
63+
// default.
64+
assert_eq!(
65+
LinkSelfContained::from_str("auto"),
66+
Ok(LinkSelfContained {
67+
crt: LinkSelfContainedCrt::Auto,
68+
linker: LinkSelfContainedLinker::Off
69+
})
70+
);
71+
}

0 commit comments

Comments
 (0)