os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/safe.test
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
# safe.test --
sl@0
     2
#
sl@0
     3
# This file contains a collection of tests for safe Tcl, packages loading,
sl@0
     4
# and using safe interpreters. Sourcing this file into tcl runs the tests
sl@0
     5
# and generates output for errors.  No output means no errors were found.
sl@0
     6
#
sl@0
     7
# Copyright (c) 1995-1996 Sun Microsystems, Inc.
sl@0
     8
# Copyright (c) 1998-1999 by Scriptics Corporation.
sl@0
     9
#
sl@0
    10
# See the file "license.terms" for information on usage and redistribution
sl@0
    11
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
sl@0
    12
#
sl@0
    13
# RCS: @(#) $Id: safe.test,v 1.13.2.3 2006/11/28 22:20:03 andreas_kupries Exp $
sl@0
    14
sl@0
    15
if {[lsearch [namespace children] ::tcltest] == -1} {
sl@0
    16
    package require tcltest
sl@0
    17
    namespace import -force ::tcltest::*
sl@0
    18
}
sl@0
    19
sl@0
    20
foreach i [interp slaves] {
sl@0
    21
  interp delete $i
sl@0
    22
}
sl@0
    23
sl@0
    24
set saveAutoPath $::auto_path
sl@0
    25
set ::auto_path [info library]
sl@0
    26
sl@0
    27
# Force actual loading of the safe package 
sl@0
    28
# because we use un exported (and thus un-autoindexed) APIs
sl@0
    29
# in this test result arguments:
sl@0
    30
catch {safe::interpConfigure}
sl@0
    31
sl@0
    32
proc equiv {x} {return $x}
sl@0
    33
sl@0
    34
test safe-1.1 {safe::interpConfigure syntax} {
sl@0
    35
    list [catch {safe::interpConfigure} msg] $msg;
sl@0
    36
} {1 {no value given for parameter "slave" (use -help for full usage) :
sl@0
    37
    slave name () name of the slave}}
sl@0
    38
sl@0
    39
test safe-1.2 {safe::interpCreate syntax} {
sl@0
    40
    list [catch {safe::interpCreate -help} msg] $msg;
sl@0
    41
} {1 {Usage information:
sl@0
    42
    Var/FlagName  Type     Value   Help
sl@0
    43
    ------------  ----     -----   ----
sl@0
    44
    ( -help                        gives this help )
sl@0
    45
    ?slave?       name     ()      name of the slave (optional)
sl@0
    46
    -accessPath   list     ()      access path for the slave
sl@0
    47
    -noStatics    boolflag (false) prevent loading of statically linked pkgs
sl@0
    48
    -statics      boolean  (true)  loading of statically linked pkgs
sl@0
    49
    -nestedLoadOk boolflag (false) allow nested loading
sl@0
    50
    -nested       boolean  (false) nested loading
sl@0
    51
    -deleteHook   script   ()      delete hook}}
sl@0
    52
sl@0
    53
test safe-1.3 {safe::interpInit syntax} {
sl@0
    54
    list [catch {safe::interpInit -noStatics} msg] $msg;
sl@0
    55
} {1 {bad value "-noStatics" for parameter
sl@0
    56
    slave name () name of the slave}}
sl@0
    57
sl@0
    58
sl@0
    59
test safe-2.1 {creating interpreters, should have no aliases} {
sl@0
    60
    interp aliases
sl@0
    61
} ""
sl@0
    62
test safe-2.2 {creating interpreters, should have no aliases} {
sl@0
    63
    catch {safe::interpDelete a}
sl@0
    64
    interp create a
sl@0
    65
    set l [a aliases]
sl@0
    66
    safe::interpDelete a
sl@0
    67
    set l
sl@0
    68
} ""
sl@0
    69
test safe-2.3 {creating safe interpreters, should have no aliases} {
sl@0
    70
    catch {safe::interpDelete a}
sl@0
    71
    interp create a -safe
sl@0
    72
    set l [a aliases]
sl@0
    73
    interp delete a
sl@0
    74
    set l
sl@0
    75
} ""
sl@0
    76
sl@0
    77
test safe-3.1 {calling safe::interpInit is safe} {
sl@0
    78
    catch {safe::interpDelete a}
sl@0
    79
    interp create a -safe 
sl@0
    80
    safe::interpInit a
sl@0
    81
    catch {interp eval a exec ls} msg
sl@0
    82
    safe::interpDelete a
sl@0
    83
    set msg
sl@0
    84
} {invalid command name "exec"}
sl@0
    85
