Merge pull request #3558 from bash/unstable-tests

Add option to run a test only on nightly
This commit is contained in:
Seiichi Uchida 2019-05-18 17:51:25 +09:00 committed by GitHub
commit 421ed946bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 38 additions and 24 deletions

View File

@ -50,22 +50,6 @@ fn doc_hint() -> String {
}
}
/// 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)]
@ -159,7 +143,7 @@ fn fill_from_parsed_config(mut self, parsed: PartialConfig, dir: &Path) -> Confi
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 {

View File

@ -40,6 +40,9 @@
#[macro_use]
mod utils;
#[macro_use]
mod release_channel;
mod attr;
mod chains;
pub(crate) mod checkstyle;

16
src/release_channel.rs Normal file
View File

@ -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")
};
}

View File

@ -11,6 +11,7 @@
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};
@ -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);
@ -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"];
@ -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) {
@ -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);