sl@0: # The tests in this file cover the procedures in tclCmdMZ.c. sl@0: # sl@0: # This file contains a collection of tests for one or more of the Tcl sl@0: # built-in commands. Sourcing this file into Tcl runs the tests and sl@0: # generates output for errors. No output means no errors were found. sl@0: # sl@0: # Copyright (c) 1991-1993 The Regents of the University of California. sl@0: # Copyright (c) 1994 Sun Microsystems, Inc. sl@0: # Copyright (c) 1998-1999 by Scriptics Corporation. sl@0: # sl@0: # See the file "license.terms" for information on usage and redistribution sl@0: # of this file, and for a DISCLAIMER OF ALL WARRANTIES. sl@0: # sl@0: # RCS: @(#) $Id: cmdMZ.test,v 1.13.2.3 2004/02/25 23:38:16 dgp Exp $ sl@0: sl@0: if {[lsearch [namespace children] ::tcltest] == -1} { sl@0: package require tcltest 2.1 sl@0: namespace import -force ::tcltest::* sl@0: } sl@0: sl@0: # Tcl_PwdObjCmd sl@0: sl@0: test cmdMZ-1.1 {Tcl_PwdObjCmd} { sl@0: list [catch {pwd a} msg] $msg sl@0: } {1 {wrong # args: should be "pwd"}} sl@0: test cmdMZ-1.2 {Tcl_PwdObjCmd: simple pwd} { sl@0: catch pwd sl@0: } 0 sl@0: test cmdMZ-1.3 {Tcl_PwdObjCmd: simple pwd} { sl@0: expr [string length pwd]>0 sl@0: } 1 sl@0: test cmdMZ-1.4 {Tcl_PwdObjCmd: failure} {unixOnly nonPortable} { sl@0: # This test fails on various unix platforms (eg Linux) where sl@0: # permissions caching causes this to fail. The caching is strictly sl@0: # incorrect, but we have no control over that. sl@0: set foodir [file join [temporaryDirectory] foo] sl@0: file delete -force $foodir sl@0: file mkdir $foodir sl@0: set cwd [pwd] sl@0: cd $foodir sl@0: file attr . -permissions 000 sl@0: set result [list [catch {pwd} msg] $msg] sl@0: cd $cwd sl@0: file delete -force $foodir sl@0: set result sl@0: } {1 {error getting working directory name: permission denied}} sl@0: sl@0: # The tests for Tcl_RegexpObjCmd, Tcl_RegsubObjCmd are in regexp.test sl@0: sl@0: # Tcl_RenameObjCmd sl@0: sl@0: test cmdMZ-2.1 {Tcl_RenameObjCmd: error conditions} { sl@0: list [catch {rename r1} msg] $msg $errorCode sl@0: } {1 {wrong # args: should be "rename oldName newName"} NONE} sl@0: test cmdMZ-2.2 {Tcl_RenameObjCmd: error conditions} { sl@0: list [catch {rename r1 r2 r3} msg] $msg $errorCode sl@0: } {1 {wrong # args: should be "rename oldName newName"} NONE} sl@0: test cmdMZ-2.3 {Tcl_RenameObjCmd: success} { sl@0: catch {rename r2 {}} sl@0: proc r1 {} {return "r1"} sl@0: rename r1 r2 sl@0: r2 sl@0: } {r1} sl@0: test cmdMZ-2.4 {Tcl_RenameObjCmd: success} { sl@0: proc r1 {} {return "r1"} sl@0: rename r1 {} sl@0: list [catch {r1} msg] $msg sl@0: } {1 {invalid command name "r1"}} sl@0: sl@0: # The tests for Tcl_ReturnObjCmd are in proc-old.test sl@0: # The tests for Tcl_ScanObjCmd are in scan.test sl@0: sl@0: # Tcl_SourceObjCmd sl@0: sl@0: test cmdMZ-3.1 {Tcl_SourceObjCmd: error conditions} {macOnly} { sl@0: list [catch {source} msg] $msg sl@0: } {1 {wrong # args: should be "source fileName" or "source -rsrc name ?fileName?" or "source -rsrcid id ?fileName?"}} sl@0: test cmdMZ-3.2 {Tcl_SourceObjCmd: error conditions} {macOnly} { sl@0: list [catch {source a b} msg] $msg sl@0: } {1 {bad argument: should be "source fileName" or "source -rsrc name ?fileName?" or "source -rsrcid id ?fileName?"}} sl@0: test cmdMZ-3.3 {Tcl_SourceObjCmd: error conditions} {unixOrPc} { sl@0: list [catch {source} msg] $msg sl@0: } {1 {wrong # args: should be "source fileName"}} sl@0: test cmdMZ-3.4 {Tcl_SourceObjCmd: error conditions} {unixOrPc} { sl@0: list [catch {source a b} msg] $msg sl@0: } {1 {wrong # args: should be "source fileName"}} sl@0: sl@0: proc ListGlobMatch {expected actual} { sl@0: if {[llength $expected] != [llength $actual]} { sl@0: return 0 sl@0: } sl@0: foreach e $expected a $actual { sl@0: if {![string match $e $a]} { sl@0: return 0 sl@0: } sl@0: } sl@0: return 1 sl@0: } sl@0: customMatch listGlob ListGlobMatch sl@0: sl@0: test cmdMZ-3.5 {Tcl_SourceObjCmd: error in script} -setup { sl@0: set file [makeFile { sl@0: set x 146 sl@0: error "error in sourced file" sl@0: set y $x sl@0: } source.file] sl@0: } -body { sl@0: list [catch {source $file} msg] $msg $errorInfo sl@0: } -cleanup { sl@0: removeFile source.file sl@0: } -match listGlob -result {1 {error in sourced file} {error in sourced file sl@0: while executing sl@0: "error "error in sourced file"" sl@0: (file "*" line 3) sl@0: invoked from within sl@0: "source $file"}} sl@0: test cmdMZ-3.6 {Tcl_SourceObjCmd: simple script} { sl@0: set file [makeFile {list result} source.file] sl@0: set result [source $file] sl@0: removeFile source.file sl@0: set result sl@0: } result sl@0: sl@0: # Tcl_SplitObjCmd sl@0: sl@0: test cmdMZ-4.1 {Tcl_SplitObjCmd: split errors} { sl@0: list [catch split msg] $msg $errorCode sl@0: } {1 {wrong # args: should be "split string ?splitChars?"} NONE} sl@0: test cmdMZ-4.2 {Tcl_SplitObjCmd: split errors} { sl@0: list [catch {split a b c} msg] $msg $errorCode sl@0: } {1 {wrong # args: should be "split string ?splitChars?"} NONE} sl@0: test cmdMZ-4.3 {Tcl_SplitObjCmd: basic split commands} { sl@0: split "a\n b\t\r c\n " sl@0: } {a {} b {} {} c {} {}} sl@0: test cmdMZ-4.4 {Tcl_SplitObjCmd: basic split commands} { sl@0: split "word 1xyzword 2zword 3" xyz sl@0: } {{word 1} {} {} {word 2} {word 3}} sl@0: test cmdMZ-4.5 {Tcl_SplitObjCmd: basic split commands} { sl@0: split "12345" {} sl@0: } {1 2 3 4 5} sl@0: test cmdMZ-4.6 {Tcl_SplitObjCmd: basic split commands} { sl@0: split "a\}b\[c\{\]\$" sl@0: } "a\\}b\\\[c\\{\\\]\\\$" sl@0: test cmdMZ-4.7 {Tcl_SplitObjCmd: basic split commands} { sl@0: split {} {} sl@0: } {} sl@0: test cmdMZ-4.8 {Tcl_SplitObjCmd: basic split commands} { sl@0: split {} sl@0: } {} sl@0: test cmdMZ-4.9 {Tcl_SplitObjCmd: basic split commands} { sl@0: split { } sl@0: } {{} {} {} {}} sl@0: test cmdMZ-4.10 {Tcl_SplitObjCmd: basic split commands} { sl@0: proc foo {} { sl@0: set x {} sl@0: foreach f [split {]\n} {}] { sl@0: append x $f sl@0: } sl@0: return $x sl@0: } sl@0: foo sl@0: } {]\n} sl@0: test cmdMZ-4.11 {Tcl_SplitObjCmd: basic split commands} { sl@0: proc foo {} { sl@0: set x ab\000c sl@0: set y [split $x {}] sl@0: return $y sl@0: } sl@0: foo sl@0: } "a b \000 c" sl@0: test cmdMZ-4.12 {Tcl_SplitObjCmd: basic split commands} { sl@0: split "a0ab1b2bbb3\000c4" ab\000c sl@0: } {{} 0 {} 1 2 {} {} 3 {} 4} sl@0: test cmdMZ-4.13 {Tcl_SplitObjCmd: basic split commands} { sl@0: # if not UTF-8 aware, result is "a {} {} b qw\xe5 {} N wq" sl@0: split "a\u4e4eb qw\u5e4e\x4e wq" " \u4e4e" sl@0: } "a b qw\u5e4eN wq" sl@0: sl@0: # The tests for Tcl_StringObjCmd are in string.test sl@0: # The tests for Tcl_SubstObjCmd are in subst.test sl@0: # The tests for Tcl_SwitchObjCmd are in switch.test sl@0: sl@0: test cmdMZ-5.1 {Tcl_TimeObjCmd: basic format of command} { sl@0: list [catch {time} msg] $msg sl@0: } {1 {wrong # args: should be "time command ?count?"}} sl@0: test cmdMZ-5.2 {Tcl_TimeObjCmd: basic format of command} { sl@0: list [catch {time a b c} msg] $msg sl@0: } {1 {wrong # args: should be "time command ?count?"}} sl@0: test cmdMZ-5.3 {Tcl_TimeObjCmd: basic format of command} { sl@0: list [catch {time a b} msg] $msg sl@0: } {1 {expected integer but got "b"}} sl@0: test cmdMZ-5.4 {Tcl_TimeObjCmd: nothing happens with negative iteration counts} { sl@0: time bogusCmd -12456 sl@0: } {0 microseconds per iteration} sl@0: test cmdMZ-5.5 {Tcl_TimeObjCmd: result format} { sl@0: regexp {^\d+ microseconds per iteration} [time {format 1}] sl@0: } 1 sl@0: test cmdMZ-5.6 {Tcl_TimeObjCmd: slower commands take longer} { sl@0: expr {[lindex [time {after 2}] 0] < [lindex [time {after 1000}] 0]} sl@0: } 1 sl@0: test cmdMZ-5.7 {Tcl_TimeObjCmd: errors generate right trace} { sl@0: list [catch {time {error foo}} msg] $msg $::errorInfo sl@0: } {1 foo {foo sl@0: while executing sl@0: "error foo" sl@0: invoked from within sl@0: "time {error foo}"}} sl@0: sl@0: # The tests for Tcl_TraceObjCmd and TraceVarProc are in trace.test sl@0: # The tests for Tcl_WhileObjCmd are in while.test sl@0: sl@0: # cleanup sl@0: ::tcltest::cleanupTests sl@0: return