test safe-3.2 {calling safe::interpCreate on trusted interp} {
sl@0
    86
    catch {safe::interpDelete a}
sl@0
    87
    safe::interpCreate a
sl@0
    88
    set l [lsort [a aliases]]
sl@0
    89
    safe::interpDelete a
sl@0
    90
    set l
sl@0
    91
} {encoding exit file load source}
sl@0
    92
test safe-3.3 {calling safe::interpCreate on trusted interp} {
sl@0
    93
    catch {safe::interpDelete a}
sl@0
    94
    safe::interpCreate a
sl@0
    95
    set x [interp eval a {source [file join $tcl_library init.tcl]}]
sl@0
    96
    safe::interpDelete a
sl@0
    97
    set x
sl@0
    98
} ""
sl@0
    99
test safe-3.4 {calling safe::interpCreate on trusted interp} {
sl@0
   100
    catch {safe::interpDelete a}
sl@0
   101
    safe::interpCreate a
sl@0
   102
    catch {set x \
sl@0
   103
		[interp eval a {source [file join $tcl_library init.tcl]}]} msg
sl@0
   104
    safe::interpDelete a
sl@0
   105
    list $x $msg
sl@0
   106
} {{} {}}
sl@0
   107
sl@0
   108
test safe-4.1 {safe::interpDelete} {
sl@0
   109
    catch {safe::interpDelete a}
sl@0
   110
    interp create a
sl@0
   111
    safe::interpDelete a
sl@0
   112
} ""
sl@0
   113
test safe-4.2 {safe::interpDelete, indirectly} {
sl@0
   114
    catch {safe::interpDelete a}
sl@0
   115
    interp create a
sl@0
   116
    a alias exit safe::interpDelete a
sl@0
   117
    a eval exit
sl@0
   118
} ""
sl@0
   119
