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

Improve resolution error messages #3640

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft
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
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions compiler-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ globset = { version = "0", features = ["serde1"] }
xxhash-rust = { version = "0", features = ["xxh3"] }
# Pubgrub dependency resolution algorithm
pubgrub = "0"
version-ranges = "0.1.1"
# Used for converting absolute path to relative path
pathdiff = { version = "0", features = ["camino"] }
# Memory arena using ids rather than references
Expand Down
74 changes: 74 additions & 0 deletions compiler-core/src/dependency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,80 @@ mod tests {
Box::new(Remote { deps })
}

fn interesting_remote() -> Box<Remote> {
let release = |version, requirements: Vec<(&str, &str)>| Release {
version: Version::try_from(version).unwrap(),
requirements: requirements
.iter()
.map(|(name, range)| {
(
name.to_string(),
Dependency {
requirement: Range::new(range.to_string()),
optional: false,
app: None,
repository: None,
},
)
})
.collect(),
retirement_status: None,
outer_checksum: vec![1, 2, 3],
meta: (),
};

let mut deps = HashMap::new();
let _ = deps.insert(
"wibble".into(),
hexpm::Package {
name: "wibble".into(),
repository: "hexpm".into(),
releases: vec![
release("0.1.0", vec![("wobble", ">= 1.0.0")]),
release("0.2.0", vec![("wobble", ">= 2.0.0")]),
release("1.0.0", vec![("wobble", ">= 1.3.0")]),
release("1.2.0", vec![("wobble", ">= 1.2.0")]),
release("1.3.0", vec![("wobble", ">= 1.2.0")]),
],
},
);
let _ = deps.insert(
"wobble".into(),
hexpm::Package {
name: "wibble".into(),
repository: "hexpm".into(),
releases: vec![
release("1.1.0", vec![]),
release("1.5.0", vec![]),
release("2.0.0", vec![]),
],
},
);

Box::new(Remote { deps })
}

#[test]
fn resolution_error_message() {
let result = resolve_versions(
interesting_remote(),
HashMap::new(),
"app".into(),
vec![
("wibble".into(), Range::new(">= 1.0.0 and < 2.0.0".into())),
("wobble".into(), Range::new("< 1.5.0".into())),
]
.into_iter(),
&vec![].into_iter().collect(),
);

if let Err(Error::DependencyResolutionFailed(message)) = result {
insta::assert_snapshot!(message)
} else {
panic!("expected a resolution error message")
}
}

#[test]
fn resolution_with_locked() {
let locked_stdlib = ("gleam_stdlib".into(), Version::parse("0.1.0").unwrap());
Expand Down
Loading