Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 92 additions & 32 deletions rustfmt-core/rustfmt-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,36 +556,96 @@ ignore = []
assert_eq!(&toml, &default_config);
}

// FIXME(#2183): these tests cannot be run in parallel because they use env vars.
// #[test]
// fn test_as_not_nightly_channel() {
// let mut config = Config::default();
// assert_eq!(config.was_set().unstable_features(), false);
// config.set().unstable_features(true);
// assert_eq!(config.was_set().unstable_features(), false);
// }

// #[test]
// fn test_as_nightly_channel() {
// let v = ::std::env::var("CFG_RELEASE_CHANNEL").unwrap_or(String::from(""));
// ::std::env::set_var("CFG_RELEASE_CHANNEL", "nightly");
// let mut config = Config::default();
// config.set().unstable_features(true);
// assert_eq!(config.was_set().unstable_features(), false);
// config.set().unstable_features(true);
// assert_eq!(config.unstable_features(), true);
// ::std::env::set_var("CFG_RELEASE_CHANNEL", v);
// }

// #[test]
// fn test_unstable_from_toml() {
// let mut config = Config::from_toml("unstable_features = true").unwrap();
// assert_eq!(config.was_set().unstable_features(), false);
// let v = ::std::env::var("CFG_RELEASE_CHANNEL").unwrap_or(String::from(""));
// ::std::env::set_var("CFG_RELEASE_CHANNEL", "nightly");
// config = Config::from_toml("unstable_features = true").unwrap();
// assert_eq!(config.was_set().unstable_features(), true);
// assert_eq!(config.unstable_features(), true);
// ::std::env::set_var("CFG_RELEASE_CHANNEL", v);
// }
mod unstable_features {
use super::super::*;

#[test]
fn test_default_not_nightly_channel() {
if is_nightly_channel!() {
// This test requires non-nightly
return;
}
let config = Config::default();
assert_eq!(config.unstable_features(), false);
assert_eq!(config.was_set().unstable_features(), false);
}

#[test]
fn test_default_nightly_channel() {
if !is_nightly_channel!() {
// This test requires nightly
return;
}
let config = Config::default();
assert_eq!(config.unstable_features(), false);
}

#[test]
fn test_from_toml_not_nightly() {
if is_nightly_channel!() {
// This test requires non-nightly
return;
}
let config = Config::from_toml("unstable_features = true", Path::new("")).unwrap();
assert_eq!(config.was_set().unstable_features(), false);
}

#[test]
fn test_from_toml_nightly() {
if !is_nightly_channel!() {
// This test requires non-nightly
return;
}
let config = Config::from_toml("unstable_features = true", Path::new("")).unwrap();
assert_eq!(config.was_set().unstable_features(), true);
}

#[test]
fn test_set_not_nightly_channel() {
if is_nightly_channel!() {
// This test requires non-nightly
return;
}
let mut config = Config::default();
assert_eq!(config.unstable_features(), false);
config.set().unstable_features(true);
assert_eq!(config.unstable_features(), true);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't expect this to be the case, but apparently we don't check the stability attribute of config options for set and override_value. That seems to imply that folks can technically already use unstable rustfmt options on stable anyway, though only via command line overrides to rustfmt

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, that's unfortunate. I will reconsider what we should do about unstable features on stable.

}

#[test]
fn test_set_nightly_channel() {
if !is_nightly_channel!() {
// This test requires nightly
return;
}
let mut config = Config::default();
assert_eq!(config.unstable_features(), false);
config.set().unstable_features(true);
assert_eq!(config.unstable_features(), true);
}

#[test]
fn test_override_not_nightly_channel() {
if is_nightly_channel!() {
// This test requires non-nightly
return;
}
let mut config = Config::default();
assert_eq!(config.unstable_features(), false);
config.override_value("unstable_features", "true");
assert_eq!(config.unstable_features(), true);
}

#[test]
fn test_override_nightly_channel() {
if !is_nightly_channel!() {
// This test requires nightly
return;
}
let mut config = Config::default();
assert_eq!(config.unstable_features(), false);
config.override_value("unstable_features", "true");
assert_eq!(config.unstable_features(), true);
}
}
}