test safe-4.3 {safe::interpDelete, state array (not a public api)} {
sl@0
   120
    catch {safe::interpDelete a}
sl@0
   121
    namespace eval safe {set [InterpStateName a](foo) 33}
sl@0
   122
    # not an error anymore to call it if interp is already
sl@0
   123
    # deleted, to make trhings smooth if it's called twice...
sl@0
   124
    catch {safe::interpDelete a} m1
sl@0
   125
    catch {namespace eval safe {set [InterpStateName a](foo)}} m2
sl@0
   126
    list $m1 $m2
sl@0
   127
} "{}\
sl@0
   128
   {can't read \"[safe::InterpStateName a](foo)\": no such variable}"
sl@0
   129
sl@0
   130
sl@0
   131
test safe-4.4 {safe::interpDelete, state array, indirectly (not a public api)} {
sl@0
   132
    catch {safe::interpDelete a}
sl@0
   133
    safe::interpCreate a
sl@0
   134
    namespace eval safe {set [InterpStateName a](foo) 33}
sl@0
   135
    a eval exit
sl@0
   136
    catch {namespace eval safe {set [InterpStateName a](foo)}} msg
sl@0
   137
} 1
sl@0
   138
sl@0
   139
test safe-4.5 {safe::interpDelete} {
sl@0
   140
    catch {safe::interpDelete a}
sl@0
   141
    safe::interpCreate a
sl@0
   142
    catch {safe::interpCreate a} msg
sl@0
   143
    set msg
sl@0
   144
} {interpreter named "a" already exists, cannot create}
sl@0
   145
test safe-4.6 {safe::interpDelete, indirectly} {
sl@0
   146
    catch {safe::interpDelete a}
sl@0
   147
    safe::interpCreate a
sl@0
   148
    a eval exit
sl@0
   149
} ""
sl@0
   150
sl@0
   151
# The following test checks whether the definition of tcl_endOfWord can be
sl@0
   152
# obtained from auto_loading.
sl@0
   153
sl@0
   154
test safe-5.1 {test auto-loading in safe interpreters} {
sl@0
   155
    catch {safe::interpDelete a}
sl@0
   156
    safe::interpCreate a
sl@0
   157
    set r [catch {interp eval a {tcl_endOfWord "" 0}} msg]
sl@0
   158
    safe::interpDelete a
sl@0
   159
    list $r $msg
sl@0
   160
} {0 -1}
sl@0
   161
sl@0
   162
# test safe interps 'information leak'
sl@0
   163
proc SI {} {
sl@0
   164
    global I
sl@0
   165
    set I [interp create -safe];
sl@0
   166
}
sl@0
   167
proc DI {} {
sl@0
   168
    global I;
sl@0
   169
    interp delete $I;
sl@0
   170
}
sl@0
   171
test safe-6.1 {test safe interpreters knowledge of the world} {
sl@0
   172
    SI; set r [lsort [$I eval {info globals}]]; DI; set r
sl@0
   173
} {tcl_interactive tcl_patchLevel tcl_platform tcl_version}
sl@0
   174
test safe-6.2 {test safe interpreters knowledge of the world} {
sl@0
   175
    SI; set r [$I eval {info script}]; DI; set r
sl@0
   176
} {}
sl@0
   177
test safe-6.3 {test safe interpreters knowledge of the world} {
sl@0
   178
    SI
sl@0
   179
    set r [lsort [$I eval {array names tcl_platform}]]
sl@0
   180
    DI
sl@0
   181
    # If running a windows-debug shell, remove the "debug" element from r.
sl@0
   182
    if {$tcl_platform(platform) == "windows" && \
sl@0
   183
	    [lsearch $r "debug"] != -1} {
sl@0
   184
	set r [lreplace $r 1 1]
sl@0
   185
    }
sl@0
   186
    set threaded [lsearch $r "threaded"]
sl@0
   187
    if {$threaded != -1} {
sl@0
   188
	set r [lreplace $r $threaded $threaded]
sl@0
   189
    }
sl@0
   190
    set tip [lsearch $r "tip,268"]
sl@0
   191
    if {$tip != -1} {
sl@0
   192
	set r [lreplace $r $tip $tip]
sl@0
   193
    }
sl@0
   194
    set tip [lsearch $r "tip,280"]
sl@0
   195
    if {$tip != -1} {
sl@0
   196
	set r [lreplace $r $tip $tip]
sl@0
   197
    }
sl@0
   198
    set r
sl@0
   199
} {byteOrder platform wordSize}
sl@0
   200
sl@0
   201
# more test should be added to check that hostname, nameofexecutable,
sl@0
   202
# aren't leaking infos, but they still do...
sl@0
   203
sl@0
   204
# high level general test
sl@0
   205
test safe-7.1 {tests that everything works at high level} {
sl@0
   206
    set i [safe::interpCreate];
sl@0
   207
    # no error shall occur:
sl@0
   208
    # (because the default access_path shall include 1st level sub dirs
sl@0
   209
    #  so package require in a slave works like in the master)
sl@0
   210
    set v [interp eval $i {package require http 1}]
sl@0
   211
    # no error shall occur:
sl@0
   212
    interp eval $i {http_config};
sl@0
   213
    safe::interpDelete $i
sl@0
   214
    set v
sl@0
   215
} 1.0
sl@0
   216
sl@0
   217
test safe-7.2 {tests specific path and interpFind/AddToAccessPath} {
sl@0
   218
    set i [safe::interpCreate -nostat -nested 1 -accessPath [list [info library]]];
sl@0
   219
    # should not add anything (p0)
sl@0
   220
    set token1 [safe::interpAddToAccessPath $i [info library]]
sl@0
   221
    # should add as p1
sl@0
   222
    set token2 [safe::interpAddToAccessPath $i "/dummy/unixlike/test/path"];
sl@0
   223
    # an error shall occur (http is not anymore in the secure 0-level
sl@0
   224
    # provided deep path)
sl@0
   225
    list $token1 $token2 \
sl@0
   226
	    [catch {interp eval $i {package require http 1}} msg] $msg \
sl@0
   227
	    [safe::interpConfigure $i]\
sl@0
   228
	    [safe::interpDelete $i]
sl@0
   229
} "{\$p(:0:)} {\$p(:1:)} 1 {can't find package http 1} {-accessPath {[list $tcl_library /dummy/unixlike/test/path]} -statics 0 -nested 1 -deleteHook {}} {}"
sl@0
   230
sl@0
   231
sl@0
   232
# test source control on file name
sl@0
   233
test safe-8.1 {safe source control on file} {
sl@0
   234
    set i "a";
sl@0
   235
    catch {safe::interpDelete $i}
sl@0
   236
    safe::interpCreate $i;
sl@0
   237
    list  [catch {$i eval {source}} msg] \
sl@0
   238
	    $msg \
sl@0
   239
	    [safe::interpDelete $i] ;
sl@0
   240
} {1 {wrong # args: should be "source fileName"} {}}
sl@0
   241
sl@0
   242
# test source control on file name
sl@0
   243
test safe-8.2 {safe source control on file} {
sl@0
   244
    set i "a";
sl@0
   245
    catch {safe::interpDelete $i}
sl@0
   246
    safe::interpCreate $i;
sl@0
   247
    list  [catch {$i eval {source}} msg] \
sl@0
   248
	    $msg \
sl@0
   249
	    [safe::interpDelete $i] ;
sl@0
   250
} {1 {wrong # args: should be "source fileName"} {}}
sl@0
   251
sl@0
   252
test safe-8.3 {safe source control on file} {
sl@0
   253
    set i "a";
sl@0
   254
    catch {safe::interpDelete $i}
sl@0
   255
    safe::interpCreate $i;
sl@0
   256
    set log {};
sl@0
   257
    proc safe-test-log {str} {global log; lappend log $str}
sl@0
   258
    set prevlog [safe::setLogCmd];
sl@0
   259
    safe::setLogCmd safe-test-log;
sl@0
   260
    list  [catch {$i eval {source .}} msg] \
sl@0
   261
	    $msg \
sl@0
   262
	    $log \
sl@0
   263
	    [safe::setLogCmd $prevlog; unset log] \
sl@0
   264
	    [safe::interpDelete $i] ;
sl@0
   265
} {1 {permission denied} {{ERROR for slave a : ".": is a directory}} {} {}}
sl@0
   266
sl@0
   267
sl@0
   268
test safe-8.4 {safe source control on file} {
sl@0
   269
    set i "a";
sl@0
   270
    catch {safe::interpDelete $i}
sl@0
   271
    safe::interpCreate $i;
sl@0
   272
    set log {};
sl@0
   273
    proc safe-test-log {str} {global log; lappend log $str}
sl@0
   274
    set prevlog [safe::setLogCmd];
sl@0
   275
    safe::setLogCmd safe-test-log;
sl@0
   276
    list  [catch {$i eval {source /abc/def}} msg] \
sl@0
   277
	    $msg \
sl@0
   278
	    $log \
sl@0
   279
	    [safe::setLogCmd $prevlog; unset log] \
sl@0
   280
	    [safe::interpDelete $i] ;
sl@0
   281
} {1 {permission denied} {{ERROR for slave a : "/abc/def": not in access_path}} {} {}}
sl@0
   282
sl@0
   283
sl@0
   284
test safe-8.5 {safe source control on file} {
sl@0
   285
    # This tested filename == *.tcl or tclIndex, but that restriction
sl@0
   286
    # was removed in 8.4a4 - hobbs
sl@0
   287
    set i "a";
sl@0
   288
    catch {safe::interpDelete $i}
sl@0
   289
    safe::interpCreate $i;
sl@0
   290
    set log {};
sl@0
   291
    proc safe-test-log {str} {global log; lappend log $str}
sl@0
   292
    set prevlog [safe::setLogCmd];
sl@0
   293
    safe::setLogCmd safe-test-log;
sl@0
   294
    list  [catch {$i eval {source [file join [info lib] blah]}} msg] \
sl@0
   295
	    $msg \
sl@0
   296
	    $log \
sl@0
   297
	    [safe::setLogCmd $prevlog; unset log] \
sl@0
   298
	    [safe::interpDelete $i] ;
sl@0
   299
} [list 1 {no such file or directory} [list "ERROR for slave a : [file join [info library] blah]:no such file or directory"] {} {}]
sl@0
   300
sl@0
   301
sl@0
   302
test safe-8.6 {safe source control on file} {
sl@0
   303
    set i "a";
sl@0
   304
    catch {safe::interpDelete $i}
sl@0
   305
    safe::interpCreate $i;
sl@0
   306
    set log {};
sl@0
   307
    proc safe-test-log {str} {global log; lappend log $str}
sl@0
   308
    set prevlog [safe::setLogCmd];
sl@0
   309
    safe::setLogCmd safe-test-log;
sl@0
   310
    list  [catch {$i eval {source [file join [info lib] blah.tcl]}} msg] \
sl@0
   311
	    $msg \
sl@0
   312
	    $log \
sl@0
   313
	    [safe::setLogCmd $prevlog; unset log] \
sl@0
   314
	    [safe::interpDelete $i] ;
sl@0
   315
} [list 1 {no such file or directory} [list "ERROR for slave a : [file join [info library] blah.tcl]:no such file or directory"] {} {}]
sl@0
   316
sl@0
   317
sl@0
   318
test safe-8.7 {safe source control on file} {
sl@0
   319
    # This tested length of filename, but that restriction
sl@0
   320
    # was removed in 8.4a4 - hobbs
sl@0
   321
    set i "a";
sl@0
   322
    catch {safe::interpDelete $i}
sl@0
   323
    safe::interpCreate $i;
sl@0
   324
    set log {};
sl@0
   325
    proc safe-test-log {str} {global log; lappend log $str}
sl@0
   326
    set prevlog [safe::setLogCmd];
sl@0
   327
    safe::setLogCmd safe-test-log;
sl@0
   328
    list  [catch {$i eval {source [file join [info lib] xxxxxxxxxxx.tcl]}}\
sl@0
   329
		 msg] \
sl@0
   330
	    $msg \
sl@0
   331
	    $log \
sl@0
   332
	    [safe::setLogCmd $prevlog; unset log] \
sl@0
   333
	    [safe::interpDelete $i] ;
sl@0
   334
} [list 1 {no such file or directory} [list "ERROR for slave a : [file join [info library] xxxxxxxxxxx.tcl]:no such file or directory"] {} {}]
sl@0
   335
sl@0
   336
test safe-8.8 {safe source forbids -rsrc} {
sl@0
   337
    set i "a";
sl@0
   338
    catch {safe::interpDelete $i}
sl@0
   339
    safe::interpCreate $i;
sl@0
   340
    list  [catch {$i eval {source -rsrc Init}} msg] \
sl@0
   341
	    $msg \
sl@0
   342
	    [safe::interpDelete $i] ;
sl@0
   343
} {1 {wrong # args: should be "source fileName"} {}}
sl@0
   344
sl@0
   345
sl@0
   346
test safe-9.1 {safe interps' deleteHook} {
sl@0
   347
    set i "a";
sl@0
   348
    catch {safe::interpDelete $i}
sl@0
   349
    set res {}
sl@0
   350
    proc testDelHook {args} {
sl@0
   351
	global res;
sl@0
   352
	# the interp still exists at that point
sl@0
   353
	interp eval a {set delete 1}
sl@0
   354
	# mark that we've been here (successfully)
sl@0
   355
	set res $args;
sl@0
   356
    }
sl@0
   357
    safe::interpCreate $i -deleteHook "testDelHook arg1 arg2";
sl@0
   358
    list [interp eval $i exit] $res
sl@0
   359
} {{} {arg1 arg2 a}}
sl@0
   360
sl@0
   361
test safe-9.2 {safe interps' error in deleteHook} {
sl@0
   362
    set i "a";
sl@0
   363
    catch {safe::interpDelete $i}
sl@0
   364
    set res {}
sl@0
   365
    proc testDelHook {args} {
sl@0
   366
	global res;
sl@0
   367
	# the interp still exists at that point
sl@0
   368
	interp eval a {set delete 1}
sl@0
   369
	# mark that we've been here (successfully)
sl@0
   370
	set res $args;
sl@0
   371
	# create an exception
sl@0
   372
	error "being catched";
sl@0
   373
    }
sl@0
   374
    set log {};
sl@0
   375
    proc safe-test-log {str} {global log; lappend log $str}
sl@0
   376
    safe::interpCreate $i -deleteHook "testDelHook arg1 arg2";
sl@0
   377
    set prevlog [safe::setLogCmd];
sl@0
   378
    safe::setLogCmd safe-test-log;
sl@0
   379
    list  [safe::interpDelete $i] $res \
sl@0
   380
	    $log \
sl@0
   381
	    [safe::setLogCmd $prevlog; unset log];
sl@0
   382
} {{} {arg1 arg2 a} {{NOTICE for slave a : About to delete} {ERROR for slave a : Delete hook error (being catched)} {NOTICE for slave a : Deleted}} {}}
sl@0
   383
sl@0
   384
sl@0
   385
test safe-9.3 {dual specification of statics} {
sl@0
   386
    list [catch {safe::interpCreate -stat true -nostat} msg] $msg
sl@0
   387
} {1 {conflicting values given for -statics and -noStatics}}
sl@0
   388
sl@0
   389
test safe-9.4 {dual specification of statics} {
sl@0
   390
    # no error shall occur
sl@0
   391
    safe::interpDelete [safe::interpCreate -stat false -nostat]
sl@0
   392
} {}
sl@0
   393
sl@0
   394
test safe-9.5 {dual specification of nested} {
sl@0
   395
    list [catch {safe::interpCreate -nested 0 -nestedload} msg] $msg
sl@0
   396
} {1 {conflicting values given for -nested and -nestedLoadOk}}
sl@0
   397
sl@0
   398
test safe-9.6 {interpConfigure widget like behaviour} {
sl@0
   399
   # this test shall work, don't try to "fix it" unless
sl@0
   400
   # you *really* know what you are doing (ie you are me :p) -- dl
sl@0
   401
   list [set i [safe::interpCreate \
sl@0
   402
	                           -noStatics \
sl@0
   403
                                   -nestedLoadOk \
sl@0
   404
	                           -deleteHook {foo bar}];
sl@0
   405
         safe::interpConfigure $i -accessPath /foo/bar ;
sl@0
   406
         safe::interpConfigure $i]\
sl@0
   407
	[safe::interpConfigure $i -aCCess]\
sl@0
   408
	[safe::interpConfigure $i -nested]\
sl@0
   409
	[safe::interpConfigure $i -statics]\
sl@0
   410
	[safe::interpConfigure $i -DEL]\
sl@0
   411
	[safe::interpConfigure $i -accessPath /blah -statics 1;
sl@0
   412
	 safe::interpConfigure $i]\
sl@0
   413
	[safe::interpConfigure $i -deleteHook toto -nosta -nested 0;
sl@0
   414
	 safe::interpConfigure $i]
sl@0
   415
} {{-accessPath /foo/bar -statics 0 -nested 1 -deleteHook {foo bar}} {-accessPath /foo/bar} {-nested 1} {-statics 0} {-deleteHook {foo bar}} {-accessPath /blah -statics 1 -nested 1 -deleteHook {foo bar}} {-accessPath /blah -statics 0 -nested 0 -deleteHook toto}}
sl@0
   416
sl@0
   417
sl@0
   418
# testing that nested and statics do what is advertised
sl@0
   419
# (we use a static package : Tcltest)
sl@0
   420
sl@0
   421
if {[catch {package require Tcltest} msg]} {
sl@0
   422
    puts "This application hasn't been compiled with Tcltest"
sl@0
   423
    puts "skipping remining safe test that relies on it."
sl@0
   424
} else {
sl@0
   425
sl@0
   426
    # we use the Tcltest package , which has no Safe_Init
sl@0
   427
sl@0
   428
test safe-10.1 {testing statics loading} {
sl@0
   429
    set i [safe::interpCreate]
sl@0
   430
    list \
sl@0
   431
	    [catch {interp eval $i {load {} Tcltest}} msg] \
sl@0
   432
	    $msg \
sl@0
   433
            [safe::interpDelete $i];
sl@0
   434
} {1 {can't use package in a safe interpreter: no Tcltest_SafeInit procedure} {}}
sl@0
   435
sl@0
   436
test safe-10.2 {testing statics loading / -nostatics} {
sl@0
   437
    set i [safe::interpCreate -nostatics]
sl@0
   438
    list \
sl@0
   439
	    [catch {interp eval $i {load {} Tcltest}} msg] \
sl@0
   440
	    $msg \
sl@0
   441
            [safe::interpDelete $i];
sl@0
   442
} {1 {permission denied (static package)} {}}
sl@0
   443
sl@0
   444
sl@0
   445
sl@0
   446
test safe-10.3 {testing nested statics loading / no nested by default} {
sl@0
   447
    set i [safe::interpCreate]
sl@0
   448
    list \
sl@0
   449
	    [catch {interp eval $i {interp create x; load {} Tcltest x}} msg] \
sl@0
   450
	    $msg \
sl@0
   451
            [safe::interpDelete $i];
sl@0
   452
} {1 {permission denied (nested load)} {}}
sl@0
   453
sl@0
   454
sl@0
   455
test safe-10.4 {testing nested statics loading / -nestedloadok} {
sl@0
   456
    set i [safe::interpCreate -nestedloadok]
sl@0
   457
    list \
sl@0
   458
	    [catch {interp eval $i {interp create x; load {} Tcltest x}} msg] \
sl@0
   459
	    $msg \
sl@0
   460
            [safe::interpDelete $i];
sl@0
   461
} {1 {can't use package in a safe interpreter: no Tcltest_SafeInit procedure} {}}
sl@0
   462
sl@0
   463
sl@0
   464
}
sl@0
   465
sl@0
   466
test safe-11.1 {testing safe encoding} {
sl@0
   467
    set i [safe::interpCreate]
sl@0
   468
    list \
sl@0
   469
	    [catch {interp eval $i encoding} msg] \
sl@0
   470
	    $msg \
sl@0
   471
	    [safe::interpDelete $i];
sl@0
   472
} {1 {wrong # args: should be "encoding option ?arg ...?"} {}}
sl@0
   473
sl@0
   474
test safe-11.2 {testing safe encoding} {
sl@0
   475
    set i [safe::interpCreate]
sl@0
   476
    list \
sl@0
   477
	    [catch {interp eval $i encoding system cp775} msg] \
sl@0
   478
	    $msg \
sl@0
   479
	    [safe::interpDelete $i];
sl@0
   480
} {1 {wrong # args: should be "encoding system"} {}}
sl@0
   481
sl@0
   482
test safe-11.3 {testing safe encoding} {
sl@0
   483
    set i [safe::interpCreate]
sl@0
   484
    set result [catch {
sl@0
   485
	string match [encoding system] [interp eval $i encoding system]
sl@0
   486
    } msg]
sl@0
   487
    list $result $msg [safe::interpDelete $i]
sl@0
   488
} {0 1 {}}
sl@0
   489
sl@0
   490
test safe-11.4 {testing safe encoding} {
sl@0
   491
    set i [safe::interpCreate]
sl@0
   492
    set result [catch {
sl@0
   493
	string match [encoding names] [interp eval $i encoding names]
sl@0
   494
    } msg]
sl@0
   495
    list $result $msg  [safe::interpDelete $i]
sl@0
   496
} {0 1 {}}
sl@0
   497
sl@0
   498
test safe-11.5 {testing safe encoding} {
sl@0
   499
    set i [safe::interpCreate]
sl@0
   500
    list \
sl@0
   501
	    [catch {interp eval $i encoding convertfrom cp1258 foobar} msg] \
sl@0
   502
	    $msg \
sl@0
   503
	    [safe::interpDelete $i];
sl@0
   504
} {0 foobar {}}
sl@0
   505
sl@0
   506
sl@0
   507
test safe-11.6 {testing safe encoding} {
sl@0
   508
    set i [safe::interpCreate]
sl@0
   509
    list \
sl@0
   510
	    [catch {interp eval $i encoding convertto cp1258 foobar} msg] \
sl@0
   511
	    $msg \
sl@0
   512
	    [safe::interpDelete $i];
sl@0
   513
} {0 foobar {}}
sl@0
   514
sl@0
   515
test safe-11.7 {testing safe encoding} {
sl@0
   516
    set i [safe::interpCreate]
sl@0
   517
    list \
sl@0
   518
	    [catch {interp eval $i encoding convertfrom} msg] \
sl@0
   519
	    $msg \
sl@0
   520
	    [safe::interpDelete $i];
sl@0
   521
} {1 {wrong # args: should be "encoding convertfrom ?encoding? data"} {}}
sl@0
   522
sl@0
   523
sl@0
   524
test safe-11.8 {testing safe encoding} {
sl@0
   525
    set i [safe::interpCreate]
sl@0
   526
    list \
sl@0
   527
	    [catch {interp eval $i encoding convertto} msg] \
sl@0
   528
	    $msg \
sl@0
   529
	    [safe::interpDelete $i];
sl@0
   530
} {1 {wrong # args: should be "encoding convertto ?encoding? data"} {}}
sl@0
   531
sl@0
   532
sl@0
   533
set ::auto_path $saveAutoPath
sl@0
   534
# cleanup
sl@0
   535
::tcltest::cleanupTests
sl@0
   536
return