Skip to content

Commit b4a2eb3

Browse files
committed
test(script): Verify use with memfd
1 parent e2c8f3c commit b4a2eb3

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

Cargo.lock

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ libc = "0.2.177"
6767
libgit2-sys = "0.18.2"
6868
libloading = "0.8.9"
6969
memchr = "2.7.6"
70+
memfd = "0.6.5"
7071
miow = "0.6.1"
7172
opener = "0.8.3"
7273
openssl = "0.10.74"
@@ -261,6 +262,9 @@ gix-transport = { version = "0.49.1", features = ["http-client-insecure-credenti
261262
same-file.workspace = true
262263
snapbox.workspace = true
263264

265+
[target.'cfg(target_os = "linux")'.dev-dependencies]
266+
memfd.workspace = true
267+
264268
[build-dependencies]
265269
flate2.workspace = true
266270
tar.workspace = true

tests/testsuite/script/cargo.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::fs;
2+
use std::io::Write;
23

34
use crate::prelude::*;
45
use cargo_test_support::basic_manifest;
@@ -2174,3 +2175,37 @@ args: []
21742175
"#]])
21752176
.run();
21762177
}
2178+
2179+
#[cargo_test(nightly, reason = "-Zscript is unstable")]
2180+
#[cfg(target_os = "linux")]
2181+
fn memfd_script() {
2182+
use std::os::fd::AsRawFd;
2183+
2184+
let fd = memfd::MemfdOptions::new()
2185+
.close_on_exec(false)
2186+
.create("otkeep-script")
2187+
.unwrap();
2188+
let mut file = fd.into_file();
2189+
file.write_all(ECHO_SCRIPT.as_bytes()).unwrap();
2190+
file.flush().unwrap();
2191+
2192+
let raw_fd = file.as_raw_fd();
2193+
2194+
let p = cargo_test_support::project()
2195+
.file("echo.rs", ECHO_SCRIPT)
2196+
.build();
2197+
2198+
p.cargo(&format!("-Zscript -v /proc/self/fd/{raw_fd}"))
2199+
.masquerade_as_nightly_cargo(&["script"])
2200+
.with_status(101)
2201+
.with_stdout_data(str![""])
2202+
.with_stderr_data(str![[r#"
2203+
[WARNING] `package.edition` is unspecified, defaulting to `2024`
2204+
2205+
thread 'main' ([..]) panicked at src/cargo/core/workspace.rs:465:18:
2206+
template is correct: [NOT_FOUND]
2207+
[NOTE] run with `RUST_BACKTRACE=1` environment variable to display a backtrace
2208+
2209+
"#]])
2210+
.run();
2211+
}

0 commit comments

Comments
 (0)