2016-02-21 07:28:15 +08:00
|
|
|
#!/bin/sh
|
|
|
|
fail() {
|
|
|
|
echo "$*; log left at $log"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2016-02-21 07:52:35 +08:00
|
|
|
lastLogIs() {
|
|
|
|
test "$(tail -n1 $log)" = "$*"
|
|
|
|
}
|
|
|
|
|
2016-02-21 07:28:15 +08:00
|
|
|
log=`mktemp elvishXXXXX`
|
|
|
|
|
|
|
|
# Start elvish-stub.
|
|
|
|
elvish-stub > $log &
|
|
|
|
stub=$!
|
|
|
|
|
|
|
|
# Wait for startup message.
|
2016-02-21 07:52:35 +08:00
|
|
|
for i in `seq 51`; do
|
2016-02-21 07:56:04 +08:00
|
|
|
test $i == 51 && {
|
2016-02-21 07:52:35 +08:00
|
|
|
fail "elvish-stub didn't write startup message within 5 seconds"
|
|
|
|
}
|
|
|
|
lastLogIs ok && break
|
|
|
|
sleep 0.1
|
|
|
|
done
|
2016-02-21 07:28:15 +08:00
|
|
|
|
|
|
|
# Send a SIGINT.
|
|
|
|
kill -2 $stub
|
|
|
|
ps $stub >/dev/null || {
|
|
|
|
fail "stub killed by SIGTERM"
|
|
|
|
}
|
2016-02-21 07:52:35 +08:00
|
|
|
lastLogIs 2 || {
|
2016-02-21 07:28:15 +08:00
|
|
|
fail "stub didn't record SIGTERM"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Really kill stub.
|
|
|
|
kill -9 $stub
|
|
|
|
|
|
|
|
rm $log
|