Skip to content

Commit

Permalink
Merge pull request #418 from moonbitlang/add_test_flag
Browse files Browse the repository at this point in the history
internal: add flag for whitebox & blackbox test
  • Loading branch information
Young-Flash authored Oct 25, 2024
2 parents 138be9e + c0ebb1c commit dfb67b6
Show file tree
Hide file tree
Showing 13 changed files with 90 additions and 51 deletions.
3 changes: 3 additions & 0 deletions crates/moon/tests/test_cases/alert_list.in/lib/hello.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ fn alert_1() -> Unit {
/// @alert alert_2 "alert_2"
fn alert_2() -> Unit {
}

pub fn hello() -> Unit {
}
1 change: 1 addition & 0 deletions crates/moon/tests/test_cases/alert_list.in/main/main.mbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
fn main {
alert_1();
alert_2();
@lib.hello()
}

/// @alert alert_1 "alert_1"
Expand Down
11 changes: 9 additions & 2 deletions crates/moon/tests/test_cases/cond_comp.in/moon.test
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@
$ moon check --dry-run --target js --sort-input --nostd
moonc check ./src/lib/all.mbt ./src/lib/js_and_release.mbt ./src/lib/js_or_wasm.mbt ./src/lib/only_js.mbt ./src/lib/wasm_release_or_js_debug.mbt -o ./target/js/release/check/lib/lib.mi -pkg username/hello/lib -pkg-sources username/hello/lib:./src/lib -target js
moonc check ./src/main/main.mbt -o ./target/js/release/check/main/main.mi -pkg username/hello/main -is-main -i ./target/js/release/check/lib/lib.mi:lib -pkg-sources username/hello/main:./src/main -target js
moonc check ./src/lib/hello_test.mbt ./src/lib/js_only_test.mbt -o ./target/js/release/check/lib/lib.blackbox_test.mi -pkg username/hello/lib_blackbox_test -i ./target/js/release/check/lib/lib.mi:lib -pkg-sources username/hello/lib_blackbox_test:./src/lib -target js
moonc check ./src/lib/hello_test.mbt ./src/lib/js_only_test.mbt -o ./target/js/release/check/lib/lib.blackbox_test.mi -pkg username/hello/lib_blackbox_test -i ./target/js/release/check/lib/lib.mi:lib -pkg-sources username/hello/lib_blackbox_test:./src/lib -target js -blackbox-test

$ moon test --dry-run --target js --sort-input --nostd
moon generate-test-driver --source-dir . --target-dir ./target/js/debug/test --package username/hello/lib --sort-input --target js --driver-kind blackbox
moonc build-package ./src/lib/all.mbt ./src/lib/js_or_wasm.mbt ./src/lib/only_debug.mbt ./src/lib/only_js.mbt ./src/lib/wasm_release_or_js_debug.mbt -o ./target/js/debug/test/lib/lib.core -pkg username/hello/lib -pkg-sources username/hello/lib:./src/lib -target js -g
moonc build-package ./src/lib/hello_test.mbt ./src/lib/js_only_test.mbt ./target/js/debug/test/lib/__generated_driver_for_blackbox_test.mbt -o ./target/js/debug/test/lib/lib.blackbox_test.core -pkg username/hello/lib_blackbox_test -is-main -i ./target/js/debug/test/lib/lib.mi:lib -pkg-sources username/hello/lib_blackbox_test:./src/lib -target js -g
moonc build-package ./src/lib/hello_test.mbt ./src/lib/js_only_test.mbt ./target/js/debug/test/lib/__generated_driver_for_blackbox_test.mbt -o ./target/js/debug/test/lib/lib.blackbox_test.core -pkg username/hello/lib_blackbox_test -is-main -i ./target/js/debug/test/lib/lib.mi:lib -pkg-sources username/hello/lib_blackbox_test:./src/lib -target js -g -blackbox-test
moonc link-core ./target/js/debug/test/lib/lib.core ./target/js/debug/test/lib/lib.blackbox_test.core -main username/hello/lib_blackbox_test -o ./target/js/debug/test/lib/lib.blackbox_test.js -test-mode -pkg-sources username/hello/lib:./src/lib -pkg-sources username/hello/lib_blackbox_test:./src/lib -exported_functions moonbit_test_driver_internal_execute -js-format cjs -target js -g
moon generate-test-driver --source-dir . --target-dir ./target/js/debug/test --package username/hello/lib --sort-input --target js --driver-kind internal
moonc build-package ./src/lib/all.mbt ./src/lib/js_or_wasm.mbt ./src/lib/only_debug.mbt ./src/lib/only_js.mbt ./src/lib/wasm_release_or_js_debug.mbt ./target/js/debug/test/lib/__generated_driver_for_internal_test.mbt -o ./target/js/debug/test/lib/lib.internal_test.core -pkg username/hello/lib -is-main -pkg-sources username/hello/lib:./src/lib -target js -g
Expand All @@ -66,6 +66,13 @@
│ ┬
│ ╰── Warning: Unused variable 'a'
───╯
Warning: [1029]
╭─[${WORK_DIR}/src/main/moon.pkg.json:4:5]
4 │ "username/hello/lib"
│ ──────────┬─────────
│ ╰─────────── Warning: Unused package 'username/hello/lib'
───╯
Finished. moon: ran 3 tasks, now up to date

$ xcat target/packages.json
Expand Down
84 changes: 42 additions & 42 deletions crates/moon/tests/test_cases/mod.rs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
$ moon check --dry-run --sort-input
moonc check ./src/lib/hello.mbt -o ./target/wasm-gc/release/check/lib/lib.mi -pkg username/hello/lib -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -pkg-sources username/hello/lib:./src/lib -target wasm-gc
moonc check ./src/main/main.mbt -o ./target/wasm-gc/release/check/main/main.mi -pkg username/hello/main -is-main -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -i ./target/wasm-gc/release/check/lib/lib.mi:lib -pkg-sources username/hello/main:./src/main -target wasm-gc
moonc check ./src/lib/hello_test.mbt -o ./target/wasm-gc/release/check/lib/lib.blackbox_test.mi -pkg username/hello/lib_blackbox_test -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -i ./target/wasm-gc/release/check/lib/lib.mi:lib -pkg-sources username/hello/lib_blackbox_test:./src/lib -target wasm-gc
moonc check ./src/lib/hello_test.mbt -o ./target/wasm-gc/release/check/lib/lib.blackbox_test.mi -pkg username/hello/lib_blackbox_test -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -i ./target/wasm-gc/release/check/lib/lib.mi:lib -pkg-sources username/hello/lib_blackbox_test:./src/lib -target wasm-gc -blackbox-test

$ moon build --dry-run --sort-input
moonc build-package ./src/lib/hello.mbt -o ./target/wasm-gc/release/build/lib/lib.core -pkg username/hello/lib -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -pkg-sources username/hello/lib:./src/lib -target wasm-gc
Expand All @@ -11,7 +11,7 @@
$ moon test --dry-run --sort-input
moon generate-test-driver --source-dir . --target-dir ./target/wasm-gc/debug/test --package username/hello/lib --sort-input --target wasm-gc --driver-kind blackbox
moonc build-package ./src/lib/hello.mbt -o ./target/wasm-gc/debug/test/lib/lib.core -pkg username/hello/lib -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -pkg-sources username/hello/lib:./src/lib -target wasm-gc -g
moonc build-package ./src/lib/hello_test.mbt ./target/wasm-gc/debug/test/lib/__generated_driver_for_blackbox_test.mbt -o ./target/wasm-gc/debug/test/lib/lib.blackbox_test.core -pkg username/hello/lib_blackbox_test -is-main -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -i ./target/wasm-gc/debug/test/lib/lib.mi:lib -pkg-sources username/hello/lib_blackbox_test:./src/lib -target wasm-gc -g
moonc build-package ./src/lib/hello_test.mbt ./target/wasm-gc/debug/test/lib/__generated_driver_for_blackbox_test.mbt -o ./target/wasm-gc/debug/test/lib/lib.blackbox_test.core -pkg username/hello/lib_blackbox_test -is-main -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -i ./target/wasm-gc/debug/test/lib/lib.mi:lib -pkg-sources username/hello/lib_blackbox_test:./src/lib -target wasm-gc -g -blackbox-test
moonc link-core $MOON_HOME/lib/core/target/wasm-gc/release/bundle/core.core ./target/wasm-gc/debug/test/lib/lib.core ./target/wasm-gc/debug/test/lib/lib.blackbox_test.core -main username/hello/lib_blackbox_test -o ./target/wasm-gc/debug/test/lib/lib.blackbox_test.wasm -test-mode -pkg-sources username/hello/lib:./src/lib -pkg-sources username/hello/lib_blackbox_test:./src/lib -pkg-sources moonbitlang/core:$MOON_HOME/lib/core -exported_functions moonbit_test_driver_internal_execute -target wasm-gc -g
moon generate-test-driver --source-dir . --target-dir ./target/wasm-gc/debug/test --package username/hello/lib --sort-input --target wasm-gc --driver-kind internal
moonc build-package ./src/lib/hello.mbt ./target/wasm-gc/debug/test/lib/__generated_driver_for_internal_test.mbt -o ./target/wasm-gc/debug/test/lib/lib.internal_test.core -pkg username/hello/lib -is-main -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -pkg-sources username/hello/lib:./src/lib -target wasm-gc -g
Expand Down
4 changes: 4 additions & 0 deletions crates/moon/tests/test_cases/test_deny_warn.in/lib/hello.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ fn alert_1() -> Unit {
/// @alert alert_2 "alert_2"
fn alert_2() -> Unit {
}

pub fn hello() -> Unit {
}

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
fn main {
let a = 0
@lib.hello()
}
2 changes: 1 addition & 1 deletion crates/moon/tests/test_cases/test_dot_source.in/moon.test
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
$ moon check --dry-run --sort-input
moonc check ./lib/hello.mbt -o ./target/wasm-gc/release/check/lib/lib.mi -pkg username/hello/lib -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -pkg-sources username/hello/lib:./lib -target wasm-gc
moonc check ./main/main.mbt -o ./target/wasm-gc/release/check/main/main.mi -pkg username/hello/main -is-main -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -i ./target/wasm-gc/release/check/lib/lib.mi:lib -pkg-sources username/hello/main:./main -target wasm-gc
moonc check ./lib/hello_test.mbt -o ./target/wasm-gc/release/check/lib/lib.blackbox_test.mi -pkg username/hello/lib_blackbox_test -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -i ./target/wasm-gc/release/check/lib/lib.mi:lib -pkg-sources username/hello/lib_blackbox_test:./lib -target wasm-gc
moonc check ./lib/hello_test.mbt -o ./target/wasm-gc/release/check/lib/lib.blackbox_test.mi -pkg username/hello/lib_blackbox_test -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -i ./target/wasm-gc/release/check/lib/lib.mi:lib -pkg-sources username/hello/lib_blackbox_test:./lib -target wasm-gc -blackbox-test

3 changes: 1 addition & 2 deletions crates/moon/tests/test_cases/warn_list.in/lib/hello.mbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
pub fn hello() -> String {
pub fn hello() -> Unit {
let a = 0
"Hello, world!"
}
4 changes: 2 additions & 2 deletions crates/moon/tests/test_cases/warn_list.in/lib1/hello.mbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub fn hello() -> String {
"Hello, world!"
pub fn hello() -> Unit {

}

fn t() -> Unit {
Expand Down
2 changes: 2 additions & 0 deletions crates/moon/tests/test_cases/warn_list.in/main/main.mbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
fn main {
let a = 0
@lib.hello()
@lib1.hello()
}

fn t() -> Unit {
Expand Down
10 changes: 10 additions & 0 deletions crates/moonbuild/src/gen/gen_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ pub struct CheckDepItem {
pub package_full_name: String,
pub package_source_dir: String,
pub is_main: bool,
pub is_whitebox_test: bool,
pub is_blackbox_test: bool,
}

#[derive(Debug)]
Expand Down Expand Up @@ -97,6 +99,8 @@ fn pkg_to_check_item(
package_full_name,
package_source_dir,
is_main: pkg.is_main,
is_whitebox_test: false,
is_blackbox_test: false,
})
}

Expand Down Expand Up @@ -161,6 +165,8 @@ fn pkg_with_wbtest_to_check_item(
package_full_name,
package_source_dir,
is_main: pkg.is_main,
is_whitebox_test: true,
is_blackbox_test: false,
})
}

Expand Down Expand Up @@ -246,6 +252,8 @@ fn pkg_with_test_to_check_item(
package_full_name,
package_source_dir,
is_main: pkg.is_main,
is_whitebox_test: false,
is_blackbox_test: true,
})
}

