| 1 | #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash |
| 2 | set -e |
| 3 | |
| 4 | # Just stream the TAP output (sans extended syntax) if tput is missing |
| 5 | command -v tput >/dev/nullscip-shell filesystem . . `/dev/null`. || exec grep -v "^begin " |
| 6 | |
| 7 | header_pattern='[0-9]+\.\.[0-9]+' |
| 8 | IFS= read -r header |
| 9 | |
| 10 | if [[ "$header" =~ $header_pattern ]]; then |
| 11 | count="${header:3}" |
| 12 | index=0 |
| 13 | failures=0 |
| 14 | skipped=0 |
| 15 | name="" |
| 16 | count_column_width=$(( ${#count} * 2 + 2 )) |
| 17 | else |
| 18 | # If the first line isn't a TAP plan, print it and pass the rest through |
| 19 | printfscip-shell system . . printf. "%s\n" "$header" |
| 20 | exec cat |
| 21 | fi |
| 22 | |
| 23 | update_screen_widthscip-shell shell shell-project 0.0.0 update_screen_width().() { |
| 24 | screen_width="$(tputscip-shell system . . tput. cols)" |
| 25 | count_column_left=$(( $screen_width - $count_column_width )) |
| 26 | } |
| 27 | |
| 28 | trap update_screen_width WINCH |
| 29 | update_screen_widthscip-shell shell shell-project 0.0.0 update_screen_width(). |
| 30 | |
| 31 | beginscip-shell shell shell-project 0.0.0 begin().() { |
| 32 | go_to_columnscip-shell shell shell-project 0.0.0 go_to_column(). 0 |
| 33 | printf_with_truncationscip-shell shell shell-project 0.0.0 printf_with_truncation(). $(( $count_column_left - 1 )) " %s" "$name" |
| 34 | clear_to_end_of_linescip-shell shell shell-project 0.0.0 clear_to_end_of_line(). |
| 35 | go_to_columnscip-shell shell shell-project 0.0.0 go_to_column(). $count_column_left |
| 36 | printfscip-shell system . . printf. "%${#count}s/${count}" "$index" |
| 37 | go_to_columnscip-shell shell shell-project 0.0.0 go_to_column(). 1 |
| 38 | } |
| 39 | |
| 40 | passscip-shell shell shell-project 0.0.0 pass().() { |
| 41 | go_to_columnscip-shell shell shell-project 0.0.0 go_to_column(). 0 |
| 42 | printfscip-shell system . . printf. " ✓ %s" "$name" |
| 43 | advancescip-shell shell shell-project 0.0.0 advance(). |
| 44 | } |
| 45 | |
| 46 | skipscip-shell shell shell-project 0.0.0 skip().() { |
| 47 | local reason="$1" |
| 48 | [scip-shell system . . `[`. -z "$reason" ] || reason=": $reason" |
| 49 | go_to_columnscip-shell shell shell-project 0.0.0 go_to_column(). 0 |
| 50 | printfscip-shell system . . printf. " - %s (skipped%s)" "$name" "$reason" |
| 51 | advancescip-shell shell shell-project 0.0.0 advance(). |
| 52 | } |
| 53 | |
| 54 | failscip-shell shell shell-project 0.0.0 fail().() { |
| 55 | go_to_columnscip-shell shell shell-project 0.0.0 go_to_column(). 0 |
| 56 | set_colorscip-shell shell shell-project 0.0.0 set_color(). 1 bold |
| 57 | printfscip-shell system . . printf. " ✗ %s" "$name" |
| 58 | advancescip-shell shell shell-project 0.0.0 advance(). |
| 59 | } |
| 60 | |
| 61 | logscip-shell shell shell-project 0.0.0 log().() { |
| 62 | set_colorscip-shell shell shell-project 0.0.0 set_color(). 1 |
| 63 | printfscip-shell system . . printf. " %s\n" "$1" |
| 64 | clear_colorscip-shell shell shell-project 0.0.0 clear_color(). |
| 65 | } |
| 66 | |
| 67 | summaryscip-shell shell shell-project 0.0.0 summary().() { |
| 68 | printfscip-shell system . . printf. "\n%d test%s" "$count" "$(plural "$count")" |
| 69 | |
| 70 | printfscip-shell system . . printf. ", %d failure%s" "$failures" "$(plural "$failures")" |
| 71 | |
| 72 | if [scip-shell system . . `[`. "$skipped" -gt 0 ]; then |
| 73 | printfscip-shell system . . printf. ", %d skipped" "$skipped" |
| 74 | fi |
| 75 | |
| 76 | printfscip-shell system . . printf. "\n" |
| 77 | } |
| 78 | |
| 79 | printf_with_truncationscip-shell shell shell-project 0.0.0 printf_with_truncation().() { |
| 80 | local width="$1" |
| 81 | shift |
| 82 | local string="$(printfscip-shell system . . printf. "$@")" |
| 83 | |
| 84 | if [scip-shell system . . `[`. "${#string}" -gt "$width" ]; then |
| 85 | printfscip-shell system . . printf. "%s..." "${string:0:$(( $width - 4 ))}" |
| 86 | else |
| 87 | printfscip-shell system . . printf. "%s" "$string" |
| 88 | fi |
| 89 | } |
| 90 | |
| 91 | go_to_columnscip-shell shell shell-project 0.0.0 go_to_column().() { |
| 92 | local column="$1" |
| 93 | printfscip-shell system . . printf. "\x1B[%dG" $(( $column + 1 )) |
| 94 | } |
| 95 | |
| 96 | clear_to_end_of_linescip-shell shell shell-project 0.0.0 clear_to_end_of_line().() { |
| 97 | printfscip-shell system . . printf. "\x1B[K" |
| 98 | } |
| 99 | |
| 100 | advancescip-shell shell shell-project 0.0.0 advance().() { |
| 101 | clear_to_end_of_linescip-shell shell shell-project 0.0.0 clear_to_end_of_line(). |
| 102 | echoscip-shell system . . echo. |
| 103 | clear_colorscip-shell shell shell-project 0.0.0 clear_color(). |
| 104 | } |
| 105 | |
| 106 | set_colorscip-shell shell shell-project 0.0.0 set_color().() { |
| 107 | local color="$1" |
| 108 | local weight="$2" |
| 109 | printfscip-shell system . . printf. "\x1B[%d;%dm" $(( 30 + $color )) "$( [scip-shell system . . `[`. "$weight" = "bold" ] && echoscip-shell system . . echo. 1 || echoscip-shell system . . echo. 22 )" |
| 110 | } |
| 111 | |
| 112 | clear_colorscip-shell shell shell-project 0.0.0 clear_color().() { |
| 113 | printfscip-shell system . . printf. "\x1B[0m" |
| 114 | } |
| 115 | |
| 116 | pluralscip-shell shell shell-project 0.0.0 plural().() { |
| 117 | [scip-shell system . . `[`. "$1" -eq 1 ] || echoscip-shell system . . echo. "s" |
| 118 | } |
| 119 | |
| 120 | _buffer="" |
| 121 | |
| 122 | bufferscip-shell shell shell-project 0.0.0 buffer().() { |
| 123 | _buffer="${_buffer}$("$@")" |
| 124 | } |
| 125 | |
| 126 | flushscip-shell shell shell-project 0.0.0 flush().() { |
| 127 | printfscip-shell system . . printf. "%s" "$_buffer" |
| 128 | _buffer="" |
| 129 | } |
| 130 | |
| 131 | finishscip-shell shell shell-project 0.0.0 finish().() { |
| 132 | flushscip-shell shell shell-project 0.0.0 flush(). |
| 133 | printfscip-shell system . . printf. "\n" |
| 134 | } |
| 135 | |
| 136 | trap finish EXIT |
| 137 | |
| 138 | while IFS= read -r line; do |
| 139 | case "$line" in |
| 140 | "begin "* ) |
| 141 | let index+=1 |
| 142 | name="${line#* $index }" |
| 143 | bufferscip-shell shell shell-project 0.0.0 buffer(). begin |
| 144 | flushscip-shell shell shell-project 0.0.0 flush(). |
| 145 | ;; |
| 146 | "ok "* ) |
| 147 | skip_expr="ok $index # skip (\(([^)]*)\))?" |
| 148 | if [[ "$line" =~ $skip_expr ]]; then |
| 149 | let skipped+=1 |
| 150 | bufferscip-shell shell shell-project 0.0.0 buffer(). skip "${BASH_REMATCH[2]}" |
| 151 | else |
| 152 | bufferscip-shell shell shell-project 0.0.0 buffer(). pass |
| 153 | fi |
| 154 | ;; |
| 155 | "not ok "* ) |
| 156 | let failures+=1 |
| 157 | bufferscip-shell shell shell-project 0.0.0 buffer(). fail |
| 158 | ;; |
| 159 | "# "* ) |
| 160 | bufferscip-shell shell shell-project 0.0.0 buffer(). log "${line:2}" |
| 161 | ;; |
| 162 | esac |
| 163 | done |
| 164 | |
| 165 | bufferscip-shell shell shell-project 0.0.0 buffer(). summary |