Skip to content

Commit

Permalink
test: add test for --enable-value-tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
Young-Flash committed Dec 26, 2024
1 parent ba87d4a commit b2e522f
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 1 deletion.
68 changes: 68 additions & 0 deletions crates/moon/tests/test_cases/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
"#######]],
);
}
4 changes: 4 additions & 0 deletions crates/moon/tests/test_cases/tracing_value.in/lib/hello.mbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pub fn hello() -> String {
"Hello, world!"
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"import": {}
}
6 changes: 6 additions & 0 deletions crates/moon/tests/test_cases/tracing_value.in/main.mbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fn main {
let a = 1
let b = 2
let c = a + b
println(c)
}
7 changes: 7 additions & 0 deletions crates/moon/tests/test_cases/tracing_value.in/main/main.mbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
fn main {
println(@lib.hello())
let a = 1
let b = 2
let c = a + b
println(c)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"is-main": true,
"import": {
"moon_new/lib": ""
}
}
3 changes: 3 additions & 0 deletions crates/moon/tests/test_cases/tracing_value.in/moon.mod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "moon_new"
}
2 changes: 1 addition & 1 deletion crates/moonbuild/src/gen/gen_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit b2e522f

Please sign in to comment.