|
| 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