Add elvish-stub.

This commit is contained in:
Qi Xiao 2016-02-21 00:28:15 +01:00
parent 56fae84255
commit ef61fcf234
2 changed files with 53 additions and 0 deletions

21
elvish-stub/main.go Normal file
View File

@ -0,0 +1,21 @@
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
)
// TODO Need to learn the semantics handle of SIGHUP and see if it deserves
// special treatment.
func main() {
signalChan := make(chan os.Signal)
signal.Notify(signalChan)
fmt.Println("ok")
os.Stdout.Sync()
for sig := range signalChan {
fmt.Println(int(sig.(syscall.Signal)))
os.Stdout.Sync()
}
}

32
elvish-stub/test.sh Executable file
View File

@ -0,0 +1,32 @@
#!/bin/sh
fail() {
echo "$*; log left at $log"
exit 1
}
log=`mktemp elvishXXXXX`
# Start elvish-stub.
elvish-stub > $log &
stub=$!
sleep 0.1
# Wait for startup message.
test `tail -n1 $log` == ok || {
fail "no startup message or startup too slow"
}
# Send a SIGINT.
kill -2 $stub
ps $stub >/dev/null || {
fail "stub killed by SIGTERM"
}
test `tail -n1 $log` == 2 || {
fail "stub didn't record SIGTERM"
}
# Really kill stub.
kill -9 $stub
rm $log