1#! /bin/sh 2# 3# @(#)syntax.sh 1.3 18/10/09 Copyright 2017 J. Schilling 4# 5 6# Read test core functions 7. ../../common/test-common 8 9# 10# Basic tests to check whether syntay detection works as expected. 11# These tests have been taken from NetBSD. 12# 13docommand syn00 "$SHELL -c 'true; fi'" "!=0" "" NONEMPTY 14docommand syn01 "$SHELL -c 'false; fi'" "!=0" "" NONEMPTY 15docommand syn02 "$SHELL -c 'false; then echo wut'" "!=0" "" NONEMPTY 16docommand syn03 "$SHELL -c 'true; then echo wut'" "!=0" "" NONEMPTY 17docommand syn04 "$SHELL -c 'true; do echo wut'" "!=0" "" NONEMPTY 18docommand syn05 "$SHELL -c 'true; then'" "!=0" "" NONEMPTY 19docommand syn06 "$SHELL -c 'true; else'" "!=0" "" NONEMPTY 20docommand syn07 "$SHELL -c 'true; do'" "!=0" "" NONEMPTY 21docommand syn08 "$SHELL -c 'true; done'" "!=0" "" NONEMPTY 22docommand syn09 "$SHELL -c ': ; }'" "!=0" "" NONEMPTY 23docommand syn10 "$SHELL -c ': ; )'" "!=0" "" NONEMPTY 24 25docommand syn11 "$SHELL -c 'true& fi'" "!=0" "" NONEMPTY 26docommand syn12 "$SHELL -c 'false& fi'" "!=0" "" NONEMPTY 27docommand syn13 "$SHELL -c 'false& then echo wut'" "!=0" "" NONEMPTY 28docommand syn14 "$SHELL -c 'true& then echo wut'" "!=0" "" NONEMPTY 29docommand syn15 "$SHELL -c 'true& do echo wut'" "!=0" "" NONEMPTY 30docommand syn16 "$SHELL -c 'true& then'" "!=0" "" NONEMPTY 31docommand syn17 "$SHELL -c 'true& else'" "!=0" "" NONEMPTY 32docommand syn18 "$SHELL -c 'true& do'" "!=0" "" NONEMPTY 33docommand syn19 "$SHELL -c 'true& done'" "!=0" "" NONEMPTY 34docommand syn20 "$SHELL -c ':&}'" "!=0" "" NONEMPTY 35docommand syn21 "$SHELL -c ':&)'" "!=0" "" NONEMPTY 36 37docommand syn30 "$SHELL -c 'case x in <|() ;; esac'" "!=0" "" NONEMPTY 38docommand syn31 "$SHELL -c 'case x in ((|)) ;; esac'" "!=0" "" NONEMPTY 39docommand syn32 "$SHELL -c 'case x in _|() ;; esac'" "!=0" "" NONEMPTY 40docommand syn33 "$SHELL -c 'case x in ()|() ;; esac'" "!=0" "" NONEMPTY 41docommand syn34 "$SHELL -c 'case x in -|;) ;; esac'" "!=0" "" NONEMPTY 42docommand syn35 "$SHELL -c 'case x in (;|-) ;; esac'" "!=0" "" NONEMPTY 43docommand syn36 "$SHELL -c 'case x in ;;|;) ;; esac'" "!=0" "" NONEMPTY 44docommand syn37 "$SHELL -c 'case x in (|| | ||) ;; esac'" "!=0" "" NONEMPTY 45docommand syn38 "$SHELL -c 'case x in (<<|>>) ;; esac'" "!=0" "" NONEMPTY 46docommand syn39 "$SHELL -c 'case x in (&&|&) ;; (|||>&) ;; &) esac'" "!=0" "" NONEMPTY 47docommand syn40 "$SHELL -c 'case x in (>||<) ;; esac'" "!=0" "" NONEMPTY 48docommand syn41 "$SHELL -c 'case x in( || | || | || | || | || );; esac'" "!=0" "" NONEMPTY 49docommand syn42 "$SHELL -c 'case x in (||| ||| ||| ||| ||) ;; esac'" "!=0" "" NONEMPTY 50docommand syn43 "$SHELL -c 'case x in <> | 51) ;; esac'" "!=0" "" NONEMPTY 52 53# 54# Those that follow are not syntax errors, and should be parsed properly. 55# 56o_posix= 57[ "$is_bosh" = true ] && o_posix="-o posix" 58 59# 60# Der historische Bourne Shell parst "{" hier als KTSYM 61docommand syn100 "$SHELL -c 'case fi in ({|}) ;; (!) ;; esac'" 0 "" "" 62docommand syn101 "$SHELL -c 'case esac in ([|]);; (][);; !!!|!!!|!!!|!!!);; esac'" 0 "" "" 63docommand syn102 "$SHELL ${o_posix} -c 'case then in ({[]]}) ;; (^^);; (^|^);; ([!]);; (-);; esac'" 0 "" "" 64# 65# Der historische Bourne Shell parst " while )" hier als WHSYM 66docommand syn103 "$SHELL -c 'case while in while );;(if|then|elif|fi);;(do|done);; esac'" 0 "" "" 67docommand syn104 "$SHELL -c 'case until in(\$);;(\$\$);;(\$4.50);;(1/2);;0.3333);;esac'" 0 "" "" 68# 69# Der historische Bourne Shell parst !) hier als NOTSYM 70docommand syn105 "$SHELL -c 'case return in !);; !\$);; \$!);; !#);; (@);; esac'" 0 "" "" 71docommand syn106 "$SHELL -c 'case break in (/);; (\/);; (/\|/\));; (\\//);; esac'" 0 "" "" 72 73docommand syn110 "$SHELL -c 'r=\"!\"; case \$r in !) echo \$r 1 ;; !\$) echo \$r 2;; \$!) echo \$r 3;; !#) echo \$r 4;; (@) echo \$r 5;; *) echo \$r 6 ;; esac'" 0 "! 1\n" "" 74docommand syn111 "$SHELL -c 'r=\"!\$\"; case \$r in !) echo \$r 1 ;; !\$) echo \$r 2;; \$!) echo \$r 3;; !#) echo \$r 4;; (@) echo \$r 5;; *) echo \$r 6 ;; esac'" 0 "!\$ 2\n" "" 75docommand syn112 "$SHELL -c 'r=\"\$!\"; case \$r in !) echo \$r 1 ;; !\$) echo \$r 2;; \$!) echo \$r 3;; !#) echo \$r 4;; (@) echo \$r 5;; *) echo \$r 6 ;; esac'" 0 "3\n" "" # $! expands to non-existing last background 76docommand syn113 "$SHELL -c 'r=\"!#\"; case \$r in !) echo \$r 1 ;; !\$) echo \$r 2;; \$!) echo \$r 3;; !#) echo \$r 4;; (@) echo \$r 5;; *) echo \$r 6 ;; esac'" 0 "!# 4\n" "" 77docommand syn114 "$SHELL -c 'r=\"@\"; case \$r in !) echo \$r 1 ;; !\$) echo \$r 2;; \$!) echo \$r 3;; !#) echo \$r 4;; (@) echo \$r 5;; *) echo \$r 6 ;; esac'" 0 "@ 5\n" "" 78docommand syn115 "$SHELL -c 'r=\"bla\"; case \$r in !) echo \$r 1 ;; !\$) echo \$r 2;; \$!) echo \$r 3;; !#) echo \$r 4;; (@) echo \$r 5;; *) echo \$r 6 ;; esac'" 0 "bla 6\n" "" 79docommand syn116 "$SHELL -c 'r=\"(@)\"; case \$r in !) echo \$r 1 ;; !\$) echo \$r 2;; \$!) echo \$r 3;; !#) echo \$r 4;; (@) echo \$r 5;; *) echo \$r 6 ;; esac'" 0 "(@) 6\n" "" 80 81# 82# The AT&T hack in _macro() from the 1980s together with the POSIX change in 83# case caused this to fail when the shell is in strict POSIX mode: 84# 85docommand syn140 "$SHELL -c 'x=; case \$x in \"\") echo OK;; *) echo BAD; esac'" 0 "OK\n" "" 86docommand syn141 "$SHELL ${o_posix} -c 'x=; case \$x in \"\") echo OK;; *) echo BAD; esac'" 0 "OK\n" "" 87 88success 89