Fossil SCM
Report expected and actual values of a failed test. Convert settings.test to use the new procedures.
Commit
72468df99cca38f85809093591c7b8f7096c01e0f4b590028c5c65c00edec826
Parent
1b458fd37748449…
2 files changed
+22
-31
+79
-12
+22
-31
| --- test/settings.test | ||
| +++ test/settings.test | ||
| @@ -70,77 +70,68 @@ | ||
| 70 | 70 | set local_settings [extract_setting_names [normalize_result_no_trim]] |
| 71 | 71 | |
| 72 | 72 | fossil settings --global |
| 73 | 73 | set global_settings [extract_setting_names [normalize_result_no_trim]] |
| 74 | 74 | |
| 75 | +# NOTE: In these tests the actual value is the setting name when the list | |
| 76 | +# contains it, and empty when it does not. | |
| 77 | +# | |
| 75 | 78 | foreach name $all_settings { |
| 76 | - test settings-have-local-$name { | |
| 77 | - [lsearch -exact $local_settings $name] != -1 | |
| 78 | - } | |
| 79 | + test_eq settings-have-local-$name \ | |
| 80 | + [lsearch -inline -exact $local_settings $name] $name | |
| 79 | 81 | |
| 80 | - test settings-have-global-$name { | |
| 81 | - [lsearch -exact $global_settings $name] != -1 | |
| 82 | - } | |
| 82 | + test_eq settings-have-global-$name \ | |
| 83 | + [lsearch -inline -exact $global_settings $name] $name | |
| 83 | 84 | } |
| 84 | 85 | |
| 85 | 86 | foreach name $local_settings { |
| 86 | - test settings-valid-local-$name { | |
| 87 | - [lsearch -exact $all_settings $name] != -1 | |
| 88 | - } | |
| 87 | + test_eq settings-valid-local-$name \ | |
| 88 | + [lsearch -inline -exact $all_settings $name] $name | |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | foreach name $global_settings { |
| 92 | - test settings-valid-global-$name { | |
| 93 | - [lsearch -exact $all_settings $name] != -1 | |
| 94 | - } | |
| 92 | + test_eq settings-valid-global-$name \ | |
| 93 | + [lsearch -inline -exact $all_settings $name] $name | |
| 95 | 94 | } |
| 96 | 95 | |
| 97 | 96 | ############################################################################### |
| 98 | 97 | |
| 99 | -set pattern(1) {^%name%$} | |
| 100 | -set pattern(2) {^%name%[ ]+\((?:local|global)\)[ ]+[^ ]+$} | |
| 98 | +set queryPattern {^%name%(?:[ ]+\((?:local|global)\)[ ]+[^ ]+)?$} | |
| 101 | 99 | |
| 102 | 100 | foreach name $all_settings { |
| 103 | 101 | fossil settings $name --exact |
| 104 | 102 | set data [normalize_result] |
| 105 | 103 | |
| 106 | - test settings-query-local-$name { | |
| 107 | - [regexp -- [string map [list %name% $name] $pattern(1)] $data] || | |
| 108 | - [regexp -- [string map [list %name% $name] $pattern(2)] $data] | |
| 109 | - } | |
| 104 | + test_match settings-query-local-$name $data \ | |
| 105 | + [string map [list %name% $name] $queryPattern] | |
| 110 | 106 | |
| 111 | 107 | if {$name eq "manifest"} { |
| 112 | 108 | fossil settings $name --exact --global -expectError |
| 113 | 109 | } else { |
| 114 | 110 | fossil settings $name --exact --global |
| 115 | 111 | } |
| 116 | 112 | set data [normalize_result] |
| 117 | 113 | |
| 118 | 114 | if {$name eq "manifest"} { |
| 119 | - test settings-query-global-$name { | |
| 120 | - $data eq "cannot set 'manifest' globally" | |
| 121 | - } | |
| 115 | + test_eq settings-query-global-$name $data \ | |
| 116 | + "cannot set 'manifest' globally" | |
| 122 | 117 | } else { |
| 123 | - test settings-query-global-$name { | |
| 124 | - [regexp -- [string map [list %name% $name] $pattern(1)] $data] || | |
| 125 | - [regexp -- [string map [list %name% $name] $pattern(2)] $data] | |
| 126 | - } | |
| 118 | + test_match settings-query-global-$name $data \ | |
| 119 | + [string map [list %name% $name] $queryPattern] | |
| 127 | 120 | } |
| 128 | 121 | } |
| 129 | 122 | |
| 130 | 123 | ############################################################################### |
| 131 | 124 | |
| 132 | 125 | fossil settings bad-setting -expectError |
| 133 | 126 | |
| 134 | -test settings-query-bad-local { | |
| 135 | - [normalize_result] eq "no such setting: bad-setting" | |
| 136 | -} | |
| 127 | +test_eq settings-query-bad-local [normalize_result] \ | |
| 128 | + "no such setting: bad-setting" | |
| 137 | 129 | |
| 138 | 130 | fossil settings bad-setting --global -expectError |
| 139 | 131 | |
| 140 | -test settings-query-bad-global { | |
| 141 | - [normalize_result] eq "no such setting: bad-setting" | |
| 142 | -} | |
| 132 | +test_eq settings-query-bad-global [normalize_result] \ | |
| 133 | + "no such setting: bad-setting" | |
| 143 | 134 | |
| 144 | 135 | ############################################################################### |
| 145 | 136 | |
| 146 | 137 | test_cleanup |
| 147 | 138 |
| --- test/settings.test | |
| +++ test/settings.test | |
| @@ -70,77 +70,68 @@ | |
| 70 | set local_settings [extract_setting_names [normalize_result_no_trim]] |
| 71 | |
| 72 | fossil settings --global |
| 73 | set global_settings [extract_setting_names [normalize_result_no_trim]] |
| 74 | |
| 75 | foreach name $all_settings { |
| 76 | test settings-have-local-$name { |
| 77 | [lsearch -exact $local_settings $name] != -1 |
| 78 | } |
| 79 | |
| 80 | test settings-have-global-$name { |
| 81 | [lsearch -exact $global_settings $name] != -1 |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | foreach name $local_settings { |
| 86 | test settings-valid-local-$name { |
| 87 | [lsearch -exact $all_settings $name] != -1 |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | foreach name $global_settings { |
| 92 | test settings-valid-global-$name { |
| 93 | [lsearch -exact $all_settings $name] != -1 |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | ############################################################################### |
| 98 | |
| 99 | set pattern(1) {^%name%$} |
| 100 | set pattern(2) {^%name%[ ]+\((?:local|global)\)[ ]+[^ ]+$} |
| 101 | |
| 102 | foreach name $all_settings { |
| 103 | fossil settings $name --exact |
| 104 | set data [normalize_result] |
| 105 | |
| 106 | test settings-query-local-$name { |
| 107 | [regexp -- [string map [list %name% $name] $pattern(1)] $data] || |
| 108 | [regexp -- [string map [list %name% $name] $pattern(2)] $data] |
| 109 | } |
| 110 | |
| 111 | if {$name eq "manifest"} { |
| 112 | fossil settings $name --exact --global -expectError |
| 113 | } else { |
| 114 | fossil settings $name --exact --global |
| 115 | } |
| 116 | set data [normalize_result] |
| 117 | |
| 118 | if {$name eq "manifest"} { |
| 119 | test settings-query-global-$name { |
| 120 | $data eq "cannot set 'manifest' globally" |
| 121 | } |
| 122 | } else { |
| 123 | test settings-query-global-$name { |
| 124 | [regexp -- [string map [list %name% $name] $pattern(1)] $data] || |
| 125 | [regexp -- [string map [list %name% $name] $pattern(2)] $data] |
| 126 | } |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | ############################################################################### |
| 131 | |
| 132 | fossil settings bad-setting -expectError |
| 133 | |
| 134 | test settings-query-bad-local { |
| 135 | [normalize_result] eq "no such setting: bad-setting" |
| 136 | } |
| 137 | |
| 138 | fossil settings bad-setting --global -expectError |
| 139 | |
| 140 | test settings-query-bad-global { |
| 141 | [normalize_result] eq "no such setting: bad-setting" |
| 142 | } |
| 143 | |
| 144 | ############################################################################### |
| 145 | |
| 146 | test_cleanup |
| 147 |
| --- test/settings.test | |
| +++ test/settings.test | |
| @@ -70,77 +70,68 @@ | |
| 70 | set local_settings [extract_setting_names [normalize_result_no_trim]] |
| 71 | |
| 72 | fossil settings --global |
| 73 | set global_settings [extract_setting_names [normalize_result_no_trim]] |
| 74 | |
| 75 | # NOTE: In these tests the actual value is the setting name when the list |
| 76 | # contains it, and empty when it does not. |
| 77 | # |
| 78 | foreach name $all_settings { |
| 79 | test_eq settings-have-local-$name \ |
| 80 | [lsearch -inline -exact $local_settings $name] $name |
| 81 | |
| 82 | test_eq settings-have-global-$name \ |
| 83 | [lsearch -inline -exact $global_settings $name] $name |
| 84 | } |
| 85 | |
| 86 | foreach name $local_settings { |
| 87 | test_eq settings-valid-local-$name \ |
| 88 | [lsearch -inline -exact $all_settings $name] $name |
| 89 | } |
| 90 | |
| 91 | foreach name $global_settings { |
| 92 | test_eq settings-valid-global-$name \ |
| 93 | [lsearch -inline -exact $all_settings $name] $name |
| 94 | } |
| 95 | |
| 96 | ############################################################################### |
| 97 | |
| 98 | set queryPattern {^%name%(?:[ ]+\((?:local|global)\)[ ]+[^ ]+)?$} |
| 99 | |
| 100 | foreach name $all_settings { |
| 101 | fossil settings $name --exact |
| 102 | set data [normalize_result] |
| 103 | |
| 104 | test_match settings-query-local-$name $data \ |
| 105 | [string map [list %name% $name] $queryPattern] |
| 106 | |
| 107 | if {$name eq "manifest"} { |
| 108 | fossil settings $name --exact --global -expectError |
| 109 | } else { |
| 110 | fossil settings $name --exact --global |
| 111 | } |
| 112 | set data [normalize_result] |
| 113 | |
| 114 | if {$name eq "manifest"} { |
| 115 | test_eq settings-query-global-$name $data \ |
| 116 | "cannot set 'manifest' globally" |
| 117 | } else { |
| 118 | test_match settings-query-global-$name $data \ |
| 119 | [string map [list %name% $name] $queryPattern] |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | ############################################################################### |
| 124 | |
| 125 | fossil settings bad-setting -expectError |
| 126 | |
| 127 | test_eq settings-query-bad-local [normalize_result] \ |
| 128 | "no such setting: bad-setting" |
| 129 | |
| 130 | fossil settings bad-setting --global -expectError |
| 131 | |
| 132 | test_eq settings-query-bad-global [normalize_result] \ |
| 133 | "no such setting: bad-setting" |
| 134 | |
| 135 | ############################################################################### |
| 136 | |
| 137 | test_cleanup |
| 138 |
+79
-12
| --- test/tester.tcl | ||
| +++ test/tester.tcl | ||
| @@ -159,11 +159,12 @@ | ||
| 159 | 159 | # and possibly answer the first prompt, if any. |
| 160 | 160 | # |
| 161 | 161 | # Consults the VERBOSE global variable to determine if |
| 162 | 162 | # diagnostics should be emitted when no error is seen. |
| 163 | 163 | # Sets the CODE and RESULT global variables for use in |
| 164 | -# test expressions. | |
| 164 | +# test expressions, and the LASTCMD global variable to the | |
| 165 | +# command, for the report of a failed test. | |
| 165 | 166 | # |
| 166 | 167 | proc fossil_maybe_answer {answer args} { |
| 167 | 168 | global fossilexe |
| 168 | 169 | set cmd $fossilexe |
| 169 | 170 | set expectError 0 |
| @@ -215,11 +216,12 @@ | ||
| 215 | 216 | set ab(off) [expr {$ab(len) - 1}] |
| 216 | 217 | if {$rc && $expectError && \ |
| 217 | 218 | [string range $result end-$ab(off) end] eq $ab(str)} { |
| 218 | 219 | set result [string range $result 0 end-$ab(len)] |
| 219 | 220 | } |
| 220 | - global RESULT CODE | |
| 221 | + global RESULT CODE LASTCMD | |
| 222 | + set LASTCMD $cmd | |
| 221 | 223 | set CODE $rc |
| 222 | 224 | if {!$whatIf} { |
| 223 | 225 | if {($rc && !$expectError) || (!$rc && $expectError)} { |
| 224 | 226 | protOut "ERROR ($rc): $result" 1 |
| 225 | 227 | } elseif {$::VERBOSE} { |
| @@ -430,12 +432,11 @@ | ||
| 430 | 432 | # Record test NAME as failed because of REASON, then stop the current |
| 431 | 433 | # test file. Call it from the top level of a test file when a step |
| 432 | 434 | # that the rest of the file depends on has failed. |
| 433 | 435 | # |
| 434 | 436 | proc test_fail_then_return {name reason} { |
| 435 | - test $name 0 | |
| 436 | - protOut "$name: $reason" 1 | |
| 437 | + test_report $name 0 "" [list "reason: $reason"] | |
| 437 | 438 | uplevel 1 [list test_cleanup] |
| 438 | 439 | return -code return |
| 439 | 440 | } |
| 440 | 441 | |
| 441 | 442 | proc test_cleanup {} { |
| @@ -769,19 +770,35 @@ | ||
| 769 | 770 | # |
| 770 | 771 | file delete $newFileName |
| 771 | 772 | } |
| 772 | 773 | } |
| 773 | 774 | |
| 774 | -# Perform a test | |
| 775 | +# Return VALUE as lines for the report of a failed test, after LABEL. | |
| 776 | +# A value on one line is shown in double quotes. Each line of a value | |
| 777 | +# on several lines is shown between "|" characters, so that leading and | |
| 778 | +# trailing white space is visible. | |
| 779 | +# | |
| 780 | +proc test_value_lines {label value} { | |
| 781 | + if {[string first \n $value] < 0} { | |
| 782 | + return [list "$label \"$value\""] | |
| 783 | + } | |
| 784 | + set lines [list [string trimright $label]] | |
| 785 | + foreach line [split $value \n] { | |
| 786 | + lappend lines " |$line|" | |
| 787 | + } | |
| 788 | + return $lines | |
| 789 | +} | |
| 790 | + | |
| 791 | +# Count test NAME as passed if OK is true, and as failed otherwise. | |
| 792 | +# For a failure that is not a known bug, write each line of DETAIL | |
| 793 | +# after the failure line. | |
| 775 | 794 | # |
| 776 | -set test_count 0 | |
| 777 | -proc test {name expr {constraints ""}} { | |
| 778 | - global bad_test ignored_test test_count RESULT | |
| 795 | +proc test_report {name ok constraints detail} { | |
| 796 | + global bad_test ignored_test test_count | |
| 779 | 797 | incr test_count |
| 780 | 798 | set knownBug [expr {"knownBug" in $constraints}] |
| 781 | - set r [uplevel 1 [list expr $expr]] | |
| 782 | - if {$r} { | |
| 799 | + if {$ok} { | |
| 783 | 800 | if {$knownBug && !$::STRICT} { |
| 784 | 801 | protOut "test $name OK (knownBug)?" |
| 785 | 802 | } else { |
| 786 | 803 | protOut "test $name OK" |
| 787 | 804 | } |
| @@ -789,16 +806,66 @@ | ||
| 789 | 806 | if {$knownBug && !$::STRICT} { |
| 790 | 807 | protOut "test $name FAILED (knownBug)!" 1 |
| 791 | 808 | lappend ignored_test $name |
| 792 | 809 | } else { |
| 793 | 810 | protOut "test $name FAILED!" 1 |
| 794 | - if {$::QUIET} {protOut "RESULT: $RESULT" 1} | |
| 811 | + foreach line $detail { | |
| 812 | + protOut " $line" 1 | |
| 813 | + } | |
| 795 | 814 | lappend bad_test $name |
| 796 | 815 | if {$::HALT} {exit 1} |
| 797 | 816 | } |
| 798 | 817 | } |
| 799 | 818 | } |
| 819 | + | |
| 820 | +# Perform a test: test NAME passes if the expression EXPR, evaluated in | |
| 821 | +# the caller, is true. A failure is reported with EXPR, the value of | |
| 822 | +# each variable in EXPR except RESULT, the last fossil command run | |
| 823 | +# and its output. The commands in EXPR are not run again. | |
| 824 | +# | |
| 825 | +set test_count 0 | |
| 826 | +set LASTCMD "" | |
| 827 | +proc test {name expr {constraints ""}} { | |
| 828 | + set r [uplevel 1 [list expr $expr]] | |
| 829 | + set detail [list] | |
| 830 | + if {!$r} { | |
| 831 | + lappend detail "expression: [string trim $expr]" | |
| 832 | + set shown [list] | |
| 833 | + foreach ref [regexp -all -inline \ | |
| 834 | + {\$\{[^\}]*\}|\$(?:::)?[A-Za-z_][A-Za-z0-9_:]*(?:\([^)]*\))?} $expr] { | |
| 835 | + if {$ref in $shown || | |
| 836 | + $ref in {$RESULT $::RESULT ${RESULT} ${::RESULT}}} continue | |
| 837 | + lappend shown $ref | |
| 838 | + if {![catch {uplevel 1 [list subst -nocommands $ref]} value]} { | |
| 839 | + lappend detail {*}[test_value_lines "$ref:" $value] | |
| 840 | + } | |
| 841 | + } | |
| 842 | + lappend detail "last command: $::LASTCMD" | |
| 843 | + if {[info exists ::RESULT]} { | |
| 844 | + lappend detail {*}[test_value_lines "its output:" $::RESULT] | |
| 845 | + } | |
| 846 | + } | |
| 847 | + test_report $name $r $constraints $detail | |
| 848 | +} | |
| 849 | + | |
| 850 | +# Test NAME passes if ACTUAL equals EXPECTED. A failure is reported | |
| 851 | +# with both values. | |
| 852 | +# | |
| 853 | +proc test_eq {name actual expected {constraints ""}} { | |
| 854 | + set detail [concat [test_value_lines "expected:" $expected] \ | |
| 855 | + [test_value_lines "actual: " $actual]] | |
| 856 | + test_report $name [expr {$actual eq $expected}] $constraints $detail | |
| 857 | +} | |
| 858 | + | |
| 859 | +# Test NAME passes if ACTUAL matches the regular expression PATTERN. A | |
| 860 | +# failure is reported with the pattern and the actual value. | |
| 861 | +# | |
| 862 | +proc test_match {name actual pattern {constraints ""}} { | |
| 863 | + set detail [concat [list "pattern: $pattern"] \ | |
| 864 | + [test_value_lines "actual: " $actual]] | |
| 865 | + test_report $name [regexp -- $pattern $actual] $constraints $detail | |
| 866 | +} | |
| 800 | 867 | set bad_test {} |
| 801 | 868 | set ignored_test {} |
| 802 | 869 | set skipped_tests {} |
| 803 | 870 | |
| 804 | 871 | # Return a random string N characters long. |
| @@ -1081,11 +1148,11 @@ | ||
| 1081 | 1148 | cd $tempHomePath |
| 1082 | 1149 | |
| 1083 | 1150 | foreach testfile $argv { |
| 1084 | 1151 | protOut "***** $testfile ******" |
| 1085 | 1152 | if { [catch {source $testdir/$testfile.test} testerror testopts] } { |
| 1086 | - test test-framework-$testfile 0 | |
| 1153 | + test_report test-framework-$testfile 0 "" [list "error: $testerror"] | |
| 1087 | 1154 | protOut "!!!!! $testfile: $testerror" |
| 1088 | 1155 | protOutDict $testopts" |
| 1089 | 1156 | } else { |
| 1090 | 1157 | test test-framework-$testfile 1 |
| 1091 | 1158 | } |
| 1092 | 1159 |
| --- test/tester.tcl | |
| +++ test/tester.tcl | |
| @@ -159,11 +159,12 @@ | |
| 159 | # and possibly answer the first prompt, if any. |
| 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. |
| 165 | # |
| 166 | proc fossil_maybe_answer {answer args} { |
| 167 | global fossilexe |
| 168 | set cmd $fossilexe |
| 169 | set expectError 0 |
| @@ -215,11 +216,12 @@ | |
| 215 | set ab(off) [expr {$ab(len) - 1}] |
| 216 | if {$rc && $expectError && \ |
| 217 | [string range $result end-$ab(off) end] eq $ab(str)} { |
| 218 | set result [string range $result 0 end-$ab(len)] |
| 219 | } |
| 220 | global RESULT CODE |
| 221 | set CODE $rc |
| 222 | if {!$whatIf} { |
| 223 | if {($rc && !$expectError) || (!$rc && $expectError)} { |
| 224 | protOut "ERROR ($rc): $result" 1 |
| 225 | } elseif {$::VERBOSE} { |
| @@ -430,12 +432,11 @@ | |
| 430 | # Record test NAME as failed because of REASON, then stop the current |
| 431 | # test file. Call it from the top level of a test file when a step |
| 432 | # that the rest of the file depends on has failed. |
| 433 | # |
| 434 | proc test_fail_then_return {name reason} { |
| 435 | test $name 0 |
| 436 | protOut "$name: $reason" 1 |
| 437 | uplevel 1 [list test_cleanup] |
| 438 | return -code return |
| 439 | } |
| 440 | |
| 441 | proc test_cleanup {} { |
| @@ -769,19 +770,35 @@ | |
| 769 | # |
| 770 | file delete $newFileName |
| 771 | } |
| 772 | } |
| 773 | |
| 774 | # Perform a test |
| 775 | # |
| 776 | set test_count 0 |
| 777 | proc test {name expr {constraints ""}} { |
| 778 | global bad_test ignored_test test_count RESULT |
| 779 | incr test_count |
| 780 | set knownBug [expr {"knownBug" in $constraints}] |
| 781 | set r [uplevel 1 [list expr $expr]] |
| 782 | if {$r} { |
| 783 | if {$knownBug && !$::STRICT} { |
| 784 | protOut "test $name OK (knownBug)?" |
| 785 | } else { |
| 786 | protOut "test $name OK" |
| 787 | } |
| @@ -789,16 +806,66 @@ | |
| 789 | if {$knownBug && !$::STRICT} { |
| 790 | protOut "test $name FAILED (knownBug)!" 1 |
| 791 | lappend ignored_test $name |
| 792 | } else { |
| 793 | protOut "test $name FAILED!" 1 |
| 794 | if {$::QUIET} {protOut "RESULT: $RESULT" 1} |
| 795 | lappend bad_test $name |
| 796 | if {$::HALT} {exit 1} |
| 797 | } |
| 798 | } |
| 799 | } |
| 800 | set bad_test {} |
| 801 | set ignored_test {} |
| 802 | set skipped_tests {} |
| 803 | |
| 804 | # Return a random string N characters long. |
| @@ -1081,11 +1148,11 @@ | |
| 1081 | cd $tempHomePath |
| 1082 | |
| 1083 | foreach testfile $argv { |
| 1084 | protOut "***** $testfile ******" |
| 1085 | if { [catch {source $testdir/$testfile.test} testerror testopts] } { |
| 1086 | test test-framework-$testfile 0 |
| 1087 | protOut "!!!!! $testfile: $testerror" |
| 1088 | protOutDict $testopts" |
| 1089 | } else { |
| 1090 | test test-framework-$testfile 1 |
| 1091 | } |
| 1092 |
| --- test/tester.tcl | |
| +++ test/tester.tcl | |
| @@ -159,11 +159,12 @@ | |
| 159 | # and possibly answer the first prompt, if any. |
| 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 |
| @@ -215,11 +216,12 @@ | |
| 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} { |
| @@ -430,12 +432,11 @@ | |
| 432 | # Record test NAME as failed because of REASON, then stop the current |
| 433 | # test file. Call it from the top level of a test file when a step |
| 434 | # that the rest of the file depends on has failed. |
| 435 | # |
| 436 | proc test_fail_then_return {name reason} { |
| 437 | test_report $name 0 "" [list "reason: $reason"] |
| 438 | uplevel 1 [list test_cleanup] |
| 439 | return -code return |
| 440 | } |
| 441 | |
| 442 | proc test_cleanup {} { |
| @@ -769,19 +770,35 @@ | |
| 770 | # |
| 771 | file delete $newFileName |
| 772 | } |
| 773 | } |
| 774 | |
| 775 | # Return VALUE as lines for the report of a failed test, after LABEL. |
| 776 | # A value on one line is shown in double quotes. Each line of a value |
| 777 | # on several lines is shown between "|" characters, so that leading and |
| 778 | # trailing white space is visible. |
| 779 | # |
| 780 | proc test_value_lines {label value} { |
| 781 | if {[string first \n $value] < 0} { |
| 782 | return [list "$label \"$value\""] |
| 783 | } |
| 784 | set lines [list [string trimright $label]] |
| 785 | foreach line [split $value \n] { |
| 786 | lappend lines " |$line|" |
| 787 | } |
| 788 | return $lines |
| 789 | } |
| 790 | |
| 791 | # Count test NAME as passed if OK is true, and as failed otherwise. |
| 792 | # For a failure that is not a known bug, write each line of DETAIL |
| 793 | # after the failure line. |
| 794 | # |
| 795 | proc test_report {name ok constraints detail} { |
| 796 | global bad_test ignored_test test_count |
| 797 | incr test_count |
| 798 | set knownBug [expr {"knownBug" in $constraints}] |
| 799 | if {$ok} { |
| 800 | if {$knownBug && !$::STRICT} { |
| 801 | protOut "test $name OK (knownBug)?" |
| 802 | } else { |
| 803 | protOut "test $name OK" |
| 804 | } |
| @@ -789,16 +806,66 @@ | |
| 806 | if {$knownBug && !$::STRICT} { |
| 807 | protOut "test $name FAILED (knownBug)!" 1 |
| 808 | lappend ignored_test $name |
| 809 | } else { |
| 810 | protOut "test $name FAILED!" 1 |
| 811 | foreach line $detail { |
| 812 | protOut " $line" 1 |
| 813 | } |
| 814 | lappend bad_test $name |
| 815 | if {$::HALT} {exit 1} |
| 816 | } |
| 817 | } |
| 818 | } |
| 819 | |
| 820 | # Perform a test: test NAME passes if the expression EXPR, evaluated in |
| 821 | # the caller, is true. A failure is reported with EXPR, the value of |
| 822 | # each variable in EXPR except RESULT, the last fossil command run |
| 823 | # and its output. The commands in EXPR are not run again. |
| 824 | # |
| 825 | set test_count 0 |
| 826 | set LASTCMD "" |
| 827 | proc test {name expr {constraints ""}} { |
| 828 | set r [uplevel 1 [list expr $expr]] |
| 829 | set detail [list] |
| 830 | if {!$r} { |
| 831 | lappend detail "expression: [string trim $expr]" |
| 832 | set shown [list] |
| 833 | foreach ref [regexp -all -inline \ |
| 834 | {\$\{[^\}]*\}|\$(?:::)?[A-Za-z_][A-Za-z0-9_:]*(?:\([^)]*\))?} $expr] { |
| 835 | if {$ref in $shown || |
| 836 | $ref in {$RESULT $::RESULT ${RESULT} ${::RESULT}}} continue |
| 837 | lappend shown $ref |
| 838 | if {![catch {uplevel 1 [list subst -nocommands $ref]} value]} { |
| 839 | lappend detail {*}[test_value_lines "$ref:" $value] |
| 840 | } |
| 841 | } |
| 842 | lappend detail "last command: $::LASTCMD" |
| 843 | if {[info exists ::RESULT]} { |
| 844 | lappend detail {*}[test_value_lines "its output:" $::RESULT] |
| 845 | } |
| 846 | } |
| 847 | test_report $name $r $constraints $detail |
| 848 | } |
| 849 | |
| 850 | # Test NAME passes if ACTUAL equals EXPECTED. A failure is reported |
| 851 | # with both values. |
| 852 | # |
| 853 | proc test_eq {name actual expected {constraints ""}} { |
| 854 | set detail [concat [test_value_lines "expected:" $expected] \ |
| 855 | [test_value_lines "actual: " $actual]] |
| 856 | test_report $name [expr {$actual eq $expected}] $constraints $detail |
| 857 | } |
| 858 | |
| 859 | # Test NAME passes if ACTUAL matches the regular expression PATTERN. A |
| 860 | # failure is reported with the pattern and the actual value. |
| 861 | # |
| 862 | proc test_match {name actual pattern {constraints ""}} { |
| 863 | set detail [concat [list "pattern: $pattern"] \ |
| 864 | [test_value_lines "actual: " $actual]] |
| 865 | test_report $name [regexp -- $pattern $actual] $constraints $detail |
| 866 | } |
| 867 | set bad_test {} |
| 868 | set ignored_test {} |
| 869 | set skipped_tests {} |
| 870 | |
| 871 | # Return a random string N characters long. |
| @@ -1081,11 +1148,11 @@ | |
| 1148 | cd $tempHomePath |
| 1149 | |
| 1150 | foreach testfile $argv { |
| 1151 | protOut "***** $testfile ******" |
| 1152 | if { [catch {source $testdir/$testfile.test} testerror testopts] } { |
| 1153 | test_report test-framework-$testfile 0 "" [list "error: $testerror"] |
| 1154 | protOut "!!!!! $testfile: $testerror" |
| 1155 | protOutDict $testopts" |
| 1156 | } else { |
| 1157 | test test-framework-$testfile 1 |
| 1158 | } |
| 1159 |