# Compare two ==CASE==-delimited transcripts and print one verdict line per # case: "ok ", "diff line N oracle<...> target<...>", or # "missing ...". First file is the oracle, second the target. # # One awk pass rather than a file-per-case split and a cmp per case: that # shape costs 262 file creations and 131 forks, and this platform does not # return memory on process exit (brintos/linux#21, brintos/hardwarejs#20). # Shipped as a file so both on-target suites run the SAME comparator rather # than two copies of it that can drift apart. NR == FNR { if ($0 ~ /^==CASE /) { n = $2; sub(/==$/, "", n); order[++nc] = n; cur = n; e[n] = ""; next } if ($0 ~ /^==END /) { cur = ""; next } if (cur != "") e[cur] = e[cur] $0 "\n" next } { if ($0 ~ /^==CASE /) { n = $2; sub(/==$/, "", n); cur = n; a[n] = ""; seen[n] = 1; next } if ($0 ~ /^==END /) { cur = ""; next } if (cur != "") a[cur] = a[cur] $0 "\n" } END { for (i = 1; i <= nc; i++) { n = order[i] if (!(n in seen)) { printf "missing %s the target transcript has no such case\n", n; continue } if (e[n] == a[n]) { printf "ok %s\n", n; continue } # The FIRST differing line, not the head of each block: both blocks # routinely open with the same several lines, so a head-of-block detail # truncates to two identical strings and says nothing about what differs. ne = split(e[n], ea, "\n"); na = split(a[n], aa, "\n") m = (ne > na ? ne : na) for (k = 1; k <= m; k++) if (ea[k] != aa[k]) { printf "diff %s line %d oracle<%s> target<%s>\n", n, k, ea[k], aa[k] break } } }