2019-04-11 15:23:14 -07:00
|
|
|
use crate::common::*;
|
2017-11-16 23:30:08 -08:00
|
|
|
|
2019-11-07 10:55:15 -08:00
|
|
|
pub(crate) fn compile(text: &str) -> Justfile {
|
|
|
|
match Compiler::compile(text) {
|
2017-11-16 23:30:08 -08:00
|
|
|
Ok(justfile) => justfile,
|
2019-11-07 10:55:15 -08:00
|
|
|
Err(error) => panic!("Expected successful compilation but got error:\n {}", error),
|
2017-11-16 23:30:08 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-17 20:04:54 -07:00
|
|
|
pub(crate) use test_utilities::{tempdir, unindent};
|
2019-07-06 20:55:46 -07:00
|
|
|
|
2019-11-07 10:55:15 -08:00
|
|
|
macro_rules! analysis_error {
|
2017-11-18 01:44:59 -08:00
|
|
|
(
|
2019-11-07 10:55:15 -08:00
|
|
|
name: $name:ident,
|
|
|
|
input: $input:expr,
|
|
|
|
offset: $offset:expr,
|
|
|
|
line: $line:expr,
|
|
|
|
column: $column:expr,
|
|
|
|
width: $width:expr,
|
|
|
|
kind: $kind:expr,
|
|
|
|
) => {
|
2017-11-18 01:44:59 -08:00
|
|
|
#[test]
|
|
|
|
fn $name() {
|
2019-11-07 10:55:15 -08:00
|
|
|
$crate::testing::error($input, $offset, $line, $column, $width, $kind);
|
2017-11-18 01:44:59 -08:00
|
|
|
}
|
2018-12-08 14:29:41 -08:00
|
|
|
};
|
2017-11-16 23:30:08 -08:00
|
|
|
}
|
2019-11-07 10:55:15 -08:00
|
|
|
|
|
|
|
pub(crate) fn error(
|
|
|
|
src: &str,
|
|
|
|
offset: usize,
|
|
|
|
line: usize,
|
|
|
|
column: usize,
|
|
|
|
width: usize,
|
|
|
|
kind: CompilationErrorKind,
|
|
|
|
) {
|
|
|
|
let expected = CompilationError {
|
|
|
|
src,
|
|
|
|
offset,
|
|
|
|
line,
|
|
|
|
column,
|
|
|
|
width,
|
|
|
|
kind,
|
|
|
|
};
|
|
|
|
|
|
|
|
let tokens = Lexer::lex(src).expect("Lexing failed in parse test...");
|
|
|
|
|
|
|
|
let module = Parser::parse(&tokens).expect("Parsing failed in analysis test...");
|
|
|
|
|
|
|
|
match Analyzer::analyze(module) {
|
|
|
|
Ok(_) => panic!("Analysis succeeded but expected: {}\n{}", expected, src),
|
|
|
|
Err(actual) => {
|
|
|
|
assert_eq!(actual, expected);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn readme_test() {
|
|
|
|
let mut justfiles = vec![];
|
|
|
|
let mut current = None;
|
|
|
|
|
|
|
|
for line in fs::read_to_string("README.adoc").unwrap().lines() {
|
|
|
|
if let Some(mut justfile) = current {
|
|
|
|
if line == "```" {
|
|
|
|
justfiles.push(justfile);
|
|
|
|
current = None;
|
|
|
|
} else {
|
|
|
|
justfile += line;
|
|
|
|
justfile += "\n";
|
|
|
|
current = Some(justfile);
|
|
|
|
}
|
|
|
|
} else if line == "```make" {
|
|
|
|
current = Some(String::new());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for justfile in justfiles {
|
|
|
|
compile(&justfile);
|
|
|
|
}
|
|
|
|
}
|