-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Consider prerelease versions if
version
field of a dependency is un…
…specified
- Loading branch information
Showing
9 changed files
with
152 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use std::fmt; | ||
|
||
use semver::{Comparator, Op, Version, VersionReq}; | ||
|
||
#[derive(Clone, Debug, Default, Eq, PartialEq, Hash)] | ||
pub enum DependencyVersionReq { | ||
#[default] | ||
Any, | ||
Req(VersionReq), | ||
Locked { | ||
exact: Version, | ||
req: VersionReq, | ||
}, | ||
} | ||
|
||
impl DependencyVersionReq { | ||
pub fn exact(version: &Version) -> Self { | ||
Self::Req(VersionReq { | ||
comparators: vec![Comparator { | ||
op: Op::Exact, | ||
major: version.major, | ||
minor: Some(version.minor), | ||
patch: Some(version.patch), | ||
pre: version.pre.clone(), | ||
}], | ||
}) | ||
} | ||
|
||
/// Evaluate whether the given `Version` satisfies the version requirement | ||
/// described by `self`. | ||
pub fn matches(&self, version: &Version) -> bool { | ||
match self { | ||
DependencyVersionReq::Any => true, | ||
DependencyVersionReq::Req(req) => req.matches(version), | ||
DependencyVersionReq::Locked { exact, .. } => { | ||
exact.major == version.major | ||
&& exact.minor == version.minor | ||
&& exact.patch == version.patch | ||
&& exact.pre == version.pre | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl From<VersionReq> for DependencyVersionReq { | ||
fn from(req: VersionReq) -> Self { | ||
DependencyVersionReq::Req(req) | ||
} | ||
} | ||
|
||
impl fmt::Display for DependencyVersionReq { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
match self { | ||
DependencyVersionReq::Any => f.write_str("*"), | ||
DependencyVersionReq::Req(req) => fmt::Display::fmt(req, f), | ||
DependencyVersionReq::Locked { req, .. } => fmt::Display::fmt(req, f), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use assert_fs::prelude::*; | ||
use assert_fs::TempDir; | ||
use indoc::indoc; | ||
|
||
use scarb_test_support::command::Scarb; | ||
use scarb_test_support::gitx; | ||
use scarb_test_support::project_builder::ProjectBuilder; | ||
|
||
/// https://github.com/software-mansion/scarb/issues/600 | ||
#[test] | ||
fn issue_600_path() { | ||
let t = TempDir::new().unwrap(); | ||
|
||
let dep1 = t.child("dep1"); | ||
ProjectBuilder::start() | ||
.name("dep1") | ||
.version("0.7.0-rc.0") | ||
.lib_cairo("fn hello() -> felt252 { 42 }") | ||
.build(&dep1); | ||
|
||
ProjectBuilder::start() | ||
.name("hello") | ||
.version("1.0.0") | ||
.dep("dep1", &dep1) | ||
.lib_cairo("fn world() -> felt252 { dep1::hello() }") | ||
.build(&t); | ||
|
||
Scarb::quick_snapbox() | ||
.arg("fetch") | ||
.current_dir(&t) | ||
.assert() | ||
.success() | ||
.stdout_eq(""); | ||
} | ||
|
||
/// https://github.com/software-mansion/scarb/issues/600 | ||
#[test] | ||
fn issue_600_git() { | ||
let t = TempDir::new().unwrap(); | ||
|
||
let dep1 = gitx::new("dep1", |t| { | ||
ProjectBuilder::start() | ||
.name("dep1") | ||
.version("0.7.0-rc.0") | ||
.lib_cairo("fn hello() -> felt252 { 42 }") | ||
.build(&t) | ||
}); | ||
|
||
ProjectBuilder::start() | ||
.name("hello") | ||
.version("1.0.0") | ||
.dep("dep1", &dep1) | ||
.lib_cairo("fn world() -> felt252 { dep1::hello() }") | ||
.build(&t); | ||
|
||
Scarb::quick_snapbox() | ||
.arg("fetch") | ||
.current_dir(&t) | ||
.assert() | ||
.success() | ||
.stdout_matches(indoc! {r#" | ||
[..] Updating git repository [..] | ||
"#}); | ||
} |