diff --git a/crates/moon/tests/test_cases/mod.rs b/crates/moon/tests/test_cases/mod.rs index 058f9594..a399abaf 100644 --- a/crates/moon/tests/test_cases/mod.rs +++ b/crates/moon/tests/test_cases/mod.rs @@ -21,7 +21,9 @@ use std::io::Write; use super::*; use expect_test::expect; use moonutil::{ - common::{get_cargo_pkg_version, CargoPathExt, TargetBackend, DEP_PATH, MOON_MOD_JSON}, + common::{ + get_cargo_pkg_version, CargoPathExt, StringExt, TargetBackend, DEP_PATH, MOON_MOD_JSON, + }, module::MoonModJSON, }; use serde::{Deserialize, Serialize}; @@ -51,7 +53,7 @@ fn test_design() { .assert() .success(); check( - &get_stdout(&dir, ["run", "main1"]), + get_stdout(&dir, ["run", "main1"]), expect![[r#" new_list new_queue @@ -62,7 +64,7 @@ fn test_design() { "#]], ); check( - &get_stdout(&dir, ["run", "main2"]), + get_stdout(&dir, ["run", "main2"]), expect![[r#" new_list new_queue @@ -72,7 +74,7 @@ fn test_design() { get_stdout(&dir, ["clean"]); check( - &get_stdout(&dir, ["run", "main2", "--target", "js", "--build-only"]), + get_stdout(&dir, ["run", "main2", "--target", "js", "--build-only"]), expect![[r#" {"artifacts_path":["$ROOT/target/js/release/build/main2/main2.js"]} "#]], @@ -104,7 +106,7 @@ fn test_diamond_pkg_001() { .assert() .success(); check( - &get_stdout(&dir, ["run", "main"]), + get_stdout(&dir, ["run", "main"]), expect![[r#" A B @@ -139,7 +141,7 @@ fn test_diamond_pkg_002() { .assert() .success(); check( - &get_stdout(&dir, ["run", "main"]), + get_stdout(&dir, ["run", "main"]), expect![[r#" A0 A1 @@ -186,7 +188,7 @@ fn test_diamond_pkg_003() { .assert() .success(); check( - &get_stdout(&dir, ["run", "main"]), + get_stdout(&dir, ["run", "main"]), expect![[r#" A0 A1 @@ -213,7 +215,7 @@ fn test_diamond_pkg_003() { fn test_extra_flags() { let dir = TestDir::new("extra_flags.in"); check( - &get_stdout(&dir, ["build", "--dry-run", "--nostd"]), + get_stdout(&dir, ["build", "--dry-run", "--nostd"]), expect![[r#" moonc build-package ./lib/hello.mbt -o ./target/wasm-gc/release/build/lib/lib.core -pkg hello/lib -pkg-sources hello/lib:./lib -target wasm-gc -g -no-builtin moonc build-package ./main/main.mbt -o ./target/wasm-gc/release/build/main/main.core -pkg hello/main -is-main -i ./target/wasm-gc/release/build/lib/lib.mi:lib -pkg-sources hello/main:./main -target wasm-gc -g -no-builtin @@ -221,7 +223,7 @@ fn test_extra_flags() { "#]], ); check( - &get_stdout(&dir, ["build", "--dry-run", "--debug", "--nostd"]), + get_stdout(&dir, ["build", "--dry-run", "--debug", "--nostd"]), expect![[r#" moonc build-package ./lib/hello.mbt -o ./target/wasm-gc/debug/build/lib/lib.core -pkg hello/lib -pkg-sources hello/lib:./lib -target wasm-gc -g -source-map -g -no-builtin moonc build-package ./main/main.mbt -o ./target/wasm-gc/debug/build/main/main.core -pkg hello/main -is-main -i ./target/wasm-gc/debug/build/lib/lib.mi:lib -pkg-sources hello/main:./main -target wasm-gc -g -source-map -g -no-builtin @@ -230,7 +232,7 @@ fn test_extra_flags() { ); check( - &get_stdout(&dir, ["run", "main", "--dry-run", "--nostd"]), + get_stdout(&dir, ["run", "main", "--dry-run", "--nostd"]), expect![[r#" moonc build-package ./lib/hello.mbt -o ./target/wasm-gc/release/build/lib/lib.core -pkg hello/lib -pkg-sources hello/lib:./lib -target wasm-gc -g -no-builtin moonc build-package ./main/main.mbt -o ./target/wasm-gc/release/build/main/main.core -pkg hello/main -is-main -i ./target/wasm-gc/release/build/lib/lib.mi:lib -pkg-sources hello/main:./main -target wasm-gc -g -no-builtin @@ -239,7 +241,7 @@ fn test_extra_flags() { "#]], ); check( - &get_stdout(&dir, ["run", "main", "--dry-run", "--debug", "--nostd"]), + get_stdout(&dir, ["run", "main", "--dry-run", "--debug", "--nostd"]), expect![[r#" moonc build-package ./lib/hello.mbt -o ./target/wasm-gc/debug/build/lib/lib.core -pkg hello/lib -pkg-sources hello/lib:./lib -target wasm-gc -g -source-map -g -no-builtin moonc build-package ./main/main.mbt -o ./target/wasm-gc/debug/build/main/main.core -pkg hello/main -is-main -i ./target/wasm-gc/debug/build/lib/lib.mi:lib -pkg-sources hello/main:./main -target wasm-gc -g -source-map -g -no-builtin @@ -253,7 +255,7 @@ fn test_extra_flags() { fn test_fancy_import() { let dir = TestDir::new("fancy_import.in/import001"); check( - &get_stdout(&dir, ["run", "main"]), + get_stdout(&dir, ["run", "main"]), expect![[r#" Hello, world! "#]], @@ -261,7 +263,7 @@ fn test_fancy_import() { let dir = TestDir::new("fancy_import.in/import002"); check( - &get_stdout(&dir, ["run", "main"]), + get_stdout(&dir, ["run", "main"]), expect![[r#" Hello, world! "#]], @@ -269,7 +271,7 @@ fn test_fancy_import() { let dir = TestDir::new("fancy_import.in/import003"); check( - &get_stdout(&dir, ["run", "main"]), + get_stdout(&dir, ["run", "main"]), expect![[r#" Hello, world! Hello, world2! @@ -278,7 +280,7 @@ fn test_fancy_import() { let dir = TestDir::new("fancy_import.in/import004"); check( - &get_stdout(&dir, ["run", "main"]), + get_stdout(&dir, ["run", "main"]), expect![[r#" f1 f2 @@ -292,7 +294,7 @@ fn test_fancy_import() { fn test_hello() { let dir = TestDir::new("hello.in"); check( - &get_stdout(&dir, ["run", "main"]), + get_stdout(&dir, ["run", "main"]), expect![[r#" Hello, world! "#]], @@ -303,7 +305,7 @@ fn test_hello() { fn test_moon_commands() { let dir = TestDir::new("moon_commands.in"); check( - &get_stdout(&dir, ["build", "--dry-run", "--nostd", "--sort-input"]), + get_stdout(&dir, ["build", "--dry-run", "--nostd", "--sort-input"]), expect![[r#" moonc build-package ./lib/list/lib.mbt -o ./target/wasm-gc/release/build/lib/list/list.core -pkg design/lib/list -pkg-sources design/lib/list:./lib/list -target wasm-gc moonc build-package ./lib/queue/lib.mbt -o ./target/wasm-gc/release/build/lib/queue/queue.core -pkg design/lib/queue -i ./target/wasm-gc/release/build/lib/list/list.mi:list -pkg-sources design/lib/queue:./lib/queue -target wasm-gc @@ -319,7 +321,7 @@ fn test_moon_commands() { fn test_moon_run_main() { let dir = TestDir::new("moon_new.in"); check( - &get_stdout(&dir, ["run", "main"]), + get_stdout(&dir, ["run", "main"]), expect![[r#" Hello, world! "#]], @@ -343,7 +345,7 @@ fn test_moon_new() { ], ); check( - &get_stdout( + get_stdout( &dir, [ "run", @@ -360,7 +362,7 @@ fn test_moon_new() { ); check( - &get_stdout( + get_stdout( &dir, [ "run", @@ -377,7 +379,7 @@ fn test_moon_new() { ); check( - &get_stdout( + get_stdout( &dir, [ "run", @@ -398,7 +400,7 @@ fn test_moon_new() { fn test_moon_help() { let dir = TestDir::new_empty(); check( - &get_stdout(&dir, ["help"]).replace("moon.exe", "moon"), + get_stdout(&dir, ["help"]).replace("moon.exe", "moon"), expect![[r#" The build system and package manager for MoonBit. @@ -450,7 +452,7 @@ fn test_bench4() { let dir = TestDir::new_empty(); get_stdout(&dir, ["generate-build-matrix", "-n", "4", "-o", "bench4"]); check( - &get_stdout( + get_stdout( &dir, [ "run", @@ -589,7 +591,7 @@ fn test_moon_new_new() { .assert() .success(); check( - &get_stdout(&hello1, ["run", "src/main"]), + get_stdout(&hello1, ["run", "src/main"]), expect![[r#" Hello, world! "#]], @@ -612,7 +614,7 @@ fn test_moon_new_new() { .assert() .success(); check( - &get_stdout(&hello2, ["run", "src/main"]), + get_stdout(&hello2, ["run", "src/main"]), expect![[r#" Hello, world! "#]], @@ -638,14 +640,14 @@ fn test_moon_new_new() { .assert() .success(); check( - &get_stdout(&hello3, ["test", "-v"]), + get_stdout(&hello3, ["test", "-v"]), expect![[r#" test moonbitlang/hello/lib/hello_test.mbt::hello ok Total tests: 1, passed: 1, failed: 0. "#]], ); check( - &get_stdout(&hello3, ["test"]), + get_stdout(&hello3, ["test"]), expect![[r#" Total tests: 1, passed: 1, failed: 0. "#]], @@ -669,7 +671,7 @@ fn test_moon_new_new() { .assert() .success(); check( - &std::fs::read_to_string(hello4.join("src").join("moon.pkg.json")).unwrap(), + std::fs::read_to_string(hello4.join("src").join("moon.pkg.json")).unwrap(), expect![[r#" { "import": [ @@ -679,7 +681,7 @@ fn test_moon_new_new() { "#]], ); check( - &get_stdout(&hello4, ["test", "-v"]), + get_stdout(&hello4, ["test", "-v"]), expect![[r#" test moonbitlang/hello/lib/hello_test.mbt::hello ok Total tests: 1, passed: 1, failed: 0. @@ -700,7 +702,7 @@ fn test_moon_new_interactive() { .assert() .success(); check( - &std::fs::read_to_string(dir.join("hello5").join("moon.mod.json")).unwrap(), + std::fs::read_to_string(dir.join("hello5").join("moon.mod.json")).unwrap(), expect![[r#" { "name": "moonbitlang/hello5", @@ -721,7 +723,7 @@ fn test_moon_new_interactive() { .assert() .success(); check( - &std::fs::read_to_string(dir.join("hello6").join("moon.pkg.json")).unwrap(), + std::fs::read_to_string(dir.join("hello6").join("moon.pkg.json")).unwrap(), expect![[r#" { "import": [ @@ -748,9 +750,7 @@ fn test_moon_new_snapshot() { .assert() .success(); check( - &replace_crlf_to_lf( - &std::fs::read_to_string(hello.join("src").join("lib").join("hello.mbt")).unwrap(), - ), + read(hello.join("src").join("lib").join("hello.mbt")), expect![[r#" pub fn hello() -> String { "Hello, world!" @@ -777,9 +777,7 @@ fn test_moon_new_snapshot() { .assert() .success(); check( - &replace_crlf_to_lf( - &std::fs::read_to_string(hello.join("src").join("lib").join("hello.mbt")).unwrap(), - ), + read(hello.join("src").join("lib").join("hello.mbt")), expect![[r#" pub fn hello() -> String { "Hello, world!" @@ -787,9 +785,7 @@ fn test_moon_new_snapshot() { "#]], ); check( - &replace_crlf_to_lf( - &std::fs::read_to_string(hello.join("src").join("lib").join("hello_test.mbt")).unwrap(), - ), + read(hello.join("src").join("lib").join("hello_test.mbt")), expect![[r#" test "hello" { if @lib.hello() != "Hello, world!" { @@ -799,13 +795,11 @@ fn test_moon_new_snapshot() { "#]], ); check( - &std::fs::read_to_string(hello.join("src").join("lib").join("moon.pkg.json")).unwrap(), + std::fs::read_to_string(hello.join("src").join("lib").join("moon.pkg.json")).unwrap(), expect!["{}"], ); check( - &replace_crlf_to_lf( - &std::fs::read_to_string(hello.join("src").join("main").join("main.mbt")).unwrap(), - ), + read(hello.join("src").join("main").join("main.mbt")), expect![[r#" fn main { println(@lib.hello()) @@ -813,7 +807,7 @@ fn test_moon_new_snapshot() { "#]], ); check( - &std::fs::read_to_string(hello.join("src").join("main").join("moon.pkg.json")).unwrap(), + std::fs::read_to_string(hello.join("src").join("main").join("moon.pkg.json")).unwrap(), expect![[r#" { "is-main": true, @@ -823,7 +817,7 @@ fn test_moon_new_snapshot() { }"#]], ); check( - &std::fs::read_to_string(hello.join("moon.mod.json")).unwrap(), + std::fs::read_to_string(hello.join("moon.mod.json")).unwrap(), expect![[r#" { "name": "moonbitlang/hello", @@ -880,9 +874,7 @@ fn test_moon_new_snapshot_lib_no_license() { .assert() .success(); check( - &replace_crlf_to_lf( - &std::fs::read_to_string(hello.join("src").join("lib").join("hello.mbt")).unwrap(), - ), + read(hello.join("src").join("lib").join("hello.mbt")), expect![[r#" pub fn hello() -> String { "Hello, world!" @@ -910,9 +902,7 @@ fn test_moon_new_snapshot_lib_no_license() { .assert() .success(); check( - &replace_crlf_to_lf( - &std::fs::read_to_string(hello.join("src").join("lib").join("hello.mbt")).unwrap(), - ), + read(hello.join("src").join("lib").join("hello.mbt")), expect![[r#" pub fn hello() -> String { "Hello, world!" @@ -920,9 +910,7 @@ fn test_moon_new_snapshot_lib_no_license() { "#]], ); check( - &replace_crlf_to_lf( - &std::fs::read_to_string(hello.join("src").join("lib").join("hello_test.mbt")).unwrap(), - ), + read(hello.join("src").join("lib").join("hello_test.mbt")), expect![[r#" test "hello" { if @lib.hello() != "Hello, world!" { @@ -932,11 +920,11 @@ fn test_moon_new_snapshot_lib_no_license() { "#]], ); check( - &std::fs::read_to_string(hello.join("src").join("lib").join("moon.pkg.json")).unwrap(), + std::fs::read_to_string(hello.join("src").join("lib").join("moon.pkg.json")).unwrap(), expect!["{}"], ); check( - &std::fs::read_to_string(hello.join("src").join("moon.pkg.json")).unwrap(), + std::fs::read_to_string(hello.join("src").join("moon.pkg.json")).unwrap(), expect![[r#" { "import": [ @@ -946,7 +934,7 @@ fn test_moon_new_snapshot_lib_no_license() { "#]], ); check( - &std::fs::read_to_string(hello.join("moon.mod.json")).unwrap(), + std::fs::read_to_string(hello.join("moon.mod.json")).unwrap(), expect![[r#" { "name": "moonbitlang/hello", @@ -960,7 +948,7 @@ fn test_moon_new_snapshot_lib_no_license() { }"#]], ); check( - &replace_crlf_to_lf(&std::fs::read_to_string(hello.join("src").join("top.mbt")).unwrap()), + read(hello.join("src").join("top.mbt")), expect![[r#" pub fn greeting() -> Unit { println(@lib.hello()) @@ -968,7 +956,7 @@ fn test_moon_new_snapshot_lib_no_license() { "#]], ); check( - &std::fs::read_to_string(hello.join("README.md")).unwrap(), + std::fs::read_to_string(hello.join("README.md")).unwrap(), expect!["# moonbitlang/hello"], ); hello.rm_rf(); @@ -1004,7 +992,7 @@ fn test_moon_test_filter_package() { let dir = TestDir::new("test_filter.in"); check( - &get_stdout( + get_stdout( &dir, [ "test", @@ -1027,7 +1015,7 @@ fn test_moon_test_filter_package() { ); check( - &get_stdout( + get_stdout( &dir, [ "test", @@ -1051,7 +1039,7 @@ fn test_moon_test_filter_multi_package() { let dir = TestDir::new("test_filter_pkg_with_test_imports.in"); check( - &get_stdout( + get_stdout( &dir, [ "test", @@ -1077,7 +1065,7 @@ fn test_moon_test_filter_multi_package() { ); check( - &get_stdout( + get_stdout( &dir, [ "test", @@ -1109,7 +1097,7 @@ fn test_moon_test_filter_multi_package() { ); check( - &get_stdout( + get_stdout( &dir, [ "test", @@ -1141,7 +1129,7 @@ fn test_moon_test_filter_multi_package() { ); check( - &get_stdout( + get_stdout( &dir, [ "test", @@ -1178,7 +1166,7 @@ fn test_moon_test_filter_package_with_deps() { let dir = TestDir::new("test_filter_pkg_with_deps.in"); check( - &get_stdout( + get_stdout( &dir, ["test", "-p", "username/hello/lib", "--no-parallelize"], ), @@ -1196,7 +1184,7 @@ fn test_moon_test_filter_package_with_deps() { ); check( - &get_stdout( + get_stdout( &dir, ["test", "-p", "username/hello/lib2", "--no-parallelize"], ), @@ -1209,7 +1197,7 @@ fn test_moon_test_filter_package_with_deps() { ); check( - &get_stdout( + get_stdout( &dir, ["test", "-p", "username/hello/lib4", "--no-parallelize"], ), @@ -1225,7 +1213,7 @@ fn test_moon_test_filter_package_with_test_imports() { let dir = TestDir::new("test_filter_pkg_with_test_imports.in"); check( - &get_stdout( + get_stdout( &dir, [ "test", @@ -1246,7 +1234,7 @@ fn test_moon_test_filter_package_with_test_imports() { ); check( - &get_stdout( + get_stdout( &dir, [ "test", @@ -1264,7 +1252,7 @@ fn test_moon_test_filter_package_with_test_imports() { ); check( - &get_stdout( + get_stdout( &dir, [ "test", @@ -1281,7 +1269,7 @@ fn test_moon_test_filter_package_with_test_imports() { ); check( - &get_stdout( + get_stdout( &dir, [ "test", @@ -1301,7 +1289,7 @@ fn test_moon_test_filter_package_with_test_imports() { ); check( - &get_stdout( + get_stdout( &dir, [ "test", @@ -1320,7 +1308,7 @@ fn test_moon_test_filter_package_with_test_imports() { ); check( - &get_stdout( + get_stdout( &dir, [ "test", @@ -1337,7 +1325,7 @@ fn test_moon_test_filter_package_with_test_imports() { ); check( - &get_stdout( + get_stdout( &dir, [ "test", @@ -1354,7 +1342,7 @@ fn test_moon_test_filter_package_with_test_imports() { ); check( - &get_stdout( + get_stdout( &dir, [ "test", @@ -1377,7 +1365,7 @@ fn test_moon_test_filter_package_dry_run() { let dir = TestDir::new("test_filter.in"); check( - &get_stdout( + get_stdout( &dir, [ "test", @@ -1398,7 +1386,7 @@ fn test_moon_test_filter_package_dry_run() { ); check( - &get_stdout(&dir, ["test", "--dry-run", "--sort-input"]), + get_stdout(&dir, ["test", "--dry-run", "--sort-input"]), expect![[r#" moon generate-test-driver --source-dir . --target-dir ./target/wasm-gc/debug/test --package username/hello/lib2 --sort-input --target wasm-gc --driver-kind internal moonc build-package ./lib2/lib.mbt ./target/wasm-gc/debug/test/lib2/__generated_driver_for_internal_test.mbt -o ./target/wasm-gc/debug/test/lib2/lib2.internal_test.core -pkg username/hello/lib2 -is-main -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -pkg-sources username/hello/lib2:./lib2 -target wasm-gc -g @@ -1424,7 +1412,7 @@ fn test_moon_test_filter_file() { let dir = TestDir::new("test_filter.in"); check( - &get_stdout(&dir, ["test", "-p", "username/hello/A", "-f", "hello.mbt"]), + get_stdout(&dir, ["test", "-p", "username/hello/A", "-f", "hello.mbt"]), expect![[r#" test A test B @@ -1433,7 +1421,7 @@ fn test_moon_test_filter_file() { ); check( - &get_stdout( + get_stdout( &dir, ["test", "-p", "username/hello/lib", "-f", "hello_wbtest.mbt"], ), @@ -1450,7 +1438,7 @@ fn test_moon_test_filter_index() { let dir = TestDir::new("test_filter.in"); check( - &get_stdout( + get_stdout( &dir, [ "test", @@ -1469,7 +1457,7 @@ fn test_moon_test_filter_index() { ); check( - &get_stdout( + get_stdout( &dir, [ "test", @@ -1507,7 +1495,7 @@ fn test_moon_test_filter_index_with_auto_update() { ], ); check( - &replace_crlf_to_lf(&std::fs::read_to_string(dir.join("lib2").join("lib.mbt")).unwrap()), + read(dir.join("lib2").join("lib.mbt")), expect![[r#" test { println(2) @@ -1544,7 +1532,7 @@ fn test_moon_test_filter_index_with_auto_update() { ], ); check( - &replace_crlf_to_lf(&std::fs::read_to_string(dir.join("lib2").join("lib.mbt")).unwrap()), + read(dir.join("lib2").join("lib.mbt")), expect![[r#" test { println(2) @@ -1579,7 +1567,7 @@ fn test_moon_test_filter_index_with_auto_update() { ], ); check( - &replace_crlf_to_lf(&std::fs::read_to_string(dir.join("lib2").join("lib.mbt")).unwrap()), + read(dir.join("lib2").join("lib.mbt")), expect![[r#" test { println(2) @@ -1604,7 +1592,7 @@ fn test_moon_test_succ() { std::env::set_var("NO_COLOR", "1"); let dir = TestDir::new("moon_test_succ.in"); check( - &get_stdout(&dir, ["test", "-v", "--sort-input", "--no-parallelize"]), + get_stdout(&dir, ["test", "-v", "--sort-input", "--no-parallelize"]), expect![[r#" test moontest/lib/hello_wbtest.mbt::0 ok test moontest/lib2/hello_wbtest.mbt::0 ok @@ -1621,13 +1609,13 @@ fn test_moon_test_succ() { fn test_moon_test_hello_exec() { let dir = TestDir::new("moon_test_hello_exec.in"); check( - &get_stdout(&dir, ["run", "main"]), + get_stdout(&dir, ["run", "main"]), expect![[r#" Hello, world! "#]], ); check( - &get_stdout(&dir, ["test", "-v"]), + get_stdout(&dir, ["test", "-v"]), expect![[r#" this is lib test test moonbitlang/hello/lib/hello_wbtest.mbt::0 ok @@ -1635,7 +1623,7 @@ fn test_moon_test_hello_exec() { "#]], ); check( - &get_stdout(&dir, ["test", "--dry-run", "--debug", "--sort-input"]), + get_stdout(&dir, ["test", "--dry-run", "--debug", "--sort-input"]), expect![[r#" moon generate-test-driver --source-dir . --target-dir ./target/wasm-gc/debug/test --package moonbitlang/hello/lib --sort-input --target wasm-gc --driver-kind whitebox moonc build-package ./lib/hello.mbt ./lib/hello_wbtest.mbt ./target/wasm-gc/debug/test/lib/__generated_driver_for_whitebox_test.mbt -o ./target/wasm-gc/debug/test/lib/lib.whitebox_test.core -pkg moonbitlang/hello/lib -is-main -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -pkg-sources moonbitlang/hello/lib:./lib -target wasm-gc -g -source-map @@ -1651,14 +1639,14 @@ fn test_moon_test_hello_exec() { fn test_moon_test_hello_exec_fntest() { let dir = TestDir::new("moon_test_hello_exec_fntest.in"); check( - &get_stdout(&dir, ["run", "main"]), + get_stdout(&dir, ["run", "main"]), expect![[r#" init in main/main.mbt "#]], ); check( - &get_stdout(&dir, ["test", "-v", "--dry-run", "--sort-input"]), + get_stdout(&dir, ["test", "-v", "--dry-run", "--sort-input"]), expect![[r#" moon generate-test-driver --source-dir . --target-dir ./target/wasm-gc/debug/test --package moonbitlang/hello/lib --sort-input --target wasm-gc --driver-kind whitebox moonc build-package ./lib/hello.mbt ./lib/hello_wbtest.mbt ./target/wasm-gc/debug/test/lib/__generated_driver_for_whitebox_test.mbt -o ./target/wasm-gc/debug/test/lib/lib.whitebox_test.core -pkg moonbitlang/hello/lib -is-main -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -pkg-sources moonbitlang/hello/lib:./lib -target wasm-gc -g @@ -1670,7 +1658,7 @@ fn test_moon_test_hello_exec_fntest() { ); check( - &get_stdout(&dir, ["test", "-v", "--sort-input", "--no-parallelize"]), + get_stdout(&dir, ["test", "-v", "--sort-input", "--no-parallelize"]), expect![[r#" test in lib/hello.mbt test moonbitlang/hello/lib/hello.mbt::0 ok @@ -1685,7 +1673,7 @@ fn test_moon_test_hello_exec_fntest() { fn test_moon_test_hello_lib() { let dir = TestDir::new("moon_test_hello_lib.in"); check( - &get_stdout(&dir, ["test", "-v"]), + get_stdout(&dir, ["test", "-v"]), expect![[r#" test moonbitlang/hello/lib/hello_wbtest.mbt::0 ok Total tests: 1, passed: 1, failed: 0. @@ -1697,14 +1685,14 @@ fn test_moon_test_hello_lib() { fn test_moon_test_with_local_dep() { let dir = TestDir::new("moon_test_with_local_dep.in"); check( - &get_stdout(&dir, ["test", "-v", "--frozen"]), + get_stdout(&dir, ["test", "-v", "--frozen"]), expect![[r#" test hello31/lib/hello_wbtest.mbt::0 ok Total tests: 1, passed: 1, failed: 0. "#]], ); check( - &get_stdout(&dir, ["run", "main", "--frozen"]), + get_stdout(&dir, ["run", "main", "--frozen"]), expect![[r#" Hello, world! "#]], @@ -1855,7 +1843,7 @@ fn test_output_format() { fn test_simple_pkg() { let dir = TestDir::new("simple-pkg-A-001.in"); check( - &get_stdout(&dir, ["run", "main"]), + get_stdout(&dir, ["run", "main"]), expect![[r#" A main @@ -1864,7 +1852,7 @@ fn test_simple_pkg() { let dir = TestDir::new("simple-pkg-A-002.in"); check( - &get_stdout(&dir, ["run", "main"]), + get_stdout(&dir, ["run", "main"]), expect![[r#" A main @@ -1873,7 +1861,7 @@ fn test_simple_pkg() { let dir = TestDir::new("simple-pkg-A-003.in"); check( - &get_stdout(&dir, ["run", "main"]), + get_stdout(&dir, ["run", "main"]), expect![[r#" A main @@ -1882,7 +1870,7 @@ fn test_simple_pkg() { let dir = TestDir::new("simple-pkg-A-004.in"); check( - &get_stdout(&dir, ["run", "main"]), + get_stdout(&dir, ["run", "main"]), expect![[r#" A main @@ -1891,7 +1879,7 @@ fn test_simple_pkg() { let dir = TestDir::new("simple-pkg-A-005.in"); check( - &get_stdout(&dir, ["run", "main"]), + get_stdout(&dir, ["run", "main"]), expect![[r#" A main @@ -1900,7 +1888,7 @@ fn test_simple_pkg() { let dir = TestDir::new("simple-pkg-A-006.in"); check( - &get_stdout(&dir, ["run", "main"]), + get_stdout(&dir, ["run", "main"]), expect![[r#" main "#]], @@ -1908,7 +1896,7 @@ fn test_simple_pkg() { let dir = TestDir::new("simple-pkg-AB-001.in"); check( - &get_stdout(&dir, ["run", "main"]), + get_stdout(&dir, ["run", "main"]), expect![[r#" A B @@ -1918,7 +1906,7 @@ fn test_simple_pkg() { let dir = TestDir::new("simple-pkg-AB-002.in"); check( - &get_stdout(&dir, ["run", "main"]), + get_stdout(&dir, ["run", "main"]), expect![[r#" A B @@ -1928,7 +1916,7 @@ fn test_simple_pkg() { let dir = TestDir::new("simple-pkg-AB-003.in"); check( - &get_stdout(&dir, ["run", "main"]), + get_stdout(&dir, ["run", "main"]), expect![[r#" A B @@ -1938,7 +1926,7 @@ fn test_simple_pkg() { let dir = TestDir::new("simple-pkg-AB-004.in"); check( - &get_stdout(&dir, ["run", "main"]), + get_stdout(&dir, ["run", "main"]), expect![[r#" A B @@ -1951,7 +1939,7 @@ fn test_simple_pkg() { fn test_target_backend() { let dir = TestDir::new("target-backend.in"); check( - &get_stdout(&dir, ["build", "--dry-run", "--nostd"]), + get_stdout(&dir, ["build", "--dry-run", "--nostd"]), expect![[r#" moonc build-package ./lib/hello.mbt -o ./target/wasm-gc/release/build/lib/lib.core -pkg hello/lib -pkg-sources hello/lib:./lib -target wasm-gc moonc build-package ./main/main.mbt -o ./target/wasm-gc/release/build/main/main.core -pkg hello/main -is-main -i ./target/wasm-gc/release/build/lib/lib.mi:lib -pkg-sources hello/main:./main -target wasm-gc @@ -1959,7 +1947,7 @@ fn test_target_backend() { "#]], ); check( - &get_stdout( + get_stdout( &dir, ["build", "--dry-run", "--target", "wasm-gc", "--nostd"], ), @@ -1970,7 +1958,7 @@ fn test_target_backend() { "#]], ); check( - &get_stdout(&dir, ["build", "--dry-run", "--target", "js", "--nostd"]), + get_stdout(&dir, ["build", "--dry-run", "--target", "js", "--nostd"]), expect![[r#" moonc build-package ./lib/hello.mbt -o ./target/js/release/build/lib/lib.core -pkg hello/lib -pkg-sources hello/lib:./lib -target js moonc build-package ./main/main.mbt -o ./target/js/release/build/main/main.core -pkg hello/main -is-main -i ./target/js/release/build/lib/lib.mi:lib -pkg-sources hello/main:./main -target js @@ -1978,7 +1966,7 @@ fn test_target_backend() { "#]], ); check( - &get_stdout(&dir, ["build", "--dry-run", "--nostd"]), + get_stdout(&dir, ["build", "--dry-run", "--nostd"]), expect![[r#" moonc build-package ./lib/hello.mbt -o ./target/wasm-gc/release/build/lib/lib.core -pkg hello/lib -pkg-sources hello/lib:./lib -target wasm-gc moonc build-package ./main/main.mbt -o ./target/wasm-gc/release/build/main/main.core -pkg hello/main -is-main -i ./target/wasm-gc/release/build/lib/lib.mi:lib -pkg-sources hello/main:./main -target wasm-gc @@ -1986,7 +1974,7 @@ fn test_target_backend() { "#]], ); check( - &get_stdout(&dir, ["run", "main", "--dry-run", "--nostd"]), + get_stdout(&dir, ["run", "main", "--dry-run", "--nostd"]), expect![[r#" moonc build-package ./lib/hello.mbt -o ./target/wasm-gc/release/build/lib/lib.core -pkg hello/lib -pkg-sources hello/lib:./lib -target wasm-gc moonc build-package ./main/main.mbt -o ./target/wasm-gc/release/build/main/main.core -pkg hello/main -is-main -i ./target/wasm-gc/release/build/lib/lib.mi:lib -pkg-sources hello/main:./main -target wasm-gc @@ -1995,7 +1983,7 @@ fn test_target_backend() { "#]], ); check( - &get_stdout( + get_stdout( &dir, ["run", "main", "--dry-run", "--target", "wasm-gc", "--nostd"], ), @@ -2007,7 +1995,7 @@ fn test_target_backend() { "#]], ); check( - &get_stdout( + get_stdout( &dir, ["run", "main", "--dry-run", "--target", "js", "--nostd"], ), @@ -2034,7 +2022,7 @@ fn test_test_error_report() { fn test_moonbit_docs_example() { let dir = TestDir::new("unicode_demo.in"); check( - &get_stdout(&dir, ["run", "main"]), + get_stdout(&dir, ["run", "main"]), expect![[r#" 3 "#]], @@ -2042,7 +2030,7 @@ fn test_moonbit_docs_example() { let dir = TestDir::new("palindrome_string.in"); check( - &get_stdout(&dir, ["run", "main"]), + get_stdout(&dir, ["run", "main"]), expect![[r#" aba "#]], @@ -2050,7 +2038,7 @@ fn test_moonbit_docs_example() { let dir = TestDir::new("avl_tree.in"); check( - &get_stdout(&dir, ["run", "main"]), + get_stdout(&dir, ["run", "main"]), expect![[r#" height of the tree: 6 0 @@ -2089,7 +2077,7 @@ fn test_moonbit_docs_example() { let dir = TestDir::new("docstring-demo.in"); check( - &get_stdout(&dir, ["run", "main"]), + get_stdout(&dir, ["run", "main"]), expect![[r#" Hello, world! "#]], @@ -2097,7 +2085,7 @@ fn test_moonbit_docs_example() { let dir = TestDir::new("multidimensional_arrays.in"); check( - &get_stdout(&dir, ["run", "main"]), + get_stdout(&dir, ["run", "main"]), expect![[r#" 11 "#]], @@ -2141,7 +2129,7 @@ fn test_moon_inline_test_004() { fn test_moon_inline_test_order() { let dir = TestDir::new("moon_inline_test_order.in"); check( - &get_stdout(&dir, ["test", "-v", "--sort-input", "--no-parallelize"]), + get_stdout(&dir, ["test", "-v", "--sort-input", "--no-parallelize"]), expect![[r#" executing A executing A::hello.mbt::test_A @@ -2164,7 +2152,7 @@ fn test_moon_inline_test_order() { ); check( - &get_stdout(&dir, ["run", "main", "--sort-input"]), + get_stdout(&dir, ["run", "main", "--sort-input"]), expect![[r#" main.mbt::init "#]], @@ -2182,7 +2170,7 @@ fn test_error_duplicate_alias() { fn test_core_order() { let dir = TestDir::new("core_order.in"); check( - &get_stdout(&dir, ["build", "--dry-run", "--nostd"]), + get_stdout(&dir, ["build", "--dry-run", "--nostd"]), expect![[r#" moonc build-package ./T/t.mbt -o ./target/wasm-gc/release/build/T/T.core -pkg lijunchen/hello/T -pkg-sources lijunchen/hello/T:./T -target wasm-gc moonc build-package ./A/a.mbt -o ./target/wasm-gc/release/build/A/A.core -pkg lijunchen/hello/A -i ./target/wasm-gc/release/build/T/T.mi:T -pkg-sources lijunchen/hello/A:./A -target wasm-gc @@ -2197,7 +2185,7 @@ fn test_core_order() { fn test_moon_bundle() { let dir = TestDir::new("moon_bundle.in"); check( - &get_stdout(&dir, ["bundle", "--dry-run", "--sort-input"]), + get_stdout(&dir, ["bundle", "--dry-run", "--sort-input"]), expect![[r#" moonc build-package ./A/lib.mbt -o ./target/wasm-gc/release/bundle/A/A.core -pkg moonbitlang/core/A -pkg-sources moonbitlang/core/A:./A -target wasm-gc moonc build-package ./B/lib.mbt -o ./target/wasm-gc/release/bundle/B/B.core -pkg moonbitlang/core/B -i ./target/wasm-gc/release/bundle/A/A.mi:A -pkg-sources moonbitlang/core/B:./B -target wasm-gc @@ -2273,7 +2261,7 @@ fn test_only_update_expect() { fn test_need_link() { let dir = TestDir::new("need_link.in"); check( - &get_stdout(&dir, ["build", "--dry-run", "--nostd", "--sort-input"]), + get_stdout(&dir, ["build", "--dry-run", "--nostd", "--sort-input"]), expect![[r#" moonc build-package ./lib/hello.mbt -o ./target/wasm-gc/release/build/lib/lib.core -pkg username/hello/lib -pkg-sources username/hello/lib:./lib -target wasm-gc moonc build-package ./main/main.mbt -o ./target/wasm-gc/release/build/main/main.core -pkg username/hello/main -is-main -i ./target/wasm-gc/release/build/lib/lib.mi:lib -pkg-sources username/hello/main:./main -target wasm-gc @@ -2298,7 +2286,7 @@ fn test_backend_config() { TargetBackend::default().to_backend_ext().replace('-', "_") ))); check( - &get_stdout(&dir, ["build", "--dry-run", "--sort-input"]), + get_stdout(&dir, ["build", "--dry-run", "--sort-input"]), expect![[r#" moonc build-package ./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:./lib -target wasm-gc moonc build-package ./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 -pkg-sources username/hello/main:./main -target wasm-gc @@ -2308,7 +2296,7 @@ fn test_backend_config() { ); check( - &get_stdout( + get_stdout( &dir, [ "build", @@ -2328,7 +2316,7 @@ fn test_backend_config() { ); check( - &get_stdout( + get_stdout( &dir, [ "build", @@ -2404,7 +2392,7 @@ fn test_dummy_core() { { let p = dir.join("target/packages.json"); check( - &replace_dir(&std::fs::read_to_string(p).unwrap(), &dir), + replace_dir(&std::fs::read_to_string(p).unwrap(), &dir), expect![[r#" { "source_dir": "$ROOT", @@ -2675,7 +2663,7 @@ fn test_dummy_core() { { let p = dir.join("target/packages.json"); check( - &replace_dir(&std::fs::read_to_string(p).unwrap(), &dir), + replace_dir(&std::fs::read_to_string(p).unwrap(), &dir), expect![[r#" { "source_dir": "$ROOT", @@ -2938,7 +2926,7 @@ fn test_dummy_core() { }; check( - &get_stdout(&dir, ["check", "--dry-run", "--sort-input"]), + get_stdout(&dir, ["check", "--dry-run", "--sort-input"]), expect![[r#" moonc check -o ./target/wasm-gc/release/check/coverage/coverage.mi -pkg moonbitlang/core/coverage -pkg-sources moonbitlang/core/coverage:./coverage -target wasm-gc moonc check -o ./target/wasm-gc/release/check/iter/iter.mi -pkg moonbitlang/core/iter -i ./target/wasm-gc/release/check/coverage/coverage.mi:coverage -pkg-sources moonbitlang/core/iter:./iter -target wasm-gc @@ -2951,7 +2939,7 @@ fn test_dummy_core() { "#]], ); check( - &get_stdout( + get_stdout( &dir, ["check", "--dry-run", "--target", "wasm", "--sort-input"], ), @@ -2967,7 +2955,7 @@ fn test_dummy_core() { "#]], ); check( - &get_stdout( + get_stdout( &dir, ["check", "--dry-run", "--target", "wasm-gc", "--sort-input"], ), @@ -2983,7 +2971,7 @@ fn test_dummy_core() { "#]], ); check( - &get_stdout( + get_stdout( &dir, ["check", "--dry-run", "--target", "js", "--sort-input"], ), @@ -3000,7 +2988,7 @@ fn test_dummy_core() { ); check( - &get_stdout(&dir, ["build", "--dry-run", "--sort-input"]), + get_stdout(&dir, ["build", "--dry-run", "--sort-input"]), expect![[r#" moonc build-package ./1/lib.mbt ./1/x.wasm-gc.mbt -o ./target/wasm-gc/release/build/1/1.core -pkg moonbitlang/core/1 -pkg-sources moonbitlang/core/1:./1 -target wasm-gc moonc build-package ./2/lib.mbt -o ./target/wasm-gc/release/build/2/2.core -pkg moonbitlang/core/2 -i ./target/wasm-gc/release/build/1/1.mi:1 -pkg-sources moonbitlang/core/2:./2 -target wasm-gc @@ -3011,7 +2999,7 @@ fn test_dummy_core() { "#]], ); check( - &get_stdout( + get_stdout( &dir, ["build", "--dry-run", "--target", "wasm", "--sort-input"], ), @@ -3025,7 +3013,7 @@ fn test_dummy_core() { "#]], ); check( - &get_stdout( + get_stdout( &dir, ["build", "--dry-run", "--target", "wasm-gc", "--sort-input"], ), @@ -3039,7 +3027,7 @@ fn test_dummy_core() { "#]], ); check( - &get_stdout( + get_stdout( &dir, ["build", "--dry-run", "--target", "js", "--sort-input"], ), @@ -3054,7 +3042,7 @@ fn test_dummy_core() { ); check( - &get_stdout(&dir, ["test", "--dry-run", "--sort-input"]), + get_stdout(&dir, ["test", "--dry-run", "--sort-input"]), expect![[r#" moon generate-test-driver --source-dir . --target-dir ./target/wasm-gc/debug/test --package moonbitlang/core/iter --sort-input --target wasm-gc --driver-kind internal moonc build-package -o ./target/wasm-gc/debug/test/coverage/coverage.core -pkg moonbitlang/core/coverage -pkg-sources moonbitlang/core/coverage:./coverage -target wasm-gc -g @@ -3085,7 +3073,7 @@ fn test_dummy_core() { "#]], ); check( - &get_stdout( + get_stdout( &dir, ["test", "--dry-run", "--target", "wasm", "--sort-input"], ), @@ -3119,7 +3107,7 @@ fn test_dummy_core() { "#]], ); check( - &get_stdout( + get_stdout( &dir, ["test", "--dry-run", "--target", "wasm-gc", "--sort-input"], ), @@ -3153,7 +3141,7 @@ fn test_dummy_core() { "#]], ); check( - &get_stdout( + get_stdout( &dir, ["test", "--dry-run", "--target", "js", "--sort-input"], ), @@ -3187,7 +3175,7 @@ fn test_dummy_core() { "#]], ); check( - &get_stdout( + get_stdout( &dir, ["test", "--dry-run", "--enable-coverage", "--sort-input"], ), @@ -3221,7 +3209,7 @@ fn test_dummy_core() { "#]], ); check( - &get_stdout(&dir, ["bundle", "--dry-run", "--sort-input"]), + get_stdout(&dir, ["bundle", "--dry-run", "--sort-input"]), expect![[r#" moonc build-package ./1/lib.mbt ./1/x.wasm-gc.mbt -o ./target/wasm-gc/release/bundle/1/1.core -pkg moonbitlang/core/1 -pkg-sources moonbitlang/core/1:./1 -target wasm-gc moonc build-package -o ./target/wasm-gc/release/bundle/coverage/coverage.core -pkg moonbitlang/core/coverage -pkg-sources moonbitlang/core/coverage:./coverage -target wasm-gc @@ -3233,7 +3221,7 @@ fn test_dummy_core() { "#]], ); check( - &get_stdout( + get_stdout( &dir, ["bundle", "--dry-run", "--target", "wasm", "--sort-input"], ), @@ -3248,7 +3236,7 @@ fn test_dummy_core() { "#]], ); check( - &get_stdout( + get_stdout( &dir, ["bundle", "--dry-run", "--target", "wasm-gc", "--sort-input"], ), @@ -3263,7 +3251,7 @@ fn test_dummy_core() { "#]], ); check( - &get_stdout( + get_stdout( &dir, ["bundle", "--dry-run", "--target", "js", "--sort-input"], ), @@ -3278,7 +3266,7 @@ fn test_dummy_core() { "#]], ); check( - &get_stdout( + get_stdout( &dir, [ "bundle", @@ -3328,7 +3316,7 @@ fn test_backend_flag() { let dir = TestDir::new("backend-flag.in"); check( - &get_stdout(&dir, ["check", "--dry-run", "--sort-input"]), + get_stdout(&dir, ["check", "--dry-run", "--sort-input"]), expect![[r#" moonc check ./lib/hello.mbt -o ./target/js/release/check/lib/lib.mi -pkg username/hello/lib -std-path $MOON_HOME/lib/core/target/js/release/bundle -pkg-sources username/hello/lib:./lib moonc check ./main/main.mbt -o ./target/js/release/check/main/main.mi -pkg username/hello/main -is-main -std-path $MOON_HOME/lib/core/target/js/release/bundle -i ./target/js/release/check/lib/lib.mi:lib -pkg-sources username/hello/main:./main @@ -3337,7 +3325,7 @@ fn test_backend_flag() { ); check( - &get_stdout(&dir, ["build", "--dry-run", "--sort-input"]), + get_stdout(&dir, ["build", "--dry-run", "--sort-input"]), expect![[r#" moonc build-package ./lib/hello.mbt -o ./target/js/release/build/lib/lib.core -pkg username/hello/lib -std-path $MOON_HOME/lib/core/target/js/release/bundle -pkg-sources username/hello/lib:./lib moonc build-package ./main/main.mbt -o ./target/js/release/build/main/main.core -pkg username/hello/main -is-main -std-path $MOON_HOME/lib/core/target/js/release/bundle -i ./target/js/release/build/lib/lib.mi:lib -pkg-sources username/hello/main:./main @@ -3346,7 +3334,7 @@ fn test_backend_flag() { ); check( - &get_stdout(&dir, ["test", "--dry-run", "--sort-input"]), + get_stdout(&dir, ["test", "--dry-run", "--sort-input"]), expect![[r#" moon generate-test-driver --source-dir . --target-dir ./target/js/debug/test moonc build-package ./lib/hello.mbt ./lib/hello_test.mbt ./target/js/debug/test/lib/__generated_driver_for_underscore_test.mbt -o ./target/js/debug/test/lib/lib.underscore_test.core -pkg username/hello/lib -is-main -std-path $MOON_HOME/lib/core/target/js/release/bundle -pkg-sources username/hello/lib:./lib -g -ryu @@ -3357,7 +3345,7 @@ fn test_backend_flag() { ); check( - &get_stdout(&dir, ["bundle", "--dry-run", "--sort-input"]), + get_stdout(&dir, ["bundle", "--dry-run", "--sort-input"]), expect![[r#" moonc build-package ./lib/hello.mbt -o ./target/js/release/bundle/lib/lib.core -pkg username/hello/lib -pkg-sources username/hello/lib:./lib moonc build-package ./main/main.mbt -o ./target/js/release/bundle/main/main.core -pkg username/hello/main -is-main -i ./target/js/release/bundle/lib/lib.mi:lib -pkg-sources username/hello/main:./main @@ -3372,7 +3360,7 @@ fn test_source_map() { // no -source-map in wasm backend check( - &get_stdout( + get_stdout( &dir, [ "build", @@ -3389,7 +3377,7 @@ fn test_source_map() { "#]], ); check( - &get_stdout( + get_stdout( &dir, [ "build", @@ -3406,7 +3394,7 @@ fn test_source_map() { "#]], ); check( - &get_stdout( + get_stdout( &dir, [ "build", @@ -3429,14 +3417,14 @@ fn test_find_ancestor_with_mod() { let dir = TestDir::new("hello.in"); check( - &get_stdout(&dir, ["run", "main"]), + get_stdout(&dir, ["run", "main"]), expect![[r#" Hello, world! "#]], ); check( - &get_stdout(&dir, ["run", "main"]), + get_stdout(&dir, ["run", "main"]), expect![[r#" Hello, world! "#]], @@ -3447,7 +3435,7 @@ fn test_find_ancestor_with_mod() { fn test_js_format() { let dir = TestDir::new("js_format.in"); check( - &get_stdout( + get_stdout( &dir, [ "build", @@ -3472,9 +3460,9 @@ fn test_js_format() { let _ = get_stdout(&dir, ["build", "--target", "js", "--nostd"]); let t = dir.join("target").join("js").join("release").join("build"); check( - &std::fs::read_to_string(t.join("lib0").join("lib0.js")) + std::fs::read_to_string(t.join("lib0").join("lib0.js")) .unwrap() - .replace("\r\n", "\n"), + .replace_crlf_to_lf(), expect![[r#" function username$hello$lib0$$hello() { return "Hello, world!"; @@ -3483,9 +3471,9 @@ fn test_js_format() { "#]], ); check( - &std::fs::read_to_string(t.join("lib1").join("lib1.js")) + std::fs::read_to_string(t.join("lib1").join("lib1.js")) .unwrap() - .replace("\r\n", "\n"), + .replace_crlf_to_lf(), expect![[r#" function username$hello$lib1$$hello() { return "Hello, world!"; @@ -3494,9 +3482,9 @@ fn test_js_format() { "#]], ); check( - &std::fs::read_to_string(t.join("lib2").join("lib2.js")) + std::fs::read_to_string(t.join("lib2").join("lib2.js")) .unwrap() - .replace("\r\n", "\n"), + .replace_crlf_to_lf(), expect![[r#" function username$hello$lib2$$hello() { return "Hello, world!"; @@ -3505,9 +3493,9 @@ fn test_js_format() { "#]], ); check( - &std::fs::read_to_string(t.join("lib3").join("lib3.js")) + std::fs::read_to_string(t.join("lib3").join("lib3.js")) .unwrap() - .replace("\r\n", "\n"), + .replace_crlf_to_lf(), expect![[r#" (() => { function username$hello$lib3$$hello() { @@ -3524,7 +3512,7 @@ fn test_warn_list_dry_run() { let dir = TestDir::new("warn_list.in"); check( - &get_stdout(&dir, ["build", "--sort-input", "--no-render", "--dry-run"]), + get_stdout(&dir, ["build", "--sort-input", "--no-render", "--dry-run"]), expect![[r#" moonc build-package ./lib/hello.mbt -w -2 -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:./lib -target wasm-gc moonc build-package ./lib1/hello.mbt -w -1 -o ./target/wasm-gc/release/build/lib1/lib1.core -pkg username/hello/lib1 -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -pkg-sources username/hello/lib1:./lib1 -target wasm-gc @@ -3534,14 +3522,14 @@ fn test_warn_list_dry_run() { ); check( - &get_stdout(&dir, ["test", "--sort-input"]), + get_stdout(&dir, ["test", "--sort-input"]), expect![[r#" Total tests: 0, passed: 0, failed: 0. "#]], ); check( - &get_stdout(&dir, ["bundle", "--sort-input", "--no-render", "--dry-run"]), + get_stdout(&dir, ["bundle", "--sort-input", "--no-render", "--dry-run"]), expect![[r#" moonc build-package ./lib/hello.mbt -w -2 -o ./target/wasm-gc/release/bundle/lib/lib.core -pkg username/hello/lib -pkg-sources username/hello/lib:./lib -target wasm-gc moonc build-package ./lib1/hello.mbt -w -1 -o ./target/wasm-gc/release/bundle/lib1/lib1.core -pkg username/hello/lib1 -pkg-sources username/hello/lib1:./lib1 -target wasm-gc @@ -3554,7 +3542,7 @@ fn test_warn_list_dry_run() { get_stdout(&dir, ["bundle", "--sort-input"]); check( - &get_stdout(&dir, ["check", "--sort-input", "--no-render", "--dry-run"]), + get_stdout(&dir, ["check", "--sort-input", "--no-render", "--dry-run"]), expect![[r#" moonc check ./lib/hello.mbt -w -2 -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 ./lib1/hello.mbt -w -1 -o ./target/wasm-gc/release/check/lib1/lib1.mi -pkg username/hello/lib1 -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -pkg-sources username/hello/lib1:./lib1 -target wasm-gc @@ -3568,21 +3556,21 @@ fn test_warn_list_real_run() { let dir = TestDir::new("warn_list.in"); check( - &get_stderr(&dir, ["build", "--sort-input", "--no-render"]), + get_stderr(&dir, ["build", "--sort-input", "--no-render"]), expect![[r#" Finished. moon: ran 4 tasks, now up to date "#]], ); check( - &get_stdout(&dir, ["test", "--sort-input"]), + get_stdout(&dir, ["test", "--sort-input"]), expect![[r#" Total tests: 0, passed: 0, failed: 0. "#]], ); check( - &get_stderr(&dir, ["bundle", "--sort-input", "--no-render"]), + get_stderr(&dir, ["bundle", "--sort-input", "--no-render"]), expect![[r#" Finished. moon: ran 4 tasks, now up to date "#]], @@ -3592,7 +3580,7 @@ fn test_warn_list_real_run() { get_stdout(&dir, ["bundle", "--sort-input"]); check( - &get_stderr(&dir, ["check", "--sort-input", "--no-render"]), + get_stderr(&dir, ["check", "--sort-input", "--no-render"]), expect![[r#" Finished. moon: ran 3 tasks, now up to date "#]], @@ -3605,7 +3593,7 @@ fn test_alert_list() { let dir = TestDir::new("alert_list.in"); check( - &get_stderr(&dir, ["build", "--sort-input"]), + get_stderr(&dir, ["build", "--sort-input"]), expect![[r#" Warning: [2000] ╭─[$ROOT/main/main.mbt:3:3] @@ -3619,14 +3607,14 @@ fn test_alert_list() { ); check( - &get_stdout(&dir, ["test", "--sort-input"]), + get_stdout(&dir, ["test", "--sort-input"]), expect![[r#" Total tests: 1, passed: 1, failed: 0. "#]], ); check( - &get_stderr(&dir, ["bundle", "--sort-input"]), + get_stderr(&dir, ["bundle", "--sort-input"]), expect![[r#" Warning: [2000] ╭─[$ROOT/main/main.mbt:3:3] @@ -3640,7 +3628,7 @@ fn test_alert_list() { ); check( - &get_stderr(&dir, ["check", "--sort-input"]), + get_stderr(&dir, ["check", "--sort-input"]), expect![[r#" Warning: [2000] ╭─[$ROOT/main/main.mbt:3:3] @@ -3659,7 +3647,7 @@ fn test_mod_level_warn_alert_list() { let dir = TestDir::new("mod_level_warn&alert_list.in"); check( - &get_stdout(&dir, ["check", "--dry-run"]), + get_stdout(&dir, ["check", "--dry-run"]), expect![[r#" moonc check ./lib/hello.mbt -w -1 -alert -alert_1 -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 -w -1-2 -alert -alert_1-alert_2 -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 @@ -3687,7 +3675,7 @@ fn test_moon_test_release() { let dir = TestDir::new("test_release.in"); check( - &get_stdout(&dir, ["test", "--dry-run", "--sort-input"]), + get_stdout(&dir, ["test", "--dry-run", "--sort-input"]), expect![[r#" moon generate-test-driver --source-dir . --target-dir ./target/wasm-gc/debug/test --package username/hello/lib --sort-input --target wasm-gc --driver-kind whitebox moonc build-package ./lib/hello.mbt ./lib/hello_wbtest.mbt ./target/wasm-gc/debug/test/lib/__generated_driver_for_whitebox_test.mbt -o ./target/wasm-gc/debug/test/lib/lib.whitebox_test.core -pkg username/hello/lib -is-main -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -pkg-sources username/hello/lib:./lib -target wasm-gc -g @@ -3699,7 +3687,7 @@ fn test_moon_test_release() { ); check( - &get_stdout(&dir, ["test", "--release", "--dry-run", "--sort-input"]), + get_stdout(&dir, ["test", "--release", "--dry-run", "--sort-input"]), expect![[r#" moon generate-test-driver --source-dir . --target-dir ./target/wasm-gc/release/test --package username/hello/lib --sort-input --target wasm-gc --driver-kind whitebox moonc build-package ./lib/hello.mbt ./lib/hello_wbtest.mbt ./target/wasm-gc/release/test/lib/__generated_driver_for_whitebox_test.mbt -o ./target/wasm-gc/release/test/lib/lib.whitebox_test.core -pkg username/hello/lib -is-main -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -pkg-sources username/hello/lib:./lib -target wasm-gc @@ -3711,7 +3699,7 @@ fn test_moon_test_release() { ); check( - &get_stdout( + get_stdout( &dir, ["test", "--release", "--sort-input", "--no-parallelize"], ), @@ -3743,7 +3731,7 @@ fn test_deny_warn() { let dir = TestDir::new("test_deny_warn.in"); check( - &get_stderr(&dir, ["check", "--sort-input"]), + get_stderr(&dir, ["check", "--sort-input"]), expect![[r#" Warning: [2000] ╭─[$ROOT/lib/hello.mbt:13:3] @@ -3792,14 +3780,14 @@ fn test_deny_warn() { ); check( - &get_err_stdout(&dir, ["check", "--deny-warn", "--sort-input"]), + get_err_stdout(&dir, ["check", "--deny-warn", "--sort-input"]), expect![[r#" failed: moonc check -error-format json -w @a -alert @all-raise-throw-unsafe+deprecated $ROOT/lib/hello.mbt -o $ROOT/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:$ROOT/lib -target wasm-gc "#]], ); check( - &get_stderr(&dir, ["build", "--sort-input"]), + get_stderr(&dir, ["build", "--sort-input"]), expect![[r#" Warning: [2000] ╭─[$ROOT/lib/hello.mbt:13:3] @@ -3848,7 +3836,7 @@ fn test_deny_warn() { ); check( - &get_err_stdout(&dir, ["build", "--deny-warn", "--sort-input"]), + get_err_stdout(&dir, ["build", "--deny-warn", "--sort-input"]), expect![[r#" failed: moonc build-package -error-format json -w @a -alert @all-raise-throw-unsafe+deprecated $ROOT/lib/hello.mbt -o $ROOT/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:$ROOT/lib -target wasm-gc "#]], @@ -3880,19 +3868,19 @@ fn test_moon_test_no_entry_warning() { fn test_moon_fmt() { let dir = TestDir::new("moon_fmt.in"); check( - &read(&dir.join("lib").join("hello.mbt")), + read(dir.join("lib").join("hello.mbt")), expect![[r#" pub fn hello() -> String { "Hello, world!" } "#]], ); check( - &read(&dir.join("main").join("main.mbt")), + read(dir.join("main").join("main.mbt")), expect![[r#" fn main { println(@lib.hello()) }"#]], ); let _ = get_stdout(&dir, ["fmt"]); check( - &read(&dir.join("lib").join("hello.mbt")), + read(dir.join("lib").join("hello.mbt")), expect![[r#" pub fn hello() -> String { "Hello, world!" @@ -3900,7 +3888,7 @@ fn test_moon_fmt() { "#]], ); check( - &read(&dir.join("main").join("main.mbt")), + read(dir.join("main").join("main.mbt")), expect![[r#" fn main { println(@lib.hello()) @@ -3922,19 +3910,19 @@ fn test_moon_fmt_002() { .stdout .to_owned(); check( - &read(&dir.join("lib").join("hello.mbt")), + read(dir.join("lib").join("hello.mbt")), expect![[r#" pub fn hello() -> String { "Hello, world!" } "#]], ); check( - &read(&dir.join("main").join("main.mbt")), + read(dir.join("main").join("main.mbt")), expect![[r#" fn main { println(@lib.hello()) }"#]], ); check( - &read( - &dir.join("target") + read( + dir.join("target") .join(TargetBackend::default().to_dir_name()) .join("release") .join("format") @@ -3948,8 +3936,8 @@ fn test_moon_fmt_002() { "#]], ); check( - &read( - &dir.join("target") + read( + dir.join("target") .join(TargetBackend::default().to_dir_name()) .join("release") .join("format") @@ -3980,7 +3968,7 @@ fn test_export_memory_name() { assert!(content.contains("awesome_memory")); check( - &get_stdout(&dir, ["build", "--dry-run", "--sort-input"]), + get_stdout(&dir, ["build", "--dry-run", "--sort-input"]), expect![[r#" moonc build-package ./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:./lib -target wasm-gc moonc build-package ./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 -pkg-sources username/hello/main:./main -target wasm-gc @@ -3989,7 +3977,7 @@ fn test_export_memory_name() { ); check( - &get_stdout( + get_stdout( &dir, ["build", "--dry-run", "--sort-input", "--target", "wasm"], ), @@ -4001,7 +3989,7 @@ fn test_export_memory_name() { ); check( - &get_stdout( + get_stdout( &dir, ["build", "--dry-run", "--sort-input", "--target", "js"], ), @@ -4017,7 +4005,7 @@ fn test_export_memory_name() { fn test_no_block_params() { let dir = TestDir::new("no_block_params.in"); check( - &get_stdout(&dir, ["build", "--dry-run", "--sort-input"]), + get_stdout(&dir, ["build", "--dry-run", "--sort-input"]), expect![[r#" moonc build-package ./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:./lib -target wasm-gc moonc build-package ./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 -pkg-sources username/hello/main:./main -target wasm-gc @@ -4026,7 +4014,7 @@ fn test_no_block_params() { ); check( - &get_stdout( + get_stdout( &dir, ["build", "--dry-run", "--sort-input", "--target", "wasm"], ), @@ -4038,7 +4026,7 @@ fn test_no_block_params() { ); check( - &get_stdout( + get_stdout( &dir, ["build", "--dry-run", "--sort-input", "--target", "js"], ), @@ -4075,7 +4063,7 @@ fn test_panic() { fn test_validate_import() { let dir = TestDir::new("validate_import.in"); check( - &get_err_stderr(&dir, ["check"]), + get_err_stderr(&dir, ["check"]), expect![[r#" error: failed to read import path in "$ROOT/main/moon.pkg.json" @@ -4084,7 +4072,7 @@ fn test_validate_import() { "#]], ); check( - &get_err_stderr(&dir, ["build"]), + get_err_stderr(&dir, ["build"]), expect![[r#" error: failed to read import path in "$ROOT/main/moon.pkg.json" @@ -4093,7 +4081,7 @@ fn test_validate_import() { "#]], ); check( - &get_err_stderr(&dir, ["test"]), + get_err_stderr(&dir, ["test"]), expect![[r#" error: failed to read import path in "$ROOT/main/moon.pkg.json" @@ -4102,7 +4090,7 @@ fn test_validate_import() { "#]], ); check( - &get_err_stderr(&dir, ["bundle"]), + get_err_stderr(&dir, ["bundle"]), expect![[r#" error: failed to read import path in "$ROOT/main/moon.pkg.json" @@ -4171,7 +4159,7 @@ fn test_multi_process() { fn test_internal_package() { let dir = TestDir::new("internal_package.in"); check( - &get_err_stderr(&dir, ["check", "--sort-input"]), + get_err_stderr(&dir, ["check", "--sort-input"]), expect![[r#" error: $ROOT/lib2/moon.pkg.json: cannot import internal package `username/hello/lib/internal` in `username/hello/lib2` $ROOT/lib2/moon.pkg.json: cannot import internal package `username/hello/lib/internal/b` in `username/hello/lib2` @@ -4189,7 +4177,7 @@ fn mooncakes_io_smoke_test() { let _ = get_stdout(&dir, ["update"]); let _ = get_stdout(&dir, ["add", "lijunchen/hello2@0.1.0"]); check( - &std::fs::read_to_string(dir.join("moon.mod.json")).unwrap(), + std::fs::read_to_string(dir.join("moon.mod.json")).unwrap(), expect![[r#" { "name": "hello", @@ -4200,7 +4188,7 @@ fn mooncakes_io_smoke_test() { ); let _ = get_stdout(&dir, ["remove", "lijunchen/hello2"]); check( - &std::fs::read_to_string(dir.join("moon.mod.json")).unwrap(), + std::fs::read_to_string(dir.join("moon.mod.json")).unwrap(), expect![[r#" { "name": "hello", @@ -4229,7 +4217,7 @@ fn mooncakes_io_smoke_test() { let mut lines = out.lines().collect::>(); lines.sort(); check( - &lines.join("\n"), + lines.join("\n"), expect![[r#" Using cached lijunchen/hello2@0.1.0 Using cached lijunchen/hello@0.1.0"#]], @@ -4248,7 +4236,7 @@ fn mooncakes_io_smoke_test() { .unwrap(); check( - &get_stdout(&dir, ["run", "main"]), + get_stdout(&dir, ["run", "main"]), expect![[r#" Hello, world!Hello, world2! "#]], @@ -4321,7 +4309,7 @@ fn whitespace_test() { // ); check( - &get_stdout(&dir, ["build", "--dry-run", "--nostd"]), + get_stdout(&dir, ["build", "--dry-run", "--nostd"]), expect![[r#" moonc build-package "./main lib/hello.mbt" -o "./target/wasm-gc/release/build/main lib/main lib.core" -pkg "username/hello/main lib" -pkg-sources "username/hello/main lib:./main lib" -target wasm-gc moonc build-package "./main exe/main.mbt" -o "./target/wasm-gc/release/build/main exe/main exe.core" -pkg "username/hello/main exe" -is-main -i "./target/wasm-gc/release/build/main lib/main lib.mi:lib" -pkg-sources "username/hello/main exe:./main exe" -target wasm-gc @@ -4330,7 +4318,7 @@ fn whitespace_test() { ); check( - &get_stdout(&dir, ["build", "--dry-run", "--debug", "--nostd"]), + get_stdout(&dir, ["build", "--dry-run", "--debug", "--nostd"]), expect![[r#" moonc build-package "./main lib/hello.mbt" -o "./target/wasm-gc/debug/build/main lib/main lib.core" -pkg "username/hello/main lib" -pkg-sources "username/hello/main lib:./main lib" -target wasm-gc -g -source-map moonc build-package "./main exe/main.mbt" -o "./target/wasm-gc/debug/build/main exe/main exe.core" -pkg "username/hello/main exe" -is-main -i "./target/wasm-gc/debug/build/main lib/main lib.mi:lib" -pkg-sources "username/hello/main exe:./main exe" -target wasm-gc -g -source-map @@ -4339,7 +4327,7 @@ fn whitespace_test() { ); check( - &get_stdout(&dir, ["run", "main exe", "--dry-run", "--nostd"]), + get_stdout(&dir, ["run", "main exe", "--dry-run", "--nostd"]), expect![[r#" moonc build-package "./main lib/hello.mbt" -o "./target/wasm-gc/release/build/main lib/main lib.core" -pkg "username/hello/main lib" -pkg-sources "username/hello/main lib:./main lib" -target wasm-gc moonc build-package "./main exe/main.mbt" -o "./target/wasm-gc/release/build/main exe/main exe.core" -pkg "username/hello/main exe" -is-main -i "./target/wasm-gc/release/build/main lib/main lib.mi:lib" -pkg-sources "username/hello/main exe:./main exe" -target wasm-gc @@ -4349,7 +4337,7 @@ fn whitespace_test() { ); check( - &get_stdout(&dir, ["run", "main exe", "--dry-run", "--debug", "--nostd"]), + get_stdout(&dir, ["run", "main exe", "--dry-run", "--debug", "--nostd"]), expect![[r#" moonc build-package "./main lib/hello.mbt" -o "./target/wasm-gc/debug/build/main lib/main lib.core" -pkg "username/hello/main lib" -pkg-sources "username/hello/main lib:./main lib" -target wasm-gc -g -source-map moonc build-package "./main exe/main.mbt" -o "./target/wasm-gc/debug/build/main exe/main exe.core" -pkg "username/hello/main exe" -is-main -i "./target/wasm-gc/debug/build/main lib/main lib.mi:lib" -pkg-sources "username/hello/main exe:./main exe" -target wasm-gc -g -source-map @@ -4358,7 +4346,7 @@ fn whitespace_test() { "#]], ); check( - &get_stdout( + get_stdout( &dir, ["build", "--target", "wasm-gc", "--dry-run", "--nostd"], ), @@ -4369,7 +4357,7 @@ fn whitespace_test() { "#]], ); check( - &get_stdout( + get_stdout( &dir, [ "build", @@ -4388,7 +4376,7 @@ fn whitespace_test() { ); check( - &get_stdout( + get_stdout( &dir, [ "run", @@ -4408,7 +4396,7 @@ fn whitespace_test() { ); check( - &get_stdout( + get_stdout( &dir, [ "run", @@ -4429,7 +4417,7 @@ fn whitespace_test() { ); check( - &get_stdout(&dir, ["run", "main exe"]), + get_stdout(&dir, ["run", "main exe"]), expect![[r#" Hello, world! "#]], @@ -4512,7 +4500,7 @@ fn debug_flag_test() { .success(); check( - &get_stdout(&dir, ["check", "--dry-run", "--nostd"]), + get_stdout(&dir, ["check", "--dry-run", "--nostd"]), expect![[r#" moonc check ./lib/hello.mbt -o ./target/wasm-gc/release/check/lib/lib.mi -pkg hello/lib -pkg-sources hello/lib:./lib -target wasm-gc moonc check ./main/main.mbt -o ./target/wasm-gc/release/check/main/main.mi -pkg hello/main -is-main -i ./target/wasm-gc/release/check/lib/lib.mi:lib -pkg-sources hello/main:./main -target wasm-gc @@ -4520,7 +4508,7 @@ fn debug_flag_test() { ); check( - &get_stdout(&dir, ["build", "--dry-run", "--nostd"]), + get_stdout(&dir, ["build", "--dry-run", "--nostd"]), expect![[r#" moonc build-package ./lib/hello.mbt -o ./target/wasm-gc/release/build/lib/lib.core -pkg hello/lib -pkg-sources hello/lib:./lib -target wasm-gc moonc build-package ./main/main.mbt -o ./target/wasm-gc/release/build/main/main.core -pkg hello/main -is-main -i ./target/wasm-gc/release/build/lib/lib.mi:lib -pkg-sources hello/main:./main -target wasm-gc @@ -4529,7 +4517,7 @@ fn debug_flag_test() { ); check( - &get_stdout(&dir, ["build", "--dry-run", "--debug", "--nostd"]), + get_stdout(&dir, ["build", "--dry-run", "--debug", "--nostd"]), expect![[r#" moonc build-package ./lib/hello.mbt -o ./target/wasm-gc/debug/build/lib/lib.core -pkg hello/lib -pkg-sources hello/lib:./lib -target wasm-gc -g -source-map moonc build-package ./main/main.mbt -o ./target/wasm-gc/debug/build/main/main.core -pkg hello/main -is-main -i ./target/wasm-gc/debug/build/lib/lib.mi:lib -pkg-sources hello/main:./main -target wasm-gc -g -source-map @@ -4538,7 +4526,7 @@ fn debug_flag_test() { ); check( - &get_stdout(&dir, ["run", "main", "--dry-run", "--nostd"]), + get_stdout(&dir, ["run", "main", "--dry-run", "--nostd"]), expect![[r#" moonc build-package ./lib/hello.mbt -o ./target/wasm-gc/release/build/lib/lib.core -pkg hello/lib -pkg-sources hello/lib:./lib -target wasm-gc moonc build-package ./main/main.mbt -o ./target/wasm-gc/release/build/main/main.core -pkg hello/main -is-main -i ./target/wasm-gc/release/build/lib/lib.mi:lib -pkg-sources hello/main:./main -target wasm-gc @@ -4548,7 +4536,7 @@ fn debug_flag_test() { ); check( - &get_stdout(&dir, ["run", "main", "--dry-run", "--debug", "--nostd"]), + get_stdout(&dir, ["run", "main", "--dry-run", "--debug", "--nostd"]), expect![[r#" moonc build-package ./lib/hello.mbt -o ./target/wasm-gc/debug/build/lib/lib.core -pkg hello/lib -pkg-sources hello/lib:./lib -target wasm-gc -g -source-map moonc build-package ./main/main.mbt -o ./target/wasm-gc/debug/build/main/main.core -pkg hello/main -is-main -i ./target/wasm-gc/debug/build/lib/lib.mi:lib -pkg-sources hello/main:./main -target wasm-gc -g -source-map @@ -4557,7 +4545,7 @@ fn debug_flag_test() { "#]], ); check( - &get_stdout( + get_stdout( &dir, ["build", "--target", "wasm-gc", "--dry-run", "--nostd"], ), @@ -4568,7 +4556,7 @@ fn debug_flag_test() { "#]], ); check( - &get_stdout( + get_stdout( &dir, [ "build", @@ -4587,7 +4575,7 @@ fn debug_flag_test() { ); check( - &get_stdout( + get_stdout( &dir, ["run", "main", "--target", "wasm-gc", "--dry-run", "--nostd"], ), @@ -4600,7 +4588,7 @@ fn debug_flag_test() { ); check( - &get_stdout( + get_stdout( &dir, [ "run", @@ -4657,7 +4645,7 @@ fn test_moon_run_with_cli_args() { let dir = TestDir::new("moo_run_with_cli_args.in"); check( - &get_stdout(&dir, ["run", "main", "--dry-run"]), + get_stdout(&dir, ["run", "main", "--dry-run"]), expect![[r#" moonc build-package ./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 -pkg-sources username/hello/main:./main -target wasm-gc moonc link-core $MOON_HOME/lib/core/target/wasm-gc/release/bundle/core.core ./target/wasm-gc/release/build/main/main.core -main username/hello/main -o ./target/wasm-gc/release/build/main/main.wasm -pkg-sources username/hello/main:./main -pkg-sources moonbitlang/core:$MOON_HOME/lib/core -target wasm-gc @@ -4666,7 +4654,7 @@ fn test_moon_run_with_cli_args() { ); check( - &get_stdout( + get_stdout( &dir, [ "run", @@ -4687,7 +4675,7 @@ fn test_moon_run_with_cli_args() { ); check( - &get_stdout(&dir, ["run", "main", "--", "中文", "😄👍", "hello", "1242"]), + get_stdout(&dir, ["run", "main", "--", "中文", "😄👍", "hello", "1242"]), expect![[r#" ["中文", "😄👍", "hello", "1242"] "#]], @@ -4704,11 +4692,11 @@ fn test_third_party() { get_stdout(&dir, ["build"]); get_stdout(&dir, ["clean"]); - let actual = &get_stderr(&dir, ["check"]); + let actual = get_stderr(&dir, ["check"]); assert!(actual.contains("moon: ran 4 tasks, now up to date")); check( - &get_stdout(&dir, ["test", "--dry-run", "--sort-input"]), + get_stdout(&dir, ["test", "--dry-run", "--sort-input"]), expect![[r#" 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 ./.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 @@ -4718,7 +4706,7 @@ fn test_third_party() { ); check( - &get_stdout(&dir, ["test", "--sort-input"]), + get_stdout(&dir, ["test", "--sort-input"]), expect![[r#" Hello, world! Hello, world! @@ -4726,10 +4714,10 @@ fn test_third_party() { "#]], ); - let actual = &get_stderr(&dir, ["build"]); + let actual = get_stderr(&dir, ["build"]); assert!(actual.contains("moon: ran 5 tasks, now up to date")); - let actual = &get_stdout(&dir, ["run", "main"]); + let actual = get_stdout(&dir, ["run", "main"]); assert!(actual.contains("Hello, world!")); } @@ -4738,7 +4726,7 @@ fn test_blackbox_success() { let dir = TestDir::new("blackbox_success_test.in"); check( - &get_stdout( + get_stdout( &dir, [ "test", @@ -4771,7 +4759,7 @@ fn test_blackbox_success() { ); check( - &get_stdout( + get_stdout( &dir, [ "test", @@ -4792,7 +4780,7 @@ fn test_blackbox_success() { ); check( - &get_stdout(&dir, ["test"]), + get_stdout(&dir, ["test"]), expect![[r#" output from A/hello.mbt! output from C/hello.mbt! @@ -4803,7 +4791,7 @@ fn test_blackbox_success() { ); check( - &get_stdout(&dir, ["check", "--sort-input", "--dry-run"]), + get_stdout(&dir, ["check", "--sort-input", "--dry-run"]), expect![[r#" 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 -pkg-sources username/hello/main:./main -target wasm-gc moonc check ./D/hello.mbt -o ./target/wasm-gc/release/check/D/D.mi -pkg username/hello/D -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -pkg-sources username/hello/D:./D -target wasm-gc @@ -4825,7 +4813,7 @@ fn test_blackbox_success() { { let p = dir.join("target/packages.json"); check( - &replace_dir(&std::fs::read_to_string(p).unwrap(), &dir), + replace_dir(&std::fs::read_to_string(p).unwrap(), &dir), expect![[r#" { "source_dir": "$ROOT", @@ -5114,7 +5102,7 @@ fn test_blackbox_dedup_alias() { fn test_import_memory_and_heap_start() { let dir = TestDir::new("import_memory.in"); check( - &get_stdout( + get_stdout( &dir, [ "build", @@ -5134,7 +5122,7 @@ fn test_import_memory_and_heap_start() { let dir = TestDir::new("import_memory.in"); check( - &get_stdout( + get_stdout( &dir, [ "build", @@ -5157,7 +5145,7 @@ fn test_import_memory_and_heap_start() { fn test_many_targets() { let dir = TestDir::new("test_many_targets.in"); check( - &get_stdout(&dir, ["test", "--target", "all", "--serial"]), + get_stdout(&dir, ["test", "--target", "all", "--serial"]), expect![[r#" Total tests: 0, passed: 0, failed: 0. [wasm] Total tests: 0, passed: 0, failed: 0. [wasm-gc] @@ -5166,7 +5154,7 @@ fn test_many_targets() { ); check( - &get_stdout(&dir, ["test", "--target", "js,wasm", "--serial"]), + get_stdout(&dir, ["test", "--target", "js,wasm", "--serial"]), expect![[r#" Total tests: 0, passed: 0, failed: 0. [wasm] Total tests: 0, passed: 0, failed: 0. [js] @@ -5174,7 +5162,7 @@ fn test_many_targets() { ); check( - &get_stdout( + get_stdout( &dir, [ "check", @@ -5195,7 +5183,7 @@ fn test_many_targets() { ); check( - &get_stdout( + get_stdout( &dir, [ "build", @@ -5216,7 +5204,7 @@ fn test_many_targets() { ); check( - &get_stdout( + get_stdout( &dir, [ "bundle", @@ -5239,7 +5227,7 @@ fn test_many_targets() { ); check( - &get_stdout( + get_stdout( &dir, [ "test", @@ -5268,7 +5256,7 @@ fn test_many_targets() { ); check( - &get_stdout( + get_stdout( &dir, [ "test", @@ -5297,7 +5285,7 @@ fn test_many_targets() { ); check( - &get_stdout( + get_stdout( &dir, [ "test", @@ -5332,7 +5320,7 @@ fn test_many_targets() { ); check( - &get_stdout( + get_stdout( &dir, [ "test", @@ -5372,7 +5360,7 @@ fn test_many_targets_auto_update_001() { let dir = TestDir::new("test_many_targets_auto_update.in"); let _ = get_stdout(&dir, ["test", "-u", "--no-parallelize"]); check( - &replace_crlf_to_lf(&std::fs::read_to_string(dir.join("lib").join("x.wasm.mbt")).unwrap()), + read(dir.join("lib").join("x.wasm.mbt")), expect![[r#" test { inspect!("wasm") @@ -5380,9 +5368,7 @@ fn test_many_targets_auto_update_001() { "#]], ); check( - &replace_crlf_to_lf( - &std::fs::read_to_string(dir.join("lib").join("x.wasm-gc.mbt")).unwrap(), - ), + read(dir.join("lib").join("x.wasm-gc.mbt")), expect![[r#" test { inspect!("wasm-gc", content="wasm-gc") @@ -5390,7 +5376,7 @@ fn test_many_targets_auto_update_001() { "#]], ); check( - &replace_crlf_to_lf(&std::fs::read_to_string(dir.join("lib").join("x.js.mbt")).unwrap()), + read(dir.join("lib").join("x.js.mbt")), expect![[r#" test { inspect!("js") @@ -5400,9 +5386,7 @@ fn test_many_targets_auto_update_001() { #[cfg(unix)] { check( - &replace_crlf_to_lf( - &std::fs::read_to_string(dir.join("lib").join("x.native.mbt")).unwrap(), - ), + read(dir.join("lib").join("x.native.mbt")), expect![[r#" test { inspect!("native") @@ -5417,7 +5401,7 @@ fn test_many_targets_auto_update_002() { let dir = TestDir::new("test_many_targets_auto_update.in"); let _ = get_stdout(&dir, ["test", "--target", "js", "-u", "--no-parallelize"]); check( - &replace_crlf_to_lf(&std::fs::read_to_string(dir.join("lib").join("x.wasm.mbt")).unwrap()), + read(dir.join("lib").join("x.wasm.mbt")), expect![[r#" test { inspect!("wasm") @@ -5425,9 +5409,7 @@ fn test_many_targets_auto_update_002() { "#]], ); check( - &replace_crlf_to_lf( - &std::fs::read_to_string(dir.join("lib").join("x.wasm-gc.mbt")).unwrap(), - ), + read(dir.join("lib").join("x.wasm-gc.mbt")), expect![[r#" test { inspect!("wasm-gc") @@ -5435,7 +5417,7 @@ fn test_many_targets_auto_update_002() { "#]], ); check( - &replace_crlf_to_lf(&std::fs::read_to_string(dir.join("lib").join("x.js.mbt")).unwrap()), + read(dir.join("lib").join("x.js.mbt")), expect![[r#" test { inspect!("js", content="js") @@ -5446,9 +5428,7 @@ fn test_many_targets_auto_update_002() { #[cfg(unix)] { check( - &replace_crlf_to_lf( - &std::fs::read_to_string(dir.join("lib").join("x.native.mbt")).unwrap(), - ), + read(dir.join("lib").join("x.native.mbt")), expect![[r#" test { inspect!("native") @@ -5461,9 +5441,7 @@ fn test_many_targets_auto_update_002() { ["test", "--target", "native", "-u", "--no-parallelize"], ); check( - &replace_crlf_to_lf( - &std::fs::read_to_string(dir.join("lib").join("x.native.mbt")).unwrap(), - ), + read(dir.join("lib").join("x.native.mbt")), expect![[r#" test { inspect!("native", content="native") @@ -5478,7 +5456,7 @@ fn test_many_targets_auto_update_003() { let dir = TestDir::new("test_many_targets_auto_update.in"); let _ = get_stdout(&dir, ["test", "--target", "wasm", "-u", "--no-parallelize"]); check( - &replace_crlf_to_lf(&std::fs::read_to_string(dir.join("lib").join("x.wasm.mbt")).unwrap()), + read(dir.join("lib").join("x.wasm.mbt")), expect![[r#" test { inspect!("wasm", content="wasm") @@ -5486,9 +5464,7 @@ fn test_many_targets_auto_update_003() { "#]], ); check( - &replace_crlf_to_lf( - &std::fs::read_to_string(dir.join("lib").join("x.wasm-gc.mbt")).unwrap(), - ), + read(dir.join("lib").join("x.wasm-gc.mbt")), expect![[r#" test { inspect!("wasm-gc") @@ -5497,7 +5473,7 @@ fn test_many_targets_auto_update_003() { ); let _ = get_stdout(&dir, ["test", "--target", "js", "-u", "--no-parallelize"]); check( - &replace_crlf_to_lf(&std::fs::read_to_string(dir.join("lib").join("x.js.mbt")).unwrap()), + read(dir.join("lib").join("x.js.mbt")), expect![[r#" test { inspect!("js", content="js") @@ -5511,7 +5487,7 @@ fn test_many_targets_auto_update_004() { let dir = TestDir::new("test_many_targets_auto_update.in"); let _ = get_stdout(&dir, ["test", "--target", "wasm", "-u", "--no-parallelize"]); check( - &replace_crlf_to_lf(&std::fs::read_to_string(dir.join("lib").join("x.wasm.mbt")).unwrap()), + read(dir.join("lib").join("x.wasm.mbt")), expect![[r#" test { inspect!("wasm", content="wasm") @@ -5523,9 +5499,7 @@ fn test_many_targets_auto_update_004() { ["test", "--target", "wasm-gc", "-u", "--no-parallelize"], ); check( - &replace_crlf_to_lf( - &std::fs::read_to_string(dir.join("lib").join("x.wasm-gc.mbt")).unwrap(), - ), + read(dir.join("lib").join("x.wasm-gc.mbt")), expect![[r#" test { inspect!("wasm-gc", content="wasm-gc") @@ -5534,7 +5508,7 @@ fn test_many_targets_auto_update_004() { ); let _ = get_stdout(&dir, ["test", "--target", "js", "-u", "--no-parallelize"]); check( - &replace_crlf_to_lf(&std::fs::read_to_string(dir.join("lib").join("x.js.mbt")).unwrap()), + read(dir.join("lib").join("x.js.mbt")), expect![[r#" test { inspect!("js", content="js") @@ -5547,7 +5521,7 @@ fn test_many_targets_auto_update_004() { fn test_many_targets_expect_failed() { let dir = TestDir::new("test_many_targets_expect_failed.in"); check( - &get_err_stdout( + get_err_stdout( &dir, ["test", "--target", "all", "--serial", "--sort-input"], ), @@ -5579,7 +5553,7 @@ fn test_many_targets_expect_failed() { "#]], ); check( - &get_err_stdout( + get_err_stdout( &dir, ["test", "--target", "js,wasm", "--sort-input", "--serial"], ), @@ -5606,7 +5580,7 @@ fn test_many_targets_expect_failed() { #[cfg(unix)] { check( - &get_err_stdout( + get_err_stdout( &dir, [ "test", @@ -5753,17 +5727,17 @@ fn test_moon_check_json_output() { #[cfg(unix)] { check( - &get_stdout(&dir, ["check", "--output-json", "-q"]), + get_stdout(&dir, ["check", "--output-json", "-q"]), expect![[r#" {"$message_type":"diagnostic","level":"warning","loc":{"path":"$ROOT/main/main.mbt","start":{"line":3,"col":3},"end":{"line":3,"col":10}},"message":"Warning (Alert alert_2): alert_2","error_code":2000} "#]], ); check( - &get_stderr(&dir, ["check", "--output-json", "-q"]), + get_stderr(&dir, ["check", "--output-json", "-q"]), expect![""], ); check( - &get_stderr(&dir, ["check", "--output-json"]), + get_stderr(&dir, ["check", "--output-json"]), expect![[r#" Finished. moon: no work to do "#]], @@ -5774,17 +5748,17 @@ fn test_moon_check_json_output() { #[cfg(windows)] { check( - &get_stdout(&dir, ["check", "--output-json", "-q"]), + get_stdout(&dir, ["check", "--output-json", "-q"]), expect![[r#" {"$message_type":"diagnostic","level":"warning","loc":{"path":"$ROOT/main/main.mbt","start":{"line":3,"col":3},"end":{"line":3,"col":10}},"message":"Warning (Alert alert_2): alert_2","error_code":2000} "#]], ); check( - &get_stderr(&dir, ["check", "--output-json", "-q"]), + get_stderr(&dir, ["check", "--output-json", "-q"]), expect![""], ); check( - &get_stderr(&dir, ["check", "--output-json"]), + get_stderr(&dir, ["check", "--output-json"]), expect![[r#" Finished. moon: no work to do "#]], @@ -5915,7 +5889,7 @@ fn moon_test_parallelize_should_success() { fn test_specify_source_dir_001() { let dir = TestDir::new("specify_source_dir_001.in"); check( - &get_stdout(&dir, ["check", "--dry-run", "--sort-input"]), + get_stdout(&dir, ["check", "--dry-run", "--sort-input"]), expect![[r#" 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 @@ -5923,7 +5897,7 @@ fn test_specify_source_dir_001() { "#]], ); check( - &get_stdout(&dir, ["build", "--dry-run", "--sort-input"]), + get_stdout(&dir, ["build", "--dry-run", "--sort-input"]), expect![[r#" 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 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 -pkg-sources username/hello/main:./src/main -target wasm-gc @@ -5931,7 +5905,7 @@ fn test_specify_source_dir_001() { "#]], ); check( - &get_stdout(&dir, ["test", "--dry-run", "--sort-input"]), + get_stdout(&dir, ["test", "--dry-run", "--sort-input"]), expect![[r#" 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 @@ -5943,7 +5917,7 @@ fn test_specify_source_dir_001() { "#]], ); check( - &get_stderr(&dir, ["check", "--sort-input"]), + get_stderr(&dir, ["check", "--sort-input"]), expect![[r#" Finished. moon: ran 3 tasks, now up to date "#]], @@ -5952,7 +5926,7 @@ fn test_specify_source_dir_001() { { let p = dir.join("target/packages.json"); check( - &replace_dir(&std::fs::read_to_string(p).unwrap(), &dir), + replace_dir(&std::fs::read_to_string(p).unwrap(), &dir), expect![[r#" { "source_dir": "$ROOT", @@ -6039,19 +6013,19 @@ fn test_specify_source_dir_001() { ) } check( - &get_stderr(&dir, ["build"]), + get_stderr(&dir, ["build"]), expect![[r#" Finished. moon: ran 3 tasks, now up to date "#]], ); check( - &get_stdout(&dir, ["test"]), + get_stdout(&dir, ["test"]), expect![[r#" Total tests: 1, passed: 1, failed: 0. "#]], ); check( - &get_stdout(&dir, ["run", "./src/main"]), + get_stdout(&dir, ["run", "./src/main"]), expect![[r#" Hello, world! "#]], @@ -6062,7 +6036,7 @@ fn test_specify_source_dir_001() { fn test_specify_source_dir_002() { let dir = TestDir::new("specify_source_dir_002.in"); check( - &get_err_stdout(&dir, ["test"]), + get_err_stdout(&dir, ["test"]), expect![[r#" test username/hello/lib/hello_test.mbt::hello failed expect test failed at $ROOT/src/lib/hello_test.mbt:2:3-2:25 @@ -6075,7 +6049,7 @@ fn test_specify_source_dir_002() { "#]], ); check( - &get_stdout(&dir, ["test", "-u", "--no-parallelize"]), + get_stdout(&dir, ["test", "-u", "--no-parallelize"]), expect![[r#" Auto updating expect tests and retesting ... @@ -6085,9 +6059,7 @@ fn test_specify_source_dir_002() { ); check( - &replace_crlf_to_lf( - &std::fs::read_to_string(dir.join("src").join("lib").join("hello_test.mbt")).unwrap(), - ), + read(dir.join("src").join("lib").join("hello_test.mbt")), expect![[r#" test "hello" { inspect!(@lib.hello(), content="Hello, world!") @@ -6100,7 +6072,7 @@ fn test_specify_source_dir_002() { fn test_specify_source_dir_003() { let dir = TestDir::new("specify_source_dir_003_empty_string.in"); check( - &get_stderr(&dir, ["check"]), + get_stderr(&dir, ["check"]), expect![[r#" Finished. moon: ran 1 task, now up to date "#]], @@ -6111,7 +6083,7 @@ fn test_specify_source_dir_003() { fn test_specify_source_dir_004() { let dir = TestDir::new("specify_source_dir_004.in"); check( - &get_stderr(&dir, ["check"]), + get_stderr(&dir, ["check"]), expect![[r#" Finished. moon: ran 3 tasks, now up to date "#]], @@ -6119,7 +6091,7 @@ fn test_specify_source_dir_004() { get_stdout(&dir, ["clean"]); check( - &get_stdout( + get_stdout( &dir, ["run", "nes/t/ed/src/main", "--target", "js", "--build-only"], ), @@ -6130,7 +6102,7 @@ fn test_specify_source_dir_004() { assert!(dir.join("target/js/release/build/main/main.js").exists()); check( - &get_stdout(&dir, ["run", "nes/t/ed/src/main"]), + get_stdout(&dir, ["run", "nes/t/ed/src/main"]), expect![[r#" Hello, world! "#]], @@ -6141,7 +6113,7 @@ fn test_specify_source_dir_004() { fn test_specify_source_dir_005() { let dir = TestDir::new("specify_source_dir_005_bad.in"); check( - &get_err_stderr(&dir, ["check"]), + get_err_stderr(&dir, ["check"]), expect![[r#" error: failed to load `$ROOT/moon.mod.json` @@ -6156,7 +6128,7 @@ fn test_specify_source_dir_005() { fn test_specify_source_dir_with_deps() { let dir = TestDir::new("specify_source_dir_with_deps_001.in"); check( - &get_stdout(&dir, ["check", "--dry-run", "--sort-input"]), + get_stdout(&dir, ["check", "--dry-run", "--sort-input"]), expect![[r#" moonc check ./anyhow/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:./anyhow/lib -target wasm-gc moonc check ./deps/hello19/source/top.mbt -o ./target/wasm-gc/release/check/.mooncakes/just/hello19/hello19.mi -pkg just/hello19 -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -pkg-sources just/hello19:./deps/hello19/source -target wasm-gc @@ -6167,7 +6139,7 @@ fn test_specify_source_dir_with_deps() { "#]], ); check( - &get_stdout(&dir, ["build", "--dry-run", "--sort-input"]), + get_stdout(&dir, ["build", "--dry-run", "--sort-input"]), expect![[r#" moonc build-package ./anyhow/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:./anyhow/lib -target wasm-gc 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 @@ -6177,7 +6149,7 @@ fn test_specify_source_dir_with_deps() { "#]], ); check( - &get_stdout(&dir, ["test", "--dry-run", "--sort-input"]), + get_stdout(&dir, ["test", "--dry-run", "--sort-input"]), expect![[r#" 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 ./anyhow/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:./anyhow/lib -target wasm-gc -g @@ -6189,25 +6161,25 @@ fn test_specify_source_dir_with_deps() { "#]], ); check( - &get_stderr(&dir, ["check"]), + get_stderr(&dir, ["check"]), expect![[r#" Finished. moon: ran 6 tasks, now up to date "#]], ); check( - &get_stderr(&dir, ["build"]), + get_stderr(&dir, ["build"]), expect![[r#" Finished. moon: ran 5 tasks, now up to date "#]], ); check( - &get_stdout(&dir, ["test"]), + get_stdout(&dir, ["test"]), expect![[r#" Total tests: 1, passed: 1, failed: 0. "#]], ); check( - &get_stdout(&dir, ["run", "./anyhow/main"]), + get_stdout(&dir, ["run", "./anyhow/main"]), expect![[r#" Hello, world! hello @@ -6220,20 +6192,20 @@ fn test_specify_source_dir_with_deps() { fn test_specify_source_dir_with_deps_002() { let dir = TestDir::new("specify_source_dir_with_deps_002.in"); check( - &get_stderr(&dir, ["check"]), + get_stderr(&dir, ["check"]), expect![[r#" Finished. moon: ran 13 tasks, now up to date "#]], ); check( - &get_stderr(&dir, ["build"]), + get_stderr(&dir, ["build"]), expect![[r#" Finished. moon: ran 10 tasks, now up to date "#]], ); - check(&get_stdout(&dir, ["test"]), expect![""]); + check(get_stdout(&dir, ["test"]), expect![""]); check( - &get_stdout(&dir, ["run", "./anyhow"]), + get_stdout(&dir, ["run", "./anyhow"]), expect![[r#" a!b!c!d! one!two!three!four! @@ -6245,7 +6217,7 @@ fn test_specify_source_dir_with_deps_002() { fn test_snapshot_test() { let dir = TestDir::new("snapshot_testing.in"); check( - &get_err_stdout(&dir, ["test", "--sort-input", "--no-parallelize"]), + get_err_stdout(&dir, ["test", "--sort-input", "--no-parallelize"]), expect![[r#" test username/hello/lib/hello_test.mbt::snapshot in blackbox test failed expect test failed at $ROOT/src/lib/hello_test.mbt:9:3 @@ -6292,7 +6264,7 @@ fn test_snapshot_test() { "#]], ); check( - &get_stdout(&dir, ["test", "-u", "--no-parallelize"]), + get_stdout(&dir, ["test", "-u", "--no-parallelize"]), expect![[r#" Auto updating expect tests and retesting ... @@ -6302,7 +6274,7 @@ fn test_snapshot_test() { ); check( - &read(&dir.join("src/lib/hello.mbt")), + read(dir.join("src/lib/hello.mbt")), expect![[r#" pub fn hello() -> String { "Hello, world!" @@ -6334,7 +6306,7 @@ fn test_snapshot_test() { "#]], ); check( - &read(&dir.join("src/lib/__snapshot__/001.txt")), + read(dir.join("src/lib/__snapshot__/001.txt")), expect![[r#" hello snapshot @@ -6342,7 +6314,7 @@ fn test_snapshot_test() { "#]], ); check( - &read(&dir.join("src/lib/__snapshot__/002.txt")), + read(dir.join("src/lib/__snapshot__/002.txt")), expect![[r#" should be @@ -6350,7 +6322,7 @@ fn test_snapshot_test() { "#]], ); check( - &read(&dir.join("src/lib/__snapshot__/003.txt")), + read(dir.join("src/lib/__snapshot__/003.txt")), expect!["Hello, world!"], ); } @@ -6359,7 +6331,7 @@ fn test_snapshot_test() { fn test_snapshot_test_target_js() { let dir = TestDir::new("snapshot_testing.in"); check( - &get_err_stdout( + get_err_stdout( &dir, ["test", "--target", "js", "--sort-input", "--no-parallelize"], ), @@ -6410,7 +6382,7 @@ fn test_snapshot_test_target_js() { ); assert!(dir.join("target/js/debug/test/package.json").exists()); check( - &get_stdout( + get_stdout( &dir, [ "test", @@ -6430,7 +6402,7 @@ fn test_snapshot_test_target_js() { ); check( - &read(&dir.join("src/lib/hello.mbt")), + read(dir.join("src/lib/hello.mbt")), expect![[r#" pub fn hello() -> String { "Hello, world!" @@ -6462,7 +6434,7 @@ fn test_snapshot_test_target_js() { "#]], ); check( - &read(&dir.join("src/lib/__snapshot__/001.txt")), + read(dir.join("src/lib/__snapshot__/001.txt")), expect![[r#" hello snapshot @@ -6470,7 +6442,7 @@ fn test_snapshot_test_target_js() { "#]], ); check( - &read(&dir.join("src/lib/__snapshot__/002.txt")), + read(dir.join("src/lib/__snapshot__/002.txt")), expect![[r#" should be @@ -6478,7 +6450,7 @@ fn test_snapshot_test_target_js() { "#]], ); check( - &read(&dir.join("src/lib/__snapshot__/003.txt")), + read(dir.join("src/lib/__snapshot__/003.txt")), expect!["Hello, world!"], ); } @@ -6617,7 +6589,7 @@ fn test_generate_test_driver_incremental() { fn test_moon_doc_dry_run() { let dir = TestDir::new("moon_doc.in"); check( - &get_stdout(&dir, ["doc", "--dry-run"]), + get_stdout(&dir, ["doc", "--dry-run"]), expect![[r#" 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 @@ -6632,7 +6604,7 @@ fn test_moon_doc() { let dir = TestDir::new("moon_doc.in"); let _ = get_stderr(&dir, ["doc"]); check( - &read(&dir.join("target/doc/username/hello/lib/members.md")), + read(dir.join("target/doc/username/hello/lib/members.md")), expect![[r#" # Documentation |Value|description| @@ -6648,11 +6620,11 @@ fn test_moon_doc() { "#]], ); check( - &read(&dir.join("target/doc/username/hello/main/members.md")), + read(dir.join("target/doc/username/hello/main/members.md")), expect!["# Documentation"], ); check( - &read(&dir.join("target/doc/username/hello/_sidebar.md")), + read(dir.join("target/doc/username/hello/_sidebar.md")), expect![[r#" - [username/hello](username/hello/) - **In this module** @@ -6667,7 +6639,7 @@ fn test_moon_doc() { fn test_failed_to_fill_whole_buffer() { let dir = TestDir::new("hello.in"); check( - &get_stderr(&dir, ["check"]), + get_stderr(&dir, ["check"]), expect![[r#" Finished. moon: ran 1 task, now up to date "#]], @@ -6678,7 +6650,7 @@ fn test_failed_to_fill_whole_buffer() { } std::fs::write(&moon_db_path, "").unwrap(); check( - &get_err_stderr(&dir, ["check"]), + get_err_stderr(&dir, ["check"]), expect![[r#" error: internal error @@ -6762,7 +6734,7 @@ pub struct TraceEvent { fn test_trace_001() { let dir = TestDir::new("hello.in"); let _ = get_stdout(&dir, ["build", "--trace"]); - let s = replace_dir(&read(&dir.join("trace.json")), &dir); + let s = replace_dir(&read(dir.join("trace.json")), &dir); let j: TraceResult = serde_json::from_str(&s).unwrap(); let event_names = j.0.iter().map(|e| e.name.clone()).collect::>(); check( @@ -6809,7 +6781,7 @@ fn no_main_just_init() { fn test_pre_build() { let dir = TestDir::new("pre_build.in"); check( - &get_stderr(&dir, ["check"]), + get_stderr(&dir, ["check"]), expect![[r#" Executed 3 pre-build tasks, now up to date Warning: [1002] @@ -6823,7 +6795,7 @@ fn test_pre_build() { "#]], ); check( - &get_stderr(&dir, ["build"]), + get_stderr(&dir, ["build"]), expect![[r#" Warning: [1002] ╭─[$ROOT/src/lib/a.mbt:3:5] @@ -6837,7 +6809,7 @@ fn test_pre_build() { ); check( - &read(&dir.join("src/lib/a.mbt")), + read(dir.join("src/lib/a.mbt")), expect![[r#" // Generated by `moon tool embed --text`, do not edit. @@ -6847,12 +6819,12 @@ fn test_pre_build() { #| "#]], ); - let content = read(&dir.join("src/lib/b.mbt")); + let content = read(dir.join("src/lib/b.mbt")); assert!(content.contains("// Generated by `moon tool embed --binary`, do not edit.")); assert!(content.contains(r#"let _b : Bytes = b"\x6d\x6f\x6f\x6e"#)); assert!(content.contains(r#"\x0a\x67\x65\x6e\x65\x72\x61\x74\x65"#)); check( - &read(&dir.join("src/lib/c.mbt")), + read(dir.join("src/lib/c.mbt")), expect![[r#" // Generated by `moon tool embed --text`, do not edit. @@ -6911,7 +6883,7 @@ fn test_bad_version() { ) .unwrap(); check( - &get_err_stderr(&dir, ["check"]), + get_err_stderr(&dir, ["check"]), expect![[r#" error: failed to load `$ROOT/moon.mod.json` @@ -6934,7 +6906,7 @@ fn test_moonfmt() { .current_dir(&dir) .output() .unwrap(); - let out = replace_crlf_to_lf(&String::from_utf8(out.stdout).unwrap()); + let out = String::from_utf8(out.stdout).unwrap().replace_crlf_to_lf(); check( &out, expect![[r#" @@ -6945,7 +6917,7 @@ fn test_moonfmt() { ); check( - &read(&dir.join("src/lib/hello.mbt")), + read(dir.join("src/lib/hello.mbt")), expect![[r#"pub fn hello() -> String { "Hello, world!" }"#]], ); @@ -6956,7 +6928,7 @@ fn test_moonfmt() { .unwrap(); let _ = String::from_utf8(out.stdout).unwrap(); check( - &read(&dir.join("src/lib/hello.mbt")), + read(dir.join("src/lib/hello.mbt")), expect![[r#" pub fn hello() -> String { "Hello, world!" @@ -6966,7 +6938,7 @@ fn test_moonfmt() { std::fs::write(dir.join("src/lib/hello.mbt"), oneline).unwrap(); check( - &read(&dir.join("src/lib/hello.mbt")), + read(dir.join("src/lib/hello.mbt")), expect![[r#"pub fn hello() -> String { "Hello, world!" }"#]], ); @@ -6977,7 +6949,7 @@ fn test_moonfmt() { .unwrap(); let _ = String::from_utf8(out.stdout).unwrap(); check( - &read(&dir.join("src/lib/hello.mbt")), + read(dir.join("src/lib/hello.mbt")), expect![[r#" pub fn hello() -> String { "Hello, world!" @@ -6985,7 +6957,7 @@ fn test_moonfmt() { "#]], ); check( - &read(&dir.join("src/lib/hello.txt")), + read(dir.join("src/lib/hello.txt")), expect![[r#" pub fn hello() -> String { "Hello, world!" diff --git a/crates/moon/tests/util.rs b/crates/moon/tests/util.rs index f2b0fdaa..f4089038 100644 --- a/crates/moon/tests/util.rs +++ b/crates/moon/tests/util.rs @@ -19,9 +19,10 @@ use std::path::{Path, PathBuf}; use expect_test::Expect; +use moonutil::common::StringExt; -pub fn check(actual: &str, expect: Expect) { - expect.assert_eq(actual) +pub fn check>(actual: S, expect: Expect) { + expect.assert_eq(actual.as_ref()) } pub fn moon_bin() -> PathBuf { @@ -73,11 +74,7 @@ pub fn copy(src: &Path, dest: &Path) -> anyhow::Result<()> { Ok(()) } -pub fn replace_crlf_to_lf(s: &str) -> String { - s.replace("\r\n", "\n") -} - #[track_caller] -pub fn read(p: &Path) -> String { - std::fs::read_to_string(p).unwrap().replace('\r', "") +pub fn read>(p: P) -> String { + std::fs::read_to_string(p).unwrap().replace_crlf_to_lf() } diff --git a/crates/moonutil/src/common.rs b/crates/moonutil/src/common.rs index 44b0b9e1..dc1dc82b 100644 --- a/crates/moonutil/src/common.rs +++ b/crates/moonutil/src/common.rs @@ -788,3 +788,13 @@ pub fn get_desc_name(package_name: &str, artifact: &str) -> String { package_name.to_string() } } + +pub trait StringExt { + fn replace_crlf_to_lf(&self) -> String; +} + +impl StringExt for str { + fn replace_crlf_to_lf(&self) -> String { + self.replace("\r\n", "\n") + } +}