3838set -e # Bomb on any script errors
3939
4040run_instruments () {
41- # Because instruments buffers it's output if it determines that it is being
42- # piped to another process, we have to use ptys to get around that so that we
43- # can use `tee` to save the output for grepping and print to stdout in real
44- # time at the same time.
45- #
46- # I don't like this because I'm hard coding a tty/pty pair in here. Suggestions
47- # to make this cleaner?
48-
41+ # Pipe to `tee` using a temporary file so everything is sent to standard out
42+ # and we have the output to check for errors.
4943 output=$( mktemp -t unix-instruments)
50- instruments " $@ " & > /dev/ttyvf &
51- pid_instruments=$!
52-
53- # Cat the instruments output to tee which outputs to stdout and saves to
54- # $output at the same time
55- cat < /dev/ptyvf | tee $output
56-
57- # Clear the process id we saved when forking instruments so the cleanup
58- # function called on exit knows it doesn't have to kill anything
59- pid_instruments=0
44+ instruments " $@ " 2>&1 | tee $output
6045
6146 # Process the instruments output looking for anything that resembles a fail
6247 # message
@@ -72,16 +57,6 @@ get_error_status() {
7257 ruby -e ' exit 1 if STDIN.read =~ /Instruments Usage Error|Instruments Trace Error|^\d+-\d+-\d+ \d+:\d+:\d+ [-+]\d+ (Fail:|Error:|None: Script threw an uncaught JavaScript error)/'
7358}
7459
75- trap cleanup_instruments EXIT
76- cleanup_instruments () {
77- # Because we fork instruments in this script, we need to clean up if it's
78- # still running because of an error or the user pressed Ctrl-C
79- if [[ $pid_instruments -gt 0 ]]; then
80- echo " Cleaning up instruments..."
81- kill -9 $pid_instruments
82- fi
83- }
84-
8560# Running this file with "----test" will try to parse an error out of whatever
8661# is handed in to it from stdin. Use this method to double check your work if
8762# you need a custom "get_error_status" function above.
0 commit comments