Skip to content

Commit

Permalink
Merge pull request #523 from moonbitlang/moonrun_args
Browse files Browse the repository at this point in the history
internal: tweak moonrun --test-mode into --test-args
  • Loading branch information
Young-Flash authored Dec 11, 2024
2 parents 7b74455 + 8edd04d commit 1d00d44
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions crates/moonbuild/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ pub async fn run_wat(
file_test_info_map: &FileTestInfo,
verbose: bool,
) -> anyhow::Result<Vec<Result<TestStatistics, TestFailedStatus>>> {
// 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",
Expand Down
14 changes: 7 additions & 7 deletions crates/moonrun/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ fn wasm_mode(
source: Source,
args: &[String],
no_stack_trace: bool,
test_mode: bool,
test_args: Option<String>,
) -> anyhow::Result<()> {
let isolate = &mut v8::Isolate::new(Default::default());
let scope = &mut v8::HandleScope::new(isolate);
Expand Down Expand Up @@ -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::<TestArgs>(&args.join(" ")).unwrap();
if let Some(ref test_args) = test_args {
let test_args = serde_json_lenient::from_str::<TestArgs>(test_args).unwrap();
let file_and_index = test_args.file_and_index;

let mut test_params: Vec<[String; 2]> = vec![];
Expand All @@ -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"
Expand Down Expand Up @@ -512,7 +512,7 @@ struct Commandline {
no_stack_trace: bool,

#[clap(long)]
test_mode: bool,
test_args: Option<String>,

#[clap(long)]
stack_size: Option<String>,
Expand Down Expand Up @@ -542,7 +542,7 @@ fn run_interactive() -> anyhow::Result<()> {
.collect::<Vec<_>>()
.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")?;
Expand Down Expand Up @@ -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"),
Expand Down

0 comments on commit 1d00d44

Please sign in to comment.