OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [tcl/] [tests/] [rename.test] - Blame information for rev 1774

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
# Commands covered:  rename
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
#
10
# See the file "license.terms" for information on usage and redistribution
11
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
12
#
13
# RCS: @(#) $Id: rename.test,v 1.1.1.1 2002-01-16 10:25:36 markom Exp $
14
 
15
if {[string compare test [info procs test]] == 1} then {source defs}
16
 
17
# Must eliminate the "unknown" command while the test is running,
18
# especially if the test is being run in a program with its
19
# own special-purpose unknown command.
20
 
21
catch {rename unknown unknown.old}
22
 
23
catch {rename r2 {}}
24
proc r1 {} {return "procedure r1"}
25
rename r1 r2
26
test rename-1.1 {simple renaming} {
27
    r2
28
} {procedure r1}
29
test rename-1.2 {simple renaming} {
30
    list [catch r1 msg] $msg
31
} {1 {invalid command name "r1"}}
32
rename r2 {}
33
test rename-1.3 {simple renaming} {
34
    list [catch r2 msg] $msg
35
} {1 {invalid command name "r2"}}
36
 
37
# The test below is tricky because it renames a built-in command.
38
# It's possible that the test procedure uses this command, so must
39
# restore the command before calling test again.
40
 
41
rename list l.new
42
set a [catch list msg1]
43
set b [l.new a b c]
44
rename l.new list
45
set c [catch l.new msg2]
46
set d [list 111 222]
47
test rename-2.1 {renaming built-in command} {
48
    list $a $msg1 $b $c $msg2 $d
49
} {1 {invalid command name "list"} {a b c} 1 {invalid command name "l.new"} {111 222}}
50
 
51
test rename-3.1 {error conditions} {
52
    list [catch {rename r1} msg] $msg $errorCode
53
} {1 {wrong # args: should be "rename oldName newName"} NONE}
54
test rename-3.2 {error conditions} {
55
    list [catch {rename r1 r2 r3} msg] $msg $errorCode
56
} {1 {wrong # args: should be "rename oldName newName"} NONE}
57
test rename-3.3 {error conditions} {
58
    proc r1 {} {}
59
    proc r2 {} {}
60
    list [catch {rename r1 r2} msg] $msg
61
} {1 {can't rename to "r2": command already exists}}
62
test rename-3.4 {error conditions} {
63
    catch {rename r1 {}}
64
    catch {rename r2 {}}
65
    list [catch {rename r1 r2} msg] $msg
66
} {1 {can't rename "r1": command doesn't exist}}
67
test rename-3.5 {error conditions} {
68
    catch {rename _non_existent_command {}}
69
    list [catch {rename _non_existent_command {}} msg] $msg
70
} {1 {can't delete "_non_existent_command": command doesn't exist}}
71
 
72
catch {rename unknown {}}
73
catch {rename unknown.old unknown}
74
 
75
if {[info command testdel] == "testdel"} {
76
    test rename-4.1 {reentrancy issues with command deletion and renaming} {
77
        set x {}
78
        testdel {} foo {lappend x deleted; rename bar {}; lappend x [info command bar]}
79
        rename foo bar
80
        lappend x |
81
        rename bar {}
82
        set x
83
    } {| deleted {}}
84
    test rename-4.2 {reentrancy issues with command deletion and renaming} {
85
        set x {}
86
        testdel {} foo {lappend x deleted; rename foo bar}
87
        rename foo {}
88
        set x
89
    } {deleted}
90
    test rename-4.3 {reentrancy issues with command deletion and renaming} {
91
        set x {}
92
        testdel {} foo {lappend x deleted; testdel {} foo {lappend x deleted2}}
93
        rename foo {}
94
        lappend x |
95
        rename foo {}
96
        set x
97
    } {deleted | deleted2}
98
    test rename-4.4 {reentrancy issues with command deletion and renaming} {
99
        set x {}
100
        testdel {} foo {lappend x deleted; rename foo bar}
101
        rename foo {}
102
        lappend x | [info command bar]
103
    } {deleted | {}}
104
    test rename-4.5 {reentrancy issues with command deletion and renaming} {
105
        set env(value) before
106
        interp create foo
107
        testdel foo cmd {set env(value) deleted}
108
        interp delete foo
109
        set env(value)
110
    } {deleted}
111
    test rename-4.6 {reentrancy issues with command deletion and renaming} {
112
        proc kill args {
113
            interp delete foo
114
        }
115
        set env(value) before
116
        interp create foo
117
        foo alias kill kill
118
        testdel foo cmd {set env(value) deleted; kill}
119
        list [catch {foo eval {rename cmd {}}} msg] $msg $env(value)
120
    } {0 {} deleted}
121
    test rename-4.7 {reentrancy issues with command deletion and renaming} {
122
        proc kill args {
123
            interp delete foo
124
        }
125
        set env(value) before
126
        interp create foo
127
        foo alias kill kill
128
        testdel foo cmd {set env(value) deleted; kill}
129
        list [catch {interp delete foo} msg] $msg $env(value)
130
    } {0 {} deleted}
131
}
132
 
133
# Save the unknown procedure which is modified by the following test.
134
 
135
catch {rename unknown unknown.old}
136
 
137
test rename-5.1 {repeated rename deletion and redefinition of same command} {
138
    set SAVED_UNKNOWN "proc unknown "
139
    append SAVED_UNKNOWN "\{[info args unknown.old]\} "
140
    append SAVED_UNKNOWN "\{[info body unknown.old]\}"
141
 
142
    for {set i 0} {$i < 10} {incr i} {
143
        eval $SAVED_UNKNOWN
144
        tcl_wordBreakBefore "" 0
145
        rename tcl_wordBreakBefore {}
146
        rename unknown {}
147
    }
148
} {}
149
 
150
catch {rename unknown {}}
151
catch {rename unknown.old unknown}
152
 
153
 
154
test rename-6.1 {old code invalidated (epoch incremented) when cmd with compile proc is renamed } {
155
    proc x {} {
156
        set a 123
157
        set b [incr a]
158
    }
159
    x
160
    rename incr incr.old
161
    proc incr {} {puts "new incr called!"}
162
    catch {x} msg
163
    set msg
164
} {called "incr" with too many arguments}
165
 
166
catch {rename incr {}}
167
catch {rename incr.old incr}
168
 
169
# Make the file return an empty string (cleaner.).
170
 
171
set x ""
172
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.