Skip to content

Commit 45ac003

Browse files
tests: restore some config tests (#4064)
1 parent 13a8e54 commit 45ac003

File tree

1 file changed

+92
-32
lines changed
  • rustfmt-core/rustfmt-config/src

1 file changed

+92
-32
lines changed

rustfmt-core/rustfmt-config/src/lib.rs

+92-32
Original file line numberDiff line numberDiff line change
@@ -556,36 +556,96 @@ ignore = []
556556
assert_eq!(&toml, &default_config);
557557
}
558558

559-
// FIXME(#2183): these tests cannot be run in parallel because they use env vars.
560-
// #[test]
561-
// fn test_as_not_nightly_channel() {
562-
// let mut config = Config::default();
563-
// assert_eq!(config.was_set().unstable_features(), false);
564-
// config.set().unstable_features(true);
565-
// assert_eq!(config.was_set().unstable_features(), false);
566-
// }
567-
568-
// #[test]
569-
// fn test_as_nightly_channel() {
570-
// let v = ::std::env::var("CFG_RELEASE_CHANNEL").unwrap_or(String::from(""));
571-
// ::std::env::set_var("CFG_RELEASE_CHANNEL", "nightly");
572-
// let mut config = Config::default();
573-
// config.set().unstable_features(true);
574-
// assert_eq!(config.was_set().unstable_features(), false);
575-
// config.set().unstable_features(true);
576-
// assert_eq!(config.unstable_features(), true);
577-
// ::std::env::set_var("CFG_RELEASE_CHANNEL", v);
578-
// }
579-
580-
// #[test]
581-
// fn test_unstable_from_toml() {
582-
// let mut config = Config::from_toml("unstable_features = true").unwrap();
583-
// assert_eq!(config.was_set().unstable_features(), false);
584-
// let v = ::std::env::var("CFG_RELEASE_CHANNEL").unwrap_or(String::from(""));
585-
// ::std::env::set_var("CFG_RELEASE_CHANNEL", "nightly");
586-
// config = Config::from_toml("unstable_features = true").unwrap();
587-
// assert_eq!(config.was_set().unstable_features(), true);
588-
// assert_eq!(config.unstable_features(), true);
589-
// ::std::env::set_var("CFG_RELEASE_CHANNEL", v);
590-
// }
559+
mod unstable_features {
560+
use super::super::*;
561+
562+
#[test]
563+
fn test_default_not_nightly_channel() {
564+
if is_nightly_channel!() {
565+
// This test requires non-nightly
566+
return;
567+
}
568+
let config = Config::default();
569+
assert_eq!(config.unstable_features(), false);
570+
assert_eq!(config.was_set().unstable_features(), false);
571+
}
572+
573+
#[test]
574+
fn test_default_nightly_channel() {
575+
if !is_nightly_channel!() {
576+
// This test requires nightly
577+
return;
578+
}
579+
let config = Config::default();
580+
assert_eq!(config.unstable_features(), false);
581+
}
582+
583+
#[test]
584+
fn test_from_toml_not_nightly() {
585+
if is_nightly_channel!() {
586+
// This test requires non-nightly
587+
return;
588+
}
589+
let config = Config::from_toml("unstable_features = true", Path::new("")).unwrap();
590+
assert_eq!(config.was_set().unstable_features(), false);
591+
}
592+
593+
#[test]
594+
fn test_from_toml_nightly() {
595+
if !is_nightly_channel!() {
596+
// This test requires non-nightly
597+
return;
598+
}
599+
let config = Config::from_toml("unstable_features = true", Path::new("")).unwrap();
600+
assert_eq!(config.was_set().unstable_features(), true);
601+
}
602+
603+
#[test]
604+
fn test_set_not_nightly_channel() {
605+
if is_nightly_channel!() {
606+
// This test requires non-nightly
607+
return;
608+
}
609+
let mut config = Config::default();
610+
assert_eq!(config.unstable_features(), false);
611+
config.set().unstable_features(true);
612+
assert_eq!(config.unstable_features(), true);
613+
}
614+
615+
#[test]
616+
fn test_set_nightly_channel() {
617+
if !is_nightly_channel!() {
618+
// This test requires nightly
619+
return;
620+
}
621+
let mut config = Config::default();
622+
assert_eq!(config.unstable_features(), false);
623+
config.set().unstable_features(true);
624+
assert_eq!(config.unstable_features(), true);
625+
}
626+
627+
#[test]
628+
fn test_override_not_nightly_channel() {
629+
if is_nightly_channel!() {
630+
// This test requires non-nightly
631+
return;
632+
}
633+
let mut config = Config::default();
634+
assert_eq!(config.unstable_features(), false);
635+
config.override_value("unstable_features", "true");
636+
assert_eq!(config.unstable_features(), true);
637+
}
638+
639+
#[test]
640+
fn test_override_nightly_channel() {
641+
if !is_nightly_channel!() {
642+
// This test requires nightly
643+
return;
644+
}
645+
let mut config = Config::default();
646+
assert_eq!(config.unstable_features(), false);
647+
config.override_value("unstable_features", "true");
648+
assert_eq!(config.unstable_features(), true);
649+
}
650+
}
591651
}

0 commit comments

Comments
 (0)