write the review-classifier fake agent scripts from a child process
This commit is contained in:
parent
c16cf1756f
commit
41f832458e
1 changed files with 31 additions and 11 deletions
25
swarm-review-classifier/src/test_script.rs
Normal file
25
swarm-review-classifier/src/test_script.rs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
//! Fake agent scripts for the tests.
|
||||
|
||||
use std::path::Path;
|
||||
|
||||
/// Write the script `body` to `path` as an executable, from a child process
|
||||
/// rather than from this one: a write fd on it held here could be inherited
|
||||
/// by a child another test thread forks, and exec'ing a file some process
|
||||
/// still holds open for writing fails with `ETXTBSY`.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// If `/bin/sh` cannot run or the write fails.
|
||||
pub fn write_executable(path: &Path, body: &str) {
|
||||
let status = std::process::Command::new("/bin/sh")
|
||||
.args([
|
||||
"-c",
|
||||
r#"printf '%s' "$1" > "$2" && chmod 755 "$2""#,
|
||||
"sh",
|
||||
body,
|
||||
])
|
||||
.arg(path)
|
||||
.status()
|
||||
.expect("run /bin/sh");
|
||||
assert!(status.success(), "writing {} failed", path.display());
|
||||
}
|
||||
Loading…
Reference in a new issue