Skip to content

Commit b3d4fb4

Browse files
ytmimicalebcartwright
authored andcommitted
Allow #[ignore] tests to run in rustfmt's test suite
There are some tests in the rustfmt test suite that are ignored by default. I believe these tests are ignored because they have caused issues with the the `rust-lang/rust` test suite. However, we recently experienced an issue (5395) that would have been avoided had these tests been running. With the introduction of the new `#[rustfmt_only_ci_test]` attribute macro we can run these tests when the `RUSTFMT_CI` environment variable is set, which will presumably only be set during rustfmts CI runs. When the environment variable is not set the `#[rustfmt_only_ci_test]` will be replaced with an `#[ignore]`.
1 parent c4416f2 commit b3d4fb4

File tree

5 files changed

+25
-6
lines changed

5 files changed

+25
-6
lines changed

ci/build_and_test.bat

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
set "RUSTFLAGS=-D warnings"
2+
set "RUSTFMT_CI=1"
23

34
:: Print version information
45
rustc -Vv || exit /b 1

ci/build_and_test.sh

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
set -euo pipefail
44

55
export RUSTFLAGS="-D warnings"
6+
export RUSTFMT_CI=1
67

78
# Print version information
89
rustc -Vv

config_proc_macro/src/lib.rs

+13
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,16 @@ pub fn stable_only_test(_args: TokenStream, input: TokenStream) -> TokenStream {
6969
TokenStream::from_str("").unwrap()
7070
}
7171
}
72+
73+
/// Used to conditionally output the TokenStream for tests that should be run as part of rustfmts
74+
/// test suite, but should be ignored when running in the rust-lang/rust test suite.
75+
#[proc_macro_attribute]
76+
pub fn rustfmt_only_ci_test(_args: TokenStream, input: TokenStream) -> TokenStream {
77+
if option_env!("RUSTFMT_CI").is_some() {
78+
input
79+
} else {
80+
let mut token_stream = TokenStream::from_str("#[ignore]").unwrap();
81+
token_stream.extend(input);
82+
token_stream
83+
}
84+
}

tests/cargo-fmt/main.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ use std::env;
44
use std::path::Path;
55
use std::process::Command;
66

7+
use rustfmt_config_proc_macro::rustfmt_only_ci_test;
8+
79
/// Run the cargo-fmt executable and return its output.
810
fn cargo_fmt(args: &[&str]) -> (String, String) {
911
let mut bin_dir = env::current_exe().unwrap();
@@ -47,7 +49,7 @@ macro_rules! assert_that {
4749
};
4850
}
4951

50-
#[ignore]
52+
#[rustfmt_only_ci_test]
5153
#[test]
5254
fn version() {
5355
assert_that!(&["--version"], starts_with("rustfmt "));
@@ -56,7 +58,7 @@ fn version() {
5658
assert_that!(&["--", "--version"], starts_with("rustfmt "));
5759
}
5860

59-
#[ignore]
61+
#[rustfmt_only_ci_test]
6062
#[test]
6163
fn print_config() {
6264
assert_that!(
@@ -65,15 +67,15 @@ fn print_config() {
6567
);
6668
}
6769

68-
#[ignore]
70+
#[rustfmt_only_ci_test]
6971
#[test]
7072
fn rustfmt_help() {
7173
assert_that!(&["--", "--help"], contains("Format Rust code"));
7274
assert_that!(&["--", "-h"], contains("Format Rust code"));
7375
assert_that!(&["--", "--help=config"], contains("Configuration Options:"));
7476
}
7577

76-
#[ignore]
78+
#[rustfmt_only_ci_test]
7779
#[test]
7880
fn cargo_fmt_out_of_line_test_modules() {
7981
// See also https://github.com/rust-lang/rustfmt/issues/5119

tests/rustfmt/main.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ use std::fs::remove_file;
55
use std::path::Path;
66
use std::process::Command;
77

8+
use rustfmt_config_proc_macro::rustfmt_only_ci_test;
9+
810
/// Run the rustfmt executable and return its output.
911
fn rustfmt(args: &[&str]) -> (String, String) {
1012
let mut bin_dir = env::current_exe().unwrap();
@@ -47,7 +49,7 @@ macro_rules! assert_that {
4749
};
4850
}
4951

50-
#[ignore]
52+
#[rustfmt_only_ci_test]
5153
#[test]
5254
fn print_config() {
5355
assert_that!(
@@ -76,7 +78,7 @@ fn print_config() {
7678
remove_file("minimal-config").unwrap();
7779
}
7880

79-
#[ignore]
81+
#[rustfmt_only_ci_test]
8082
#[test]
8183
fn inline_config() {
8284
// single invocation

0 commit comments

Comments
 (0)