elvish/stubimpl/test.sh

46 lines
899 B
Bash
Raw Normal View History

2016-02-21 18:59:46 +08:00
#!/bin/sh -x
2016-02-21 19:21:57 +08:00
# This test is broken. I haven't yet found a way to start a background process
# with a stdin that I can later write to. Presumably this can be doen with a
# pipe, but there is no way to create pipes explicitly in sh(1).
2016-02-21 07:28:15 +08:00
fail() {
2016-02-21 18:59:46 +08:00
echo "$*; log left in $dir"
2016-02-21 07:28:15 +08:00
exit 1
}
waitlog() {
for i in `seq 51`; do
test $i = 51 && {
return 1
}
2016-02-21 18:59:46 +08:00
test "$(tail -n1 log)" = "$*" && break
sleep 0.1
done
}
2016-02-21 18:59:46 +08:00
dir=`mktemp -d elvishXXXX`
cd "$dir"
mkfifo fifo
2016-02-21 07:28:15 +08:00
# Start elvish-stub.
2016-02-21 18:59:46 +08:00
elvish-stub > log < fifo &
2016-02-21 07:28:15 +08:00
stub=$!
# Wait for startup message.
waitlog ok || fail "didn't write startup message"
# Send SIG{INT,TERM,TSTP}
for sig in 2 15 20; do
kill -$sig $stub
ps $stub >/dev/null || {
fail "stub killed by signal #$sig"
}
waitlog $sig || fail "didn't record signal #$sig"
done
2016-02-21 07:28:15 +08:00
# Really kill stub.
kill -9 $stub
2016-02-21 18:59:46 +08:00
rmdir "$dir"