allow stderr to be ignored on non-beta compilers

This commit is contained in:
Ashley Mannix 2021-08-05 12:48:40 +10:00
parent ab6c459cb4
commit eb31b1ae4b
4 changed files with 41 additions and 0 deletions

View File

@ -24,6 +24,7 @@ compiler_builtins = { version = '0.1.2', optional = true }
[dev-dependencies]
trybuild = "1.0"
rustversion = "1.0"
serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"

1
tests/compile-fail/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.stderr

View File

@ -1,5 +1,44 @@
use std::{
fs,
ffi::OsStr,
io,
path::Path,
};
#[test]
fn compile_fail() {
prepare_stderr_files("tests/compile-fail").unwrap();
let t = trybuild::TestCases::new();
t.compile_fail("tests/compile-fail/*.rs");
}
fn prepare_stderr_files(path: impl AsRef<Path>) -> io::Result<()> {
for entry in fs::read_dir(path)? {
let entry = entry?;
if entry.path().extension().and_then(OsStr::to_str) == Some("beta") {
let renamed = entry.path().with_extension("");
if renamed.exists() {
fs::remove_file(&renamed)?;
}
rename_beta_stderr(entry.path(), renamed)?;
}
}
Ok(())
}
#[rustversion::beta]
fn rename_beta_stderr(from: impl AsRef<Path>, to: impl AsRef<Path>) -> io::Result<()> {
fs::copy(from, to)?;
Ok(())
}
#[rustversion::not(beta)]
fn rename_beta_stderr(_: impl AsRef<Path>, _: impl AsRef<Path>) -> io::Result<()> {
Ok(())
}