Introduce a proper error handling framework

This commit is contained in:
Oli Scherer 2022-07-06 09:09:53 +00:00
parent b3e64c252a
commit 570032b0dd
8 changed files with 471 additions and 50 deletions

194
Cargo.lock generated
View File

@ -2,6 +2,21 @@
# It is not intended for manual editing.
version = 3
[[package]]
name = "addr2line"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9ecd88a8c8378ca913a680cd98f0f13ac67383d35993f86c90a70e3f137816b"
dependencies = [
"gimli",
]
[[package]]
name = "adler"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
[[package]]
name = "aho-corasick"
version = "0.7.18"
@ -37,18 +52,66 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "backtrace"
version = "0.3.65"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "11a17d453482a265fd5f8479f2a3f405566e6ca627837aaddb85af8b1ab8ef61"
dependencies = [
"addr2line",
"cc",
"cfg-if",
"libc",
"miniz_oxide",
"object",
"rustc-demangle",
]
[[package]]
name = "bitflags"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "cc"
version = "1.0.73"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11"
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "color-eyre"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ebf286c900a6d5867aeff75cfee3192857bb7f24b547d4f0df2ed6baa812c90"
dependencies = [
"backtrace",
"color-spantrace",
"eyre",
"indenter",
"once_cell",
"owo-colors",
"tracing-error",
]
[[package]]
name = "color-spantrace"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ba75b3d9449ecdccb27ecbc479fdc0b87fa2dd43d2f8298f9bf0e59aacc8dce"
dependencies = [
"once_cell",
"owo-colors",
"tracing-core",
"tracing-error",
]
[[package]]
name = "colored"
version = "2.0.0"
@ -158,6 +221,16 @@ dependencies = [
"termcolor",
]
[[package]]
name = "eyre"
version = "0.6.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c2b6b5a29c02cdc822728b7d7b8ae1bab3e3b05d44522770ddd49722eeac7eb"
dependencies = [
"indenter",
"once_cell",
]
[[package]]
name = "getrandom"
version = "0.2.3"
@ -169,6 +242,12 @@ dependencies = [
"wasi",
]
[[package]]
name = "gimli"
version = "0.26.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78cc372d058dcf6d5ecd98510e7fbc9e5aec4d21de70f65fea8fecebcd881bd4"
[[package]]
name = "hermit-abi"
version = "0.1.19"
@ -184,6 +263,12 @@ version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
[[package]]
name = "indenter"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683"
[[package]]
name = "instant"
version = "0.1.12"
@ -267,6 +352,15 @@ dependencies = [
"autocfg",
]
[[package]]
name = "miniz_oxide"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6f5c75688da582b8ffc1f1799e9db273f32133c49e048f614d22ec3256773ccc"
dependencies = [
"adler",
]
[[package]]
name = "miri"
version = "0.1.0"
@ -286,6 +380,21 @@ dependencies = [
"ui_test",
]
[[package]]
name = "object"
version = "0.28.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e42c982f2d955fac81dd7e1d0e1426a7d702acd9c98d19ab01083a6a0328c424"
dependencies = [
"memchr",
]
[[package]]
name = "once_cell"
version = "1.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1"
[[package]]
name = "output_vt100"
version = "0.1.3"
@ -295,6 +404,12 @@ dependencies = [
"winapi",
]
[[package]]
name = "owo-colors"
version = "3.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "decf7381921fea4dcb2549c5667eda59b3ec297ab7e2b5fc33eac69d2e7da87b"
[[package]]
name = "parking_lot"
version = "0.11.2"
@ -329,6 +444,12 @@ dependencies = [
"libc",
]
[[package]]
name = "pin-project-lite"
version = "0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116"
[[package]]
name = "ppv-lite86"
version = "0.2.15"
@ -431,6 +552,12 @@ version = "0.6.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b"
[[package]]
name = "rustc-demangle"
version = "0.1.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342"
[[package]]
name = "rustc-hash"
version = "1.1.0"
@ -501,6 +628,15 @@ dependencies = [
"serde",
]
[[package]]
name = "sharded-slab"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "900fba806f70c630b0a382d0d825e17a0f19fcd059a2ade1ff237bcddf446b31"
dependencies = [
"lazy_static",
]
[[package]]
name = "shell-escape"
version = "0.1.5"
@ -533,10 +669,62 @@ dependencies = [
"winapi-util",
]
[[package]]
name = "thread_local"
version = "1.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5516c27b78311c50bf42c071425c560ac799b11c30b31f87e3081965fe5e0180"
dependencies = [
"once_cell",
]
[[package]]
name = "tracing"
version = "0.1.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a400e31aa60b9d44a52a8ee0343b5b18566b03a8321e0d321f695cf56e940160"
dependencies = [
"cfg-if",
"pin-project-lite",
"tracing-core",
]
[[package]]
name = "tracing-core"
version = "0.1.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b7358be39f2f274f322d2aaed611acc57f382e8eb1e5b48cb9ae30933495ce7"
dependencies = [
"once_cell",
"valuable",
]
[[package]]
name = "tracing-error"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d686ec1c0f384b1277f097b2f279a2ecc11afe8c133c1aabf036a27cb4cd206e"
dependencies = [
"tracing",
"tracing-subscriber",
]
[[package]]
name = "tracing-subscriber"
version = "0.3.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3a713421342a5a666b7577783721d3117f1b69a393df803ee17bb73b1e122a59"
dependencies = [
"sharded-slab",
"thread_local",
"tracing-core",
]
[[package]]
name = "ui_test"
version = "0.1.0"
dependencies = [
"color-eyre",
"colored",
"crossbeam",
"lazy_static",
@ -553,6 +741,12 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d22af068fba1eb5edcb4aea19d382b2a3deb4c8f9d475c589b6ada9e0fd493ee"
[[package]]
name = "valuable"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d"
[[package]]
name = "wasi"
version = "0.10.2+wasi-snapshot-preview1"

View File

@ -2,13 +2,13 @@ use colored::*;
use regex::Regex;
use std::env;
use std::path::PathBuf;
use ui_test::{Config, Mode, OutputConflictHandling};
use ui_test::{Config, Mode, OutputConflictHandling, color_eyre::Result};
fn miri_path() -> PathBuf {
PathBuf::from(option_env!("MIRI").unwrap_or(env!("CARGO_BIN_EXE_miri")))
}
fn run_tests(mode: Mode, path: &str, target: Option<String>) {
fn run_tests(mode: Mode, path: &str, target: Option<String>) -> Result<()> {
let in_rustc_test_suite = option_env!("RUSTC_STAGE").is_some();
// Add some flags we always want.
@ -108,7 +108,7 @@ regexes! {
"sys/[a-z]+/" => "sys/PLATFORM/",
}
fn ui(mode: Mode, path: &str) {
fn ui(mode: Mode, path: &str) -> Result<()> {
let target = get_target();
let msg = format!(
@ -117,20 +117,24 @@ fn ui(mode: Mode, path: &str) {
);
eprintln!("{}", msg.green().bold());
run_tests(mode, path, target);
run_tests(mode, path, target)
}
fn get_target() -> Option<String> {
env::var("MIRI_TEST_TARGET").ok()
}
fn main() {
fn main() -> Result<()> {
ui_test::color_eyre::install()?;
// Add a test env var to do environment communication tests.
env::set_var("MIRI_ENV_VAR_TEST", "0");
// Let the tests know where to store temp files (they might run for a different target, which can make this hard to find).
env::set_var("MIRI_TEMP", env::temp_dir());
ui(Mode::Pass, "tests/pass");
ui(Mode::Panic, "tests/panic");
ui(Mode::Fail, "tests/fail");
ui(Mode::Pass, "tests/pass")?;
ui(Mode::Panic, "tests/panic")?;
ui(Mode::Fail, "tests/fail")?;
Ok(())
}

194
ui_test/Cargo.lock generated
View File

@ -2,6 +2,21 @@
# It is not intended for manual editing.
version = 3
[[package]]
name = "addr2line"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9ecd88a8c8378ca913a680cd98f0f13ac67383d35993f86c90a70e3f137816b"
dependencies = [
"gimli",
]
[[package]]
name = "adler"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
[[package]]
name = "aho-corasick"
version = "0.7.18"
@ -37,12 +52,60 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "backtrace"
version = "0.3.65"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "11a17d453482a265fd5f8479f2a3f405566e6ca627837aaddb85af8b1ab8ef61"
dependencies = [
"addr2line",
"cc",
"cfg-if",
"libc",
"miniz_oxide",
"object",
"rustc-demangle",
]
[[package]]
name = "cc"
version = "1.0.73"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11"
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "color-eyre"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ebf286c900a6d5867aeff75cfee3192857bb7f24b547d4f0df2ed6baa812c90"
dependencies = [
"backtrace",
"color-spantrace",
"eyre",
"indenter",
"once_cell",
"owo-colors",
"tracing-error",
]
[[package]]
name = "color-spantrace"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ba75b3d9449ecdccb27ecbc479fdc0b87fa2dd43d2f8298f9bf0e59aacc8dce"
dependencies = [
"once_cell",
"owo-colors",
"tracing-core",
"tracing-error",
]
[[package]]
name = "colored"
version = "2.0.0"
@ -139,6 +202,22 @@ version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0e25ea47919b1560c4e3b7fe0aaab9becf5b84a10325ddf7db0f0ba5e1026499"
[[package]]
name = "eyre"
version = "0.6.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c2b6b5a29c02cdc822728b7d7b8ae1bab3e3b05d44522770ddd49722eeac7eb"
dependencies = [
"indenter",
"once_cell",
]
[[package]]
name = "gimli"
version = "0.26.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78cc372d058dcf6d5ecd98510e7fbc9e5aec4d21de70f65fea8fecebcd881bd4"
[[package]]
name = "hermit-abi"
version = "0.1.19"
@ -148,6 +227,12 @@ dependencies = [
"libc",
]
[[package]]
name = "indenter"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683"
[[package]]
name = "itoa"
version = "1.0.2"
@ -181,6 +266,30 @@ dependencies = [
"autocfg",
]
[[package]]
name = "miniz_oxide"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6f5c75688da582b8ffc1f1799e9db273f32133c49e048f614d22ec3256773ccc"
dependencies = [
"adler",
]
[[package]]
name = "object"
version = "0.28.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e42c982f2d955fac81dd7e1d0e1426a7d702acd9c98d19ab01083a6a0328c424"
dependencies = [
"memchr",
]
[[package]]
name = "once_cell"
version = "1.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1"
[[package]]
name = "output_vt100"
version = "0.1.3"
@ -190,6 +299,18 @@ dependencies = [
"winapi",
]
[[package]]
name = "owo-colors"
version = "3.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "decf7381921fea4dcb2549c5667eda59b3ec297ab7e2b5fc33eac69d2e7da87b"
[[package]]
name = "pin-project-lite"
version = "0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116"
[[package]]
name = "pretty_assertions"
version = "1.2.1"
@ -237,6 +358,12 @@ version = "0.6.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49b3de9ec5dc0a3417da371aab17d729997c15010e7fd24ff707773a33bddb64"
[[package]]
name = "rustc-demangle"
version = "0.1.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342"
[[package]]
name = "rustc_version"
version = "0.4.0"
@ -295,6 +422,15 @@ dependencies = [
"serde",
]
[[package]]
name = "sharded-slab"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "900fba806f70c630b0a382d0d825e17a0f19fcd059a2ade1ff237bcddf446b31"
dependencies = [
"lazy_static",
]
[[package]]
name = "syn"
version = "1.0.95"
@ -306,10 +442,62 @@ dependencies = [
"unicode-ident",
]
[[package]]
name = "thread_local"
version = "1.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5516c27b78311c50bf42c071425c560ac799b11c30b31f87e3081965fe5e0180"
dependencies = [
"once_cell",
]
[[package]]
name = "tracing"
version = "0.1.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a400e31aa60b9d44a52a8ee0343b5b18566b03a8321e0d321f695cf56e940160"
dependencies = [
"cfg-if",
"pin-project-lite",
"tracing-core",
]
[[package]]
name = "tracing-core"
version = "0.1.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b7358be39f2f274f322d2aaed611acc57f382e8eb1e5b48cb9ae30933495ce7"
dependencies = [
"once_cell",
"valuable",
]
[[package]]
name = "tracing-error"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d686ec1c0f384b1277f097b2f279a2ecc11afe8c133c1aabf036a27cb4cd206e"
dependencies = [
"tracing",
"tracing-subscriber",
]
[[package]]
name = "tracing-subscriber"
version = "0.3.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3a713421342a5a666b7577783721d3117f1b69a393df803ee17bb73b1e122a59"
dependencies = [
"sharded-slab",
"thread_local",
"tracing-core",
]
[[package]]
name = "ui_test"
version = "0.1.0"
dependencies = [
"color-eyre",
"colored",
"crossbeam",
"lazy_static",
@ -326,6 +514,12 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d22af068fba1eb5edcb4aea19d382b2a3deb4c8f9d475c589b6ada9e0fd493ee"
[[package]]
name = "valuable"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d"
[[package]]
name = "winapi"
version = "0.3.9"

View File

@ -17,3 +17,5 @@ crossbeam = "0.8.1"
lazy_static = "1.4.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
color-eyre = "0.6.1"

View File

@ -4,6 +4,8 @@ use regex::Regex;
use crate::rustc_stderr::Level;
use color_eyre::eyre::Result;
#[cfg(test)]
mod tests;
@ -102,8 +104,8 @@ macro_rules! checked {
}
impl Comments {
pub(crate) fn parse_file(path: &Path) -> Self {
let content = std::fs::read_to_string(path).unwrap();
pub(crate) fn parse_file(path: &Path) -> Result<Self> {
let content = std::fs::read_to_string(path)?;
Self::parse(path, &content)
}
@ -112,7 +114,7 @@ impl Comments {
///
/// This function will only parse `//@` and `//~` style comments
/// and ignore all others
fn parse_checked(path: &Path, content: &str) -> Self {
fn parse_checked(path: &Path, content: &str) -> Result<Self> {
let mut this = Self::default();
// The line that a `|` will refer to
@ -136,16 +138,16 @@ impl Comments {
fallthrough_to = None;
}
}
this
Ok(this)
}
/// Parse comments in `content`.
/// `path` is only used to emit diagnostics if parsing fails.
pub(crate) fn parse(path: &Path, content: &str) -> Self {
let mut this = Self::parse_checked(path, content);
pub(crate) fn parse(path: &Path, content: &str) -> Result<Self> {
let mut this = Self::parse_checked(path, content)?;
if content.contains("//@") {
// Migration mode: if new syntax is used, ignore all old syntax
return this;
return Ok(this);
}
for (l, line) in content.lines().enumerate() {
@ -209,7 +211,7 @@ impl Comments {
this.error_pattern = Some((s.trim().to_string(), l));
}
}
this
Ok(this)
}
fn parse_command_with_args(&mut self, command: &str, args: &str, path: &Path, l: usize) {

View File

@ -1,9 +1,13 @@
use std::path::Path;
use std::{path::Path, panic::catch_unwind};
use super::Comments;
use color_eyre::eyre::{Result, bail};
use crate::tests::init;
#[test]
fn parse_simple_comment() {
fn parse_simple_comment() -> Result<()> {
init();
let s = r"
use std::mem;
@ -11,7 +15,7 @@ fn main() {
let _x: &i32 = unsafe { mem::transmute(16usize) }; //~ ERROR encountered a dangling reference (address $HEX is unallocated)
}
";
let comments = Comments::parse(Path::new("<dummy>"), s);
let comments = Comments::parse(Path::new("<dummy>"), s)?;
println!("parsed comments: {:#?}", comments);
assert_eq!(comments.error_matches[0].definition_line, 5);
assert_eq!(comments.error_matches[0].revision, None);
@ -19,29 +23,33 @@ fn main() {
comments.error_matches[0].matched,
"encountered a dangling reference (address $HEX is unallocated)"
);
Ok(())
}
#[test]
fn parse_slash_slash_at() {
fn parse_slash_slash_at() -> Result<()> {
init();
let s = r"
//@ error-pattern: foomp
use std::mem;
";
let comments = Comments::parse(Path::new("<dummy>"), s);
let comments = Comments::parse(Path::new("<dummy>"), s)?;
println!("parsed comments: {:#?}", comments);
assert_eq!(comments.error_pattern, Some(("foomp".to_string(), 2)));
Ok(())
}
#[test]
#[should_panic]
fn parse_slash_slash_at_fail() {
fn parse_slash_slash_at_fail() -> Result<()> {
init();
let s = r"
//@ error-pattern foomp
use std::mem;
";
let comments = Comments::parse(Path::new("<dummy>"), s);
println!("parsed comments: {:#?}", comments);
assert_eq!(comments.error_pattern, Some(("foomp".to_string(), 2)));
match catch_unwind(|| Comments::parse(Path::new("<dummy>"), s)) {
Ok(_) => bail!("expected parsing to panic"),
Err(_) => Ok(()),
}
}

View File

@ -11,6 +11,8 @@ use colored::*;
use comments::ErrorMatch;
use regex::Regex;
use rustc_stderr::{Level, Message};
use color_eyre::eyre::Result;
pub use color_eyre;
use crate::comments::{Comments, Condition};
@ -51,7 +53,7 @@ pub enum OutputConflictHandling {
pub type Filter = Vec<(Regex, &'static str)>;
pub fn run_tests(config: Config) {
pub fn run_tests(config: Config) -> Result<()> {
eprintln!(" Compiler flags: {:?}", config.args);
// Get the triple with which to run the tests
@ -94,7 +96,7 @@ pub fn run_tests(config: Config) {
// Create N worker threads that receive files to test.
for _ in 0..std::thread::available_parallelism().unwrap().get() {
s.spawn(|_| {
s.spawn(|_| -> Result<()> {
for path in &receive {
if !config.path_filter.is_empty() {
let path_display = path.display().to_string();
@ -103,7 +105,7 @@ pub fn run_tests(config: Config) {
continue;
}
}
let comments = Comments::parse_file(&path);
let comments = Comments::parse_file(&path)?;
// Ignore file if only/ignore rules do (not) apply
if !test_file_conditions(&comments, &target) {
ignored.fetch_add(1, Ordering::Relaxed);
@ -142,6 +144,7 @@ pub fn run_tests(config: Config) {
}
}
}
Ok(())
});
}
})
@ -246,6 +249,7 @@ pub fn run_tests(config: Config) {
filtered.to_string().yellow(),
);
eprintln!();
Ok(())
}
#[derive(Debug)]

View File

@ -20,7 +20,8 @@ fn config() -> Config {
}
#[test]
fn issue_2156() {
fn issue_2156() -> Result<()> {
init();
let s = r"
use std::mem;
@ -29,7 +30,7 @@ fn main() {
}
";
let path = Path::new("$DIR/<dummy>");
let comments = Comments::parse(path, s);
let comments = Comments::parse(path, s)?;
let mut errors = vec![];
let config = config();
let messages = vec![
@ -46,13 +47,14 @@ fn main() {
[
Error::PatternNotFound { definition_line: 5, .. },
Error::ErrorsWithoutPattern { path: Some((_, 5)), .. },
] => {}
] => Ok(()),
_ => panic!("{:#?}", errors),
}
}
#[test]
fn find_pattern() {
fn find_pattern() -> Result<()> {
init();
let s = r"
use std::mem;
@ -60,7 +62,7 @@ fn main() {
let _x: &i32 = unsafe { mem::transmute(16usize) }; //~ ERROR encountered a dangling reference (address 0x10 is unallocated)
}
";
let comments = Comments::parse(Path::new("<dummy>"), s);
let comments = Comments::parse(Path::new("<dummy>"), s)?;
let config = config();
{
let messages = vec![vec![], vec![], vec![], vec![], vec![], vec![
@ -137,14 +139,15 @@ fn main() {
);
match &errors[..] {
// Note no `ErrorsWithoutPattern`, because there are no `//~NOTE` in the test file, so we ignore them
[Error::PatternNotFound { definition_line: 5, .. }] => {}
[Error::PatternNotFound { definition_line: 5, .. }] => Ok(()),
_ => panic!("not the expected error: {:#?}", errors),
}
}
}
#[test]
fn duplicate_pattern() {
fn duplicate_pattern() -> Result<()> {
init();
let s = r"
use std::mem;
@ -153,7 +156,7 @@ fn main() {
//~^ ERROR encountered a dangling reference (address 0x10 is unallocated)
}
";
let comments = Comments::parse(Path::new("<dummy>"), s);
let comments = Comments::parse(Path::new("<dummy>"), s)?;
let config = config();
let messages = vec![
vec![], vec![], vec![], vec![], vec![],
@ -167,13 +170,14 @@ fn main() {
let mut errors = vec![];
check_annotations(messages, vec![], Path::new("moobar"), &mut errors, &config, "", &comments);
match &errors[..] {
[Error::PatternNotFound { definition_line: 6, .. }] => {}
[Error::PatternNotFound { definition_line: 6, .. }] => Ok(()),
_ => panic!("{:#?}", errors),
}
}
#[test]
fn missing_pattern() {
fn missing_pattern() -> Result<()> {
init();
let s = r"
use std::mem;
@ -181,7 +185,7 @@ fn main() {
let _x: &i32 = unsafe { mem::transmute(16usize) }; //~ ERROR encountered a dangling reference (address 0x10 is unallocated)
}
";
let comments = Comments::parse(Path::new("<dummy>"), s);
let comments = Comments::parse(Path::new("<dummy>"), s)?;
let config = config();
let messages = vec![
vec![], vec![], vec![], vec![], vec![],
@ -199,13 +203,14 @@ fn main() {
let mut errors = vec![];
check_annotations(messages, vec![], Path::new("moobar"), &mut errors, &config, "", &comments);
match &errors[..] {
[Error::ErrorsWithoutPattern { path: Some((_, 5)), .. }] => {}
[Error::ErrorsWithoutPattern { path: Some((_, 5)), .. }] => Ok(()),
_ => panic!("{:#?}", errors),
}
}
#[test]
fn missing_warn_pattern() {
fn missing_warn_pattern() -> Result<()> {
init();
let s = r"
use std::mem;
@ -214,7 +219,7 @@ fn main() {
//~^ WARN cake
}
";
let comments = Comments::parse(Path::new("<dummy>"), s);
let comments = Comments::parse(Path::new("<dummy>"), s)?;
let config = config();
let messages= vec![
vec![],
@ -242,7 +247,7 @@ fn main() {
match &errors[..] {
[Error::ErrorsWithoutPattern { path: Some((_, 5)), msgs, .. }] =>
match &msgs[..] {
[Message { message, level: Level::Warn }] if message == "kaboom" => {}
[Message { message, level: Level::Warn }] if message == "kaboom" => Ok(()),
_ => panic!("{:#?}", msgs),
},
_ => panic!("{:#?}", errors),
@ -250,7 +255,8 @@ fn main() {
}
#[test]
fn missing_implicit_warn_pattern() {
fn missing_implicit_warn_pattern() -> Result<()> {
init();
let s = r"
use std::mem;
@ -259,7 +265,7 @@ fn main() {
//~^ cake
}
";
let comments = Comments::parse(Path::new("<dummy>"), s);
let comments = Comments::parse(Path::new("<dummy>"), s)?;
let config = config();
let messages = vec![
vec![],
@ -285,13 +291,14 @@ fn main() {
let mut errors = vec![];
check_annotations(messages, vec![], Path::new("moobar"), &mut errors, &config, "", &comments);
match &errors[..] {
[] => {}
[] => Ok(()),
_ => panic!("{:#?}", errors),
}
}
#[test]
fn implicit_err_pattern() {
fn implicit_err_pattern() -> Result<()> {
init();
let s = r"
use std::mem;
@ -299,7 +306,7 @@ fn main() {
let _x: &i32 = unsafe { mem::transmute(16usize) }; //~ encountered a dangling reference (address 0x10 is unallocated)
}
";
let comments = Comments::parse(Path::new("<dummy>"), s);
let comments = Comments::parse(Path::new("<dummy>"), s)?;
let config = config();
let messages = vec![
vec![],
@ -317,7 +324,13 @@ fn main() {
let mut errors = vec![];
check_annotations(messages, vec![], Path::new("moobar"), &mut errors, &config, "", &comments);
match &errors[..] {
[Error::ErrorPatternWithoutErrorAnnotation(_, 5)] => {}
[Error::ErrorPatternWithoutErrorAnnotation(_, 5)] => Ok(()),
_ => panic!("{:#?}", errors),
}
}
static INIT: std::sync::Once = std::sync::Once::new();
pub fn init() {
INIT.call_once(|| color_eyre::install().unwrap());
}