Skip to content

Commit

Permalink
support TRYBUILD=overwrite in our beta test scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
KodrAus committed Oct 24, 2021
1 parent f0a2bf6 commit 9e770dd
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 9 deletions.
18 changes: 9 additions & 9 deletions tests/compile-fail/trait/custom_impl.stderr.beta
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error[E0277]: the trait bound `BootlegFlags: ImplementedByBitFlagsMacro` is not satisfied
--> $DIR/custom_impl.rs:5:6
|
5 | impl BitFlags for BootlegFlags {
| ^^^^^^^^ the trait `ImplementedByBitFlagsMacro` is not implemented for `BootlegFlags`
|
--> $DIR/custom_impl.rs:5:6
|
5 | impl BitFlags for BootlegFlags {
| ^^^^^^^^ the trait `ImplementedByBitFlagsMacro` is not implemented for `BootlegFlags`
|
note: required by a bound in `BitFlags`
--> $DIR/bitflags_trait.rs:6:21
|
6 | pub trait BitFlags: ImplementedByBitFlagsMacro {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `BitFlags`
--> $DIR/bitflags_trait.rs:10:21
|
10 | pub trait BitFlags: ImplementedByBitFlagsMacro {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `BitFlags`
45 changes: 45 additions & 0 deletions tests/compile.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::{
env,
fs,
ffi::OsStr,
io,
Expand All @@ -12,7 +13,14 @@ fn fail() {
prepare_stderr_files("tests/compile-fail").unwrap();

let t = trybuild::TestCases::new();

t.compile_fail("tests/compile-fail/**/*.rs");

// `trybuild` will run its tests on `drop`
// We want to get a chance to use its output first
drop(t);

overwrite_stderr_files("tests/compile-fail").unwrap();
}

#[test]
Expand Down Expand Up @@ -50,6 +58,43 @@ fn prepare_stderr_files(path: impl AsRef<Path>) -> io::Result<()> {
Ok(())
}

// If we want to overwrite the expected compiler output then rename it
// to use our `.stderr.beta` convention. Otherwise the renamed file won't
// actually get picked up on the next run
fn overwrite_stderr_files(path: impl AsRef<Path>) -> io::Result<()> {
if env::var("TRYBUILD").ok().filter(|o| o == "overwrite").is_some() {
for entry in WalkDir::new(path) {
let entry = entry?;

// Look for any `.stderr` files and rename them to `.stderr.beta`
// If there's an existing `.beta` file then we want to remove it
if entry.path().extension().and_then(OsStr::to_str) == Some("stderr") {
let renamed = entry.path().with_extension("stderr.beta");

if renamed.exists() {
remove_beta_stderr(&renamed)?;
}

rename_beta_stderr(entry.path(), renamed)?;
}
}
}

Ok(())
}

#[rustversion::beta]
fn remove_beta_stderr(path: impl AsRef<Path>) -> io::Result<()> {
fs::remove_file(path)?;

Ok(())
}

#[rustversion::not(beta)]
fn remove_beta_stderr(_: impl AsRef<Path>) -> io::Result<()> {
Ok(())
}

#[rustversion::beta]
fn rename_beta_stderr(from: impl AsRef<Path>, to: impl AsRef<Path>) -> io::Result<()> {
fs::copy(from, to)?;
Expand Down

0 comments on commit 9e770dd

Please sign in to comment.