Skip to content

Commit

Permalink
internal: provide bbtest info to ide
Browse files Browse the repository at this point in the history
  • Loading branch information
Young-Flash committed Jul 12, 2024
1 parent 0d0eee2 commit dd6d0e3
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 9 deletions.
4 changes: 2 additions & 2 deletions crates/moon/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ impl TestDir {
Self { path: tmp_dir }
}

fn join(&self, sub: &str) -> PathBuf {
self.path.path().join(sub)
fn join(&self, sub: impl AsRef<str>) -> PathBuf {
self.path.path().join(sub.as_ref())
}
}

Expand Down
138 changes: 131 additions & 7 deletions crates/moon/tests/test_cases/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1536,13 +1536,13 @@ fn test_output_format() {
.assert()
.success();
assert!(dir
.join(&format!(
.join(format!(
"target/{}/release/build/main/main.wasm",
TargetBackend::default().to_backend_ext()
))
.exists());
assert!(!dir
.join(&format!(
.join(format!(
"target/{}/release/build/main/main.wat",
TargetBackend::default().to_backend_ext()
))
Expand All @@ -1560,13 +1560,13 @@ fn test_output_format() {
.assert()
.success();
assert!(dir
.join(&format!(
.join(format!(
"target/{}/release/build/main/main.wat",
TargetBackend::default().to_backend_ext()
))
.exists());
assert!(!dir
.join(&format!(
.join(format!(
"target/{}/release/build/main/main.wasm",
TargetBackend::default().to_backend_ext()
))
Expand All @@ -1584,13 +1584,13 @@ fn test_output_format() {
.assert()
.success();
assert!(!dir
.join(&format!(
.join(format!(
"target/{}/release/build/main/main.wat",
TargetBackend::default().to_backend_ext()
))
.exists());
assert!(dir
.join(&format!(
.join(format!(
"target/{}/release/build/main/main.wasm",
TargetBackend::default().to_backend_ext()
))
Expand Down Expand Up @@ -2052,7 +2052,7 @@ fn test_backend_config() {
let dir = TestDir::new("backend_config.in");

let _ = get_stdout_with_args(&dir, ["build", "--output-wat"]);
let out = std::fs::read_to_string(dir.join(&format!(
let out = std::fs::read_to_string(dir.join(format!(
"target/{}/release/build/lib/lib.wat",
TargetBackend::default().to_backend_ext()
)))
Expand Down Expand Up @@ -2190,8 +2190,10 @@ fn test_dummy_core() {
"$ROOT/0/y_test.wasm-gc.mbt",
"$ROOT/0/y_test.wasm.mbt"
],
"bbtest-files": [],
"deps": [],
"test-deps": [],
"bbtest-deps": [],
"artifact": "$ROOT/target/wasm-gc/release/check/0/0.mi"
},
{
Expand All @@ -2208,8 +2210,10 @@ fn test_dummy_core() {
"test-files": [
"$ROOT/1/x_test.wasm-gc.mbt"
],
"bbtest-files": [],
"deps": [],
"test-deps": [],
"bbtest-deps": [],
"artifact": "$ROOT/target/wasm-gc/release/check/1/1.mi"
},
{
Expand All @@ -2221,13 +2225,15 @@ fn test_dummy_core() {
"$ROOT/2/lib.mbt"
],
"test-files": [],
"bbtest-files": [],
"deps": [
{
"path": "moonbitlang/core/1",
"alias": "1"
}
],
"test-deps": [],
"bbtest-deps": [],
"artifact": "$ROOT/target/wasm-gc/release/check/2/2.mi"
},
{
Expand All @@ -2237,13 +2243,15 @@ fn test_dummy_core() {
"rel": "char",
"files": [],
"test-files": [],
"bbtest-files": [],
"deps": [
{
"path": "moonbitlang/core/coverage",
"alias": "coverage"
}
],
"test-deps": [],
"bbtest-deps": [],
"artifact": "$ROOT/target/wasm-gc/release/check/char/char.mi"
},
{
Expand All @@ -2253,8 +2261,10 @@ fn test_dummy_core() {
"rel": "coverage",
"files": [],
"test-files": [],
"bbtest-files": [],
"deps": [],
"test-deps": [],
"bbtest-deps": [],
"artifact": "$ROOT/target/wasm-gc/release/check/coverage/coverage.mi"
},
{
Expand All @@ -2264,6 +2274,7 @@ fn test_dummy_core() {
"rel": "iter",
"files": [],
"test-files": [],
"bbtest-files": [],
"deps": [
{
"path": "moonbitlang/core/coverage",
Expand All @@ -2276,6 +2287,7 @@ fn test_dummy_core() {
"alias": "char"
}
],
"bbtest-deps": [],
"artifact": "$ROOT/target/wasm-gc/release/check/iter/iter.mi"
}
],
Expand Down Expand Up @@ -2317,8 +2329,10 @@ fn test_dummy_core() {
"$ROOT/0/y_test.wasm-gc.mbt",
"$ROOT/0/y_test.wasm.mbt"
],
"bbtest-files": [],
"deps": [],
"test-deps": [],
"bbtest-deps": [],
"artifact": "$ROOT/target/js/release/check/0/0.mi"
},
{
Expand All @@ -2335,8 +2349,10 @@ fn test_dummy_core() {
"test-files": [
"$ROOT/1/x_test.wasm-gc.mbt"
],
"bbtest-files": [],
"deps": [],
"test-deps": [],
"bbtest-deps": [],
"artifact": "$ROOT/target/js/release/check/1/1.mi"
},
{
Expand All @@ -2348,13 +2364,15 @@ fn test_dummy_core() {
"$ROOT/2/lib.mbt"
],
"test-files": [],
"bbtest-files": [],
"deps": [
{
"path": "moonbitlang/core/1",
"alias": "1"
}
],
"test-deps": [],
"bbtest-deps": [],
"artifact": "$ROOT/target/js/release/check/2/2.mi"
},
{
Expand All @@ -2364,13 +2382,15 @@ fn test_dummy_core() {
"rel": "char",
"files": [],
"test-files": [],
"bbtest-files": [],
"deps": [
{
"path": "moonbitlang/core/coverage",
"alias": "coverage"
}
],
"test-deps": [],
"bbtest-deps": [],
"artifact": "$ROOT/target/js/release/check/char/char.mi"
},
{
Expand All @@ -2380,8 +2400,10 @@ fn test_dummy_core() {
"rel": "coverage",
"files": [],
"test-files": [],
"bbtest-files": [],
"deps": [],
"test-deps": [],
"bbtest-deps": [],
"artifact": "$ROOT/target/js/release/check/coverage/coverage.mi"
},
{
Expand All @@ -2391,6 +2413,7 @@ fn test_dummy_core() {
"rel": "iter",
"files": [],
"test-files": [],
"bbtest-files": [],
"deps": [
{
"path": "moonbitlang/core/coverage",
Expand All @@ -2403,6 +2426,7 @@ fn test_dummy_core() {
"alias": "char"
}
],
"bbtest-deps": [],
"artifact": "$ROOT/target/js/release/check/iter/iter.mi"
}
],
Expand Down Expand Up @@ -4179,6 +4203,106 @@ fn test_blackbox_success() {
moonc check ./A/hello.mbt ./A/hello_test.mbt -o ./target/wasm-gc/release/check/A/A.underscore_test.mi -pkg username/hello/A -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -i ./target/wasm-gc/release/check/B/B.mi:B -pkg-sources username/hello/A:./A -target wasm-gc
"#]],
);

snapbox::cmd::Command::new(moon_bin())
.current_dir(&dir)
.args(["check", "--sort-input"])
.assert()
.success();

#[cfg(unix)]
{
let p = dir.join(format!(
"target/{}/release/check/packages.json",
TargetBackend::default().to_backend_ext()
));
check(
&replace_dir(&std::fs::read_to_string(p).unwrap(), &dir),
expect![[r#"
{
"source_dir": "$ROOT",
"name": "username/hello",
"packages": [
{
"is-main": false,
"is-third-party": false,
"root": "username/hello",
"rel": "A",
"files": [
"$ROOT/A/hello.mbt"
],
"test-files": [
"$ROOT/A/hello_test.mbt"
],
"bbtest-files": [
"$ROOT/A/hello_bbtest.mbt"
],
"deps": [],
"test-deps": [
{
"path": "username/hello/B",
"alias": "B"
}
],
"bbtest-deps": [
{
"path": "username/hello/C",
"alias": "C"
}
],
"artifact": "$ROOT/target/wasm-gc/release/check/A/A.mi"
},
{
"is-main": false,
"is-third-party": false,
"root": "username/hello",
"rel": "B",
"files": [
"$ROOT/B/hello.mbt"
],
"test-files": [],
"bbtest-files": [],
"deps": [],
"test-deps": [],
"bbtest-deps": [],
"artifact": "$ROOT/target/wasm-gc/release/check/B/B.mi"
},
{
"is-main": false,
"is-third-party": false,
"root": "username/hello",
"rel": "C",
"files": [
"$ROOT/C/hello.mbt"
],
"test-files": [],
"bbtest-files": [],
"deps": [],
"test-deps": [],
"bbtest-deps": [],
"artifact": "$ROOT/target/wasm-gc/release/check/C/C.mi"
},
{
"is-main": true,
"is-third-party": false,
"root": "username/hello",
"rel": "main",
"files": [
"$ROOT/main/main.mbt"
],
"test-files": [],
"bbtest-files": [],
"deps": [],
"test-deps": [],
"bbtest-deps": [],
"artifact": "$ROOT/target/wasm-gc/release/check/main/main.mi"
}
],
"deps": [],
"backend": "wasm-gc"
}"#]],
);
}
}

#[test]
Expand Down
25 changes: 25 additions & 0 deletions crates/moonutil/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@ pub fn convert_mdb_to_json(module: &ModuleDB) -> ModuleDBJSON {
.iter()
.map(|f| f.display().to_string())
.collect();
let bbtest_files = pkg
.bbtest_files
.iter()
.map(|f| f.display().to_string())
.collect();
let mut deps = vec![];
for dep in &pkg.imports {
let alias = match &dep.alias {
Expand Down Expand Up @@ -223,15 +228,35 @@ pub fn convert_mdb_to_json(module: &ModuleDB) -> ModuleDBJSON {
});
}

let mut bbtest_deps = vec![];
for dep in &pkg.bbtest_imports {
let alias = match &dep.alias {
None => {
let alias = dep.path.rel_path.components.last();
match alias {
None => dep.path.module_name.split('/').last().unwrap().to_string(),
Some(x) => x.to_string(),
}
}
Some(x) => x.to_string(),
};
bbtest_deps.push(AliasJSON {
path: dep.path.make_full_path(),
alias,
});
}

pkgs.push(PackageJSON {
is_main: pkg.is_main,
is_third_party: pkg.is_third_party,
root: pkg.root.full_name(),
rel: pkg.rel.full_name(),
files,
test_files,
bbtest_files,
deps,
test_deps,
bbtest_deps,
artifact: pkg
.artifact
.with_extension("mi")
Expand Down
2 changes: 2 additions & 0 deletions crates/moonutil/src/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@ pub struct PackageJSON {
pub rel: String,
pub files: Vec<String>,
pub test_files: Vec<String>,
pub bbtest_files: Vec<String>,
pub deps: Vec<AliasJSON>,
pub test_deps: Vec<AliasJSON>,
pub bbtest_deps: Vec<AliasJSON>,
pub artifact: String,
}

Expand Down

0 comments on commit dd6d0e3

Please sign in to comment.