2018-08-27 16:03:52 -07:00
|
|
|
#[cfg(unix)]
|
2019-04-12 00:46:29 -07:00
|
|
|
mod unix {
|
|
|
|
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},
|
|
|
|
};
|
2019-10-17 20:04:54 -07:00
|
|
|
use test_utilities::tempdir;
|
2019-04-12 00:46:29 -07:00
|
|
|
|
|
|
|
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(
|
|
|
|
"
|
Gargantuan refactor (#522)
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
2019-11-09 21:43:20 -08: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
|
|
|
}
|