aboutsummaryrefslogtreecommitdiff
path: root/lib/test/output.sh
blob: 4b0968507e407567cef59fbd6b764ebec7c6db83 (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/bin/sh

  _bold=$(tput md)
  _rst=$(tput me)
  _red=$(tput AF 202)
  _redb=$(tput AF 202)
  _green=$(tput AF 2)
  _yellow=$(tput AF 3)
  _blue=$(tput AF 111)
  _darkgray=$(tput AF 8)
  _gray=$(tput AF 102)
  _orange=$(tput AF 214)

cloyster_test_log() {
#    >&2 echo -e "${_ctx}[${_logcontext}]${_rst} $@${_rst}"
    >&2 echo -e "$@${_rst}"
  }
  cloyster_test_debug() {
    if is_true "${DEBUG}"; then cloyster_test_log "🔵 ${_blue}${@}"; fi
  }
  cloyster_test_info() {
    cloyster_test_log "👍 ${@}"
  }
  cloyster_test_warn() {
    cloyster_test_log "⚠️  ${_bold}${_yellow}${@}"
  }
  cloyster_test_error() {
   cloyster_test_log "❌ ${_redb}${@}"
  }


_echo_block=
_echo_block_per_line=25
_echo_block_count=
_echo_block_init() {
  _echo_block=y
  _echo_block_count=1
}
_echo_block() {
  if is_true "${_echo_block}"; then
    _echo_block_count=$((${_echo_block_count} + 1))
    case $1 in
      success) e="🟩";;
      skipped) e="🟦";;
      failed) e="🟥";;
      ignored) e="🟧";;
      *) e="⬛";;
    esac
    if [ "${_echo_block_count}" -le "${_echo_block_per_line}" ]; then
      echo -n "${e}"
    else
      _echo_block_count=1
      echo "${e}"
    fi
  fi
}
_echo_block_flush() {
  if is_true "${_echo_block}"; then
      _echo_block=
      _echo_block_count=
      echo ""
  fi
}

_test_output_overview() {
  if [ -n "${_cloyster_test_tests_failed}" ]; then
    color="${_redb}"
    accent="${_bold}${_redb}"
    emoji="❌"
    title="FAILED"
  else
    color="${_green}"
    accent="${_bold}${_green}"
    emoji="✅"
    title="PASSED"
  fi

  cloyster_test_log "${emoji} ${_bold}${_yellow}${CLOYSTER_COMMAND}${_rst} ${color}tests${_rst} ${accent}${title}${_rst}"
  _greenb=$(tput AF 154)
  _gray=$(tput AF 8)
  echo -n "${emoji} ${_bold}${_cloyster_test_tests_counter_count} tests${_rst}, ${_bold}${_greenb}${_cloyster_test_tests_counter_success} ok${_rst}"
  if [ ! "${_cloyster_test_tests_counter_failed}" = "0" ]; then
    echo -n ", ${_bold}${_redb}${_cloyster_test_tests_counter_failed} failed${_rst}"
  fi
  if [ ! "${_cloyster_test_tests_counter_ignored}" = "0" ]; then
    echo -n ", ${_bold}${_orange}${_cloyster_test_tests_counter_ignored} ignored${_rst}"
  fi
  if [ ! "${_cloyster_test_tests_counter_skipped}" = "0" ]; then
    echo -n ", ${_bold}${_blue}${_cloyster_test_tests_counter_skipped} skipped${_rst}"
  fi
  echo -n " ${_gray}in ${duration}ms${_rst}"
  echo -e "${_rst}"
}

_test_output_results() {
  list=${1:-"success skipped ignored failed"}
  for t in ${list}; do _test_output_results_one "${t}"; done
}

_test_output_results_one() {
  key=$1
  cnt=0
  count=$(readvar "_cloyster_test_tests_counter_${key}")

  case $key in
    success) color="${_green}"; type="SUCCESS"; emoji="👍"; logcolor=$(tput AF 64);;
    skipped) color="${_blue}"; type="SKIPPED"; emoji="🙈"; logcolor=$(tput AF 111);;
    failed) color="${_red}"; type="FAILED"; emoji="😡"; logcolor=$(tput AF 181);;
    ignored) color="${_orange}"; type="IGNORED"; emoji="🥲"; logcolor=$(tput 130);;
    *) color="${_yellow}"; type="TEST"; emoji="💩"; logcolor=${_yellow};;
  esac

  for id in $(readvar "_cloyster_test_tests_${key}"); do
     cnt=$(( $cnt + 1 ))
     name=$(readvar "_cloyster_test_tests_${id}__name")
     args=$(readvar "_cloyster_test_tests_${id}__args")
     lineno=$(readvar "_cloyster_test_tests_${id}__line")
     status=$(readvar "_cloyster_test_tests_${id}__status")
     args_s=; lineno_s=; status_s=; line=
     args_s=" [${args}]"
     if [ -n "${lineno}" ] && [ ! "${lineno}" = "0" ]; then lineno_s=" L#${lineno}"; fi
     if [ -n "${status}" ]; then status_s=" !${status}"; fi
     line="\n${emoji} ${_bold}${color}${type} ${cnt}/${count}:${_rst} ${_bold}${name}${_rst}"
     line="${line}${_gray}${args_s}${_darkgray}${lineno_s}${status_s}${_rst}"
     echo -e "${line}"
     cat "${_tmp_dir}/test_${id}.log" | while read -r line; do
       echo -e "   ${logcolor}> ${line}${_rst}"
     done
  done
}