summaryrefslogtreecommitdiffstats
path: root/tests/compile.test
diff options
context:
space:
mode:
Diffstat (limited to 'tests/compile.test')
-rw-r--r--tests/compile.test781
1 files changed, 154 insertions, 627 deletions
diff --git a/tests/compile.test b/tests/compile.test
index 36b4f3a..7646c12 100644
--- a/tests/compile.test
+++ b/tests/compile.test
@@ -1,24 +1,18 @@
-# This file contains tests for the files tclCompile.c, tclCompCmds.c and
-# tclLiteral.c
+# This file contains tests for the files tclCompile.c, tclCompCmds.c
+# and tclLiteral.c
#
-# This file contains a collection of tests for one or more of the Tcl built-in
-# commands. Sourcing this file into Tcl runs the tests and generates output
-# for errors. No output means no errors were found.
+# This file contains a collection of tests for one or more of the Tcl
+# built-in commands. Sourcing this file into Tcl runs the tests and
+# generates output for errors. No output means no errors were found.
#
-# Copyright © 1997 Sun Microsystems, Inc.
-# Copyright © 1998-1999 Scriptics Corporation.
+# Copyright (c) 1997 by Sun Microsystems, Inc.
+# Copyright (c) 1998-1999 by Scriptics Corporation.
#
-# See the file "license.terms" for information on usage and redistribution of
-# this file, and for a DISCLAIMER OF ALL WARRANTIES.
+# See the file "license.terms" for information on usage and redistribution
+# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
-if {"::tcltest" ni [namespace children]} {
- package require tcltest 2.5
- namespace import -force ::tcltest::*
-}
-
-
-::tcltest::loadTestedCommands
-catch [list package require -exact tcl::test [info patchlevel]]
+package require tcltest 2
+namespace import -force ::tcltest::*
testConstraint exec [llength [info commands exec]]
testConstraint memory [llength [info commands memory]]
@@ -32,11 +26,10 @@ catch {namespace delete test_ns_compile}
catch {unset x}
catch {unset y}
catch {unset a}
-
-test compile-1.1 {TclCompileString: look up cmds in proc ns, not current ns} -setup {
+
+test compile-1.1 {TclCompileString: look up cmds in proc ns, not current ns} {
catch {namespace delete test_ns_compile}
catch {unset x}
-} -body {
set x 123
namespace eval test_ns_compile {
proc set {args} {
@@ -48,70 +41,63 @@ test compile-1.1 {TclCompileString: look up cmds in proc ns, not current ns} -se
}
}
list [test_ns_compile::p] [set x]
-} -result {{123 test_ns_compile::set} {123 test_ns_compile::set}}
+} {{123 test_ns_compile::set} {123 test_ns_compile::set}}
test compile-1.2 {TclCompileString, error result is reset if TclGetLong determines word isn't an integer} {
proc p {x} {info commands 3m}
list [catch {p} msg] $msg
} {1 {wrong # args: should be "p x"}}
-
-test compile-2.1 {TclCompileDollarVar: global scalar name with ::s} -setup {
+test compile-2.1 {TclCompileDollarVar: global scalar name with ::s} {
catch {unset x}
-} -body {
set x 123
- list $::x [expr {"x" in [info globals]}]
-} -result {123 1}
-test compile-2.2 {TclCompileDollarVar: global scalar name with ::s} -setup {
+ list $::x [expr {[lsearch -exact [info globals] x] != 0}]
+} {123 1}
+test compile-2.2 {TclCompileDollarVar: global scalar name with ::s} {
catch {unset y}
-} -body {
proc p {} {
set ::y 789
return $::y
}
- list [p] $::y [expr {"y" in [info globals]}]
-} -result {789 789 1}
-test compile-2.3 {TclCompileDollarVar: global array name with ::s} -setup {
+ list [p] $::y [expr {[lsearch -exact [info globals] y] != 0}]
+} {789 789 1}
+test compile-2.3 {TclCompileDollarVar: global array name with ::s} {
catch {unset a}
-} -body {
set ::a(1) 2
- list $::a(1) [set ::a($::a(1)) 3] $::a(2) [expr {"a" in [info globals]}]
-} -result {2 3 3 1}
-test compile-2.4 {TclCompileDollarVar: global scalar name with ::s} -setup {
+ list $::a(1) [set ::a($::a(1)) 3] $::a(2) [expr {[lsearch -exact [info globals] a] != 0}]
+} {2 3 3 1}
+test compile-2.4 {TclCompileDollarVar: global scalar name with ::s} {
catch {unset a}
-} -body {
proc p {} {
set ::a(1) 1
return $::a($::a(1))
}
- list [p] $::a(1) [expr {"a" in [info globals]}]
-} -result {1 1 1}
-test compile-2.5 {TclCompileDollarVar: global array, called as ${arrName(0)}} -setup {
+ list [p] $::a(1) [expr {[lsearch -exact [info globals] a] != 0}]
+} {1 1 1}
+test compile-2.5 {TclCompileDollarVar: global array, called as ${arrName(0)}} {
catch {unset a}
-} -body {
proc p {} {
global a
set a(1) 1
return ${a(1)}$::a(1)$a(1)
}
- list [p] $::a(1) [expr {"a" in [info globals]}]
-} -result {111 1 1}
+ list [p] $::a(1) [expr {[lsearch -exact [info globals] a] != 0}]
+} {111 1 1}
-test compile-3.1 {TclCompileCatchCmd: only catch cmds with scalar vars are compiled inline} -setup {
+test compile-3.1 {TclCompileCatchCmd: only catch cmds with scalar vars are compiled inline} {
catch {unset a}
-} -body {
set a(1) xyzzyx
proc p {} {
global a
catch {set x 123} a(1)
}
list [p] $a(1)
-} -result {0 123}
+} {0 123}
test compile-3.2 {TclCompileCatchCmd: non-local variables} {
set ::foo 1
proc catch-test {} {
catch {set x 3} ::foo
}
catch-test
- return $::foo
+ set ::foo
} 3
test compile-3.3 {TclCompileCatchCmd: overagressive compiling [bug 219184]} {
proc catch-test {str} {
@@ -119,13 +105,13 @@ test compile-3.3 {TclCompileCatchCmd: overagressive compiling [bug 219184]} {
error BAD
}
catch {catch-test error} ::foo
- return $::foo
+ set ::foo
} {GOOD}
test compile-3.4 {TclCompileCatchCmd: bcc'ed [return] is caught} {
proc foo {} {
set fail [catch {
return 1
- }] ; # {}
+ }] ; # {}
return 2
}
foo
@@ -135,8 +121,8 @@ test compile-3.5 {TclCompileCatchCmd: recover from error, [Bug 705406]} {
catch {
if {[a]} {
if b {}
- }
- }
+ }
+ }
}
list [catch foo msg] $msg
} {0 1}
@@ -170,41 +156,12 @@ test compile-3.6 {TclCompileCatchCmd: error in storing result [Bug 3098302]} {*}
-cleanup {namespace delete catchtest}
}
-test compile-3.7 {TclCompileCatchCmd: error in storing options [Bug 3098302]} {*}{
- -setup {
- namespace eval catchtest {
- variable options1 {}
- }
- trace add variable catchtest::options1 write catchtest::failtrace
- proc catchtest::failtrace {n1 n2 op} {
- return -code error "trace on $n1 fails by request"
- }
- }
- -body {
- proc catchtest::x {} {
- variable options1
- set count 0
- for {set i 0} {$i < 10} {incr i} {
- set status2 [catch {
- set status1 [catch {
- return -code error -level 0 "original failure"
- } result1 options1]
- } result2 options2]
- incr count
- }
- list $count $result2
- }
- catchtest::x
- }
- -result {10 {can't set "options1": trace on options1 fails by request}}
- -cleanup {namespace delete catchtest}
-}
test compile-4.1 {TclCompileForCmd: command substituted test expression} {
set i 0
set j 0
# Should be "forever"
- for {} [expr {$i < 3}] {} {
+ for {} [expr $i < 3] {} {
set j [incr i]
if {$j > 3} break
}
@@ -227,44 +184,30 @@ test compile-5.2 {TclCompileForeachCmd: non-local variables} {
foreach-test
set ::foo
} 3
-test compile-5.3 {TclCompileForeachCmd: [Bug b9b2079e6d]} -setup {
- proc demo {} {
- foreach x y {
- if 1 break else
- }
- }
-} -body {
- demo
-} -cleanup {
- rename demo {}
-} -returnCodes error -result {wrong # args: no script following "else" argument}
-test compile-6.1 {TclCompileSetCmd: global scalar names with ::s} -setup {
+test compile-6.1 {TclCompileSetCmd: global scalar names with ::s} {
catch {unset x}
catch {unset y}
-} -body {
set x 123
proc p {} {
set ::y 789
return $::y
}
- list $::x [expr {"x" in [info globals]}] \
- [p] $::y [expr {"y" in [info globals]}]
-} -result {123 1 789 789 1}
-test compile-6.2 {TclCompileSetCmd: global array names with ::s} -setup {
+ list $::x [expr {[lsearch -exact [info globals] x] != 0}] \
+ [p] $::y [expr {[lsearch -exact [info globals] y] != 0}]
+} {123 1 789 789 1}
+test compile-6.2 {TclCompileSetCmd: global array names with ::s} {
catch {unset a}
-} -body {
set ::a(1) 2
proc p {} {
set ::a(1) 1
return $::a($::a(1))
}
- list $::a(1) [p] [set ::a($::a(1)) 3] $::a(1) [expr {"a" in [info globals]}]
-} -result {2 1 3 3 1}
-test compile-6.3 {TclCompileSetCmd: namespace var names with ::s} -setup {
+ list $::a(1) [p] [set ::a($::a(1)) 3] $::a(1) [expr {[lsearch -exact [info globals] a] != 0}]
+} {2 1 3 3 1}
+test compile-6.3 {TclCompileSetCmd: namespace var names with ::s} {
catch {namespace delete test_ns_compile}
catch {unset x}
-} -body {
namespace eval test_ns_compile {
variable v hello
variable arr
@@ -272,13 +215,13 @@ test compile-6.3 {TclCompileSetCmd: namespace var names with ::s} -setup {
set ::test_ns_compile::arr(1) 123
}
list $::x $::test_ns_compile::arr(1)
-} -result {hello 123}
+} {hello 123}
test compile-7.1 {TclCompileWhileCmd: command substituted test expression} {
set i 0
set j 0
# Should be "forever"
- while [expr {$i < 3}] {
+ while [expr $i < 3] {
set j [incr i]
if {$j > 3} break
}
@@ -286,10 +229,10 @@ test compile-7.1 {TclCompileWhileCmd: command substituted test expression} {
} {4}
test compile-8.1 {CollectArgInfo: binary data} {
- list [catch "string length \x00foo" msg] $msg
+ list [catch "string length \000foo" msg] $msg
} {0 4}
test compile-8.2 {CollectArgInfo: binary data} {
- list [catch "string length foo\x00" msg] $msg
+ list [catch "string length foo\000" msg] $msg
} {0 4}
test compile-8.3 {CollectArgInfo: handle "]" at end of command properly} {
set x ]
@@ -313,45 +256,53 @@ test compile-10.1 {BLACKBOX: exception stack overflow} {
}
} {}
-test compile-11.1 {Tcl_Append*: ensure Tcl_ResetResult is used properly} -body {
- apply {{} {
+test compile-11.1 {Tcl_Append*: ensure Tcl_ResetResult is used properly} {
+ proc p {} {
# shared object - Interp result && Var 'r'
set r [list foobar]
# command that will add error to result
lindex a bogus
- }}
-} -returnCodes error -result {bad index "bogus": must be integer?[+-]integer? or end?[+-]integer?}
-test compile-11.2 {Tcl_Append*: ensure Tcl_ResetResult is used properly} -body {
- apply {{} { set r [list foobar] ; string index a bogus }}
-} -returnCodes error -result {bad index "bogus": must be integer?[+-]integer? or end?[+-]integer?}
+ }
+ list [catch {p} msg] $msg
+} {1 {bad index "bogus": must be integer?[+-]integer? or end?[+-]integer?}}
+test compile-11.2 {Tcl_Append*: ensure Tcl_ResetResult is used properly} {
+ proc p {} { set r [list foobar] ; string index a bogus }
+ list [catch {p} msg] $msg
+} {1 {bad index "bogus": must be integer?[+-]integer? or end?[+-]integer?}}
test compile-11.3 {Tcl_Append*: ensure Tcl_ResetResult is used properly} -body {
- apply {{} { set r [list foobar] ; string index a 0o9 }}
-} -returnCodes error -match glob -result {*invalid octal number*}
-test compile-11.4 {Tcl_Append*: ensure Tcl_ResetResult is used properly} -body {
- apply {{} { set r [list foobar] ; array set var {one two many} }}
-} -returnCodes error -result {list must have an even number of elements}
-test compile-11.5 {Tcl_Append*: ensure Tcl_ResetResult is used properly} -body {
- apply {{} { set r [list foobar] ; incr foo bar baz}}
-} -returnCodes error -result {wrong # args: should be "incr varName ?increment?"}
-test compile-11.6 {Tcl_Append*: ensure Tcl_ResetResult is used properly} -body {
- apply {{} { set r [list foobar] ; incr}}
-} -returnCodes error -result {wrong # args: should be "incr varName ?increment?"}
+ proc p {} { set r [list foobar] ; string index a 0o9 }
+ list [catch {p} msg] $msg
+} -match glob -result {1 {*invalid octal number*}}
+test compile-11.4 {Tcl_Append*: ensure Tcl_ResetResult is used properly} {
+ proc p {} { set r [list foobar] ; array set var {one two many} }
+ list [catch {p} msg] $msg
+} {1 {list must have an even number of elements}}
+test compile-11.5 {Tcl_Append*: ensure Tcl_ResetResult is used properly} {
+ proc p {} { set r [list foobar] ; incr foo bar baz}
+ list [catch {p} msg] $msg
+} {1 {wrong # args: should be "incr varName ?increment?"}}
+test compile-11.6 {Tcl_Append*: ensure Tcl_ResetResult is used properly} {
+ proc p {} { set r [list foobar] ; incr}
+ list [catch {p} msg] $msg
+} {1 {wrong # args: should be "incr varName ?increment?"}}
test compile-11.7 {Tcl_Append*: ensure Tcl_ResetResult is used properly} -body {
- apply {{} { set r [list foobar] ; expr [concat !a] }}
+ proc p {} { set r [list foobar] ; expr !a }
+ p
} -returnCodes error -match glob -result *
test compile-11.8 {Tcl_Append*: ensure Tcl_ResetResult is used properly} -body {
- apply {{} { set r [list foobar] ; expr {!a} }}
+ proc p {} { set r [list foobar] ; expr {!a} }
+ p
} -returnCodes error -match glob -result *
-test compile-11.9 {Tcl_Append*: ensure Tcl_ResetResult is used properly} -body {
- apply {{} { set r [list foobar] ; llength "\{" }}
+test compile-11.9 {Tcl_Append*: ensure Tcl_ResetResult is used properly} {
+ proc p {} { set r [list foobar] ; llength "\{" }
list [catch {p} msg] $msg
-} -returnCodes error -result {unmatched open brace in list}
+} {1 {unmatched open brace in list}}
-#
+#
# Special section for tests of tclLiteral.c
# The following tests check for incorrect memory handling in
-# TclReleaseLiteral. They are only effective when tcl is compiled with
-# TCL_MEM_DEBUG
+# TclReleaseLiteral. They are only effective when tcl is compiled
+# with TCL_MEM_DEBUG
#
# Special test for leak on interp delete [Bug 467523].
test compile-12.1 {testing literal leak on interp delete} -setup {
@@ -362,10 +313,10 @@ test compile-12.1 {testing literal leak on interp delete} -setup {
} -constraints memory -body {
set end [getbytes]
for {set i 0} {$i < 5} {incr i} {
- interp create foo
- foo eval {
+ interp create foo
+ foo eval {
namespace eval bar {}
- }
+ }
interp delete foo
set tmp $end
set end [getbytes]
@@ -375,9 +326,9 @@ test compile-12.1 {testing literal leak on interp delete} -setup {
rename getbytes {}
unset -nocomplain end i tmp leakedBytes
} -result 0
-# Special test for a memory error in a preliminary fix of [Bug 467523]. It
-# requires executing a helpfile. Presumably the child process is used because
-# when this test fails, it crashes.
+# Special test for a memory error in a preliminary fix of [Bug 467523].
+# It requires executing a helpfile. Presumably the child process is
+# used because when this test fails, it crashes.
test compile-12.2 {testing error on literal deletion} -constraints {memory exec} -body {
set sourceFile [makeFile {
for {set i 0} {$i < 5} {incr i} {
@@ -386,7 +337,7 @@ test compile-12.2 {testing error on literal deletion} -constraints {memory exec}
}
puts 0
} source.file]
- exec [interpreter] $sourceFile
+ exec [interpreter] $sourceFile
} -cleanup {
catch {removeFile $sourceFile}
} -result 0
@@ -402,28 +353,29 @@ test compile-12.3 {check for a buffer overrun} -body {
test compile-12.4 {TclCleanupLiteralTable segfault} -body {
# Tcl Bug 1001997
# Here, we're trying to test a case that causes a crash in
- # TclCleanupLiteralTable. The conditions that we're trying to establish
- # are:
- # - TclCleanupLiteralTable is attempting to clean up a bytecode object in
- # the literal table.
- # - The bytecode object in question contains the only reference to another
- # literal.
+ # TclCleanupLiteralTable. The conditions that we're trying to
+ # establish are:
+ # - TclCleanupLiteralTable is attempting to clean up a bytecode
+ # object in the literal table.
+ # - The bytecode object in question contains the only reference
+ # to another literal.
# - The literal in question is in the same hash bucket as the bytecode
# object, and immediately follows it in the chain.
- # Since newly registered literals are added at the FRONT of the bucket
- # chains, and since the bytecode object is registered before its literals,
- # this is difficult to achieve. What we do is:
- # (a) do a [namespace eval] of a string that's calculated to hash into
- # the same bucket as a literal that it contains. In this case, the
- # script and the variable 'bugbug' land in the same bucket.
- # (b) do a [namespace eval] of a string that contains enough literals to
- # force TclRegisterLiteral to rebuild the global literal table. The
- # newly created hash buckets will contain the literals, IN REVERSE
- # ORDER, thus putting the bytecode immediately ahead of 'bugbug' and
- # 'bug4345bug'. The bytecode object will contain the only references
- # to those two literals.
- # (c) Delete the interpreter to invoke TclCleanupLiteralTable and tickle
- # the bug.
+ # Since newly registered literals are added at the FRONT of the
+ # bucket chains, and since the bytecode object is registered before
+ # its literals, this is difficult to achieve. What we do is:
+ # (a) do a [namespace eval] of a string that's calculated to
+ # hash into the same bucket as a literal that it contains.
+ # In this case, the script and the variable 'bugbug'
+ # land in the same bucket.
+ # (b) do a [namespace eval] of a string that contains enough
+ # literals to force TclRegisterLiteral to rebuild the global
+ # literal table. The newly created hash buckets will contain
+ # the literals, IN REVERSE ORDER, thus putting the bytecode
+ # immediately ahead of 'bugbug' and 'bug4345bug'. The bytecode
+ # object will contain the only references to those two literals.
+ # (c) Delete the interpreter to invoke TclCleanupLiteralTable
+ # and tickle the bug.
proc foo {} {
set i [interp create]
$i eval {
@@ -457,8 +409,9 @@ test compile-12.4 {TclCleanupLiteralTable segfault} -body {
rename foo {}
} -result ok
-# Special test for underestimating the maxStackSize required for a compiled
-# command. A failure will cause a segfault in the child process.
+# Special test for underestimating the maxStackSize required for a
+# compiled command. A failure will cause a segfault in the child
+# process.
test compile-13.1 {testing underestimate of maxStackSize in list cmd} {exec} {
set body {set x [list}
for {set i 0} {$i < 3000} {incr i} {
@@ -469,67 +422,6 @@ test compile-13.1 {testing underestimate of maxStackSize in list cmd} {exec} {
list [catch {exec [interpreter] << $script} msg] $msg
} {0 OK}
-# Tests of nested compile (body in body compilation), should not generate stack overflow
-# (with abnormal program termination), bug [fec0c17d39]:
-proc _ti_gencode {} {
- # creates test interpreter on demand with [gencode] generator:
- if {[interp exists ti]} {
- return
- }
- interp create ti
- ti eval {proc gencode {nr {cmd eval} {nl 0}} {
- set code ""
- set e ""; if {$nl} {set e "\n"}
- for {set i 0} {$i < $nr} {incr i} {
- append code "$cmd \{$e"
- }
- append code "lappend result 1$e"
- for {set i 0} {$i < $nr} {incr i} {
- append code "\}$e"
- }
- #puts [format "%% %.40s ... %d bytes" $code [string length $code]]
- return $code
- }}
-}
-test compile-13.2 {TclCompileScript: testing expected nested scripts compilation} -setup {
- _ti_gencode
- interp recursionlimit ti [expr {10000+50}]
- ti eval {set result {}}
-} -body {
- # Test different compilation variants (instructions evalStk, invokeStk, etc),
- # with 1500 (1000 in debug) nested scripts (bodies). If you get SO/SF exceptions on some low-stack
- # boxes or systems, please don't decrease it (either provide a constraint)
- ti eval {foreach cmd {eval "if 1" try catch} {
- set c [gencode [expr {[tcl::build-info debug] ? 1500 : 1000}] $cmd]
- if 1 $c
- }}
- ti eval {set result}
-} -result {1 1 1 1}
-test compile-13.3 {TclCompileScript: testing check of max depth by nested scripts compilation} -setup {
- _ti_gencode
- interp recursionlimit ti 100
- ti eval {set result {}}
-} -body {
- # Test different compilation variants (instructions evalStk, invokeStk, etc),
- # with 500 nested scripts (bodies). It must generate "too many nested compilations"
- # error for any variant we're testing here:
- ti eval {foreach cmd {eval "if 1" try catch} {
- set c [gencode 500 $cmd]
- lappend errors [catch $c e] $e
- }}
- #puts $errors
- # all of nested calls exceed the limit, so must end with "too many nested compilations"
- # (or evaluations, depending on compile method/instruction and "mixed" compile within
- # evaluation), so no one succeeds, the result must be empty:
- ti eval {set result}
-} -result {}
-#
-# clean up:
-if {[interp exists ti]} {
- interp delete ti
-}
-rename _ti_gencode {}
-
# Tests compile-14.* for [Bug 599788] [Bug 0c043a175a47da8c2342]
test compile-14.1 {testing errors in element name; segfault?} {} {
catch {set a([error])} msg1
@@ -540,7 +432,7 @@ test compile-14.1 {testing errors in element name; segfault?} {} {
test compile-14.2 {testing element name "$"} -body {
unset -nocomplain a
set a() 1
- set a(1) 2
+ set a(1) 2
set a($) 3
list [set a()] [set a(1)] [set a($)] [unset a() a(1); lindex [array names a] 0]
} -cleanup {unset a} -result [list 1 2 3 {$}]
@@ -548,25 +440,39 @@ test compile-14.2 {testing element name "$"} -body {
# Tests compile-15.* cover Tcl Bug 633204
test compile-15.1 {proper TCL_RETURN code from [return]} {
- apply {{} {catch return}}
+ proc p {} {catch return}
+ set result [p]
+ rename p {}
+ set result
} 2
test compile-15.2 {proper TCL_RETURN code from [return]} {
- apply {{} {catch {return foo}}}
+ proc p {} {catch {return foo}}
+ set result [p]
+ rename p {}
+ set result
} 2
test compile-15.3 {proper TCL_RETURN code from [return]} {
- apply {{} {catch {return $::tcl_library}}}
+ proc p {} {catch {return $::tcl_library}}
+ set result [p]
+ rename p {}
+ set result
} 2
test compile-15.4 {proper TCL_RETURN code from [return]} {
- apply {{} {catch {return [info library]}}}
+ proc p {} {catch {return [info library]}}
+ set result [p]
+ rename p {}
+ set result
} 2
test compile-15.5 {proper TCL_RETURN code from [return]} {
- apply {{} {catch {set a 1}; return}}
+ proc p {} {catch {set a 1}; return}
+ set result [p]
+ rename p {}
+ set result
} ""
-# Do all tests once byte compiled and once with direct string evaluation
-foreach noComp {0 1} {
+for {set noComp 0} {$noComp <= 1} {incr noComp} {
-if {$noComp} {
+if $noComp {
interp alias {} run {} testevalex
set constraints testevalex
} else {
@@ -636,42 +542,43 @@ test compile-16.17.$noComp {TclCompileScript: word expansion} $constraints {
run {list {*}x y z}
} {x y z}
-# These tests note that expansion can in theory cause the number of arguments
-# to a command to exceed INT_MAX, which is as big as objc is allowed to get.
+# These tests note that expansion can in theory cause the number of
+# arguments to a command to exceed INT_MAX, which is as big as objc
+# is allowed to get.
#
-# In practice, it seems we will run out of memory before we confront this
-# issue. Note that compiled operations run out of memory at smaller objc
-# values than direct string evaluation.
+# In practice, it seems we will run out of memory before we confront
+# this issue. Note that compiled operations run out of memory at
+# smaller objc values than direct string evaluation.
#
-# These tests are constrained as knownBug because they are likely to cause
-# memory allocation panics somewhere, and we don't want panics in the test
-# suite.
+# These tests are constrained as knownBug because they are likely
+# to cause memory allocation panics somewhere, and we don't want
+# panics in the test suite.
#
test compile-16.18.$noComp {TclCompileScript: word expansion} -body {
proc LongList {} {return [lrepeat [expr {1<<10}] x]}
llength [run "list [string repeat {{*}[LongList] } [expr {1<<10}]]"]
} -constraints [linsert $constraints 0 knownBug] -cleanup {
rename LongList {}
-} -result [expr {1<<20}]
+} -returnCodes ok -result [expr {1<<20}]
test compile-16.19.$noComp {TclCompileScript: word expansion} -body {
proc LongList {} {return [lrepeat [expr {1<<11}] x]}
llength [run "list [string repeat {{*}[LongList] } [expr {1<<11}]]"]
} -constraints [linsert $constraints 0 knownBug] -cleanup {
rename LongList {}
-} -result [expr {1<<22}]
+} -returnCodes ok -result [expr {1<<22}]
test compile-16.20.$noComp {TclCompileScript: word expansion} -body {
proc LongList {} {return [lrepeat [expr {1<<12}] x]}
llength [run "list [string repeat {{*}[LongList] } [expr {1<<12}]]"]
} -constraints [linsert $constraints 0 knownBug] -cleanup {
rename LongList {}
-} -result [expr {1<<24}]
+} -returnCodes ok -result [expr {1<<24}]
# This is the one that should cause overflow
test compile-16.21.$noComp {TclCompileScript: word expansion} -body {
proc LongList {} {return [lrepeat [expr {1<<16}] x]}
llength [run "list [string repeat {{*}[LongList] } [expr {1<<16}]]"]
} -constraints [linsert $constraints 0 knownBug] -cleanup {
rename LongList {}
-} -result [expr {wide(1)<<32}]
+} -returnCodes ok -result [expr {wide(1)<<32}]
test compile-16.22.$noComp {
Bug 845412: TclCompileScript: word expansion not mandatory
} -body {
@@ -680,7 +587,7 @@ test compile-16.22.$noComp {
run "ReturnResults [string repeat {x } 260]"
} -constraints $constraints -cleanup {
rename ReturnResults {}
-} -result [string trim [string repeat {x } 260]]
+} -returnCodes ok -result [string trim [string repeat {x } 260]]
test compile-16.23.$noComp {
Bug 1032805: defer parse error until run time
} -constraints $constraints -body {
@@ -692,23 +599,16 @@ test compile-16.23.$noComp {
}
} -cleanup {
namespace delete x
-} -result {syntax {}{}}
+} -returnCodes ok -result {syntax {}{}}
test compile-16.24.$noComp {
Bug 1638414: bad list constant as first expanded term
} -constraints $constraints -body {
run "{*}\"\{foo bar\""
} -returnCodes error -result {unmatched open brace in list}
-test compile-16.25.$noComp {TclCompileScript: word expansion, naked backslashes} $constraints {
- run {list {*}{a \n b}}
-} {a {
-} b}
-test compile-16.26.$noComp {TclCompileScript: word expansion, protected backslashes} $constraints {
- run {list {*}{a {\n} b}}
-} {a {\n} b}
} ;# End of noComp loop
-# These tests are messy because it wrecks the interpreter it runs in! They
-# demonstrate issues arising from [FRQ 1101710]
+# These tests are messy because it wrecks the interpreter it runs in!
+# They demonstrate issues arising from [FRQ 1101710]
test compile-17.1 {Command interpretation binding for compiled code} -constraints knownBug -setup {
set i [interp create]
} -body {
@@ -738,374 +638,6 @@ test compile-17.2 {Command interpretation binding for non-compiled code} -setup
interp delete $i
} -result substituted
-# This tests the supported parts of the unsupported [disassemble] command. It
-# does not check the format of disassembled bytecode though; that's liable to
-# change without warning.
-
-set disassemblables [linsert [join {
- constructor destructor lambda method objmethod proc script
-} ", "] end-1 or]
-test compile-18.1 {disassembler - basics} -returnCodes error -body {
- tcl::unsupported::disassemble
-} -match glob -result {wrong # args: should be "*"}
-test compile-18.2 {disassembler - basics} -returnCodes error -body {
- tcl::unsupported::disassemble ?
-} -result "bad type \"?\": must be $disassemblables"
-test compile-18.3 {disassembler - basics} -returnCodes error -body {
- tcl::unsupported::disassemble lambda
-} -match glob -result {wrong # args: should be "* lambda lambdaTerm"}
-test compile-18.4 {disassembler - basics} -returnCodes error -body {
- tcl::unsupported::disassemble lambda \{
-} -result "can't interpret \"\{\" as a lambda expression"
-test compile-18.5 {disassembler - basics} -body {
- # Allow any string: the result format is not defined anywhere!
- tcl::unsupported::disassemble lambda {{} {}}
-} -match glob -result *
-test compile-18.6 {disassembler - basics} -returnCodes error -body {
- tcl::unsupported::disassemble proc
-} -match glob -result {wrong # args: should be "* proc procName"}
-test compile-18.7 {disassembler - basics} -returnCodes error -body {
- tcl::unsupported::disassemble proc nosuchproc
-} -result {"nosuchproc" isn't a procedure}
-test compile-18.8 {disassembler - basics} -setup {
- proc chewonthis {} {}
-} -body {
- # Allow any string: the result format is not defined anywhere!
- tcl::unsupported::disassemble proc chewonthis
-} -cleanup {
- rename chewonthis {}
-} -match glob -result *
-test compile-18.9 {disassembler - basics} -returnCodes error -body {
- tcl::unsupported::disassemble script
-} -match glob -result {wrong # args: should be "* script script"}
-test compile-18.10 {disassembler - basics} -body {
- # Allow any string: the result format is not defined anywhere!
- tcl::unsupported::disassemble script {}
-} -match glob -result *
-test compile-18.11 {disassembler - basics} -returnCodes error -body {
- tcl::unsupported::disassemble method
-} -match glob -result {wrong # args: should be "* method className methodName"}
-test compile-18.12 {disassembler - basics} -returnCodes error -body {
- tcl::unsupported::disassemble method nosuchclass foo
-} -result {nosuchclass does not refer to an object}
-test compile-18.13 {disassembler - basics} -returnCodes error -setup {
- oo::object create justanobject
-} -body {
- tcl::unsupported::disassemble method justanobject foo
-} -cleanup {
- justanobject destroy
-} -result {"justanobject" is not a class}
-test compile-18.14 {disassembler - basics} -returnCodes error -body {
- tcl::unsupported::disassemble method oo::object nosuchmethod
-} -result {unknown method "nosuchmethod"}
-test compile-18.15 {disassembler - basics} -setup {
- oo::class create foo {method bar {} {}}
-} -body {
- # Allow any string: the result format is not defined anywhere!
- tcl::unsupported::disassemble method foo bar
-} -cleanup {
- foo destroy
-} -match glob -result *
-test compile-18.16 {disassembler - basics} -returnCodes error -body {
- tcl::unsupported::disassemble objmethod
-} -match glob -result {wrong # args: should be "* objmethod objectName methodName"}
-test compile-18.17 {disassembler - basics} -returnCodes error -body {
- tcl::unsupported::disassemble objmethod nosuchobject foo
-} -result {nosuchobject does not refer to an object}
-test compile-18.18 {disassembler - basics} -returnCodes error -body {
- tcl::unsupported::disassemble objmethod oo::object nosuchmethod
-} -result {unknown method "nosuchmethod"}
-test compile-18.19 {disassembler - basics} -setup {
- oo::object create foo
- oo::objdefine foo {method bar {} {}}
-} -body {
- # Allow any string: the result format is not defined anywhere!
- tcl::unsupported::disassemble objmethod foo bar
-} -cleanup {
- foo destroy
-} -match glob -result *
-# There never was a compile-18.20.
-# The keys of the dictionary produced by [getbytecode] are defined.
-set bytecodekeys {literals variables exception instructions auxiliary commands script namespace stackdepth exceptdepth}
-test compile-18.21 {disassembler - basics} -returnCodes error -body {
- tcl::unsupported::getbytecode
-} -match glob -result {wrong # args: should be "*"}
-test compile-18.22 {disassembler - basics} -returnCodes error -body {
- tcl::unsupported::getbytecode ?
-} -result "bad type \"?\": must be $disassemblables"
-test compile-18.23 {disassembler - basics} -returnCodes error -body {
- tcl::unsupported::getbytecode lambda
-} -match glob -result {wrong # args: should be "* lambda lambdaTerm"}
-test compile-18.24 {disassembler - basics} -returnCodes error -body {
- tcl::unsupported::getbytecode lambda \{
-} -result "can't interpret \"\{\" as a lambda expression"
-test compile-18.25 {disassembler - basics} -body {
- dict keys [tcl::unsupported::getbytecode lambda {{} {}}]
-} -result "$bytecodekeys initiallinenumber sourcefile"
-test compile-18.26 {disassembler - basics} -returnCodes error -body {
- tcl::unsupported::getbytecode proc
-} -match glob -result {wrong # args: should be "* proc procName"}
-test compile-18.27 {disassembler - basics} -returnCodes error -body {
- tcl::unsupported::getbytecode proc nosuchproc
-} -result {"nosuchproc" isn't a procedure}
-test compile-18.28 {disassembler - basics} -setup {
- proc chewonthis {} {}
-} -body {
- dict keys [tcl::unsupported::getbytecode proc chewonthis]
-} -cleanup {
- rename chewonthis {}
-} -result "$bytecodekeys initiallinenumber sourcefile"
-test compile-18.28.1 {disassembler - tricky bit} -setup {
- eval [list proc chewonthis {} {}]
-} -body {
- dict keys [tcl::unsupported::getbytecode proc chewonthis]
-} -cleanup {
- rename chewonthis {}
-} -result $bytecodekeys
-test compile-18.28.2 {disassembler - tricky bit} -setup {
- eval {proc chewonthis {} {}}
-} -body {
- dict keys [tcl::unsupported::getbytecode proc chewonthis]
-} -cleanup {
- rename chewonthis {}
-} -result "$bytecodekeys initiallinenumber sourcefile"
-test compile-18.28.3 {disassembler - tricky bit} -setup {
- proc Proc {n a b} {
- proc $n $a $b
- }
- Proc chewonthis {} {}
-} -body {
- dict keys [tcl::unsupported::getbytecode proc chewonthis]
-} -cleanup {
- rename Proc {}
- rename chewonthis {}
-} -result $bytecodekeys
-test compile-18.28.4 {disassembler - tricky bit} -setup {
- proc Proc {n a b} {
- tailcall proc $n $a $b
- }
- Proc chewonthis {} {}
-} -body {
- dict keys [tcl::unsupported::getbytecode proc chewonthis]
-} -cleanup {
- rename Proc {}
- rename chewonthis {}
-} -result "$bytecodekeys initiallinenumber sourcefile"
-test compile-18.29 {disassembler - basics} -returnCodes error -body {
- tcl::unsupported::getbytecode script
-} -match glob -result {wrong # args: should be "* script script"}
-test compile-18.30 {disassembler - basics} -body {
- dict keys [tcl::unsupported::getbytecode script {}]
-} -result $bytecodekeys
-test compile-18.31 {disassembler - basics} -returnCodes error -body {
- tcl::unsupported::getbytecode method
-} -match glob -result {wrong # args: should be "* method className methodName"}
-test compile-18.32 {disassembler - basics} -returnCodes error -body {
- tcl::unsupported::getbytecode method nosuchclass foo
-} -result {nosuchclass does not refer to an object}
-test compile-18.33 {disassembler - basics} -returnCodes error -setup {
- oo::object create justanobject
-} -body {
- tcl::unsupported::getbytecode method justanobject foo
-} -cleanup {
- justanobject destroy
-} -result {"justanobject" is not a class}
-test compile-18.34 {disassembler - basics} -returnCodes error -body {
- tcl::unsupported::getbytecode method oo::object nosuchmethod
-} -result {unknown method "nosuchmethod"}
-test compile-18.35 {disassembler - basics} -setup {
- oo::class create foo {method bar {} {}}
-} -body {
- dict keys [tcl::unsupported::getbytecode method foo bar]
-} -cleanup {
- foo destroy
-} -result "$bytecodekeys initiallinenumber sourcefile"
-test compile-18.36 {disassembler - basics} -returnCodes error -body {
- tcl::unsupported::getbytecode objmethod
-} -match glob -result {wrong # args: should be "* objmethod objectName methodName"}
-test compile-18.37 {disassembler - basics} -returnCodes error -body {
- tcl::unsupported::getbytecode objmethod nosuchobject foo
-} -result {nosuchobject does not refer to an object}
-test compile-18.38 {disassembler - basics} -returnCodes error -body {
- tcl::unsupported::getbytecode objmethod oo::object nosuchmethod
-} -result {unknown method "nosuchmethod"}
-test compile-18.39 {disassembler - basics} -setup {
- oo::object create foo
- oo::objdefine foo {method bar {} {}}
-} -body {
- dict keys [tcl::unsupported::getbytecode objmethod foo bar]
-} -cleanup {
- foo destroy
-} -result "$bytecodekeys initiallinenumber sourcefile"
-test compile-18.40 {disassembler - basics} -returnCodes error -body {
- tcl::unsupported::disassemble constructor
-} -match glob -result {wrong # args: should be "* constructor className"}
-test compile-18.41 {disassembler - basics} -returnCodes error -body {
- tcl::unsupported::disassemble constructor nosuchclass
-} -result {nosuchclass does not refer to an object}
-test compile-18.42 {disassembler - basics} -returnCodes error -setup {
- oo::object create justanobject
-} -body {
- tcl::unsupported::disassemble constructor justanobject
-} -cleanup {
- justanobject destroy
-} -result {"justanobject" is not a class}
-test compile-18.43 {disassembler - basics} -returnCodes error -setup {
- oo::class create constructorless
-} -body {
- tcl::unsupported::disassemble constructor constructorless
-} -cleanup {
- constructorless destroy
-} -result {"constructorless" has no defined constructor}
-test compile-18.44 {disassembler - basics} -setup {
- oo::class create foo {constructor {} {set x 1}}
-} -body {
- # Allow any string: the result format is not defined anywhere!
- tcl::unsupported::disassemble constructor foo
-} -cleanup {
- foo destroy
-} -match glob -result *
-test compile-18.45 {disassembler - basics} -returnCodes error -body {
- tcl::unsupported::getbytecode constructor
-} -match glob -result {wrong # args: should be "* constructor className"}
-test compile-18.46 {disassembler - basics} -returnCodes error -body {
- tcl::unsupported::getbytecode constructor nosuchobject
-} -result {nosuchobject does not refer to an object}
-test compile-18.47 {disassembler - basics} -returnCodes error -setup {
- oo::class create constructorless
-} -body {
- tcl::unsupported::getbytecode constructor constructorless
-} -cleanup {
- constructorless destroy
-} -result {"constructorless" has no defined constructor}
-test compile-18.48 {disassembler - basics} -setup {
- oo::class create foo {constructor {} {set x 1}}
-} -body {
- dict keys [tcl::unsupported::getbytecode constructor foo]
-} -cleanup {
- foo destroy
-} -result "$bytecodekeys"
-# There is no compile-18.49
-test compile-18.50 {disassembler - basics} -returnCodes error -body {
- tcl::unsupported::disassemble destructor
-} -match glob -result {wrong # args: should be "* destructor className"}
-test compile-18.51 {disassembler - basics} -returnCodes error -body {
- tcl::unsupported::disassemble destructor nosuchclass
-} -result {nosuchclass does not refer to an object}
-test compile-18.52 {disassembler - basics} -returnCodes error -setup {
- oo::object create justanobject
-} -body {
- tcl::unsupported::disassemble destructor justanobject
-} -cleanup {
- justanobject destroy
-} -result {"justanobject" is not a class}
-test compile-18.53 {disassembler - basics} -returnCodes error -setup {
- oo::class create constructorless
-} -body {
- tcl::unsupported::disassemble destructor constructorless
-} -cleanup {
- constructorless destroy
-} -result {"constructorless" has no defined destructor}
-test compile-18.54 {disassembler - basics} -setup {
- oo::class create foo {destructor {set x 1}}
-} -body {
- # Allow any string: the result format is not defined anywhere!
- tcl::unsupported::disassemble destructor foo
-} -cleanup {
- foo destroy
-} -match glob -result *
-test compile-18.55 {disassembler - basics} -returnCodes error -body {
- tcl::unsupported::getbytecode destructor
-} -match glob -result {wrong # args: should be "* destructor className"}
-test compile-18.56 {disassembler - basics} -returnCodes error -body {
- tcl::unsupported::getbytecode destructor nosuchobject
-} -result {nosuchobject does not refer to an object}
-test compile-18.57 {disassembler - basics} -returnCodes error -setup {
- oo::class create constructorless
-} -body {
- tcl::unsupported::getbytecode destructor constructorless
-} -cleanup {
- constructorless destroy
-} -result {"constructorless" has no defined destructor}
-test compile-18.58 {disassembler - basics} -setup {
- oo::class create foo {destructor {set x 1}}
-} -body {
- dict keys [tcl::unsupported::getbytecode destructor foo]
-} -cleanup {
- foo destroy
-} -result "$bytecodekeys"
-
-test compile-19.0 {Bug 3614102: reset stack housekeeping} -body {
- # This will panic in a --enable-symbols=compile build, unless bug is fixed.
- apply {{} {list [if 1]}}
-} -returnCodes error -match glob -result *
-
-test compile-20.1 {ensure there are no infinite loops in optimizing} {
- tcl::unsupported::disassemble script {
- while 1 {
- return -code continue -level 0
- }
- }
- return
-} {}
-test compile-20.2 {ensure there are no infinite loops in optimizing} {
- tcl::unsupported::disassemble script {
- while 1 {
- while 1 {
- return -code break -level 0
- }
- }
- }
- return
-} {}
-
-test compile-21.1 {stack balance management} {
- apply {{} {
- set result {}
- while 1 {
- lappend result a
- lappend result [list b [break]]
- lappend result c
- }
- return $result
- }}
-} a
-test compile-21.2 {stack balance management} {
- apply {{} {
- set result {}
- while {[incr i] <= 10} {
- lappend result $i
- lappend result [list b [continue] c]
- lappend result c
- }
- return $result
- }}
-} {1 2 3 4 5 6 7 8 9 10}
-test compile-21.3 {stack balance management} {
- apply {args {
- set result {}
- while 1 {
- lappend result a
- lappend result [concat {*}$args [break]]
- lappend result c
- }
- return $result
- }} P Q R S T
-} a
-test compile-21.4 {stack balance management} {
- apply {args {
- set result {}
- while {[incr i] <= 10} {
- lappend result $i
- lappend result [concat {*}$args [continue] c]
- lappend result c
- }
- return $result
- }} P Q R S T
-} {1 2 3 4 5 6 7 8 9 10}
-
-# TODO sometime - check that bytecode from tbcload is *not* disassembled.
-
# cleanup
catch {rename p ""}
catch {namespace delete test_ns_compile}
@@ -1114,8 +646,3 @@ catch {unset y}
catch {unset a}
::tcltest::cleanupTests
return
-
-# Local Variables:
-# mode: tcl
-# fill-column: 78
-# End: