Start work on a --wasm flag for the test subcommand
This commit is contained in:
parent
08ccf5babf
commit
51720beeb0
4 changed files with 48 additions and 17 deletions
|
|
@ -77,6 +77,10 @@ fn run() -> Result<()> {
|
|||
.long("quiet")
|
||||
.short("q");
|
||||
|
||||
let wasm_arg = Arg::with_name("wasm")
|
||||
.long("wasm")
|
||||
.help("compile parsers to wasm instead of native dynamic libraries");
|
||||
|
||||
let matches = App::new("tree-sitter")
|
||||
.author("Max Brunsfeld <maxbrunsfeld@gmail.com>")
|
||||
.about("Generates and tests parsers")
|
||||
|
|
@ -125,7 +129,7 @@ fn run() -> Result<()> {
|
|||
.arg(&debug_arg)
|
||||
.arg(&debug_build_arg)
|
||||
.arg(&debug_graph_arg)
|
||||
.arg(Arg::with_name("wasm").long("wasm").help("use wasm file"))
|
||||
.arg(&wasm_arg)
|
||||
.arg(Arg::with_name("debug-xml").long("xml").short("x"))
|
||||
.arg(
|
||||
Arg::with_name("stat")
|
||||
|
|
@ -201,7 +205,8 @@ fn run() -> Result<()> {
|
|||
)
|
||||
.arg(&debug_arg)
|
||||
.arg(&debug_build_arg)
|
||||
.arg(&debug_graph_arg),
|
||||
.arg(&debug_graph_arg)
|
||||
.arg(&wasm_arg),
|
||||
)
|
||||
.subcommand(
|
||||
SubCommand::with_name("highlight")
|
||||
|
|
@ -308,13 +313,25 @@ fn run() -> Result<()> {
|
|||
let debug_build = matches.is_present("debug-build");
|
||||
let update = matches.is_present("update");
|
||||
let filter = matches.value_of("filter");
|
||||
let wasm = matches.is_present("wasm");
|
||||
let mut parser = Parser::new();
|
||||
|
||||
loader.use_debug_build(debug_build);
|
||||
|
||||
if wasm {
|
||||
let engine = tree_sitter::wasmtime::Engine::default();
|
||||
parser
|
||||
.set_wasm_store(WasmStore::new(engine.clone()))
|
||||
.unwrap();
|
||||
loader.use_wasm(engine);
|
||||
}
|
||||
|
||||
let languages = loader.languages_at_path(¤t_dir)?;
|
||||
let language = languages
|
||||
.first()
|
||||
.ok_or_else(|| anyhow!("No language found"))?;
|
||||
parser.set_language(*language)?;
|
||||
|
||||
let test_dir = current_dir.join("test");
|
||||
|
||||
// Run the corpus tests. Look for them at two paths: `test/corpus` and `corpus`.
|
||||
|
|
@ -324,7 +341,7 @@ fn run() -> Result<()> {
|
|||
}
|
||||
if test_corpus_dir.is_dir() {
|
||||
test::run_tests_at_path(
|
||||
*language,
|
||||
&mut parser,
|
||||
&test_corpus_dir,
|
||||
debug,
|
||||
debug_graph,
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ impl Default for TestEntry {
|
|||
}
|
||||
|
||||
pub fn run_tests_at_path(
|
||||
language: Language,
|
||||
parser: &mut Parser,
|
||||
path: &Path,
|
||||
debug: bool,
|
||||
debug_graph: bool,
|
||||
|
|
@ -64,11 +64,9 @@ pub fn run_tests_at_path(
|
|||
) -> Result<()> {
|
||||
let test_entry = parse_tests(path)?;
|
||||
let mut _log_session = None;
|
||||
let mut parser = Parser::new();
|
||||
parser.set_language(language)?;
|
||||
|
||||
if debug_graph {
|
||||
_log_session = Some(util::log_graphs(&mut parser, "log.html")?);
|
||||
_log_session = Some(util::log_graphs(parser, "log.html")?);
|
||||
} else if debug {
|
||||
parser.set_logger(Some(Box::new(|log_type, message| {
|
||||
if log_type == LogType::Lex {
|
||||
|
|
@ -81,7 +79,7 @@ pub fn run_tests_at_path(
|
|||
let mut failures = Vec::new();
|
||||
let mut corrected_entries = Vec::new();
|
||||
run_tests(
|
||||
&mut parser,
|
||||
parser,
|
||||
test_entry,
|
||||
filter,
|
||||
0,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue