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