diff --git a/crates/moon/tests/test_cases/mod.rs b/crates/moon/tests/test_cases/mod.rs index 9c88751e..db8a6707 100644 --- a/crates/moon/tests/test_cases/mod.rs +++ b/crates/moon/tests/test_cases/mod.rs @@ -8218,3 +8218,71 @@ fn test_strip_debug() { "#]], ); } + +#[test] +fn test_tracing_value() { + let dir = TestDir::new("tracing_value.in"); + + // main.mbt in package + check( + get_stdout( + &dir, + [ + "run", + "./main/main.mbt", + "--enable-value-tracing", + "--dry-run", + ], + ), + expect![[r#" + moonc build-package ./lib/hello.mbt -o ./target/wasm-gc/release/build/lib/lib.core -pkg moon_new/lib -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -pkg-sources moon_new/lib:./lib -target wasm-gc + moonc build-package ./main/main.mbt -o ./target/wasm-gc/release/build/main/main.core -pkg moon_new/main -is-main -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -i ./target/wasm-gc/release/build/lib/lib.mi:lib -pkg-sources moon_new/main:./main -target wasm-gc -enable-value-tracing + moonc link-core $MOON_HOME/lib/core/target/wasm-gc/release/bundle/core.core ./target/wasm-gc/release/build/lib/lib.core ./target/wasm-gc/release/build/main/main.core -main moon_new/main -o ./target/wasm-gc/release/build/main/main.wasm -pkg-config-path ./main/moon.pkg.json -pkg-sources moon_new/lib:./lib -pkg-sources moon_new/main:./main -pkg-sources moonbitlang/core:$MOON_HOME/lib/core -target wasm-gc + moonrun ./target/wasm-gc/release/build/main/main.wasm + "#]], + ); + check( + get_stdout(&dir, ["run", "./main/main.mbt", "--enable-value-tracing"]), + expect![[r#" + Hello, world! + ######MOONBIT_VALUE_TRACING_START###### + {"name":"a","value":"1","line":"3","start_column":"7","end_column":"8"} + ######MOONBIT_VALUE_TRACING_END###### + ######MOONBIT_VALUE_TRACING_START###### + {"name":"b","value":"2","line":"4","start_column":"7","end_column":"8"} + ######MOONBIT_VALUE_TRACING_END###### + ######MOONBIT_VALUE_TRACING_START###### + {"name":"c","value":"3","line":"5","start_column":"7","end_column":"8"} + ######MOONBIT_VALUE_TRACING_END###### + 3 + "#]], + ); + + // single file + check( + get_stdout( + &dir, + ["run", "./main.mbt", "--enable-value-tracing", "--dry-run"], + ), + expect![[r#" + moonc build-package $ROOT/main.mbt -o $ROOT/target/main.core -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -is-main -pkg moon/run/single -g -O0 -source-map -target wasm-gc -enable-value-tracing + moonc link-core $MOON_HOME/lib/core/target/wasm-gc/release/bundle/core.core $ROOT/target/main.core -o $ROOT/target/main.wasm -pkg-sources moon/run/single:$ROOT -pkg-sources moonbitlang/core:$MOON_HOME/lib/core -g -O0 -source-map -target wasm-gc + moonrun $ROOT/target/main.wasm + "#]], + ); + check( + get_stdout(&dir, ["run", "./main.mbt", "--enable-value-tracing"]), + expect![[r#######" + ######MOONBIT_VALUE_TRACING_START###### + {"name":"a","value":"1","line":"2","start_column":"7","end_column":"8"} + ######MOONBIT_VALUE_TRACING_END###### + ######MOONBIT_VALUE_TRACING_START###### + {"name":"b","value":"2","line":"3","start_column":"7","end_column":"8"} + ######MOONBIT_VALUE_TRACING_END###### + ######MOONBIT_VALUE_TRACING_START###### + {"name":"c","value":"3","line":"4","start_column":"7","end_column":"8"} + ######MOONBIT_VALUE_TRACING_END###### + 3 + "#######]], + ); +} diff --git a/crates/moon/tests/test_cases/tracing_value.in/lib/hello.mbt b/crates/moon/tests/test_cases/tracing_value.in/lib/hello.mbt new file mode 100644 index 00000000..a7ac2bee --- /dev/null +++ b/crates/moon/tests/test_cases/tracing_value.in/lib/hello.mbt @@ -0,0 +1,4 @@ +pub fn hello() -> String { + "Hello, world!" +} + diff --git a/crates/moon/tests/test_cases/tracing_value.in/lib/moon.pkg.json b/crates/moon/tests/test_cases/tracing_value.in/lib/moon.pkg.json new file mode 100644 index 00000000..9585a087 --- /dev/null +++ b/crates/moon/tests/test_cases/tracing_value.in/lib/moon.pkg.json @@ -0,0 +1,3 @@ +{ + "import": {} +} diff --git a/crates/moon/tests/test_cases/tracing_value.in/main.mbt b/crates/moon/tests/test_cases/tracing_value.in/main.mbt new file mode 100644 index 00000000..984b291c --- /dev/null +++ b/crates/moon/tests/test_cases/tracing_value.in/main.mbt @@ -0,0 +1,6 @@ +fn main { + let a = 1 + let b = 2 + let c = a + b + println(c) +} diff --git a/crates/moon/tests/test_cases/tracing_value.in/main/main.mbt b/crates/moon/tests/test_cases/tracing_value.in/main/main.mbt new file mode 100644 index 00000000..0291b343 --- /dev/null +++ b/crates/moon/tests/test_cases/tracing_value.in/main/main.mbt @@ -0,0 +1,7 @@ +fn main { + println(@lib.hello()) + let a = 1 + let b = 2 + let c = a + b + println(c) +} diff --git a/crates/moon/tests/test_cases/tracing_value.in/main/moon.pkg.json b/crates/moon/tests/test_cases/tracing_value.in/main/moon.pkg.json new file mode 100644 index 00000000..4343a4ef --- /dev/null +++ b/crates/moon/tests/test_cases/tracing_value.in/main/moon.pkg.json @@ -0,0 +1,6 @@ +{ + "is-main": true, + "import": { + "moon_new/lib": "" + } +} \ No newline at end of file diff --git a/crates/moon/tests/test_cases/tracing_value.in/moon.mod.json b/crates/moon/tests/test_cases/tracing_value.in/moon.mod.json new file mode 100644 index 00000000..b5d8b346 --- /dev/null +++ b/crates/moon/tests/test_cases/tracing_value.in/moon.mod.json @@ -0,0 +1,3 @@ +{ + "name": "moon_new" +} diff --git a/crates/moonbuild/src/gen/gen_build.rs b/crates/moonbuild/src/gen/gen_build.rs index 4a263ce0..d1dd34dd 100644 --- a/crates/moonbuild/src/gen/gen_build.rs +++ b/crates/moonbuild/src/gen/gen_build.rs @@ -248,7 +248,6 @@ pub fn gen_build_command( let command = CommandBuilder::new("moonc") .arg("build-package") - .arg_with_cond(item.enable_value_tracing, "-enable-value-tracing") .args_with_cond(moonc_opt.render, vec!["-error-format", "json"]) .args_with_cond( moonc_opt.build_opt.deny_warn, @@ -297,6 +296,7 @@ pub fn gen_build_command( .arg_with_cond(enable_coverage, "-enable-coverage") .arg_with_cond(self_coverage, "-coverage-package-override=@self") .args(moonc_opt.extra_build_opt.iter()) + .arg_with_cond(item.enable_value_tracing, "-enable-value-tracing") .build(); log::debug!("Command: {}", command); build.cmdline = Some(command);