spawn x command and compare semvers

This commit is contained in:
DebugSteven 2022-12-05 16:18:43 -07:00
parent b2cd3374e9
commit b9b33d983d
3 changed files with 33 additions and 12 deletions

View File

@ -4805,9 +4805,9 @@ checksum = "1ef965a420fe14fdac7dd018862966a4c14094f900e1650bbc71ddd7d580c8af"
[[package]]
name = "semver"
version = "1.0.12"
version = "1.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2333e6df6d6598f2b1974829f853c2b4c5f4a6e503c10af918081aa6f8564e1"
checksum = "e25dfac463d778e353db5be2449d1cce89bd6fd23c9f1ea21310ce6e5a1b29c4"
dependencies = [
"serde",
]
@ -5309,6 +5309,7 @@ dependencies = [
"lazy_static",
"miropt-test-tools",
"regex",
"semver",
"termcolor",
"walkdir",
]

View File

@ -11,6 +11,7 @@ miropt-test-tools = { path = "../miropt-test-tools" }
lazy_static = "1"
walkdir = "2"
ignore = "0.4.18"
semver = "1.0.14"
termcolor = "1.1.3"
[[bin]]

View File

@ -1,17 +1,36 @@
use std::process::Command;
use semver::{BuildMetadata, Prerelease, Version};
use std::io::ErrorKind;
use std::process::{Command, Stdio};
pub fn check(_bad: &mut bool) {
let result = Command::new("x").arg("--version").output();
let output = match result {
Ok(output) => output,
Err(_e) => todo!(),
pub fn check(bad: &mut bool) {
let result = Command::new("x")
.arg("--version")
.stdout(Stdio::piped())
.spawn();
let child = match result {
Ok(child) => child,
Err(e) => match e.kind() {
ErrorKind::NotFound => return (),
_ => return tidy_error!(bad, "{}", e),
},
};
let output = child.wait_with_output().unwrap();
if output.status.success() {
let version = String::from_utf8_lossy(&output.stdout);
assert_eq!("0.1.0", version.trim_end());
let version = Version::parse(version.trim_end()).unwrap();
let expected = Version {
major: 0,
minor: 1,
patch: 0,
pre: Prerelease::new("").unwrap(),
build: BuildMetadata::EMPTY,
};
if version < expected {
return tidy_error!(bad, "Current version of x is {version} Consider updating to the newer version of x by running `cargo install --path src/tools/x`");
}
} else {
return tidy_error!(bad, "{}", output.status);
}
// FIXME: throw some kind of tidy error when the version of x isn't
// greater than or equal to the version we'd expect.
//tidy_error!(bad, "Current version of x is {version} Consider updating to the newer version of x by running `cargo install --path src/tools/x`")
}