1#!/bin/sh 2xtest | awk ' 3 4 # Escapes the special characters in a string so that, when 5 # included in a regex, it represents a literal match 6 function regx_escape_literal(str, ret) { 7 ret = str 8 gsub(/[\[\]\^\$\.\*\?\+\{\}\\\(\)\|]/ , "\\\\&", str) 9 return str 10 } 11 12 # Returns the simple test formatted name 13 function name(n, ret) { 14 ret = n 15 gsub(/\./, " ", ret) 16 return ret 17 } 18 19 # Returns the simple test formatted result 20 function result(res) { 21 if(res ~ /OK/) { 22 return "PASS" 23 } else if(res ~ /FAILED/) { 24 return "FAIL" 25 } 26 } 27 28 function parse(name, description, has_subtests, result_line) { 29 has_subtests = 0 30 31 # Consume every line up to the result line 32 result_line = " " regx_escape_literal(name) " (OK|FAILED)" 33 do { 34 getline 35 36 # If this is a subtest (denoted by an "o" bullet) then subparse 37 if($0 ~ /^o /) { 38 parse($2, description " : " substr($0, index($0, $3))) 39 has_subtests = 1 40 } 41 } while ($0 !~ result_line) 42 43 # Only print the results for the deepest nested subtests 44 if(!has_subtests) { 45 print result($2) ": " name(name) " - " description 46 } 47 } 48 49 # Start parsing at the beginning of every test (denoted by a "*" bullet) 50 /^\* / { parse($2, substr($0, index($0, $3))) } 51 52' 53