os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/init.test
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
# Functionality covered: this file contains a collection of tests for the
sl@0
     2
# auto loading and namespaces.
sl@0
     3
#
sl@0
     4
# Sourcing this file into Tcl runs the tests and generates output for
sl@0
     5
# errors. No output means no errors were found.
sl@0
     6
#
sl@0
     7
# Copyright (c) 1997 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: init.test,v 1.9.2.2 2004/10/26 20:14:36 dgp 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
# Clear out any namespaces called test_ns_*
sl@0
    21
catch {eval namespace delete [namespace children :: test_ns_*]}
sl@0
    22
sl@0
    23
# Six cases - white box testing
sl@0
    24
sl@0
    25
test init-1.1 {auto_qualify - absolute cmd - namespace} {
sl@0
    26
    auto_qualify ::foo::bar ::blue
sl@0
    27
} ::foo::bar
sl@0
    28
sl@0
    29
test init-1.2 {auto_qualify - absolute cmd - global} {
sl@0
    30
    auto_qualify ::global ::sub
sl@0
    31
} global
sl@0
    32
sl@0
    33
test init-1.3 {auto_qualify - no colons cmd - global} {
sl@0
    34
    auto_qualify nocolons ::
sl@0
    35
} nocolons 
sl@0
    36
sl@0
    37
test init-1.4 {auto_qualify - no colons cmd - namespace} {
sl@0
    38
    auto_qualify nocolons ::sub
sl@0
    39
} {::sub::nocolons nocolons}
sl@0
    40
sl@0
    41
test init-1.5 {auto_qualify - colons in cmd - global} {
sl@0
    42
    auto_qualify foo::bar ::
sl@0
    43
} ::foo::bar
sl@0
    44
sl@0
    45
test init-1.6 {auto_qualify - colons in cmd - namespace} {
sl@0
    46
    auto_qualify foo::bar ::sub
sl@0
    47
} {::sub::foo::bar ::foo::bar}
sl@0
    48
sl@0
    49
# Some additional tests
sl@0
    50
sl@0
    51
test init-1.7 {auto_qualify - multiples colons 1} {
sl@0
    52
    auto_qualify :::foo::::bar ::blue
sl@0
    53
} ::foo::bar
sl@0
    54
sl@0
    55
test init-1.8 {auto_qualify - multiple colons 2} {
sl@0
    56
    auto_qualify :::foo ::bar
sl@0
    57
} foo
sl@0
    58
sl@0
    59
sl@0
    60
# we use a sub interp and auto_reset and double the tests because there is 2
sl@0
    61
# places where auto_loading occur (before loading the indexes files and after)
sl@0
    62
sl@0
    63
set testInterp [interp create]
sl@0
    64
interp eval $testInterp [list set argv $argv]
sl@0
    65
interp eval $testInterp [list package require tcltest]
sl@0
    66
interp eval $testInterp [list namespace import -force ::tcltest::*]
sl@0
    67
sl@0
    68
