mirror of
https://github.com/deps-rs/deps.rs.git
synced 2024-11-22 02:16:30 +00:00
skip pre-releases when determining latest release
This commit is contained in:
parent
281be47b20
commit
f4fa88e204
2 changed files with 91 additions and 8 deletions
|
@ -23,12 +23,14 @@ impl DependencyAnalyzer {
|
||||||
dep.latest_that_matches = Some(ver.clone());
|
dep.latest_that_matches = Some(ver.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some(ref mut current_latest) = dep.latest {
|
if !ver.is_prerelease() {
|
||||||
if *current_latest < *ver {
|
if let Some(ref mut current_latest) = dep.latest {
|
||||||
*current_latest = ver.clone();
|
if *current_latest < *ver {
|
||||||
|
*current_latest = ver.clone();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
dep.latest = Some(ver.clone());
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
dep.latest = Some(ver.clone());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,3 +52,77 @@ impl DependencyAnalyzer {
|
||||||
self.deps
|
self.deps
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::{CrateDeps, CrateRelease, DependencyAnalyzer};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn tracks_latest_without_matching() {
|
||||||
|
let mut deps = CrateDeps::default();
|
||||||
|
deps.main.insert("hyper".parse().unwrap(), "^0.11.0".parse().unwrap());
|
||||||
|
|
||||||
|
let mut analyzer = DependencyAnalyzer::new(&deps);
|
||||||
|
analyzer.process(vec![
|
||||||
|
CrateRelease { name: "hyper".parse().unwrap(), version: "0.10.0".parse().unwrap(), yanked: false },
|
||||||
|
CrateRelease { name: "hyper".parse().unwrap(), version: "0.10.1".parse().unwrap(), yanked: false }
|
||||||
|
]);
|
||||||
|
|
||||||
|
let analyzed = analyzer.finalize();
|
||||||
|
|
||||||
|
assert_eq!(analyzed.main.get("hyper").unwrap().latest_that_matches, None);
|
||||||
|
assert_eq!(analyzed.main.get("hyper").unwrap().latest, Some("0.10.1".parse().unwrap()));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn tracks_latest_that_matches() {
|
||||||
|
let mut deps = CrateDeps::default();
|
||||||
|
deps.main.insert("hyper".parse().unwrap(), "^0.10.0".parse().unwrap());
|
||||||
|
|
||||||
|
let mut analyzer = DependencyAnalyzer::new(&deps);
|
||||||
|
analyzer.process(vec![
|
||||||
|
CrateRelease { name: "hyper".parse().unwrap(), version: "0.10.0".parse().unwrap(), yanked: false },
|
||||||
|
CrateRelease { name: "hyper".parse().unwrap(), version: "0.10.1".parse().unwrap(), yanked: false },
|
||||||
|
CrateRelease { name: "hyper".parse().unwrap(), version: "0.11.0".parse().unwrap(), yanked: false }
|
||||||
|
]);
|
||||||
|
|
||||||
|
let analyzed = analyzer.finalize();
|
||||||
|
|
||||||
|
assert_eq!(analyzed.main.get("hyper").unwrap().latest_that_matches, Some("0.10.1".parse().unwrap()));
|
||||||
|
assert_eq!(analyzed.main.get("hyper").unwrap().latest, Some("0.11.0".parse().unwrap()));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn skips_yanked_releases() {
|
||||||
|
let mut deps = CrateDeps::default();
|
||||||
|
deps.main.insert("hyper".parse().unwrap(), "^0.10.0".parse().unwrap());
|
||||||
|
|
||||||
|
let mut analyzer = DependencyAnalyzer::new(&deps);
|
||||||
|
analyzer.process(vec![
|
||||||
|
CrateRelease { name: "hyper".parse().unwrap(), version: "0.10.0".parse().unwrap(), yanked: false },
|
||||||
|
CrateRelease { name: "hyper".parse().unwrap(), version: "0.10.1".parse().unwrap(), yanked: true },
|
||||||
|
]);
|
||||||
|
|
||||||
|
let analyzed = analyzer.finalize();
|
||||||
|
|
||||||
|
assert_eq!(analyzed.main.get("hyper").unwrap().latest_that_matches, Some("0.10.0".parse().unwrap()));
|
||||||
|
assert_eq!(analyzed.main.get("hyper").unwrap().latest, Some("0.10.0".parse().unwrap()));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn skips_prereleases() {
|
||||||
|
let mut deps = CrateDeps::default();
|
||||||
|
deps.main.insert("hyper".parse().unwrap(), "^0.10.0".parse().unwrap());
|
||||||
|
|
||||||
|
let mut analyzer = DependencyAnalyzer::new(&deps);
|
||||||
|
analyzer.process(vec![
|
||||||
|
CrateRelease { name: "hyper".parse().unwrap(), version: "0.10.0".parse().unwrap(), yanked: false },
|
||||||
|
CrateRelease { name: "hyper".parse().unwrap(), version: "0.10.1-alpha".parse().unwrap(), yanked: false },
|
||||||
|
]);
|
||||||
|
|
||||||
|
let analyzed = analyzer.finalize();
|
||||||
|
|
||||||
|
assert_eq!(analyzed.main.get("hyper").unwrap().latest_that_matches, Some("0.10.0".parse().unwrap()));
|
||||||
|
assert_eq!(analyzed.main.get("hyper").unwrap().latest, Some("0.10.0".parse().unwrap()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use std::borrow::Borrow;
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
|
@ -12,8 +13,11 @@ impl Into<String> for CrateName {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
impl Borrow<str> for CrateName {
|
||||||
pub struct CrateNameValidationError;
|
fn borrow(&self) -> &str {
|
||||||
|
&self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl AsRef<str> for CrateName {
|
impl AsRef<str> for CrateName {
|
||||||
fn as_ref(&self) -> &str {
|
fn as_ref(&self) -> &str {
|
||||||
|
@ -21,6 +25,9 @@ impl AsRef<str> for CrateName {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct CrateNameValidationError;
|
||||||
|
|
||||||
impl FromStr for CrateName {
|
impl FromStr for CrateName {
|
||||||
type Err = CrateNameValidationError;
|
type Err = CrateNameValidationError;
|
||||||
|
|
||||||
|
@ -44,7 +51,7 @@ pub struct CrateRelease {
|
||||||
pub yanked: bool
|
pub yanked: bool
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Default)]
|
||||||
pub struct CrateDeps {
|
pub struct CrateDeps {
|
||||||
pub main: BTreeMap<CrateName, VersionReq>,
|
pub main: BTreeMap<CrateName, VersionReq>,
|
||||||
pub dev: BTreeMap<CrateName, VersionReq>,
|
pub dev: BTreeMap<CrateName, VersionReq>,
|
||||||
|
|
Loading…
Reference in a new issue