1#! /bin/sh 2# 3# @(#)error.sh 1.4 17/06/28 Copyright 2016-2017 J. Schilling 4# 5 6# Read test core functions 7. ../../common/test-common 8 9# 10# Basic tests to verify the consequences of shell errors 11# 12 13# 14# Test shell language syntax error 15# 16docommand error00 "$SHELL -c 'LC_ALL=C; while true; done; echo FAIL'" "!=0" "" NONEMPTY 17 18# 19# Test all special builtins with a "utility error". 20# Expected is: exit != 0 before "FAIL" is printed. 21# 22docommand error01 "$SHELL -c 'LC_ALL=C; . xxzzy; echo FAIL'" "!=0" "" NONEMPTY 23# : never fails 24#docommand error02 "$SHELL -c 'LC_ALL=C; : xxzzy; echo FAIL'" "!=0" "" NONEMPTY 25docommand error03 "$SHELL -c 'LC_ALL=C;for i in a; do break 0; done; echo FAIL'" "!=0" "" IGNORE 26docommand error04 "$SHELL -c 'LC_ALL=C;for i in a; do continue 0; done; echo FAIL'" "!=0" "" IGNORE 27docommand error05 "$SHELL -c 'LC_ALL=C; eval . xxzzy; echo FAIL'" "!=0" "" NONEMPTY 28docommand error06 "$SHELL -c 'LC_ALL=C; exec xxzzy; echo FAIL'" "!=0" "" NONEMPTY 29docommand error07 "$SHELL -c 'LC_ALL=C; exit xxzzy; echo FAIL'" "!=0" "" NONEMPTY 30docommand error08 "$SHELL -c 'LC_ALL=C; export -z; echo FAIL'" "!=0" "" NONEMPTY 31docommand error09 "$SHELL -c 'LC_ALL=C; readonly -z; echo FAIL'" "!=0" "" NONEMPTY 32docommand error10 "$SHELL -c 'LC_ALL=C; return xxzzy; echo FAIL'" "!=0" "" NONEMPTY 33docommand error11 "$SHELL -c 'LC_ALL=C; set -z; echo FAIL'" "!=0" "" NONEMPTY 34docommand error12 "$SHELL -c 'LC_ALL=C; shift xxzzy; echo FAIL'" "!=0" "" NONEMPTY 35# times never fails even with sh and ksh 36#docommand error13 "$SHELL -c 'LC_ALL=C; times xxzzy; echo FAIL'" "!=0" "" NONEMPTY 37# even sh and ksh do not fail with trap syntax errors 38#docommand error14 "$SHELL -c 'LC_ALL=C; trap \"\" xxzzy; echo FAIL'" "!=0" "" NONEMPTY 39docommand error15 "$SHELL -c 'LC_ALL=C; unset -z; echo FAIL'" "!=0" "" NONEMPTY 40 41# 42# Other utility (not a special builtin) shall not exit 43# 44docommand error16 "$SHELL -c 'LC_ALL=C; command -z; echo OK'" 0 "OK\n" NONEMPTY 45 46# 47# Redirection errors with special builtins shall exit 48# 49docommand error17 "$SHELL -c 'LC_ALL=C; . > /; echo FAIL'" "!=0" "" NONEMPTY 50docommand error18 "$SHELL -c 'LC_ALL=C; : > /; echo FAIL'" "!=0" "" NONEMPTY 51docommand error19 "$SHELL -c 'LC_ALL=C; break > /; echo FAIL'" "!=0" "" NONEMPTY 52docommand error20 "$SHELL -c 'LC_ALL=C; continue > /; echo FAIL'" "!=0" "" NONEMPTY 53docommand error21 "$SHELL -c 'LC_ALL=C; eval echo > /; echo FAIL'" "!=0" "" NONEMPTY 54docommand error22 "$SHELL -c 'LC_ALL=C; exec > /; echo FAIL'" "!=0" "" NONEMPTY 55docommand error23 "$SHELL -c 'LC_ALL=C; exit 0 > /; echo FAIL'" "!=0" "" NONEMPTY 56docommand error24 "$SHELL -c 'LC_ALL=C; export PATH > /; echo FAIL'" "!=0" "" NONEMPTY 57docommand error25 "$SHELL -c 'LC_ALL=C; readonly PATH > /; echo FAIL'" "!=0" "" NONEMPTY 58docommand error26 "$SHELL -c 'LC_ALL=C; return > /; echo FAIL'" "!=0" "" NONEMPTY 59docommand error27 "$SHELL -c 'LC_ALL=C; set > /; echo FAIL'" "!=0" "" NONEMPTY 60docommand error28 "$SHELL -c 'LC_ALL=C; set 1 2 3; shift > /; echo FAIL'" "!=0" "" NONEMPTY 61docommand error29 "$SHELL -c 'LC_ALL=C; times > /; echo FAIL'" "!=0" "" NONEMPTY 62docommand error30 "$SHELL -c 'LC_ALL=C; trap > /; echo FAIL'" "!=0" "" NONEMPTY 63docommand error31 "$SHELL -c 'LC_ALL=C; unset LC_ALL > /; echo FAIL'" "!=0" "" NONEMPTY 64 65docommand error32 "$SHELL -c 'LC_ALL=C; echo > /; echo OK'" 0 "OK\n" NONEMPTY 66docommand error33 "$SHELL -c 'LC_ALL=C; readonly LC_ALL; LC_ALL=6; echo FAIL'" "!=0" "" NONEMPTY 67docommand error34 "$SHELL -c 'LC_ALL=C; : \"\${x!y}\"; echo FAIL'" "!=0" "" NONEMPTY 68 69# 70# Test shell language syntax error interactive may not exit 71# 72docommand error100 "$SHELL -ci 'LC_ALL=C; while true; done 73echo OK'" 0 "OK\n" NONEMPTY 74 75# 76# Test all special builtins with a "utility error". 77# Expected is no exit in interactive mode 78# 79docommand error101 "$SHELL -ci 'LC_ALL=C; . xxzzy 80echo OK'" 0 "OK\n" NONEMPTY 81docommand error102 "$SHELL -ci 'LC_ALL=C; : xxzzy 82echo OK'" 0 "OK\n" NONEMPTY 83docommand error103 "$SHELL -ci 'LC_ALL=C;for i in a; do break 0; done 84echo OK'" 0 "OK\n" IGNORE 85docommand error104 "$SHELL -ci 'LC_ALL=C;for i in a; do continue 0; done 86echo OK'" 0 "OK\n" IGNORE 87docommand error105 "$SHELL -ci 'LC_ALL=C; eval . xxzzy 88echo OK'" 0 "OK\n" NONEMPTY 89# exec always exits even with sh and ksh 90#docommand error106 "$SHELL -ci 'LC_ALL=C; exec xxzzy 91#echo OK'" 0 "OK\n" NONEMPTY 92# exit alays exits 93#docommand error107 "$SHELL -ci 'LC_ALL=C; exit xxzzy 94#echo OK'" 0 "" NONEMPTY 95docommand error108 "$SHELL -ci 'LC_ALL=C; export -z 96echo OK'" 0 "OK\n" NONEMPTY 97docommand error109 "$SHELL -ci 'LC_ALL=C; readonly -z 98echo OK'" 0 "OK\n" NONEMPTY 99docommand error110 "$SHELL -ci 'LC_ALL=C; return xxzzy 100echo OK'" 0 "OK\n" NONEMPTY 101docommand error111 "$SHELL -ci 'LC_ALL=C; set -z 102echo OK'" 0 "OK\n" NONEMPTY 103docommand error112 "$SHELL -ci 'LC_ALL=C; shift xxzzy 104echo OK'" 0 "OK\n" NONEMPTY 105# times never fails even with sh and ksh 106#docommand error113 "$SHELL -c 'LC_ALL=C; times xxzzy; echo FAIL'" "!=0" "" NONEMPTY 107docommand error114 "$SHELL -ci 'LC_ALL=C; trap \"\" xxzzy 108echo OK'" 0 "OK\n" NONEMPTY 109docommand error115 "$SHELL -ci 'LC_ALL=C; unset -z 110echo OK'" 0 "OK\n" NONEMPTY 111 112# 113# Other utility (not a special builtin) shall not exit 114# 115docommand error116 "$SHELL -ci 'LC_ALL=C; command -z 116echo OK'" 0 "OK\n" NONEMPTY 117 118# 119# Redirection errors with special builtins in interactive mode shall not exit 120# 121if [ "`uname -s`" = Haiku ]; then 122 echo "Skipping tests error117 ... error132 because of a Haiku OS bug" 123else 124docommand error117 "$SHELL -ci 'LC_ALL=C; . > / 125echo OK'" 0 "OK\n" NONEMPTY 126docommand error118 "$SHELL -ci 'LC_ALL=C; : > / 127echo OK'" 0 "OK\n" NONEMPTY 128docommand error119 "$SHELL -ci 'LC_ALL=C; break > / 129echo OK'" 0 "OK\n" NONEMPTY 130docommand error120 "$SHELL -ci 'LC_ALL=C; continue > / 131echo OK'" 0 "OK\n" NONEMPTY 132docommand error121 "$SHELL -ci 'LC_ALL=C; eval echo > / 133echo OK'" 0 "OK\n" NONEMPTY 134docommand error122 "$SHELL -ci 'LC_ALL=C; exec > / 135echo OK'" 0 "OK\n" NONEMPTY 136docommand error123 "$SHELL -ci 'LC_ALL=C; exit 0 > / 137echo OK'" 0 "OK\n" NONEMPTY 138docommand error124 "$SHELL -ci 'LC_ALL=C; export PATH > / 139echo OK'" 0 "OK\n" NONEMPTY 140docommand error125 "$SHELL -ci 'LC_ALL=C; readonly PATH > / 141echo OK'" 0 "OK\n" NONEMPTY 142docommand error126 "$SHELL -ci 'LC_ALL=C; return > / 143echo OK'" 0 "OK\n" NONEMPTY 144docommand error127 "$SHELL -ci 'LC_ALL=C; set > / 145echo OK'" 0 "OK\n" NONEMPTY 146docommand error128 "$SHELL -ci 'LC_ALL=C; set 1 2 3; shift > / 147echo OK'" 0 "OK\n" NONEMPTY 148docommand error129 "$SHELL -ci 'LC_ALL=C; times > / 149echo OK'" 0 "OK\n" NONEMPTY 150docommand error130 "$SHELL -ci 'LC_ALL=C; trap > / 151echo OK'" 0 "OK\n" NONEMPTY 152docommand error131 "$SHELL -ci 'LC_ALL=C; unset LC_ALL > / 153echo OK'" 0 "OK\n" NONEMPTY 154 155docommand error132 "$SHELL -ci 'LC_ALL=C; echo > / 156echo OK'" 0 "OK\n" NONEMPTY 157fi 158docommand error133 "$SHELL -ci 'LC_ALL=C; readonly LC_ALL; LC_ALL=6 159echo OK'" 0 "OK\n" NONEMPTY 160docommand error134 "$SHELL -ci 'LC_ALL=C; : \"\${x!y}\" 161echo OK'" 0 "OK\n" NONEMPTY 162 163success 164