From 8edd04de27a1a1e7ec1566a85d4488fc52ede4d5 Mon Sep 17 00:00:00 2001 From: Young-Flash Date: Wed, 11 Dec 2024 15:36:45 +0800 Subject: [PATCH] internal: tweak moonrun --test-mode into --test-args --- crates/moonbuild/src/runtest.rs | 4 ++-- crates/moonrun/src/main.rs | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/crates/moonbuild/src/runtest.rs b/crates/moonbuild/src/runtest.rs index a1824e67..9f6eee0c 100644 --- a/crates/moonbuild/src/runtest.rs +++ b/crates/moonbuild/src/runtest.rs @@ -71,8 +71,8 @@ pub async fn run_wat( file_test_info_map: &FileTestInfo, verbose: bool, ) -> anyhow::Result>> { - // put "--test-mode" at the front of args - let mut _args = vec!["--test-mode".to_string()]; + // put "--test-args" at the front of args + let mut _args = vec!["--test-args".to_string()]; _args.push(serde_json_lenient::to_string(args).unwrap()); run( "moonrun", diff --git a/crates/moonrun/src/main.rs b/crates/moonrun/src/main.rs index 22556759..2d6d407a 100644 --- a/crates/moonrun/src/main.rs +++ b/crates/moonrun/src/main.rs @@ -420,7 +420,7 @@ fn wasm_mode( source: Source, args: &[String], no_stack_trace: bool, - test_mode: bool, + test_args: Option, ) -> anyhow::Result<()> { let isolate = &mut v8::Isolate::new(Default::default()); let scope = &mut v8::HandleScope::new(isolate); @@ -451,8 +451,8 @@ fn wasm_mode( let mut dtors = Vec::new(); init_env(&mut dtors, scope, args); - if test_mode { - let test_args = serde_json_lenient::from_str::(&args.join(" ")).unwrap(); + if let Some(ref test_args) = test_args { + let test_args = serde_json_lenient::from_str::(test_args).unwrap(); let file_and_index = test_args.file_and_index; let mut test_params: Vec<[String; 2]> = vec![]; @@ -465,7 +465,7 @@ fn wasm_mode( script.push_str(&format!("const testParams = {:?};", test_params)); } script.push_str(&format!("const no_stack_trace = {};", no_stack_trace)); - script.push_str(&format!("const test_mode = {};", test_mode)); + script.push_str(&format!("const test_mode = {};", test_args.is_some())); let js_glue = include_str!(concat!( env!("CARGO_MANIFEST_DIR"), "/src/template/js_glue.js" @@ -512,7 +512,7 @@ struct Commandline { no_stack_trace: bool, #[clap(long)] - test_mode: bool, + test_args: Option, #[clap(long)] stack_size: Option, @@ -542,7 +542,7 @@ fn run_interactive() -> anyhow::Result<()> { .collect::>() .join(", "); - wasm_mode(Source::Bytes(&bytes_string), &[], false, false)?; + wasm_mode(Source::Bytes(&bytes_string), &[], false, None)?; const END_MARKER: [u8; 4] = [0xFF, 0xFE, 0xFD, 0xFC]; io::stdout().write_all(&END_MARKER)?; io::stdout().write_all(b"\n")?; @@ -589,7 +589,7 @@ fn main() -> anyhow::Result<()> { Source::File(file), &matches.args, matches.no_stack_trace, - matches.test_mode, + matches.test_args, ) } _ => anyhow::bail!("Unsupported file type"),