os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/cmdMZ.test
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 # The tests in this file cover the procedures in tclCmdMZ.c.
     2 #
     3 # This file contains a collection of tests for one or more of the Tcl
     4 # built-in commands.  Sourcing this file into Tcl runs the tests and
     5 # generates output for errors.  No output means no errors were found.
     6 #
     7 # Copyright (c) 1991-1993 The Regents of the University of California.
     8 # Copyright (c) 1994 Sun Microsystems, Inc.
     9 # Copyright (c) 1998-1999 by Scriptics Corporation.
    10 #
    11 # See the file "license.terms" for information on usage and redistribution
    12 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
    13 #
    14 # RCS: @(#) $Id: cmdMZ.test,v 1.13.2.3 2004/02/25 23:38:16 dgp Exp $
    15 
    16 if {[lsearch [namespace children] ::tcltest] == -1} {
    17     package require tcltest 2.1
    18     namespace import -force ::tcltest::*
    19 }
    20 
    21 # Tcl_PwdObjCmd
    22 
    23 test cmdMZ-1.1 {Tcl_PwdObjCmd} {
    24     list [catch {pwd a} msg] $msg
    25 } {1 {wrong # args: should be "pwd"}}
    26 test cmdMZ-1.2 {Tcl_PwdObjCmd: simple pwd} {
    27     catch pwd
    28 } 0
    29 test cmdMZ-1.3 {Tcl_PwdObjCmd: simple pwd} {
    30     expr [string length pwd]>0
    31 } 1
    32 test cmdMZ-1.4 {Tcl_PwdObjCmd: failure} {unixOnly nonPortable} {
    33     # This test fails on various unix platforms (eg Linux) where
    34     # permissions caching causes this to fail.  The caching is strictly
    35     # incorrect, but we have no control over that.
    36     set foodir [file join [temporaryDirectory] foo]
    37     file delete -force $foodir
    38     file mkdir $foodir
    39     set cwd [pwd]
    40     cd $foodir
    41     file attr . -permissions 000
    42     set result [list [catch {pwd} msg] $msg]
    43     cd $cwd
    44     file delete -force $foodir
    45     set result
    46 } {1 {error getting working directory name: permission denied}}
    47 
    48 # The tests for Tcl_RegexpObjCmd, Tcl_RegsubObjCmd are in regexp.test
    49 
    50 # Tcl_RenameObjCmd
    51 
    52 test cmdMZ-2.1 {Tcl_RenameObjCmd: error conditions} {
    53     list [catch {rename r1} msg] $msg $errorCode
    54 } {1 {wrong # args: should be "rename oldName newName"} NONE}
    55 test cmdMZ-2.2 {Tcl_RenameObjCmd: error conditions} {
    56     list [catch {rename r1 r2 r3} msg] $msg $errorCode
    57 } {1 {wrong # args: should be "rename oldName newName"} NONE}
    58 test cmdMZ-2.3 {Tcl_RenameObjCmd: success} {
    59     catch {rename r2 {}}
    60     proc r1 {} {return "r1"}
    61     rename r1 r2
    62     r2
    63 } {r1}
    64 test cmdMZ-2.4 {Tcl_RenameObjCmd: success} {
    65     proc r1 {} {return "r1"}
    66     rename r1 {}
    67     list [catch {r1} msg] $msg
    68 } {1 {invalid command name "r1"}}
    69 
    70 # The tests for Tcl_ReturnObjCmd are in proc-old.test
    71 # The tests for Tcl_ScanObjCmd are in scan.test
    72 
    73 # Tcl_SourceObjCmd
    74 
    75 test cmdMZ-3.1 {Tcl_SourceObjCmd: error conditions} {macOnly} {
    76     list [catch {source} msg] $msg
    77 } {1 {wrong # args: should be "source fileName" or "source -rsrc name ?fileName?" or "source -rsrcid id ?fileName?"}}
    78 test cmdMZ-3.2 {Tcl_SourceObjCmd: error conditions} {macOnly} {
    79     list [catch {source a b} msg] $msg
    80 } {1 {bad argument: should be "source fileName" or "source -rsrc name ?fileName?" or "source -rsrcid id ?fileName?"}}
    81 test cmdMZ-3.3 {Tcl_SourceObjCmd: error conditions} {unixOrPc} {
    82     list [catch {source} msg] $msg
    83 } {1 {wrong # args: should be "source fileName"}}
    84 test cmdMZ-3.4 {Tcl_SourceObjCmd: error conditions} {unixOrPc} {
    85     list [catch {source a b} msg] $msg
    86 } {1 {wrong # args: should be "source fileName"}}
    87 
    88 proc ListGlobMatch {expected actual} {
    89     if {[llength $expected] != [llength $actual]} {
    90 	return 0
    91     }
    92     foreach e $expected a $actual {
    93 	if {![string match $e $a]} {
    94 	    return 0
    95 	}
    96     }
    97     return 1
    98 }
    99 customMatch listGlob ListGlobMatch
   100 
   101 test cmdMZ-3.5 {Tcl_SourceObjCmd: error in script} -setup {
   102     set file [makeFile {
   103 	set x 146
   104 	error "error in sourced file"
   105 	set y $x
   106     } source.file]
   107 } -body {
   108     list [catch {source $file} msg] $msg $errorInfo
   109 } -cleanup {
   110     removeFile source.file
   111 } -match listGlob -result {1 {error in sourced file} {error in sourced file
   112     while executing
   113 "error "error in sourced file""
   114     (file "*" line 3)
   115     invoked from within
   116 "source $file"}}
   117 test cmdMZ-3.6 {Tcl_SourceObjCmd: simple script} {
   118     set file [makeFile {list result} source.file]
   119     set result [source $file]
   120     removeFile source.file
   121     set result
   122 } result
   123 
   124 # Tcl_SplitObjCmd
   125 
   126 test cmdMZ-4.1 {Tcl_SplitObjCmd: split errors} {
   127     list [catch split msg] $msg $errorCode
   128 } {1 {wrong # args: should be "split string ?splitChars?"} NONE}
   129 test cmdMZ-4.2 {Tcl_SplitObjCmd: split errors} {
   130     list [catch {split a b c} msg] $msg $errorCode
   131 } {1 {wrong # args: should be "split string ?splitChars?"} NONE}
   132 test cmdMZ-4.3 {Tcl_SplitObjCmd: basic split commands} {
   133     split "a\n b\t\r c\n "
   134 } {a {} b {} {} c {} {}}
   135 test cmdMZ-4.4 {Tcl_SplitObjCmd: basic split commands} {
   136     split "word 1xyzword 2zword 3" xyz
   137 } {{word 1} {} {} {word 2} {word 3}}
   138 test cmdMZ-4.5 {Tcl_SplitObjCmd: basic split commands} {
   139     split "12345" {}
   140 } {1 2 3 4 5}
   141 test cmdMZ-4.6 {Tcl_SplitObjCmd: basic split commands} {
   142     split "a\}b\[c\{\]\$"
   143 } "a\\}b\\\[c\\{\\\]\\\$"
   144 test cmdMZ-4.7 {Tcl_SplitObjCmd: basic split commands} {
   145     split {} {}
   146 } {}
   147 test cmdMZ-4.8 {Tcl_SplitObjCmd: basic split commands} {
   148     split {}
   149 } {}
   150 test cmdMZ-4.9 {Tcl_SplitObjCmd: basic split commands} {
   151     split {   }
   152 } {{} {} {} {}}
   153 test cmdMZ-4.10 {Tcl_SplitObjCmd: basic split commands} {
   154     proc foo {} {
   155         set x {}
   156         foreach f [split {]\n} {}] {
   157             append x $f
   158         }
   159         return $x	
   160     }
   161     foo
   162 } {]\n}
   163 test cmdMZ-4.11 {Tcl_SplitObjCmd: basic split commands} {
   164     proc foo {} {
   165         set x ab\000c
   166         set y [split $x {}]
   167         return $y
   168     }
   169     foo
   170 } "a b \000 c"
   171 test cmdMZ-4.12 {Tcl_SplitObjCmd: basic split commands} {
   172     split "a0ab1b2bbb3\000c4" ab\000c
   173 } {{} 0 {} 1 2 {} {} 3 {} 4}
   174 test cmdMZ-4.13 {Tcl_SplitObjCmd: basic split commands} {
   175     # if not UTF-8 aware, result is "a {} {} b qw\xe5 {} N wq"
   176     split "a\u4e4eb qw\u5e4e\x4e wq" " \u4e4e"
   177 } "a b qw\u5e4eN wq"
   178 
   179 # The tests for Tcl_StringObjCmd are in string.test
   180 # The tests for Tcl_SubstObjCmd are in subst.test
   181 # The tests for Tcl_SwitchObjCmd are in switch.test
   182 
   183 test cmdMZ-5.1 {Tcl_TimeObjCmd: basic format of command} {
   184     list [catch {time} msg] $msg
   185 } {1 {wrong # args: should be "time command ?count?"}}
   186 test cmdMZ-5.2 {Tcl_TimeObjCmd: basic format of command} {
   187     list [catch {time a b c} msg] $msg
   188 } {1 {wrong # args: should be "time command ?count?"}}
   189 test cmdMZ-5.3 {Tcl_TimeObjCmd: basic format of command} {
   190     list [catch {time a b} msg] $msg
   191 } {1 {expected integer but got "b"}}
   192 test cmdMZ-5.4 {Tcl_TimeObjCmd: nothing happens with negative iteration counts} {
   193     time bogusCmd -12456
   194 } {0 microseconds per iteration}
   195 test cmdMZ-5.5 {Tcl_TimeObjCmd: result format} {
   196     regexp {^\d+ microseconds per iteration} [time {format 1}]
   197 } 1
   198 test cmdMZ-5.6 {Tcl_TimeObjCmd: slower commands take longer} {
   199     expr {[lindex [time {after 2}] 0] < [lindex [time {after 1000}] 0]}
   200 } 1
   201 test cmdMZ-5.7 {Tcl_TimeObjCmd: errors generate right trace} {
   202     list [catch {time {error foo}} msg] $msg $::errorInfo
   203 } {1 foo {foo
   204     while executing
   205 "error foo"
   206     invoked from within
   207 "time {error foo}"}}
   208 
   209 # The tests for Tcl_TraceObjCmd and TraceVarProc are in trace.test
   210 # The tests for Tcl_WhileObjCmd are in while.test
   211 
   212 # cleanup
   213 ::tcltest::cleanupTests
   214 return