Skip to content

Commit

Permalink
Allow (but ignore) micro part of LLVM version (fixes #37)
Browse files Browse the repository at this point in the history
  • Loading branch information
djc committed Jan 18, 2021
1 parent a4bbdaf commit 62b3cf9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
5 changes: 5 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ pub struct LlvmVersion {
pub major: u64,
/// Minor version
pub minor: u64,
// TODO: expose micro version here
}

impl fmt::Display for LlvmVersion {
Expand Down Expand Up @@ -135,6 +136,10 @@ impl FromStr for LlvmVersion {
return Err(LlvmVersionParseError::MinorVersionRequiredBefore4);
}

if let Some(Err(e)) = parts.next() {
return Err(e.into());
}

if parts.next().is_some() {
return Err(LlvmVersionParseError::TooManyComponents);
}
Expand Down
40 changes: 30 additions & 10 deletions tests/all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,36 @@ LLVM version: 11.0",
);
}

#[test]
fn parse_llvm_micro() {
let version = version_meta_for(
"rustc 1.51.0-nightly (4253153db 2021-01-17)
binary: rustc
commit-hash: 4253153db205251f72ea4493687a31e04a2a8ca0
commit-date: 2021-01-17
host: x86_64-pc-windows-msvc
release: 1.51.0-nightly
LLVM version: 11.0.1",
)
.unwrap();

assert_eq!(version.semver, Version::parse("1.51.0-nightly").unwrap());
assert_eq!(
version.commit_hash.as_deref(),
Some("4253153db205251f72ea4493687a31e04a2a8ca0")
);
assert_eq!(version.commit_date.as_deref(), Some("2021-01-17"));
assert_eq!(version.host, "x86_64-pc-windows-msvc");
assert_eq!(version.short_version_string, "rustc 1.51.0-nightly (4253153db 2021-01-17)");
assert_eq!(
version.llvm_version,
Some(LlvmVersion {
major: 11,
minor: 0
})
);
}

#[test]
fn parse_debian_buster() {
let version = version_meta_for(
Expand Down Expand Up @@ -296,16 +326,6 @@ fn parse_llvm_version_leading_zero_on_nonzero() {
});
}

#[test]
fn parse_llvm_version_3_components() {
let res: Result<LlvmVersion, _> = "4.0.0".parse();

assert!(match res {
Err(LlvmVersionParseError::TooManyComponents) => true,
_ => false,
});
}

#[test]
fn parse_llvm_version_4_components() {
let res: Result<LlvmVersion, _> = "4.0.0.0".parse();
Expand Down

0 comments on commit 62b3cf9

Please sign in to comment.