tcltest.test

来自「tcl是工具命令语言」· TEST 代码 · 共 1,734 行 · 第 1/4 页

TEST
1,734
字号
# This file contains a collection of tests for one or more of the Tcl# built-in commands.  Sourcing this file into Tcl runs the tests and# generates output for errors.  No output means no errors were found.## Copyright (c) 1998-1999 by Scriptics Corporation. # Copyright (c) 2000 by Ajuba Solutions# All rights reserved.## RCS: @(#) $Id: tcltest.test,v 1.37 2003/01/31 22:19:30 dgp Exp $# Note that there are several places where the value of # tcltest::currentFailure is stored/reset in the -setup/-cleanup# of a test that has a body that runs [test] that will fail.# This is a workaround of using the same tcltest code that we are# testing to run the test itself.  Ditto on things like [verbose].## It would be better to have the -body of the tests run the tcltest# commands in a slave interp so the [test] being tested would not# interfere with the [test] doing the testing.  #if {[catch {package require tcltest 2.1}]} {    puts stderr "Skipping tests in [info script].  tcltest 2.1 required."    return}namespace eval ::tcltest::test {namespace import ::tcltest::*makeFile {    package require tcltest    namespace import ::tcltest::test    test a-1.0 {test a} {	list 0    } {0}    test b-1.0 {test b} {	list 1    } {0}    test c-1.0 {test c} {knownBug} {    } {}    test d-1.0 {test d} {	error "foo" foo 9    } {}    tcltest::cleanupTests    exit} test.tclcd [temporaryDirectory]testConstraint exec [llength [info commands exec]]# test -help# Child processes because -help [exit]s.test tcltest-1.1 {tcltest -help} {exec} {    set result [catch {exec [interpreter] test.tcl -help} msg]    list $result [regexp Usage $msg]} {1 1} test tcltest-1.2 {tcltest -help -something} {exec} {    set result [catch {exec [interpreter] test.tcl -help -something} msg]    list $result [regexp Usage $msg]} {1 1}test tcltest-1.3 {tcltest -h} {exec} {    set result [catch {exec [interpreter] test.tcl -h} msg]    list $result [regexp Usage $msg]} {1 0} # -verbose, implicit & explicit testing of [verbose]proc slave {msgVar args} {    upvar 1 $msgVar msg    interp create [namespace current]::i    # Fake the slave interp into dumping output to a file    i eval {namespace eval ::tcltest {}}    i eval "set tcltest::outputChannel\	    \[[list open [set of [makeFile {} output]] w]]"    i eval "set tcltest::errorChannel\	    \[[list open [set ef [makeFile {} error]] w]]"    i eval [list set argv0 [lindex $args 0]]    i eval [list set argv [lrange $args 1 end]]    i eval [list package ifneeded tcltest [package provide tcltest] \	    [package ifneeded tcltest [package provide tcltest]]]    i eval {proc exit args {}}    # Need to capture output in msg    set code [catch {i eval {source $argv0}} foo]if $code {#puts "$code: $foo\n$::errorInfo"}    i eval {close $tcltest::outputChannel}    interp delete [namespace current]::i    set f [open $of]    set msg [read -nonewline $f]    close $f    set f [open $ef]    set err [read -nonewline $f]    close $f    removeFile output    removeFile error    if {[string length $err]} {	set code 1	append msg \n$err    }    return $code#    return [catch {uplevel 1 [linsert $args 0  exec [interpreter]]} msg]}test tcltest-2.0 {tcltest (verbose default - 'b')} {unixOrPc} {    set result [slave msg test.tcl]    list $result [regexp "Contents of test case" $msg] [regexp a-1.0 $msg] \	    [regexp c-1.0 $msg] \	    [regexp "Total.+4.+Passed.+1.+Skipped.+1.+Failed.+2" $msg]} {0 1 0 0 1}test tcltest-2.1 {tcltest -verbose 'b'} {unixOrPc} {    set result [slave msg test.tcl -verbose 'b']    list $result [regexp "Contents of test case" $msg] [regexp a-1.0 $msg] \	    [regexp c-1.0 $msg] \	    [regexp "Total.+4.+Passed.+1.+Skipped.+1.+Failed.+2" $msg]} {0 1 0 0 1}test tcltest-2.2 {tcltest -verbose 'p'} {unixOrPc} {    set result [slave msg test.tcl -verbose 'p']    list $result [regexp "Contents of test case" $msg] [regexp a-1.0 $msg] \	    [regexp c-1.0 $msg] \	    [regexp "Total.+4.+Passed.+1.+Skipped.+1.+Failed.+2" $msg]} {0 0 1 0 1}test tcltest-2.3 {tcltest -verbose 's'} {unixOrPc} {    set result [slave msg test.tcl -verbose 's']    list $result [regexp "Contents of test case" $msg] [regexp a-1.0 $msg] \	    [regexp c-1.0 $msg] \	    [regexp "Total.+4.+Passed.+1.+Skipped.+1.+Failed.+2" $msg]} {0 0 0 1 1}test tcltest-2.4 {tcltest -verbose 'ps'} {unixOrPc} {    set result [slave msg test.tcl -verbose 'ps']    list $result [regexp "Contents of test case" $msg] [regexp a-1.0 $msg] \	    [regexp c-1.0 $msg] \	    [regexp "Total.+4.+Passed.+1.+Skipped.+1.+Failed.+2" $msg]} {0 0 1 1 1}test tcltest-2.5 {tcltest -verbose 'psb'} {unixOrPc} {    set result [slave msg test.tcl -verbose 'psb']    list $result [regexp "Contents of test case" $msg] [regexp a-1.0 $msg] \	    [regexp c-1.0 $msg] \	    [regexp "Total.+4.+Passed.+1.+Skipped.+1.+Failed.+2" $msg]} {0 1 1 1 1}test tcltest-2.5a {tcltest -verbose 'pass skip body'} {unixOrPc} {    set result [slave msg test.tcl -verbose "pass skip body"]    list $result [regexp "Contents of test case" $msg] [regexp a-1.0 $msg] \	    [regexp c-1.0 $msg] \	    [regexp "Total.+4.+Passed.+1.+Skipped.+1.+Failed.+2" $msg]} {0 1 1 1 1}test tcltest-2.6 {tcltest -verbose 't'}  {    -constraints {unixOrPc}     -body {	set result [slave msg test.tcl -verbose 't']	list $result $msg    }    -result {^0 .*a-1.0 start.*b-1.0 start}    -match regexp}test tcltest-2.6a {tcltest -verbose 'start'}  {    -constraints {unixOrPc}     -body {	set result [slave msg test.tcl -verbose start]	list $result $msg    }    -result {^0 .*a-1.0 start.*b-1.0 start}    -match regexp}test tcltest-2.7 {tcltest::verbose}  {    -body {	set oldVerbosity [verbose]	verbose bar	set currentVerbosity [verbose]	verbose foo	set newVerbosity [verbose]	verbose $oldVerbosity	list $currentVerbosity $newVerbosity     }    -result {body {}}}test tcltest-2.8 {tcltest -verbose 'error'} {    -constraints {unixOrPc}    -body {	set result [slave msg test.tcl -verbose error]	list $result $msg    }    -result {errorInfo: foo.*errorCode: 9}    -match regexp}# -match, [match]test tcltest-3.1 {tcltest -match 'a*'} {unixOrPc} {    set result [slave msg test.tcl -match a* -verbose 'ps']    list $result [regexp a-1.0 $msg] [regexp b-1.0 $msg] [regexp c-1.0 $msg] \	    [regexp "Total.+4.+Passed.+1.+Skipped.+3.+Failed.+0" $msg]} {0 1 0 0 1}test tcltest-3.2 {tcltest -match 'b*'} {unixOrPc} {    set result [slave msg test.tcl -match b* -verbose 'ps']    list $result [regexp a-1.0 $msg] [regexp b-1.0 $msg] [regexp c-1.0 $msg] \	    [regexp "Total.+4.+Passed.+0.+Skipped.+3.+Failed.+1" $msg]} {0 0 1 0 1}test tcltest-3.3 {tcltest -match 'c*'} {unixOrPc} {    set result [slave msg test.tcl -match c* -verbose 'ps']    list $result [regexp a-1.0 $msg] [regexp b-1.0 $msg] [regexp c-1.0 $msg] \	    [regexp "Total.+4.+Passed.+0.+Skipped.+4.+Failed.+0" $msg]} {0 0 0 1 1}test tcltest-3.4 {tcltest -match 'a* b*'} {unixOrPc} {    set result [slave msg test.tcl -match {a* b*} -verbose 'ps']    list $result [regexp a-1.0 $msg] [regexp b-1.0 $msg] [regexp c-1.0 $msg] \	    [regexp "Total.+4.+Passed.+1.+Skipped.+2.+Failed.+1" $msg]} {0 1 1 0 1}test tcltest-3.5 {tcltest::match}  {    -body {	set oldMatch [match]	match foo	set currentMatch [match]	match bar	set newMatch [match]	match $oldMatch	list $currentMatch $newMatch    }    -result {foo bar}}	# -skip, [skip]test tcltest-4.1 {tcltest -skip 'a*'} {unixOrPc} {    set result [slave msg test.tcl -skip a* -verbose 'ps']    list $result [regexp a-1.0 $msg] [regexp b-1.0 $msg] [regexp c-1.0 $msg] \	    [regexp "Total.+4.+Passed.+0.+Skipped.+2.+Failed.+1" $msg]} {0 0 1 1 1}test tcltest-4.2 {tcltest -skip 'b*'} {unixOrPc} {    set result [slave msg test.tcl -skip b* -verbose 'ps']    list $result [regexp a-1.0 $msg] [regexp b-1.0 $msg] [regexp c-1.0 $msg] \	    [regexp "Total.+4.+Passed.+1.+Skipped.+2.+Failed.+1" $msg]} {0 1 0 1 1}test tcltest-4.3 {tcltest -skip 'c*'} {unixOrPc} {    set result [slave msg test.tcl -skip c* -verbose 'ps']    list $result [regexp a-1.0 $msg] [regexp b-1.0 $msg] [regexp c-1.0 $msg] \	    [regexp "Total.+4.+Passed.+1.+Skipped.+1.+Failed.+2" $msg]} {0 1 1 0 1}test tcltest-4.4 {tcltest -skip 'a* b*'} {unixOrPc} {    set result [slave msg test.tcl -skip {a* b*} -verbose 'ps']    list $result [regexp a-1.0 $msg] [regexp b-1.0 $msg] [regexp c-1.0 $msg] \	    [regexp "Total.+4.+Passed.+0.+Skipped.+3.+Failed.+1" $msg]} {0 0 0 1 1}test tcltest-4.5 {tcltest -match 'a* b*' -skip 'b*'} {unixOrPc} {    set result [slave msg test.tcl -match {a* b*} -skip b* -verbose 'ps']    list $result [regexp a-1.0 $msg] [regexp b-1.0 $msg] [regexp c-1.0 $msg] \	    [regexp "Total.+4.+Passed.+1.+Skipped.+3.+Failed.+0" $msg]} {0 1 0 0 1}test tcltest-4.6 {tcltest::skip} {    -body {	set oldSkip [skip]	skip foo	set currentSkip [skip]	skip bar	set newSkip [skip]	skip $oldSkip	list $currentSkip $newSkip    }    -result {foo bar}}# -constraints, -limitconstraints, [testConstraint],# $constraintsSpecified, [limitConstraints]test tcltest-5.1 {tcltest -constraints 'knownBug'} {unixOrPc} {    set result [slave msg test.tcl -constraints knownBug -verbose 'ps']    list $result [regexp a-1.0 $msg] [regexp b-1.0 $msg] [regexp c-1.0 $msg] \	    [regexp "Total.+4.+Passed.+2.+Skipped.+0.+Failed.+2" $msg]} {0 1 1 1 1}test tcltest-5.2 {tcltest -constraints 'knownBug' -limitconstraints 1} {unixOrPc} {    set result [slave msg test.tcl -constraints knownBug -verbose 'p' -limitconstraints 1]    list $result [regexp a-1.0 $msg] [regexp b-1.0 $msg] [regexp c-1.0 $msg] \	    [regexp "Total.+4.+Passed.+1.+Skipped.+3.+Failed.+0" $msg]} {0 0 0 1 1}test tcltest-5.3 {testConstraint - constraint empty (tcltest::safeFetch)}  {    -body {	set r1 [testConstraint tcltestFakeConstraint]	set r2 [testConstraint tcltestFakeConstraint 4]	set r3 [testConstraint tcltestFakeConstraint]	list $r1 $r2 $r3    }    -result {0 4 4}    -cleanup {unset ::tcltest::testConstraints(tcltestFakeConstraint)}}# Removed this test of internals of tcltest.  Those internals have changed.#test tcltest-5.4 {tcltest::constraintsSpecified} {#    -setup {#	set constraintlist $::tcltest::constraintsSpecified#	set ::tcltest::constraintsSpecified {}#    }#    -body {#	set r1 $::tcltest::constraintsSpecified#	testConstraint tcltestFakeConstraint1 1#	set r2 $::tcltest::constraintsSpecified#	testConstraint tcltestFakeConstraint2 1#	set r3 $::tcltest::constraintsSpecified#	list $r1 $r2 $r3#    }#    -result {{} tcltestFakeConstraint1 {tcltestFakeConstraint1 tcltestFakeConstraint2}}#    -cleanup {#	set ::tcltest::constraintsSpecified $constraintlist#	unset ::tcltest::testConstraints(tcltestFakeConstraint1) #	unset ::tcltest::testConstraints(tcltestFakeConstraint2) #    }#}test tcltest-5.5 {InitConstraints: list of built-in constraints} \	-constraints {!singleTestInterp} \	-setup {tcltest::InitConstraints} \	-body { lsort [array names ::tcltest::testConstraints] } \	-result [lsort {    95 98 asyncPipeClose eformat emptyTest exec hasIsoLocale interactive    knownBug mac macCrash macOnly macOrPc macOrUnix macOrWin nonBlockFiles    nonPortable notRoot nt pc pcCrash pcOnly root singleTestInterp socket    stdio tempNotMac tempNotPc tempNotUnix tempNotWin unix unixCrash unixExecs    unixOnly unixOrPc unixOrWin userInteraction win winCrash winOnly}]# Removed this broken test.  Its usage of [limitConstraints] was not# in agreement with the documentation.  [limitConstraints] is supposed# to take an optional boolean argument, and "knownBug" ain't no boolean!#test tcltest-5.6 {tcltest::limitConstraints} {#    -setup {#        set keeplc $::tcltest::limitConstraints#        set keepkb [testConstraint knownBug]#    }#    -body {#        set r1 [limitConstraints]#        set r2 [limitConstraints knownBug]#        set r3 [limitConstraints]#        list $r1 $r2 $r3#    }#    -cleanup {#        limitConstraints $keeplc#        testConstraint knownBug $keepkb#    }#    -result {false knownBug knownBug}#}# -outfile, -errfile, [outputChannel], [outputFile], [errorChannel], [errorFile]set printerror [makeFile {    package require tcltest    namespace import ::tcltest::*    puts [outputChannel] "a test"    ::tcltest::PrintError "a really short string"    ::tcltest::PrintError "a really really really really really really long \	    string containing \"quotes\" and other bad bad stuff"    ::tcltest::PrintError "a really really long string containing a \	    \"Path/that/is/really/long/and/contains/no/spaces\""    ::tcltest::PrintError "a really really long string containing a \	    \"Really/Long/Path/that/contains/no/spaces/and/is/longer/than/eighty/characters/to/see/what/happens\""     ::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\""    exit} printerror.tcl]test tcltest-6.1 {tcltest -outfile, -errfile defaults} {    -constraints unixOrPc    -body {	slave msg $printerror	return $msg    }    -result {a test.*a really}    -match regexp}test tcltest-6.2 {tcltest -outfile a.tmp} {unixOrPc unixExecs} {    slave msg $printerror -outfile a.tmp    set result1 [catch {exec grep "a test" a.tmp}]    set result2 [catch {exec grep "a really" a.tmp}]    list [regexp "a test" $msg] [regexp "a really" $msg] \	    $result1 $result2 [file exists a.tmp] [file delete a.tmp] } {0 1 0 1 1 {}}test tcltest-6.3 {tcltest -errfile a.tmp} {unixOrPc unixExecs} {    slave msg $printerror -errfile a.tmp    set result1 [catch {exec grep "a test" a.tmp}]    set result2 [catch {exec grep "a really" a.tmp}]    list [regexp "a test" $msg] [regexp "a really" $msg] \	    $result1 $result2 [file exists a.tmp] [file delete a.tmp]} {1 0 1 0 1 {}}test tcltest-6.4 {tcltest -outfile a.tmp -errfile b.tmp} {unixOrPc unixExecs} {    slave msg $printerror -outfile a.tmp -errfile b.tmp    set result1 [catch {exec grep "a test" a.tmp}]    set result2 [catch {exec grep "a really" b.tmp}]    list [regexp "a test" $msg] [regexp "a really" $msg] \	    $result1 $result2 \	    [file exists a.tmp] [file delete a.tmp] \	    [file exists b.tmp] [file delete b.tmp]} {0 0 0 0 1 {} 1 {}}test tcltest-6.5 {tcltest::errorChannel - retrieval} {    -setup {	set of [errorChannel]	set ::tcltest::errorChannel stderr    }    -body {	errorChannel    }    -result {stderr}    -cleanup {	set ::tcltest::errorChannel $of    }}test tcltest-6.6 {tcltest::errorFile (implicit errorChannel)} {    -setup {	set ef [makeFile {} efile]	set of [errorFile]	set ::tcltest::errorChannel stderr	set ::tcltest::errorFile stderr    }    -body {	set f0 [errorChannel]	set f1 [errorFile]	set f2 [errorFile $ef]	set f3 [errorChannel]	set f4 [errorFile]	subst {$f0;$f1;$f2;$f3;$f4}     }    -result {stderr;stderr;.*efile;file[0-9a-f]+;.*efile}    -match regexp    -cleanup {	errorFile $of	removeFile efile    }}test tcltest-6.7 {tcltest::outputChannel - retrieval} {    -setup {	set of [outputChannel]

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?