From 8760ff2c585f77b82a4960fdff539200a9ea02a7 Mon Sep 17 00:00:00 2001 From: Li Junchen Date: Tue, 15 Oct 2024 11:55:24 +0800 Subject: [PATCH 1/3] add a test case for test_publish.in --- .../moon/tests/test_cases/test_publish.in/.gitignore | 2 ++ crates/moon/tests/test_cases/test_publish.in/README.md | 1 + .../tests/test_cases/test_publish.in/moon.mod.json | 10 ++++++++++ .../tests/test_cases/test_publish.in/src/lib/hello.mbt | 3 +++ .../test_cases/test_publish.in/src/lib/hello_test.mbt | 5 +++++ .../test_cases/test_publish.in/src/lib/moon.pkg.json | 1 + .../tests/test_cases/test_publish.in/src/main/main.mbt | 3 +++ .../test_cases/test_publish.in/src/main/moon.pkg.json | 6 ++++++ 8 files changed, 31 insertions(+) create mode 100644 crates/moon/tests/test_cases/test_publish.in/.gitignore create mode 100644 crates/moon/tests/test_cases/test_publish.in/README.md create mode 100644 crates/moon/tests/test_cases/test_publish.in/moon.mod.json create mode 100644 crates/moon/tests/test_cases/test_publish.in/src/lib/hello.mbt create mode 100644 crates/moon/tests/test_cases/test_publish.in/src/lib/hello_test.mbt create mode 100644 crates/moon/tests/test_cases/test_publish.in/src/lib/moon.pkg.json create mode 100644 crates/moon/tests/test_cases/test_publish.in/src/main/main.mbt create mode 100644 crates/moon/tests/test_cases/test_publish.in/src/main/moon.pkg.json diff --git a/crates/moon/tests/test_cases/test_publish.in/.gitignore b/crates/moon/tests/test_cases/test_publish.in/.gitignore new file mode 100644 index 00000000..b1283a74 --- /dev/null +++ b/crates/moon/tests/test_cases/test_publish.in/.gitignore @@ -0,0 +1,2 @@ +target/ +.mooncakes/ diff --git a/crates/moon/tests/test_cases/test_publish.in/README.md b/crates/moon/tests/test_cases/test_publish.in/README.md new file mode 100644 index 00000000..ae00983f --- /dev/null +++ b/crates/moon/tests/test_cases/test_publish.in/README.md @@ -0,0 +1 @@ +# username/hello \ No newline at end of file diff --git a/crates/moon/tests/test_cases/test_publish.in/moon.mod.json b/crates/moon/tests/test_cases/test_publish.in/moon.mod.json new file mode 100644 index 00000000..8ef5f2fb --- /dev/null +++ b/crates/moon/tests/test_cases/test_publish.in/moon.mod.json @@ -0,0 +1,10 @@ +{ + "name": "username/hello", + "version": "0.1.0", + "readme": "README.md", + "repository": "", + "license": "MIT", + "keywords": [], + "description": "", + "source": "src" +} \ No newline at end of file diff --git a/crates/moon/tests/test_cases/test_publish.in/src/lib/hello.mbt b/crates/moon/tests/test_cases/test_publish.in/src/lib/hello.mbt new file mode 100644 index 00000000..9012592a --- /dev/null +++ b/crates/moon/tests/test_cases/test_publish.in/src/lib/hello.mbt @@ -0,0 +1,3 @@ +pub fn hello() -> String { + "Hello, world!" +} diff --git a/crates/moon/tests/test_cases/test_publish.in/src/lib/hello_test.mbt b/crates/moon/tests/test_cases/test_publish.in/src/lib/hello_test.mbt new file mode 100644 index 00000000..e0e3a7d1 --- /dev/null +++ b/crates/moon/tests/test_cases/test_publish.in/src/lib/hello_test.mbt @@ -0,0 +1,5 @@ +test "hello" { + if @lib.hello() != "Hello, world!" { + fail!("@lib.hello() != \"Hello, world!\"") + } +} diff --git a/crates/moon/tests/test_cases/test_publish.in/src/lib/moon.pkg.json b/crates/moon/tests/test_cases/test_publish.in/src/lib/moon.pkg.json new file mode 100644 index 00000000..9e26dfee --- /dev/null +++ b/crates/moon/tests/test_cases/test_publish.in/src/lib/moon.pkg.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/crates/moon/tests/test_cases/test_publish.in/src/main/main.mbt b/crates/moon/tests/test_cases/test_publish.in/src/main/main.mbt new file mode 100644 index 00000000..d25cb935 --- /dev/null +++ b/crates/moon/tests/test_cases/test_publish.in/src/main/main.mbt @@ -0,0 +1,3 @@ +fn main { + println(@lib.hello()) +} diff --git a/crates/moon/tests/test_cases/test_publish.in/src/main/moon.pkg.json b/crates/moon/tests/test_cases/test_publish.in/src/main/moon.pkg.json new file mode 100644 index 00000000..48783525 --- /dev/null +++ b/crates/moon/tests/test_cases/test_publish.in/src/main/moon.pkg.json @@ -0,0 +1,6 @@ +{ + "is-main": true, + "import": [ + "username/hello/lib" + ] +} \ No newline at end of file From 64bded1727c7a5af5756bc106600c7ad6a8672b1 Mon Sep 17 00:00:00 2001 From: Li Junchen Date: Wed, 16 Oct 2024 11:02:23 +0800 Subject: [PATCH 2/3] CI: add target/debug to path --- .github/workflows/ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 48568eb3..30205742 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -141,6 +141,7 @@ jobs: chmod +x ~/.moon/bin/tcc git clone --depth 1 https://github.com/moonbitlang/core.git ~/.moon/lib/core echo "$HOME/.moon/bin" >> $GITHUB_PATH + echo "$GITHUB_WORKSPACE/target/debug" >> $GITHUB_PATH - name: install MoonBit(Windows) if: ${{ matrix.os == 'windows-latest' }} @@ -153,6 +154,7 @@ jobs: Invoke-WebRequest -Uri https://cli.moonbitlang.com/moon-ci/Windows-x86_64/mooncake.exe -OutFile "$env:USERPROFILE/.moon/bin/mooncake.exe" git clone --depth 1 https://github.com/moonbitlang/core.git "$env:USERPROFILE/.moon/lib/core" "$env:USERPROFILE\.moon\bin" | Out-File -FilePath $env:GITHUB_PATH -Append + "$env:GITHUB_WORKSPACE\target\debug" | Out-File -FilePath $env:GITHUB_PATH -Append - name: Build run: cargo build @@ -223,6 +225,7 @@ jobs: chmod +x ~/.moon/bin/tcc git clone --depth 1 https://github.com/moonbitlang/core.git ~/.moon/lib/core echo "$HOME/.moon/bin" >> $GITHUB_PATH + echo "$GITHUB_WORKSPACE/target/debug" >> $GITHUB_PATH - name: install cargo-tarpaulin ${{ env.CARGO_TARPAULIN_VERSION }} run: | From e3555787d51524ade189023a944be939ca47ddab Mon Sep 17 00:00:00 2001 From: Li Junchen Date: Wed, 16 Oct 2024 11:02:50 +0800 Subject: [PATCH 3/3] update tests --- crates/moon/tests/test_cases/mod.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/crates/moon/tests/test_cases/mod.rs b/crates/moon/tests/test_cases/mod.rs index 5cd96c62..3b6daa71 100644 --- a/crates/moon/tests/test_cases/mod.rs +++ b/crates/moon/tests/test_cases/mod.rs @@ -7217,3 +7217,27 @@ fn test_use_cc_for_native_release() { ); } } + +#[test] +fn test_moon_package_list() { + let dir = TestDir::new("test_publish.in"); + check( + get_stderr(&dir, ["package", "--list"]), + expect![[r#" + Running moon check ... + Finished. moon: ran 3 tasks, now up to date + Check passed + README.md + moon.mod.json + src + src/lib + src/lib/hello.mbt + src/lib/hello_test.mbt + src/lib/moon.pkg.json + src/main + src/main/main.mbt + src/main/moon.pkg.json + Package to $ROOT/target/publish/username-hello-0.1.0.zip + "#]], + ); +}