Skip to content

Commit

Permalink
add test case for third party dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
Young-Flash committed Jul 9, 2024
1 parent 63c24fb commit 817d3c0
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ jobs:
cargo run --bin moon test --source-dir "$env:USERPROFILE\.moon\lib\core" --release --target js
cargo run --bin moon test --source-dir "$env:USERPROFILE\.moon\lib\core" --release --target wasm
- name: moon update
run: moon update

- name: Run tests
run: cargo test

Expand Down
35 changes: 35 additions & 0 deletions crates/moon/tests/test_cases/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4092,3 +4092,38 @@ fn test_moon_run_with_cli_args() {
"#]],
);
}

#[test]
fn test_third_party() {
let dir = TestDir::new("third_party.in");
get_stdout_with_args_and_replace_dir(&dir, ["build"]);
get_stdout_with_args_and_replace_dir(&dir, ["clean"]);

let actual = &get_stdout_with_args_and_replace_dir(&dir, ["check"]);
assert!(actual.contains("moon: ran 4 tasks, now up to date"));

check(
&get_stdout_with_args_and_replace_dir(&dir, ["test", "--dry-run", "--sort-input"]),
expect![[r#"
moon generate-test-driver --source-dir . --target-dir ./target/wasm-gc/debug/test --sort-input
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
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
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-sources lijunchen/hello18/lib:./lib -pkg-sources username/hello/lib:./lib -pkg-sources moonbitlang/core:$MOON_HOME/lib/core -target wasm-gc -g
"#]],
);

check(
&get_stdout_with_args_and_replace_dir(&dir, ["test", "--sort-input"]),
expect![[r#"
Hello, world!
Hello, world!
Total tests: 2, passed: 2, failed: 0.
"#]],
);

let actual = &get_stdout_with_args_and_replace_dir(&dir, ["build"]);
assert!(actual.contains("moon: ran 5 tasks, now up to date"));

let actual = &get_stdout_with_args_and_replace_dir(&dir, ["run", "main"]);
assert!(actual.contains("Hello, world!"));
}
2 changes: 2 additions & 0 deletions crates/moon/tests/test_cases/third_party.in/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
target/
.mooncakes/
1 change: 1 addition & 0 deletions crates/moon/tests/test_cases/third_party.in/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# username/hello
5 changes: 5 additions & 0 deletions crates/moon/tests/test_cases/third_party.in/lib/moon.pkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"import": [
"lijunchen/hello18/lib"
]
}
8 changes: 8 additions & 0 deletions crates/moon/tests/test_cases/third_party.in/lib/test.mbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

test {
println("Hello, world!")
}

test {
println(@lib.hello())
}
3 changes: 3 additions & 0 deletions crates/moon/tests/test_cases/third_party.in/main/main.mbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main {
println(@lib.hello())
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"is-main": true,
"import": [
"lijunchen/hello18/lib"
]
}
12 changes: 12 additions & 0 deletions crates/moon/tests/test_cases/third_party.in/moon.mod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "username/hello",
"version": "0.1.0",
"deps": {
"lijunchen/hello18": "0.1.30"
},
"readme": "README.md",
"repository": "",
"license": "",
"keywords": [],
"description": ""
}

0 comments on commit 817d3c0

Please sign in to comment.