2019-10-07 10:32:51 +03:00
|
|
|
mod testing;
|
2019-07-07 06:55:46 +03:00
|
|
|
|
2018-08-28 02:03:52 +03:00
|
|
|
#[cfg(unix)]
|
2019-04-12 10:46:29 +03:00
|
|
|
mod unix {
|
2019-10-07 10:32:51 +03:00
|
|
|
use super::testing::tempdir;
|
2019-04-12 10:46:29 +03:00
|
|
|
use executable_path::executable_path;
|
|
|
|
use std::{
|
2019-04-17 08:06:28 +03:00
|
|
|
fs,
|
2019-04-12 10:46:29 +03:00
|
|
|
process::Command,
|
|
|
|
time::{Duration, Instant},
|
|
|
|
};
|
|
|
|
|
|
|
|
fn kill(process_id: u32) {
|
|
|
|
unsafe {
|
|
|
|
libc::kill(process_id as i32, libc::SIGINT);
|
|
|
|
}
|
2018-08-28 02:03:52 +03:00
|
|
|
}
|
|
|
|
|
2019-04-12 10:46:29 +03:00
|
|
|
fn interrupt_test(justfile: &str) {
|
2019-07-07 06:55:46 +03:00
|
|
|
let tmp = tempdir();
|
2019-04-12 10:46:29 +03:00
|
|
|
let mut justfile_path = tmp.path().to_path_buf();
|
|
|
|
justfile_path.push("justfile");
|
2019-04-17 08:06:28 +03:00
|
|
|
fs::write(justfile_path, justfile).unwrap();
|
2018-08-28 02:03:52 +03:00
|
|
|
|
2019-04-12 10:46:29 +03:00
|
|
|
let start = Instant::now();
|
2018-08-28 02:03:52 +03:00
|
|
|
|
2019-04-12 10:46:29 +03:00
|
|
|
let mut child = Command::new(&executable_path("just"))
|
|
|
|
.current_dir(&tmp)
|
|
|
|
.spawn()
|
|
|
|
.expect("just invocation failed");
|
2018-08-28 02:03:52 +03:00
|
|
|
|
2019-04-12 10:46:29 +03:00
|
|
|
while start.elapsed() < Duration::from_millis(500) {}
|
2018-08-28 02:03:52 +03:00
|
|
|
|
2019-04-12 10:46:29 +03:00
|
|
|
kill(child.id());
|
2018-08-28 02:03:52 +03:00
|
|
|
|
2019-04-12 10:46:29 +03:00
|
|
|
let status = child.wait().unwrap();
|
2018-08-28 02:03:52 +03:00
|
|
|
|
2019-04-12 10:46:29 +03:00
|
|
|
let elapsed = start.elapsed();
|
2018-08-28 02:03:52 +03:00
|
|
|
|
2019-04-12 10:46:29 +03:00
|
|
|
if elapsed > Duration::from_secs(2) {
|
|
|
|
panic!("process returned too late: {:?}", elapsed);
|
|
|
|
}
|
2018-08-28 02:03:52 +03:00
|
|
|
|
2019-04-12 10:46:29 +03:00
|
|
|
if elapsed < Duration::from_millis(100) {
|
|
|
|
panic!("process returned too early : {:?}", elapsed);
|
|
|
|
}
|
2018-08-28 02:03:52 +03:00
|
|
|
|
2019-04-12 10:46:29 +03:00
|
|
|
assert_eq!(status.code(), Some(130));
|
|
|
|
}
|
2018-08-28 02:03:52 +03:00
|
|
|
|
2019-04-12 10:46:29 +03:00
|
|
|
#[test]
|
2019-04-16 08:40:02 +03:00
|
|
|
#[ignore]
|
2019-04-12 10:46:29 +03:00
|
|
|
fn interrupt_shebang() {
|
|
|
|
interrupt_test(
|
|
|
|
"
|
2018-08-28 02:03:52 +03:00
|
|
|
default:
|
|
|
|
#!/usr/bin/env sh
|
2019-04-12 09:58:08 +03:00
|
|
|
sleep 1
|
2018-12-09 01:29:41 +03:00
|
|
|
",
|
2019-04-12 10:46:29 +03:00
|
|
|
);
|
|
|
|
}
|
2018-08-28 02:03:52 +03:00
|
|
|
|
2019-04-12 10:46:29 +03:00
|
|
|
#[test]
|
2019-04-16 08:40:02 +03:00
|
|
|
#[ignore]
|
2019-04-12 10:46:29 +03:00
|
|
|
fn interrupt_line() {
|
|
|
|
interrupt_test(
|
|
|
|
"
|
2018-08-28 02:03:52 +03:00
|
|
|
default:
|
2019-04-12 09:58:08 +03:00
|
|
|
@sleep 1
|
2018-12-09 01:29:41 +03:00
|
|
|
",
|
2019-04-12 10:46:29 +03:00
|
|
|
);
|
|
|
|
}
|
2018-08-28 02:03:52 +03:00
|
|
|
|
2019-04-12 10:46:29 +03:00
|
|
|
#[test]
|
|
|
|
#[ignore]
|
|
|
|
fn interrupt_backtick() {
|
|
|
|
interrupt_test(
|
|
|
|
"
|
2019-04-12 09:58:08 +03:00
|
|
|
foo = `sleep 1`
|
2018-08-28 02:03:52 +03:00
|
|
|
|
|
|
|
default:
|
2019-04-12 10:46:29 +03:00
|
|
|
@echo {{foo}}
|
2018-12-09 01:29:41 +03:00
|
|
|
",
|
2019-04-12 10:46:29 +03:00
|
|
|
);
|
|
|
|
}
|
2018-08-28 02:03:52 +03:00
|
|
|
}
|