sh: Sync with FreeBSD:
[dragonfly.git] / tools / regression / bin / sh / expansion / cmdsubst1.0
1 # $FreeBSD: head/tools/regression/bin/sh/expansion/cmdsubst1.0 201366 2010-01-01 18:17:46Z jilles $
2
3 failures=0
4
5 check() {
6         if ! eval "[ $* ]"; then
7                 echo "Failed: $*"
8                 : $((failures += 1))
9         fi
10 }
11
12 check '"$(echo abcde)" = "abcde"'
13 check '"$(echo abcde; :)" = "abcde"'
14
15 check '"$(printf abcde)" = "abcde"'
16 check '"$(printf abcde; :)" = "abcde"'
17
18 # regular
19 check '-n "$(umask)"'
20 check '-n "$(umask; :)"'
21 check '-n "$(umask 2>&1)"'
22 check '-n "$(umask 2>&1; :)"'
23
24 # special
25 check '-n "$(times)"'
26 check '-n "$(times; :)"'
27 check '-n "$(times 2>&1)"'
28 check '-n "$(times 2>&1; :)"'
29
30 # regular
31 check '".$(umask -@ 2>&1)." = ".umask: Illegal option -@."'
32 check '".$(umask -@ 2>&1; :)." = ".umask: Illegal option -@."'
33 check '".$({ umask -@; } 2>&1)." = ".umask: Illegal option -@."'
34
35 # special
36 check '".$(shift xyz 2>&1)." = ".shift: Illegal number: xyz."'
37 check '".$(shift xyz 2>&1; :)." = ".shift: Illegal number: xyz."'
38 check '".$({ shift xyz; } 2>&1)." = ".shift: Illegal number: xyz."'
39
40 v=1
41 check '-z "$(v=2 :)"'
42 check '"$v" = 1'
43 check '-z "$(v=3)"'
44 check '"$v" = 1'
45 check '"$(v=4 eval echo \$v)" = 4'
46 check '"$v" = 1'
47
48 exit $((failures > 0))