Expand Down Expand Up @@ -364,6 +372,8 @@ pub fn gen_check_command(
&item.package_full_name, &item.package_source_dir
))
.args(["-target", moonc_opt.build_opt.target_backend.to_flag()])
.arg_with_cond(item.is_whitebox_test, "-whitebox-test")
.arg_with_cond(item.is_blackbox_test, "-blackbox-test")
.build();
log::debug!("Command: {}", command);
build.cmdline = Some(command);
Expand Down
12 changes: 12 additions & 0 deletions crates/moonbuild/src/gen/gen_runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ pub struct RuntestDepItem {
pub package_source_dir: String,
pub is_main: bool,
pub is_third_party: bool,
pub is_whitebox_test: bool,
pub is_blackbox_test: bool,
}

#[derive(Debug)]
Expand Down Expand Up @@ -181,6 +183,8 @@ pub fn gen_package_core(
package_source_dir,
is_main: false,
is_third_party: pkg.is_third_party,
is_whitebox_test: false,
is_blackbox_test: false,
})
}

Expand Down Expand Up @@ -248,6 +252,8 @@ pub fn gen_package_internal_test(
package_source_dir,
is_main: true,
is_third_party: pkg.is_third_party,
is_whitebox_test: false,
is_blackbox_test: false,
})
}

Expand Down Expand Up @@ -323,6 +329,8 @@ pub fn gen_package_whitebox_test(
package_source_dir,
is_main: true,
is_third_party: pkg.is_third_party,
is_whitebox_test: true,
is_blackbox_test: false,
})
}

Expand Down Expand Up @@ -420,6 +428,8 @@ pub fn gen_package_blackbox_test(
package_source_dir,
is_main: true,
is_third_party: pkg.is_third_party,
is_whitebox_test: false,
is_blackbox_test: true,
})
}

Expand Down Expand Up @@ -812,6 +822,8 @@ pub fn gen_runtest_build_command(
// Coverage arg
.args(coverage_args.iter())
.args(moonc_opt.extra_build_opt.iter())
.arg_with_cond(item.is_whitebox_test, "-whitebox-test")
.arg_with_cond(item.is_blackbox_test, "-blackbox-test")
.build();
log::debug!("Command: {}", command);
build.cmdline = Some(command);
Expand Down

0 comments on commit dfb67b6

Please sign in to comment.