summaryrefslogtreecommitdiffstats
path: root/Test/runtests.zsh
blob: ea862d2b3c158b1e3c400d9fc90b11fac7eaba4a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/zsh -f

emulate zsh

# Run all specified tests, keeping count of which succeeded.
# The reason for this extra layer above the test script is to
# protect from catastrophic failure of an individual test.
# We could probably do that with subshells instead.

integer success=0 failure=0 skipped=0 retval
typeset resln rule col
typeset -a ffiles res

# colour to use for ztst failure messages. also used as a signal that colours
# are available generally
[[ -t 1 ]] &&
(( ! $+ZTST_failcolour )) &&
[[ -z $NO_COLOR ]] &&
[[ $TERM == *color* || "$( tput colors 2> /dev/null )" == <8-> ]] &&
typeset -x ZTST_failcolour=red

for file in "${(f)ZTST_testlist}"; do
  file=${file#./}
  $ZTST_exe +Z -f $ZTST_srcdir/ztst.zsh $file
  retval=$?
  if (( $retval == 2 )); then
    (( skipped++ ))
  elif (( $retval )); then
    (( failure++ ))
    (( $retval > 128 )) && {
      [[ -n $ZTST_failcolour ]] && print -rnP "%F{$ZTST_failcolour}"
      print -r - "$file: test failed: SIG$signals[$retval - 127]."
      [[ -n $ZTST_failcolour ]] && print -rnP %f
    }
    ffiles+=( $file )
  else
    (( success++ ))
  fi
  print
done

res=(
  "$success successful test script${${success:#1}:+s}"
  "$failure failure${${failure:#1}:+s}"
  "$skipped skipped"
)
resln=${(j<, >)res}
rule=${resln//?/\*}

[[ -n $ZTST_failcolour ]] &&
if (( failure )); then
  col=red
elif (( success )); then
  col=green
else
  col=yellow
fi

(( $#col )) && print -rnP - "%F{$col}"
print -rl - $rule $resln
(( $#ffiles )) &&
print -rl - '' "failing test script${${#ffiles:#1}:+s}:" ${(@)ffiles/#/  }
print -rl - $rule
(( $#col )) && print -rnP - %f

return $(( failure ? 1 : 0 ))