1
#!/bin/sh
2

3 2
set -eu
4

5
# gosh: https://github.com/mvdan/sh v3.0.2 fails
6 2
umask >/dev/null
7

8
# mrsh: https://github.com/emersion/mrsh WIP 657ea07 fails
9 2
( false ) 2>/dev/null && exit 1
10

11
redefine() { echo redefine; }
12 2
if [ "$(redefine() { :; }; redefine)" = "redefine" ]; then
13
  # ksh
14 0
  echo "SHELLSPEC_DEFECT_REDEFINE=1"
15
fi
16

17 2
if ! (false() { :; }; false) 2>/dev/null; then
18
  # busybox 1.1.3
19 0
  echo "SHELLSPEC_DEFECT_BUILTIN=1"
20
fi
21

22
# shellcheck disable=SC2034,SC2234
23 2
if ( [ "$( ( readonly value=123 ) 2>&1 )" ] ) 2>/dev/null; then
24
  # pdksh 5.2.14 (debian-2.2), ksh 93q, ksh 93r
25
  # busybox 1.15.3, busybox 1.19.4
26 0
  echo "SHELLSPEC_DEFECT_READONLY=1"
27
fi
28

29
# shellcheck disable=SC2154
30 2
if (set -u; unset v ||:; : "$v") 2>/dev/null; then
31
  # posh 0.10.2
32 0
  echo "SHELLSPEC_DEFECT_SHELLFLAG=1"
33
fi
34

35 2
if [ ! "$(errexit() { set -e; false; :; }; errexit && echo OK)" ]; then
36
  # bosh 2020/04/10
37 0
  echo "SHELLSPEC_DEFECT_ERREXIT=1"
38
fi
39

40
# Workaround for zsh 4.2.5
41
zshexit() { ( exit 1 ); }
42 2
if [ "${ZSH_VERSION:-}" ] && zshexit; then
43 0
  echo "SHELLSPEC_DEFECT_ZSHEXIT=1"
44
fi
45

46
# Workaround for posh 0.8.5
47 2
case $(kill -l 1 2>/dev/null) in (1*)
48 0
  echo "SHELLSPEC_DEFECT_SIGNAL=1"
49
esac
50

51 2
set +e
52 2
(set -e; subshell() { return 2; }; subshell) 2>/dev/null
53 2
if [ $? -eq 1 ]; then
54 0
  echo "SHELLSPEC_DEFECT_SUBSHELL=1"
55
fi
56 2
set -e
57

58 2
set +e
59 2
eval "set -e"
60 2
sete=$-
61 2
if [ "$sete" = "${sete%e*}" ]; then
62 0
  echo "SHELLSPEC_DEFECT_SETE=1"
63
fi
64 2
set -e
65

66 2
SHELLSPEC_CLONE_TYPE="posix"
67
# shellcheck disable=SC2039,SC3044
68 2
if typeset >/dev/null 2>&1; then
69
  # shellcheck disable=SC2034,SC3044
70 2
  set -- "$(var=data; typeset -p var 2>/dev/null ||:)" ||:
71 2
  if [ ! "${1#*data}" = "$1" ]; then
72 2
    [ "${BASH_VERSION:-}" ] && SHELLSPEC_CLONE_TYPE=bash
73 2
    [ "${ZSH_VERSION:-}" ] && SHELLSPEC_CLONE_TYPE=zsh
74 2
    [ "${YASH_VERSION:-}" ] && SHELLSPEC_CLONE_TYPE=yash
75 2
    [ "${KSH_VERSION:-}" ] && SHELLSPEC_CLONE_TYPE=ksh
76 0
  elif [ "${ZSH_VERSION:-}" ]; then
77 0
    SHELLSPEC_CLONE_TYPE=old_zsh
78 0
  elif ( typeset -r .sh >/dev/null 2>&1 ); then
79 0
    SHELLSPEC_CLONE_TYPE=old_ksh
80
  else
81 0
    SHELLSPEC_CLONE_TYPE=old_pdksh
82
  fi
83
fi
84 2
echo "SHELLSPEC_CLONE_TYPE=$SHELLSPEC_CLONE_TYPE"
85

86 2
if sleep 0.1 2>/dev/null; then
87 0
  echo "SHELLSPEC_MSLEEP=1"
88
fi
89

90 2
if (: >/dev/tty && : </dev/tty) 2>/dev/null; then
91 2
  echo "SHELLSPEC_TTY=1"
