Unite bless environment variables under RUSTC_BLESS
Currently, Clippy, Miri, Rustfmt, and rustc all use an environment variable to indicate that output should be blessed, but they use different variable names. In order to improve consistency, this patch applies the following changes: - Emit `RUSTC_BLESS` within `prepare_cargo_test` so it is always available - Change usage of `MIRI_BLESS` in the Miri subtree to use `RUSTC_BLESS` - Change usage of `BLESS` in the Clippy subtree to `RUSTC_BLESS` - Change usage of `BLESS` in the Rustfmt subtree to `RUSTC_BLESS` - Adjust the blessable test in `rustc_errors` to use this same convention - Update documentation where applicable Any tools that uses `RUSTC_BLESS` should check that it is set to any value other than `"0"`.
This commit is contained in:
parent
6908c73ab0
commit
9439e02fb2
8 changed files with 22 additions and 31 deletions
|
@ -63,7 +63,7 @@ fn test_wrapping_write() {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_output() {
|
fn test_output() {
|
||||||
// Capture `--bless` when run via ./x
|
// Capture `--bless` when run via ./x
|
||||||
let bless = std::env::var("RUSTC_BLESS").unwrap_or_default() == "1";
|
let bless = std::env::var_os("RUSTC_BLESS").is_some_and(|v| v != "0");
|
||||||
let ast = MdStream::parse_str(INPUT);
|
let ast = MdStream::parse_str(INPUT);
|
||||||
let bufwtr = BufferWriter::stderr(ColorChoice::Always);
|
let bufwtr = BufferWriter::stderr(ColorChoice::Always);
|
||||||
let mut buffer = bufwtr.buffer();
|
let mut buffer = bufwtr.buffer();
|
||||||
|
|
|
@ -430,10 +430,6 @@ impl Step for Rustfmt {
|
||||||
&[],
|
&[],
|
||||||
);
|
);
|
||||||
|
|
||||||
if builder.config.cmd.bless() {
|
|
||||||
cargo.env("BLESS", "1");
|
|
||||||
}
|
|
||||||
|
|
||||||
let dir = testdir(builder, compiler.host);
|
let dir = testdir(builder, compiler.host);
|
||||||
t!(fs::create_dir_all(&dir));
|
t!(fs::create_dir_all(&dir));
|
||||||
cargo.env("RUSTFMT_TEST_DIR", dir);
|
cargo.env("RUSTFMT_TEST_DIR", dir);
|
||||||
|
@ -633,10 +629,6 @@ impl Step for Miri {
|
||||||
cargo.env("MIRI_SYSROOT", &miri_sysroot);
|
cargo.env("MIRI_SYSROOT", &miri_sysroot);
|
||||||
cargo.env("MIRI_HOST_SYSROOT", sysroot);
|
cargo.env("MIRI_HOST_SYSROOT", sysroot);
|
||||||
cargo.env("MIRI", &miri);
|
cargo.env("MIRI", &miri);
|
||||||
// propagate --bless
|
|
||||||
if builder.config.cmd.bless() {
|
|
||||||
cargo.env("MIRI_BLESS", "Gesundheit");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set the target.
|
// Set the target.
|
||||||
cargo.env("MIRI_TEST_TARGET", target.rustc_target_arg());
|
cargo.env("MIRI_TEST_TARGET", target.rustc_target_arg());
|
||||||
|
@ -654,8 +646,8 @@ impl Step for Miri {
|
||||||
cargo.env("MIRIFLAGS", "-O -Zmir-opt-level=4 -Cdebug-assertions=yes");
|
cargo.env("MIRIFLAGS", "-O -Zmir-opt-level=4 -Cdebug-assertions=yes");
|
||||||
// Optimizations can change backtraces
|
// Optimizations can change backtraces
|
||||||
cargo.env("MIRI_SKIP_UI_CHECKS", "1");
|
cargo.env("MIRI_SKIP_UI_CHECKS", "1");
|
||||||
// `MIRI_SKIP_UI_CHECKS` and `MIRI_BLESS` are incompatible
|
// `MIRI_SKIP_UI_CHECKS` and `RUSTC_BLESS` are incompatible
|
||||||
cargo.env_remove("MIRI_BLESS");
|
cargo.env_remove("RUSTC_BLESS");
|
||||||
// Optimizations can change error locations and remove UB so don't run `fail` tests.
|
// Optimizations can change error locations and remove UB so don't run `fail` tests.
|
||||||
cargo.args(&["tests/pass", "tests/panic"]);
|
cargo.args(&["tests/pass", "tests/panic"]);
|
||||||
|
|
||||||
|
@ -799,11 +791,6 @@ impl Step for Clippy {
|
||||||
cargo.add_rustc_lib_path(builder, compiler);
|
cargo.add_rustc_lib_path(builder, compiler);
|
||||||
let mut cargo = prepare_cargo_test(cargo, &[], &[], "clippy", compiler, host, builder);
|
let mut cargo = prepare_cargo_test(cargo, &[], &[], "clippy", compiler, host, builder);
|
||||||
|
|
||||||
// propagate --bless
|
|
||||||
if builder.config.cmd.bless() {
|
|
||||||
cargo.env("BLESS", "Gesundheit");
|
|
||||||
}
|
|
||||||
|
|
||||||
let _guard = builder.msg_sysroot_tool(Kind::Test, compiler.stage, "clippy", host, host);
|
let _guard = builder.msg_sysroot_tool(Kind::Test, compiler.stage, "clippy", host, host);
|
||||||
|
|
||||||
#[allow(deprecated)] // Clippy reports errors if it blessed the outputs
|
#[allow(deprecated)] // Clippy reports errors if it blessed the outputs
|
||||||
|
@ -2245,9 +2232,11 @@ fn prepare_cargo_test(
|
||||||
) -> Command {
|
) -> Command {
|
||||||
let mut cargo = cargo.into();
|
let mut cargo = cargo.into();
|
||||||
|
|
||||||
// If bless is passed, give downstream crates a way to use it
|
// Propegate `--bless` if it has not already been set/unset
|
||||||
if builder.config.cmd.bless() {
|
// Any tools that want to use this should bless if `RUSTC_BLESS` is set to
|
||||||
cargo.env("RUSTC_BLESS", "1");
|
// anything other than `0`.
|
||||||
|
if builder.config.cmd.bless() && !cargo.get_envs().any(|v| v.0 == "RUSTC_BLESS") {
|
||||||
|
cargo.env("RUSTC_BLESS", "Gesundheit");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pass in some standard flags then iterate over the graph we've discovered
|
// Pass in some standard flags then iterate over the graph we've discovered
|
||||||
|
|
|
@ -115,7 +115,9 @@ fn base_config(test_dir: &str) -> compiletest::Config {
|
||||||
mode: TestMode::Yolo,
|
mode: TestMode::Yolo,
|
||||||
stderr_filters: vec![],
|
stderr_filters: vec![],
|
||||||
stdout_filters: vec![],
|
stdout_filters: vec![],
|
||||||
output_conflict_handling: if var_os("BLESS").is_some() || env::args().any(|arg| arg == "--bless") {
|
// FIXME(tgross35): deduplicate bless env once clippy can update
|
||||||
|
output_conflict_handling: if var_os("RUSTC_BLESS").is_some_and(|v| v != "0")
|
||||||
|
|| env::args().any(|arg| arg == "--bless") {
|
||||||
compiletest::OutputConflictHandling::Bless
|
compiletest::OutputConflictHandling::Bless
|
||||||
} else {
|
} else {
|
||||||
compiletest::OutputConflictHandling::Error("cargo test -- -- --bless".into())
|
compiletest::OutputConflictHandling::Error("cargo test -- -- --bless".into())
|
||||||
|
|
|
@ -482,7 +482,7 @@ Moreover, Miri recognizes some environment variables:
|
||||||
purpose.
|
purpose.
|
||||||
* `MIRI_NO_STD` (recognized by `cargo miri` and the test suite) makes sure that the target's
|
* `MIRI_NO_STD` (recognized by `cargo miri` and the test suite) makes sure that the target's
|
||||||
sysroot is built without libstd. This allows testing and running no_std programs.
|
sysroot is built without libstd. This allows testing and running no_std programs.
|
||||||
* `MIRI_BLESS` (recognized by the test suite and `cargo-miri-test/run-test.py`): overwrite all
|
* `RUSTC_BLESS` (recognized by the test suite and `cargo-miri-test/run-test.py`): overwrite all
|
||||||
`stderr` and `stdout` files instead of checking whether the output matches.
|
`stderr` and `stdout` files instead of checking whether the output matches.
|
||||||
* `MIRI_SKIP_UI_CHECKS` (recognized by the test suite): don't check whether the
|
* `MIRI_SKIP_UI_CHECKS` (recognized by the test suite): don't check whether the
|
||||||
`stderr` or `stdout` files match the actual output.
|
`stderr` or `stdout` files match the actual output.
|
||||||
|
|
|
@ -303,7 +303,7 @@ test|bless)
|
||||||
$CARGO build $CARGO_EXTRA_FLAGS --manifest-path "$MIRIDIR"/Cargo.toml
|
$CARGO build $CARGO_EXTRA_FLAGS --manifest-path "$MIRIDIR"/Cargo.toml
|
||||||
find_sysroot
|
find_sysroot
|
||||||
if [ "$COMMAND" = "bless" ]; then
|
if [ "$COMMAND" = "bless" ]; then
|
||||||
export MIRI_BLESS="Gesundheit"
|
export RUSTC_BLESS="Gesundheit"
|
||||||
fi
|
fi
|
||||||
# Then test, and let caller control flags.
|
# Then test, and let caller control flags.
|
||||||
# Only in root project as `cargo-miri` has no tests.
|
# Only in root project as `cargo-miri` has no tests.
|
||||||
|
|
|
@ -8,8 +8,8 @@ and the working directory to contain the cargo-miri-test project.
|
||||||
import difflib
|
import difflib
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import sys
|
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import sys
|
||||||
|
|
||||||
CGREEN = '\33[32m'
|
CGREEN = '\33[32m'
|
||||||
CBOLD = '\33[1m'
|
CBOLD = '\33[1m'
|
||||||
|
@ -37,7 +37,8 @@ def normalize_stderr(str):
|
||||||
return str
|
return str
|
||||||
|
|
||||||
def check_output(actual, path, name):
|
def check_output(actual, path, name):
|
||||||
if 'MIRI_BLESS' in os.environ:
|
if os.environ.get("RUSTC_BLESS", "0") != "0":
|
||||||
|
# Write the output only if bless is set
|
||||||
open(path, mode='w').write(actual)
|
open(path, mode='w').write(actual)
|
||||||
return True
|
return True
|
||||||
expected = open(path).read()
|
expected = open(path).read()
|
||||||
|
|
|
@ -72,13 +72,14 @@ fn test_config(target: &str, path: &str, mode: Mode, with_dependencies: bool) ->
|
||||||
program.args.push(flag);
|
program.args.push(flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let bless = env::var_os("RUSTC_BLESS").is_some_and(|v| v !="0");
|
||||||
let skip_ui_checks = env::var_os("MIRI_SKIP_UI_CHECKS").is_some();
|
let skip_ui_checks = env::var_os("MIRI_SKIP_UI_CHECKS").is_some();
|
||||||
|
|
||||||
let output_conflict_handling = match (env::var_os("MIRI_BLESS").is_some(), skip_ui_checks) {
|
let output_conflict_handling = match (bless, skip_ui_checks) {
|
||||||
(false, false) => OutputConflictHandling::Error("./miri bless".into()),
|
(false, false) => OutputConflictHandling::Error("./miri bless".into()),
|
||||||
(true, false) => OutputConflictHandling::Bless,
|
(true, false) => OutputConflictHandling::Bless,
|
||||||
(false, true) => OutputConflictHandling::Ignore,
|
(false, true) => OutputConflictHandling::Ignore,
|
||||||
(true, true) => panic!("cannot use MIRI_BLESS and MIRI_SKIP_UI_CHECKS at the same time"),
|
(true, true) => panic!("cannot use RUSTC_BLESS and MIRI_SKIP_UI_CHECKS at the same time"),
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut config = Config {
|
let mut config = Config {
|
||||||
|
|
|
@ -838,11 +838,9 @@ fn handle_result(
|
||||||
|
|
||||||
// Ignore LF and CRLF difference for Windows.
|
// Ignore LF and CRLF difference for Windows.
|
||||||
if !string_eq_ignore_newline_repr(&fmt_text, &text) {
|
if !string_eq_ignore_newline_repr(&fmt_text, &text) {
|
||||||
if let Some(bless) = std::env::var_os("BLESS") {
|
if std::env::var_os("RUSTC_BLESS").is_some_and(|v| v != "0") {
|
||||||
if bless != "0" {
|
std::fs::write(file_name, fmt_text).unwrap();
|
||||||
std::fs::write(file_name, fmt_text).unwrap();
|
continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
let diff = make_diff(&text, &fmt_text, DIFF_CONTEXT_SIZE);
|
let diff = make_diff(&text, &fmt_text, DIFF_CONTEXT_SIZE);
|
||||||
assert!(
|
assert!(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue