Add new macro variant 'check' to ensure there are no errors AND the compiled output matches
This commit is contained in:
@@ -6,6 +6,12 @@ macro_rules! output {
|
||||
};
|
||||
}
|
||||
|
||||
/// Represents both compilation errors and compiled output
|
||||
pub struct CompilationCheckResult {
|
||||
pub errors: Vec<crate::Error<'static>>,
|
||||
pub output: String,
|
||||
}
|
||||
|
||||
#[cfg_attr(test, macro_export)]
|
||||
macro_rules! compile {
|
||||
($source:expr) => {{
|
||||
@@ -37,6 +43,21 @@ macro_rules! compile {
|
||||
res.instructions.write(&mut writer)?;
|
||||
output!(writer)
|
||||
}};
|
||||
|
||||
(check $source:expr) => {{
|
||||
let mut writer = std::io::BufWriter::new(Vec::new());
|
||||
let compiler = crate::Compiler::new(
|
||||
parser::Parser::new(tokenizer::Tokenizer::from($source)),
|
||||
Some(crate::CompilerConfig { debug: true }),
|
||||
);
|
||||
let res = compiler.compile();
|
||||
res.instructions.write(&mut writer)?;
|
||||
let output = output!(writer);
|
||||
crate::test::CompilationCheckResult {
|
||||
errors: res.errors,
|
||||
output,
|
||||
}
|
||||
}};
|
||||
}
|
||||
mod binary_expression;
|
||||
mod branching;
|
||||
|
||||
Reference in New Issue
Block a user