os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/load.test
First public contribution.
1 # Commands covered: load
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.
7 # Copyright (c) 1995 Sun Microsystems, Inc.
8 # Copyright (c) 1998-1999 by Scriptics Corporation.
10 # See the file "license.terms" for information on usage and redistribution
11 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
13 # RCS: @(#) $Id: load.test,v 1.11.2.1 2004/09/14 17:02:56 das Exp $
15 if {[lsearch [namespace children] ::tcltest] == -1} {
16 package require tcltest 2
17 namespace import -force ::tcltest::*
20 # Figure out what extension is used for shared libraries on this
23 if {$tcl_platform(platform) == "macintosh"} {
24 puts "can't run dynamic library tests on macintosh machines"
25 ::tcltest::cleanupTests
29 # Tests require the existence of one of the DLLs in the dltest directory.
30 set ext [info sharedlibextension]
31 set testDir [file join [file dirname [info nameofexecutable]] dltest]
32 set x [file join $testDir pkga$ext]
33 set dll "[file tail $x]Required"
34 ::tcltest::testConstraint $dll [file readable $x]
36 # Tests also require that this DLL has not already been loaded.
37 set loaded "[file tail $x]Loaded"
38 set alreadyLoaded [info loaded]
39 ::tcltest::testConstraint $loaded \
40 [expr {![string match *pkga* $alreadyLoaded]}]
42 set alreadyTotalLoaded [info loaded]
44 # Certain tests require the 'teststaticpkg' command from tcltest
46 ::tcltest::testConstraint teststaticpkg \
47 [string compare {} [info commands teststaticpkg]]
50 test load-1.1 {basic errors} {} {
51 list [catch {load} msg] $msg
52 } "1 {wrong \# args: should be \"load fileName ?packageName? ?interp?\"}"
53 test load-1.2 {basic errors} {} {
54 list [catch {load a b c d} msg] $msg
55 } "1 {wrong \# args: should be \"load fileName ?packageName? ?interp?\"}"
56 test load-1.3 {basic errors} {} {
57 list [catch {load a b foobar} msg] $msg
58 } {1 {could not find interpreter "foobar"}}
59 test load-1.4 {basic errors} {} {
60 list [catch {load {}} msg] $msg
61 } {1 {must specify either file name or package name}}
62 test load-1.5 {basic errors} {} {
63 list [catch {load {} {}} msg] $msg
64 } {1 {must specify either file name or package name}}
65 test load-1.6 {basic errors} {} {
66 list [catch {load {} Unknown} msg] $msg
67 } {1 {package "Unknown" isn't loaded statically}}
69 test load-2.1 {basic loading, with guess for package name} \
71 load [file join $testDir pkga$ext]
72 list [pkga_eq abc def] [info commands pkga_*]
73 } {0 {pkga_eq pkga_quote}}
74 interp create -safe child
75 test load-2.2 {loading into a safe interpreter, with package name conversion} \
77 load [file join $testDir pkgb$ext] pKgB child
78 list [child eval pkgb_sub 44 13] [catch {child eval pkgb_unsafe} msg] $msg \
79 [catch {pkgb_sub 12 10} msg2] $msg2
80 } {31 1 {invalid command name "pkgb_unsafe"} 1 {invalid command name "pkgb_sub"}}
81 test load-2.3 {loading with no _Init procedure} -constraints [list $dll $loaded] \
83 list [catch {load [file join $testDir pkgc$ext] foo} msg] $msg
84 } -match glob -result {1 {*couldn't find procedure Foo_Init}}
85 test load-2.4 {loading with no _SafeInit procedure} [list $dll $loaded] {
86 list [catch {load [file join $testDir pkga$ext] {} child} msg] $msg
87 } {1 {can't use package in a safe interpreter: no Pkga_SafeInit procedure}}
89 test load-3.1 {error in _Init procedure, same interpreter} \
91 list [catch {load [file join $testDir pkge$ext] pkge} msg] \
92 $msg $errorInfo $errorCode
93 } {1 {couldn't open "non_existent": no such file or directory} {couldn't open "non_existent": no such file or directory
97 "if 44 {open non_existent}"
99 "load [file join $testDir pkge$ext] pkge"} {POSIX ENOENT {no such file or directory}}}
100 test load-3.2 {error in _Init procedure, slave interpreter} \
101 [list $dll $loaded] {
102 catch {interp delete x}
106 set result [list [catch {load [file join $testDir pkge$ext] pkge x} msg] \
107 $msg $errorInfo $errorCode]
110 } {1 {couldn't open "non_existent": no such file or directory} {couldn't open "non_existent": no such file or directory
114 "if 44 {open non_existent}"
116 "load [file join $testDir pkge$ext] pkge x"} {POSIX ENOENT {no such file or directory}}}
118 test load-4.1 {reloading package into same interpreter} [list $dll $loaded] {
119 list [catch {load [file join $testDir pkga$ext] pkga} msg] $msg
121 test load-4.2 {reloading package into same interpreter} [list $dll $loaded] {
122 list [catch {load [file join $testDir pkga$ext] pkgb} msg] $msg
123 } [list 1 "file \"[file join $testDir pkga$ext]\" is already loaded for package \"Pkga\""]
125 test load-5.1 {file name not specified and no static package: pick default} \
126 [list $dll $loaded] {
127 catch {interp delete x}
129 load [file join $testDir pkga$ext] pkga
131 set result [info loaded x]
134 } [list [list [file join $testDir pkga$ext] Pkga]]
136 # On some platforms, like SunOS 4.1.3, these tests can't be run because
137 # they cause the process to exit.
139 test load-6.1 {errors loading file} [list $dll $loaded nonPortable] {
143 test load-7.1 {Tcl_StaticPackage procedure} [list teststaticpkg] {
145 teststaticpkg Test 1 0
148 list [set x] [child eval set x]
150 test load-7.2 {Tcl_StaticPackage procedure} [list teststaticpkg] {
152 teststaticpkg Another 0 0
154 child eval {set x "not loaded"}
155 list [catch {load {} Another child} msg] $msg \
156 [child eval set x] [set x]
157 } {1 {can't use package in a safe interpreter: no Another_SafeInit procedure} {not loaded} loaded}
158 test load-7.3 {Tcl_StaticPackage procedure} [list teststaticpkg] {
160 teststaticpkg More 0 1
164 test load-7.4 {Tcl_StaticPackage procedure, redundant calls} \
165 [list teststaticpkg $dll $loaded] {
166 teststaticpkg Double 0 1
167 teststaticpkg Double 0 1
169 } [concat [list {{} Double} {{} More} {{} Another} {{} Test} [list [file join $testDir pkge$ext] Pkge] [list [file join $testDir pkgb$ext] Pkgb] [list [file join $testDir pkga$ext] Pkga]] $alreadyTotalLoaded]
171 test load-8.1 {TclGetLoadedPackages procedure} [list teststaticpkg $dll $loaded] {
173 } [concat [list {{} Double} {{} More} {{} Another} {{} Test} [list [file join $testDir pkge$ext] Pkge] [list [file join $testDir pkgb$ext] Pkgb] [list [file join $testDir pkga$ext] Pkga]] $alreadyTotalLoaded]
174 test load-8.2 {TclGetLoadedPackages procedure} [list teststaticpkg] {
175 list [catch {info loaded gorp} msg] $msg
176 } {1 {could not find interpreter "gorp"}}
177 test load-8.3 {TclGetLoadedPackages procedure} [list teststaticpkg $dll $loaded] {
178 list [info loaded {}] [info loaded child]
179 } [list [concat [list {{} Double} {{} More} {{} Another} {{} Test} [list [file join $testDir pkga$ext] Pkga]] $alreadyLoaded] [list {{} Test} [list [file join $testDir pkgb$ext] Pkgb]]]
180 test load-8.4 {TclGetLoadedPackages procedure} [list $dll $loaded teststaticpkg] {
181 load [file join $testDir pkgb$ext] pkgb
182 list [info loaded {}] [lsort [info commands pkgb_*]]
183 } [list [concat [list [list [file join $testDir pkgb$ext] Pkgb] {{} Double} {{} More} {{} Another} {{} Test} [list [file join $testDir pkga$ext] Pkga]] $alreadyLoaded] {pkgb_sub pkgb_unsafe}]
186 test load-9.1 {Tcl_StaticPackage, load already-loaded package into another interp} \
187 -constraints {teststaticpkg} \
191 load {} Tcltest child1
192 load {} Tcltest child2
195 child1 eval { teststaticpkg Loadninepointone 0 1 }
196 child2 eval { teststaticpkg Loadninepointone 0 1 }
198 [child1 eval { info loaded {} }] \
199 [child2 eval { info loaded {} }]
201 -result {{{{} Loadninepointone} {{} Tcltest}} {{{} Loadninepointone} {{} Tcltest}}} \
202 -cleanup { interp delete child1 ; interp delete child2 }
206 ::tcltest::cleanupTests