diff options
Diffstat (limited to 'scripts/lib/timing-extract.awk')
| -rw-r--r-- | scripts/lib/timing-extract.awk | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/scripts/lib/timing-extract.awk b/scripts/lib/timing-extract.awk new file mode 100644 index 0000000..9cb15d7 --- /dev/null +++ b/scripts/lib/timing-extract.awk @@ -0,0 +1,32 @@ +# scripts/lib/timing-extract.awk +# Extract per-test durations from bats JUnit report XML. +# +# Emits TSV: "<seconds>\t<suite>\t<test name>" for each <testcase>. +# The caller sorts and renders. Handles testcase elements that span the line +# regardless of whether they are self-closing or contain <failure> children. + +function attr(line, key, re, s) { + re = key "=\"" + if (index(line, re) == 0) return "" + s = line + sub(".*" re, "", s) # drop up to opening quote + sub(/".*/, "", s) # drop from closing quote + return s +} + +function unesc(s) { + gsub(/"/, "\"", s) + gsub(/'/, "'", s) + gsub(/</, "<", s) + gsub(/>/, ">", s) + gsub(/&/, "\\&", s) + return s +} + +/<testcase[ \t]/ { + name = unesc(attr($0, "name")) + cls = unesc(attr($0, "classname")) + t = attr($0, "time") + if (t == "") t = "0" + printf "%s\t%s\t%s\n", t, cls, name +} |
