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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Gargantuan refactor (#522)
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
2019-11-09 21:43:20 -08:00
|
|
|
pub(crate) fn config(args: &[&str]) -> Config {
|
|
|
|
let mut args = Vec::from(args);
|
|
|
|
args.insert(0, "just");
|
|
|
|
|
|
|
|
let app = Config::app();
|
|
|
|
|
|
|
|
let matches = app.get_matches_from_safe(args).unwrap();
|
|
|
|
|
|
|
|
Config::from_matches(&matches).unwrap()
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|