diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2019-12-09 11:31:25 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2019-12-09 11:31:25 (GMT) |
commit | 54b0e77083c64793570653ba6e506f173eef82f0 (patch) | |
tree | fb1dc054e0c14e1911abe23c1729f46f1a7f00b6 /library | |
parent | 39bf69006a6847b4068bd3b9b8debda81197502a (diff) | |
parent | c66173309fa8adc4c4159bdeae016c7f9e2cbae0 (diff) | |
download | tcl-54b0e77083c64793570653ba6e506f173eef82f0.zip tcl-54b0e77083c64793570653ba6e506f173eef82f0.tar.gz tcl-54b0e77083c64793570653ba6e506f173eef82f0.tar.bz2 |
Merge 8.6
Diffstat (limited to 'library')
-rw-r--r-- | library/tcltest/tcltest.tcl | 119 |
1 files changed, 66 insertions, 53 deletions
diff --git a/library/tcltest/tcltest.tcl b/library/tcltest/tcltest.tcl index 28c50ef..e5dbdfe 100644 --- a/library/tcltest/tcltest.tcl +++ b/library/tcltest/tcltest.tcl @@ -1982,18 +1982,24 @@ proc tcltest::test {name description args} { } } - # First, run the setup script - set code [catch { - uplevel 1 [list [namespace which SetupTest] $setup] - } setupMsg] + # First, run the setup script (or a hook if it presents): + if {[set cmd [uplevel 1 {namespace which SetupTest}]] ne ""} { + set setup [list $cmd $setup] + } + set processTest 1 + set code [catch {uplevel 1 $setup} setupMsg] if {$code == 1} { set errorInfo(setup) $::errorInfo set errorCodeRes(setup) $::errorCode + if {$errorCodeRes(setup) eq "BYPASS-SKIPPED-TEST"} { + _noticeSkipped $name $setupMsg + set processTest [set code 0] + } } set setupFailure [expr {$code != 0}] # Only run the test body if the setup was successful - if {!$setupFailure} { + if {$processTest && !$setupFailure} { # Register startup time if {[IsVerbose msec] || [IsVerbose usec]} { @@ -2016,16 +2022,20 @@ proc tcltest::test {name description args} { if {$returnCode == 1} { set errorInfo(body) $::errorInfo set errorCodeRes(body) $::errorCode + if {$errorCodeRes(body) eq "BYPASS-SKIPPED-TEST"} { + _noticeSkipped $name $actualAnswer + set processTest [set returnCode 0] + } } } # check if the return code matched the expected return code set codeFailure 0 - if {!$setupFailure && ($returnCode ni $returnCodes)} { + if {$processTest && !$setupFailure && ($returnCode ni $returnCodes)} { set codeFailure 1 } set errorCodeFailure 0 - if {!$setupFailure && !$codeFailure && $returnCode == 1 && \ + if {$processTest && !$setupFailure && !$codeFailure && $returnCode == 1 && \ ![string match $errorCode $errorCodeRes(body)]} { set errorCodeFailure 1 } @@ -2034,7 +2044,7 @@ proc tcltest::test {name description args} { # them. If the comparison fails, then so did the test. set outputFailure 0 variable outData - if {[info exists output] && !$codeFailure} { + if {$processTest && [info exists output] && !$codeFailure} { if {[set outputCompare [catch { CompareStrings $outData $output $match } outputMatch]] == 0} { @@ -2046,7 +2056,7 @@ proc tcltest::test {name description args} { set errorFailure 0 variable errData - if {[info exists errorOutput] && !$codeFailure} { + if {$processTest && [info exists errorOutput] && !$codeFailure} { if {[set errorCompare [catch { CompareStrings $errData $errorOutput $match } errorMatch]] == 0} { @@ -2058,7 +2068,9 @@ proc tcltest::test {name description args} { # check if the answer matched the expected answer # Only check if we ran the body of the test (no setup failure) - if {$setupFailure || $codeFailure} { + if {!$processTest} { + set scriptFailure 0 + } elseif {$setupFailure || $codeFailure} { set scriptFailure 0 } elseif {[set scriptCompare [catch { CompareStrings $actualAnswer $result $match @@ -2068,10 +2080,11 @@ proc tcltest::test {name description args} { set scriptFailure 1 } - # Always run the cleanup script - set code [catch { - uplevel 1 [list [namespace which CleanupTest] $cleanup] - } cleanupMsg] + # Always run the cleanup script (or a hook if it presents): + if {[set cmd [uplevel 1 {namespace which CleanupTest}]] ne ""} { + set cleanup [list $cmd $cleanup] + } + set code [catch {uplevel 1 $cleanup} cleanupMsg] if {$code == 1} { set errorInfo(cleanup) $::errorInfo set errorCodeRes(cleanup) $::errorCode @@ -2121,6 +2134,12 @@ proc tcltest::test {name description args} { } } + # if skipped, it is safe to return here + if {!$processTest} { + incr testLevel -1 + return + } + # if we didn't experience any failures, then we passed variable numTests if {!($setupFailure || $cleanupFailure || $coreFailure @@ -2181,7 +2200,7 @@ proc tcltest::test {name description args} { puts [outputChannel] "---- errorCode(setup): $errorCodeRes(setup)" } } - if {$scriptFailure} { + if {$processTest && $scriptFailure} { if {$scriptCompare} { puts [outputChannel] "---- Error testing result: $scriptMatch" } else { @@ -2248,6 +2267,32 @@ proc tcltest::test {name description args} { return } +# Skip -- +# +# Skips a running test and add a reason to skipped "constraints". Can be used +# to conditional intended abort of the test. +# +# Side Effects: Maintains tally of total tests seen and tests skipped. +# +proc tcltest::Skip {reason} { + return -code error -errorcode BYPASS-SKIPPED-TEST $reason +} + +proc tcltest::_noticeSkipped {name reason} { + variable testLevel + variable numTests + + if {[IsVerbose skip]} { + puts [outputChannel] "++++ $name SKIPPED: $reason" + } + + if {$testLevel == 1} { + incr numTests(Skipped) + AddToSkippedBecause $reason + } +} + + # Skipped -- # # Given a test name and it constraints, returns a boolean indicating @@ -2328,22 +2373,13 @@ proc tcltest::Skipped {name constraints} { } if {!$doTest} { - if {[IsVerbose skip]} { - puts [outputChannel] "++++ $name SKIPPED: $constraints" - } - - if {$testLevel == 1} { - incr numTests(Skipped) - AddToSkippedBecause $constraints - } + _noticeSkipped $name $constraints return 1 } } return 0 } - - # RunTest -- # # This is where the body of a test is evaluated. The combination of @@ -2360,38 +2396,15 @@ proc tcltest::RunTest {name script} { memory tag $name } - set code [catch {uplevel 1 [list [ - namespace origin EvalTest] $script]} actualAnswer copts] + # run the test script (or a hook if it presents): + if {[set cmd [uplevel 1 {namespace which EvalTest}]] ne ""} { + set script [list $cmd $script] + } + set code [catch {uplevel 1 $script} actualAnswer] return [list $actualAnswer $code] } - -proc tcltest::EvalTest script { - set code [catch {uplevel 1 $script} cres copts] - dict set copts -code $code - dict incr copts -level - return -options $copts $cres -} - - - -# SetupTest -- -# -# Evaluates the -setup script for a test - -proc tcltest::SetupTest setup { - uplevel 1 $setup -} - - -# CleanupTest -- -# -# Evaluates the -cleanup script for a test -proc tcltest::CleanupTest cleanup { - uplevel 1 $cleanup -} - ##################################################################### # tcltest::cleanupTestsHook -- |