mirror of https://github.com/passcod/cargo-watch
Two ways to test
This commit is contained in:
parent
537182c16e
commit
60b221fe9e
|
@ -31,6 +31,9 @@ struct Args {
|
|||
#[clap(long, default_value = "5000")]
|
||||
timeout: u64,
|
||||
|
||||
#[clap(long)]
|
||||
expect_timeout: bool,
|
||||
|
||||
#[clap(raw = true)]
|
||||
cmd: Vec<String>,
|
||||
}
|
||||
|
@ -74,20 +77,26 @@ fn main() -> Result<()> {
|
|||
}
|
||||
|
||||
let start = Instant::now();
|
||||
let mut good = false;
|
||||
let mut timed_out = true;
|
||||
let mut output = None;
|
||||
while start.elapsed() < timeout {
|
||||
if cw.try_wait().into_diagnostic()?.is_some() {
|
||||
good = true;
|
||||
if let Some(out) = cw.try_wait().into_diagnostic()? {
|
||||
timed_out = false;
|
||||
output.replace(out);
|
||||
break;
|
||||
} else {
|
||||
sleep(Duration::from_millis(10));
|
||||
}
|
||||
}
|
||||
|
||||
cw.kill().into_diagnostic()?;
|
||||
tmp_dir.close().into_diagnostic()?;
|
||||
|
||||
if !good {
|
||||
bail!("Timed out");
|
||||
match (timed_out, args.expect_timeout) {
|
||||
(true, false) => bail!("Timed out"),
|
||||
(false, false) => {}
|
||||
(true, true) => eprintln!("{{~expected timeout~}}"),
|
||||
(false, true) => bail!("Expected timeout, but got quit: {:?}", output),
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
This first one tests that test-cw behaves correctly:
|
||||
|
||||
```
|
||||
$ test-cw --
|
||||
> --quit-after-n 1 -S sh -s 'echo in; sleep 1; echo out'
|
||||
? 0
|
||||
[[Running `echo in; sleep 1; echo out`]]
|
||||
in
|
||||
out
|
||||
|
@ -9,9 +12,17 @@ out
|
|||
|
||||
```
|
||||
|
||||
|
||||
This one uses `--quit-after-n`. As the default is to restart the command on
|
||||
event, we're looking for the second command to start in the middle of the
|
||||
first. We ignore the output after the second start because the order of the
|
||||
`ForceStop` message and the `in` message can vary. But we're looking for the
|
||||
`quit-after-n` signalling message afterwards to check that Cargo Watch stopped.
|
||||
|
||||
```
|
||||
$ test-cw --touch File --touch Other --between 500 --
|
||||
> --quit-after-n 2 --postpone -S sh -s 'echo in; sleep 1; echo out'
|
||||
? 0
|
||||
[[Running `echo in; sleep 1; echo out`]]
|
||||
in
|
||||
[[Running `echo in; sleep 1; echo out`]]
|
||||
|
@ -20,3 +31,22 @@ in
|
|||
|
||||
```
|
||||
|
||||
|
||||
This one doesn't use `--quit-after-n`, and instead relies on test-cw to time
|
||||
out Cargo Watch. As such, it's similar to the above except that we look for the
|
||||
last "success" message from Cargo Watch, and then the expected timeout
|
||||
signalling from the tester.
|
||||
|
||||
```
|
||||
$ test-cw --touch File --touch Other --between 500 --expect-timeout --
|
||||
> --postpone -S sh -s 'echo in; sleep 1; echo out'
|
||||
? 0
|
||||
[[Running `echo in; sleep 1; echo out`]]
|
||||
in
|
||||
[[Running `echo in; sleep 1; echo out`]]
|
||||
...
|
||||
[[Command was successful]]
|
||||
{~expected timeout~}
|
||||
|
||||
```
|
||||
|
||||
|
|
Loading…
Reference in New Issue