1
1
mirror of https://github.com/casey/just.git synced 2024-11-27 09:15:08 +03:00
just/tests/interrupts.rs
Casey Rodarmor 49ab423592
Refactor lexer tests (#498)
- Refactor the lexer tests to be more readable, abandoning the
  previous string-based summary DSL in favor of a more obvious
  sequence of `TokenKinds` with optional lexemes. The new tests
  also test that token lexemes are correct.

- Move duplicated `unindent` function into a shared crate,
  `test-utilities`. This new versionless dev-dependency will
  prevent publishing to crates.io, at least until rust-lang/cargo/pull/7333
  makes it into stable. If we publish a new version before then,
  test-utilities will need to be published to crates.io, so we can depend
  on it by version.
2019-10-17 20:04:54 -07:00

85 lines
1.4 KiB
Rust

#[cfg(unix)]
mod unix {
use executable_path::executable_path;
use std::{
fs,
process::Command,
time::{Duration, Instant},
};
use test_utilities::tempdir;
fn kill(process_id: u32) {
unsafe {
libc::kill(process_id as i32, libc::SIGINT);
}
}
fn interrupt_test(justfile: &str) {
let tmp = tempdir();
let mut justfile_path = tmp.path().to_path_buf();
justfile_path.push("justfile");
fs::write(justfile_path, justfile).unwrap();
let start = Instant::now();
let mut child = Command::new(&executable_path("just"))
.current_dir(&tmp)
.spawn()
.expect("just invocation failed");
while start.elapsed() < Duration::from_millis(500) {}
kill(child.id());
let status = child.wait().unwrap();
let elapsed = start.elapsed();
if elapsed > Duration::from_secs(2) {
panic!("process returned too late: {:?}", elapsed);
}
if elapsed < Duration::from_millis(100) {
panic!("process returned too early : {:?}", elapsed);
}
assert_eq!(status.code(), Some(130));
}
#[test]
#[ignore]
fn interrupt_shebang() {
interrupt_test(
"
default:
#!/usr/bin/env sh
sleep 1
",
);
}
#[test]
#[ignore]
fn interrupt_line() {
interrupt_test(
"
default:
@sleep 1
",
);
}
#[test]
#[ignore]
fn interrupt_backtick() {
interrupt_test(
"
foo = `sleep 1`
default:
@echo {{foo}}
",
);
}
}