1use std::sync::Arc;
2
3use miette::Diagnostic;
4use thiserror::Error;
5
6#[derive(Error, Diagnostic, Debug)]
7#[error("An error occurred while parsing testcases")]
8pub struct TestParseError {
9 #[related]
10 pub(crate) errors: Vec<TestErrorCase>,
11
12 #[source_code]
13 pub(crate) source_code: Option<miette::NamedSource<Arc<str>>>,
14}
15
16impl From<kdl::KdlError> for TestParseError {
17 fn from(source: kdl::KdlError) -> Self {
18 TestParseError {
19 errors: vec![TestErrorCase::Kdl { source }],
20 source_code: None,
21 }
22 }
23}
24
25impl From<TestErrorCase> for TestParseError {
26 fn from(source: TestErrorCase) -> Self {
27 TestParseError {
28 errors: vec![source],
29 source_code: None,
30 }
31 }
32}
33
34#[derive(Error, Diagnostic, Debug)]
35pub enum TestErrorCase {
36 #[error("An error occurred while parsing the KDL data")]
37 Kdl {
38 #[source]
39 source: kdl::KdlError,
40 },
41 #[error("Not a valid test case")]
42 #[diagnostic(help("The outer items must all be `testcase`s"))]
43 NotTestcase {
44 #[label("Expected a `testcase`")]
45 span: miette::SourceSpan,
46 },
47 #[error("An argument was missing")]
48 MissingArgument {
49 #[label("This node is missing an argument")]
50 parent: miette::SourceSpan,
51
52 #[help]
53 missing: String,
54 },
55 #[error("An argument was of the wrong type")]
56 WrongArgumentType {
57 #[label("This node has an argument of a wrong kind")]
58 parent: miette::SourceSpan,
59
60 #[label("this one")]
61 argument: miette::SourceSpan,
62
63 #[help]
64 expected: String,
65 },
66 #[error("Could not find condition with this name")]
67 UnknownCondition {
68 #[label]
69 condition: miette::SourceSpan,
70 },
71 #[error("Could not find verb with this name")]
72 UnknownVerb {
73 #[label]
74 verb: miette::SourceSpan,
75 },
76
77 #[error("A panic occurred while running the test")]
78 Panic {
79 #[diagnostic_source]
80 error: miette::Error,
81
82 #[label("in this node")]
83 label: miette::SourceSpan,
84 },
85
86 #[error("An error occurred while running the test")]
87 Error {
88 #[diagnostic_source]
89 error: miette::Error,
90
91 #[label("in this node")]
92 label: miette::SourceSpan,
93 },
94}