~dricottone/my-utils

ref: 86e36bedac92f051a285f01385f38446a71db9a6 my-utils/clean-unittest.awk -rwxr-xr-x 907 bytes
86e36bedDominic Ricottone Small fixes recommended by shellcheck 5 years ago
                                                                                
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
#!/usr/bin/awk -f

# clean-unittest.awk
# ==================
# Usage: python -m unittest | clean-unittest.awk
#
# Clean output of Python's unittest

BEGIN { last_testcase="PROBABLYWILLNOTMATCH"; blank_lines=0; first_line=1 }
{
  if ($0 ~ /^ *$/) {
    if (blank_lines == 0 && first_line == 0) {
      print $0
    }
    blank_lines+=1
  }
  else if ($0 ~ /^test/) {
    blank_lines=0
    if ($0 !~ last_testcase) {
      split($0, last_array, "[()]")
      last_testcase=last_array[2]
      print last_testcase
    }
    sub(/ \(.*\) /, " ")
    $0="  " $0
    print $0
  }
  else if ($0 ~ /Ran [0-9]+ tests in [0-9]+.[0-9]+s/) {
    num_tests=$0
  }
  else if ($0 ~ /^FAIL: / || $0 ~ /^ERROR: /) {
    blank_lines=0
    print "\n" $0
  }
  else if ($0 ~ /^OK$/ || $0 ~ /^FAILED /) {
    blank_lines=0
    print num_tests " ... " $0
  }
  else if ($0 !~ /^ *[-=]+ *$/) {
    print $0
  }
  first_line=0
}