From 4f49b16079b27d7ce633619e4cddfdf2bffbc952 Mon Sep 17 00:00:00 2001 From: cashmere Date: Fri, 4 Sep 2026 09:05:24 +0200 Subject: initial commit --- test/rewrite-test-output.tcl | 645 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 645 insertions(+) create mode 100644 test/rewrite-test-output.tcl (limited to 'test/rewrite-test-output.tcl') diff --git a/test/rewrite-test-output.tcl b/test/rewrite-test-output.tcl new file mode 100644 index 0000000..600b43a --- /dev/null +++ b/test/rewrite-test-output.tcl @@ -0,0 +1,645 @@ +#!/usr/bin/env tclsh + +# Script to anonymise test results for comparison. +# - Replaces hashes, pids and similar with fixed strings +# - Rewrites temporary paths to standardise them in output + +# Pick up options +set EXTRA 0 +set i [lsearch $argv -extra] +while { $i >= 0 } { + incr EXTRA + set argv [lreplace $argv $i $i] + set i [lsearch $argv -extra] +} + +# With no arguments or "-", use stdin. +set fname "-" +if { [llength $argv] > 0 } { + set fname [lindex $argv 0] +} + +# Any -options, or an empty first argument, is an error. +if { [llength $argv] > 1 || [regexp {^-.+} $fname] } { + puts stderr "Error: argument error" + puts stderr "usage: \[-extra\] [file tail $argv0] ?FILE" + puts stderr " Rewrite test output to ease comparison of outputs." + puts stderr " With -extra, more output is rewritten as is summaries" + puts stderr " to make diff(1) mor euseful across runs and platforms." + exit 1 +} elseif { $fname ne "-" && ! [file exists $fname] } { + puts stderr "File does not exist: '$fname'" + exit 1 +} + +proc common_rewrites { line testname } { + # Normalise the fossil commands with path as just fossil + regsub {^(?:[A-Z]:)?/.*?/fossil(?:\.exe)? } $line {fossil } line + if {[string match "Usage: *" $line]} { + regsub {^(Usage: )/.*?/fossil(?:\.exe)? } $line {\1fossil } line + regsub {^(Usage: )[A-Z]:\\.*?\\fossil(?:\.exe)? } $line {\1fossil } line + } + + # Accept 40 and 64 byte hashes as such + regsub -all {[[:<:]][0-9a-f]{40}[[:>:]]} $line HASH line + regsub -all {[[:<:]][0-9a-f]{64}[[:>:]]} $line HASH line + + # Date and time + regsub -all {[[:<:]]\d{4}-\d\d-\d\d \d\d:\d\d:\d\d[[:>:]]} $line {YYYY-mm-dd HH:MM:SS} line + if { [lsearch -exact {"amend" "wiki"} $testname] >= 0 } { + # With embedded T and milliseconds + regsub { \d{4}-\d\d-\d\dT\d\d:\d\d:\d\d\.\d{3}$} $line { YYYY-mm-ddTHH:MM:SS.NNN} line + } + if { [lsearch -exact {"amend" "th1-hooks" "wiki"} $testname] >= 0 } { + regsub {[[:<:]]\d{4}-\d\d-\d\d[[:>:]]} $line {YYYY-mm-dd} line + } + + # Timelines have HH:MM:SS [HASH], but don't mess with the zero'ed version. + regsub {^(?!00:00:00 \[0000000000\])\d\d:\d\d:\d\d \[[0-9a-f]{10}\] } $line {HH:MM:SS [HASH] } line + + # Temporary directories + regsub -all {(?:[A-Z]:)?/.*?/repo_\d+/\d+_\d+} $line {/TMP/repo_PID/SEC_SEQ} line + # Home directories only seem present with .fossil or _fossil. Simplify to .fossil. + regsub -all {(?:[A-Z]:)?/.*?/home_\d+/[._]fossil[[:>:]]} $line {/TMP/home_PID/.fossil} line + + # Users in output + regsub { (\(user: )[^\)]*\)$} $line { \1USER)} line + + return $line +} + +# +# tests/tests_unix/tests_windows contain tuples of +# +# 1. A regular expression to match current line +# 2. A substitution for the current line +# +# Some common patterns applicable to multiples tests are appended below. +# +# The common_rewrites procedure is run first, so use e.g. HASH as needed. +# + +dict set tests "amend" { + {^(fossil artifact) [0-9a-f]{10}} + {\1 HASH} + {^U [^ ]+$} + {U USER} + {^Z [0-9a-f]{32}$} + {Z CHECKSUM} + {^(ed -s \./ci-comment-).*?(\.txt)$} + {\1UNIQ\2} + {^(fossil amend HASH -date \{?)\d\d/\d\d/\d{4}} + {\1dd/mm/YYYY} + {^(fossil amend HASH -date \{.* )\d{4}(\})$} + {\1YYYY\2} + {^(fossil amend HASH -date \{.* )\d\d:} + {\1HH:} + {^(fossil amend HASH -date \{)[A-Z][a-z]{2} [A-Z][a-z]{2} [ 0-9]\d } + {\1Day Mon dd } + {(\] Edit \[)[0-9a-f]{16}.[0-9a-f]{10}(\]: )} + {\1HASH1|HASH2\2} + {(\] Edit \[.*?&dp=)[0-9a-f]{16}} + {\1dp=HASH} +} + +dict set tests "cmdline" { + {^(fossil test-echo --args) .*/} + {\1 /TMP/} + {^(g\.nameOfExe =) \[[^\]]+[/\\]fossil(?:\.exe)?\]$} + {\1 [/PATH/FOSSILCMD]} + {^(argv\[0\] =) \[[^\]]+[/\\]fossil(?:\.exe)?\]$} + {\1 [/PATH/FOSSILCMD]} +} + +dict set tests "contains-selector" { + {^(fossil test-contains-selector) .*?/(compare-selector.css )} + {\1 /TMP/\2} +} + +dict set tests "json" { + {^(Content-Length) \d+$} + {\1 LENGTH} + {^(Cookie: fossil-)[0-9a-f]{16}(\=HASH%2F)\d+\.\d+(%2Fanonymous)$} + {\1CODE\2NOW\3} + {^(GET /json/cap\?authToken\=HASH)/\d+\.\d+/(anonymous )} + {\1/NOW/\2} + {^(Cookie: fossil-)[0-9a-f]{16}\=[0-9A-F]{50}%2F[0-9a-f]{16}%2F(.*)$} + {\1CODE=SHA1%2FCODE%2F\2} + {("authToken":").+?(")} + {\1AUTHTOKEN\2} + {("averageArtifactSize":)\d+()} + {\1SIZE\2} + {("compiler":").+?(")} + {\1COMPILER\2} + {("loginCookieName":").+?(")} + {\1COOKIE\2} + {("manifestVersion":"\[)[0-9a-f]{10}(\]")} + {\1HASH\2} + {("manifestYear":")\d{4}(")} + {\1YYYY\2} + {("name":").+?(")} + {\1NAME\2} + {("password":")[0-9a-f]+(")} + {\1PASSWORD\2} + {("projectCode":")[0-9a-f]{40}(")} + {\1HASH\2} + {("procTimeMs":)\d+} + {\1MSEC} + {("procTimeUs":)\d+} + {\1USEC} + {("releaseVersion":")\d+\.\d+(")} + {\1VERSION\2} + {("releaseVersionNumber":")\d+(")} + {\1VERSION_NUMBER\2} + {("timestamp":)\d+} + {\1SEC} + {("seed":)\d+()} + {\1SEED\2} + {("uid":)\d+()} + {\1UID\2} + {("uncompressedArtifactSize":)\d+()} + {\1SIZE\2} + {("user":").+?(")} + {\1USER\2} + {("version":"YYYY-mm-dd HH:MM:SS )\[[0-9a-f]{10}\] \(\d+\.\d+\.\d+\)"} + {\1[HASH] (major.minor.patch)} + {^(Date:) [A-Z][a-z]{2}, \d\d? [A-Z][a-z]{2} \d{4} \d\d:\d\d:\d\d [-+]\d{4}$} + {\1 Day, dd Mon YYYY HH:MM:SS TZ} +} + +dict set tests "merge_renames" { + {^(size: {7})\d+( bytes)$} + {\1N\2} + {^(type: {7}Check-in by ).+?( on YYYY-mm-dd HH:MM:SS)$} + {\1USER\2} +} + +dict set tests "set-manifest" { + {^(project-code: )[0-9a-f]{40}$} + {\1HASH} line +} + +dict set tests "stash" { + {^(---|\+\+\+) NUL$} + {\1 /dev/null} + {(^ 1: \[)[0-9a-f]{14}(\] on YYYY-mm-dd HH:MM:SS)$} + {\1HASH\2} + {(^ 1: \[)[0-9a-f]{14}(\] from YYYY-mm-dd HH:MM:SS)$} + {\1HASH\2} +} + +dict set tests "th1" { + {^(fossil test-th-source) (?:[A-Z]:)?.*?/(th1-)\d+([.]th1)$} + {\1 /TMP/\2PID\3} + {^(?:[A-Z]:)?[/\\].*?[/\\]fossil(?:\.exe)?$} + {/PATH/FOSSILCMD} + {[[:<:]](Content-Security-Policy[[:>:]].*'nonce-)[0-9a-f]{48}(';)} + {\1NONCE\2} + {^()$} + {\1ID\2} + {^\d+\.\d{3}(s by)$} + {N.MMM\1} + {^(Fossil) \d+\.\d+ \[[0-9a-f]{10}\] (YYYY-mm-dd HH:MM:SS)$} + {\1 N.M [HASH] \2} + {^(