92
fi
93

94 2
if "${0%/*}/shellspec-shebang" 2>/dev/null; then
95 2
  echo "SHELLSPEC_SHEBANG_MULTIARG=1"
96
fi
97

98
# shellcheck disable=SC2039,SC3047
99 2
if (trap '' DEBUG) 2>/dev/null; then
100 2
  echo "SHELLSPEC_DEBUG_TRAP=1"
101 2
  echo "SHELLSPEC_KCOV_COMPATIBLE_SHELL=1"
102
fi
103

104
set_path() {
105 2
  if [ "${KSH_VERSION:-}" ] && (eval ': "${.sh.version}"' 2>/dev/null); then
106
    # Workaround for ksh with kcov. Prevent ShellSpec self test fails.
107 0
    hash -r 2>/dev/null &&:
108
  fi
109 2
  PATH="$1"
110
}
111

112 2
set_path "${PATH:-}:/"
113 2
case $PATH in (*\;/)
114 0
  echo "SHELLSPEC_BUSYBOX_W32=1"
115
esac
116

117
# shellcheck disable=SC2123
118 2
set_path /
119 2
if [ "$SHELLSPEC_SANDBOX" ] && ! $SHELLSPEC_SHELL -c ":" 2>/dev/null; then
120
  # busybox ash on cygwin
121 0
  echo "SHELLSPEC_DEFECT_SANDBOX=1"
122
fi
123

124 2
set_path ""
125 2
if printf '' 2>/dev/null; then
126 2
  echo "SHELLSPEC_BUILTIN_PRINTF=1"
127
fi
128 2
if print -nr -- '' 2>/dev/null; then
129 0
  echo "SHELLSPEC_BUILTIN_PRINT=1"
130
fi
131

132
typesetf_check() { :; }
133
# shellcheck disable=SC2034,SC2039,SC3044
134 2
if typeset -f typesetf_check >/dev/null 2>&1; then
135 2
  echo "SHELLSPEC_BUILTIN_TYPESETF=1"
136
fi
137

138 2
if type shopt >/dev/null 2>&1; then
139 2
  echo "SHELLSPEC_SHOPT_AVAILABLE=1"
140
  # shellcheck disable=SC2039,SC3044
141 2
  if shopt -s failglob 2>/dev/null; then
142 2
    echo "SHELLSPEC_FAILGLOB_AVAILABLE=1"
143
  fi
144
fi
145

146 2
if setopt NO_NOMATCH >/dev/null 2>&1; then
147 0
  echo "SHELLSPEC_NOMATCH_AVAILABLE=1"
148
fi
149

150
#shellcheck disable=SC2034
151
{
152 2
  if [ "$({ BASH_XTRACEFD=3; set -x; :; } 2>/dev/null 3>&1)" ]; then
153 2
    echo "SHELLSPEC_XTRACEFD_VAR=BASH_XTRACEFD"
154 0
  elif [ "$({ ZSH_XTRACEFD=3; set -x; :; } 2>/dev/null 3>&1)" ]; then
155 0
    echo "SHELLSPEC_XTRACEFD_VAR=ZSH_XTRACEFD"
156
  fi
157

158
  xtrace() { echo XTRACE > /dev/null; }
159 2
  xtrace=$({ set -x; xtrace; } 2>&1)
160 2
  case $xtrace in (*XTRACE*) ;; (*)
161 0
    type typeset >/dev/null 2>&1 && xtrace=2 || xtrace=1
162 0
    echo "SHELLSPEC_DEFECT_XTRACE=$xtrace"
163
  esac
164 2
} 2>/dev/null &&:
165

166 2
if [ "${POSH_VERSION:-}" ] || ! export -p >/dev/null 2>&1; then
167 0
  echo "SHELLSPEC_DEFECT_EXPORTP=1"
168
fi
169

170 2
VAR="readonly"
171 2
readonly VAR
172 2
export VAR
173 2
if ! $SHELLSPEC_SHELL "${0%/*}/shellspec-inspection-readonly.sh" 2>/dev/null; then
174
  # ksh: readonly flag is inherit to child processes
175 0
  echo "SHELLSPEC_PATH_IS_READONLY=1"
176
fi
177

178
# arithmetic expansion is also required
179 2
exit $((0))

Read our documentation on viewing source code .

Loading