Fossil SCM

Test runner changes: fossil_raw from Dan Mestas for full binary control plus some helper procedures; global variable protection and changes from Dan Shearer. Update test suite docs.

danshearer 2026-11-24 09:51 UTC test-suite-new
Commit 5862da0a752ef3cc1e84229f4c136a0f32071f6ab26ad46556f65bb250bbbc5d
2 files changed +22 -2 +141 -10
+22 -2
--- test/README.md
+++ test/README.md
@@ -125,10 +125,29 @@
125125
Each `NAME.test` file is a Tcl script sourced by `tester.tcl`. `test_setup` creates and opens a repository in a temporary directory. `fossil ARGS` runs the
126126
executable being tested and sets `RESULT` to its output and `CODE` to 0 if the command succeeded and did not write anything to standard error, or 1 otherwise. `test_eq NAME ACTUAL EXPECTED` and `test_match NAME ACTUAL PATTERN`
127127
report both values when they fail, and `test NAME EXPRESSION` gives the report. `test_skip REASON` skips the rest of the file, `test_skip_part REASON`
128128
reports a few skipped tests while the file continues, and `test_fail_then_return NAME
129129
REASON` records a failed setup step and stops the file. A last argument of `knownBug` to any of the `test` procedures marks a known bug as described above.
130
+
131
+`fossil_raw ARGS` also runs the executable, for the tests `fossil` can't
132
+do. It sets `RESULT` to standard output and standard error together, as
133
+bytes, and `CODE` to the exit status, to `crash` if a signal ended the
134
+command, or to `timeout`. A failed command isn't reported as an error, so
135
+check `CODE` yourself. Use it when you need:
136
+
137
+* the output byte for byte, such as CRLF line endings or binary content
138
+* the exit status, or to tell a crash from a failure
139
+* text on standard error from a command that succeeds
140
+* standard input, with `-input TEXT`
141
+* a time limit, with `-seconds N`. The default is 600.
142
+* a server in the test's own Tcl. The Tcl event loop runs while the
143
+ command does, so a `socket -server` in your test file can answer it.
144
+
145
+`holds_strings TEXT WANTED` returns 1 if `TEXT` has every string in the
146
+list `WANTED`, where a string starting with `!` must be absent.
147
+`test_start_server` takes options for `fossil server` after its second
148
+argument.
130149
131150
## Maintaining the tests
132151
133152
First step is noticing bugs. One pattern is when Fossil's output changes causing tests that rely on changed output to fail. `tester.tcl` prints the expected and the actual text for each but this won't always be obvious. It's possible that output changes may mask a code failure too.
134153
@@ -140,16 +159,17 @@
140159
141160
A test marked `knownBug` should fail on every applicable system. If the fault only shows up in some environments, the test must set up the relevant environment. If Fossil really does behave differently on some system depending how the system is configured (for example decomposed pathnames on macOS, which vary depending whether the filesystem is HFS+ or APFS) the test must check the behavior. The test suite avoids operating system names by testing for behaviors instead, wherever possible. If a test needs something the system might not have, that becomes a requirement and you can use `test_skip` for.
142161
143162
`fixed_word_lines NLINE` is a procedure in `tester.tcl` that returns generated text as a string, the same text on every run. `delta1.test` and `merge2.test` use it for their input. If your new test needs text to work on start with this. Look at delta and merge tests for examples of how to use this with character encodings.
144163
145
-Beware of global variables! If you feel you really have to create a new global variable, be sure there isn't a collision with other files. Some future design
146
-of tester.tcl should avoid this problem.
164
+Beware of global variables! `tester.tcl` removes on exit any globals a test file
165
+creates. A global defined by `tester.tcl`, such as `RESULT`, is still shared, so
166
+don't reuse one of those.
147167
148168
`make test` runs only the `.test` files. The other scripts in `test/` are run by hand:
149169
150170
* `release-checklist.wiki` lists the checks to make before a release, with the `.wiki` and `.md` pages they use.
151171
* `many-www.tcl` requests about 10,000 web pages from an open checkout with `fossil test-http` and times each, to find crashes and slow pages. `valgrind-www.tcl` requests hundreds of pages under valgrind to find memory errors.
152172
* `update-test-1.sh` and `update-test-2.sh` run `fossil update` scenarios in an empty directory.
153173
* `link-tester.html` steps through a list of links in `fossil ui`, for checking each page by eye.
154174
155175
The remaining files are helper scripts and test data.
156176
--- test/README.md
+++ test/README.md
@@ -125,10 +125,29 @@
125 Each `NAME.test` file is a Tcl script sourced by `tester.tcl`. `test_setup` creates and opens a repository in a temporary directory. `fossil ARGS` runs the
126 executable being tested and sets `RESULT` to its output and `CODE` to 0 if the command succeeded and did not write anything to standard error, or 1 otherwise. `test_eq NAME ACTUAL EXPECTED` and `test_match NAME ACTUAL PATTERN`
127 report both values when they fail, and `test NAME EXPRESSION` gives the report. `test_skip REASON` skips the rest of the file, `test_skip_part REASON`
128 reports a few skipped tests while the file continues, and `test_fail_then_return NAME
129 REASON` records a failed setup step and stops the file. A last argument of `knownBug` to any of the `test` procedures marks a known bug as described above.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
131 ## Maintaining the tests
132
133 First step is noticing bugs. One pattern is when Fossil's output changes causing tests that rely on changed output to fail. `tester.tcl` prints the expected and the actual text for each but this won't always be obvious. It's possible that output changes may mask a code failure too.
134
@@ -140,16 +159,17 @@
140
141 A test marked `knownBug` should fail on every applicable system. If the fault only shows up in some environments, the test must set up the relevant environment. If Fossil really does behave differently on some system depending how the system is configured (for example decomposed pathnames on macOS, which vary depending whether the filesystem is HFS+ or APFS) the test must check the behavior. The test suite avoids operating system names by testing for behaviors instead, wherever possible. If a test needs something the system might not have, that becomes a requirement and you can use `test_skip` for.
142
143 `fixed_word_lines NLINE` is a procedure in `tester.tcl` that returns generated text as a string, the same text on every run. `delta1.test` and `merge2.test` use it for their input. If your new test needs text to work on start with this. Look at delta and merge tests for examples of how to use this with character encodings.
144
145 Beware of global variables! If you feel you really have to create a new global variable, be sure there isn't a collision with other files. Some future design
146 of tester.tcl should avoid this problem.
 
