-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add test of
cargo test
on cargo near new
result
- Loading branch information
dj8yf0μl
committed
Oct 23, 2024
1 parent
3d76a76
commit d6fa2f6
Showing
4 changed files
with
147 additions
and
61 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/// finds version of package in a crate's Cargo.lock | ||
fn get_locked_package_version( | ||
manifest_path: &camino::Utf8PathBuf, | ||
package_name: &str, | ||
) -> color_eyre::Result<semver::Version> { | ||
let meta = | ||
cargo_near_build::CrateMetadata::collect(manifest_path.clone().try_into()?, false, None)?; | ||
|
||
let package = meta.find_dependency(package_name)?; | ||
|
||
Ok(package.version.clone()) | ||
} | ||
|
||
/// This asserts sync of versions of *package_name* in lock-file of | ||
/// project_one vs project_two | ||
pub fn assert_versions_equal( | ||
manifest_one: &camino::Utf8PathBuf, | ||
manifest_two: &camino::Utf8PathBuf, | ||
package_name: &str, | ||
) -> cargo_near::CliResult { | ||
let versions = [manifest_one, manifest_two] | ||
.iter() | ||
.map(|manifest| get_locked_package_version(manifest, package_name)) | ||
.collect::<Result<Vec<_>, color_eyre::Report>>()?; | ||
|
||
assert_eq!( | ||
versions[0], | ||
versions[1], | ||
"no sync of versions of `{}` in lock-file of `{}` and \ | ||
`{}` projects", | ||
package_name, | ||
manifest_one.as_str(), | ||
manifest_two.as_str(), | ||
); | ||
Ok(()) | ||
} |
This file was deleted.
Oops, something went wrong.
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,40 @@ | ||
/// this asserts sync of rust toolchains channels of file_one vs file_two | ||
pub fn assert_equal( | ||
toolchain_one: &camino::Utf8PathBuf, | ||
toolchain_two: &camino::Utf8PathBuf, | ||
) -> cargo_near::CliResult { | ||
let channels = [toolchain_one, toolchain_two] | ||
.iter() | ||
.map(|file| get_toolchain_channel(file.as_std_path())) | ||
.collect::<Result<Vec<_>, color_eyre::Report>>()?; | ||
assert_eq!( | ||
channels[0], | ||
channels[1], | ||
"no sync of channels of the toolchain `{}` \ | ||
and `{}`", | ||
toolchain_one.as_str(), | ||
toolchain_two.as_str(), | ||
); | ||
Ok(()) | ||
} | ||
|
||
/// parses `rust-toolchain.toml` and returns `channel` | ||
fn get_toolchain_channel(toolchain_file: &std::path::Path) -> color_eyre::Result<String> { | ||
let toml_table_str = { | ||
let bytes = std::fs::read(toolchain_file).map_err(|err| { | ||
color_eyre::eyre::eyre!("read file, {:?}, err {}", toolchain_file, err) | ||
})?; | ||
core::str::from_utf8(&bytes)?.to_owned() | ||
}; | ||
let toml_table = toml_table_str.parse::<toml::Table>()?; | ||
let entry = toml_table["toolchain"]["channel"].clone(); | ||
let result = match entry { | ||
toml::Value::String(channel_string) => channel_string, | ||
_ => { | ||
return Err(color_eyre::eyre::eyre!( | ||
"unexpected variant of toml.toolchain.channel" | ||
)) | ||
} | ||
}; | ||
Ok(result) | ||
} |