#!/usr/bin/env bash # # Sanity checks for the shell. # # Usage: # ./smoke.sh set -o nounset set -o pipefail set -o errexit readonly OSH=bin/osh # Read from a file. osh-file() { echo ===== Hello cat >_tmp/hi.sh <_tmp/no-newline.sh $OSH _tmp/no-newline.sh } # Read from stdin. osh-stdin() { $OSH < _tmp/hi.sh echo ===== EMPTY $OSH < _tmp/empty.sh echo ===== NO TRAILING NEWLINE $OSH < _tmp/no-newline.sh # Line continuation tests $OSH <&2 "$@" exit 1 } assert() { test "$@" || die "$@ failed" } ast() { bin/osh -n -c 'echo hi' bin/osh -n --ast-format text -c 'echo hi' bin/osh -n --ast-format abbrev-html -c 'echo hi' bin/osh -n --ast-format html -c 'echo hi' # Not dumping to terminal if bin/osh -n --ast-format oheap -c 'echo hi'; then die "Should have failed" fi local ast_bin=_tmp/smoke-ast.bin bin/osh -n --ast-format oheap -c 'echo hi' > $ast_bin ls -l $ast_bin hexdump -C $ast_bin } help() { set +o errexit bin/oil osh --help assert $? -eq 0 bin/osh --help assert $? -eq 0 bin/oil --help assert $? -eq 0 } _error-case() { echo echo "$@" echo bin/osh -c "$@" } parse-errors() { set +o errexit _error-case 'echo < <<' _error-case '${foo:}' _error-case '$(( 1 + ))' _error-case 'echo $( echo > >> )' #_error-case 'echo ${' } "$@"