just/src/testing.rs

48 lines
1.0 KiB
Rust
Raw Normal View History

use crate::common::*;
2017-11-16 23:30:08 -08:00
2019-04-19 02:17:43 -07:00
pub fn parse(text: &str) -> Justfile {
2017-11-18 03:36:02 -08:00
match Parser::parse(text) {
2017-11-16 23:30:08 -08:00
Ok(justfile) => justfile,
2019-04-19 02:17:43 -07:00
Err(error) => panic!("Expected successful parse but got error:\n {}", error),
2017-11-16 23:30:08 -08:00
}
}
2019-04-19 02:17:43 -07:00
macro_rules! error_test {
(
name: $name:ident,
input: $input:expr,
offset: $offset:expr,
line: $line:expr,
column: $column:expr,
width: $width:expr,
kind: $kind:expr,
) => {
#[test]
fn $name() {
2019-04-19 02:17:43 -07:00
let text: &str = $input;
let offset: usize = $offset;
let column: usize = $column;
let width: usize = $width;
let line: usize = $line;
let kind: CompilationErrorKind = $kind;
let expected = CompilationError {
text,
offset,
line,
column,
width,
kind,
};
2019-04-19 02:17:43 -07:00
match Parser::parse(text) {
Ok(_) => panic!("Compilation succeeded but expected: {}\n{}", expected, text),
Err(actual) => {
use pretty_assertions::assert_eq;
assert_eq!(actual, expected);
}
}
}
};
2017-11-16 23:30:08 -08:00
}