Fossil SCM

fossil-scm / test / th1-tcl.test
Blame History Raw 190 lines
1
#
2
# Copyright (c) 2011 D. Richard Hipp
3
#
4
# This program is free software; you can redistribute it and/or
5
# modify it under the terms of the Simplified BSD License (also
6
# known as the "2-Clause License" or "FreeBSD License".)
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but without any warranty; without even the implied warranty of
10
# merchantability or fitness for a particular purpose.
11
#
12
# Author contact information:
13
# [email protected]
14
# http://www.hwaci.com/drh/
15
#
16
############################################################################
17
#
18
# TH1/Tcl integration
19
#
20
21
set path [file dirname [info script]]
22
23
###############################################################################
24
25
fossil test-th-eval "hasfeature tcl"
26
27
if {[normalize_result] ne "1"} {
28
puts "Fossil was not compiled with Tcl support."
29
test_cleanup_then_return
30
}
31
32
###############################################################################
33
34
test_setup
35
36
###############################################################################
37
38
set env(TH1_ENABLE_TCL) 1; # Tcl integration must be enabled for this test.
39
40
###############################################################################
41
42
fossil test-th-render --open-config \
43
[file nativename [file join $path th1-tcl1.txt]]
44
45
test th1-tcl-1 {[regexp -- {^tclReady\(before\) = 0
46
tclReady\(after\) = 1
47
\d+
48
\d+
49
\d+
50
via Tcl invoke
51
4
52
4
53
two words
54
one_word
55
three words now
56
\d+
57
two words
58
4
59
\d+
60
two words
61
4
62
\d+
63
one_word
64
three words now$} [normalize_result]]}
65
66
###############################################################################
67
68
if {[catch {package require sqlite3}] == 0} {
69
fossil test-th-render --open-config \
70
[file nativename [file join $path th1-tcl2.txt]]
71
72
test th1-tcl-2 {[regexp -- {^\d+$} [normalize_result]]}
73
} else {
74
puts stderr "Skipping 'th1-tcl-2', SQLite package for Tcl not available"
75
}
76
77
###############################################################################
78
79
fossil test-th-render --open-config \
80
[file nativename [file join $path th1-tcl3.txt]]
81
82
test th1-tcl-3 {$RESULT eq {<hr><p class="thmainError">ERROR:\
83
invalid command name &quot;bad_command&quot;</p>}}
84
85
###############################################################################
86
87
fossil test-th-render --open-config \
88
[file nativename [file join $path th1-tcl4.txt]]
89
90
test th1-tcl-4 {$RESULT eq {<hr><p class="thmainError">ERROR:\
91
divide by zero</p>}}
92
93
###############################################################################
94
95
fossil test-th-render --open-config \
96
[file nativename [file join $path th1-tcl5.txt]]
97
98
test th1-tcl-5 {$RESULT eq {<hr><p class="thmainError">ERROR:\
99
Tcl command not found: bad_command</p>} || $RESULT eq {<hr><p\
100
class="thmainError">ERROR: invalid command name &quot;bad_command&quot;</p>}}
101
102
###############################################################################
103
104
fossil test-th-render --open-config \
105
[file nativename [file join $path th1-tcl6.txt]]
106
107
test th1-tcl-6 {$RESULT eq {<hr><p class="thmainError">ERROR:\
108
no such command: bad_command</p>}}
109
110
###############################################################################
111
112
fossil test-th-render --open-config \
113
[file nativename [file join $path th1-tcl7.txt]]
114
115
test th1-tcl-7 {$RESULT eq {<hr><p class="thmainError">ERROR:\
116
syntax error in expression: &quot;2**0&quot;</p>}}
117
118
###############################################################################
119
120
fossil test-th-render --open-config \
121
[file nativename [file join $path th1-tcl8.txt]]
122
123
test th1-tcl-8 {$RESULT eq {<hr><p class="thmainError">ERROR:\
124
cannot invoke Tcl command: tailcall</p>} || $RESULT eq {<hr><p\
125
class="thmainError">ERROR: tailcall can only be called from a proc or\
126
lambda</p>} || $RESULT eq {<hr><p class="thmainError">ERROR: This test\
127
requires Tcl 8.6 or higher.</p>}}
128
129
###############################################################################
130
131
fossil test-th-render --open-config \
132
[file nativename [file join $path th1-tcl9.txt]]
133
134
# Under cygwin, the printed name with Usage: strips the extension
135
if { $::is_cygwin && [file extension $fossilexe] eq ".exe" } {
136
set fossilexeref [string range $fossilexe 0 end-4]
137
} else {
138
set fossilexeref $fossilexe
139
}
140
141
test th1-tcl-9 {[string trim $RESULT] eq [list [file tail $fossilexeref] 3 \
142
[list test-th-render --open-config [file nativename [file join $path \
143
th1-tcl9.txt]]]]}
144
145
###############################################################################
146
147
fossil test-th-eval "tclMakeSafe a"
148
test th1-tcl-10 {[normalize_result] eq \
149
{TH_ERROR: wrong # args: should be "tclMakeSafe"}}
150
151
###############################################################################
152
153
fossil test-th-eval "list \[tclIsSafe\] \[tclMakeSafe\] \[tclIsSafe\]"
154
test th1-tcl-11 {[normalize_result] eq {0 {} 1}}
155
156
###############################################################################
157
158
fossil test-th-eval "tclMakeSafe; tclMakeSafe"
159
test th1-tcl-12 {[normalize_result] eq \
160
{TH_ERROR: Tcl interpreter is already 'safe'}}
161
162
###############################################################################
163
164
fossil test-th-eval "tclEval pwd; tclMakeSafe; tclEval pwd"
165
test th1-tcl-13 {[normalize_result] eq {TH_ERROR: invalid command name "pwd"}}
166
167
###############################################################################
168
169
fossil test-th-eval "tclMakeSafe; tclExpr {0 + \[string length \[pwd\]\]}"
170
test th1-tcl-14 {[normalize_result] eq {TH_ERROR: invalid command name "pwd"}}
171
172
###############################################################################
173
174
fossil test-th-eval "tclInvoke pwd; tclMakeSafe; tclInvoke pwd"
175
test th1-tcl-15 {[normalize_result] eq {TH_ERROR: Tcl command not found: pwd}}
176
177
###############################################################################
178
179
fossil test-th-eval "tclMakeSafe; tclEval set x 2"
180
test th1-tcl-16 {[normalize_result] eq {2}}
181
182
###############################################################################
183
184
fossil test-th-eval "tclMakeSafe; tclEval set x 2; tclEval info vars x"
185
test th1-tcl-17 {[normalize_result] eq {x}}
186
187
###############################################################################
188
189
test_cleanup
190

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button