Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lijunchen committed Jan 6, 2025
1 parent 76a6b3a commit d4e0655
Showing 1 changed file with 97 additions and 3 deletions.
100 changes: 97 additions & 3 deletions crates/moon/tests/test_cases/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1695,7 +1695,8 @@ fn test_moon_test_with_local_dep() {
check(
get_stdout(&dir, ["run", "main", "--frozen"]),
expect![[r#"
Hello, world!
hello from mooncake
hello from mooncake2
"#]],
);
// Run moon info
Expand Down Expand Up @@ -1734,17 +1735,63 @@ fn test_moon_test_with_local_dep() {
mods
mods/lijunchen
mods/lijunchen/mooncake
mods/lijunchen/mooncake/.mooncakes
mods/lijunchen/mooncake/lib
mods/lijunchen/mooncake/lib/hello.mbt
mods/lijunchen/mooncake/lib/hello_wbtest.mbt
mods/lijunchen/mooncake/lib/moon.pkg.json
mods/lijunchen/mooncake/moon.mod.json
mods/lijunchen/mooncake/moon.pkg.json
mods/lijunchen/mooncake/target
mods/lijunchen/mooncake/target/.moon-lock
mods/lijunchen/mooncake/target/common
mods/lijunchen/mooncake/target/common/.moon-lock
mods/lijunchen/mooncake/target/packages.json
mods/lijunchen/mooncake/target/wasm-gc
mods/lijunchen/mooncake/target/wasm-gc/release
mods/lijunchen/mooncake/target/wasm-gc/release/check
mods/lijunchen/mooncake/target/wasm-gc/release/check/.moon-lock
mods/lijunchen/mooncake/target/wasm-gc/release/check/check.moon_db
mods/lijunchen/mooncake/target/wasm-gc/release/check/check.output
mods/lijunchen/mooncake/target/wasm-gc/release/check/lib
mods/lijunchen/mooncake/target/wasm-gc/release/check/lib/lib.mi
mods/lijunchen/mooncake/target/wasm-gc/release/check/lib/lib.whitebox_test.mi
mods/lijunchen/mooncake/target/wasm-gc/release/check/moon.db
mods/lijunchen/mooncake/target/wasm-gc/release/check/mooncake.mi
mods/lijunchen/mooncake/top.mbt
mods/lijunchen/mooncake2
mods/lijunchen/mooncake2/moon.mod.json
mods/lijunchen/mooncake2/src
mods/lijunchen/mooncake2/src/lib
mods/lijunchen/mooncake2/src/lib/hello.mbt
mods/lijunchen/mooncake2/src/lib/hello_wbtest.mbt
mods/lijunchen/mooncake2/src/lib/moon.pkg.json
mods/lijunchen/mooncake2/src/moon.pkg.json
mods/lijunchen/mooncake2/src/top.mbt
moon.mod.json"#]],
);
}

#[test]
fn test_pkg_source_in() {
let dir = TestDir::new("moon_test_with_local_dep.in");
let out = get_stdout(&dir, ["build", "--dry-run", "--sort-input", "--frozen"]);
check(
&out,
expect![[r#"
moonc build-package ./mods/lijunchen/mooncake/lib/hello.mbt -o ./target/wasm-gc/release/build/.mooncakes/lijunchen/mooncake/lib/lib.core -pkg lijunchen/mooncake/lib -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -pkg-sources lijunchen/mooncake/lib:./mods/lijunchen/mooncake/lib -target wasm-gc
moonc build-package ./mods/lijunchen/mooncake2/src/lib/hello.mbt -o ./target/wasm-gc/release/build/.mooncakes/lijunchen/mooncake2/lib/lib.core -pkg lijunchen/mooncake2/lib -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -pkg-sources lijunchen/mooncake2/lib:./mods/lijunchen/mooncake2/src/lib -target wasm-gc
moonc build-package ./lib/hello.mbt -o ./target/wasm-gc/release/build/lib/lib.core -pkg hello31/lib -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -pkg-sources hello31/lib:./lib -target wasm-gc
moonc build-package ./mods/lijunchen/mooncake/top.mbt -o ./target/wasm-gc/release/build/.mooncakes/lijunchen/mooncake/mooncake.core -pkg lijunchen/mooncake -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -i ./target/wasm-gc/release/build/.mooncakes/lijunchen/mooncake/lib/lib.mi:lib -pkg-sources lijunchen/mooncake:./mods/lijunchen/mooncake -target wasm-gc
moonc build-package ./mods/lijunchen/mooncake2/src/top.mbt -o ./target/wasm-gc/release/build/.mooncakes/lijunchen/mooncake2/mooncake2.core -pkg lijunchen/mooncake2 -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -i ./target/wasm-gc/release/build/.mooncakes/lijunchen/mooncake2/lib/lib.mi:lib -pkg-sources lijunchen/mooncake2:./mods/lijunchen/mooncake2/src -target wasm-gc
moonc build-package ./main/main.mbt -o ./target/wasm-gc/release/build/main/main.core -pkg hello31/main -is-main -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -i ./target/wasm-gc/release/build/lib/lib.mi:lib -i ./target/wasm-gc/release/build/.mooncakes/lijunchen/mooncake/mooncake.mi:mooncake -i ./target/wasm-gc/release/build/.mooncakes/lijunchen/mooncake2/mooncake2.mi:mooncake2 -pkg-sources hello31/main:./main -target wasm-gc
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/.mooncakes/lijunchen/mooncake/lib/lib.core ./target/wasm-gc/release/build/.mooncakes/lijunchen/mooncake/mooncake.core ./target/wasm-gc/release/build/.mooncakes/lijunchen/mooncake2/lib/lib.core ./target/wasm-gc/release/build/.mooncakes/lijunchen/mooncake2/mooncake2.core ./target/wasm-gc/release/build/main/main.core -main hello31/main -o ./target/wasm-gc/release/build/main/main.wasm -pkg-config-path ./main/moon.pkg.json -pkg-sources hello31/lib:./lib -pkg-sources lijunchen/mooncake/lib:./mods/lijunchen/mooncake/lib -pkg-sources lijunchen/mooncake:./mods/lijunchen/mooncake -pkg-sources lijunchen/mooncake2/lib:./mods/lijunchen/mooncake2/src/lib -pkg-sources lijunchen/mooncake2:./mods/lijunchen/mooncake2/src -pkg-sources hello31/main:./main -pkg-sources moonbitlang/core:$MOON_HOME/lib/core -target wasm-gc
"#]],
);
assert!(out.contains("lijunchen/mooncake:./mods/lijunchen/mooncake"));
assert!(out.contains("lijunchen/mooncake2:./mods/lijunchen/mooncake2/src"));
}

#[test]
fn test_output_format() {
let dir = TestDir::new("output-format.in");
Expand Down Expand Up @@ -4948,7 +4995,7 @@ fn test_third_party() {
moon generate-test-driver --source-dir . --target-dir ./target --package username/hello/lib --sort-input --target wasm-gc --driver-kind internal
moonc build-package ./.mooncakes/lijunchen/hello18/lib/hello.mbt -o ./target/wasm-gc/debug/test/.mooncakes/lijunchen/hello18/lib/lib.core -pkg lijunchen/hello18/lib -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -pkg-sources lijunchen/hello18/lib:./.mooncakes/lijunchen/hello18/lib -target wasm-gc -g -O0
moonc build-package ./lib/test.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 -i ./target/wasm-gc/debug/test/.mooncakes/lijunchen/hello18/lib/lib.mi:lib -pkg-sources username/hello/lib:./lib -target wasm-gc -g -O0 -no-mi
moonc link-core $MOON_HOME/lib/core/target/wasm-gc/release/bundle/core.core ./target/wasm-gc/debug/test/.mooncakes/lijunchen/hello18/lib/lib.core ./target/wasm-gc/debug/test/lib/lib.internal_test.core -main username/hello/lib -o ./target/wasm-gc/debug/test/lib/lib.internal_test.wasm -test-mode -pkg-config-path ./lib/moon.pkg.json -pkg-sources lijunchen/hello18/lib:./lib -pkg-sources username/hello/lib:./lib -pkg-sources moonbitlang/core:$MOON_HOME/lib/core -exported_functions moonbit_test_driver_internal_execute,moonbit_test_driver_finish -target wasm-gc -g -O0
moonc link-core $MOON_HOME/lib/core/target/wasm-gc/release/bundle/core.core ./target/wasm-gc/debug/test/.mooncakes/lijunchen/hello18/lib/lib.core ./target/wasm-gc/debug/test/lib/lib.internal_test.core -main username/hello/lib -o ./target/wasm-gc/debug/test/lib/lib.internal_test.wasm -test-mode -pkg-config-path ./lib/moon.pkg.json -pkg-sources lijunchen/hello18/lib:./.mooncakes/lijunchen/hello18/lib -pkg-sources username/hello/lib:./lib -pkg-sources moonbitlang/core:$MOON_HOME/lib/core -exported_functions moonbit_test_driver_internal_execute,moonbit_test_driver_finish -target wasm-gc -g -O0
"#]],
);

Expand All @@ -4968,6 +5015,53 @@ fn test_third_party() {
assert!(actual.contains("Hello, world!"));
}

#[test]
fn test_moonbitlang_x() {
if std::env::var("CI").is_err() {
return;
}
let dir = TestDir::new("test_moonbitlang_x.in");
get_stdout(&dir, ["update"]);

let build_output = get_stdout(&dir, ["build", "--dry-run", "--sort-input"]);

check(
&build_output,
expect![[r#"
moonc build-package ./.mooncakes/moonbitlang/x/stack/stack.mbt ./.mooncakes/moonbitlang/x/stack/types.mbt -w -29 -o ./target/wasm-gc/release/build/.mooncakes/moonbitlang/x/stack/stack.core -pkg moonbitlang/x/stack -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -pkg-sources moonbitlang/x/stack:./.mooncakes/moonbitlang/x/stack -target wasm-gc
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 -i ./target/wasm-gc/release/build/.mooncakes/moonbitlang/x/stack/stack.mi:stack -pkg-sources username/hello/lib:./src/lib -target wasm-gc
moonc build-package ./src/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 -i ./target/wasm-gc/release/build/lib/lib.mi:lib -i ./target/wasm-gc/release/build/.mooncakes/moonbitlang/x/stack/stack.mi:stack -pkg-sources username/hello/main:./src/main -target wasm-gc
moonc link-core $MOON_HOME/lib/core/target/wasm-gc/release/bundle/core.core ./target/wasm-gc/release/build/.mooncakes/moonbitlang/x/stack/stack.core ./target/wasm-gc/release/build/lib/lib.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 ./src/main/moon.pkg.json -pkg-sources moonbitlang/x/stack:./.mooncakes/moonbitlang/x/stack -pkg-sources username/hello/lib:./src/lib -pkg-sources username/hello/main:./src/main -pkg-sources moonbitlang/core:$MOON_HOME/lib/core -target wasm-gc
moonc build-package ./.mooncakes/moonbitlang/x/internal/ffi/byte_array_wasm.mbt ./.mooncakes/moonbitlang/x/internal/ffi/dir_wasm.mbt ./.mooncakes/moonbitlang/x/internal/ffi/string_wasm.mbt -w -29 -o ./target/wasm-gc/release/build/.mooncakes/moonbitlang/x/internal/ffi/ffi.core -pkg moonbitlang/x/internal/ffi -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -pkg-sources moonbitlang/x/internal/ffi:./.mooncakes/moonbitlang/x/internal/ffi -target wasm-gc
moonc build-package ./.mooncakes/moonbitlang/x/fs/internal/ffi/fs_wasm.mbt -w -29 -o ./target/wasm-gc/release/build/.mooncakes/moonbitlang/x/fs/internal/ffi/ffi.core -pkg moonbitlang/x/fs/internal/ffi -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -i ./target/wasm-gc/release/build/.mooncakes/moonbitlang/x/internal/ffi/ffi.mi:ffi -pkg-sources moonbitlang/x/fs/internal/ffi:./.mooncakes/moonbitlang/x/fs/internal/ffi -target wasm-gc
moonc build-package ./.mooncakes/moonbitlang/x/fs/fs.mbt -w -29 -o ./target/wasm-gc/release/build/.mooncakes/moonbitlang/x/fs/fs.core -pkg moonbitlang/x/fs -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -i ./target/wasm-gc/release/build/.mooncakes/moonbitlang/x/fs/internal/ffi/ffi.mi:ffi -pkg-sources moonbitlang/x/fs:./.mooncakes/moonbitlang/x/fs -target wasm-gc
moonc link-core $MOON_HOME/lib/core/target/wasm-gc/release/bundle/core.core ./target/wasm-gc/release/build/.mooncakes/moonbitlang/x/internal/ffi/ffi.core ./target/wasm-gc/release/build/.mooncakes/moonbitlang/x/fs/internal/ffi/ffi.core ./target/wasm-gc/release/build/.mooncakes/moonbitlang/x/fs/fs.core -main moonbitlang/x/fs -o ./target/wasm-gc/release/build/.mooncakes/moonbitlang/x/fs/fs.wasm -pkg-config-path ./.mooncakes/moonbitlang/x/fs/moon.pkg.json -pkg-sources moonbitlang/x/internal/ffi:./.mooncakes/moonbitlang/x/internal/ffi -pkg-sources moonbitlang/x/fs/internal/ffi:./.mooncakes/moonbitlang/x/fs/internal/ffi -pkg-sources moonbitlang/x/fs:./.mooncakes/moonbitlang/x/fs -pkg-sources moonbitlang/core:$MOON_HOME/lib/core -target wasm-gc
"#]],
);

let test_output = get_stdout(&dir, ["test", "--dry-run", "--sort-input"]);
check(
&test_output,
expect![[r#"
moonc build-package ./.mooncakes/moonbitlang/x/stack/stack.mbt ./.mooncakes/moonbitlang/x/stack/types.mbt -w -29 -o ./target/wasm-gc/debug/test/.mooncakes/moonbitlang/x/stack/stack.core -pkg moonbitlang/x/stack -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -pkg-sources moonbitlang/x/stack:./.mooncakes/moonbitlang/x/stack -target wasm-gc -g -O0
moon generate-test-driver --source-dir . --target-dir ./target --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 -i ./target/wasm-gc/debug/test/.mooncakes/moonbitlang/x/stack/stack.mi:stack -pkg-sources username/hello/lib:./src/lib -target wasm-gc -g -O0
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 -i ./target/wasm-gc/debug/test/.mooncakes/moonbitlang/x/stack/stack.mi:stack -pkg-sources username/hello/lib_blackbox_test:./src/lib -target wasm-gc -g -O0 -blackbox-test -no-mi
moonc link-core $MOON_HOME/lib/core/target/wasm-gc/release/bundle/core.core ./target/wasm-gc/debug/test/.mooncakes/moonbitlang/x/stack/stack.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-config-path ./src/lib/moon.pkg.json -pkg-sources moonbitlang/x/stack:./.mooncakes/moonbitlang/x/stack -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,moonbit_test_driver_finish -target wasm-gc -g -O0
moon generate-test-driver --source-dir . --target-dir ./target --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 -i ./target/wasm-gc/debug/test/.mooncakes/moonbitlang/x/stack/stack.mi:stack -pkg-sources username/hello/lib:./src/lib -target wasm-gc -g -O0 -no-mi
moonc link-core $MOON_HOME/lib/core/target/wasm-gc/release/bundle/core.core ./target/wasm-gc/debug/test/.mooncakes/moonbitlang/x/stack/stack.core ./target/wasm-gc/debug/test/lib/lib.internal_test.core -main username/hello/lib -o ./target/wasm-gc/debug/test/lib/lib.internal_test.wasm -test-mode -pkg-config-path ./src/lib/moon.pkg.json -pkg-sources moonbitlang/x/stack:./.mooncakes/moonbitlang/x/stack -pkg-sources username/hello/lib:./src/lib -pkg-sources moonbitlang/core:$MOON_HOME/lib/core -exported_functions moonbit_test_driver_internal_execute,moonbit_test_driver_finish -target wasm-gc -g -O0
"#]],
);

check(
get_stdout(&dir, ["run", "src/main"]),
expect![[r#"
Some(123)
"#]],
);
}

#[test]
fn test_blackbox_success() {
let dir = TestDir::new("blackbox_success_test.in");
Expand Down Expand Up @@ -6372,7 +6466,7 @@ fn test_specify_source_dir_with_deps() {
moonc build-package ./deps/hello19/source/top.mbt -o ./target/wasm-gc/release/build/.mooncakes/just/hello19/hello19.core -pkg just/hello19 -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -pkg-sources just/hello19:./deps/hello19/source -target wasm-gc
moonc build-package ./deps/hello19/source/lib/hello.mbt -o ./target/wasm-gc/release/build/.mooncakes/just/hello19/lib/lib.core -pkg just/hello19/lib -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -pkg-sources just/hello19/lib:./deps/hello19/source/lib -target wasm-gc
moonc build-package ./anyhow/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 -i ./target/wasm-gc/release/build/lib/lib.mi:emmm -i ./target/wasm-gc/release/build/.mooncakes/just/hello19/hello19.mi:hello19 -i ./target/wasm-gc/release/build/.mooncakes/just/hello19/lib/lib.mi:lib -pkg-sources username/hello/main:./anyhow/main -target wasm-gc
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/.mooncakes/just/hello19/hello19.core ./target/wasm-gc/release/build/.mooncakes/just/hello19/lib/lib.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 ./anyhow/main/moon.pkg.json -pkg-sources username/hello/lib:./anyhow/lib -pkg-sources just/hello19:./anyhow -pkg-sources just/hello19/lib:./anyhow/lib -pkg-sources username/hello/main:./anyhow/main -pkg-sources moonbitlang/core:$MOON_HOME/lib/core -target wasm-gc
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/.mooncakes/just/hello19/hello19.core ./target/wasm-gc/release/build/.mooncakes/just/hello19/lib/lib.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 ./anyhow/main/moon.pkg.json -pkg-sources username/hello/lib:./anyhow/lib -pkg-sources just/hello19:./deps/hello19/source -pkg-sources just/hello19/lib:./deps/hello19/source/lib -pkg-sources username/hello/main:./anyhow/main -pkg-sources moonbitlang/core:$MOON_HOME/lib/core -target wasm-gc
"#]],
);
check(
Expand Down

0 comments on commit d4e0655

Please sign in to comment.