Fossil SCM
Factor out common test code into the 'tester.tcl' script.
Commit
666ec2eef2b6d829b9fc310555003f75d2d0e950
Parent
a313f031a48c451…
2 files changed
+57
+4
-50
+57
| --- test/tester.tcl | ||
| +++ test/tester.tcl | ||
| @@ -328,19 +328,76 @@ | ||
| 328 | 328 | } |
| 329 | 329 | append out \n$line |
| 330 | 330 | } |
| 331 | 331 | return [string range $out 1 end] |
| 332 | 332 | } |
| 333 | + | |
| 334 | +# Executes the "fossil http" command. The entire content of the HTTP request | |
| 335 | +# is read from the data file name, with [subst] being performed on it prior to | |
| 336 | +# submission. Temporary input and output files are created and deleted. The | |
| 337 | +# result will be the contents of the temoprary output file. | |
| 338 | +proc test_fossil_http { repository dataFileName url } { | |
| 339 | + set suffix [appendArgs [pid] - [getSeqNo] - [clock seconds] .txt] | |
| 340 | + set inFileName [file join $::tempPath [appendArgs test-http-in- $suffix]] | |
| 341 | + set outFileName [file join $::tempPath [appendArgs test-http-out- $suffix]] | |
| 342 | + set data [subst [read_file $dataFileName]] | |
| 343 | + | |
| 344 | + write_file $inFileName $data | |
| 345 | + fossil http $inFileName $outFileName 127.0.0.1 $repository | |
| 346 | + set result [expr {[file exists $outFileName] ? [read_file $outFileName] : ""}] | |
| 347 | + | |
| 348 | + if {1} then { | |
| 349 | + catch {file delete $inFileName} | |
| 350 | + catch {file delete $outFileName} | |
| 351 | + } | |
| 352 | + | |
| 353 | + return $result | |
| 354 | +} | |
| 333 | 355 | |
| 334 | 356 | # obtains and increments a "sequence number" for this test run. |
| 335 | 357 | proc getSeqNo {} { |
| 336 | 358 | upvar #0 seqNo seqNo |
| 337 | 359 | if {![info exists seqNo]} { |
| 338 | 360 | set seqNo 0 |
| 339 | 361 | } |
| 340 | 362 | return [incr seqNo] |
| 341 | 363 | } |
| 364 | + | |
| 365 | +# fixup the whitespace in the result to make it easier to compare. | |
| 366 | +proc normalize_result {} { | |
| 367 | + return [string map [list \r\n \n] [string trim $::RESULT]] | |
| 368 | +} | |
| 369 | + | |
| 370 | +# returns the first line of the normalized result. | |
| 371 | +proc first_data_line {} { | |
| 372 | + return [lindex [split [normalize_result] \n] 0] | |
| 373 | +} | |
| 374 | + | |
| 375 | +# returns the second line of the normalized result. | |
| 376 | +proc second_data_line {} { | |
| 377 | + return [lindex [split [normalize_result] \n] 1] | |
| 378 | +} | |
| 379 | + | |
| 380 | +# returns the third line of the normalized result. | |
| 381 | +proc third_data_line {} { | |
| 382 | + return [lindex [split [normalize_result] \n] 2] | |
| 383 | +} | |
| 384 | + | |
| 385 | +# returns the last line of the normalized result. | |
| 386 | +proc last_data_line {} { | |
| 387 | + return [lindex [split [normalize_result] \n] end] | |
| 388 | +} | |
| 389 | + | |
| 390 | +# returns the second to last line of the normalized result. | |
| 391 | +proc next_to_last_data_line {} { | |
| 392 | + return [lindex [split [normalize_result] \n] end-1] | |
| 393 | +} | |
| 394 | + | |
| 395 | +# returns the third to last line of the normalized result. | |
| 396 | +proc third_to_last_data_line {} { | |
| 397 | + return [lindex [split [normalize_result] \n] end-2] | |
| 398 | +} | |
| 342 | 399 | |
| 343 | 400 | protInit $fossilexe |
| 344 | 401 | foreach testfile $argv { |
| 345 | 402 | set dir [file root [file tail $testfile]] |
| 346 | 403 | file delete -force $dir |
| 347 | 404 |
| --- test/tester.tcl | |
| +++ test/tester.tcl | |
| @@ -328,19 +328,76 @@ | |
| 328 | } |
| 329 | append out \n$line |
| 330 | } |
| 331 | return [string range $out 1 end] |
| 332 | } |
| 333 | |
| 334 | # obtains and increments a "sequence number" for this test run. |
| 335 | proc getSeqNo {} { |
| 336 | upvar #0 seqNo seqNo |
| 337 | if {![info exists seqNo]} { |
| 338 | set seqNo 0 |
| 339 | } |
| 340 | return [incr seqNo] |
| 341 | } |
| 342 | |
| 343 | protInit $fossilexe |
| 344 | foreach testfile $argv { |
| 345 | set dir [file root [file tail $testfile]] |
| 346 | file delete -force $dir |
| 347 |
| --- test/tester.tcl | |
| +++ test/tester.tcl | |
| @@ -328,19 +328,76 @@ | |
| 328 | } |
| 329 | append out \n$line |
| 330 | } |
| 331 | return [string range $out 1 end] |
| 332 | } |
| 333 | |
| 334 | # Executes the "fossil http" command. The entire content of the HTTP request |
| 335 | # is read from the data file name, with [subst] being performed on it prior to |
| 336 | # submission. Temporary input and output files are created and deleted. The |
| 337 | # result will be the contents of the temoprary output file. |
| 338 | proc test_fossil_http { repository dataFileName url } { |
| 339 | set suffix [appendArgs [pid] - [getSeqNo] - [clock seconds] .txt] |
| 340 | set inFileName [file join $::tempPath [appendArgs test-http-in- $suffix]] |
| 341 | set outFileName [file join $::tempPath [appendArgs test-http-out- $suffix]] |
| 342 | set data [subst [read_file $dataFileName]] |
| 343 | |
| 344 | write_file $inFileName $data |
| 345 | fossil http $inFileName $outFileName 127.0.0.1 $repository |
| 346 | set result [expr {[file exists $outFileName] ? [read_file $outFileName] : ""}] |
| 347 | |
| 348 | if {1} then { |
| 349 | catch {file delete $inFileName} |
| 350 | catch {file delete $outFileName} |
| 351 | } |
| 352 | |
| 353 | return $result |
| 354 | } |
| 355 | |
| 356 | # obtains and increments a "sequence number" for this test run. |
| 357 | proc getSeqNo {} { |
| 358 | upvar #0 seqNo seqNo |
| 359 | if {![info exists seqNo]} { |
| 360 | set seqNo 0 |
| 361 | } |
| 362 | return [incr seqNo] |
| 363 | } |
| 364 | |
| 365 | # fixup the whitespace in the result to make it easier to compare. |
| 366 | proc normalize_result {} { |
| 367 | return [string map [list \r\n \n] [string trim $::RESULT]] |
| 368 | } |
| 369 | |
| 370 | # returns the first line of the normalized result. |
| 371 | proc first_data_line {} { |
| 372 | return [lindex [split [normalize_result] \n] 0] |
| 373 | } |
| 374 | |
| 375 | # returns the second line of the normalized result. |
| 376 | proc second_data_line {} { |
| 377 | return [lindex [split [normalize_result] \n] 1] |
| 378 | } |
| 379 | |
| 380 | # returns the third line of the normalized result. |
| 381 | proc third_data_line {} { |
| 382 | return [lindex [split [normalize_result] \n] 2] |
| 383 | } |
| 384 | |
| 385 | # returns the last line of the normalized result. |
| 386 | proc last_data_line {} { |
| 387 | return [lindex [split [normalize_result] \n] end] |
| 388 | } |
| 389 | |
| 390 | # returns the second to last line of the normalized result. |
| 391 | proc next_to_last_data_line {} { |
| 392 | return [lindex [split [normalize_result] \n] end-1] |
| 393 | } |
| 394 | |
| 395 | # returns the third to last line of the normalized result. |
| 396 | proc third_to_last_data_line {} { |
| 397 | return [lindex [split [normalize_result] \n] end-2] |
| 398 | } |
| 399 | |
| 400 | protInit $fossilexe |
| 401 | foreach testfile $argv { |
| 402 | set dir [file root [file tail $testfile]] |
| 403 | file delete -force $dir |
| 404 |
+4
-50
| --- test/th1-hooks.test | ||
| +++ test/th1-hooks.test | ||
| @@ -28,58 +28,10 @@ | ||
| 28 | 28 | |
| 29 | 29 | set env(TH1_ENABLE_HOOKS) 1; # TH1 hooks must be enabled for this test. |
| 30 | 30 | |
| 31 | 31 | ############################################################################### |
| 32 | 32 | |
| 33 | -proc fossil_th1_hook_http { repository url } { | |
| 34 | - set suffix [appendArgs [pid] - [getSeqNo] - [clock seconds] .txt] | |
| 35 | - set inFileName [file join $::tempPath [appendArgs test-http-in- $suffix]] | |
| 36 | - set outFileName [file join $::tempPath [appendArgs test-http-out- $suffix]] | |
| 37 | - set data [subst [read_file [file join $::testdir th1-hooks-input.txt]]] | |
| 38 | - | |
| 39 | - write_file $inFileName $data | |
| 40 | - fossil http $inFileName $outFileName 127.0.0.1 $repository | |
| 41 | - set result [expr {[file exists $outFileName] ? [read_file $outFileName] : ""}] | |
| 42 | - | |
| 43 | - if {1} then { | |
| 44 | - catch {file delete $inFileName} | |
| 45 | - catch {file delete $outFileName} | |
| 46 | - } | |
| 47 | - | |
| 48 | - return $result | |
| 49 | -} | |
| 50 | - | |
| 51 | -proc normalize_result {} { | |
| 52 | - return [string map [list \r\n \n] [string trim $::RESULT]] | |
| 53 | -} | |
| 54 | - | |
| 55 | -proc first_data_line {} { | |
| 56 | - return [lindex [split [normalize_result] \n] 0] | |
| 57 | -} | |
| 58 | - | |
| 59 | -proc second_data_line {} { | |
| 60 | - return [lindex [split [normalize_result] \n] 1] | |
| 61 | -} | |
| 62 | - | |
| 63 | -proc third_data_line {} { | |
| 64 | - return [lindex [split [normalize_result] \n] 2] | |
| 65 | -} | |
| 66 | - | |
| 67 | -proc last_data_line {} { | |
| 68 | - return [lindex [split [normalize_result] \n] end] | |
| 69 | -} | |
| 70 | - | |
| 71 | -proc next_to_last_data_line {} { | |
| 72 | - return [lindex [split [normalize_result] \n] end-1] | |
| 73 | -} | |
| 74 | - | |
| 75 | -proc third_to_last_data_line {} { | |
| 76 | - return [lindex [split [normalize_result] \n] end-2] | |
| 77 | -} | |
| 78 | - | |
| 79 | -############################################################################### | |
| 80 | - | |
| 81 | 33 | set testTh1Setup { |
| 82 | 34 | proc initialize_hook_log {} { |
| 83 | 35 | if {![info exists ::hook_log]} { |
| 84 | 36 | set ::hook_log "" |
| 85 | 37 | } |
| @@ -152,10 +104,12 @@ | ||
| 152 | 104 | regexp -line -- {^repository: (.*)$} $data dummy repository |
| 153 | 105 | |
| 154 | 106 | if {[string length $repository] == 0 || ![file exists $repository]} then { |
| 155 | 107 | error "unable to locate repository" |
| 156 | 108 | } |
| 109 | + | |
| 110 | +set dataFileName [file join $::testdir th1-hooks-input.txt] | |
| 157 | 111 | |
| 158 | 112 | ############################################################################### |
| 159 | 113 | |
| 160 | 114 | saveTh1SetupFile; writeTh1SetupFile $testTh1Setup |
| 161 | 115 | |
| @@ -216,23 +170,23 @@ | ||
| 216 | 170 | test th1-custom-cmd-4a {[string trim $RESULT] eq \ |
| 217 | 171 | {<h1><b>command_hook test4</b></h1>}} |
| 218 | 172 | |
| 219 | 173 | ############################################################################### |
| 220 | 174 | |
| 221 | -set RESULT [fossil_th1_hook_http $repository /timeline] | |
| 175 | +set RESULT [test_fossil_http $repository $dataFileName /timeline] | |
| 222 | 176 | test th1-web-hooks-1a {[regexp {<title>Fossil: Timeline</title>} $RESULT]} |
| 223 | 177 | |
| 224 | 178 | test th1-web-hooks-1b {[regexp [appendArgs \ |
| 225 | 179 | {<h1><b>command_hook http webpage_hook timeline} " " \ |
| 226 | 180 | {webpage_notify timeline</b></h1>}] $RESULT]} |
| 227 | 181 | |
| 228 | 182 | ############################################################################### |
| 229 | 183 | |
| 230 | -set RESULT [fossil_th1_hook_http $repository /test1] | |
| 184 | +set RESULT [test_fossil_http $repository $dataFileName /test1] | |
| 231 | 185 | test th1-custom-web-1a {[next_to_last_data_line] eq $repository} |
| 232 | 186 | |
| 233 | 187 | test th1-custom-web-1b {[last_data_line] eq \ |
| 234 | 188 | {<h1><b>command_hook http webpage_hook test1 webpage_notify test1</b></h1>}} |
| 235 | 189 | |
| 236 | 190 | ############################################################################### |
| 237 | 191 | |
| 238 | 192 | restoreTh1SetupFile |
| 239 | 193 |
| --- test/th1-hooks.test | |
| +++ test/th1-hooks.test | |
| @@ -28,58 +28,10 @@ | |
| 28 | |
| 29 | set env(TH1_ENABLE_HOOKS) 1; # TH1 hooks must be enabled for this test. |
| 30 | |
| 31 | ############################################################################### |
| 32 | |
| 33 | proc fossil_th1_hook_http { repository url } { |
| 34 | set suffix [appendArgs [pid] - [getSeqNo] - [clock seconds] .txt] |
| 35 | set inFileName [file join $::tempPath [appendArgs test-http-in- $suffix]] |
| 36 | set outFileName [file join $::tempPath [appendArgs test-http-out- $suffix]] |
| 37 | set data [subst [read_file [file join $::testdir th1-hooks-input.txt]]] |
| 38 | |
| 39 | write_file $inFileName $data |
| 40 | fossil http $inFileName $outFileName 127.0.0.1 $repository |
| 41 | set result [expr {[file exists $outFileName] ? [read_file $outFileName] : ""}] |
| 42 | |
| 43 | if {1} then { |
| 44 | catch {file delete $inFileName} |
| 45 | catch {file delete $outFileName} |
| 46 | } |
| 47 | |
| 48 | return $result |
| 49 | } |
| 50 | |
| 51 | proc normalize_result {} { |
| 52 | return [string map [list \r\n \n] [string trim $::RESULT]] |
| 53 | } |
| 54 | |
| 55 | proc first_data_line {} { |
| 56 | return [lindex [split [normalize_result] \n] 0] |
| 57 | } |
| 58 | |
| 59 | proc second_data_line {} { |
| 60 | return [lindex [split [normalize_result] \n] 1] |
| 61 | } |
| 62 | |
| 63 | proc third_data_line {} { |
| 64 | return [lindex [split [normalize_result] \n] 2] |
| 65 | } |
| 66 | |
| 67 | proc last_data_line {} { |
| 68 | return [lindex [split [normalize_result] \n] end] |
| 69 | } |
| 70 | |
| 71 | proc next_to_last_data_line {} { |
| 72 | return [lindex [split [normalize_result] \n] end-1] |
| 73 | } |
| 74 | |
| 75 | proc third_to_last_data_line {} { |
| 76 | return [lindex [split [normalize_result] \n] end-2] |
| 77 | } |
| 78 | |
| 79 | ############################################################################### |
| 80 | |
| 81 | set testTh1Setup { |
| 82 | proc initialize_hook_log {} { |
| 83 | if {![info exists ::hook_log]} { |
| 84 | set ::hook_log "" |
| 85 | } |
| @@ -152,10 +104,12 @@ | |
| 152 | regexp -line -- {^repository: (.*)$} $data dummy repository |
| 153 | |
| 154 | if {[string length $repository] == 0 || ![file exists $repository]} then { |
| 155 | error "unable to locate repository" |
| 156 | } |
| 157 | |
| 158 | ############################################################################### |
| 159 | |
| 160 | saveTh1SetupFile; writeTh1SetupFile $testTh1Setup |
| 161 | |
| @@ -216,23 +170,23 @@ | |
| 216 | test th1-custom-cmd-4a {[string trim $RESULT] eq \ |
| 217 | {<h1><b>command_hook test4</b></h1>}} |
| 218 | |
| 219 | ############################################################################### |
| 220 | |
| 221 | set RESULT [fossil_th1_hook_http $repository /timeline] |
| 222 | test th1-web-hooks-1a {[regexp {<title>Fossil: Timeline</title>} $RESULT]} |
| 223 | |
| 224 | test th1-web-hooks-1b {[regexp [appendArgs \ |
| 225 | {<h1><b>command_hook http webpage_hook timeline} " " \ |
| 226 | {webpage_notify timeline</b></h1>}] $RESULT]} |
| 227 | |
| 228 | ############################################################################### |
| 229 | |
| 230 | set RESULT [fossil_th1_hook_http $repository /test1] |
| 231 | test th1-custom-web-1a {[next_to_last_data_line] eq $repository} |
| 232 | |
| 233 | test th1-custom-web-1b {[last_data_line] eq \ |
| 234 | {<h1><b>command_hook http webpage_hook test1 webpage_notify test1</b></h1>}} |
| 235 | |
| 236 | ############################################################################### |
| 237 | |
| 238 | restoreTh1SetupFile |
| 239 |
| --- test/th1-hooks.test | |
| +++ test/th1-hooks.test | |
| @@ -28,58 +28,10 @@ | |
| 28 | |
| 29 | set env(TH1_ENABLE_HOOKS) 1; # TH1 hooks must be enabled for this test. |
| 30 | |
| 31 | ############################################################################### |
| 32 | |
| 33 | set testTh1Setup { |
| 34 | proc initialize_hook_log {} { |
| 35 | if {![info exists ::hook_log]} { |
| 36 | set ::hook_log "" |
| 37 | } |
| @@ -152,10 +104,12 @@ | |
| 104 | regexp -line -- {^repository: (.*)$} $data dummy repository |
| 105 | |
| 106 | if {[string length $repository] == 0 || ![file exists $repository]} then { |
| 107 | error "unable to locate repository" |
| 108 | } |
| 109 | |
| 110 | set dataFileName [file join $::testdir th1-hooks-input.txt] |
| 111 | |
| 112 | ############################################################################### |
| 113 | |
| 114 | saveTh1SetupFile; writeTh1SetupFile $testTh1Setup |
| 115 | |
| @@ -216,23 +170,23 @@ | |
| 170 | test th1-custom-cmd-4a {[string trim $RESULT] eq \ |
| 171 | {<h1><b>command_hook test4</b></h1>}} |
| 172 | |
| 173 | ############################################################################### |
| 174 | |
| 175 | set RESULT [test_fossil_http $repository $dataFileName /timeline] |
| 176 | test th1-web-hooks-1a {[regexp {<title>Fossil: Timeline</title>} $RESULT]} |
| 177 | |
| 178 | test th1-web-hooks-1b {[regexp [appendArgs \ |
| 179 | {<h1><b>command_hook http webpage_hook timeline} " " \ |
| 180 | {webpage_notify timeline</b></h1>}] $RESULT]} |
| 181 | |
| 182 | ############################################################################### |
| 183 | |
| 184 | set RESULT [test_fossil_http $repository $dataFileName /test1] |
| 185 | test th1-custom-web-1a {[next_to_last_data_line] eq $repository} |
| 186 | |
| 187 | test th1-custom-web-1b {[last_data_line] eq \ |
| 188 | {<h1><b>command_hook http webpage_hook test1 webpage_notify test1</b></h1>}} |
| 189 | |
| 190 | ############################################################################### |
| 191 | |
| 192 | restoreTh1SetupFile |
| 193 |