Skip to content

Commit

Permalink
Deal with channel-dependant stderr
Browse files Browse the repository at this point in the history
Signed-off-by: Sasha Pourcelot <[email protected]>
  • Loading branch information
scrabsha committed May 5, 2024
1 parent eaa6de4 commit 241e5cc
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ syn = { version = "2.0", default-features = false, features = ["parsing"] }

[dev-dependencies]
# MSRV: 1.45 (README)
trybuild = "1.0"
trybuild = "1.0"
# MSRV: 1.32 (README, checked in CI)
rustc_version = "0.4.0"
51 changes: 51 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,58 @@ fn parse_punctuation(mut input: &[TokenTree]) -> Option<(Span, Terminal, &[Token
#[cfg(test)]
#[test]
fn ui() {
setup_channel_dependant_stderrs();

let t = trybuild::TestCases::new();
t.pass("tests/ui/pass/*.rs");
t.compile_fail("tests/ui/fail/*.rs");

drop(t);

cleanup_channel_dependant_stderrs();
}

#[cfg(test)]
const CHANNEL_DEPENDANT_STDERRS: [&str; 1] = ["bad_range_pattern"];

#[cfg(test)]
fn setup_channel_dependant_stderrs() {
// The error messages of `expandable` depend on the channel that is used
// when compiling the crate, as we use the nightly-only `Span::join` method.

use std::fs;

for (original, link) in nightly_dependant_stderrs() {
fs::hard_link(original, link).unwrap();
}
}

#[cfg(test)]
fn cleanup_channel_dependant_stderrs() {
use std::fs;

for (_, link) in nightly_dependant_stderrs() {
fs::remove_file(link).unwrap();
}
}

#[cfg(test)]
fn nightly_dependant_stderrs() -> Vec<(String, String)> {
use rustc_version::Channel;

CHANNEL_DEPENDANT_STDERRS
.into_iter()
.map(|unstable_stderr| {
let channel = rustc_version::version_meta().unwrap().channel;
let suffix = match channel {
Channel::Nightly | Channel::Dev => "nightly",
Channel::Beta | Channel::Stable => "stable",
};

let in_path = format!("tests/ui/fail/{unstable_stderr}.stderr_{suffix}");
let out_path = format!("tests/ui/fail/{unstable_stderr}.stderr");

(in_path, out_path)
})
.collect()
}
File renamed without changes.
5 changes: 5 additions & 0 deletions tests/ui/fail/bad_range_pattern.stderr_stable
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
error: Potentially invalid expansion. Expected `=`, `|`.
--> tests/ui/fail/bad_range_pattern.rs:6:15
|
6 | let $p..=0 = ();
| ^

0 comments on commit 241e5cc

Please sign in to comment.