Debian Codegraph @

tests/safe-stock.test

raw
1 # safe-stock.test --
2 #
3 # This file contains tests for safe Tcl that were previously in the file
4 # safe.test, and use files and packages of stock Tcl 8.6 to perform the tests.
5 # These files may be changed or disappear in future revisions of Tcl,
6 # for example package http 1.0 will be removed from Tcl 9.0.
7 #
8 # The tests are replaced in safe.tcl with tests that use files provided in the
9 # tests directory. Test numbering is for comparison with similar tests in
10 # safe.test.
11 #
12 # Sourcing this file into tcl runs the tests and generates output for errors.
13 # No output means no errors were found.
14 #
15 # Copyright (c) 1995-1996 Sun Microsystems, Inc.
16 # Copyright (c) 1998-1999 Scriptics Corporation.
17 #
18 # See the file "license.terms" for information on usage and redistribution of
19 # this file, and for a DISCLAIMER OF ALL WARRANTIES.
20
21 if {"::tcltest" ni [namespace children]} {
22 package require tcltest 2.5
23 namespace import -force ::tcltest::*
24 }
25
26 foreach i [interp children] {
27 interp delete $i
28 }
29
30 set SaveAutoPath $::auto_path
31 set ::auto_path [info library]
32 set TestsDir [file normalize [file dirname [info script]]]
33 set PathMapp [list $tcl_library TCLLIB $TestsDir TESTSDIR]
34
35 proc mapList {map listIn} {
36 set listOut {}
37 foreach element $listIn {
38 lappend listOut [string map $map $element]
39 }
40 return $listOut
41 }
42
43 # Force actual loading of the safe package because we use unexported (and
44 # thus unautoindexed) APIs in this test result arguments:
45 catch {safe::interpConfigure}
46
47 # high level general test
48 test safe-stock-7.1 {tests that everything works at high level, uses http 2} -body {
49 set i [safe::interpCreate]
50 # no error shall occur:
51 # (because the default access_path shall include 1st level sub dirs so
52 # package require in a child works like in the parent)
53 set v [interp eval $i {package require http 2}]
54 # no error shall occur:
55 interp eval $i {http::config}
56 safe::interpDelete $i
57 set v
58 } -match glob -result 2.*
59 test safe-stock-7.2 {tests specific path and interpFind/AddToAccessPath, uses http1.0} -body {
60 set i [safe::interpCreate -nostat -nested 1 -accessPath [list [info library]]]
61 # should not add anything (p0)
62 set token1 [safe::interpAddToAccessPath $i [info library]]
63 # should add as p1
64 set token2 [safe::interpAddToAccessPath $i "/dummy/unixlike/test/path"]
65 set confA [safe::interpConfigure $i]
66 set mappA [mapList $PathMapp [dict get $confA -accessPath]]
67 # an error shall occur (http is not anymore in the secure 0-level
68 # provided deep path)
69 list $token1 $token2 -- \
70 [catch {interp eval $i {package require http 1}} msg] $msg -- \
71 $mappA -- [safe::interpDelete $i]
72 } -match glob -result {{$p(:0:)} {$p(:*:)} -- 1 {can't find package http 1} --\
73 {TCLLIB */dummy/unixlike/test/path} -- {}}
74 test safe-stock-7.4 {tests specific path and positive search, uses http1.0} -body {
75 set i [safe::interpCreate -nostat -nested 1 -accessPath [list [info library]]]
76 # should not add anything (p0)
77 set token1 [safe::interpAddToAccessPath $i [info library]]
78 # should add as p1
79 set token2 [safe::interpAddToAccessPath $i [file join [info library] http1.0]]
80 set confA [safe::interpConfigure $i]
81 set mappA [mapList $PathMapp [dict get $confA -accessPath]]
82 # this time, unlike test safe-stock-7.2, http should be found
83 list $token1 $token2 -- \
84 [catch {interp eval $i {package require http 1}} msg] $msg -- \
85 $mappA -- [safe::interpDelete $i]
86 } -match glob -result {{$p(:0:)} {$p(:*:)} -- 0 1.0 -- {TCLLIB *TCLLIB/http1.0} -- {}}
87
88 # The following test checks whether the definition of tcl_endOfWord can be
89 # obtained from auto_loading. It was previously test "safe-5.1".
90 test safe-stock-9.8 {test auto-loading in safe interpreters, was test 5.1} -setup {
91 catch {safe::interpDelete a}
92 safe::interpCreate a
93 } -body {
94 interp eval a {tcl_endOfWord "" 0}
95 } -cleanup {
96 safe::interpDelete a
97 } -result -1
98
99 set ::auto_path $SaveAutoPath
100 unset SaveAutoPath TestsDir PathMapp
101 rename mapList {}
102
103 # cleanup
104 ::tcltest::cleanupTests
105 return
106
107 # Local Variables:
108 # mode: tcl
109 # End: