1use crate::{
2 parser::{Pattern, Spanned},
3 rustc_stderr::{Message, Span},
4 Mode,
5};
6use std::{num::NonZeroUsize, path::PathBuf, process::ExitStatus};
7
8/// All the ways in which a test can fail.
9#[derive(Debug)]
10#[must_use]
11pub enum Error {
12 /// Got an invalid exit status for the given mode.
13 ExitStatus {
14 /// The expected mode.
15 mode: Mode,
16 /// The exit status of the command.
17 status: ExitStatus,
18 /// The expected exit status as set in the file or derived from the mode.
19 expected: i32,
20 },
21 /// A pattern was declared but had no matching error.
22 PatternNotFound {
23 /// The pattern that was not found, and the span of where that pattern was declared.
24 pattern: Spanned<Pattern>,
25 /// Can be `None` when it is expected outside the current file
26 expected_line: Option<NonZeroUsize>,
27 },
28 /// A ui test checking for failure does not have any failure patterns
29 NoPatternsFound,
30 /// A ui test checking for success has failure patterns
31 PatternFoundInPassTest {
32 /// Span of a flag changing the mode (if changed from default).
33 mode: Option<Span>,
34 /// Span of the pattern
35 span: Span,
36 },
37 /// Stderr/Stdout differed from the `.stderr`/`.stdout` file present.
38 OutputDiffers {
39 /// The file containing the expected output that differs from the actual output.
40 path: PathBuf,
41 /// The output from the command.
42 actual: Vec<u8>,
43 /// The contents of the file.
44 expected: Vec<u8>,
45 /// A command, that when run, causes the output to get blessed instead of erroring.
46 bless_command: String,
47 },
48 /// There were errors that don't have a pattern.
49 ErrorsWithoutPattern {
50 /// The main message of the error.
51 msgs: Vec<Message>,
52 /// File and line information of the error.
53 path: Option<Spanned<PathBuf>>,
54 },
55 /// A comment failed to parse.
56 InvalidComment {
57 /// The comment
58 msg: String,
59 /// The character range in which it was defined.
60 span: Span,
61 },
62 /// Conflicting comments
63 MultipleRevisionsWithResults {
64 /// The comment being looked for
65 kind: String,
66 /// The lines where conflicts happened
67 lines: Vec<NonZeroUsize>,
68 },
69 /// A subcommand (e.g. rustfix) of a test failed.
70 Command {
71 /// The name of the subcommand (e.g. "rustfix").
72 kind: String,
73 /// The exit status of the command.
74 status: ExitStatus,
75 },
76 /// This catches crashes of ui tests and reports them along the failed test.
77 Bug(String),
78 /// An auxiliary build failed with its own set of errors.
79 Aux {
80 /// Path to the aux file.
81 path: PathBuf,
82 /// The errors that occurred during the build of the aux file.
83 errors: Vec<Error>,
84 /// The line in which the aux file was requested to be built.
85 line: NonZeroUsize,
86 },
87 /// An error occured applying [`rustfix`] suggestions
88 Rustfix(anyhow::Error),
89}
90
91pub(crate) type Errors = Vec<Error>;
92