Skip to content

Commit

Permalink
Merge pull request rust-lang#3558 from bash/unstable-tests
Browse files Browse the repository at this point in the history
Add option to run a test only on nightly
  • Loading branch information
topecongiro committed May 18, 2019
2 parents e6d616e + 8b57668 commit 421ed94
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 24 deletions.
18 changes: 1 addition & 17 deletions src/config/config_type.rs
Expand Up @@ -50,22 +50,6 @@ impl ConfigType for IgnoreList {
}
}

/// Checks if we're in a nightly build.
///
/// The environment variable `CFG_RELEASE_CHANNEL` is set during the rustc bootstrap
/// to "stable", "beta", or "nightly" depending on what toolchain is being built.
/// If we are being built as part of the stable or beta toolchains, we want
/// to disable unstable configuration options.
///
/// 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_rules! is_nightly_channel {
() => {
option_env!("CFG_RELEASE_CHANNEL").map_or(true, |c| c == "nightly" || c == "dev")
};
}

macro_rules! create_config {
($($i:ident: $ty:ty, $def:expr, $stb:expr, $( $dstring:expr ),+ );+ $(;)*) => (
#[cfg(test)]
Expand Down Expand Up @@ -159,7 +143,7 @@ macro_rules! create_config {
self.$i.1 = true;
self.$i.2 = val;
} else {
if is_nightly_channel!() {
if crate::is_nightly_channel!() {
self.$i.1 = true;
self.$i.2 = val;
} else {
Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Expand Up @@ -40,6 +40,9 @@ pub use crate::rustfmt_diff::{ModifiedChunk, ModifiedLines};
#[macro_use]
mod utils;

#[macro_use]
mod release_channel;

mod attr;
mod chains;
pub(crate) mod checkstyle;
Expand Down
16 changes: 16 additions & 0 deletions src/release_channel.rs
@@ -0,0 +1,16 @@
/// Checks if we're in a nightly build.
///
/// The environment variable `CFG_RELEASE_CHANNEL` is set during the rustc bootstrap
/// to "stable", "beta", or "nightly" depending on what toolchain is being built.
/// If we are being built as part of the stable or beta toolchains, we want
/// to disable unstable configuration options.
///
/// 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")
};
}
25 changes: 18 additions & 7 deletions src/test/mod.rs
Expand Up @@ -11,6 +11,7 @@ use std::thread;

use crate::config::{Color, Config, EmitMode, FileName, NewlineStyle, ReportTactic};
use crate::formatting::{ReportedErrors, SourceFile};
use crate::is_nightly_channel;
use crate::rustfmt_diff::{make_diff, print_diff, DiffLine, Mismatch, ModifiedChunk, OutputWriter};
use crate::source_file;
use crate::{FormatReport, FormatReportFormatterBuilder, Input, Session};
Expand Down Expand Up @@ -259,9 +260,9 @@ fn assert_output(source: &Path, expected_filename: &Path) {
#[test]
fn idempotence_tests() {
run_test_with(&TestSetting::default(), || {
match option_env!("CFG_RELEASE_CHANNEL") {
None | Some("nightly") => {}
_ => return, // these tests require nightly
// these tests require nightly
if !is_nightly_channel!() {
return;
}
// Get all files in the tests/target directory.
let files = get_test_files(Path::new("tests/target"), true);
Expand All @@ -277,9 +278,9 @@ fn idempotence_tests() {
// no warnings are emitted.
#[test]
fn self_tests() {
match option_env!("CFG_RELEASE_CHANNEL") {
None | Some("nightly") => {}
_ => return, // Issue-3443: these tests require nightly
// Issue-3443: these tests require nightly
if !is_nightly_channel!() {
return;
}
let mut files = get_test_files(Path::new("tests"), false);
let bin_directories = vec!["cargo-fmt", "git-rustfmt", "bin", "format-diff"];
Expand Down Expand Up @@ -426,6 +427,16 @@ fn check_files(files: Vec<PathBuf>, opt_config: &Option<PathBuf>) -> (Vec<Format
let mut reports = vec![];

for file_name in files {
let sig_comments = read_significant_comments(&file_name);
if sig_comments.contains_key("unstable") && !is_nightly_channel!() {
debug!(
"Skipping '{}' because it requires unstable \
features which are only available on nightly...",
file_name.display()
);
continue;
}

debug!("Testing '{}'...", file_name.display());

match idempotent_check(&file_name, &opt_config) {
Expand Down Expand Up @@ -485,7 +496,7 @@ fn read_config(filename: &Path) -> Config {
};

for (key, val) in &sig_comments {
if key != "target" && key != "config" {
if key != "target" && key != "config" && key != "unstable" {
config.override_value(key, val);
if config.is_default(key) {
warn!("Default value {} used explicitly for {}", val, key);
Expand Down

0 comments on commit 421ed94

Please sign in to comment.