summaryrefslogtreecommitdiffstats
path: root/_testing/report-test.zsh
blob: 6c05f460013b37efd6286927b8171dc140851abd (plain)
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
67
#!/bin/zsh

local failmark="\e[31m✘\e[0m"
local passmark="\e[32m✔\e[0m"
local skipmark="\e[33m☡\e[0m"
local failed=0
local T=

if [[ $MARKDOWN_REPORT == 1 ]] {
    echo '## Irssi Scripts Test Report'
    # github started to block excess use of emojis
    #failmark=:x:
    #passmark=:white_check_mark:
    #skipmark=:construction:
    failmark=passmark=skipmark=T="|"
} \
else {
    echo '============================== TEST REPORT ============================='
}
printf "%32s $T LOAD $T HDR $T CRIT $T SCORE $T PASS\n"
if [[ $MARKDOWN_REPORT == 1 ]] {
 echo "----: $T :--: $T :-: $T :--: $T ----: $T :---:"
}
typeset -a cached_run
cached_run=()
REPORT_STAGE=yes
. ./_testing/_get_files_arr.zsh

typeset -A allow_fail
allow_fail=($(perl -MYAML::Tiny=LoadFile -e'print "$_ 1 " for @{LoadFile(+shift)->{whitelist}}' _testing/config.yml))

for scriptfile ($filelist) {
    if [[ $MARKDOWN_REPORT == 1 ]] { print -n '[' }
    printf "%32s " $scriptfile:t:r
    if [[ $MARKDOWN_REPORT == 1 ]] { print -n '](Test/'$scriptfile:t:r'/)' }
    print -n $T
    local pass=0
    if [[ -f "Test/${scriptfile:t:r}/failed.yml" ]] { print -n '  '$failmark'   ' } \
    else { print -n '  '$passmark'   '; ((++pass)) }; print -n $T
    if { grep -qs 'Severity: 6' "Test/${scriptfile:t:r}/perlcritic.log" } { print -n '  '$failmark'   ' } \
    else { print -n '  '$passmark'   '; ((++pass)) }; print -n $T
    if { grep -qs 'Code before strictures are enabled\|Two-argument "open" used' "Test/${scriptfile:t:r}/perlcritic.log" }  { print -n '  '$failmark'   ' } \
    else { print -n '  '$passmark'   '; ((++pass)) }; print -n $T
    perl -ne '$score += $1 -1 if /Severity: (\d+)/; END { printf "%3d", $score }' "Test/${scriptfile:t:r}/perlcritic.log" 2>/dev/null
    print -n '   '$T
    if [[ $pass -lt 3 ]]  {
	if [[ -n $allow_fail[$scriptfile:t:r] ]] {
	    print -n '  '$skipmark'   '
	} \
	else {
	    print -n '  '$failmark'   '
	    if [[ $failed -lt 254 ]] { ((++failed)) }
	}
    } \
    else {
	print -n '  '$passmark'   '; ((++pass))
	echo 1>"Test/${scriptfile:t:r}/passed"
    }
    if [[ $+cached_run[(r)$scriptfile] -gt 0 ]] {
        print -n $T' (c)'
    }
    echo
}
exit $failed