2018-08-27 16:03:52 -07:00
|
|
|
extern crate brev;
|
|
|
|
extern crate executable_path;
|
|
|
|
extern crate libc;
|
|
|
|
extern crate tempdir;
|
|
|
|
|
|
|
|
use executable_path::executable_path;
|
2018-12-08 14:29:41 -08:00
|
|
|
use std::{
|
|
|
|
process::Command,
|
|
|
|
thread,
|
|
|
|
time::{Duration, Instant},
|
|
|
|
};
|
2018-08-27 16:03:52 -07:00
|
|
|
use tempdir::TempDir;
|
|
|
|
|
|
|
|
#[cfg(unix)]
|
|
|
|
fn kill(process_id: u32) {
|
|
|
|
unsafe {
|
|
|
|
libc::kill(process_id as i32, libc::SIGINT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(unix)]
|
|
|
|
fn interrupt_test(justfile: &str) {
|
2018-12-08 14:29:41 -08:00
|
|
|
let tmp = TempDir::new("just-interrupts").unwrap_or_else(|err| {
|
|
|
|
panic!(
|
|
|
|
"integration test: failed to create temporary directory: {}",
|
|
|
|
err
|
|
|
|
)
|
|
|
|
});
|
2018-08-27 16:03:52 -07:00
|
|
|
|
|
|
|
let mut justfile_path = tmp.path().to_path_buf();
|
|
|
|
justfile_path.push("justfile");
|
|
|
|
brev::dump(justfile_path, justfile);
|
|
|
|
|
|
|
|
let start = Instant::now();
|
|
|
|
|
|
|
|
let mut child = Command::new(&executable_path("just"))
|
|
|
|
.current_dir(&tmp)
|
|
|
|
.spawn()
|
|
|
|
.expect("just invocation failed");
|
|
|
|
|
|
|
|
thread::sleep(Duration::new(1, 0));
|
|
|
|
|
|
|
|
kill(child.id());
|
|
|
|
|
|
|
|
let status = child.wait().unwrap();
|
|
|
|
|
|
|
|
let elapsed = start.elapsed();
|
|
|
|
|
2018-12-18 20:27:27 -08:00
|
|
|
if elapsed > Duration::new(4, 0) {
|
2018-08-27 16:03:52 -07:00
|
|
|
panic!("process returned too late: {:?}", elapsed);
|
|
|
|
}
|
|
|
|
|
2018-12-18 20:27:27 -08:00
|
|
|
if elapsed < Duration::new(1, 0) {
|
2018-08-27 16:03:52 -07:00
|
|
|
panic!("process returned too early : {:?}", elapsed);
|
|
|
|
}
|
|
|
|
|
|
|
|
assert_eq!(status.code(), Some(130));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(unix)]
|
|
|
|
#[test]
|
|
|
|
fn interrupt_shebang() {
|
2018-12-08 14:29:41 -08:00
|
|
|
interrupt_test(
|
|
|
|
"
|
2018-08-27 16:03:52 -07:00
|
|
|
default:
|
|
|
|
#!/usr/bin/env sh
|
|
|
|
sleep 2
|
2018-12-08 14:29:41 -08:00
|
|
|
",
|
|
|
|
);
|
2018-08-27 16:03:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(unix)]
|
|
|
|
#[test]
|
|
|
|
fn interrupt_line() {
|
2018-12-08 14:29:41 -08:00
|
|
|
interrupt_test(
|
|
|
|
"
|
2018-08-27 16:03:52 -07:00
|
|
|
default:
|
|
|
|
@sleep 2
|
2018-12-08 14:29:41 -08:00
|
|
|
",
|
|
|
|
);
|
2018-08-27 16:03:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(unix)]
|
|
|
|
#[test]
|
|
|
|
fn interrupt_backtick() {
|
2018-12-08 14:29:41 -08:00
|
|
|
interrupt_test(
|
|
|
|
"
|
2018-08-27 16:03:52 -07:00
|
|
|
foo = `sleep 2`
|
|
|
|
|
|
|
|
default:
|
|
|
|
@echo hello
|
2018-12-08 14:29:41 -08:00
|
|
|
",
|
|
|
|
);
|
2018-08-27 16:03:52 -07:00
|
|
|
}
|