interp eval $testInterp {
sl@0
    69
sl@0
    70
auto_reset
sl@0
    71
catch {rename parray {}}
sl@0
    72
sl@0
    73
test init-2.0 {load parray - stage 1} {
sl@0
    74
    set ret [catch {parray} error]
sl@0
    75
    rename parray {} ; # remove it, for the next test - that should not fail.
sl@0
    76
    list $ret $error
sl@0
    77
} {1 {wrong # args: should be "parray a ?pattern?"}}
sl@0
    78
sl@0
    79
sl@0
    80
test init-2.1 {load parray - stage 2} {
sl@0
    81
    set ret [catch {parray} error]
sl@0
    82
    list $ret $error
sl@0
    83
} {1 {wrong # args: should be "parray a ?pattern?"}}
sl@0
    84
sl@0
    85
sl@0
    86
auto_reset
sl@0
    87
catch {rename ::safe::setLogCmd {}}
sl@0
    88
#unset auto_index(::safe::setLogCmd)
sl@0
    89
#unset auto_oldpath
sl@0
    90
sl@0
    91
test init-2.2 {load ::safe::setLogCmd - stage 1} {
sl@0
    92
    ::safe::setLogCmd
sl@0
    93
    rename ::safe::setLogCmd {} ; # should not fail
sl@0
    94
} {}
sl@0
    95
sl@0
    96
test init-2.3 {load ::safe::setLogCmd - stage 2} {
sl@0
    97
    ::safe::setLogCmd
sl@0
    98
    rename ::safe::setLogCmd {} ; # should not fail
sl@0
    99
} {}
sl@0
   100
sl@0
   101
auto_reset
sl@0
   102
catch {rename ::safe::setLogCmd {}}
sl@0
   103
sl@0
   104
test init-2.4 {load safe:::setLogCmd - stage 1} {
sl@0
   105
    safe:::setLogCmd ; # intentionally 3 :
sl@0
   106
    rename ::safe::setLogCmd {} ; # should not fail
sl@0
   107
} {}
sl@0
   108
sl@0
   109
test init-2.5 {load safe:::setLogCmd - stage 2} {
sl@0
   110
    safe:::setLogCmd ; # intentionally 3 :
sl@0
   111
    rename ::safe::setLogCmd {} ; # should not fail
sl@0
   112
} {}
sl@0
   113
sl@0
   114
auto_reset
sl@0
   115
catch {rename ::safe::setLogCmd {}}
sl@0
   116
sl@0
   117
test init-2.6 {load setLogCmd from safe:: - stage 1} {
sl@0
   118
    namespace eval safe setLogCmd 
sl@0
   119
    rename ::safe::setLogCmd {} ; # should not fail
sl@0
   120
} {}
sl@0
   121
sl@0
   122
test init-2.7 {oad setLogCmd from safe::  - stage 2} {
sl@0
   123
    namespace eval safe setLogCmd 
sl@0
   124
    rename ::safe::setLogCmd {} ; # should not fail
sl@0
   125
} {}
sl@0
   126
sl@0
   127
sl@0
   128
sl@0
   129
test init-2.8 {load tcl::HistAdd} -setup {
sl@0
   130
    auto_reset
sl@0
   131
    catch {rename ::tcl::HistAdd {}}
sl@0
   132
} -body {
sl@0
   133
    # 3 ':' on purpose
sl@0
   134
    list [catch {tcl:::HistAdd} error] $error
sl@0
   135
} -cleanup {
sl@0
   136
    rename ::tcl::HistAdd {} ; 
sl@0
   137
} -result {1 {wrong # args: should be "tcl:::HistAdd command ?exec?"}}
sl@0
   138
sl@0
   139
sl@0
   140
test init-3.0 {random stuff in the auto_index, should still work} {
sl@0
   141
    set auto_index(foo:::bar::blah) {
sl@0
   142
        namespace eval foo {namespace eval bar {proc blah {} {return 1}}}
sl@0
   143
    }
sl@0
   144
    foo:::bar::blah
sl@0
   145
} 1
sl@0
   146
sl@0
   147
# Tests that compare the error stack trace generated when autoloading
sl@0
   148
# with that generated when no autoloading is necessary.  Ideally they
sl@0
   149
# should be the same.
sl@0
   150
sl@0
   151
set count 0
sl@0
   152
foreach arg [subst -nocommands -novariables {
sl@0
   153
		c
sl@0
   154
                {argument
sl@0
   155
                which spans
sl@0
   156
                multiple lines}
sl@0
   157
                {argument which is all on one line but which is of such great length that the Tcl C library will truncate it when appending it onto the global error stack}
sl@0
   158
                {argument which spans multiple lines
sl@0
   159
                and is long enough to be truncated and
sl@0
   160
"               <- includes a false lead in the prune point search
sl@0
   161
                and must be longer still to force truncation}
sl@0
   162
                {contrived example: rare circumstance 
sl@0
   163
		where the point at which to prune the
sl@0
   164
		error stack cannot be uniquely determined.
sl@0
   165
		foo bar foo
sl@0
   166
"}
sl@0
   167
                {contrived example: rare circumstance 
sl@0
   168
		where the point at which to prune the
sl@0
   169
		error stack cannot be uniquely determined.
sl@0
   170
		foo bar
sl@0
   171
"}
sl@0
   172
		{argument that contains non-ASCII character, \u20ac, and which is of such great length that it will be longer than 150 bytes so it will be truncated by the Tcl C library}
sl@0
   173
	}] {
sl@0
   174
sl@0
   175
    test init-4.$count.0 {::errorInfo produced by [unknown]} {
sl@0
   176
	auto_reset
sl@0
   177
	catch {parray a b $arg}
sl@0
   178
	set first $::errorInfo
sl@0
   179
	catch {parray a b $arg}
sl@0
   180
	set second $::errorInfo
sl@0
   181
	string equal $first $second
sl@0
   182
    } 1
sl@0
   183
sl@0
   184
    test init-4.$count.1 {::errorInfo produced by [unknown]} {
sl@0
   185
	auto_reset
sl@0
   186
	namespace eval junk [list array set $arg [list 1 2 3 4]]
sl@0
   187
	trace variable ::junk::$arg r \
sl@0
   188
		"[list error [subst {Variable \"$arg\" is write-only}]] ;# "
sl@0
   189
	catch {parray ::junk::$arg}
sl@0
   190
	set first $::errorInfo
sl@0
   191
	catch {parray ::junk::$arg}
sl@0
   192
	set second $::errorInfo
sl@0
   193
	string equal $first $second
sl@0
   194
    } 1
sl@0
   195
sl@0
   196
    incr count
sl@0
   197
}
sl@0
   198
sl@0
   199
cleanupTests
sl@0
   200
}	;#  End of [interp eval $testInterp]
sl@0
   201
sl@0
   202
# cleanup
sl@0
   203
interp delete $testInterp
sl@0
   204
::tcltest::cleanupTests
sl@0
   205
return
sl@0
   206