Skip to content

Commit

Permalink
fix passing args to moonrun (#487)
Browse files Browse the repository at this point in the history
  • Loading branch information
Young-Flash authored Nov 21, 2024
1 parent 9dbfd0e commit 09f9369
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 5 deletions.
25 changes: 21 additions & 4 deletions crates/moon/tests/test_cases/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4835,7 +4835,7 @@ fn test_moon_run_with_cli_args() {
check(
get_stdout(&dir, ["run", "main", "--dry-run"]),
expect![[r#"
moonc build-package ./main/main.mbt -o ./target/wasm-gc/release/build/main/main.core -pkg username/hello/main -is-main -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -pkg-sources username/hello/main:./main -target wasm-gc
moonc build-package ./main/main_wasm.mbt -o ./target/wasm-gc/release/build/main/main.core -pkg username/hello/main -is-main -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -pkg-sources username/hello/main:./main -target wasm-gc
moonc link-core $MOON_HOME/lib/core/target/wasm-gc/release/bundle/core.core ./target/wasm-gc/release/build/main/main.core -main username/hello/main -o ./target/wasm-gc/release/build/main/main.wasm -pkg-config-path ./main/moon.pkg.json -pkg-sources username/hello/main:./main -pkg-sources moonbitlang/core:$MOON_HOME/lib/core -target wasm-gc
moonrun ./target/wasm-gc/release/build/main/main.wasm
"#]],
Expand All @@ -4856,16 +4856,33 @@ fn test_moon_run_with_cli_args() {
],
),
expect![[r#"
moonc build-package ./main/main.mbt -o ./target/wasm-gc/release/build/main/main.core -pkg username/hello/main -is-main -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -pkg-sources username/hello/main:./main -target wasm-gc
moonc build-package ./main/main_wasm.mbt -o ./target/wasm-gc/release/build/main/main.core -pkg username/hello/main -is-main -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -pkg-sources username/hello/main:./main -target wasm-gc
moonc link-core $MOON_HOME/lib/core/target/wasm-gc/release/bundle/core.core ./target/wasm-gc/release/build/main/main.core -main username/hello/main -o ./target/wasm-gc/release/build/main/main.wasm -pkg-config-path ./main/moon.pkg.json -pkg-sources username/hello/main:./main -pkg-sources moonbitlang/core:$MOON_HOME/lib/core -target wasm-gc
moonrun ./target/wasm-gc/release/build/main/main.wasm -- 中文 😄👍 hello 1242
"#]],
);

check(
get_stdout(&dir, ["run", "main", "--", "中文", "😄👍", "hello", "1242"]),
get_stdout(
&dir,
[
"run", "main", "--", "中文", "😄👍", "hello", "1242", "--flag",
],
),
expect![[r#"
["中文", "😄👍", "hello", "1242", "--flag"]
"#]],
);

check(
get_stdout(
&dir,
[
"run", "main", "--target", "js", "--", "中文", "😄👍", "hello", "1242", "--flag",
],
),
expect![[r#"
["中文", "😄👍", "hello", "1242"]
["--", "中文", "😄👍", "hello", "1242", "--flag"]
"#]],
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
pub fn get_args() -> Array[String] {
get_cli_args_internal()
}

extern "js" fn get_cli_args_internal() -> Array[String] =
#| function() {
#| return process.argv.slice(2);
#| }

fn main {
get_args() |> println
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{
"is-main": true
"is-main": true,
"targets": {
"main_wasm.mbt": ["wasm", "wasm-gc"],
"main_js.mbt": ["js"]
}
}
1 change: 1 addition & 0 deletions crates/moonbuild/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ fn run(command: &str, path: &Path, args: &[String], verbose: bool) -> anyhow::Re
}
let mut execution = Command::new(command)
.arg(path)
.arg("--")
.args(args)
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
Expand Down

0 comments on commit 09f9369

Please sign in to comment.