| 1 |
# This file contains a collection of tests for one or more of the Tcl |
| 2 |
# built-in commands. Sourcing this file into Tcl runs the tests and |
| 3 |
# generates output for errors. No output means no errors were found. |
| 4 |
# |
| 5 |
# Copyright (c) 1998-1999 Scriptics Corporation. |
| 6 |
# Copyright (c) 2000 Ajuba Solutions |
| 7 |
# All rights reserved. |
| 8 |
|
| 9 |
# Note that there are several places where the value of |
| 10 |
# tcltest::currentFailure is stored/reset in the -setup/-cleanup |
| 11 |
# of a test that has a body that runs [test] that will fail. |
| 12 |
# This is a workaround of using the same tcltest code that we are |
| 13 |
# testing to run the test itself. Ditto on things like [verbose]. |
| 14 |
# |
| 15 |
# It would be better to have the -body of the tests run the tcltest |
| 16 |
# commands in a child interp so the [test] being tested would not |
| 17 |
# interfere with the [test] doing the testing. |
| 18 |
# |
| 19 |
|
| 20 |
if {"::tcltest" ni [namespace children]} { |
| 21 |
package require tcltest 2.1 |
| 22 |
namespace import -force ::tcltest::* |
| 23 |
} |
| 24 |
|
| 25 |
# File permissions broken on wsl without some "exotic" wsl configuration |
| 26 |
testConstraint notWsl [expr {[llength [array names ::env *WSL*]] == 0}] |
| 27 |
|
| 28 |
namespace eval ::tcltest::test { |
| 29 |
|
| 30 |
namespace import ::tcltest::* |
| 31 |
|
| 32 |
makeFile { |
| 33 |
package require tcltest 2.5 |
| 34 |
namespace import ::tcltest::test |
| 35 |
test a-1.0 {test a} { |
| 36 |
list 0 |
| 37 |
} {0} |
| 38 |
test b-1.0 {test b} { |
| 39 |
list 1 |
| 40 |
} {0} |
| 41 |
test c-1.0 {test c} {knownBug} { |
| 42 |
} {} |
| 43 |
test d-1.0 {test d} { |
| 44 |
error "foo" foo 9 |
| 45 |
} {} |
| 46 |
tcltest::cleanupTests |
| 47 |
exit |
| 48 |
} test.tcl |
| 49 |
|
| 50 |
cd [temporaryDirectory] |
| 51 |
testConstraint exec [llength [info commands exec]] |
| 52 |
|
| 53 |
# test -help |
| 54 |
# Child processes because -help [exit]s. |
| 55 |
test tcltest-1.1 {tcltest -help} {exec} { |
| 56 |
set result [catch {exec [interpreter] test.tcl -help} msg] |
| 57 |
list $result [regexp Usage $msg] |
| 58 |
} {1 1} |
| 59 |
test tcltest-1.2 {tcltest -help -something} {exec} { |
| 60 |
set result [catch {exec [interpreter] test.tcl -help -something} msg] |
| 61 |
list $result [regexp Usage $msg] |
| 62 |
} {1 1} |
| 63 |
test tcltest-1.3 {tcltest -h} {exec} { |
| 64 |
set result [catch {exec [interpreter] test.tcl -h} msg] |
| 65 |
list $result [regexp Usage $msg] |
| 66 |
} {1 0} |
| 67 |
|
| 68 |
# -verbose, implicit & explicit testing of [verbose] |
| 69 |
proc child {msgVar args} { |
| 70 |
upvar 1 $msgVar msg |
| 71 |
|
| 72 |
interp create [namespace current]::i |
| 73 |
# Fake the child interp into dumping output to a file |
| 74 |
i eval {namespace eval ::tcltest {}} |
| 75 |
i eval "set tcltest::outputChannel\ |
| 76 |
\[[list open [set of [makeFile {} output]] w]]" |
| 77 |
i eval "set tcltest::errorChannel\ |
| 78 |
\[[list open [set ef [makeFile {} error]] w]]" |
| 79 |
i eval [list set argv0 [lindex $args 0]] |
| 80 |
i eval [list set argv [lrange $args 1 end]] |
| 81 |
i eval [list package ifneeded tcltest [package provide tcltest] \ |
| 82 |
[package ifneeded tcltest [package provide tcltest]]] |
| 83 |
i eval {proc exit args {}} |
| 84 |
|
| 85 |
# Need to capture output in msg |
| 86 |
|
| 87 |
set code [catch {i eval {source $argv0}}] |
| 88 |
i eval {close $tcltest::outputChannel} |
| 89 |
interp delete [namespace current]::i |
| 90 |
set f [open $of] |
| 91 |
set msg [read -nonewline $f] |
| 92 |
close $f |
| 93 |
set f [open $ef] |
| 94 |
set err [read -nonewline $f] |
| 95 |
close $f |
| 96 |
removeFile output |
| 97 |
removeFile error |
| 98 |
if {[string length $err]} { |
| 99 |
set code 1 |
| 100 |
append msg \n$err |
| 101 |
} |
| 102 |
return $code |
| 103 |
} |
| 104 |
test tcltest-2.0 {tcltest (verbose default - 'b')} {unixOrWin} { |
| 105 |
set result [child msg test.tcl] |
| 106 |
list $result [regexp "Contents of test case" $msg] [regexp a-1.0 $msg] \ |
| 107 |
[regexp c-1.0 $msg] \ |
| 108 |
[regexp "Total.+4.+Passed.+1.+Skipped.+1.+Failed.+2" $msg] |
| 109 |
} {0 1 0 0 1} |
| 110 |
test tcltest-2.1 {tcltest -verbose 'b'} {unixOrWin} { |
| 111 |
set result [child msg test.tcl -verbose 'b'] |
| 112 |
list $result [regexp "Contents of test case" $msg] [regexp a-1.0 $msg] \ |
| 113 |
[regexp c-1.0 $msg] \ |
| 114 |
[regexp "Total.+4.+Passed.+1.+Skipped.+1.+Failed.+2" $msg] |
| 115 |
} {0 1 0 0 1} |
| 116 |
test tcltest-2.2 {tcltest -verbose 'p'} {unixOrWin} { |
| 117 |
set result [child msg test.tcl -verbose 'p'] |
| 118 |
list $result [regexp "Contents of test case" $msg] [regexp a-1.0 $msg] \ |
| 119 |
[regexp c-1.0 $msg] \ |
| 120 |
[regexp "Total.+4.+Passed.+1.+Skipped.+1.+Failed.+2" $msg] |
| 121 |
} {0 0 1 0 1} |
| 122 |
test tcltest-2.3 {tcltest -verbose 's'} {unixOrWin} { |
| 123 |
set result [child msg test.tcl -verbose 's'] |
| 124 |
list $result [regexp "Contents of test case" $msg] [regexp a-1.0 $msg] \ |
| 125 |
[regexp c-1.0 $msg] \ |
| 126 |
[regexp "Total.+4.+Passed.+1.+Skipped.+1.+Failed.+2" $msg] |
| 127 |
} {0 0 0 1 1} |
| 128 |
test tcltest-2.4 {tcltest -verbose 'ps'} {unixOrWin} { |
| 129 |
set result [child msg test.tcl -verbose 'ps'] |
| 130 |
list $result [regexp "Contents of test case" $msg] [regexp a-1.0 $msg] \ |
| 131 |
[regexp c-1.0 $msg] \ |
| 132 |
[regexp "Total.+4.+Passed.+1.+Skipped.+1.+Failed.+2" $msg] |
| 133 |
} {0 0 1 1 1} |
| 134 |
test tcltest-2.5 {tcltest -verbose 'psb'} {unixOrWin} { |
| 135 |
set result [child msg test.tcl -verbose 'psb'] |
| 136 |
list $result [regexp "Contents of test case" $msg] [regexp a-1.0 $msg] \ |
| 137 |
[regexp c-1.0 $msg] \ |
| 138 |
[regexp "Total.+4.+Passed.+1.+Skipped.+1.+Failed.+2" $msg] |
| 139 |
} {0 1 1 1 1} |
| 140 |
|
| 141 |
test tcltest-2.5a {tcltest -verbose 'pass skip body'} {unixOrWin} { |
| 142 |
set result [child msg test.tcl -verbose "pass skip body"] |
| 143 |
list $result [regexp "Contents of test case" $msg] [regexp a-1.0 $msg] \ |
| 144 |
[regexp c-1.0 $msg] \ |
| 145 |
[regexp "Total.+4.+Passed.+1.+Skipped.+1.+Failed.+2" $msg] |
| 146 |
} {0 1 1 1 1} |
| 147 |
|
| 148 |
test tcltest-2.6 {tcltest -verbose 't'} { |
| 149 |
-constraints {unixOrWin} |
| 150 |
-body { |
| 151 |
set result [child msg test.tcl -verbose 't'] |
| 152 |
list $result $msg |
| 153 |
} |
| 154 |
-result {^0 .*a-1.0 start.*b-1.0 start} |
| 155 |
-match regexp |
| 156 |
} |
| 157 |
|
| 158 |
test tcltest-2.6a {tcltest -verbose 'start'} { |
| 159 |
-constraints {unixOrWin} |
| 160 |
-body { |
| 161 |
set result [child msg test.tcl -verbose start] |
| 162 |
list $result $msg |
| 163 |
} |
| 164 |
-result {^0 .*a-1.0 start.*b-1.0 start} |
| 165 |
-match regexp |
| 166 |
} |
| 167 |
|
| 168 |
test tcltest-2.7 {tcltest::verbose} { |
| 169 |
-body { |
| 170 |
set oldVerbosity [verbose] |
| 171 |
verbose bar |
| 172 |
set currentVerbosity [verbose] |
| 173 |
verbose foo |
| 174 |
set newVerbosity [verbose] |
| 175 |
verbose $oldVerbosity |
| 176 |
list $currentVerbosity $newVerbosity |
| 177 |
} |
| 178 |
-result {body {}} |
| 179 |
} |
| 180 |
|
| 181 |
test tcltest-2.8 {tcltest -verbose 'error'} { |
| 182 |
-constraints {unixOrWin} |
| 183 |
-body { |
| 184 |
set result [child msg test.tcl -verbose error] |
| 185 |
list $result $msg |
| 186 |
} |
| 187 |
-result {errorInfo: foo.*errorCode: 9} |
| 188 |
-match regexp |
| 189 |
} |
| 190 |
# -match, [match] |
| 191 |
test tcltest-3.1 {tcltest -match 'a*'} {unixOrWin} { |
| 192 |
set result [child msg test.tcl -match a* -verbose 'ps'] |
| 193 |
list $result [regexp a-1.0 $msg] [regexp b-1.0 $msg] [regexp c-1.0 $msg] \ |
| 194 |
[regexp "Total.+4.+Passed.+1.+Skipped.+3.+Failed.+0" $msg] |
| 195 |
} {0 1 0 0 1} |
| 196 |
test tcltest-3.2 {tcltest -match 'b*'} {unixOrWin} { |
| 197 |
set result [child msg test.tcl -match b* -verbose 'ps'] |
| 198 |
list $result [regexp a-1.0 $msg] [regexp b-1.0 $msg] [regexp c-1.0 $msg] \ |
| 199 |
[regexp "Total.+4.+Passed.+0.+Skipped.+3.+Failed.+1" $msg] |
| 200 |
} {0 0 1 0 1} |
| 201 |
test tcltest-3.3 {tcltest -match 'c*'} {unixOrWin} { |
| 202 |
set result [child msg test.tcl -match c* -verbose 'ps'] |
| 203 |
list $result [regexp a-1.0 $msg] [regexp b-1.0 $msg] [regexp c-1.0 $msg] \ |
| 204 |
[regexp "Total.+4.+Passed.+0.+Skipped.+4.+Failed.+0" $msg] |
| 205 |
} {0 0 0 1 1} |
| 206 |
test tcltest-3.4 {tcltest -match 'a* b*'} {unixOrWin} { |
| 207 |
set result [child msg test.tcl -match {a* b*} -verbose 'ps'] |
| 208 |
list $result [regexp a-1.0 $msg] [regexp b-1.0 $msg] [regexp c-1.0 $msg] \ |
| 209 |
[regexp "Total.+4.+Passed.+1.+Skipped.+2.+Failed.+1" $msg] |
| 210 |
} {0 1 1 0 1} |
| 211 |
|
| 212 |
test tcltest-3.5 {tcltest::match} { |
| 213 |
-body { |
| 214 |
set oldMatch [match] |
| 215 |
match foo |
| 216 |
set currentMatch [match] |
| 217 |
match bar |
| 218 |
set newMatch [match] |
| 219 |
match $oldMatch |
| 220 |
list $currentMatch $newMatch |
| 221 |
} |
| 222 |
-result {foo bar} |
| 223 |
} |
| 224 |
|
| 225 |
# -skip, [skip] |
| 226 |
test tcltest-4.1 {tcltest -skip 'a*'} {unixOrWin} { |
| 227 |
set result [child msg test.tcl -skip a* -verbose 'ps'] |
| 228 |
list $result [regexp a-1.0 $msg] [regexp b-1.0 $msg] [regexp c-1.0 $msg] \ |
| 229 |
[regexp "Total.+4.+Passed.+0.+Skipped.+2.+Failed.+1" $msg] |
| 230 |
} {0 0 1 1 1} |
| 231 |
test tcltest-4.2 {tcltest -skip 'b*'} {unixOrWin} { |
| 232 |
set result [child msg test.tcl -skip b* -verbose 'ps'] |
| 233 |
list $result [regexp a-1.0 $msg] [regexp b-1.0 $msg] [regexp c-1.0 $msg] \ |
| 234 |
[regexp "Total.+4.+Passed.+1.+Skipped.+2.+Failed.+1" $msg] |
| 235 |
} {0 1 0 1 1} |
| 236 |
test tcltest-4.3 {tcltest -skip 'c*'} {unixOrWin} { |
| 237 |
set result [child msg test.tcl -skip c* -verbose 'ps'] |
| 238 |
list $result [regexp a-1.0 $msg] [regexp b-1.0 $msg] [regexp c-1.0 $msg] \ |
| 239 |
[regexp "Total.+4.+Passed.+1.+Skipped.+1.+Failed.+2" $msg] |
| 240 |
} {0 1 1 0 1} |
| 241 |
test tcltest-4.4 {tcltest -skip 'a* b*'} {unixOrWin} { |
| 242 |
set result [child msg test.tcl -skip {a* b*} -verbose 'ps'] |
| 243 |
list $result [regexp a-1.0 $msg] [regexp b-1.0 $msg] [regexp c-1.0 $msg] \ |
| 244 |
[regexp "Total.+4.+Passed.+0.+Skipped.+3.+Failed.+1" $msg] |
| 245 |
} {0 0 0 1 1} |
| 246 |
test tcltest-4.5 {tcltest -match 'a* b*' -skip 'b*'} {unixOrWin} { |
| 247 |
set result [child msg test.tcl -match {a* b*} -skip b* -verbose 'ps'] |
| 248 |
list $result [regexp a-1.0 $msg] [regexp b-1.0 $msg] [regexp c-1.0 $msg] \ |
| 249 |
[regexp "Total.+4.+Passed.+1.+Skipped.+3.+Failed.+0" $msg] |
| 250 |
} {0 1 0 0 1} |
| 251 |
|
| 252 |
test tcltest-4.6 {tcltest::skip} { |
| 253 |
-body { |
| 254 |
set oldSkip [skip] |
| 255 |
skip foo |
| 256 |
set currentSkip [skip] |
| 257 |
skip bar |
| 258 |
set newSkip [skip] |
| 259 |
skip $oldSkip |
| 260 |
list $currentSkip $newSkip |
| 261 |
} |
| 262 |
-result {foo bar} |
| 263 |
} |
| 264 |
|
| 265 |
# -constraints, -limitconstraints, [testConstraint], |
| 266 |
# $constraintsSpecified, [limitConstraints] |
| 267 |
test tcltest-5.1 {tcltest -constraints 'knownBug'} {unixOrWin} { |
| 268 |
set result [child msg test.tcl -constraints knownBug -verbose 'ps'] |
| 269 |
list $result [regexp a-1.0 $msg] [regexp b-1.0 $msg] [regexp c-1.0 $msg] \ |
| 270 |
[regexp "Total.+4.+Passed.+2.+Skipped.+0.+Failed.+2" $msg] |
| 271 |
} {0 1 1 1 1} |
| 272 |
test tcltest-5.2 {tcltest -constraints 'knownBug' -limitconstraints 1} {unixOrWin} { |
| 273 |
set result [child msg test.tcl -constraints knownBug -verbose 'p' -limitconstraints 1] |
| 274 |
list $result [regexp a-1.0 $msg] [regexp b-1.0 $msg] [regexp c-1.0 $msg] \ |
| 275 |
[regexp "Total.+4.+Passed.+1.+Skipped.+3.+Failed.+0" $msg] |
| 276 |
} {0 0 0 1 1} |
| 277 |
|
| 278 |
test tcltest-5.3 {testConstraint - constraint empty (tcltest::safeFetch)} { |
| 279 |
-body { |
| 280 |
set r1 [testConstraint tcltestFakeConstraint] |
| 281 |
set r2 [testConstraint tcltestFakeConstraint 4] |
| 282 |
set r3 [testConstraint tcltestFakeConstraint] |
| 283 |
list $r1 $r2 $r3 |
| 284 |
} |
| 285 |
-result {0 4 4} |
| 286 |
-cleanup {unset ::tcltest::testConstraints(tcltestFakeConstraint)} |
| 287 |
} |
| 288 |
|
| 289 |
# Removed this test of internals of tcltest. Those internals have changed. |
| 290 |
#test tcltest-5.4 {tcltest::constraintsSpecified} { |
| 291 |
# -setup { |
| 292 |
# set constraintlist $::tcltest::constraintsSpecified |
| 293 |
# set ::tcltest::constraintsSpecified {} |
| 294 |
# } |
| 295 |
# -body { |
| 296 |
# set r1 $::tcltest::constraintsSpecified |
| 297 |
# testConstraint tcltestFakeConstraint1 1 |
| 298 |
# set r2 $::tcltest::constraintsSpecified |
| 299 |
# testConstraint tcltestFakeConstraint2 1 |
| 300 |
# set r3 $::tcltest::constraintsSpecified |
| 301 |
# list $r1 $r2 $r3 |
| 302 |
# } |
| 303 |
# -result {{} tcltestFakeConstraint1 {tcltestFakeConstraint1 tcltestFakeConstraint2}} |
| 304 |
# -cleanup { |
| 305 |
# set ::tcltest::constraintsSpecified $constraintlist |
| 306 |
# unset ::tcltest::testConstraints(tcltestFakeConstraint1) |
| 307 |
# unset ::tcltest::testConstraints(tcltestFakeConstraint2) |
| 308 |
# } |
| 309 |
#} |
| 310 |
|
| 311 |
test tcltest-5.5 {InitConstraints: list of built-in constraints} \ |
| 312 |
-constraints {!singleTestInterp notWsl} \ |
| 313 |
-setup {tcltest::InitConstraints} \ |
| 314 |
-body { lsort [array names ::tcltest::testConstraints] } \ |
| 315 |
-result [lsort { |
| 316 |
95 98 asyncPipeClose eformat emptyTest exec hasIsoLocale interactive |
| 317 |
knownBug mac macCrash macOnly macOrPc macOrUnix macOrWin nonBlockFiles |
| 318 |
nonPortable notRoot nt pc pcCrash pcOnly root singleTestInterp socket |
| 319 |
stdio tempNotMac tempNotPc tempNotUnix tempNotWin unix unixCrash unixExecs |
| 320 |
unixOnly unixOrPc unixOrWin userInteraction win winCrash winOnly |
| 321 |
}] |
| 322 |
|
| 323 |
# Removed this broken test. Its usage of [limitConstraints] was not |
| 324 |
# in agreement with the documentation. [limitConstraints] is supposed |
| 325 |
# to take an optional boolean argument, and "knownBug" ain't no boolean! |
| 326 |
#test tcltest-5.6 {tcltest::limitConstraints} { |
| 327 |
# -setup { |
| 328 |
# set keeplc $::tcltest::limitConstraints |
| 329 |
# set keepkb [testConstraint knownBug] |
| 330 |
# } |
| 331 |
# -body { |
| 332 |
# set r1 [limitConstraints] |
| 333 |
# set r2 [limitConstraints knownBug] |
| 334 |
# set r3 [limitConstraints] |
| 335 |
# list $r1 $r2 $r3 |
| 336 |
# } |
| 337 |
# -cleanup { |
| 338 |
# limitConstraints $keeplc |
| 339 |
# testConstraint knownBug $keepkb |
| 340 |
# } |
| 341 |
# -result {false knownBug knownBug} |
| 342 |
#} |
| 343 |
|
| 344 |
# -outfile, -errfile, [outputChannel], [outputFile], [errorChannel], [errorFile] |
| 345 |
set printerror [makeFile { |
| 346 |
package require tcltest 2.5 |
| 347 |
namespace import ::tcltest::* |
| 348 |
puts [outputChannel] "a test" |
| 349 |
::tcltest::PrintError "a really short string" |
| 350 |
::tcltest::PrintError "a really really really really really really long \ |
| 351 |
string containing \"quotes\" and other bad bad stuff" |
| 352 |
::tcltest::PrintError "a really really long string containing a \ |
| 353 |
\"Path/that/is/really/long/and/contains/no/spaces\"" |
| 354 |
::tcltest::PrintError "a really really long string containing a \ |
| 355 |
\"Really/Long/Path/that/contains/no/spaces/and/is/longer/than/eighty/characters/to/see/what/happens\"" |
| 356 |
::tcltest::PrintError "Problem renaming file: error renaming \"Z:/ws/tcl8.2/win32-ix86/tests/core\" to \"Z:/ws/tcl8.2/win32-ix86/tests/movecore-core\"" |
| 357 |
exit |
| 358 |
} printerror.tcl] |
| 359 |
|
| 360 |
test tcltest-6.1 {tcltest -outfile, -errfile defaults} { |
| 361 |
-constraints unixOrWin |
| 362 |
-body { |
| 363 |
child msg $printerror |
| 364 |
return $msg |
| 365 |
} |
| 366 |
-result {a test.*a really} |
| 367 |
-match regexp |
| 368 |
} |
| 369 |
test tcltest-6.2 {tcltest -outfile a.tmp} {unixOrWin unixExecs} { |
| 370 |
child msg $printerror -outfile a.tmp |
| 371 |
set result1 [catch {exec grep "a test" a.tmp}] |
| 372 |
set result2 [catch {exec grep "a really" a.tmp}] |
| 373 |
list [regexp "a test" $msg] [regexp "a really" $msg] \ |
| 374 |
$result1 $result2 [file exists a.tmp] [file delete a.tmp] |
| 375 |
} {0 1 0 1 1 {}} |
| 376 |
test tcltest-6.3 {tcltest -errfile a.tmp} {unixOrWin unixExecs} { |
| 377 |
child msg $printerror -errfile a.tmp |
| 378 |
set result1 [catch {exec grep "a test" a.tmp}] |
| 379 |
set result2 [catch {exec grep "a really" a.tmp}] |
| 380 |
list [regexp "a test" $msg] [regexp "a really" $msg] \ |
| 381 |
$result1 $result2 [file exists a.tmp] [file delete a.tmp] |
| 382 |
} {1 0 1 0 1 {}} |
| 383 |
test tcltest-6.4 {tcltest -outfile a.tmp -errfile b.tmp} {unixOrWin unixExecs} { |
| 384 |
child msg $printerror -outfile a.tmp -errfile b.tmp |
| 385 |
set result1 [catch {exec grep "a test" a.tmp}] |
| 386 |
set result2 [catch {exec grep "a really" b.tmp}] |
| 387 |
list [regexp "a test" $msg] [regexp "a really" $msg] \ |
| 388 |
$result1 $result2 \ |
| 389 |
[file exists a.tmp] [file delete a.tmp] \ |
| 390 |
[file exists b.tmp] [file delete b.tmp] |
| 391 |
} {0 0 0 0 1 {} 1 {}} |
| 392 |
|
| 393 |
test tcltest-6.5 {tcltest::errorChannel - retrieval} { |
| 394 |
-setup { |
| 395 |
set of [errorChannel] |
| 396 |
set ::tcltest::errorChannel stderr |
| 397 |
} |
| 398 |
-body { |
| 399 |
errorChannel |
| 400 |
} |
| 401 |
-result {stderr} |
| 402 |
-cleanup { |
| 403 |
set ::tcltest::errorChannel $of |
| 404 |
} |
| 405 |
} |
| 406 |
|
| 407 |
test tcltest-6.6 {tcltest::errorFile (implicit errorChannel)} { |
| 408 |
-setup { |
| 409 |
set ef [makeFile {} efile] |
| 410 |
set of [errorFile] |
| 411 |
set ::tcltest::errorChannel stderr |
| 412 |
set ::tcltest::errorFile stderr |
| 413 |
} |
| 414 |
-body { |
| 415 |
set f0 [errorChannel] |
| 416 |
set f1 [errorFile] |
| 417 |
set f2 [errorFile $ef] |
| 418 |
set f3 [errorChannel] |
| 419 |
set f4 [errorFile] |
| 420 |
subst {$f0;$f1;$f2;$f3;$f4} |
| 421 |
} |
| 422 |
-result {stderr;stderr;.*efile;file[0-9a-f]+;.*efile} |
| 423 |
-match regexp |
| 424 |
-cleanup { |
| 425 |
errorFile $of |
| 426 |
removeFile efile |
| 427 |
} |
| 428 |
} |
| 429 |
test tcltest-6.7 {tcltest::outputChannel - retrieval} { |
| 430 |
-setup { |
| 431 |
set of [outputChannel] |
| 432 |
set ::tcltest::outputChannel stdout |
| 433 |
} |
| 434 |
-body { |
| 435 |
outputChannel |
| 436 |
} |
| 437 |
-result {stdout} |
| 438 |
-cleanup { |
| 439 |
set ::tcltest::outputChannel $of |
| 440 |
} |
| 441 |
} |
| 442 |
|
| 443 |
test tcltest-6.8 {tcltest::outputFile (implicit outputFile)} { |
| 444 |
-setup { |
| 445 |
set ef [makeFile {} efile] |
| 446 |
set of [outputFile] |
| 447 |
set ::tcltest::outputChannel stdout |
| 448 |
set ::tcltest::outputFile stdout |
| 449 |
} |
| 450 |
-body { |
| 451 |
set f0 [outputChannel] |
| 452 |
set f1 [outputFile] |
| 453 |
set f2 [outputFile $ef] |
| 454 |
set f3 [outputChannel] |
| 455 |
set f4 [outputFile] |
| 456 |
subst {$f0;$f1;$f2;$f3;$f4} |
| 457 |
} |
| 458 |
-result {stdout;stdout;.*efile;file[0-9a-f]+;.*efile} |
| 459 |
-match regexp |
| 460 |
-cleanup { |
| 461 |
outputFile $of |
| 462 |
removeFile efile |
| 463 |
} |
| 464 |
} |
| 465 |
|
| 466 |
# -debug, [debug] |
| 467 |
# Must use child processes to test -debug because it always writes |
| 468 |
# messages to stdout, and we have no way to capture stdout of a |
| 469 |
# child interp |
| 470 |
test tcltest-7.1 {tcltest test.tcl -debug 0} {unixOrWin} { |
| 471 |
catch {exec [interpreter] test.tcl -debug 0} msg |
| 472 |
regexp "Flags passed into tcltest" $msg |
| 473 |
} {0} |
| 474 |
test tcltest-7.2 {tcltest test.tcl -debug 1} {unixOrWin} { |
| 475 |
catch {exec [interpreter] test.tcl -debug 1 -skip b*} msg |
| 476 |
list [regexp userSpecifiedSkip $msg] \ |
| 477 |
[regexp "Flags passed into tcltest" $msg] |
| 478 |
} {1 0} |
| 479 |
test tcltest-7.3 {tcltest test.tcl -debug 1} {unixOrWin} { |
| 480 |
catch {exec [interpreter] test.tcl -debug 1 -match b*} msg |
| 481 |
list [regexp userSpecifiedNonMatch $msg] \ |
| 482 |
[regexp "Flags passed into tcltest" $msg] |
| 483 |
} {1 0} |
| 484 |
test tcltest-7.4 {tcltest test.tcl -debug 2} {unixOrWin} { |
| 485 |
catch {exec [interpreter] test.tcl -debug 2} msg |
| 486 |
list [regexp "Flags passed into tcltest" $msg] [regexp "Running" $msg] |
| 487 |
} {1 0} |
| 488 |
test tcltest-7.5 {tcltest test.tcl -debug 3} {unixOrWin} { |
| 489 |
catch {exec [interpreter] test.tcl -debug 3} msg |
| 490 |
list [regexp "Flags passed into tcltest" $msg] [regexp "Running" $msg] |
| 491 |
} {1 1} |
| 492 |
|
| 493 |
test tcltest-7.6 {tcltest::debug} { |
| 494 |
-setup { |
| 495 |
set old $::tcltest::debug |
| 496 |
set ::tcltest::debug 0 |
| 497 |
} |
| 498 |
-body { |
| 499 |
set f1 [debug] |
| 500 |
set f2 [debug 1] |
| 501 |
set f3 [debug] |
| 502 |
set f4 [debug 2] |
| 503 |
set f5 [debug] |
| 504 |
list $f1 $f2 $f3 $f4 $f5 |
| 505 |
} |
| 506 |
-result {0 1 1 2 2} |
| 507 |
-cleanup { |
| 508 |
set ::tcltest::debug $old |
| 509 |
} |
| 510 |
} |
| 511 |
removeFile test.tcl |
| 512 |
|
| 513 |
# directory tests |
| 514 |
|
| 515 |
set a [makeFile { |
| 516 |
package require tcltest 2.5 |
| 517 |
tcltest::makeFile {} a.tmp |
| 518 |
puts [tcltest::outputChannel] "testdir: [tcltest::testsDirectory]" |
| 519 |
exit |
| 520 |
} a.tcl] |
| 521 |
|
| 522 |
set tdiaf [makeFile {} thisdirectoryisafile] |
| 523 |
|
| 524 |
set normaldirectory [makeDirectory normaldirectory] |
| 525 |
normalizePath normaldirectory |
| 526 |
|
| 527 |
# -tmpdir, [temporaryDirectory] |
| 528 |
test tcltest-8.1 {tcltest a.tcl -tmpdir a} -constraints unixOrWin -setup { |
| 529 |
file delete -force thisdirectorydoesnotexist |
| 530 |
} -body { |
| 531 |
child msg $a -tmpdir thisdirectorydoesnotexist |
| 532 |
file exists [file join thisdirectorydoesnotexist a.tmp] |
| 533 |
} -cleanup { |
| 534 |
file delete -force thisdirectorydoesnotexist |
| 535 |
} -result 1 |
| 536 |
test tcltest-8.2 {tcltest a.tcl -tmpdir thisdirectoryisafile} { |
| 537 |
-constraints unixOrWin |
| 538 |
-body { |
| 539 |
child msg $a -tmpdir $tdiaf |
| 540 |
return $msg |
| 541 |
} |
| 542 |
-result {*not a directory*} |
| 543 |
-match glob |
| 544 |
} |
| 545 |
# Test non-writable directories, non-readable directories with directory flags |
| 546 |
set notReadableDir [file join [temporaryDirectory] notreadable] |
| 547 |
set notWritableDir [file join [temporaryDirectory] notwritable] |
| 548 |
makeDirectory notreadable |
| 549 |
makeDirectory notwritable |
| 550 |
switch -- $::tcl_platform(platform) { |
| 551 |
unix { |
| 552 |
file attributes $notReadableDir -permissions 0o333 |
| 553 |
file attributes $notWritableDir -permissions 0o555 |
| 554 |
} |
| 555 |
default { |
| 556 |
# note in FAT/NTFS we won't be able to protect directory with read-only attribute... |
| 557 |
catch {file attributes $notWritableDir -readonly 1} |
| 558 |
catch {testchmod 0o444 $notWritableDir} |
| 559 |
} |
| 560 |
} |
| 561 |
test tcltest-8.3 {tcltest a.tcl -tmpdir notReadableDir} { |
| 562 |
-constraints {unix notRoot notWsl} |
| 563 |
-body { |
| 564 |
child msg $a -tmpdir $notReadableDir |
| 565 |
return $msg |
| 566 |
} |
| 567 |
-result {*not readable*} |
| 568 |
-match glob |
| 569 |
} |
| 570 |
# This constraint doesn't go at the top of the file so that it doesn't |
| 571 |
# interfere with tcltest-5.5 |
| 572 |
testConstraint notFAT [expr { |
| 573 |
![regexp {^(FAT\d*|NTFS)$} [lindex [file system $notWritableDir] 1]] |
| 574 |
|| $::tcl_platform(platform) eq "unix" || [llength [info commands testchmod]] |
| 575 |
}] |
| 576 |
# FAT/NTFS permissions are fairly hopeless; ignore this test if that FS is used |
| 577 |
test tcltest-8.4 {tcltest a.tcl -tmpdir notWritableDir} { |
| 578 |
-constraints {unixOrWin notRoot notFAT notWsl} |
| 579 |
-body { |
| 580 |
child msg $a -tmpdir $notWritableDir |
| 581 |
return $msg |
| 582 |
} |
| 583 |
-result {*not writable*} |
| 584 |
-match glob |
| 585 |
} |
| 586 |
test tcltest-8.5 {tcltest a.tcl -tmpdir normaldirectory} { |
| 587 |
-constraints unixOrWin |
| 588 |
-body { |
| 589 |
child msg $a -tmpdir $normaldirectory |
| 590 |
# The join is necessary because the message can be split on multiple |
| 591 |
# lines |
| 592 |
file exists [file join $normaldirectory a.tmp] |
| 593 |
} |
| 594 |
-cleanup { |
| 595 |
catch {file delete [file join $normaldirectory a.tmp]} |
| 596 |
} |
| 597 |
-result 1 |
| 598 |
} |
| 599 |
cd [workingDirectory] |
| 600 |
test tcltest-8.6 {temporaryDirectory} { |
| 601 |
-setup { |
| 602 |
set old $::tcltest::temporaryDirectory |
| 603 |
set ::tcltest::temporaryDirectory $normaldirectory |
| 604 |
} |
| 605 |
-body { |
| 606 |
set f1 [temporaryDirectory] |
| 607 |
set f2 [temporaryDirectory [workingDirectory]] |
| 608 |
set f3 [temporaryDirectory] |
| 609 |
list $f1 $f2 $f3 |
| 610 |
} |
| 611 |
-result "[list $normaldirectory [workingDirectory] [workingDirectory]]" |
| 612 |
-cleanup { |
| 613 |
set ::tcltest::temporaryDirectory $old |
| 614 |
} |
| 615 |
} |
| 616 |
test tcltest-8.6a {temporaryDirectory - test format 2} -setup { |
| 617 |
set old $::tcltest::temporaryDirectory |
| 618 |
set ::tcltest::temporaryDirectory $normaldirectory |
| 619 |
} -body { |
| 620 |
set f1 [temporaryDirectory] |
| 621 |
set f2 [temporaryDirectory [workingDirectory]] |
| 622 |
set f3 [temporaryDirectory] |
| 623 |
list $f1 $f2 $f3 |
| 624 |
} -cleanup { |
| 625 |
set ::tcltest::temporaryDirectory $old |
| 626 |
} -result [list $normaldirectory [workingDirectory] [workingDirectory]] |
| 627 |
cd [temporaryDirectory] |
| 628 |
# -testdir, [testsDirectory] |
| 629 |
test tcltest-8.10 {tcltest a.tcl -testdir thisdirectorydoesnotexist} { |
| 630 |
-constraints unixOrWin |
| 631 |
-setup { |
| 632 |
file delete -force thisdirectorydoesnotexist |
| 633 |
} |
| 634 |
-body { |
| 635 |
child msg $a -testdir thisdirectorydoesnotexist |
| 636 |
return $msg |
| 637 |
} |
| 638 |
-match glob |
| 639 |
-result {*does not exist*} |
| 640 |
} |
| 641 |
test tcltest-8.11 {tcltest a.tcl -testdir thisdirectoryisafile} { |
| 642 |
-constraints unixOrWin |
| 643 |
-body { |
| 644 |
child msg $a -testdir $tdiaf |
| 645 |
return $msg |
| 646 |
} |
| 647 |
-match glob |
| 648 |
-result {*not a directory*} |
| 649 |
} |
| 650 |
test tcltest-8.12 {tcltest a.tcl -testdir notReadableDir} { |
| 651 |
-constraints {unix notRoot notWsl} |
| 652 |
-body { |
| 653 |
child msg $a -testdir $notReadableDir |
| 654 |
return $msg |
| 655 |
} |
| 656 |
-match glob |
| 657 |
-result {*not readable*} |
| 658 |
} |
| 659 |
test tcltest-8.13 {tcltest a.tcl -testdir normaldirectory} { |
| 660 |
-constraints unixOrWin |
| 661 |
-body { |
| 662 |
child msg $a -testdir $normaldirectory |
| 663 |
# The join is necessary because the message can be split on multiple |
| 664 |
# lines |
| 665 |
list [string first "testdir: $normaldirectory" [join $msg]] \ |
| 666 |
[file exists [file join [temporaryDirectory] a.tmp]] |
| 667 |
} |
| 668 |
-cleanup { |
| 669 |
file delete [file join [temporaryDirectory] a.tmp] |
| 670 |
} |
| 671 |
-result {0 1} |
| 672 |
} |
| 673 |
cd [workingDirectory] |
| 674 |
set current [pwd] |
| 675 |
test tcltest-8.14 {testsDirectory} { |
| 676 |
-setup { |
| 677 |
set old $::tcltest::testsDirectory |
| 678 |
set ::tcltest::testsDirectory $normaldirectory |
| 679 |
} |
| 680 |
-body { |
| 681 |
set f1 [testsDirectory] |
| 682 |
set f2 [testsDirectory $current] |
| 683 |
set f3 [testsDirectory] |
| 684 |
list $f1 $f2 $f3 |
| 685 |
} |
| 686 |
-result "[list $normaldirectory $current $current]" |
| 687 |
-cleanup { |
| 688 |
set ::tcltest::testsDirectory $old |
| 689 |
} |
| 690 |
} |
| 691 |
# [workingDirectory] |
| 692 |
test tcltest-8.60 {::workingDirectory} { |
| 693 |
-setup { |
| 694 |
set old $::tcltest::workingDirectory |
| 695 |
set current [pwd] |
| 696 |
set ::tcltest::workingDirectory $normaldirectory |
| 697 |
cd $normaldirectory |
| 698 |
} |
| 699 |
-body { |
| 700 |
set f1 [workingDirectory] |
| 701 |
set f2 [pwd] |
| 702 |
set f3 [workingDirectory $current] |
| 703 |
set f4 [pwd] |
| 704 |
set f5 [workingDirectory] |
| 705 |
list $f1 $f2 $f3 $f4 $f5 |
| 706 |
} |
| 707 |
-result "[list $normaldirectory \ |
| 708 |
$normaldirectory \ |
| 709 |
$current \ |
| 710 |
$current \ |
| 711 |
$current]" |
| 712 |
-cleanup { |
| 713 |
set ::tcltest::workingDirectory $old |
| 714 |
cd $current |
| 715 |
} |
| 716 |
} |
| 717 |
|
| 718 |
# clean up from directory testing |
| 719 |
|
| 720 |
switch -- $::tcl_platform(platform) { |
| 721 |
unix { |
| 722 |
file attributes $notReadableDir -permissions 0o777 |
| 723 |
file attributes $notWritableDir -permissions 0o777 |
| 724 |
} |
| 725 |
default { |
| 726 |
catch {testchmod 0o777 $notWritableDir} |
| 727 |
catch {file attributes $notWritableDir -readonly 0} |
| 728 |
} |
| 729 |
} |
| 730 |
|
| 731 |
file delete -force -- $notReadableDir $notWritableDir |
| 732 |
removeFile a.tcl |
| 733 |
removeFile thisdirectoryisafile |
| 734 |
removeDirectory normaldirectory |
| 735 |
|
| 736 |
# -file, -notfile, [matchFiles], [skipFiles] |
| 737 |
test tcltest-9.1 {-file d*.tcl} -constraints {unixOrWin} -setup { |
| 738 |
set old [testsDirectory] |
| 739 |
testsDirectory [file dirname [info script]] |
| 740 |
} -body { |
| 741 |
child msg [file join [testsDirectory] all.tcl] -file d*.test |
| 742 |
return $msg |
| 743 |
} -cleanup { |
| 744 |
testsDirectory $old |
| 745 |
} -match regexp -result {dstring\.test} |
| 746 |
|
| 747 |
test tcltest-9.2 {-file d*.tcl} -constraints {unixOrWin} -setup { |
| 748 |
set old [testsDirectory] |
| 749 |
testsDirectory [file dirname [info script]] |
| 750 |
} -body { |
| 751 |
child msg [file join [testsDirectory] all.tcl] \ |
| 752 |
-file d*.test -notfile dstring* |
| 753 |
regexp {dstring\.test} $msg |
| 754 |
} -cleanup { |
| 755 |
testsDirectory $old |
| 756 |
} -result 0 |
| 757 |
|
| 758 |
test tcltest-9.3 {matchFiles} { |
| 759 |
-body { |
| 760 |
set old [matchFiles] |
| 761 |
matchFiles foo |
| 762 |
set current [matchFiles] |
| 763 |
matchFiles bar |
| 764 |
set new [matchFiles] |
| 765 |
matchFiles $old |
| 766 |
list $current $new |
| 767 |
} |
| 768 |
-result {foo bar} |
| 769 |
} |
| 770 |
|
| 771 |
test tcltest-9.4 {skipFiles} { |
| 772 |
-body { |
| 773 |
set old [skipFiles] |
| 774 |
skipFiles foo |
| 775 |
set current [skipFiles] |
| 776 |
skipFiles bar |
| 777 |
set new [skipFiles] |
| 778 |
skipFiles $old |
| 779 |
list $current $new |
| 780 |
} |
| 781 |
-result {foo bar} |
| 782 |
} |
| 783 |
|
| 784 |
test tcltest-9.5 {GetMatchingFiles: Bug 1119798} -setup { |
| 785 |
set d [makeDirectory tmp] |
| 786 |
makeDirectory foo $d |
| 787 |
makeFile {} fee $d |
| 788 |
file copy [file join [file dirname [info script]] all.tcl] $d |
| 789 |
} -body { |
| 790 |
child msg [file join [temporaryDirectory] all.tcl] -file f* |
| 791 |
regexp {exiting with errors:} $msg |
| 792 |
} -cleanup { |
| 793 |
file delete [file join $d all.tcl] |
| 794 |
removeFile fee $d |
| 795 |
removeDirectory foo $d |
| 796 |
removeDirectory tmp |
| 797 |
} -result 0 |
| 798 |
|
| 799 |
# -preservecore, [preserveCore] |
| 800 |
set mc [makeFile { |
| 801 |
package require tcltest 2.5 |
| 802 |
namespace import ::tcltest::test |
| 803 |
test makecore {make a core file} { |
| 804 |
set f [open core w] |
| 805 |
close $f |
| 806 |
} {} |
| 807 |
::tcltest::cleanupTests |
| 808 |
return |
| 809 |
} makecore.tcl] |
| 810 |
|
| 811 |
cd [temporaryDirectory] |
| 812 |
test tcltest-10.1 {-preservecore 0} {unixOrWin} { |
| 813 |
child msg $mc -preservecore 0 |
| 814 |
file delete core |
| 815 |
regexp "Core file produced" $msg |
| 816 |
} {0} |
| 817 |
test tcltest-10.2 {-preservecore 1} {unixOrWin} { |
| 818 |
child msg $mc -preservecore 1 |
| 819 |
file delete core |
| 820 |
regexp "Core file produced" $msg |
| 821 |
} {1} |
| 822 |
test tcltest-10.3 {-preservecore 2} {unixOrWin} { |
| 823 |
child msg $mc -preservecore 2 |
| 824 |
file delete core |
| 825 |
list [regexp "Core file produced" $msg] [regexp "Moving file to" $msg] \ |
| 826 |
[regexp "core-" $msg] [file delete core-makecore] |
| 827 |
} {1 1 1 {}} |
| 828 |
test tcltest-10.4 {-preservecore 3} {unixOrWin} { |
| 829 |
child msg $mc -preservecore 3 |
| 830 |
file delete core |
| 831 |
list [regexp "Core file produced" $msg] [regexp "Moving file to" $msg] \ |
| 832 |
[regexp "core-" $msg] [file delete core-makecore] |
| 833 |
} {1 1 1 {}} |
| 834 |
|
| 835 |
# Removing this test. It makes no sense to test the ability of |
| 836 |
# [preserveCore] to accept an invalid value that will cause errors |
| 837 |
# in other parts of tcltest's operation. |
| 838 |
#test tcltest-10.5 {preserveCore} { |
| 839 |
# -body { |
| 840 |
# set old [preserveCore] |
| 841 |
# set result [preserveCore foo] |
| 842 |
# set result2 [preserveCore] |
| 843 |
# preserveCore $old |
| 844 |
# list $result $result2 |
| 845 |
# } |
| 846 |
# -result {foo foo} |
| 847 |
#} |
| 848 |
removeFile makecore.tcl |
| 849 |
|
| 850 |
# -load, -loadfile, [loadScript], [loadFile] |
| 851 |
set contents { |
| 852 |
package require tcltest 2.5 |
| 853 |
namespace import tcltest::* |
| 854 |
puts [outputChannel] $::tcltest::loadScript |
| 855 |
exit |
| 856 |
} |
| 857 |
set loadfile [makeFile $contents load.tcl] |
| 858 |
|
| 859 |
test tcltest-12.1 {-load xxx} {unixOrWin} { |
| 860 |
child msg $loadfile -load xxx |
| 861 |
return $msg |
| 862 |
} {xxx} |
| 863 |
|
| 864 |
# Using child process because of -debug usage. |
| 865 |
test tcltest-12.2 {-loadfile load.tcl} {unixOrWin} { |
| 866 |
catch {exec [interpreter] $loadfile -debug 2 -loadfile $loadfile} msg |
| 867 |
list \ |
| 868 |
[regexp {tcltest} [join [list $msg] [split $msg \n]]] \ |
| 869 |
[regexp {loadScript} [join [list $msg] [split $msg \n]]] |
| 870 |
} {1 1} |
| 871 |
|
| 872 |
test tcltest-12.3 {loadScript} { |
| 873 |
-setup { |
| 874 |
set old $::tcltest::loadScript |
| 875 |
set ::tcltest::loadScript {} |
| 876 |
} |
| 877 |
-body { |
| 878 |
set f1 [loadScript] |
| 879 |
set f2 [loadScript xxx] |
| 880 |
set f3 [loadScript] |
| 881 |
list $f1 $f2 $f3 |
| 882 |
} |
| 883 |
-result {{} xxx xxx} |
| 884 |
-cleanup { |
| 885 |
set ::tcltest::loadScript $old |
| 886 |
} |
| 887 |
} |
| 888 |
|
| 889 |
test tcltest-12.4 {loadFile} { |
| 890 |
-setup { |
| 891 |
set olds $::tcltest::loadScript |
| 892 |
set ::tcltest::loadScript {} |
| 893 |
set oldf $::tcltest::loadFile |
| 894 |
set ::tcltest::loadFile {} |
| 895 |
} |
| 896 |
-body { |
| 897 |
set f1 [loadScript] |
| 898 |
set f2 [loadFile] |
| 899 |
set f3 [loadFile $loadfile] |
| 900 |
set f4 [loadScript] |
| 901 |
set f5 [loadFile] |
| 902 |
list $f1 $f2 $f3 $f4 $f5 |
| 903 |
} |
| 904 |
-result "[list {} {} $loadfile $contents $loadfile]\n" |
| 905 |
-cleanup { |
| 906 |
set ::tcltest::loadScript $olds |
| 907 |
set ::tcltest::loadFile $oldf |
| 908 |
} |
| 909 |
} |
| 910 |
removeFile load.tcl |
| 911 |
|
| 912 |
# [interpreter] |
| 913 |
test tcltest-13.1 {interpreter} { |
| 914 |
-constraints notValgrind |
| 915 |
-setup { |
| 916 |
#to do: Why is $::tcltest::tcltest being saved and restored here? |
| 917 |
set old $::tcltest::tcltest |
| 918 |
set ::tcltest::tcltest tcltest |
| 919 |
} |
| 920 |
-body { |
| 921 |
set f1 [interpreter] |
| 922 |
set f2 [interpreter tclsh] |
| 923 |
set f3 [interpreter] |
| 924 |
list $f1 $f2 $f3 |
| 925 |
} |
| 926 |
-result {tcltest tclsh tclsh} |
| 927 |
-cleanup { |
| 928 |
# writing ::tcltest::tcltest triggers a trace that sets up the stdio |
| 929 |
# constraint, which involves a call to [exec] that might fail after |
| 930 |
# "fork" and before "exec", in which case the forked process will not |
| 931 |
# have a chance to clean itself up before exiting, which causes |
| 932 |
# valgrind to issue numerous "still reachable" reports. |
| 933 |
set ::tcltest::tcltest $old |
| 934 |
} |
| 935 |
} |
| 936 |
|
| 937 |
# -singleproc, [singleProcess] |
| 938 |
set spd [makeDirectory singleprocdir] |
| 939 |
makeFile { |
| 940 |
set foo 1 |
| 941 |
} single1.test $spd |
| 942 |
|
| 943 |
makeFile { |
| 944 |
unset foo |
| 945 |
} single2.test $spd |
| 946 |
|
| 947 |
set allfile [makeFile { |
| 948 |
package require tcltest 2.5 |
| 949 |
namespace import tcltest::* |
| 950 |
testsDirectory [file join [temporaryDirectory] singleprocdir] |
| 951 |
runAllTests |
| 952 |
} all-single.tcl $spd] |
| 953 |
cd [workingDirectory] |
| 954 |
|
| 955 |
test tcltest-14.1 {-singleproc - single process} { |
| 956 |
-constraints {unixOrWin} |
| 957 |
-body { |
| 958 |
child msg $allfile -singleproc 0 -tmpdir [temporaryDirectory] |
| 959 |
return $msg |
| 960 |
} |
| 961 |
-result {Test file error: can't unset .foo.: no such variable} |
| 962 |
-match regexp |
| 963 |
} |
| 964 |
|
| 965 |
test tcltest-14.2 {-singleproc - multiple process} { |
| 966 |
-constraints {unixOrWin} |
| 967 |
-body { |
| 968 |
child msg $allfile -singleproc 1 -tmpdir [temporaryDirectory] |
| 969 |
return $msg |
| 970 |
} |
| 971 |
-result {single1.test.*single2.test.*all\-single.tcl:.*Total.*0.*Passed.*0.*Skipped.*0.*Failed.*0} |
| 972 |
-match regexp |
| 973 |
} |
| 974 |
|
| 975 |
test tcltest-14.3 {singleProcess} { |
| 976 |
-setup { |
| 977 |
set old $::tcltest::singleProcess |
| 978 |
set ::tcltest::singleProcess 0 |
| 979 |
} |
| 980 |
-body { |
| 981 |
set f1 [singleProcess] |
| 982 |
set f2 [singleProcess 1] |
| 983 |
set f3 [singleProcess] |
| 984 |
list $f1 $f2 $f3 |
| 985 |
} |
| 986 |
-result {0 1 1} |
| 987 |
-cleanup { |
| 988 |
set ::tcltest::singleProcess $old |
| 989 |
} |
| 990 |
} |
| 991 |
removeFile single1.test $spd |
| 992 |
removeFile single2.test $spd |
| 993 |
removeDirectory singleprocdir |
| 994 |
|
| 995 |
# -asidefromdir, -relateddir, [matchDirectories], [skipDirectories] |
| 996 |
|
| 997 |
# Before running these tests, need to set up test subdirectories with their own |
| 998 |
# all.tcl files. |
| 999 |
|
| 1000 |
set dtd [makeDirectory dirtestdir] |
| 1001 |
set dtd1 [makeDirectory dirtestdir2.1 $dtd] |
| 1002 |
set dtd2 [makeDirectory dirtestdir2.2 $dtd] |
| 1003 |
set dtd3 [makeDirectory dirtestdir2.3 $dtd] |
| 1004 |
makeFile { |
| 1005 |
package require tcltest 2.5 |
| 1006 |
namespace import -force tcltest::* |
| 1007 |
testsDirectory [file join [temporaryDirectory] dirtestdir] |
| 1008 |
runAllTests |
| 1009 |
} all.tcl $dtd |
| 1010 |
makeFile { |
| 1011 |
package require tcltest 2.5 |
| 1012 |
namespace import -force tcltest::* |
| 1013 |
testsDirectory [file join [temporaryDirectory] dirtestdir dirtestdir2.1] |
| 1014 |
runAllTests |
| 1015 |
} all.tcl $dtd1 |
| 1016 |
makeFile { |
| 1017 |
package require tcltest 2.5 |
| 1018 |
namespace import -force tcltest::* |
| 1019 |
testsDirectory [file join [temporaryDirectory] dirtestdir dirtestdir2.2] |
| 1020 |
runAllTests |
| 1021 |
} all.tcl $dtd2 |
| 1022 |
makeFile { |
| 1023 |
package require tcltest 2.5 |
| 1024 |
namespace import -force tcltest::* |
| 1025 |
testsDirectory [file join [temporaryDirectory] dirtestdir dirtestdir2.3] |
| 1026 |
runAllTests |
| 1027 |
} all.tcl $dtd3 |
| 1028 |
|
| 1029 |
test tcltest-15.1 {basic directory walking} { |
| 1030 |
-constraints {unixOrWin} |
| 1031 |
-body { |
| 1032 |
if {[child msg \ |
| 1033 |
[file join $dtd all.tcl] \ |
| 1034 |
-tmpdir [temporaryDirectory]] == 1} { |
| 1035 |
error $msg |
| 1036 |
} |
| 1037 |
} |
| 1038 |
-match regexp |
| 1039 |
-returnCodes 1 |
| 1040 |
-result {Tests located in:.*dirtestdir.*Tests located in:.*dirtestdir2.[123].*Tests located in:.*dirtestdir2.[123].*Tests located in:.*dirtestdir2.[123]} |
| 1041 |
} |
| 1042 |
|
| 1043 |
test tcltest-15.2 {-asidefromdir} { |
| 1044 |
-constraints {unixOrWin} |
| 1045 |
-body { |
| 1046 |
if {[child msg \ |
| 1047 |
[file join $dtd all.tcl] \ |
| 1048 |
-asidefromdir dirtestdir2.3 \ |
| 1049 |
-tmpdir [temporaryDirectory]] == 1} { |
| 1050 |
error $msg |
| 1051 |
} |
| 1052 |
} |
| 1053 |
-match regexp |
| 1054 |
-returnCodes 1 |
| 1055 |
-result {Tests located in:.*dirtestdir.*Tests located in:.*dirtestdir2.[12].*Tests located in:.*dirtestdir2.[12].*dirtestdir2.[12] test ended at .*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1056 |
Error: No test files remain after applying your match and skip patterns! |
| 1057 |
Error: No test files remain after applying your match and skip patterns! |
| 1058 |
Error: No test files remain after applying your match and skip patterns!$} |
| 1059 |
} |
| 1060 |
|
| 1061 |
test tcltest-15.3 {-relateddir, non-existent dir} { |
| 1062 |
-constraints {unixOrWin} |
| 1063 |
-body { |
| 1064 |
if {[child msg \ |
| 1065 |
[file join $dtd all.tcl] \ |
| 1066 |
-relateddir [file join [temporaryDirectory] dirtestdir0] \ |
| 1067 |
-tmpdir [temporaryDirectory]] == 1} { |
| 1068 |
error $msg |
| 1069 |
} |
| 1070 |
} |
| 1071 |
-returnCodes 1 |
| 1072 |
-match regexp |
| 1073 |
-result {[^~]|dirtestdir[^2]} |
| 1074 |
} |
| 1075 |
|
| 1076 |
test tcltest-15.4 {-relateddir, subdir} { |
| 1077 |
-constraints {unixOrWin} |
| 1078 |
-body { |
| 1079 |
if {[child msg \ |
| 1080 |
[file join $dtd all.tcl] \ |
| 1081 |
-relateddir dirtestdir2.1 -tmpdir [temporaryDirectory]] == 1} { |
| 1082 |
error $msg |
| 1083 |
} |
| 1084 |
} |
| 1085 |
-returnCodes 1 |
| 1086 |
-match regexp |
| 1087 |
-result {Tests located in:.*dirtestdir2.[^23]} |
| 1088 |
} |
| 1089 |
test tcltest-15.5 {-relateddir, -asidefromdir} { |
| 1090 |
-constraints {unixOrWin} |
| 1091 |
-body { |
| 1092 |
if {[child msg \ |
| 1093 |
[file join $dtd all.tcl] \ |
| 1094 |
-relateddir "dirtestdir2.1 dirtestdir2.2" \ |
| 1095 |
-asidefromdir dirtestdir2.2 \ |
| 1096 |
-tmpdir [temporaryDirectory]] == 1} { |
| 1097 |
error $msg |
| 1098 |
} |
| 1099 |
} |
| 1100 |
-match regexp |
| 1101 |
-returnCodes 1 |
| 1102 |
-result {Tests located in:.*dirtestdir2.[^23]} |
| 1103 |
} |
| 1104 |
|
| 1105 |
test tcltest-15.6 {matchDirectories} { |
| 1106 |
-setup { |
| 1107 |
set old [matchDirectories] |
| 1108 |
set ::tcltest::matchDirectories {} |
| 1109 |
} |
| 1110 |
-body { |
| 1111 |
set r1 [matchDirectories] |
| 1112 |
set r2 [matchDirectories foo] |
| 1113 |
set r3 [matchDirectories] |
| 1114 |
list $r1 $r2 $r3 |
| 1115 |
} |
| 1116 |
-cleanup { |
| 1117 |
set ::tcltest::matchDirectories $old |
| 1118 |
} |
| 1119 |
-result {{} foo foo} |
| 1120 |
} |
| 1121 |
|
| 1122 |
test tcltest-15.7 {skipDirectories} { |
| 1123 |
-setup { |
| 1124 |
set old [skipDirectories] |
| 1125 |
set ::tcltest::skipDirectories {} |
| 1126 |
} |
| 1127 |
-body { |
| 1128 |
set r1 [skipDirectories] |
| 1129 |
set r2 [skipDirectories foo] |
| 1130 |
set r3 [skipDirectories] |
| 1131 |
list $r1 $r2 $r3 |
| 1132 |
} |
| 1133 |
-cleanup { |
| 1134 |
set ::tcltest::skipDirectories $old |
| 1135 |
} |
| 1136 |
-result {{} foo foo} |
| 1137 |
} |
| 1138 |
removeDirectory dirtestdir2.3 $dtd |
| 1139 |
removeDirectory dirtestdir2.2 $dtd |
| 1140 |
removeDirectory dirtestdir2.1 $dtd |
| 1141 |
removeDirectory dirtestdir |
| 1142 |
|
| 1143 |
# TCLTEST_OPTIONS |
| 1144 |
test tcltest-19.1 {TCLTEST_OPTIONS default} -setup { |
| 1145 |
if {[info exists ::env(TCLTEST_OPTIONS)]} { |
| 1146 |
set oldoptions $::env(TCLTEST_OPTIONS) |
| 1147 |
} else { |
| 1148 |
set oldoptions none |
| 1149 |
} |
| 1150 |
# set this to { } instead of just {} to get around quirk in |
| 1151 |
# Windows env handling that removes empty elements from env array. |
| 1152 |
set ::env(TCLTEST_OPTIONS) { } |
| 1153 |
interp create child1 |
| 1154 |
child1 eval [list set argv {-debug 2}] |
| 1155 |
child1 alias puts puts |
| 1156 |
interp create child2 |
| 1157 |
child2 alias puts puts |
| 1158 |
} -cleanup { |
| 1159 |
interp delete child2 |
| 1160 |
interp delete child1 |
| 1161 |
if {$oldoptions eq "none"} { |
| 1162 |
unset ::env(TCLTEST_OPTIONS) |
| 1163 |
} else { |
| 1164 |
set ::env(TCLTEST_OPTIONS) $oldoptions |
| 1165 |
} |
| 1166 |
} -body { |
| 1167 |
child1 eval [package ifneeded tcltest [package provide tcltest]] |
| 1168 |
child1 eval tcltest::debug |
| 1169 |
set ::env(TCLTEST_OPTIONS) "-debug 3" |
| 1170 |
child2 eval [package ifneeded tcltest [package provide tcltest]] |
| 1171 |
child2 eval tcltest::debug |
| 1172 |
} -result {^3$} -match regexp -output\ |
| 1173 |
{tcltest::debug\s+= 2.*tcltest::debug\s+= 3} |
| 1174 |
|
| 1175 |
# Begin testing of tcltest procs ... |
| 1176 |
|
| 1177 |
cd [temporaryDirectory] |
| 1178 |
# PrintError |
| 1179 |
test tcltest-20.1 {PrintError} {unixOrWin} { |
| 1180 |
set result [child msg $printerror] |
| 1181 |
list $result [regexp "Error: a really short string" $msg] \ |
| 1182 |
[regexp " \"quotes\"" $msg] [regexp " \"Path" $msg] \ |
| 1183 |
[regexp " \"Really" $msg] [regexp Problem $msg] |
| 1184 |
} {1 1 1 1 1 1} |
| 1185 |
cd [workingDirectory] |
| 1186 |
removeFile printerror.tcl |
| 1187 |
|
| 1188 |
# test::test |
| 1189 |
test tcltest-21.0 {name and desc but no args specified} -setup { |
| 1190 |
set v [verbose] |
| 1191 |
} -cleanup { |
| 1192 |
verbose $v |
| 1193 |
} -body { |
| 1194 |
verbose {} |
| 1195 |
test tcltest-21.0.0 bar |
| 1196 |
} -result {} |
| 1197 |
|
| 1198 |
test tcltest-21.1 {expect with glob} { |
| 1199 |
-body { |
| 1200 |
list a b c d e |
| 1201 |
} |
| 1202 |
-match glob |
| 1203 |
-result {[ab] b c d e} |
| 1204 |
} |
| 1205 |
|
| 1206 |
test tcltest-21.2 {force a test command failure} { |
| 1207 |
-body { |
| 1208 |
test tcltest-21.2.0 { |
| 1209 |
return 2 |
| 1210 |
} {1} |
| 1211 |
} |
| 1212 |
-returnCodes 1 |
| 1213 |
-result {bad option "1": must be -body, -cleanup, -constraints, -errorCode, -errorOutput, -match, -output, -result, -returnCodes, or -setup} |
| 1214 |
} |
| 1215 |
|
| 1216 |
test tcltest-21.3 {test command with setup} { |
| 1217 |
-setup { |
| 1218 |
set foo 1 |
| 1219 |
} |
| 1220 |
-body { |
| 1221 |
set foo |
| 1222 |
} |
| 1223 |
-cleanup {unset foo} |
| 1224 |
-result {1} |
| 1225 |
} |
| 1226 |
|
| 1227 |
test tcltest-21.4 {test command with cleanup failure} { |
| 1228 |
-setup { |
| 1229 |
if {[info exists foo]} { |
| 1230 |
unset foo |
| 1231 |
} |
| 1232 |
set fail $::tcltest::currentFailure |
| 1233 |
set v [verbose] |
| 1234 |
} |
| 1235 |
-body { |
| 1236 |
verbose {} |
| 1237 |
test tcltest-21.4.0 {foo-1} { |
| 1238 |
-cleanup {unset foo} |
| 1239 |
} |
| 1240 |
} |
| 1241 |
-result {^$} |
| 1242 |
-match regexp |
| 1243 |
-cleanup {verbose $v; set ::tcltest::currentFailure $fail} |
| 1244 |
-output "Test cleanup failed:.*can't unset \"foo\": no such variable" |
| 1245 |
} |
| 1246 |
|
| 1247 |
test tcltest-21.5 {test command with setup failure} { |
| 1248 |
-setup { |
| 1249 |
if {[info exists foo]} { |
| 1250 |
unset foo |
| 1251 |
} |
| 1252 |
set fail $::tcltest::currentFailure |
| 1253 |
} |
| 1254 |
-body { |
| 1255 |
test tcltest-21.5.0 {foo-2} { |
| 1256 |
-setup {unset foo} |
| 1257 |
} |
| 1258 |
} |
| 1259 |
-result {^$} |
| 1260 |
-match regexp |
| 1261 |
-cleanup {set ::tcltest::currentFailure $fail} |
| 1262 |
-output "Test setup failed:.*can't unset \"foo\": no such variable" |
| 1263 |
} |
| 1264 |
|
| 1265 |
test tcltest-21.6 {test command - setup occurs before cleanup & before script} { |
| 1266 |
-setup {set v [verbose]; set fail $::tcltest::currentFailure} |
| 1267 |
-body { |
| 1268 |
verbose {} |
| 1269 |
test tcltest-21.6.0 {foo-3} { |
| 1270 |
-setup { |
| 1271 |
if {[info exists foo]} { |
| 1272 |
unset foo |
| 1273 |
} |
| 1274 |
set foo 1 |
| 1275 |
set expected 2 |
| 1276 |
} |
| 1277 |
-body { |
| 1278 |
incr foo |
| 1279 |
set foo |
| 1280 |
} |
| 1281 |
-cleanup { |
| 1282 |
if {$foo != 2} { |
| 1283 |
puts [outputChannel] "foo is wrong" |
| 1284 |
} else { |
| 1285 |
puts [outputChannel] "foo is 2" |
| 1286 |
} |
| 1287 |
} |
| 1288 |
-result {$expected} |
| 1289 |
} |
| 1290 |
} |
| 1291 |
-cleanup {verbose $v; set ::tcltest::currentFailure $fail} |
| 1292 |
-result {^$} |
| 1293 |
-match regexp |
| 1294 |
-output "foo is 2" |
| 1295 |
} |
| 1296 |
|
| 1297 |
test tcltest-21.7 {test command - bad flag} { |
| 1298 |
-setup {set fail $::tcltest::currentFailure} |
| 1299 |
-cleanup {set ::tcltest::currentFailure $fail} |
| 1300 |
-body { |
| 1301 |
test tcltest-21.7.0 {foo-4} { |
| 1302 |
-foobar {} |
| 1303 |
} |
| 1304 |
} |
| 1305 |
-returnCodes 1 |
| 1306 |
-result {bad option "-foobar": must be -body, -cleanup, -constraints, -errorCode, -errorOutput, -match, -output, -result, -returnCodes, or -setup} |
| 1307 |
} |
| 1308 |
|
| 1309 |
# alternate test command format (these are the same as 21.1-21.6, with the |
| 1310 |
# exception of being in the all-inline format) |
| 1311 |
|
| 1312 |
test tcltest-21.7a {expect with glob} \ |
| 1313 |
-body {list a b c d e} \ |
| 1314 |
-result {[ab] b c d e} \ |
| 1315 |
-match glob |
| 1316 |
|
| 1317 |
test tcltest-21.8 {force a test command failure} \ |
| 1318 |
-setup {set fail $::tcltest::currentFailure} \ |
| 1319 |
-body { |
| 1320 |
test tcltest-21.8.0 { |
| 1321 |
return 2 |
| 1322 |
} {1} |
| 1323 |
} \ |
| 1324 |
-returnCodes 1 \ |
| 1325 |
-cleanup {set ::tcltest::currentFailure $fail} \ |
| 1326 |
-result {bad option "1": must be -body, -cleanup, -constraints, -errorCode, -errorOutput, -match, -output, -result, -returnCodes, or -setup} |
| 1327 |
|
| 1328 |
test tcltest-21.9 {test command with setup} \ |
| 1329 |
-setup {set foo 1} \ |
| 1330 |
-body {set foo} \ |
| 1331 |
-cleanup {unset foo} \ |
| 1332 |
-result {1} |
| 1333 |
|
| 1334 |
test tcltest-21.10 {test command with cleanup failure} -setup { |
| 1335 |
if {[info exists foo]} { |
| 1336 |
unset foo |
| 1337 |
} |
| 1338 |
set fail $::tcltest::currentFailure |
| 1339 |
set v [verbose] |
| 1340 |
} -cleanup { |
| 1341 |
verbose $v |
| 1342 |
set ::tcltest::currentFailure $fail |
| 1343 |
} -body { |
| 1344 |
verbose {} |
| 1345 |
test tcltest-21.10.0 {foo-1} -cleanup {unset foo} |
| 1346 |
} -result {^$} -match regexp \ |
| 1347 |
-output {Test cleanup failed:.*can't unset \"foo\": no such variable} |
| 1348 |
|
| 1349 |
test tcltest-21.11 {test command with setup failure} -setup { |
| 1350 |
if {[info exists foo]} { |
| 1351 |
unset foo |
| 1352 |
} |
| 1353 |
set fail $::tcltest::currentFailure |
| 1354 |
} -cleanup {set ::tcltest::currentFailure $fail} -body { |
| 1355 |
test tcltest-21.11.0 {foo-2} -setup {unset foo} |
| 1356 |
} -result {^$} -output {Test setup failed:.*can't unset \"foo\": no such variable} -match regexp |
| 1357 |
|
| 1358 |
test tcltest-21.12 { |
| 1359 |
test command - setup occurs before cleanup & before script |
| 1360 |
} -setup { |
| 1361 |
set fail $::tcltest::currentFailure |
| 1362 |
set v [verbose] |
| 1363 |
} -cleanup { |
| 1364 |
verbose $v |
| 1365 |
set ::tcltest::currentFailure $fail |
| 1366 |
} -body { |
| 1367 |
verbose {} |
| 1368 |
test tcltest-21.12.0 {foo-3} -setup { |
| 1369 |
if {[info exists foo]} { |
| 1370 |
unset foo |
| 1371 |
} |
| 1372 |
set foo 1 |
| 1373 |
set expected 2 |
| 1374 |
} -body { |
| 1375 |
incr foo |
| 1376 |
set foo |
| 1377 |
} -cleanup { |
| 1378 |
if {$foo != 2} { |
| 1379 |
puts [outputChannel] "foo is wrong" |
| 1380 |
} else { |
| 1381 |
puts [outputChannel] "foo is 2" |
| 1382 |
} |
| 1383 |
} -result {$expected} |
| 1384 |
} -result {^$} -output {foo is 2} -match regexp |
| 1385 |
|
| 1386 |
# test all.tcl usage (runAllTests); simulate .test file failure, as well as |
| 1387 |
# crashes to determine whether or not these errors are logged. |
| 1388 |
|
| 1389 |
set atd [makeDirectory alltestdir] |
| 1390 |
makeFile { |
| 1391 |
package require tcltest 2.5 |
| 1392 |
namespace import -force tcltest::* |
| 1393 |
testsDirectory [file join [temporaryDirectory] alltestdir] |
| 1394 |
runAllTests |
| 1395 |
} all.tcl $atd |
| 1396 |
makeFile { |
| 1397 |
exit 1 |
| 1398 |
} exit.test $atd |
| 1399 |
makeFile { |
| 1400 |
error "throw an error" |
| 1401 |
} error.test $atd |
| 1402 |
makeFile { |
| 1403 |
package require tcltest 2.5 |
| 1404 |
namespace import -force tcltest::* |
| 1405 |
test foo-1.1 {foo} { |
| 1406 |
-body { return 1 } |
| 1407 |
-result {1} |
| 1408 |
} |
| 1409 |
cleanupTests |
| 1410 |
} test.test $atd |
| 1411 |
|
| 1412 |
# Must use a child process because stdout/stderr parsing can't be |
| 1413 |
# duplicated in child interp. |
| 1414 |
test tcltest-22.1 {runAllTests} { |
| 1415 |
-constraints {unixOrWin} |
| 1416 |
-body { |
| 1417 |
exec [interpreter] \ |
| 1418 |
[file join $atd all.tcl] \ |
| 1419 |
-verbose t -tmpdir [temporaryDirectory] |
| 1420 |
} |
| 1421 |
-match regexp |
| 1422 |
-result "Test files exiting with errors:.*error.test.*exit.test" |
| 1423 |
} |
| 1424 |
removeDirectory alltestdir |
| 1425 |
|
| 1426 |
# makeFile, removeFile, makeDirectory, removeDirectory, viewFile |
| 1427 |
test tcltest-23.1 {makeFile} { |
| 1428 |
-setup { |
| 1429 |
set mfdir [file join [temporaryDirectory] mfdir] |
| 1430 |
file mkdir $mfdir |
| 1431 |
} |
| 1432 |
-body { |
| 1433 |
makeFile {} t1.tmp |
| 1434 |
makeFile {} et1.tmp $mfdir |
| 1435 |
list [file exists [file join [temporaryDirectory] t1.tmp]] \ |
| 1436 |
[file exists [file join $mfdir et1.tmp]] |
| 1437 |
} |
| 1438 |
-cleanup { |
| 1439 |
file delete -force $mfdir \ |
| 1440 |
[file join [temporaryDirectory] t1.tmp] |
| 1441 |
} |
| 1442 |
-result {1 1} |
| 1443 |
} |
| 1444 |
test tcltest-23.2 {removeFile} { |
| 1445 |
-setup { |
| 1446 |
set mfdir [file join [temporaryDirectory] mfdir] |
| 1447 |
file mkdir $mfdir |
| 1448 |
makeFile {} t1.tmp |
| 1449 |
makeFile {} et1.tmp $mfdir |
| 1450 |
if {![file exists [file join [temporaryDirectory] t1.tmp]] || \ |
| 1451 |
![file exists [file join $mfdir et1.tmp]]} { |
| 1452 |
error "file creation didn't work" |
| 1453 |
} |
| 1454 |
} |
| 1455 |
-body { |
| 1456 |
removeFile t1.tmp |
| 1457 |
removeFile et1.tmp $mfdir |
| 1458 |
list [file exists [file join [temporaryDirectory] t1.tmp]] \ |
| 1459 |
[file exists [file join $mfdir et1.tmp]] |
| 1460 |
} |
| 1461 |
-cleanup { |
| 1462 |
file delete -force $mfdir \ |
| 1463 |
[file join [temporaryDirectory] t1.tmp] |
| 1464 |
} |
| 1465 |
-result {0 0} |
| 1466 |
} |
| 1467 |
test tcltest-23.3 {makeDirectory} { |
| 1468 |
-body { |
| 1469 |
set mfdir [file join [temporaryDirectory] mfdir] |
| 1470 |
file mkdir $mfdir |
| 1471 |
makeDirectory d1 |
| 1472 |
makeDirectory d2 $mfdir |
| 1473 |
list [file exists [file join [temporaryDirectory] d1]] \ |
| 1474 |
[file exists [file join $mfdir d2]] |
| 1475 |
} |
| 1476 |
-cleanup { |
| 1477 |
file delete -force [file join [temporaryDirectory] d1] $mfdir |
| 1478 |
} |
| 1479 |
-result {1 1} |
| 1480 |
} |
| 1481 |
test tcltest-23.4 {removeDirectory} { |
| 1482 |
-setup { |
| 1483 |
set mfdir [makeDirectory mfdir] |
| 1484 |
makeDirectory t1 |
| 1485 |
makeDirectory t2 $mfdir |
| 1486 |
if {![file exists $mfdir] || \ |
| 1487 |
![file exists [file join [temporaryDirectory] $mfdir t2]]} { |
| 1488 |
error "setup failed - directory not created" |
| 1489 |
} |
| 1490 |
} |
| 1491 |
-body { |
| 1492 |
removeDirectory t1 |
| 1493 |
removeDirectory t2 $mfdir |
| 1494 |
list [file exists [file join [temporaryDirectory] t1]] \ |
| 1495 |
[file exists [file join $mfdir t2]] |
| 1496 |
} |
| 1497 |
-result {0 0} |
| 1498 |
} |
| 1499 |
test tcltest-23.5 {viewFile} { |
| 1500 |
-body { |
| 1501 |
set mfdir [file join [temporaryDirectory] mfdir] |
| 1502 |
file mkdir $mfdir |
| 1503 |
makeFile {foobar} t1.tmp |
| 1504 |
makeFile {foobarbaz} t2.tmp $mfdir |
| 1505 |
list [viewFile t1.tmp] [viewFile t2.tmp $mfdir] |
| 1506 |
} |
| 1507 |
-result {foobar foobarbaz} |
| 1508 |
-cleanup { |
| 1509 |
file delete -force $mfdir |
| 1510 |
removeFile t1.tmp |
| 1511 |
} |
| 1512 |
} |
| 1513 |
|
| 1514 |
# customMatch |
| 1515 |
proc matchNegative { expected actual } { |
| 1516 |
set match 0 |
| 1517 |
foreach a $actual e $expected { |
| 1518 |
if { $a != $e } { |
| 1519 |
set match 1 |
| 1520 |
break |
| 1521 |
} |
| 1522 |
} |
| 1523 |
return $match |
| 1524 |
} |
| 1525 |
|
| 1526 |
test tcltest-24.0 { |
| 1527 |
customMatch: syntax |
| 1528 |
} -body { |
| 1529 |
list [catch {customMatch} result] $result |
| 1530 |
} -result [list 1 "wrong # args: should be \"customMatch mode script\""] |
| 1531 |
|
| 1532 |
test tcltest-24.1 { |
| 1533 |
customMatch: syntax |
| 1534 |
} -body { |
| 1535 |
list [catch {customMatch foo} result] $result |
| 1536 |
} -result [list 1 "wrong # args: should be \"customMatch mode script\""] |
| 1537 |
|
| 1538 |
test tcltest-24.2 { |
| 1539 |
customMatch: syntax |
| 1540 |
} -body { |
| 1541 |
list [catch {customMatch foo bar baz} result] $result |
| 1542 |
} -result [list 1 "wrong # args: should be \"customMatch mode script\""] |
| 1543 |
|
| 1544 |
test tcltest-24.3 { |
| 1545 |
customMatch: argument checking |
| 1546 |
} -body { |
| 1547 |
list [catch {customMatch bad "a \{ b"} result] $result |
| 1548 |
} -result [list 1 "invalid customMatch script; can't evaluate after completion"] |
| 1549 |
|
| 1550 |
test tcltest-24.4 { |
| 1551 |
test: valid -match values |
| 1552 |
} -body { |
| 1553 |
list [catch { |
| 1554 |
test tcltest-24.4.0 {} \ |
| 1555 |
-match [namespace current]::noSuchMode |
| 1556 |
} result] $result |
| 1557 |
} -match glob -result {1 *bad -match value*} |
| 1558 |
|
| 1559 |
test tcltest-24.5 { |
| 1560 |
test: valid -match values |
| 1561 |
} -setup { |
| 1562 |
customMatch [namespace current]::alwaysMatch "format 1 ;#" |
| 1563 |
} -body { |
| 1564 |
list [catch { |
| 1565 |
test tcltest-24.5.0 {} \ |
| 1566 |
-match [namespace current]::noSuchMode |
| 1567 |
} result] $result |
| 1568 |
} -match glob -result {1 *bad -match value*: must be *alwaysMatch,*} |
| 1569 |
|
| 1570 |
test tcltest-24.6 { |
| 1571 |
customMatch: -match script that always matches |
| 1572 |
} -setup { |
| 1573 |
customMatch [namespace current]::alwaysMatch "format 1 ;#" |
| 1574 |
set v [verbose] |
| 1575 |
} -body { |
| 1576 |
verbose {} |
| 1577 |
test tcltest-24.6.0 {} -match [namespace current]::alwaysMatch \ |
| 1578 |
-body {format 1} -result 0 |
| 1579 |
} -cleanup { |
| 1580 |
verbose $v |
| 1581 |
} -result {} -output {} -errorOutput {} |
| 1582 |
|
| 1583 |
test tcltest-24.7 { |
| 1584 |
customMatch: replace default -exact matching |
| 1585 |
} -setup { |
| 1586 |
set saveExactMatchScript $::tcltest::CustomMatch(exact) |
| 1587 |
customMatch exact "format 1 ;#" |
| 1588 |
set v [verbose] |
| 1589 |
} -body { |
| 1590 |
verbose {} |
| 1591 |
test tcltest-24.7.0 {} -body {format 1} -result 0 |
| 1592 |
} -cleanup { |
| 1593 |
verbose $v |
| 1594 |
customMatch exact $saveExactMatchScript |
| 1595 |
unset saveExactMatchScript |
| 1596 |
} -result {} -output {} |
| 1597 |
|
| 1598 |
test tcltest-24.9 { |
| 1599 |
customMatch: error during match |
| 1600 |
} -setup { |
| 1601 |
proc errorDuringMatch args {return -code error "match returned error"} |
| 1602 |
customMatch [namespace current]::errorDuringMatch \ |
| 1603 |
[namespace code errorDuringMatch] |
| 1604 |
set v [verbose] |
| 1605 |
set fail $::tcltest::currentFailure |
| 1606 |
} -body { |
| 1607 |
verbose {} |
| 1608 |
test tcltest-24.9.0 {} -match [namespace current]::errorDuringMatch |
| 1609 |
} -cleanup { |
| 1610 |
verbose $v |
| 1611 |
set ::tcltest::currentFailure $fail |
| 1612 |
} -match glob -result {} -output {*FAILED*match returned error*} |
| 1613 |
|
| 1614 |
test tcltest-24.10 { |
| 1615 |
customMatch: bad return from match command |
| 1616 |
} -setup { |
| 1617 |
proc nonBooleanReturn args {return foo} |
| 1618 |
customMatch nonBooleanReturn [namespace code nonBooleanReturn] |
| 1619 |
set v [verbose] |
| 1620 |
set fail $::tcltest::currentFailure |
| 1621 |
} -body { |
| 1622 |
verbose {} |
| 1623 |
test tcltest-24.10.0 {} -match nonBooleanReturn |
| 1624 |
} -cleanup { |
| 1625 |
verbose $v |
| 1626 |
set ::tcltest::currentFailure $fail |
| 1627 |
} -match glob -result {} -output {*FAILED*expected boolean value*} |
| 1628 |
|
| 1629 |
test tcltest-24.11 { |
| 1630 |
test: -match exact |
| 1631 |
} -body { |
| 1632 |
set result {A B C} |
| 1633 |
} -match exact -result {A B C} |
| 1634 |
|
| 1635 |
test tcltest-24.12 { |
| 1636 |
test: -match exact match command eval in ::, not caller namespace |
| 1637 |
} -setup { |
| 1638 |
set saveExactMatchScript $::tcltest::CustomMatch(exact) |
| 1639 |
customMatch exact [list string equal] |
| 1640 |
set v [verbose] |
| 1641 |
proc string args {error {called [string] in caller namespace}} |
| 1642 |
} -body { |
| 1643 |
verbose {} |
| 1644 |
test tcltest-24.12.0 {} -body {format 1} -result 1 |
| 1645 |
} -cleanup { |
| 1646 |
rename string {} |
| 1647 |
verbose $v |
| 1648 |
customMatch exact $saveExactMatchScript |
| 1649 |
unset saveExactMatchScript |
| 1650 |
} -match exact -result {} -output {} |
| 1651 |
|
| 1652 |
test tcltest-24.13 { |
| 1653 |
test: -match exact failure |
| 1654 |
} -setup { |
| 1655 |
set saveExactMatchScript $::tcltest::CustomMatch(exact) |
| 1656 |
customMatch exact [list string equal] |
| 1657 |
set v [verbose] |
| 1658 |
set fail $::tcltest::currentFailure |
| 1659 |
} -body { |
| 1660 |
verbose {} |
| 1661 |
test tcltest-24.13.0 {} -body {format 1} -result 0 |
| 1662 |
} -cleanup { |
| 1663 |
set ::tcltest::currentFailure $fail |
| 1664 |
verbose $v |
| 1665 |
customMatch exact $saveExactMatchScript |
| 1666 |
unset saveExactMatchScript |
| 1667 |
} -match glob -result {} -output {*FAILED*Result was: |
| 1668 |
1*(exact matching): |
| 1669 |
0*} |
| 1670 |
|
| 1671 |
test tcltest-24.14 { |
| 1672 |
test: -match glob |
| 1673 |
} -body { |
| 1674 |
set result {A B C} |
| 1675 |
} -match glob -result {A B*} |
| 1676 |
|
| 1677 |
test tcltest-24.15 { |
| 1678 |
test: -match glob failure |
| 1679 |
} -setup { |
| 1680 |
set v [verbose] |
| 1681 |
set fail $::tcltest::currentFailure |
| 1682 |
} -body { |
| 1683 |
verbose {} |
| 1684 |
test tcltest-24.15.0 {} -match glob -body {format {A B C}} \ |
| 1685 |
-result {A B* } |
| 1686 |
} -cleanup { |
| 1687 |
set ::tcltest::currentFailure $fail |
| 1688 |
verbose $v |
| 1689 |
} -match glob -result {} -output {*FAILED*Result was: |
| 1690 |
*(glob matching): |
| 1691 |
*} |
| 1692 |
|
| 1693 |
test tcltest-24.16 { |
| 1694 |
test: -match regexp |
| 1695 |
} -body { |
| 1696 |
set result {A B C} |
| 1697 |
} -match regexp -result {A B.*} |
| 1698 |
|
| 1699 |
test tcltest-24.17 { |
| 1700 |
test: -match regexp failure |
| 1701 |
} -setup { |
| 1702 |
set fail $::tcltest::currentFailure |
| 1703 |
set v [verbose] |
| 1704 |
} -body { |
| 1705 |
verbose {} |
| 1706 |
test tcltest-24.17.0 {} -match regexp -body {format {A B C}} \ |
| 1707 |
-result {A B.* X} |
| 1708 |
} -cleanup { |
| 1709 |
set ::tcltest::currentFailure $fail |
| 1710 |
verbose $v |
| 1711 |
} -match glob -result {} -output {*FAILED*Result was: |
| 1712 |
*(regexp matching): |
| 1713 |
*} |
| 1714 |
|
| 1715 |
test tcltest-24.18 { |
| 1716 |
test: -match custom forget namespace qualification |
| 1717 |
} -setup { |
| 1718 |
set fail $::tcltest::currentFailure |
| 1719 |
set v [verbose] |
| 1720 |
customMatch negative matchNegative |
| 1721 |
} -body { |
| 1722 |
verbose {} |
| 1723 |
test tcltest-24.18.0 {} -match negative -body {format {A B C}} \ |
| 1724 |
-result {A B X} |
| 1725 |
} -cleanup { |
| 1726 |
set ::tcltest::currentFailure $fail |
| 1727 |
verbose $v |
| 1728 |
} -match glob -result {} -output {*FAILED*Error testing result:*} |
| 1729 |
|
| 1730 |
test tcltest-24.19 { |
| 1731 |
test: -match custom |
| 1732 |
} -setup { |
| 1733 |
set v [verbose] |
| 1734 |
customMatch negative [namespace code matchNegative] |
| 1735 |
} -body { |
| 1736 |
verbose {} |
| 1737 |
test tcltest-24.19.0 {} -match negative -body {format {A B C}} \ |
| 1738 |
-result {A B X} |
| 1739 |
} -cleanup { |
| 1740 |
verbose $v |
| 1741 |
} -match exact -result {} -output {} |
| 1742 |
|
| 1743 |
test tcltest-24.20 { |
| 1744 |
test: -match custom failure |
| 1745 |
} -setup { |
| 1746 |
set fail $::tcltest::currentFailure |
| 1747 |
set v [verbose] |
| 1748 |
customMatch negative [namespace code matchNegative] |
| 1749 |
} -body { |
| 1750 |
verbose {} |
| 1751 |
test tcltest-24.20.0 {} -match negative -body {format {A B C}} \ |
| 1752 |
-result {A B C} |
| 1753 |
} -cleanup { |
| 1754 |
set ::tcltest::currentFailure $fail |
| 1755 |
verbose $v |
| 1756 |
} -match glob -result {} -output {*FAILED*Result was: |
| 1757 |
*(negative matching): |
| 1758 |
*} |
| 1759 |
|
| 1760 |
test tcltest-25.1 { |
| 1761 |
constraint of setup/cleanup (Bug 589859) |
| 1762 |
} -setup { |
| 1763 |
set foo 0 |
| 1764 |
} -body { |
| 1765 |
# Buggy tcltest will generate result of 2 |
| 1766 |
test tcltest-25.1.0 {} -constraints knownBug -setup { |
| 1767 |
incr foo |
| 1768 |
} -body { |
| 1769 |
incr foo |
| 1770 |
} -cleanup { |
| 1771 |
incr foo |
| 1772 |
} -match glob -result * |
| 1773 |
set foo |
| 1774 |
} -cleanup { |
| 1775 |
unset foo |
| 1776 |
} -result 0 |
| 1777 |
|
| 1778 |
test tcltest-25.2 { |
| 1779 |
puts -nonewline (Bug 612786) |
| 1780 |
} -body { |
| 1781 |
puts -nonewline stdout bla |
| 1782 |
puts -nonewline stdout bla |
| 1783 |
} -output {blabla} |
| 1784 |
|
| 1785 |
test tcltest-25.3 { |
| 1786 |
reported return code (Bug 611922) |
| 1787 |
} -setup { |
| 1788 |
set fail $::tcltest::currentFailure |
| 1789 |
set v [verbose] |
| 1790 |
} -body { |
| 1791 |
verbose {} |
| 1792 |
test tcltest-25.3.0 {} -body { |
| 1793 |
error foo |
| 1794 |
} |
| 1795 |
} -cleanup { |
| 1796 |
set ::tcltest::currentFailure $fail |
| 1797 |
verbose $v |
| 1798 |
} -match glob -output {*generated error; Return code was: 1*} |
| 1799 |
|
| 1800 |
test tcltest-26.1 {Bug/RFE 1017151} -setup { |
| 1801 |
makeFile { |
| 1802 |
package require tcltest 2.5 |
| 1803 |
set ::errorInfo "Should never see this" |
| 1804 |
tcltest::test tcltest-26.1.0 { |
| 1805 |
no errorInfo when only return code mismatch |
| 1806 |
} -body { |
| 1807 |
set x 1 |
| 1808 |
} -returnCodes error -result 1 |
| 1809 |
tcltest::cleanupTests |
| 1810 |
} test.tcl |
| 1811 |
} -body { |
| 1812 |
child msg [file join [temporaryDirectory] test.tcl] |
| 1813 |
return $msg |
| 1814 |
} -cleanup { |
| 1815 |
removeFile test.tcl |
| 1816 |
} -match glob -result {* |
| 1817 |
---- Return code should have been one of: 1 |
| 1818 |
==== tcltest-26.1.0 FAILED*} |
| 1819 |
|
| 1820 |
test tcltest-26.2 {Bug/RFE 1017151} -setup { |
| 1821 |
makeFile { |
| 1822 |
package require tcltest 2.5 |
| 1823 |
set ::errorInfo "Should never see this" |
| 1824 |
tcltest::test tcltest-26.2.0 {do not mask body errorInfo} -body { |
| 1825 |
error "body error" |
| 1826 |
} -cleanup { |
| 1827 |
error "cleanup error" |
| 1828 |
} -result 1 |
| 1829 |
tcltest::cleanupTests |
| 1830 |
} test.tcl |
| 1831 |
} -body { |
| 1832 |
child msg [file join [temporaryDirectory] test.tcl] |
| 1833 |
return $msg |
| 1834 |
} -cleanup { |
| 1835 |
removeFile test.tcl |
| 1836 |
} -match glob -result {* |
| 1837 |
---- errorInfo: body error |
| 1838 |
* |
| 1839 |
---- errorInfo(cleanup): cleanup error*} |
| 1840 |
|
| 1841 |
cleanupTests |
| 1842 |
} |
| 1843 |
|
| 1844 |
namespace delete ::tcltest::test |
| 1845 |
return |
| 1846 |
|
| 1847 |
# Local Variables: |
| 1848 |
# mode: tcl |
| 1849 |
# End: |