Testing spinner behavior during interrupts and termination signals can be done with the following command and cases:
Everything should spin and stop without problem:
$ ./wait # And then wait
$ echo $? # 0
There are a few places to try interrupting and testing error codes. These include:
- Before the spinner is created
- Before the spinner starts
- After the spinner starts
- After the spinner stops
Outputs will indicate when these points are reached. Interrupt at each of these to verify the cursor returns.
Different types of interrupt signals can be sent with the following key combos:
SIGINT
:CTRL-C
SIGQUIT
:CTRL-\
And a SIGTERM
can be generated by killing the process from another window:
$ ./wait
SPIN TEST: preparing test program #42550
...
$ kill 42550
The error codes for each of these interrupts can be checked with:
$ echo $?
0
Expected values for each of the above interrupts might be:
SIGINT
: 130SIGQUIT
: 131SIGTERM
: 143
More information on exit codes can be found here.
The small program (which calls spinner
) can also capture interrupts and handle
interrupts itself:
$ ./wait --signal
Note: SIGQUIT
is not captured to allow checks of the unchecked signal case.
All of these exit behaviors can be tested when the spinner program is called from another program or script:
$ make # Build and run the small program with make
$ ./sit.sh # Run the small program from a script