Fossil SCM
Fix many outdated comments; refactor duplicated code; add new switch -knownBug for the case where the known bug is the fossil return code; Remove dead code and the unused -whatIf parameter
Commit
970df5d58b756cbafdbf1f311c45bd2be4f01f265fbe7308d9fb78005969fc04
Parent
097ee074f36a000…
1 file changed
+50
-188
+50
-188
| --- test/tester.tcl | ||
| +++ test/tester.tcl | ||
| @@ -51,56 +51,16 @@ | ||
| 51 | 51 | catch {exec $::fossilexe changes --changed} res |
| 52 | 52 | set dirty_ckout [string length $res] |
| 53 | 53 | |
| 54 | 54 | set argv [lrange $argv 1 end] |
| 55 | 55 | |
| 56 | -set i [lsearch $argv -keep] | |
| 57 | -if {$i>=0} { | |
| 58 | - set KEEP 1 | |
| 59 | - set argv [lreplace $argv $i $i] | |
| 60 | -} else { | |
| 61 | - set KEEP 0 | |
| 62 | -} | |
| 63 | - | |
| 64 | -set i [lsearch $argv -halt] | |
| 65 | -if {$i>=0} { | |
| 66 | - set HALT 1 | |
| 67 | - set argv [lreplace $argv $i $i] | |
| 68 | -} else { | |
| 69 | - set HALT 0 | |
| 70 | -} | |
| 71 | - | |
| 72 | -set i [lsearch $argv -prot] | |
| 73 | -if {$i>=0} { | |
| 74 | - set PROT 1 | |
| 75 | - set argv [lreplace $argv $i $i] | |
| 76 | -} else { | |
| 77 | - set PROT 0 | |
| 78 | -} | |
| 79 | - | |
| 80 | -set i [lsearch $argv -verbose] | |
| 81 | -if {$i>=0} { | |
| 82 | - set VERBOSE 1 | |
| 83 | - set argv [lreplace $argv $i $i] | |
| 84 | -} else { | |
| 85 | - set VERBOSE 0 | |
| 86 | -} | |
| 87 | - | |
| 88 | -set i [lsearch $argv -quiet] | |
| 89 | -if {$i>=0} { | |
| 90 | - set QUIET 1 | |
| 91 | - set argv [lreplace $argv $i $i] | |
| 92 | -} else { | |
| 93 | - set QUIET 0 | |
| 94 | -} | |
| 95 | - | |
| 96 | -set i [lsearch $argv -strict] | |
| 97 | -if {$i>=0} { | |
| 98 | - set STRICT 1 | |
| 99 | - set argv [lreplace $argv $i $i] | |
| 100 | -} else { | |
| 101 | - set STRICT 0 | |
| 56 | +foreach option {keep halt prot verbose quiet strict} { | |
| 57 | + set i [lsearch -exact $argv -$option] | |
| 58 | + set [string toupper $option] [expr {$i >= 0}] | |
| 59 | + if {$i >= 0} { | |
| 60 | + set argv [lreplace $argv $i $i] | |
| 61 | + } | |
| 102 | 62 | } |
| 103 | 63 | |
| 104 | 64 | if {[llength $argv]==0} { |
| 105 | 65 | foreach f [lsort [glob $testdir/*.test]] { |
| 106 | 66 | set base [file root [file tail $f]] |
| @@ -160,11 +120,17 @@ | ||
| 160 | 120 | # |
| 161 | 121 | # Consults the VERBOSE global variable to determine if |
| 162 | 122 | # diagnostics should be emitted when no error is seen. |
| 163 | 123 | # Sets the CODE and RESULT global variables for use in |
| 164 | 124 | # test expressions, and the LASTCMD global variable to the |
| 165 | -# command, for the report of a failed test. | |
| 125 | +# command, for the report of a failed test. CODE is 0 if the | |
| 126 | +# command succeeded and did not write anything to standard error, | |
| 127 | +# and 1 otherwise. | |
| 128 | +# | |
| 129 | +# A command that exits with the wrong status gets an ERROR line. | |
| 130 | +# Where that status is a known bug, -knownBug among the arguments | |
| 131 | +# limits the ERROR line to -strict runs. | |
| 166 | 132 | # |
| 167 | 133 | proc fossil_maybe_answer {answer args} { |
| 168 | 134 | global fossilexe |
| 169 | 135 | set cmd $fossilexe |
| 170 | 136 | set expectError 0 |
| @@ -177,58 +143,48 @@ | ||
| 177 | 143 | set index [lsearch -exact $args -keepNewline] |
| 178 | 144 | if {$index != -1} { |
| 179 | 145 | set keepNewline 1 |
| 180 | 146 | set args [lreplace $args $index $index] |
| 181 | 147 | } |
| 182 | - set whatIf 0 | |
| 183 | - set index [lsearch -exact $args -whatIf] | |
| 148 | + set knownBug 0 | |
| 149 | + set index [lsearch -exact $args -knownBug] | |
| 184 | 150 | if {$index != -1} { |
| 185 | - set whatIf 1 | |
| 151 | + set knownBug 1 | |
| 186 | 152 | set args [lreplace $args $index $index] |
| 187 | 153 | } |
| 188 | 154 | foreach a $args { |
| 189 | 155 | lappend cmd $a |
| 190 | 156 | } |
| 191 | - protOut $cmd | |
| 157 | + protOut [list fossil {*}$args] | |
| 192 | 158 | |
| 193 | 159 | flush stdout |
| 194 | - if {$whatIf} { | |
| 195 | - protOut [pwd]; protOut $answer | |
| 196 | - set result WHAT-IF-MODE; set rc 42 | |
| 197 | - } else { | |
| 198 | - if {[string length $answer] > 0} { | |
| 199 | - protOut $answer | |
| 200 | - set prompt_file [file join $::tempPath fossil_prompt_answer] | |
| 201 | - write_file $prompt_file $answer\n | |
| 202 | - set execCmd [list eval exec] | |
| 203 | - if {$keepNewline} {lappend execCmd -keepnewline} | |
| 204 | - lappend execCmd $cmd <$prompt_file | |
| 205 | - set rc [catch $execCmd result] | |
| 206 | - file delete $prompt_file | |
| 207 | - } else { | |
| 208 | - set execCmd [list eval exec] | |
| 209 | - if {$keepNewline} {lappend execCmd -keepnewline} | |
| 210 | - lappend execCmd $cmd | |
| 211 | - set rc [catch $execCmd result] | |
| 212 | - } | |
| 213 | - } | |
| 160 | + set execCmd [list eval exec] | |
| 161 | + if {$keepNewline} {lappend execCmd -keepnewline} | |
| 162 | + lappend execCmd $cmd | |
| 163 | + set prompt_file [file join $::tempPath fossil_prompt_answer] | |
| 164 | + if {[string length $answer] > 0} { | |
| 165 | + protOut $answer | |
| 166 | + write_file $prompt_file $answer\n | |
| 167 | + lappend execCmd <$prompt_file | |
| 168 | + } | |
| 169 | + set rc [catch $execCmd result] | |
| 170 | + file delete $prompt_file | |
| 214 | 171 | set ab(str) {child process exited abnormally} |
| 215 | 172 | set ab(len) [string length $ab(str)] |
| 216 | 173 | set ab(off) [expr {$ab(len) - 1}] |
| 217 | 174 | if {$rc && $expectError && \ |
| 218 | 175 | [string range $result end-$ab(off) end] eq $ab(str)} { |
| 219 | 176 | set result [string range $result 0 end-$ab(len)] |
| 220 | 177 | } |
| 221 | 178 | global RESULT CODE LASTCMD |
| 222 | - set LASTCMD $cmd | |
| 179 | + set LASTCMD [list fossil {*}$args] | |
| 223 | 180 | set CODE $rc |
| 224 | - if {!$whatIf} { | |
| 225 | - if {($rc && !$expectError) || (!$rc && $expectError)} { | |
| 226 | - protOut "ERROR ($rc): $result" 1 | |
| 227 | - } elseif {$::VERBOSE} { | |
| 228 | - protOut "RESULT ($rc): $result" | |
| 229 | - } | |
| 181 | + set wrongStatus [expr {($rc != 0) != $expectError}] | |
| 182 | + if {$wrongStatus && (!$knownBug || $::STRICT)} { | |
| 183 | + protOut "ERROR ($rc): $result" 1 | |
| 184 | + } elseif {$::VERBOSE} { | |
| 185 | + protOut "RESULT ($rc): $result" | |
| 230 | 186 | } |
| 231 | 187 | set RESULT $result |
| 232 | 188 | } |
| 233 | 189 | |
| 234 | 190 | # Read a file into memory. |
| @@ -607,12 +563,12 @@ | ||
| 607 | 563 | # the tests inline with the rscript commands. |
| 608 | 564 | # |
| 609 | 565 | # Be sure to adhere to the requirements of run_in_checkout! |
| 610 | 566 | proc test_block_in_checkout { name rscript {tscript ""} } { |
| 611 | 567 | if {$::outside_fossil_repo || $::dirty_ckout} { |
| 612 | - set $::CODE 0 | |
| 613 | - set $::RESULT "" | |
| 568 | + set ::CODE 0 | |
| 569 | + set ::RESULT "" | |
| 614 | 570 | } else { |
| 615 | 571 | uplevel 1 [list run_in_checkout $rscript] |
| 616 | 572 | if {[string length $tscript] == 0} { |
| 617 | 573 | return "" |
| 618 | 574 | } else { |
| @@ -624,13 +580,12 @@ | ||
| 624 | 580 | } |
| 625 | 581 | } |
| 626 | 582 | |
| 627 | 583 | # Single-test wrapper for the above. |
| 628 | 584 | proc test_in_checkout { name rscript tscript } { |
| 629 | - return test_block_in_checkout name rscript { | |
| 630 | - test $name $tscript | |
| 631 | - } | |
| 585 | + uplevel 1 [list test_block_in_checkout $name $rscript \ | |
| 586 | + [list test $name $tscript]] | |
| 632 | 587 | } |
| 633 | 588 | |
| 634 | 589 | # Normalize file status lists (like those returned by 'fossil changes') |
| 635 | 590 | # so they can be compared using simple string comparison |
| 636 | 591 | # |
| @@ -691,28 +646,17 @@ | ||
| 691 | 646 | } |
| 692 | 647 | |
| 693 | 648 | # Returns a usable temporary directory -OR- fails the testing process. |
| 694 | 649 | # |
| 695 | 650 | proc getTemporaryPath {} { |
| 696 | - # | |
| 697 | - # NOTE: Build the list of "temporary directory" environment variables | |
| 698 | - # to check, including all reasonable "cases" of the environment | |
| 699 | - # variable names. | |
| 700 | - # | |
| 701 | 651 | set names [list] |
| 702 | 652 | |
| 703 | - # | |
| 704 | - # TODO: Add more here, if necessary. | |
| 705 | - # | |
| 706 | 653 | foreach name [list FOSSIL_TEST_TEMP FOSSIL_TEMP TMPDIR TEMP TMP] { |
| 707 | 654 | lappend names [string toupper $name] [string tolower $name] \ |
| 708 | 655 | [string totitle $name] |
| 709 | 656 | } |
| 710 | 657 | |
| 711 | - # | |
| 712 | - # NOTE: Check if we can use any of the environment variables. | |
| 713 | - # | |
| 714 | 658 | foreach name $names { |
| 715 | 659 | set value [getEnvironmentVariable $name] |
| 716 | 660 | |
| 717 | 661 | if {[string length $value] > 0} { |
| 718 | 662 | set value [file normalize $value] |
| @@ -721,87 +665,21 @@ | ||
| 721 | 665 | return $value |
| 722 | 666 | } |
| 723 | 667 | } |
| 724 | 668 | } |
| 725 | 669 | |
| 726 | - # | |
| 727 | - # NOTE: On non-Windows systems, fallback to /tmp if it is usable. | |
| 728 | - # | |
| 729 | 670 | if {!$::is_windows} { |
| 730 | 671 | set value /tmp |
| 731 | 672 | |
| 732 | 673 | if {[file exists $value] && [file isdirectory $value]} { |
| 733 | 674 | return $value |
| 734 | 675 | } |
| 735 | 676 | } |
| 736 | 677 | |
| 737 | - # | |
| 738 | - # NOTE: There must be a usable temporary directory to continue testing. | |
| 739 | - # | |
| 740 | 678 | error "Cannot find a usable temporary directory, testing halted." |
| 741 | 679 | } |
| 742 | 680 | |
| 743 | -# Return the name of the versioned settings file containing the TH1 | |
| 744 | -# setup script. | |
| 745 | -# | |
| 746 | -proc getTh1SetupFileName {} { | |
| 747 | - # | |
| 748 | - # NOTE: This uses the "testdir" global variable provided by the | |
| 749 | - # test suite; alternatively, the root of the source tree | |
| 750 | - # could be obtained directly from Fossil. | |
| 751 | - # | |
| 752 | - return [file normalize [file join .fossil-settings th1-setup]] | |
| 753 | -} | |
| 754 | - | |
| 755 | -# Return the saved name of the versioned settings file containing | |
| 756 | -# the TH1 setup script. | |
| 757 | -# | |
| 758 | -proc getSavedTh1SetupFileName {} { | |
| 759 | - return [appendArgs [getTh1SetupFileName] . [pid]] | |
| 760 | -} | |
| 761 | - | |
| 762 | -# Sets the TH1 setup script to the one provided. Prior to calling | |
| 763 | -# this, the [saveTh1SetupFile] procedure should be called in order to | |
| 764 | -# preserve the existing TH1 setup script. Prior to completing the test, | |
| 765 | -# the [restoreTh1SetupFile] procedure should be called to restore the | |
| 766 | -# original TH1 setup script. | |
| 767 | -# | |
| 768 | -proc writeTh1SetupFile { data } { | |
| 769 | - set fileName [getTh1SetupFileName] | |
| 770 | - file mkdir [file dirname $fileName] | |
| 771 | - return [write_file $fileName $data] | |
| 772 | -} | |
| 773 | - | |
| 774 | -# Saves the TH1 setup script file by renaming it, based on the current | |
| 775 | -# process ID. | |
| 776 | -# | |
| 777 | -proc saveTh1SetupFile {} { | |
| 778 | - set oldFileName [getTh1SetupFileName] | |
| 779 | - if {[file exists $oldFileName]} { | |
| 780 | - set newFileName [getSavedTh1SetupFileName] | |
| 781 | - catch {file delete $newFileName} | |
| 782 | - file rename $oldFileName $newFileName | |
| 783 | - } | |
| 784 | -} | |
| 785 | - | |
| 786 | -# Restores the original TH1 setup script file by renaming it back, based | |
| 787 | -# on the current process ID. | |
| 788 | -# | |
| 789 | -proc restoreTh1SetupFile {} { | |
| 790 | - set oldFileName [getSavedTh1SetupFileName] | |
| 791 | - set newFileName [getTh1SetupFileName] | |
| 792 | - if {[file exists $oldFileName]} { | |
| 793 | - catch {file delete $newFileName} | |
| 794 | - file rename $oldFileName $newFileName | |
| 795 | - } else { | |
| 796 | - # | |
| 797 | - # NOTE: There was no TH1 setup script file, delete the test one. | |
| 798 | - # | |
| 799 | - file delete $newFileName | |
| 800 | - } | |
| 801 | -} | |
| 802 | - | |
| 803 | 681 | # Return VALUE as lines for the report of a failed test, after LABEL. |
| 804 | 682 | # A value on one line is shown in double quotes. Each line of a value |
| 805 | 683 | # on several lines is shown between "|" characters, so that leading and |
| 806 | 684 | # trailing white space is visible. |
| 807 | 685 | # |
| @@ -1027,29 +905,21 @@ | ||
| 1027 | 905 | error "fossil server did not report its port: $output" |
| 1028 | 906 | } |
| 1029 | 907 | return [list $pid $port $outFileName] |
| 1030 | 908 | } |
| 1031 | 909 | |
| 1032 | -# This procedure stops a Fossil server instance that was previously started | |
| 1033 | -# by the [test_start_server] procedure. The value of the "stop argument" | |
| 1034 | -# will vary by platform as will the exact method used to stop the server. | |
| 1035 | -# The fileName argument is the name of a temporary output file to delete. | |
| 910 | +# Stops a Fossil server that test_start_server started. On Windows the | |
| 911 | +# stop argument is the name of a file that must not exist yet; creating | |
| 912 | +# it makes the server exit. Elsewhere it is the server's process ID. | |
| 913 | +# FILENAME is a temporary output file to delete. | |
| 1036 | 914 | proc test_stop_server { stopArg pid fileName } { |
| 1037 | 915 | if {$::is_windows} { |
| 1038 | - # | |
| 1039 | - # NOTE: On Windows, the "stop argument" must be the name of a file | |
| 1040 | - # that does NOT already exist. | |
| 1041 | - # | |
| 1042 | 916 | if {[string length $stopArg] > 0 && \ |
| 1043 | 917 | ![file exists $stopArg] && \ |
| 1044 | 918 | [catch {write_file $stopArg [clock seconds]}] == 0} { |
| 1045 | 919 | while {1} { |
| 1046 | 920 | if {[catch { |
| 1047 | - # | |
| 1048 | - # NOTE: Using the TaskList utility requires Windows XP or | |
| 1049 | - # later. | |
| 1050 | - # | |
| 1051 | 921 | exec tasklist.exe /FI "PID eq $pid" |
| 1052 | 922 | } result] != 0 || ![regexp -- " $pid " $result]} { |
| 1053 | 923 | break |
| 1054 | 924 | } |
| 1055 | 925 | after 1000; # wait a bit... |
| @@ -1059,22 +929,14 @@ | ||
| 1059 | 929 | file delete $fileName |
| 1060 | 930 | } |
| 1061 | 931 | return true |
| 1062 | 932 | } |
| 1063 | 933 | } else { |
| 1064 | - # | |
| 1065 | - # NOTE: On Unix, the "stop argument" must be an integer identifier | |
| 1066 | - # that refers to an existing process. | |
| 1067 | - # | |
| 1068 | 934 | if {[regexp {^(?:-)?\d+$} $stopArg] && \ |
| 1069 | 935 | [catch {exec kill -TERM $stopArg}] == 0} { |
| 1070 | 936 | while {1} { |
| 1071 | 937 | if {[catch { |
| 1072 | - # | |
| 1073 | - # TODO: Is this portable to all the supported variants of | |
| 1074 | - # Unix? It should be, it's POSIX. | |
| 1075 | - # | |
| 1076 | 938 | exec ps -p $pid |
| 1077 | 939 | } result] != 0 || ![regexp -- "(?:^$pid| $pid) " $result]} { |
| 1078 | 940 | break |
| 1079 | 941 | } |
| 1080 | 942 | after 1000; # wait a bit... |
| @@ -1103,14 +965,12 @@ | ||
| 1103 | 965 | fossil http --in $inFileName --out $outFileName --ipaddr 127.0.0.1 \ |
| 1104 | 966 | $repository --localauth --th-trace -expectError |
| 1105 | 967 | |
| 1106 | 968 | set result [expr {[file exists $outFileName] ? [read_file $outFileName] : ""}] |
| 1107 | 969 | |
| 1108 | - if {1} { | |
| 1109 | - catch {file delete $inFileName} | |
| 1110 | - catch {file delete $outFileName} | |
| 1111 | - } | |
| 970 | + catch {file delete $inFileName} | |
| 971 | + catch {file delete $outFileName} | |
| 1112 | 972 | |
| 1113 | 973 | return $result |
| 1114 | 974 | } |
| 1115 | 975 | |
| 1116 | 976 | # obtains and increments a "sequence number" for this test run. |
| @@ -1194,10 +1054,11 @@ | ||
| 1194 | 1054 | please set TEMP variable in environment, error: $error" |
| 1195 | 1055 | } |
| 1196 | 1056 | |
| 1197 | 1057 | |
| 1198 | 1058 | protInit $fossilexe |
| 1059 | +protOut "***** Testing $fossilexe" | |
| 1199 | 1060 | set ::tempKeepHome 1 |
| 1200 | 1061 | |
| 1201 | 1062 | # Start in tempHomePath to help avoid errors with require_no_open_checkout |
| 1202 | 1063 | set startPwd [pwd] |
| 1203 | 1064 | cd $tempHomePath |
| @@ -1229,15 +1090,16 @@ | ||
| 1229 | 1090 | protOut "***** Final results: $nErr errors out of $test_count tests" 1 |
| 1230 | 1091 | } |
| 1231 | 1092 | if {$nErr>0} { |
| 1232 | 1093 | protOut "***** Considered failures: $bad_test" 1 |
| 1233 | 1094 | } |
| 1234 | -set nErr [llength $ignored_test] | |
| 1235 | -if {$nErr>0 || !$::QUIET} { | |
| 1236 | - protOut "***** Ignored results: $nErr ignored errors out of $test_count tests" 1 | |
| 1095 | +set nIgnored [llength $ignored_test] | |
| 1096 | +if {$nIgnored>0 || !$::QUIET} { | |
| 1097 | + protOut "***** Ignored results: $nIgnored ignored errors out of\ | |
| 1098 | + $test_count tests" 1 | |
| 1237 | 1099 | } |
| 1238 | -if {$nErr>0} { | |
| 1100 | +if {$nIgnored>0} { | |
| 1239 | 1101 | protOut "***** Ignored failures: $ignored_test" 1 |
| 1240 | 1102 | } |
| 1241 | 1103 | set nSkipped [llength $skipped_tests] |
| 1242 | 1104 | if {$nSkipped>0} { |
| 1243 | 1105 | protOut "***** Skipped tests: [lmap s $skipped_tests {lindex $s 0}]" 1 |
| 1244 | 1106 |
| --- test/tester.tcl | |
| +++ test/tester.tcl | |
| @@ -51,56 +51,16 @@ | |
| 51 | catch {exec $::fossilexe changes --changed} res |
| 52 | set dirty_ckout [string length $res] |
| 53 | |
| 54 | set argv [lrange $argv 1 end] |
| 55 | |
| 56 | set i [lsearch $argv -keep] |
| 57 | if {$i>=0} { |
| 58 | set KEEP 1 |
| 59 | set argv [lreplace $argv $i $i] |
| 60 | } else { |
| 61 | set KEEP 0 |
| 62 | } |
| 63 | |
| 64 | set i [lsearch $argv -halt] |
| 65 | if {$i>=0} { |
| 66 | set HALT 1 |
| 67 | set argv [lreplace $argv $i $i] |
| 68 | } else { |
| 69 | set HALT 0 |
| 70 | } |
| 71 | |
| 72 | set i [lsearch $argv -prot] |
| 73 | if {$i>=0} { |
| 74 | set PROT 1 |
| 75 | set argv [lreplace $argv $i $i] |
| 76 | } else { |
| 77 | set PROT 0 |
| 78 | } |
| 79 | |
| 80 | set i [lsearch $argv -verbose] |
| 81 | if {$i>=0} { |
| 82 | set VERBOSE 1 |
| 83 | set argv [lreplace $argv $i $i] |
| 84 | } else { |
| 85 | set VERBOSE 0 |
| 86 | } |
| 87 | |
| 88 | set i [lsearch $argv -quiet] |
| 89 | if {$i>=0} { |
| 90 | set QUIET 1 |
| 91 | set argv [lreplace $argv $i $i] |
| 92 | } else { |
| 93 | set QUIET 0 |
| 94 | } |
| 95 | |
| 96 | set i [lsearch $argv -strict] |
| 97 | if {$i>=0} { |
| 98 | set STRICT 1 |
| 99 | set argv [lreplace $argv $i $i] |
| 100 | } else { |
| 101 | set STRICT 0 |
| 102 | } |
| 103 | |
| 104 | if {[llength $argv]==0} { |
| 105 | foreach f [lsort [glob $testdir/*.test]] { |
| 106 | set base [file root [file tail $f]] |
| @@ -160,11 +120,17 @@ | |
| 160 | # |
| 161 | # Consults the VERBOSE global variable to determine if |
| 162 | # diagnostics should be emitted when no error is seen. |
| 163 | # Sets the CODE and RESULT global variables for use in |
| 164 | # test expressions, and the LASTCMD global variable to the |
| 165 | # command, for the report of a failed test. |
| 166 | # |
| 167 | proc fossil_maybe_answer {answer args} { |
| 168 | global fossilexe |
| 169 | set cmd $fossilexe |
| 170 | set expectError 0 |
| @@ -177,58 +143,48 @@ | |
| 177 | set index [lsearch -exact $args -keepNewline] |
| 178 | if {$index != -1} { |
| 179 | set keepNewline 1 |
| 180 | set args [lreplace $args $index $index] |
| 181 | } |
| 182 | set whatIf 0 |
| 183 | set index [lsearch -exact $args -whatIf] |
| 184 | if {$index != -1} { |
| 185 | set whatIf 1 |
| 186 | set args [lreplace $args $index $index] |
| 187 | } |
| 188 | foreach a $args { |
| 189 | lappend cmd $a |
| 190 | } |
| 191 | protOut $cmd |
| 192 | |
| 193 | flush stdout |
| 194 | if {$whatIf} { |
| 195 | protOut [pwd]; protOut $answer |
| 196 | set result WHAT-IF-MODE; set rc 42 |
| 197 | } else { |
| 198 | if {[string length $answer] > 0} { |
| 199 | protOut $answer |
| 200 | set prompt_file [file join $::tempPath fossil_prompt_answer] |
| 201 | write_file $prompt_file $answer\n |
| 202 | set execCmd [list eval exec] |
| 203 | if {$keepNewline} {lappend execCmd -keepnewline} |
| 204 | lappend execCmd $cmd <$prompt_file |
| 205 | set rc [catch $execCmd result] |
| 206 | file delete $prompt_file |
| 207 | } else { |
| 208 | set execCmd [list eval exec] |
| 209 | if {$keepNewline} {lappend execCmd -keepnewline} |
| 210 | lappend execCmd $cmd |
| 211 | set rc [catch $execCmd result] |
| 212 | } |
| 213 | } |
| 214 | set ab(str) {child process exited abnormally} |
| 215 | set ab(len) [string length $ab(str)] |
| 216 | set ab(off) [expr {$ab(len) - 1}] |
| 217 | if {$rc && $expectError && \ |
| 218 | [string range $result end-$ab(off) end] eq $ab(str)} { |
| 219 | set result [string range $result 0 end-$ab(len)] |
| 220 | } |
| 221 | global RESULT CODE LASTCMD |
| 222 | set LASTCMD $cmd |
| 223 | set CODE $rc |
| 224 | if {!$whatIf} { |
| 225 | if {($rc && !$expectError) || (!$rc && $expectError)} { |
| 226 | protOut "ERROR ($rc): $result" 1 |
| 227 | } elseif {$::VERBOSE} { |
| 228 | protOut "RESULT ($rc): $result" |
| 229 | } |
| 230 | } |
| 231 | set RESULT $result |
| 232 | } |
| 233 | |
| 234 | # Read a file into memory. |
| @@ -607,12 +563,12 @@ | |
| 607 | # the tests inline with the rscript commands. |
| 608 | # |
| 609 | # Be sure to adhere to the requirements of run_in_checkout! |
| 610 | proc test_block_in_checkout { name rscript {tscript ""} } { |
| 611 | if {$::outside_fossil_repo || $::dirty_ckout} { |
| 612 | set $::CODE 0 |
| 613 | set $::RESULT "" |
| 614 | } else { |
| 615 | uplevel 1 [list run_in_checkout $rscript] |
| 616 | if {[string length $tscript] == 0} { |
| 617 | return "" |
| 618 | } else { |
| @@ -624,13 +580,12 @@ | |
| 624 | } |
| 625 | } |
| 626 | |
| 627 | # Single-test wrapper for the above. |
| 628 | proc test_in_checkout { name rscript tscript } { |
| 629 | return test_block_in_checkout name rscript { |
| 630 | test $name $tscript |
| 631 | } |
| 632 | } |
| 633 | |
| 634 | # Normalize file status lists (like those returned by 'fossil changes') |
| 635 | # so they can be compared using simple string comparison |
| 636 | # |
| @@ -691,28 +646,17 @@ | |
| 691 | } |
| 692 | |
| 693 | # Returns a usable temporary directory -OR- fails the testing process. |
| 694 | # |
| 695 | proc getTemporaryPath {} { |
| 696 | # |
| 697 | # NOTE: Build the list of "temporary directory" environment variables |
| 698 | # to check, including all reasonable "cases" of the environment |
| 699 | # variable names. |
| 700 | # |
| 701 | set names [list] |
| 702 | |
| 703 | # |
| 704 | # TODO: Add more here, if necessary. |
| 705 | # |
| 706 | foreach name [list FOSSIL_TEST_TEMP FOSSIL_TEMP TMPDIR TEMP TMP] { |
| 707 | lappend names [string toupper $name] [string tolower $name] \ |
| 708 | [string totitle $name] |
| 709 | } |
| 710 | |
| 711 | # |
| 712 | # NOTE: Check if we can use any of the environment variables. |
| 713 | # |
| 714 | foreach name $names { |
| 715 | set value [getEnvironmentVariable $name] |
| 716 | |
| 717 | if {[string length $value] > 0} { |
| 718 | set value [file normalize $value] |
| @@ -721,87 +665,21 @@ | |
| 721 | return $value |
| 722 | } |
| 723 | } |
| 724 | } |
| 725 | |
| 726 | # |
| 727 | # NOTE: On non-Windows systems, fallback to /tmp if it is usable. |
| 728 | # |
| 729 | if {!$::is_windows} { |
| 730 | set value /tmp |
| 731 | |
| 732 | if {[file exists $value] && [file isdirectory $value]} { |
| 733 | return $value |
| 734 | } |
| 735 | } |
| 736 | |
| 737 | # |
| 738 | # NOTE: There must be a usable temporary directory to continue testing. |
| 739 | # |
| 740 | error "Cannot find a usable temporary directory, testing halted." |
| 741 | } |
| 742 | |
| 743 | # Return the name of the versioned settings file containing the TH1 |
| 744 | # setup script. |
| 745 | # |
| 746 | proc getTh1SetupFileName {} { |
| 747 | # |
| 748 | # NOTE: This uses the "testdir" global variable provided by the |
| 749 | # test suite; alternatively, the root of the source tree |
| 750 | # could be obtained directly from Fossil. |
| 751 | # |
| 752 | return [file normalize [file join .fossil-settings th1-setup]] |
| 753 | } |
| 754 | |
| 755 | # Return the saved name of the versioned settings file containing |
| 756 | # the TH1 setup script. |
| 757 | # |
| 758 | proc getSavedTh1SetupFileName {} { |
| 759 | return [appendArgs [getTh1SetupFileName] . [pid]] |
| 760 | } |
| 761 | |
| 762 | # Sets the TH1 setup script to the one provided. Prior to calling |
| 763 | # this, the [saveTh1SetupFile] procedure should be called in order to |
| 764 | # preserve the existing TH1 setup script. Prior to completing the test, |
| 765 | # the [restoreTh1SetupFile] procedure should be called to restore the |
| 766 | # original TH1 setup script. |
| 767 | # |
| 768 | proc writeTh1SetupFile { data } { |
| 769 | set fileName [getTh1SetupFileName] |
| 770 | file mkdir [file dirname $fileName] |
| 771 | return [write_file $fileName $data] |
| 772 | } |
| 773 | |
| 774 | # Saves the TH1 setup script file by renaming it, based on the current |
| 775 | # process ID. |
| 776 | # |
| 777 | proc saveTh1SetupFile {} { |
| 778 | set oldFileName [getTh1SetupFileName] |
| 779 | if {[file exists $oldFileName]} { |
| 780 | set newFileName [getSavedTh1SetupFileName] |
| 781 | catch {file delete $newFileName} |
| 782 | file rename $oldFileName $newFileName |
| 783 | } |
| 784 | } |
| 785 | |
| 786 | # Restores the original TH1 setup script file by renaming it back, based |
| 787 | # on the current process ID. |
| 788 | # |
| 789 | proc restoreTh1SetupFile {} { |
| 790 | set oldFileName [getSavedTh1SetupFileName] |
| 791 | set newFileName [getTh1SetupFileName] |
| 792 | if {[file exists $oldFileName]} { |
| 793 | catch {file delete $newFileName} |
| 794 | file rename $oldFileName $newFileName |
| 795 | } else { |
| 796 | # |
| 797 | # NOTE: There was no TH1 setup script file, delete the test one. |
| 798 | # |
| 799 | file delete $newFileName |
| 800 | } |
| 801 | } |
| 802 | |
| 803 | # Return VALUE as lines for the report of a failed test, after LABEL. |
| 804 | # A value on one line is shown in double quotes. Each line of a value |
| 805 | # on several lines is shown between "|" characters, so that leading and |
| 806 | # trailing white space is visible. |
| 807 | # |
| @@ -1027,29 +905,21 @@ | |
| 1027 | error "fossil server did not report its port: $output" |
| 1028 | } |
| 1029 | return [list $pid $port $outFileName] |
| 1030 | } |
| 1031 | |
| 1032 | # This procedure stops a Fossil server instance that was previously started |
| 1033 | # by the [test_start_server] procedure. The value of the "stop argument" |
| 1034 | # will vary by platform as will the exact method used to stop the server. |
| 1035 | # The fileName argument is the name of a temporary output file to delete. |
| 1036 | proc test_stop_server { stopArg pid fileName } { |
| 1037 | if {$::is_windows} { |
| 1038 | # |
| 1039 | # NOTE: On Windows, the "stop argument" must be the name of a file |
| 1040 | # that does NOT already exist. |
| 1041 | # |
| 1042 | if {[string length $stopArg] > 0 && \ |
| 1043 | ![file exists $stopArg] && \ |
| 1044 | [catch {write_file $stopArg [clock seconds]}] == 0} { |
| 1045 | while {1} { |
| 1046 | if {[catch { |
| 1047 | # |
| 1048 | # NOTE: Using the TaskList utility requires Windows XP or |
| 1049 | # later. |
| 1050 | # |
| 1051 | exec tasklist.exe /FI "PID eq $pid" |
| 1052 | } result] != 0 || ![regexp -- " $pid " $result]} { |
| 1053 | break |
| 1054 | } |
| 1055 | after 1000; # wait a bit... |
| @@ -1059,22 +929,14 @@ | |
| 1059 | file delete $fileName |
| 1060 | } |
| 1061 | return true |
| 1062 | } |
| 1063 | } else { |
| 1064 | # |
| 1065 | # NOTE: On Unix, the "stop argument" must be an integer identifier |
| 1066 | # that refers to an existing process. |
| 1067 | # |
| 1068 | if {[regexp {^(?:-)?\d+$} $stopArg] && \ |
| 1069 | [catch {exec kill -TERM $stopArg}] == 0} { |
| 1070 | while {1} { |
| 1071 | if {[catch { |
| 1072 | # |
| 1073 | # TODO: Is this portable to all the supported variants of |
| 1074 | # Unix? It should be, it's POSIX. |
| 1075 | # |
| 1076 | exec ps -p $pid |
| 1077 | } result] != 0 || ![regexp -- "(?:^$pid| $pid) " $result]} { |
| 1078 | break |
| 1079 | } |
| 1080 | after 1000; # wait a bit... |
| @@ -1103,14 +965,12 @@ | |
| 1103 | fossil http --in $inFileName --out $outFileName --ipaddr 127.0.0.1 \ |
| 1104 | $repository --localauth --th-trace -expectError |
| 1105 | |
| 1106 | set result [expr {[file exists $outFileName] ? [read_file $outFileName] : ""}] |
| 1107 | |
| 1108 | if {1} { |
| 1109 | catch {file delete $inFileName} |
| 1110 | catch {file delete $outFileName} |
| 1111 | } |
| 1112 | |
| 1113 | return $result |
| 1114 | } |
| 1115 | |
| 1116 | # obtains and increments a "sequence number" for this test run. |
| @@ -1194,10 +1054,11 @@ | |
| 1194 | please set TEMP variable in environment, error: $error" |
| 1195 | } |
| 1196 | |
| 1197 | |
| 1198 | protInit $fossilexe |
| 1199 | set ::tempKeepHome 1 |
| 1200 | |
| 1201 | # Start in tempHomePath to help avoid errors with require_no_open_checkout |
| 1202 | set startPwd [pwd] |
| 1203 | cd $tempHomePath |
| @@ -1229,15 +1090,16 @@ | |
| 1229 | protOut "***** Final results: $nErr errors out of $test_count tests" 1 |
| 1230 | } |
| 1231 | if {$nErr>0} { |
| 1232 | protOut "***** Considered failures: $bad_test" 1 |
| 1233 | } |
| 1234 | set nErr [llength $ignored_test] |
| 1235 | if {$nErr>0 || !$::QUIET} { |
| 1236 | protOut "***** Ignored results: $nErr ignored errors out of $test_count tests" 1 |
| 1237 | } |
| 1238 | if {$nErr>0} { |
| 1239 | protOut "***** Ignored failures: $ignored_test" 1 |
| 1240 | } |
| 1241 | set nSkipped [llength $skipped_tests] |
| 1242 | if {$nSkipped>0} { |
| 1243 | protOut "***** Skipped tests: [lmap s $skipped_tests {lindex $s 0}]" 1 |
| 1244 |
| --- test/tester.tcl | |
| +++ test/tester.tcl | |
| @@ -51,56 +51,16 @@ | |
| 51 | catch {exec $::fossilexe changes --changed} res |
| 52 | set dirty_ckout [string length $res] |
| 53 | |
| 54 | set argv [lrange $argv 1 end] |
| 55 | |
| 56 | foreach option {keep halt prot verbose quiet strict} { |
| 57 | set i [lsearch -exact $argv -$option] |
| 58 | set [string toupper $option] [expr {$i >= 0}] |
| 59 | if {$i >= 0} { |
| 60 | set argv [lreplace $argv $i $i] |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | if {[llength $argv]==0} { |
| 65 | foreach f [lsort [glob $testdir/*.test]] { |
| 66 | set base [file root [file tail $f]] |
| @@ -160,11 +120,17 @@ | |
| 120 | # |
| 121 | # Consults the VERBOSE global variable to determine if |
| 122 | # diagnostics should be emitted when no error is seen. |
| 123 | # Sets the CODE and RESULT global variables for use in |
| 124 | # test expressions, and the LASTCMD global variable to the |
| 125 | # command, for the report of a failed test. CODE is 0 if the |
| 126 | # command succeeded and did not write anything to standard error, |
| 127 | # and 1 otherwise. |
| 128 | # |
| 129 | # A command that exits with the wrong status gets an ERROR line. |
| 130 | # Where that status is a known bug, -knownBug among the arguments |
| 131 | # limits the ERROR line to -strict runs. |
| 132 | # |
| 133 | proc fossil_maybe_answer {answer args} { |
| 134 | global fossilexe |
| 135 | set cmd $fossilexe |
| 136 | set expectError 0 |
| @@ -177,58 +143,48 @@ | |
| 143 | set index [lsearch -exact $args -keepNewline] |
| 144 | if {$index != -1} { |
| 145 | set keepNewline 1 |
| 146 | set args [lreplace $args $index $index] |
| 147 | } |
| 148 | set knownBug 0 |
| 149 | set index [lsearch -exact $args -knownBug] |
| 150 | if {$index != -1} { |
| 151 | set knownBug 1 |
| 152 | set args [lreplace $args $index $index] |
| 153 | } |
| 154 | foreach a $args { |
| 155 | lappend cmd $a |
| 156 | } |
| 157 | protOut [list fossil {*}$args] |
| 158 | |
| 159 | flush stdout |
| 160 | set execCmd [list eval exec] |
| 161 | if {$keepNewline} {lappend execCmd -keepnewline} |
| 162 | lappend execCmd $cmd |
| 163 | set prompt_file [file join $::tempPath fossil_prompt_answer] |
| 164 | if {[string length $answer] > 0} { |
| 165 | protOut $answer |
| 166 | write_file $prompt_file $answer\n |
| 167 | lappend execCmd <$prompt_file |
| 168 | } |
| 169 | set rc [catch $execCmd result] |
| 170 | file delete $prompt_file |
| 171 | set ab(str) {child process exited abnormally} |
| 172 | set ab(len) [string length $ab(str)] |
| 173 | set ab(off) [expr {$ab(len) - 1}] |
| 174 | if {$rc && $expectError && \ |
| 175 | [string range $result end-$ab(off) end] eq $ab(str)} { |
| 176 | set result [string range $result 0 end-$ab(len)] |
| 177 | } |
| 178 | global RESULT CODE LASTCMD |
| 179 | set LASTCMD [list fossil {*}$args] |
| 180 | set CODE $rc |
| 181 | set wrongStatus [expr {($rc != 0) != $expectError}] |
| 182 | if {$wrongStatus && (!$knownBug || $::STRICT)} { |
| 183 | protOut "ERROR ($rc): $result" 1 |
| 184 | } elseif {$::VERBOSE} { |
| 185 | protOut "RESULT ($rc): $result" |
| 186 | } |
| 187 | set RESULT $result |
| 188 | } |
| 189 | |
| 190 | # Read a file into memory. |
| @@ -607,12 +563,12 @@ | |
| 563 | # the tests inline with the rscript commands. |
| 564 | # |
| 565 | # Be sure to adhere to the requirements of run_in_checkout! |
| 566 | proc test_block_in_checkout { name rscript {tscript ""} } { |
| 567 | if {$::outside_fossil_repo || $::dirty_ckout} { |
| 568 | set ::CODE 0 |
| 569 | set ::RESULT "" |
| 570 | } else { |
| 571 | uplevel 1 [list run_in_checkout $rscript] |
| 572 | if {[string length $tscript] == 0} { |
| 573 | return "" |
| 574 | } else { |
| @@ -624,13 +580,12 @@ | |
| 580 | } |
| 581 | } |
| 582 | |
| 583 | # Single-test wrapper for the above. |
| 584 | proc test_in_checkout { name rscript tscript } { |
| 585 | uplevel 1 [list test_block_in_checkout $name $rscript \ |
| 586 | [list test $name $tscript]] |
| 587 | } |
| 588 | |
| 589 | # Normalize file status lists (like those returned by 'fossil changes') |
| 590 | # so they can be compared using simple string comparison |
| 591 | # |
| @@ -691,28 +646,17 @@ | |
| 646 | } |
| 647 | |
| 648 | # Returns a usable temporary directory -OR- fails the testing process. |
| 649 | # |
| 650 | proc getTemporaryPath {} { |
| 651 | set names [list] |
| 652 | |
| 653 | foreach name [list FOSSIL_TEST_TEMP FOSSIL_TEMP TMPDIR TEMP TMP] { |
| 654 | lappend names [string toupper $name] [string tolower $name] \ |
| 655 | [string totitle $name] |
| 656 | } |
| 657 | |
| 658 | foreach name $names { |
| 659 | set value [getEnvironmentVariable $name] |
| 660 | |
| 661 | if {[string length $value] > 0} { |
| 662 | set value [file normalize $value] |
| @@ -721,87 +665,21 @@ | |
| 665 | return $value |
| 666 | } |
| 667 | } |
| 668 | } |
| 669 | |
| 670 | if {!$::is_windows} { |
| 671 | set value /tmp |
| 672 | |
| 673 | if {[file exists $value] && [file isdirectory $value]} { |
| 674 | return $value |
| 675 | } |
| 676 | } |
| 677 | |
| 678 | error "Cannot find a usable temporary directory, testing halted." |
| 679 | } |
| 680 | |
| 681 | # Return VALUE as lines for the report of a failed test, after LABEL. |
| 682 | # A value on one line is shown in double quotes. Each line of a value |
| 683 | # on several lines is shown between "|" characters, so that leading and |
| 684 | # trailing white space is visible. |
| 685 | # |
| @@ -1027,29 +905,21 @@ | |
| 905 | error "fossil server did not report its port: $output" |
| 906 | } |
| 907 | return [list $pid $port $outFileName] |
| 908 | } |
| 909 | |
| 910 | # Stops a Fossil server that test_start_server started. On Windows the |
| 911 | # stop argument is the name of a file that must not exist yet; creating |
| 912 | # it makes the server exit. Elsewhere it is the server's process ID. |
| 913 | # FILENAME is a temporary output file to delete. |
| 914 | proc test_stop_server { stopArg pid fileName } { |
| 915 | if {$::is_windows} { |
| 916 | if {[string length $stopArg] > 0 && \ |
| 917 | ![file exists $stopArg] && \ |
| 918 | [catch {write_file $stopArg [clock seconds]}] == 0} { |
| 919 | while {1} { |
| 920 | if {[catch { |
| 921 | exec tasklist.exe /FI "PID eq $pid" |
| 922 | } result] != 0 || ![regexp -- " $pid " $result]} { |
| 923 | break |
| 924 | } |
| 925 | after 1000; # wait a bit... |
| @@ -1059,22 +929,14 @@ | |
| 929 | file delete $fileName |
| 930 | } |
| 931 | return true |
| 932 | } |
| 933 | } else { |
| 934 | if {[regexp {^(?:-)?\d+$} $stopArg] && \ |
| 935 | [catch {exec kill -TERM $stopArg}] == 0} { |
| 936 | while {1} { |
| 937 | if {[catch { |
| 938 | exec ps -p $pid |
| 939 | } result] != 0 || ![regexp -- "(?:^$pid| $pid) " $result]} { |
| 940 | break |
| 941 | } |
| 942 | after 1000; # wait a bit... |
| @@ -1103,14 +965,12 @@ | |
| 965 | fossil http --in $inFileName --out $outFileName --ipaddr 127.0.0.1 \ |
| 966 | $repository --localauth --th-trace -expectError |
| 967 | |
| 968 | set result [expr {[file exists $outFileName] ? [read_file $outFileName] : ""}] |
| 969 | |
| 970 | catch {file delete $inFileName} |
| 971 | catch {file delete $outFileName} |
| 972 | |
| 973 | return $result |
| 974 | } |
| 975 | |
| 976 | # obtains and increments a "sequence number" for this test run. |
| @@ -1194,10 +1054,11 @@ | |
| 1054 | please set TEMP variable in environment, error: $error" |
| 1055 | } |
| 1056 | |
| 1057 | |
| 1058 | protInit $fossilexe |
| 1059 | protOut "***** Testing $fossilexe" |
| 1060 | set ::tempKeepHome 1 |
| 1061 | |
| 1062 | # Start in tempHomePath to help avoid errors with require_no_open_checkout |
| 1063 | set startPwd [pwd] |
| 1064 | cd $tempHomePath |
| @@ -1229,15 +1090,16 @@ | |
| 1090 | protOut "***** Final results: $nErr errors out of $test_count tests" 1 |
| 1091 | } |
| 1092 | if {$nErr>0} { |
| 1093 | protOut "***** Considered failures: $bad_test" 1 |
| 1094 | } |
| 1095 | set nIgnored [llength $ignored_test] |
| 1096 | if {$nIgnored>0 || !$::QUIET} { |
| 1097 | protOut "***** Ignored results: $nIgnored ignored errors out of\ |
| 1098 | $test_count tests" 1 |
| 1099 | } |
| 1100 | if {$nIgnored>0} { |
| 1101 | protOut "***** Ignored failures: $ignored_test" 1 |
| 1102 | } |
| 1103 | set nSkipped [llength $skipped_tests] |
| 1104 | if {$nSkipped>0} { |
| 1105 | protOut "***** Skipped tests: [lmap s $skipped_tests {lindex $s 0}]" 1 |
| 1106 |