Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit fd22c27

Browse files
author
Ruben Schmidmeister
committed
Allow tests to be run on nightly only
1 parent c97aa15 commit fd22c27

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

src/test/mod.rs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,9 @@ fn assert_output(source: &Path, expected_filename: &Path) {
259259
#[test]
260260
fn idempotence_tests() {
261261
run_test_with(&TestSetting::default(), || {
262-
match option_env!("CFG_RELEASE_CHANNEL") {
263-
None | Some("nightly") => {}
264-
_ => return, // these tests require nightly
262+
// these tests require nightly
263+
if !is_nightly() {
264+
return;
265265
}
266266
// Get all files in the tests/target directory.
267267
let files = get_test_files(Path::new("tests/target"), true);
@@ -277,9 +277,9 @@ fn idempotence_tests() {
277277
// no warnings are emitted.
278278
#[test]
279279
fn self_tests() {
280-
match option_env!("CFG_RELEASE_CHANNEL") {
281-
None | Some("nightly") => {}
282-
_ => return, // Issue-3443: these tests require nightly
280+
// Issue-3443: these tests require nightly
281+
if !is_nightly() {
282+
return;
283283
}
284284
let mut files = get_test_files(Path::new("tests"), false);
285285
let bin_directories = vec!["cargo-fmt", "git-rustfmt", "bin", "format-diff"];
@@ -313,6 +313,11 @@ fn self_tests() {
313313
);
314314
}
315315

316+
fn is_nightly() -> bool {
317+
let release_channel = option_env!("CFG_RELEASE_CHANNEL");
318+
release_channel.is_none() || release_channel == Some("nightly")
319+
}
320+
316321
#[test]
317322
fn stdin_formatting_smoke_test() {
318323
let input = Input::Text("fn main () {}".to_owned());
@@ -426,6 +431,16 @@ fn check_files(files: Vec<PathBuf>, opt_config: &Option<PathBuf>) -> (Vec<Format
426431
let mut reports = vec![];
427432

428433
for file_name in files {
434+
let sig_comments = read_significant_comments(&file_name);
435+
if sig_comments.contains_key("unstable") && !is_nightly() {
436+
debug!(
437+
"Skipping '{}' because it requires unstable \
438+
features which are only available on nightly...",
439+
file_name.display()
440+
);
441+
continue;
442+
}
443+
429444
debug!("Testing '{}'...", file_name.display());
430445

431446
match idempotent_check(&file_name, &opt_config) {
@@ -485,7 +500,7 @@ fn read_config(filename: &Path) -> Config {
485500
};
486501

487502
for (key, val) in &sig_comments {
488-
if key != "target" && key != "config" {
503+
if key != "target" && key != "config" && key != "unstable" {
489504
config.override_value(key, val);
490505
if config.is_default(key) {
491506
warn!("Default value {} used explicitly for {}", val, key);

0 commit comments

Comments
 (0)