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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [tcl/] [tests/] [source.test] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
# Commands covered:  source
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-1996 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: source.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
test source-1.1 {source command} {
18
    set x "old x value"
19
    set y "old y value"
20
    set z "old z value"
21
    makeFile {
22
        set x 22
23
        set y 33
24
        set z 44
25
    } source.file
26
    source source.file
27
    list $x $y $z
28
} {22 33 44}
29
test source-1.2 {source command} {
30
    makeFile {list result} source.file
31
    source source.file
32
} result
33
 
34
# The mac version of source returns a different result for
35
# the next two tests.
36
 
37
if {$tcl_platform(platform) == "macintosh"} {
38
    set retMsg1 {1 {wrong # args: should be "source fileName" or "source -rsrc name ?fileName?" or "source -rsrcid id ?fileName?"}}
39
    set retMsg2 {1 {bad argument: should be "source fileName" or "source -rsrc name ?fileName?" or "source -rsrcid id ?fileName?"}}
40
} else {
41
    set retMsg1 {1 {wrong # args: should be "source fileName"}}
42
    set retMsg2 {1 {wrong # args: should be "source fileName"}}
43
}
44
test source-2.1 {source error conditions} {
45
    list [catch {source} msg] $msg
46
} $retMsg1
47
test source-2.2 {source error conditions} {
48
    list [catch {source a b} msg] $msg
49
} $retMsg2
50
test source-2.3 {source error conditions} {
51
    makeFile {
52
        set x 146
53
        error "error in sourced file"
54
        set y $x
55
    } source.file
56
    list [catch {source source.file} msg] $msg $errorInfo
57
} {1 {error in sourced file} {error in sourced file
58
    while executing
59
"error "error in sourced file""
60
    (file "source.file" line 3)
61
    invoked from within
62
"source source.file"}}
63
test source-2.4 {source error conditions} {
64
    makeFile {break} source.file
65
    catch {source source.file}
66
} 3
67
test source-2.5 {source error conditions} {
68
    makeFile {continue} source.file
69
    catch {source source.file}
70
} 4
71
test source-2.6 {source error conditions} {
72
    normalizeMsg [list [catch {source _non_existent_} msg] $msg $errorCode]
73
} {1 {couldn't read file "_non_existent_": no such file or directory} {posix enoent {no such file or directory}}}
74
 
75
test source-3.1 {return in middle of source file} {
76
    makeFile {
77
        set x new-x
78
        return allDone
79
        set y new-y
80
    } source.file
81
    set x old-x
82
    set y old-y
83
    set z [source source.file]
84
    list $x $y $z
85
} {new-x old-y allDone}
86
test source-3.2 {return with special code etc.} {
87
    makeFile {
88
        set x new-x
89
        return -code break "Silly result"
90
        set y new-y
91
    } source.file
92
    list [catch {source source.file} msg] $msg
93
} {3 {Silly result}}
94
test source-3.3 {return with special code etc.} {
95
    makeFile {
96
        set x new-x
97
        return -code error "Simulated error"
98
        set y new-y
99
    } source.file
100
    list [catch {source source.file} msg] $msg $errorInfo $errorCode
101
} {1 {Simulated error} {Simulated error
102
    while executing
103
"source source.file"} NONE}
104
test source-3.4 {return with special code etc.} {
105
    makeFile {
106
        set x new-x
107
        return -code error -errorinfo "Simulated errorInfo stuff"
108
        set y new-y
109
    } source.file
110
    list [catch {source source.file} msg] $msg $errorInfo $errorCode
111
} {1 {} {Simulated errorInfo stuff
112
    invoked from within
113
"source source.file"} NONE}
114
test source-3.5 {return with special code etc.} {
115
    makeFile {
116
        set x new-x
117
        return -code error -errorinfo "Simulated errorInfo stuff" \
118
                -errorcode {a b c}
119
        set y new-y
120
    } source.file
121
    list [catch {source source.file} msg] $msg $errorInfo $errorCode
122
} {1 {} {Simulated errorInfo stuff
123
    invoked from within
124
"source source.file"} {a b c}}
125
 
126
# Test for the Macintosh specfic features of the source command
127
test source-4.1 {source error conditions} {macOnly} {
128
    list [catch {source -rsrc _no_exist_} msg] $msg
129
} [list 1 "The resource \"_no_exist_\" could not be loaded from application."]
130
test source-4.2 {source error conditions} {macOnly} {
131
    list [catch {source -rsrcid bad_id} msg] $msg
132
} [list 1 "expected integer but got \"bad_id\""]
133
test source-4.3 {source error conditions} {macOnly} {
134
    list [catch {source -rsrc rsrcName fileName extra} msg] $msg
135
} $retMsg1
136
test source-4.4 {source error conditions} {macOnly} {
137
    list [catch {source non_switch rsrcName} msg] $msg
138
} $retMsg2
139
test source-4.5 {source error conditions} {macOnly} {
140
    list [catch {source -bad_switch argument} msg] $msg
141
} $retMsg2
142
test source-5.1 {source resource files} {macOnly} {
143
    list [catch {source -rsrc rsrcName bad_file} msg] $msg
144
} [list 1 "Error finding the file: \"bad_file\"."]
145
test source-5.2 {source resource files} {macOnly} {
146
    makeFile {return} source.file
147
    list [catch {source -rsrc rsrcName source.file} msg] $msg
148
} [list 1 "Error reading the file: \"source.file\"."]
149
test source-5.3 {source resource files} {macOnly} {
150
    testWriteTextResource -rsrc rsrcName -file rsrc.file {set msg2 ok; return}
151
    set result [catch {source -rsrc rsrcName rsrc.file} msg]
152
    removeFile rsrc.file
153
    list $msg2 $result $msg
154
} [list ok 0 {}]
155
test source-5.4 {source resource files} {macOnly} {
156
    catch {unset msg2}
157
    testWriteTextResource -rsrc fileRsrcName -file rsrc.file {set msg2 ok; return}
158
    source -rsrc fileRsrcName rsrc.file
159
    set result [catch {source -rsrc fileRsrcName} msg]
160
    removeFile rsrc.file
161
    list $msg2 $result $msg
162
} [list ok 1 {The resource "fileRsrcName" could not be loaded from application.}]
163
test source-5.5 {source resource files} {macOnly} {
164
    testWriteTextResource -rsrcid 200 -file rsrc.file {set msg2 hello; set msg3 bye}
165
    set result [catch {source -rsrcid 200 rsrc.file} msg]
166
    removeFile rsrc.file
167
    list $msg2 $result $msg
168
} [list hello 0 bye]
169
test source-5.6 {source resource files} {macOnly} {
170
    testWriteTextResource -rsrcid 200 -file rsrc.file {set msg2 hello; error bad; set msg3 bye}
171
    set result [catch {source -rsrcid 200 rsrc.file} msg]
172
    removeFile rsrc.file
173
    list $msg2 $result $msg
174
} [list hello 1 bad]
175
 
176
test source-6.1 {source is binary ok} {
177
    set x {}
178
    makeFile [list set x "a b\0c"] source.file
179
    source source.file
180
    string length $x
181
} 5
182
 
183
catch {removeFile source.file}
184
 
185
# Generate null final value
186
 
187
concat {}

powered by: WebSVN 2.1.0

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