Skip to content

Commit

Permalink
Merge pull request #508 from moonbitlang/duplicate_alias_detection_fo…
Browse files Browse the repository at this point in the history
…r_mod_level_pkg

fix: duplicate alias detection when pkg in the same level with mod
  • Loading branch information
Young-Flash authored Dec 4, 2024
2 parents f14566e + 96f36db commit e545930
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
5 changes: 2 additions & 3 deletions crates/moonbuild/src/gen/gen_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

use super::cmd_builder::CommandBuilder;
use super::n2_errors::{N2Error, N2ErrorKind};
use super::util::self_in_test_import;
use crate::gen::MiAlias;
use anyhow::bail;
use indexmap::map::IndexMap;
Expand Down Expand Up @@ -198,9 +199,7 @@ fn pkg_with_test_to_check_item(
pkg: &Package,
moonc_opt: &MooncOpt,
) -> anyhow::Result<CheckDepItem> {
let self_in_test_import = pkg.test_imports.iter().any(|import| {
import.path.make_full_path() == format!("{}/{}", pkg.root.full_name(), pkg.rel.full_name())
});
let self_in_test_import = self_in_test_import(pkg);

if !self_in_test_import
&& pkg
Expand Down
5 changes: 2 additions & 3 deletions crates/moonbuild/src/gen/gen_runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use moonutil::path::{ImportPath, PathComponent};
use petgraph::graph::NodeIndex;

use super::cmd_builder::CommandBuilder;
use super::util::self_in_test_import;
use super::{is_self_coverage_lib, is_skip_coverage_lib};
use std::collections::HashSet;
use std::path::PathBuf;
Expand Down Expand Up @@ -418,9 +419,7 @@ pub fn gen_package_blackbox_test(
moonc_opt: &MooncOpt,
patch_file: Option<PathBuf>,
) -> anyhow::Result<RuntestDepItem> {
let self_in_test_import = pkg.test_imports.iter().any(|import| {
import.path.make_full_path() == format!("{}/{}", pkg.root.full_name(), pkg.rel.full_name())
});
let self_in_test_import = self_in_test_import(pkg);

if !self_in_test_import
&& pkg
Expand Down
14 changes: 14 additions & 0 deletions crates/moonbuild/src/gen/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,17 @@ pub fn nodes_to_pkg_sources(m: &ModuleDB, nodes: &[String]) -> Vec<(String, Stri
pub fn graph_to_dot(m: &ModuleDB) {
println!("{:?}", Dot::with_config(&m.graph, &[Config::EdgeNoLabel]));
}

pub fn self_in_test_import(pkg: &Package) -> bool {
// for package in the same level of mod, like "Yoorkin/prettyprinter", pkg.rel.full_name() is_empty
// current_pkg_full_path should be "Yoorkin/prettyprinter" instead of "Yoorkin/prettyprinter/"
let current_pkg_full_path = if pkg.rel.full_name().is_empty() {
pkg.root.full_name()
} else {
format!("{}/{}", pkg.root.full_name(), pkg.rel.full_name())
};

pkg.test_imports
.iter()
.any(|import| import.path.make_full_path() == current_pkg_full_path)
}

0 comments on commit e545930

Please sign in to comment.