From 4745cec7f3a016d48c86c67bb6b41b3d434cd28e Mon Sep 17 00:00:00 2001 From: Ruben Schmidmeister Date: Fri, 17 May 2019 16:07:49 +0200 Subject: [PATCH] Re-use nightly channel macro --- src/config/config_type.rs | 1 + src/test/mod.rs | 12 ++++-------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/config/config_type.rs b/src/config/config_type.rs index d14969418ad..26cd672f83a 100644 --- a/src/config/config_type.rs +++ b/src/config/config_type.rs @@ -60,6 +60,7 @@ fn doc_hint() -> String { /// If we're being built by cargo (e.g., `cargo +nightly install rustfmt-nightly`), /// `CFG_RELEASE_CHANNEL` is not set. As we only support being built against the /// nightly compiler when installed from crates.io, default to nightly mode. +#[macro_export] macro_rules! is_nightly_channel { () => { option_env!("CFG_RELEASE_CHANNEL").map_or(true, |c| c == "nightly" || c == "dev") diff --git a/src/test/mod.rs b/src/test/mod.rs index 101a8c07fd9..d3e18130977 100644 --- a/src/test/mod.rs +++ b/src/test/mod.rs @@ -14,6 +14,7 @@ use crate::rustfmt_diff::{make_diff, print_diff, DiffLine, Mismatch, ModifiedChunk, OutputWriter}; use crate::source_file; use crate::{FormatReport, FormatReportFormatterBuilder, Input, Session}; +use crate::is_nightly_channel; const DIFF_CONTEXT_SIZE: usize = 3; const CONFIGURATIONS_FILE_NAME: &str = "Configurations.md"; @@ -260,7 +261,7 @@ fn assert_output(source: &Path, expected_filename: &Path) { fn idempotence_tests() { run_test_with(&TestSetting::default(), || { // these tests require nightly - if !is_nightly() { + if !is_nightly_channel!() { return; } // Get all files in the tests/target directory. @@ -278,7 +279,7 @@ fn idempotence_tests() { #[test] fn self_tests() { // Issue-3443: these tests require nightly - if !is_nightly() { + if !is_nightly_channel!() { return; } let mut files = get_test_files(Path::new("tests"), false); @@ -313,11 +314,6 @@ fn self_tests() { ); } -fn is_nightly() -> bool { - let release_channel = option_env!("CFG_RELEASE_CHANNEL"); - release_channel.is_none() || release_channel == Some("nightly") -} - #[test] fn stdin_formatting_smoke_test() { let input = Input::Text("fn main () {}".to_owned()); @@ -432,7 +428,7 @@ fn check_files(files: Vec, opt_config: &Option) -> (Vec