1
#!/bin/sh
2
#shellcheck disable=SC2004,SC2016
3

4 0
set -euf
5

6 0
interrupt=''
7 0
"$SHELLSPEC_TRAP" 'interrupt=1' INT
8 0
"$SHELLSPEC_TRAP" '' TERM
9

10 0
echo $$ > "$SHELLSPEC_REPORTER_PID"
11

12
# shellcheck source=lib/libexec/reporter.sh
13 0
. "${SHELLSPEC_LIB:-./lib}/libexec/reporter.sh"
14

15 0
import "formatter"
16 0
import "color_schema"
17 0
color_constants
18

19 0
found_focus='' no_examples='' aborted=1 repetition='' coverage_failed='' \
20
fail_fast='' fail_fast_count=${SHELLSPEC_FAIL_FAST_COUNT:-999999} reason='' \
21
current_example_index=0 example_index='' \
22
last_example_no='' last_skip_id='' not_enough_examples=''
23

24
# shellcheck disable=SC2034
25 0
specfile_count=0 expected_example_count=0 example_count=0 \
26
succeeded_count='' failed_count='' warned_count='' error_count='' \
27
todo_count='' fixed_count='' skipped_count='' error_index='' \
28
suppressed_todo_count='' suppressed_fixed_count='' suppressed_skipped_count=''
29

30
# shellcheck disable=SC2034
31 0
field_id='' field_type='' field_tag='' field_example_no='' field_focused='' \
32
field_temporary='' field_skipid='' field_pending='' field_message='' \
33
field_quick='' field_specfile='' field_stdout='' field_stderr=''
34

35 0
init_quick_data
36

37 0
[ "$SHELLSPEC_GENERATORS" ] && mkdir -p "$SHELLSPEC_REPORTDIR"
38

39
# shellcheck disable=SC2086
40 0
load_formatter "${SHELLSPEC_FORMATTER:-debug}" $SHELLSPEC_GENERATORS
41

42 0
formatters initialize "$@"
43 0
generators prepare "$@"
44 0
[ "$SHELLSPEC_XTRACE" ] && require_formatters trace
45

46 0
output_formatters begin
47

48
reporter_callback() {
49 0
  case $field_type in
50
    begin)
51 0
      field_example_count='' last_example_no=0 \
52
      last_skip_id='' suppress_pending=''
53 0
      inc specfile_count
54
      # shellcheck disable=SC2034
55 0
      example_count_per_file=0 succeeded_count_per_file=0 \
56
      failed_count_per_file=0 warned_count_per_file=0 todo_count_per_file=0 \
57
      fixed_count_per_file=0 skipped_count_per_file=0 error_count_per_file=0
58
      ;;
59
    example)
60
      # shellcheck disable=SC2034
61 0
      field_evaluation='' field_pending='' reason='' temporary_skip=0
62 0
      [ "$field_example_no" -le "$last_example_no" ] && repetition=1 && return 0
63 0
      [ "$field_focused" = "focus" ] && found_focus=1
64 0
      example_index='' last_example_no=$field_example_no
65
      ;;
66
    statement)
67 0
      while :; do
68
        # Do not add references if example_index is blank
69 0
        case $field_tag in
70 0
          evaluation) break ;;
71
          good)
72 0
            [ "$field_pending" ] || break
73 0
            [ ! "$suppress_pending" ] || break
74
            ;;
75 0
          bad) [ ! "$suppress_pending" ] || break ;;
76
          pending)
77 0
            suppress_pending=1
78 0
            case $SHELLSPEC_PENDING_MESSAGE in (quiet)
79 0
              [ "$field_temporary" ] || break
80
            esac
81 0
            suppress_pending=''
82
            ;;
83
          skip)
84 0
            case $SHELLSPEC_SKIP_MESSAGE in (quiet)
85 0
              [ "$field_temporary" ] || break
86
            esac
87 0
            case $SHELLSPEC_SKIP_MESSAGE in (moderate | quiet)
88 0
              [ ! "$field_skipid" = "$last_skip_id" ] || break
89 0
              last_skip_id=$field_skipid
90
            esac
91 0
            inc temporary_skip
92
        esac
93

94
        # shellcheck disable=SC2034
95 0
        case $field_tag in (pending | skip)
96 0
          reason=$field_message
97
        esac
98

99 0
        if [ ! "$example_index" ]; then
100 0
          inc current_example_index
101 0
          example_index=$current_example_index
102
        fi
103 0
        break
104
      done
105
      ;;
106
    result)
107 0
      inc example_count example_count_per_file
108 0
      inc "${field_tag}_count" "${field_tag}_count_per_file"
109 0
      [ "${failed_count:-0}" -ge "$fail_fast_count" ] && aborted='' fail_fast=1
110

111 0
      case $field_tag in (skipped | fixed | todo)
112 0
        [ "$example_index" ] || inc "suppressed_${field_tag}_count"
113
      esac
114

115 0
      add_quick_data "$field_specfile:@$field_id" "$field_tag" "$field_quick"
