]>
git.proxmox.com Git - rustc.git/blob - vendor/semver/tests/node/mod.rs
1 #![cfg(test_node_semver)]
4 use std
::fmt
::{self, Display}
;
5 use std
::process
::Command
;
7 #[derive(Default, Eq, PartialEq, Hash, Debug)]
8 pub(super) struct VersionReq(semver
::VersionReq
);
11 pub(super) const STAR
: Self = VersionReq(semver
::VersionReq
::STAR
);
13 pub(super) fn matches(&self, version
: &Version
) -> bool
{
14 let out
= Command
::new("node")
17 "console.log(require('semver').satisfies('{}', '{}'))",
19 self.to_string().replace('
,'
, ""),
23 if out
.stdout
== b
"true\n" {
25 } else if out
.stdout
== b
"false\n" {
28 let s
= String
::from_utf8_lossy(&out
.stdout
) + String
::from_utf8_lossy(&out
.stderr
);
29 panic
!("unexpected output: {}", s
);
34 impl Display
for VersionReq
{
35 fn fmt(&self, formatter
: &mut fmt
::Formatter
) -> fmt
::Result
{
36 Display
::fmt(&self.0, formatter
)
40 #[cfg_attr(not(no_track_caller), track_caller)]
41 pub(super) fn req(text
: &str) -> VersionReq
{
42 VersionReq(crate::util
::req(text
))