Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ModuleDB reporting wrong path when transient dependency cannot find the correct import #564

Merged
merged 3 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions crates/moon/tests/test_cases/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4406,6 +4406,19 @@ fn test_internal_package() {
);
}

#[test]
fn test_nonexistent_package() {
let dir = TestDir::new("nonexistent_package.in");
check(
get_err_stderr(&dir, ["check", "--sort-input"]),
expect![[r#"
error: $ROOT/main/moon.pkg.json: cannot import `username/hello/lib/b` in `username/hello/main`, no such package
$ROOT/main/moon.pkg.json: cannot import `username/hello/transient` in `username/hello/main`, no such package
$ROOT/pkg/transient/moon.pkg.json: cannot import `username/transient/lib/b` in `username/transient`, no such package
"#]],
);
}

#[test]
fn mooncakes_io_smoke_test() {
if std::env::var("CI").is_err() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
target/
.mooncakes/
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# username/hello
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub fn hello() -> String {
"Hello, world!"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
test "hello" {
if hello() != "Hello, world!" {
return Err("hello() != \"Hello, world!\"")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"import": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main {
println(@lib.hello())
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"is-main": true,
"import": ["username/hello/lib", "username/hello/lib/b", "username/hello/transient"]
}
10 changes: 10 additions & 0 deletions crates/moon/tests/test_cases/nonexistent_package.in/moon.mod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "username/hello",
"version": "0.1.0",
"deps": { "username/transient": { "path": "pkg/transient" } },
"readme": "README.md",
"repository": "",
"license": "",
"keywords": [],
"description": ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub fn hello() -> String {
"Hello, world!"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
test "hello" {
if hello() != "Hello, world!" {
return Err("hello() != \"Hello, world!\"")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"import": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "username/transient",
"version": "0.1.0",
"deps": {},
"readme": "README.md",
"repository": "",
"license": "",
"keywords": [],
"description": ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"import": ["username/transient/lib/b"]
}
12 changes: 2 additions & 10 deletions crates/moonutil/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,23 +353,15 @@ impl ModuleDB {
if !pkg.full_components().can_import(&item.full_components()) {
errors.push(format!(
"{}: cannot import internal package `{}` in `{}`",
self.source_dir
.join(self.source.as_ref().unwrap_or(&String::new()))
.join(pkg.rel.fs_full_name())
.join(MOON_PKG_JSON)
.display(),
pkg.root_path.join(MOON_PKG_JSON).display(),
imported,
pkg.full_name()
))
}
if !self.packages.contains_key(&imported) {
errors.push(format!(
"{}: cannot import `{}` in `{}`, no such package",
self.source_dir
.join(self.source.as_ref().unwrap_or(&String::new()))
.join(pkg.rel.fs_full_name())
.join(MOON_PKG_JSON)
.display(),
pkg.root_path.join(MOON_PKG_JSON).display(),
imported,
pkg.full_name(),
));
Expand Down
Loading