116
      ;;
117
    end)
118
      # field_example_count not provided when range or filter option specified
119 0
      field_example_count=${field_example_count:-$example_count_per_file}
120 0
      expected_example_count=$(($expected_example_count + $field_example_count))
121 0
      if [ "$example_count_per_file" -ne "$field_example_count" ]; then
122 0
        not_enough_examples=${not_enough_examples:-0}
123 0
        not_enough_examples=$(($not_enough_examples + $field_example_count))
124 0
        not_enough_examples=$(($not_enough_examples - $example_count_per_file))
125
      fi
126
      ;;
127
    error)
128 0
      inc error_count error_count_per_file
129 0
      base26 error_index "$error_count"
130
      ;;
131
    finished)
132 0
      aborted=''
133 0
      if [ "$SHELLSPEC_FAIL_NO_EXAMPLES" ]; then
134 0
        [ "$example_count" -gt 0 ] || no_examples=1
135
      fi
136
  esac
137

138 0
  color_schema
139 0
  output_formatters each "$@"
140

141 0
  [ ! "${fail_fast}${interrupt}${repetition}" ]
142
}
143

144 0
tssv_parse "field" reporter_callback ||:
145

146 0
timeout 1 read_time_log "time" "$SHELLSPEC_TIME_LOG" ||:
147 0
read_time_log "time" "$SHELLSPEC_TIME_LOG" ||:
148

149 0
output_formatters end
150

151 0
generators cleanup "$@"
152 0
formatters finalize "$@"
153

154 0
if [ "$repetition" ]; then
155 0
  error "Illegal executed same example" \
156
    "in ${field_specfile:-} line ${field_lineno_range:-}${LF}" \
157
    "(Use 'parameterized example' instead of running the example in a loop)$LF"
158
fi
159

160 0
if [ "${SHELLSPEC_FOCUS_FILTER:-}" ]; then
161 0
  if [ ! "$found_focus" ]; then
162 0
    info "You specified --focus option, but not found any focused examples."
163 0
    info "To focus, prepend 'f' to groups / examples. (e.g. fDescribe, fIt)$LF"
164
  fi
165
else
166 0
  if [ "$found_focus" ]; then
167 0
    info "You need to specify --focus option" \
168
      "to run focused (underlined) example(s) only.$LF"
169
  fi
170
fi
171

172 0
if [ -e "$SHELLSPEC_QUICK_FILE" ] && [ ! "$interrupt" ]; then
173 0
  quick_file="$SHELLSPEC_QUICK_FILE" done=1
174 0
  [ "${aborted}${not_enough_examples}${fail_fast}" ] && done=''
175 0
  [ -e "$quick_file" ] && in_quick_file=$quick_file || in_quick_file=/dev/null
176 0
  quick_file_data=$(filter_quick_file "$done" "$@" < "$in_quick_file")
177 0
  if [ -s "$quick_file" ] && [ ! "$quick_file_data" ]; then
178 0
    info "All examples have been passed. Rerun to prevent regression.$LF"
179
  fi
180 0
  puts "$quick_file_data${quick_file_data:+"$LF"}" | sort > "$quick_file"
181
fi
182

183 0
if [ -e "$SHELLSPEC_DEPRECATION_LOGFILE" ]; then
184 0
  count=0 found='Found '
185 0
  while IFS= read -r line && inc count; do
186 0
    [ "$SHELLSPEC_DEPRECATION_LOG" ] && info "$line"
187 0
  done < "$SHELLSPEC_DEPRECATION_LOGFILE"
188 0
  pluralize found "$count deprecation"
189 0
  if [ "$SHELLSPEC_DEPRECATION_LOG" ]; then
190 0
    info "$found. Use --hide-deprecations to hide the details."
191
  else
192 0
    info "$found. Use --show-deprecations to show the details."
193
  fi
194
fi
195

196 0
if [ "$repetition" ]; then
197 0
  exit_status=$SHELLSPEC_ERROR_EXIT_CODE
198 0
elif [ "$interrupt" ]; then
199 0
  exit_status=130
200 0
elif [ "$aborted" ]; then
201 0
  exit_status=1
202 0
elif [ "$SHELLSPEC_FAIL_LOW_COVERAGE" ] && [ "$coverage_failed" ]; then
203 0
  exit_status=$SHELLSPEC_FAILURE_EXIT_CODE
204 0
elif [ "$SHELLSPEC_WARNING_AS_FAILURE" ] && [ "$warned_count" ]; then
205 0
  exit_status=$SHELLSPEC_FAILURE_EXIT_CODE
206 0
elif [ "${failed_count}${error_count}${fixed_count}" ]; then
207 0
  exit_status=$SHELLSPEC_FAILURE_EXIT_CODE
208 0
elif [ "${not_enough_examples}${no_examples}" ]; then
209 0
  exit_status=$SHELLSPEC_FAILURE_EXIT_CODE
210
else
211 0
  exit_status=0
212
fi
213

214 0
exit "$exit_status"

Read our documentation on viewing source code .

Loading