diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /third_party/rust/semver/tests/node/mod.rs | |
parent | Initial commit. (diff) | |
download | firefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/semver/tests/node/mod.rs')
-rw-r--r-- | third_party/rust/semver/tests/node/mod.rs | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/third_party/rust/semver/tests/node/mod.rs b/third_party/rust/semver/tests/node/mod.rs new file mode 100644 index 0000000000..eb50673d5f --- /dev/null +++ b/third_party/rust/semver/tests/node/mod.rs @@ -0,0 +1,43 @@ +#![cfg(test_node_semver)] + +use semver::Version; +use std::fmt::{self, Display}; +use std::process::Command; + +#[derive(Default, Eq, PartialEq, Hash, Debug)] +pub(super) struct VersionReq(semver::VersionReq); + +impl VersionReq { + pub(super) const STAR: Self = VersionReq(semver::VersionReq::STAR); + + pub(super) fn matches(&self, version: &Version) -> bool { + let out = Command::new("node") + .arg("-e") + .arg(format!( + "console.log(require('semver').satisfies('{}', '{}'))", + version, + self.to_string().replace(',', ""), + )) + .output() + .unwrap(); + if out.stdout == b"true\n" { + true + } else if out.stdout == b"false\n" { + false + } else { + let s = String::from_utf8_lossy(&out.stdout) + String::from_utf8_lossy(&out.stderr); + panic!("unexpected output: {}", s); + } + } +} + +impl Display for VersionReq { + fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + Display::fmt(&self.0, formatter) + } +} + +#[cfg_attr(not(no_track_caller), track_caller)] +pub(super) fn req(text: &str) -> VersionReq { + VersionReq(crate::util::req(text)) +} |