From e74ba7103aae9bad8445532016c86f55e3496142 Mon Sep 17 00:00:00 2001 From: Rynco Maekawa Date: Wed, 23 Oct 2024 10:59:34 +0800 Subject: [PATCH 1/4] Auto add coverage when needed --- crates/moon/src/cli/test.rs | 6 ++- crates/moonbuild/src/gen/gen_runtest.rs | 50 ++++++++++++++++++++++++- crates/moonutil/src/common.rs | 1 + 3 files changed, 55 insertions(+), 2 deletions(-) diff --git a/crates/moon/src/cli/test.rs b/crates/moon/src/cli/test.rs index 84662546..b4a1b25d 100644 --- a/crates/moon/src/cli/test.rs +++ b/crates/moon/src/cli/test.rs @@ -348,7 +348,7 @@ fn do_run_test( moonbuild_opt: MoonbuildOpt, build_only: bool, auto_update: bool, - module: ModuleDB, + mut module: ModuleDB, verbose: bool, ) -> anyhow::Result { let backend_hint = moonbuild_opt @@ -358,6 +358,10 @@ fn do_run_test( .map(|_| format!(" [{}]", moonc_opt.build_opt.target_backend.to_backend_ext())) .unwrap_or_default(); + // Preprocess module db: add coverage libs if needed + moonbuild::gen::gen_runtest::moduledb_test_pp(&mut module, &moonc_opt)?; + let module = module; + let test_res = entry::run_test( moonc_opt, moonbuild_opt, diff --git a/crates/moonbuild/src/gen/gen_runtest.rs b/crates/moonbuild/src/gen/gen_runtest.rs index 97f63061..05cef83f 100644 --- a/crates/moonbuild/src/gen/gen_runtest.rs +++ b/crates/moonbuild/src/gen/gen_runtest.rs @@ -19,11 +19,16 @@ use anyhow::{bail, Ok}; use colored::Colorize; use indexmap::IndexMap; -use moonutil::common::{get_desc_name, DriverKind, GeneratedTestDriver, MOONBITLANG_CORE}; +use moonutil::common::{ + get_desc_name, DriverKind, GeneratedTestDriver, MOONBITLANG_CORE, MOONBITLANG_COVERAGE, +}; use moonutil::module::ModuleDB; use moonutil::package::Package; +use moonutil::path::{ImportPath, PathComponent}; +use petgraph::graph::NodeIndex; use super::cmd_builder::CommandBuilder; +use super::{is_self_coverage_lib, is_skip_coverage_lib}; use std::collections::HashSet; use std::path::PathBuf; use std::rc::Rc; @@ -68,6 +73,49 @@ pub struct N2RuntestInput { pub test_drivers: Vec, } +/// Preprocess module db for test. Mainly for adding coverage library reference to each package. +pub fn moduledb_test_pp(mdb: &mut ModuleDB, moonc_opt: &MooncOpt) -> anyhow::Result<()> { + if moonc_opt.build_opt.enable_coverage { + // Only core module needs to add coverage library + if mdb.name == MOONBITLANG_CORE { + // Add coverage library reference to each package + for (pkg_name, pkg) in mdb.get_all_packages_mut() { + if is_self_coverage_lib(pkg_name) || is_skip_coverage_lib(pkg_name) { + continue; + } + pkg.imports.push(moonutil::path::ImportComponent { + path: ImportPath { + module_name: MOONBITLANG_CORE.into(), + rel_path: PathComponent { + components: vec!["coverage".into()], + }, + is_3rd: false, + }, + alias: None, + }); + } + + // Update dependency graph + let coverage_lib_node = mdb + .get_all_packages() + .get_index_of(MOONBITLANG_COVERAGE) + .unwrap(); + let coverage_lib_node = NodeIndex::new(coverage_lib_node); + let node_cnt = mdb.graph.node_count(); + for i in 0..node_cnt { + let node_ix = NodeIndex::new(i); + let node = mdb.graph.node_weight(node_ix).unwrap(); + if is_self_coverage_lib(node) || is_skip_coverage_lib(node) { + continue; + } + mdb.graph.add_edge(node_ix, coverage_lib_node, 0); + } + } + } + + Ok(()) +} + pub fn gen_package_test_driver( g: &GeneratedTestDriver, pkg: &Package, diff --git a/crates/moonutil/src/common.rs b/crates/moonutil/src/common.rs index 55bc073b..be58474b 100644 --- a/crates/moonutil/src/common.rs +++ b/crates/moonutil/src/common.rs @@ -36,6 +36,7 @@ pub const MOON_MOD_JSON: &str = "moon.mod.json"; pub const MOON_PKG_JSON: &str = "moon.pkg.json"; pub const MOON_PID_NAME: &str = ".moon.pid"; pub const MOONBITLANG_CORE: &str = "moonbitlang/core"; +pub const MOONBITLANG_COVERAGE: &str = "moonbitlang/core/coverage"; pub const MOON_TEST_DELIMITER_BEGIN: &str = "----- BEGIN MOON TEST RESULT -----"; pub const MOON_TEST_DELIMITER_END: &str = "----- END MOON TEST RESULT -----"; From cb48c66e779ea10f69570d59bc46d4317e8106aa Mon Sep 17 00:00:00 2001 From: Rynco Maekawa Date: Thu, 24 Oct 2024 14:12:49 +0800 Subject: [PATCH 2/4] Move auto add coverage processing outwards to cover dry-run --- crates/moon/src/cli/test.rs | 10 +++++----- crates/moonbuild/src/gen/gen_runtest.rs | 10 ++++++++-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/crates/moon/src/cli/test.rs b/crates/moon/src/cli/test.rs index b4a1b25d..4f090970 100644 --- a/crates/moon/src/cli/test.rs +++ b/crates/moon/src/cli/test.rs @@ -323,6 +323,10 @@ fn run_test_internal( .iter() .map(|(name, pkg)| (name.clone(), pkg.alert_list.clone())) .collect(); + + // add coverage libs if needed + moonbuild::gen::gen_runtest::add_coverage_to_core_if_needed(&mut module, &moonc_opt)?; + if cli.dry_run { return dry_run::print_commands(&module, &moonc_opt, &moonbuild_opt).map(From::from); } @@ -348,7 +352,7 @@ fn do_run_test( moonbuild_opt: MoonbuildOpt, build_only: bool, auto_update: bool, - mut module: ModuleDB, + module: ModuleDB, verbose: bool, ) -> anyhow::Result { let backend_hint = moonbuild_opt @@ -358,10 +362,6 @@ fn do_run_test( .map(|_| format!(" [{}]", moonc_opt.build_opt.target_backend.to_backend_ext())) .unwrap_or_default(); - // Preprocess module db: add coverage libs if needed - moonbuild::gen::gen_runtest::moduledb_test_pp(&mut module, &moonc_opt)?; - let module = module; - let test_res = entry::run_test( moonc_opt, moonbuild_opt, diff --git a/crates/moonbuild/src/gen/gen_runtest.rs b/crates/moonbuild/src/gen/gen_runtest.rs index 05cef83f..81166ffb 100644 --- a/crates/moonbuild/src/gen/gen_runtest.rs +++ b/crates/moonbuild/src/gen/gen_runtest.rs @@ -19,6 +19,7 @@ use anyhow::{bail, Ok}; use colored::Colorize; use indexmap::IndexMap; +use log::info; use moonutil::common::{ get_desc_name, DriverKind, GeneratedTestDriver, MOONBITLANG_CORE, MOONBITLANG_COVERAGE, }; @@ -73,11 +74,16 @@ pub struct N2RuntestInput { pub test_drivers: Vec, } -/// Preprocess module db for test. Mainly for adding coverage library reference to each package. -pub fn moduledb_test_pp(mdb: &mut ModuleDB, moonc_opt: &MooncOpt) -> anyhow::Result<()> { +/// Automatically add coverage library import to core module if needed +pub fn add_coverage_to_core_if_needed( + mdb: &mut ModuleDB, + moonc_opt: &MooncOpt, +) -> anyhow::Result<()> { if moonc_opt.build_opt.enable_coverage { // Only core module needs to add coverage library if mdb.name == MOONBITLANG_CORE { + info!("Automatically adding coverage library to other packages in the core module"); + // Add coverage library reference to each package for (pkg_name, pkg) in mdb.get_all_packages_mut() { if is_self_coverage_lib(pkg_name) || is_skip_coverage_lib(pkg_name) { From 9c678c9ab3b741598bb356885f488b6462c1d7a0 Mon Sep 17 00:00:00 2001 From: Rynco Maekawa Date: Thu, 24 Oct 2024 14:14:24 +0800 Subject: [PATCH 3/4] Update test results This PR should _only_ affect core module and nothing else, and only add coverage input to `test --enable-coverage` command. --- crates/moon/tests/test_cases/mod.rs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/crates/moon/tests/test_cases/mod.rs b/crates/moon/tests/test_cases/mod.rs index 9fa38cee..1c351511 100644 --- a/crates/moon/tests/test_cases/mod.rs +++ b/crates/moon/tests/test_cases/mod.rs @@ -3198,30 +3198,30 @@ fn test_dummy_core() { expect![[r#" moon generate-test-driver --source-dir . --target-dir ./target --package moonbitlang/core/iter --sort-input --target wasm-gc --driver-kind internal --enable-coverage 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 -enable-coverage -coverage-package-override=@self - moonc build-package ./target/wasm-gc/debug/test/iter/__generated_driver_for_internal_test.mbt -o ./target/wasm-gc/debug/test/iter/iter.internal_test.core -pkg moonbitlang/core/iter -is-main -i ./target/wasm-gc/debug/test/coverage/coverage.mi:coverage -pkg-sources moonbitlang/core/iter:./iter -target wasm-gc -g -enable-coverage + moonc build-package ./target/wasm-gc/debug/test/iter/__generated_driver_for_internal_test.mbt -o ./target/wasm-gc/debug/test/iter/iter.internal_test.core -pkg moonbitlang/core/iter -is-main -i ./target/wasm-gc/debug/test/coverage/coverage.mi:coverage -i ./target/wasm-gc/debug/test/coverage/coverage.mi:coverage -pkg-sources moonbitlang/core/iter:./iter -target wasm-gc -g -enable-coverage moonc link-core ./target/wasm-gc/debug/test/coverage/coverage.core ./target/wasm-gc/debug/test/iter/iter.internal_test.core -main moonbitlang/core/iter -o ./target/wasm-gc/debug/test/iter/iter.internal_test.wasm -test-mode -pkg-config-path ./iter/moon.pkg.json -pkg-sources moonbitlang/core/coverage:./coverage -pkg-sources moonbitlang/core/iter:./iter -exported_functions moonbit_test_driver_internal_execute,moonbit_test_driver_finish -target wasm-gc -g moon generate-test-driver --source-dir . --target-dir ./target --package moonbitlang/core/coverage --sort-input --target wasm-gc --driver-kind internal --enable-coverage --coverage-package-override=@self moonc build-package ./target/wasm-gc/debug/test/coverage/__generated_driver_for_internal_test.mbt -o ./target/wasm-gc/debug/test/coverage/coverage.internal_test.core -pkg moonbitlang/core/coverage -is-main -pkg-sources moonbitlang/core/coverage:./coverage -target wasm-gc -g -enable-coverage -coverage-package-override=@self moonc link-core ./target/wasm-gc/debug/test/coverage/coverage.internal_test.core -main moonbitlang/core/coverage -o ./target/wasm-gc/debug/test/coverage/coverage.internal_test.wasm -test-mode -pkg-config-path ./coverage/moon.pkg.json -pkg-sources moonbitlang/core/coverage:./coverage -exported_functions moonbit_test_driver_internal_execute,moonbit_test_driver_finish -target wasm-gc -g moon generate-test-driver --source-dir . --target-dir ./target --package moonbitlang/core/char --sort-input --target wasm-gc --driver-kind internal --enable-coverage - moonc build-package ./target/wasm-gc/debug/test/char/__generated_driver_for_internal_test.mbt -o ./target/wasm-gc/debug/test/char/char.internal_test.core -pkg moonbitlang/core/char -is-main -i ./target/wasm-gc/debug/test/coverage/coverage.mi:coverage -pkg-sources moonbitlang/core/char:./char -target wasm-gc -g -enable-coverage + moonc build-package ./target/wasm-gc/debug/test/char/__generated_driver_for_internal_test.mbt -o ./target/wasm-gc/debug/test/char/char.internal_test.core -pkg moonbitlang/core/char -is-main -i ./target/wasm-gc/debug/test/coverage/coverage.mi:coverage -i ./target/wasm-gc/debug/test/coverage/coverage.mi:coverage -pkg-sources moonbitlang/core/char:./char -target wasm-gc -g -enable-coverage moonc link-core ./target/wasm-gc/debug/test/coverage/coverage.core ./target/wasm-gc/debug/test/char/char.internal_test.core -main moonbitlang/core/char -o ./target/wasm-gc/debug/test/char/char.internal_test.wasm -test-mode -pkg-config-path ./char/moon.pkg.json -pkg-sources moonbitlang/core/coverage:./coverage -pkg-sources moonbitlang/core/char:./char -exported_functions moonbit_test_driver_internal_execute,moonbit_test_driver_finish -target wasm-gc -g moon generate-test-driver --source-dir . --target-dir ./target --package moonbitlang/core/2 --sort-input --target wasm-gc --driver-kind internal --enable-coverage - moonc build-package ./1/lib.mbt ./1/x.wasm-gc.mbt -o ./target/wasm-gc/debug/test/1/1.core -pkg moonbitlang/core/1 -pkg-sources moonbitlang/core/1:./1 -target wasm-gc -g -enable-coverage - moonc build-package ./2/lib.mbt ./target/wasm-gc/debug/test/2/__generated_driver_for_internal_test.mbt -o ./target/wasm-gc/debug/test/2/2.internal_test.core -pkg moonbitlang/core/2 -is-main -i ./target/wasm-gc/debug/test/1/1.mi:1 -pkg-sources moonbitlang/core/2:./2 -target wasm-gc -g -enable-coverage - moonc link-core ./target/wasm-gc/debug/test/1/1.core ./target/wasm-gc/debug/test/2/2.internal_test.core -main moonbitlang/core/2 -o ./target/wasm-gc/debug/test/2/2.internal_test.wasm -test-mode -pkg-config-path ./2/moon.pkg.json -pkg-sources moonbitlang/core/1:./1 -pkg-sources moonbitlang/core/2:./2 -exported_functions moonbit_test_driver_internal_execute,moonbit_test_driver_finish -target wasm-gc -g + moonc build-package ./1/lib.mbt ./1/x.wasm-gc.mbt -o ./target/wasm-gc/debug/test/1/1.core -pkg moonbitlang/core/1 -i ./target/wasm-gc/debug/test/coverage/coverage.mi:coverage -pkg-sources moonbitlang/core/1:./1 -target wasm-gc -g -enable-coverage + moonc build-package ./2/lib.mbt ./target/wasm-gc/debug/test/2/__generated_driver_for_internal_test.mbt -o ./target/wasm-gc/debug/test/2/2.internal_test.core -pkg moonbitlang/core/2 -is-main -i ./target/wasm-gc/debug/test/1/1.mi:1 -i ./target/wasm-gc/debug/test/coverage/coverage.mi:coverage -pkg-sources moonbitlang/core/2:./2 -target wasm-gc -g -enable-coverage + moonc link-core ./target/wasm-gc/debug/test/coverage/coverage.core ./target/wasm-gc/debug/test/1/1.core ./target/wasm-gc/debug/test/2/2.internal_test.core -main moonbitlang/core/2 -o ./target/wasm-gc/debug/test/2/2.internal_test.wasm -test-mode -pkg-config-path ./2/moon.pkg.json -pkg-sources moonbitlang/core/coverage:./coverage -pkg-sources moonbitlang/core/1:./1 -pkg-sources moonbitlang/core/2:./2 -exported_functions moonbit_test_driver_internal_execute,moonbit_test_driver_finish -target wasm-gc -g moon generate-test-driver --source-dir . --target-dir ./target --package moonbitlang/core/1 --sort-input --target wasm-gc --driver-kind whitebox --enable-coverage - moonc build-package ./1/lib.mbt ./1/x.wasm-gc.mbt ./1/x_wbtest.wasm-gc.mbt ./target/wasm-gc/debug/test/1/__generated_driver_for_whitebox_test.mbt -o ./target/wasm-gc/debug/test/1/1.whitebox_test.core -pkg moonbitlang/core/1 -is-main -pkg-sources moonbitlang/core/1:./1 -target wasm-gc -g -enable-coverage -whitebox-test - moonc link-core ./target/wasm-gc/debug/test/1/1.whitebox_test.core -main moonbitlang/core/1 -o ./target/wasm-gc/debug/test/1/1.whitebox_test.wasm -test-mode -pkg-config-path ./1/moon.pkg.json -pkg-sources moonbitlang/core/1:./1 -exported_functions moonbit_test_driver_internal_execute,moonbit_test_driver_finish -target wasm-gc -g + moonc build-package ./1/lib.mbt ./1/x.wasm-gc.mbt ./1/x_wbtest.wasm-gc.mbt ./target/wasm-gc/debug/test/1/__generated_driver_for_whitebox_test.mbt -o ./target/wasm-gc/debug/test/1/1.whitebox_test.core -pkg moonbitlang/core/1 -is-main -i ./target/wasm-gc/debug/test/coverage/coverage.mi:coverage -pkg-sources moonbitlang/core/1:./1 -target wasm-gc -g -enable-coverage -whitebox-test + moonc link-core ./target/wasm-gc/debug/test/coverage/coverage.core ./target/wasm-gc/debug/test/1/1.whitebox_test.core -main moonbitlang/core/1 -o ./target/wasm-gc/debug/test/1/1.whitebox_test.wasm -test-mode -pkg-config-path ./1/moon.pkg.json -pkg-sources moonbitlang/core/coverage:./coverage -pkg-sources moonbitlang/core/1:./1 -exported_functions moonbit_test_driver_internal_execute,moonbit_test_driver_finish -target wasm-gc -g moon generate-test-driver --source-dir . --target-dir ./target --package moonbitlang/core/1 --sort-input --target wasm-gc --driver-kind internal --enable-coverage - moonc build-package ./1/lib.mbt ./1/x.wasm-gc.mbt ./target/wasm-gc/debug/test/1/__generated_driver_for_internal_test.mbt -o ./target/wasm-gc/debug/test/1/1.internal_test.core -pkg moonbitlang/core/1 -is-main -pkg-sources moonbitlang/core/1:./1 -target wasm-gc -g -enable-coverage - moonc link-core ./target/wasm-gc/debug/test/1/1.internal_test.core -main moonbitlang/core/1 -o ./target/wasm-gc/debug/test/1/1.internal_test.wasm -test-mode -pkg-config-path ./1/moon.pkg.json -pkg-sources moonbitlang/core/1:./1 -exported_functions moonbit_test_driver_internal_execute,moonbit_test_driver_finish -target wasm-gc -g + moonc build-package ./1/lib.mbt ./1/x.wasm-gc.mbt ./target/wasm-gc/debug/test/1/__generated_driver_for_internal_test.mbt -o ./target/wasm-gc/debug/test/1/1.internal_test.core -pkg moonbitlang/core/1 -is-main -i ./target/wasm-gc/debug/test/coverage/coverage.mi:coverage -pkg-sources moonbitlang/core/1:./1 -target wasm-gc -g -enable-coverage + moonc link-core ./target/wasm-gc/debug/test/coverage/coverage.core ./target/wasm-gc/debug/test/1/1.internal_test.core -main moonbitlang/core/1 -o ./target/wasm-gc/debug/test/1/1.internal_test.wasm -test-mode -pkg-config-path ./1/moon.pkg.json -pkg-sources moonbitlang/core/coverage:./coverage -pkg-sources moonbitlang/core/1:./1 -exported_functions moonbit_test_driver_internal_execute,moonbit_test_driver_finish -target wasm-gc -g moon generate-test-driver --source-dir . --target-dir ./target --package moonbitlang/core/0 --sort-input --target wasm-gc --driver-kind whitebox --enable-coverage - moonc build-package ./0/lib.mbt ./0/y.wasm-gc.mbt ./0/y_wbtest.mbt ./0/y_wbtest.wasm-gc.mbt ./target/wasm-gc/debug/test/0/__generated_driver_for_whitebox_test.mbt -o ./target/wasm-gc/debug/test/0/0.whitebox_test.core -pkg moonbitlang/core/0 -is-main -pkg-sources moonbitlang/core/0:./0 -target wasm-gc -g -enable-coverage -whitebox-test - moonc link-core ./target/wasm-gc/debug/test/0/0.whitebox_test.core -main moonbitlang/core/0 -o ./target/wasm-gc/debug/test/0/0.whitebox_test.wasm -test-mode -pkg-config-path ./0/moon.pkg.json -pkg-sources moonbitlang/core/0:./0 -exported_functions moonbit_test_driver_internal_execute,moonbit_test_driver_finish -target wasm-gc -g + moonc build-package ./0/lib.mbt ./0/y.wasm-gc.mbt ./0/y_wbtest.mbt ./0/y_wbtest.wasm-gc.mbt ./target/wasm-gc/debug/test/0/__generated_driver_for_whitebox_test.mbt -o ./target/wasm-gc/debug/test/0/0.whitebox_test.core -pkg moonbitlang/core/0 -is-main -i ./target/wasm-gc/debug/test/coverage/coverage.mi:coverage -pkg-sources moonbitlang/core/0:./0 -target wasm-gc -g -enable-coverage -whitebox-test + moonc link-core ./target/wasm-gc/debug/test/coverage/coverage.core ./target/wasm-gc/debug/test/0/0.whitebox_test.core -main moonbitlang/core/0 -o ./target/wasm-gc/debug/test/0/0.whitebox_test.wasm -test-mode -pkg-config-path ./0/moon.pkg.json -pkg-sources moonbitlang/core/coverage:./coverage -pkg-sources moonbitlang/core/0:./0 -exported_functions moonbit_test_driver_internal_execute,moonbit_test_driver_finish -target wasm-gc -g moon generate-test-driver --source-dir . --target-dir ./target --package moonbitlang/core/0 --sort-input --target wasm-gc --driver-kind internal --enable-coverage - moonc build-package ./0/lib.mbt ./0/y.wasm-gc.mbt ./target/wasm-gc/debug/test/0/__generated_driver_for_internal_test.mbt -o ./target/wasm-gc/debug/test/0/0.internal_test.core -pkg moonbitlang/core/0 -is-main -pkg-sources moonbitlang/core/0:./0 -target wasm-gc -g -enable-coverage - moonc link-core ./target/wasm-gc/debug/test/0/0.internal_test.core -main moonbitlang/core/0 -o ./target/wasm-gc/debug/test/0/0.internal_test.wasm -test-mode -pkg-config-path ./0/moon.pkg.json -pkg-sources moonbitlang/core/0:./0 -exported_functions moonbit_test_driver_internal_execute,moonbit_test_driver_finish -target wasm-gc -g + moonc build-package ./0/lib.mbt ./0/y.wasm-gc.mbt ./target/wasm-gc/debug/test/0/__generated_driver_for_internal_test.mbt -o ./target/wasm-gc/debug/test/0/0.internal_test.core -pkg moonbitlang/core/0 -is-main -i ./target/wasm-gc/debug/test/coverage/coverage.mi:coverage -pkg-sources moonbitlang/core/0:./0 -target wasm-gc -g -enable-coverage + moonc link-core ./target/wasm-gc/debug/test/coverage/coverage.core ./target/wasm-gc/debug/test/0/0.internal_test.core -main moonbitlang/core/0 -o ./target/wasm-gc/debug/test/0/0.internal_test.wasm -test-mode -pkg-config-path ./0/moon.pkg.json -pkg-sources moonbitlang/core/coverage:./coverage -pkg-sources moonbitlang/core/0:./0 -exported_functions moonbit_test_driver_internal_execute,moonbit_test_driver_finish -target wasm-gc -g "#]], ); check( From 73db67a37cdcdb9a1febabff0518f469d2be8163 Mon Sep 17 00:00:00 2001 From: Rynco Maekawa Date: Mon, 4 Nov 2024 17:05:36 +0800 Subject: [PATCH 4/4] Warn on coverage library not found for core add coverage operations --- crates/moonbuild/src/gen/gen_runtest.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crates/moonbuild/src/gen/gen_runtest.rs b/crates/moonbuild/src/gen/gen_runtest.rs index 81166ffb..6afd2856 100644 --- a/crates/moonbuild/src/gen/gen_runtest.rs +++ b/crates/moonbuild/src/gen/gen_runtest.rs @@ -84,6 +84,12 @@ pub fn add_coverage_to_core_if_needed( if mdb.name == MOONBITLANG_CORE { info!("Automatically adding coverage library to other packages in the core module"); + // Check if the coverage library is available + if !mdb.contains_package(MOONBITLANG_COVERAGE) { + log::warn!("Coverage library is not available in core module. Skipping relevant operations."); + return Ok(()); + } + // Add coverage library reference to each package for (pkg_name, pkg) in mdb.get_all_packages_mut() { if is_self_coverage_lib(pkg_name) || is_skip_coverage_lib(pkg_name) {