Skip to content

Commit c1784fe

Browse files
committed
Make a panic message more informative if binary files are accidentally created somewhere in the test folder
1 parent 5b33008 commit c1784fe

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

tests/compile-test.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use std::collections::BTreeMap;
1313
use std::env::{self, remove_var, set_var, var_os};
1414
use std::ffi::{OsStr, OsString};
1515
use std::fs;
16-
use std::path::{Path, PathBuf};
16+
use std::path::Path;
1717
use std::sync::LazyLock;
1818
use test_utils::IS_RUSTC_TEST_SUITE;
1919

@@ -124,10 +124,9 @@ fn base_config(test_dir: &str) -> (compiletest::Config, Args) {
124124
OutputConflictHandling::Error("cargo uibless".into())
125125
},
126126
target: None,
127-
out_dir: PathBuf::from(std::env::var_os("CARGO_TARGET_DIR").unwrap_or("target".into()))
128-
.join("ui_test")
129-
.canonicalize()
130-
.unwrap(),
127+
out_dir: fs::canonicalize(std::env::var_os("CARGO_TARGET_DIR").unwrap_or("target".into()))
128+
.unwrap()
129+
.join("ui_test"),
131130
..compiletest::Config::rustc(Path::new("tests").join(test_dir))
132131
};
133132

@@ -323,7 +322,9 @@ fn run_ui_cargo() {
323322
|path, _args| test_filter(path) && path.ends_with("Cargo.toml"),
324323
|config, path| {
325324
let mut config = config.clone();
326-
config.out_dir = PathBuf::from("target/ui_test_cargo/").join(path.parent().unwrap());
325+
config.out_dir = fs::canonicalize("target/ui_test_cargo/")
326+
.unwrap()
327+
.join(path.parent().unwrap());
327328
Some(config)
328329
},
329330
if quiet {

tests/headers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fn old_test_headers() {
1616
continue;
1717
}
1818

19-
let file = fs::read_to_string(entry.path()).unwrap();
19+
let file = fs::read_to_string(entry.path()).unwrap_or_else(|err| panic!("{}: {err}", entry.path().display()));
2020

2121
if let Some(header) = old_headers.find(&file) {
2222
println!("Found header `{}` in {}", header.as_str(), entry.path().display());

0 commit comments

Comments
 (0)