aboutsummaryrefslogtreecommitdiff
path: root/scripts/lib/timing-extract.awk
diff options
context:
space:
mode:
authorAlexander M Pickering <alex@cogarr.net>2026-07-21 20:19:46 -0500
committerAlexander M Pickering <alex@cogarr.net>2026-07-21 20:19:46 -0500
commit657fb0007f39f07cc0401e0c5d03e25df6234aa4 (patch)
treef73fe23232dc80802f39caed738c38464a60ec6d /scripts/lib/timing-extract.awk
downloadtrbldoc-657fb0007f39f07cc0401e0c5d03e25df6234aa4.tar.gz
trbldoc-657fb0007f39f07cc0401e0c5d03e25df6234aa4.tar.bz2
trbldoc-657fb0007f39f07cc0401e0c5d03e25df6234aa4.zip
Inital commit.
Diffstat (limited to 'scripts/lib/timing-extract.awk')
-rw-r--r--scripts/lib/timing-extract.awk32
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(/&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
+}