2018-08-28 02:03:52 +03:00
|
|
|
#[cfg(unix)]
|
2019-04-12 10:46:29 +03:00
|
|
|
mod unix {
|
|
|
|
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},
|
|
|
|
};
|
2019-10-18 06:04:54 +03:00
|
|
|
use test_utilities::tempdir;
|
2019-04-12 10:46:29 +03:00
|
|
|
|
|
|
|
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(
|
|
|
|
"
|
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-10 08:43:20 +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
|
|
|
}
|