litcheck_filecheck/test/
mod.rs1mod result;
2#[cfg(test)]
3pub(crate) mod testing;
4
5pub(crate) use self::result::TestInputType;
6pub use self::result::TestResult;
7#[cfg(test)]
8pub use self::testing::TestContext;
9
10use crate::{check::Checker, common::*, parse};
11
12pub struct Test<'a> {
17 config: &'a Config,
18 strings: StringInterner,
19 match_file: ArcSource,
20}
21impl<'a> Test<'a> {
22 pub fn new<S>(match_file: S, config: &'a Config) -> Self
26 where
27 ArcSource: From<S>,
28 {
29 Self {
30 config,
31 match_file: ArcSource::from(match_file),
32 strings: StringInterner::new(),
33 }
34 }
35
36 pub fn verify<'input, S>(&mut self, input_file: S) -> DiagResult<Vec<MatchInfo<'static>>>
42 where
43 ArcSource: From<S> + 'input,
44 {
45 let mut parser = parse::CheckFileParser::new(&self.config, &mut self.strings);
47
48 let match_file = parser
49 .parse(&self.match_file)
50 .map_err(|err| Report::new(err).with_source_code(self.match_file.clone()))?;
51
52 let program = match_file.compile(self.config, &mut self.strings)?;
54
55 let mut checker = Checker::new(
57 self.config,
58 &mut self.strings,
59 program,
60 self.match_file.clone(),
61 );
62 checker
63 .check_input(ArcSource::from(input_file))
64 .into_result()
65 .map_err(Report::new)
66 }
67}