aboutsummaryrefslogtreecommitdiff
path: root/scripts/lib/timing-extract.awk
blob: 9cb15d74f2763ab5a5fc9a8336136b92b2dea29f (plain)
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
# 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(/&quot;/, "\"", s)
  gsub(/&apos;/, "'", s)
  gsub(/&lt;/,  "<", s)
  gsub(/&gt;/,  ">", s)
  gsub(/&amp;/, "\\&", 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
}