147
148 `make test` runs only the `.test` files. The other scripts in `test/` are run by hand:
149
150 * `release-checklist.wiki` lists the checks to make before a release, with the `.wiki` and `.md` pages they use.
151 * `many-www.tcl` requests about 10,000 web pages from an open checkout with `fossil test-http` and times each, to find crashes and slow pages. `valgrind-www.tcl` requests hundreds of pages under valgrind to find memory errors.
152 * `update-test-1.sh` and `update-test-2.sh` run `fossil update` scenarios in an empty directory.
153 * `link-tester.html` steps through a list of links in `fossil ui`, for checking each page by eye.
154
155 The remaining files are helper scripts and test data.
156
--- test/README.md
+++ test/README.md
@@ -125,10 +125,29 @@
125 Each `NAME.test` file is a Tcl script sourced by `tester.tcl`. `test_setup` creates and opens a repository in a temporary directory. `fossil ARGS` runs the
126 executable being tested and sets `RESULT` to its output and `CODE` to 0 if the command succeeded and did not write anything to standard error, or 1 otherwise. `test_eq NAME ACTUAL EXPECTED` and `test_match NAME ACTUAL PATTERN`
127 report both values when they fail, and `test NAME EXPRESSION` gives the report. `test_skip REASON` skips the rest of the file, `test_skip_part REASON`
128 reports a few skipped tests while the file continues, and `test_fail_then_return NAME
129 REASON` records a failed setup step and stops the file. A last argument of `knownBug` to any of the `test` procedures marks a known bug as described above.
130
131 `fossil_raw ARGS` also runs the executable, for the tests `fossil` can't
132 do. It sets `RESULT` to standard output and standard error together, as
133 bytes, and `CODE` to the exit status, to `crash` if a signal ended the
134 command, or to `timeout`. A failed command isn't reported as an error, so
135 check `CODE` yourself. Use it when you need:
136
137 * the output byte for byte, such as CRLF line endings or binary content
138 * the exit status, or to tell a crash from a failure
139 * text on standard error from a command that succeeds
140 * standard input, with `-input TEXT`
141 * a time limit, with `-seconds N`. The default is 600.
142 * a server in the test's own Tcl. The Tcl event loop runs while the
143 command does, so a `socket -server` in your test file can answer it.
144
145 `holds_strings TEXT WANTED` returns 1 if `TEXT` has every string in the
146 list `WANTED`, where a string starting with `!` must be absent.
147 `test_start_server` takes options for `fossil server` after its second
148 argument.
149
150 ## Maintaining the tests
151
152 First step is noticing bugs. One pattern is when Fossil's output changes causing tests that rely on changed output to fail. `tester.tcl` prints the expected and the actual text for each but this won't always be obvious. It's possible that output changes may mask a code failure too.
153
@@ -140,16 +159,17 @@
159
160 A test marked `knownBug` should fail on every applicable system. If the fault only shows up in some environments, the test must set up the relevant environment. If Fossil really does behave differently on some system depending how the system is configured (for example decomposed pathnames on macOS, which vary depending whether the filesystem is HFS+ or APFS) the test must check the behavior. The test suite avoids operating system names by testing for behaviors instead, wherever possible. If a test needs something the system might not have, that becomes a requirement and you can use `test_skip` for.
161
162 `fixed_word_lines NLINE` is a procedure in `tester.tcl` that returns generated text as a string, the same text on every run. `delta1.test` and `merge2.test` use it for their input. If your new test needs text to work on start with this. Look at delta and merge tests for examples of how to use this with character encodings.
163
164 Beware of global variables! `tester.tcl` removes on exit any globals a test file
165 creates. A global defined by `tester.tcl`, such as `RESULT`, is still shared, so
166 don't reuse one of those.
167
168 `make test` runs only the `.test` files. The other scripts in `test/` are run by hand:
169
170 * `release-checklist.wiki` lists the checks to make before a release, with the `.wiki` and `.md` pages they use.
171 * `many-www.tcl` requests about 10,000 web pages from an open checkout with `fossil test-http` and times each, to find crashes and slow pages. `valgrind-www.tcl` requests hundreds of pages under valgrind to find memory errors.
172 * `update-test-1.sh` and `update-test-2.sh` run `fossil update` scenarios in an empty directory.
173 * `link-tester.html` steps through a list of links in `fossil ui`, for checking each page by eye.
174
175 The remaining files are helper scripts and test data.
176
+141 -10
--- test/tester.tcl
+++ test/tester.tcl
@@ -247,10 +247,123 @@
247247
protOut "RESULT ($rc): $result"
248248
}
249249
set RESULT $result
250250
}
251251
252
+# Run the Fossil program with the arguments ARGS. fossil_raw does not
253
+# report a failed command as an error, which the "fossil" procedure does.
254
+# Use it where a test reads the output as bytes, expects text on
255
+# standard error, gives fossil input, or has to tell a crash from a
256
+# failure. ARGS can begin with either or both of these options:
257
+#
258
+# -seconds N Kill fossil after N seconds. The default is 600.
259
+# -input TEXT Give fossil TEXT on standard input. The default is
260
+# an empty standard input.
261
+#
262
+# Sets RESULT to standard output and standard error together, as bytes.
263
+# Sets CODE to the exit status, to "crash" when a signal ended fossil, or
264
+# to "timeout" when fossil was killed at the time limit. The Tcl event
265
+# loop runs while fossil does, so a server that the test file has made
266
+# with "socket -server" can answer fossil.
267
+#
268
+proc fossil_raw {args} {
269
+ global fossilexe RESULT CODE LASTCMD fossilRawState
270
+ set seconds 600
271
+ set input ""
272
+ while {[lindex $args 0] in {-seconds -input}} {
273
+ set args [lassign $args option value]
274
+ switch -- $option {
275
+ -seconds {set seconds $value}
276
+ -input {set input $value}
277
+ }
278
+ }
279
+ set LASTCMD [list fossil {*}$args]
280
+ protOut $LASTCMD
281
+ flush stdout
282
+
283
+ set RESULT ""
284
+ set fossilRawState running
285
+ set pipe [open "|[list $fossilexe {*}$args << $input 2>@1]" rb]
286
+ fconfigure $pipe -blocking 0
287
+ fileevent $pipe readable [list fossil_raw_read $pipe]
288
+ set timer [after [expr {$seconds*1000}] {set fossilRawState late}]
289
+ vwait fossilRawState
290
+ after cancel $timer
291
+
292
+ if {$fossilRawState eq "late"} {
293
+ fossil_raw_kill $pipe
294
+ set CODE timeout
295
+ } else {
296
+ set CODE [fossil_raw_status $pipe]
297
+ }
298
+ if {$::VERBOSE} {
299
+ protOut "RESULT ($CODE): $RESULT"
300
+ }
301
+}
302
+
303
+# Adds what fossil has written on PIPE to RESULT, and ends the wait in
304
+# fossil_raw when fossil has closed its output.
305
+#
306
+proc fossil_raw_read {pipe} {
307
+ append ::RESULT [read $pipe]
308
+ if {[eof $pipe]} {set ::fossilRawState done}
309
+}
310
+
311
+# Kills the fossil process that writes to PIPE.
312
+#
313
+proc fossil_raw_kill {pipe} {
314
+ foreach process [pid $pipe] {
315
+ if {$::is_windows} {
316
+ catch {exec taskkill /F /PID $process}
317
+ } else {
318
+ catch {exec kill -9 $process}
319
+ }
320
+ }
321
+ catch {close $pipe}
322
+}
323
+
324
+# Closes PIPE and returns the exit status of its fossil process, or
325
+# "crash" when a signal ended the process.
326
+#
327
+proc fossil_raw_status {pipe} {
328
+ fconfigure $pipe -blocking 1
329
+ if {![catch {close $pipe} message options]} {
330
+ return 0
331
+ }
332
+ lassign [dict get $options -errorcode] kind process status
333
+ return [expr {$kind eq "CHILDSTATUS" ? $status : "crash"}]
334
+}
335
+
336
+# Returns 1 if TEXT holds every string in WANTED, and 0 otherwise. A
337
+# string in WANTED that begins with "!" must be absent from TEXT.
338
+#
339
+proc holds_strings {text wanted} {
340
+ foreach string $wanted {
341
+ if {[string index $string 0] eq "!"} {
342
+ if {[string first [string range $string 1 end] $text] >= 0} {return 0}
343
+ } elseif {[string first $string $text] < 0} {
344
+ return 0
345
+ }
346
+ }
347
+ return 1
348
+}
349
+
350
+proc test_standin {name destination} {
351
+ file copy -force [file join $::testfiledir standin $name] $destination
352
+ file attributes $destination -permissions 0755
353
+ return $destination
354
+}
355
+
356
+# The cards with which a sync client and a sync server state their
357
+# version, for a test that writes a request or a reply. A server treats
358
+# a client that does not send the card as older than 2.0, and does not
359
+# send it SHA3 hashes.
360
+#
361
+set XFER_VERSION "22900 20261110 124827"
362
+set CLIENT_VERSION_CARD "pragma client-version $XFER_VERSION\n"
363
+set SERVER_VERSION_CARD "pragma server-version $XFER_VERSION\n"
364
+
252365
# Read a file into memory.
253366
#
254367
proc read_file {filename} {
255368
set in [open $filename r]
256369
fconfigure $in -translation binary
@@ -724,13 +837,13 @@
724837
}
725838
}
726839
}
727840
728841
# Single-test wrapper for the above.
729
-proc test_in_checkout { name rscript tscript } {
730
- uplevel 1 [list test_block_in_checkout $name $rscript \
731
- [list test $name $tscript]]
842
+proc test_in_checkout { name rscript tscript args } {
843
+ return [uplevel 1 [list test_block_in_checkout $name $rscript \
844
+ [list test $name $tscript {*}$args]]]
732845
}
733846
734847
# Normalize file status lists (like those returned by 'fossil changes')
735848
# so they can be compared using simple string comparison
736849
#
@@ -943,11 +1056,11 @@
9431056
#
9441057
# The file is divided into blocks of $blocksize lines each. The first
9451058
# block is number 0. Changes are only made within blocks where
9461059
# the block number divided by $count has a remainder of $index.
9471060
#
948
-# For any given line that mets the block count criteria, the probably
1061
+# For any given line that meets the block count criteria, the probability
9491062
# of a change is $prob
9501063
#
9511064
# Changes do not add or remove newlines
9521065
#
9531066
proc random_changes {body blocksize count index prob} {
@@ -1040,12 +1153,13 @@
10401153
10411154
# This procedure executes the "fossil server" command. The return value
10421155
# is a list comprised of the new process identifier and the port on which
10431156
# the server started. The varName argument refers to a variable
10441157
# where the "stop argument" is to be stored. This value must eventually be
1045
-# passed to the [test_stop_server] procedure.
1046
-proc test_start_server { repository {varName ""} } {
1158
+# passed to the [test_stop_server] procedure. Any further arguments are
1159
+# options for "fossil server".
1160
+proc test_start_server { repository {varName ""} args } {
10471161
global fossilexe tempPath
10481162
set command [list exec $fossilexe server --localhost]
10491163
if {[string length $varName] > 0} {
10501164
upvar 1 $varName stopArg
10511165
}
@@ -1055,11 +1169,11 @@
10551169
lappend command --stopper $stopArg
10561170
}
10571171
set outFileName [file join $tempPath [appendArgs \
10581172
fossil_server_ [string trim [clock seconds] -] _ \
10591173
[getSeqNo]]].out
1060
- lappend command $repository >&$outFileName &
1174
+ lappend command {*}$args $repository >&$outFileName &
10611175
set pid [eval $command]
10621176
if {!$::is_windows} {
10631177
set stopArg $pid
10641178
}
10651179
# The server prints its port in a line such as "Listening for HTTP
@@ -1124,11 +1238,11 @@
11241238
}
11251239
11261240
# Executes the "fossil http" command. The entire content of the HTTP request
11271241
# is read from the data file name, with [subst] being performed on it prior to
11281242
# submission. Temporary input and output files are created and deleted. The
1129
-# result will be the contents of the temoprary output file.
1243
+# result will be the contents of the temporary output file.
11301244
proc test_fossil_http { repository dataFileName url } {
11311245
set suffix [appendArgs [pid] - [getSeqNo] - [clock seconds] .txt]
11321246
set inFileName [file join $::tempPath [appendArgs test-http-in- $suffix]]
11331247
set outFileName [file join $::tempPath [appendArgs test-http-out- $suffix]]
11341248
set data [subst [read_file $dataFileName]]
@@ -1211,12 +1325,12 @@
12111325
12121326
set tempHomePath [file join $tempPath home_[pid]]
12131327
12141328
# Close stdin to avoid errors on wrapped text for narrow terminals.
12151329
# Closing stdin means that terminal detection returns 0 width, in turn
1216
-# causing the relvant strings to be printed on a single line.
1217
-# However, closing stdin makes file descriptor 0 avaailable on some systems
1330
+# causing the relevant strings to be printed on a single line.
1331
+# However, closing stdin makes file descriptor 0 available on some systems
12181332
# and/or TCL implementations, which triggers fossil to complain about opening
12191333
# databases using fd 0. Avoid this by opening the script, consuming fd 0.
12201334
close stdin
12211335
set possibly_fd0 [open [info script] r]
12221336
@@ -1240,12 +1354,28 @@
12401354
set ::tempKeepHome 1
12411355
12421356
# Start in tempHomePath to help avoid errors with require_no_open_checkout
12431357
set startPwd [pwd]
12441358
cd $tempHomePath
1359
+
1360
+# Remove every global variable that is not in the list BEFORE, apart from
1361
+# the ones that Tcl makes for itself. Run after each test file, this
1362
+# stops a variable that one test file sets from changing what a later
1363
+# test file does.
1364
+#
1365
+proc unset_new_globals {before} {
1366
+ foreach name [info globals] {
1367
+ if {$name in $before} continue
1368
+ if {[regexp {^(tcl_|auto_|error)} $name]} continue
1369
+ uplevel #0 [list unset -nocomplain $name]
1370
+ }
1371
+}
1372
+set seqNo 0
12451373
12461374
foreach testfile $argv {
1375
+ set globalsBefore [info globals]
1376
+ lappend globalsBefore globalsBefore
12471377
protOut "***** $testfile ******"
12481378
if { [catch {source $testfiledir/$testfile.test} testerror testopts] } {
12491379
test_report test-framework-$testfile 0 "" [list "error: $testerror"]
12501380
protOut "!!!!! $testfile: $testerror"
12511381
protOutDict $testopts
@@ -1256,10 +1386,11 @@
12561386
}
12571387
} else {
12581388
test test-framework-$testfile 1
12591389
}
12601390
protOut "***** End of $testfile: [llength $bad_test] errors so far ******"
1391
+ unset_new_globals $globalsBefore
12611392
}
12621393
cd $startPwd
12631394
unset ::tempKeepHome; delete_temporary_home
12641395
12651396
# Clean up the file descriptor
12661397
--- test/tester.tcl
+++ test/tester.tcl
@@ -247,10 +247,123 @@
247 protOut "RESULT ($rc): $result"
248 }
249 set RESULT $result
250 }
251
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
252 # Read a file into memory.
253 #
254 proc read_file {filename} {
255 set in [open $filename r]
256 fconfigure $in -translation binary
@@ -724,13 +837,13 @@
724 }
725 }
726 }
727
728 # Single-test wrapper for the above.
729 proc test_in_checkout { name rscript tscript } {
730 uplevel 1 [list test_block_in_checkout $name $rscript \
731 [list test $name $tscript]]
732 }
733
734 # Normalize file status lists (like those returned by 'fossil changes')
735 # so they can be compared using simple string comparison
736 #
@@ -943,11 +1056,11 @@
943 #
944 # The file is divided into blocks of $blocksize lines each. The first
945 # block is number 0. Changes are only made within blocks where
946 # the block number divided by $count has a remainder of $index.
947 #
948 # For any given line that mets the block count criteria, the probably
949 # of a change is $prob
950 #
951 # Changes do not add or remove newlines
952 #
953 proc random_changes {body blocksize count index prob} {
@@ -1040,12 +1153,13 @@
1040
1041 # This procedure executes the "fossil server" command. The return value
1042 # is a list comprised of the new process identifier and the port on which
1043 # the server started. The varName argument refers to a variable
1044 # where the "stop argument" is to be stored. This value must eventually be
1045 # passed to the [test_stop_server] procedure.
1046 proc test_start_server { repository {varName ""} } {
 
1047 global fossilexe tempPath
1048 set command [list exec $fossilexe server --localhost]
1049 if {[string length $varName] > 0} {
1050 upvar 1 $varName stopArg
1051 }
@@ -1055,11 +1169,11 @@
1055 lappend command --stopper $stopArg
1056 }
1057 set outFileName [file join $tempPath [appendArgs \
1058 fossil_server_ [string trim [clock seconds] -] _ \
1059 [getSeqNo]]].out
1060 lappend command $repository >&$outFileName &
1061 set pid [eval $command]
1062 if {!$::is_windows} {
1063 set stopArg $pid
1064 }
1065 # The server prints its port in a line such as "Listening for HTTP
@@ -1124,11 +1238,11 @@
1124 }
1125
1126 # Executes the "fossil http" command. The entire content of the HTTP request
1127 # is read from the data file name, with [subst] being performed on it prior to
1128 # submission. Temporary input and output files are created and deleted. The
1129 # result will be the contents of the temoprary output file.
1130 proc test_fossil_http { repository dataFileName url } {
1131 set suffix [appendArgs [pid] - [getSeqNo] - [clock seconds] .txt]
1132 set inFileName [file join $::tempPath [appendArgs test-http-in- $suffix]]
1133 set outFileName [file join $::tempPath [appendArgs test-http-out- $suffix]]
1134 set data [subst [read_file $dataFileName]]
@@ -1211,12 +1325,12 @@
1211
1212 set tempHomePath [file join $tempPath home_[pid]]
1213
1214 # Close stdin to avoid errors on wrapped text for narrow terminals.
1215 # Closing stdin means that terminal detection returns 0 width, in turn
1216 # causing the relvant strings to be printed on a single line.
1217 # However, closing stdin makes file descriptor 0 avaailable on some systems
1218 # and/or TCL implementations, which triggers fossil to complain about opening
1219 # databases using fd 0. Avoid this by opening the script, consuming fd 0.
1220 close stdin
1221 set possibly_fd0 [open [info script] r]
1222
@@ -1240,12 +1354,28 @@
1240 set ::tempKeepHome 1
1241
1242 # Start in tempHomePath to help avoid errors with require_no_open_checkout
1243 set startPwd [pwd]
1244 cd $tempHomePath
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1245
1246 foreach testfile $argv {
 
 
1247 protOut "***** $testfile ******"
1248 if { [catch {source $testfiledir/$testfile.test} testerror testopts] } {
1249 test_report test-framework-$testfile 0 "" [list "error: $testerror"]
1250 protOut "!!!!! $testfile: $testerror"
1251 protOutDict $testopts
@@ -1256,10 +1386,11 @@
1256 }
1257 } else {
1258 test test-framework-$testfile 1
1259 }
1260 protOut "***** End of $testfile: [llength $bad_test] errors so far ******"
 
1261 }
1262 cd $startPwd
1263 unset ::tempKeepHome; delete_temporary_home
1264
1265 # Clean up the file descriptor
1266
--- test/tester.tcl
+++ test/tester.tcl
@@ -247,10 +247,123 @@
247 protOut "RESULT ($rc): $result"
248 }
249 set RESULT $result
250 }
251
252 # Run the Fossil program with the arguments ARGS. fossil_raw does not
253 # report a failed command as an error, which the "fossil" procedure does.
254 # Use it where a test reads the output as bytes, expects text on
255 # standard error, gives fossil input, or has to tell a crash from a
256 # failure. ARGS can begin with either or both of these options:
257 #
258 # -seconds N Kill fossil after N seconds. The default is 600.
259 # -input TEXT Give fossil TEXT on standard input. The default is
260 # an empty standard input.
261 #
262 # Sets RESULT to standard output and standard error together, as bytes.
263 # Sets CODE to the exit status, to "crash" when a signal ended fossil, or
264 # to "timeout" when fossil was killed at the time limit. The Tcl event
265 # loop runs while fossil does, so a server that the test file has made
266 # with "socket -server" can answer fossil.
267 #
268 proc fossil_raw {args} {
269 global fossilexe RESULT CODE LASTCMD fossilRawState
270 set seconds 600
271 set input ""
272 while {[lindex $args 0] in {-seconds -input}} {
273 set args [lassign $args option value]
274 switch -- $option {
275 -seconds {set seconds $value}
276 -input {set input $value}
277 }
278 }
279 set LASTCMD [list fossil {*}$args]
280 protOut $LASTCMD
281 flush stdout
282
283 set RESULT ""
284 set fossilRawState running
285 set pipe [open "|[list $fossilexe {*}$args << $input 2>@1]" rb]
286 fconfigure $pipe -blocking 0
287 fileevent $pipe readable [list fossil_raw_read $pipe]
288 set timer [after [expr {$seconds*1000}] {set fossilRawState late}]
289 vwait fossilRawState
290 after cancel $timer
291
292 if {$fossilRawState eq "late"} {
293 fossil_raw_kill $pipe
294 set CODE timeout
295 } else {
296 set CODE [fossil_raw_status $pipe]
297 }
298 if {$::VERBOSE} {
299 protOut "RESULT ($CODE): $RESULT"
300 }
301 }
302
303 # Adds what fossil has written on PIPE to RESULT, and ends the wait in
304 # fossil_raw when fossil has closed its output.
305 #
306 proc fossil_raw_read {pipe} {
307 append ::RESULT [read $pipe]
308 if {[eof $pipe]} {set ::fossilRawState done}
309 }
310
311 # Kills the fossil process that writes to PIPE.
312 #
313 proc fossil_raw_kill {pipe} {
314 foreach process [pid $pipe] {
315 if {$::is_windows} {
316 catch {exec taskkill /F /PID $process}
317 } else {
318 catch {exec kill -9 $process}
319 }
320 }
321 catch {close $pipe}
322 }
323
324 # Closes PIPE and returns the exit status of its fossil process, or
325 # "crash" when a signal ended the process.
326 #
327 proc fossil_raw_status {pipe} {
328 fconfigure $pipe -blocking 1
329 if {![catch {close $pipe} message options]} {
330 return 0
331 }
332 lassign [dict get $options -errorcode] kind process status
333 return [expr {$kind eq "CHILDSTATUS" ? $status : "crash"}]
334 }
335
336 # Returns 1 if TEXT holds every string in WANTED, and 0 otherwise. A
337 # string in WANTED that begins with "!" must be absent from TEXT.
338 #
339 proc holds_strings {text wanted} {
340 foreach string $wanted {
341 if {[string index $string 0] eq "!"} {
342 if {[string first [string range $string 1 end] $text] >= 0} {return 0}
343 } elseif {[string first $string $text] < 0} {
344 return 0
345 }
346 }
347 return 1
348 }
349
350 proc test_standin {name destination} {
351 file copy -force [file join $::testfiledir standin $name] $destination
352 file attributes $destination -permissions 0755
353 return $destination
354 }
355
356 # The cards with which a sync client and a sync server state their
357 # version, for a test that writes a request or a reply. A server treats
358 # a client that does not send the card as older than 2.0, and does not
359 # send it SHA3 hashes.
360 #
361 set XFER_VERSION "22900 20261110 124827"
362 set CLIENT_VERSION_CARD "pragma client-version $XFER_VERSION\n"
363 set SERVER_VERSION_CARD "pragma server-version $XFER_VERSION\n"
364
365 # Read a file into memory.
366 #
367 proc read_file {filename} {
368 set in [open $filename r]
369 fconfigure $in -translation binary
@@ -724,13 +837,13 @@
837 }
838 }
839 }
840
841 # Single-test wrapper for the above.
842 proc test_in_checkout { name rscript tscript args } {
843 return [uplevel 1 [list test_block_in_checkout $name $rscript \
844 [list test $name $tscript {*}$args]]]
845 }
846
847 # Normalize file status lists (like those returned by 'fossil changes')
848 # so they can be compared using simple string comparison
849 #
@@ -943,11 +1056,11 @@
1056 #
1057 # The file is divided into blocks of $blocksize lines each. The first
1058 # block is number 0. Changes are only made within blocks where
1059 # the block number divided by $count has a remainder of $index.
1060 #
1061 # For any given line that meets the block count criteria, the probability
1062 # of a change is $prob
1063 #
1064 # Changes do not add or remove newlines
1065 #
1066 proc random_changes {body blocksize count index prob} {
@@ -1040,12 +1153,13 @@
1153
1154 # This procedure executes the "fossil server" command. The return value
1155 # is a list comprised of the new process identifier and the port on which
1156 # the server started. The varName argument refers to a variable
1157 # where the "stop argument" is to be stored. This value must eventually be
1158 # passed to the [test_stop_server] procedure. Any further arguments are
1159 # options for "fossil server".
1160 proc test_start_server { repository {varName ""} args } {
1161 global fossilexe tempPath
1162 set command [list exec $fossilexe server --localhost]
1163 if {[string length $varName] > 0} {
1164 upvar 1 $varName stopArg
1165 }
@@ -1055,11 +1169,11 @@
1169 lappend command --stopper $stopArg
1170 }
1171 set outFileName [file join $tempPath [appendArgs \
1172 fossil_server_ [string trim [clock seconds] -] _ \
1173 [getSeqNo]]].out
1174 lappend command {*}$args $repository >&$outFileName &
1175 set pid [eval $command]
1176 if {!$::is_windows} {
1177 set stopArg $pid
1178 }
1179 # The server prints its port in a line such as "Listening for HTTP
@@ -1124,11 +1238,11 @@
1238 }
1239
1240 # Executes the "fossil http" command. The entire content of the HTTP request
1241 # is read from the data file name, with [subst] being performed on it prior to
1242 # submission. Temporary input and output files are created and deleted. The
1243 # result will be the contents of the temporary output file.
1244 proc test_fossil_http { repository dataFileName url } {
1245 set suffix [appendArgs [pid] - [getSeqNo] - [clock seconds] .txt]
1246 set inFileName [file join $::tempPath [appendArgs test-http-in- $suffix]]
1247 set outFileName [file join $::tempPath [appendArgs test-http-out- $suffix]]
1248 set data [subst [read_file $dataFileName]]
@@ -1211,12 +1325,12 @@
1325
1326 set tempHomePath [file join $tempPath home_[pid]]
1327
1328 # Close stdin to avoid errors on wrapped text for narrow terminals.
1329 # Closing stdin means that terminal detection returns 0 width, in turn
1330 # causing the relevant strings to be printed on a single line.
1331 # However, closing stdin makes file descriptor 0 available on some systems
1332 # and/or TCL implementations, which triggers fossil to complain about opening
1333 # databases using fd 0. Avoid this by opening the script, consuming fd 0.
1334 close stdin
1335 set possibly_fd0 [open [info script] r]
1336
@@ -1240,12 +1354,28 @@
1354 set ::tempKeepHome 1
1355
1356 # Start in tempHomePath to help avoid errors with require_no_open_checkout
1357 set startPwd [pwd]
1358 cd $tempHomePath
1359
1360 # Remove every global variable that is not in the list BEFORE, apart from
1361 # the ones that Tcl makes for itself. Run after each test file, this
1362 # stops a variable that one test file sets from changing what a later
1363 # test file does.
1364 #
1365 proc unset_new_globals {before} {
1366 foreach name [info globals] {
1367 if {$name in $before} continue
1368 if {[regexp {^(tcl_|auto_|error)} $name]} continue
1369 uplevel #0 [list unset -nocomplain $name]
1370 }
1371 }
1372 set seqNo 0
1373
1374 foreach testfile $argv {
1375 set globalsBefore [info globals]
1376 lappend globalsBefore globalsBefore
1377 protOut "***** $testfile ******"
1378 if { [catch {source $testfiledir/$testfile.test} testerror testopts] } {
1379 test_report test-framework-$testfile 0 "" [list "error: $testerror"]
1380 protOut "!!!!! $testfile: $testerror"
1381 protOutDict $testopts
@@ -1256,10 +1386,11 @@
1386 }
1387 } else {
1388 test test-framework-$testfile 1
1389 }
1390 protOut "***** End of $testfile: [llength $bad_test] errors so far ******"
1391 unset_new_globals $globalsBefore
1392 }
1393 cd $startPwd
1394 unset ::tempKeepHome; delete_temporary_home
1395
1396 # Clean up the file descriptor
1397

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button