summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2023-08-04 19:06:56 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2023-08-04 19:06:56 (GMT)
commitfa96cac29f10b30e6fb499800598cc35ba2a19d3 (patch)
tree0786f1348044b9dee6e871de4d2399f36f596c91 /tests
parentb8117727ea202b0bdb4566ec994df5a4faaf93d8 (diff)
parentaeaba6971a969d6e628e5fd35f4cfca4fb2c683b (diff)
downloadtcl-fa96cac29f10b30e6fb499800598cc35ba2a19d3.zip
tcl-fa96cac29f10b30e6fb499800598cc35ba2a19d3.tar.gz
tcl-fa96cac29f10b30e6fb499800598cc35ba2a19d3.tar.bz2
Merge 8.7
Diffstat (limited to 'tests')
-rw-r--r--tests/chanio.test10
-rw-r--r--tests/io.test75
-rw-r--r--tests/listObj.test33
3 files changed, 87 insertions, 31 deletions
diff --git a/tests/chanio.test b/tests/chanio.test
index c5d3aca..f3461f0 100644
--- a/tests/chanio.test
+++ b/tests/chanio.test
@@ -1098,7 +1098,7 @@ test chan-io-7.3 {FilterInputBytes: split up character at EOF} -setup {
chan puts -nonewline $f "1234567890123\x82\x4F\x82\x50\x82"
chan close $f
set f [open $path(test1)]
- chan configure $f -encoding shiftjis
+ chan configure $f -encoding shiftjis -profile tcl8
lappend x [chan gets $f line] $line
lappend x [chan tell $f] [testchannel inputbuffered $f] [chan eof $f]
lappend x [chan gets $f line] $line
@@ -6875,7 +6875,7 @@ test chan-io-52.9 {TclCopyChannel & encodings} {fcopy} {
[file size $path(utf8-fcopy.txt)] \
[file size $path(utf8-rp.txt)]
} {3 5 5}
-test chan-io-52.10 {TclCopyChannel & encodings} {fcopy notWinCI} {
+test chan-io-52.10 {TclCopyChannel & encodings} -constraints {fcopy notWinCI} -body {
# encoding to binary (=> implies that the internal utf-8 is written)
set in [open $path(kyrillic.txt) r]
set out [open $path(utf8-fcopy.txt) w]
@@ -6883,10 +6883,12 @@ test chan-io-52.10 {TclCopyChannel & encodings} {fcopy notWinCI} {
# -translation binary is also -encoding binary
chan configure $out -translation binary
chan copy $in $out
+ file size $path(utf8-fcopy.txt)
+} -cleanup {
chan close $in
chan close $out
- file size $path(utf8-fcopy.txt)
-} 5
+ unset in out
+} -result 5
test chan-io-52.11 {TclCopyChannel & encodings} -setup {
set f [open $path(utf8-fcopy.txt) w]
fconfigure $f -encoding utf-8 -translation lf
diff --git a/tests/io.test b/tests/io.test
index ca636ce..6d985ee 100644
--- a/tests/io.test
+++ b/tests/io.test
@@ -1555,20 +1555,34 @@ test io-12.9 {ReadChars: multibyte chars split} -body {
puts -nonewline $f [string repeat a 9]\xC2
close $f
set f [open $path(test1)]
- fconfigure $f -encoding utf-8 -buffersize 10
+ fconfigure $f -encoding utf-8 -profile tcl8 -buffersize 10
set in [read $f]
- close $f
+ read $f
scan [string index $in end] %c
} -cleanup {
catch {close $f}
} -result 194
-test io-12.10 {ReadChars: multibyte chars split} -body {
+test io-12.11 {ReadChars: multibyte chars split} -body {
+ set f [open $path(test1) w]
+ fconfigure $f -translation binary
+ puts -nonewline $f [string repeat a 9]\xC2
+ close $f
+ set f [open $path(test1)]
+ fconfigure $f -encoding utf-8 -profile strict -buffersize 10
+ set in [read $f]
+ close $f
+ scan [string index $in end] %c
+} -cleanup {
+ catch {close $f}
+} -returnCodes 1 -match glob -result {error reading "file*":\
+ invalid or incomplete multibyte or wide character}
+test io-12.12 {ReadChars: multibyte chars split} -body {
set f [open $path(test1) w]
fconfigure $f -translation binary
puts -nonewline $f [string repeat a 9]\xC2
close $f
set f [open $path(test1)]
- fconfigure $f -encoding utf-8 -buffersize 11
+ fconfigure $f -encoding utf-8 -profile tcl8 -buffersize 11
set in [read $f]
close $f
scan [string index $in end] %c
@@ -5765,7 +5779,7 @@ test io-39.21 {Tcl_SetChannelOption, setting read mode independently} \
close $s2
set modes
} {auto crlf}
-test io-39.22 {Tcl_SetChannelOption, invariance} {unix} {
+test io-39.22 {Tcl_SetChannelOption, invariance} -constraints {unix} -body {
file delete $path(test1)
set f1 [open $path(test1) w+]
set l ""
@@ -5776,8 +5790,8 @@ test io-39.22 {Tcl_SetChannelOption, invariance} {unix} {
lappend l [fconfigure $f1 -eofchar]
close $f1
set l
-} {{{} {}} {O G} {D D}}
-test io-39.22a {Tcl_SetChannelOption, invariance} {
+} -result {{{} {}} {O G} {D D}}
+test io-39.22a {Tcl_SetChannelOption, invariance} -body {
file delete $path(test1)
set f1 [open $path(test1) w+]
set l [list]
@@ -5788,7 +5802,7 @@ test io-39.22a {Tcl_SetChannelOption, invariance} {
lappend l [list [catch {fconfigure $f1 -eofchar {1 2 3}} msg] $msg]
close $f1
set l
-} {{O G} {D D} {1 {bad value for -eofchar: should be a list of zero, one, or two elements}}}
+} -result {{O G} {D D} {1 {bad value for -eofchar: should be a list of zero, one, or two elements}}}
test io-39.23 {Tcl_GetChannelOption, server socket is not readable or
writable, it should still have valid -eofchar and -translation options } {
set l [list]
@@ -6367,7 +6381,7 @@ test io-47.3 {deleting fileevent on interpreter delete} {testfevent fileevent} {
fileevent $f readable {script 1}
fileevent $f2 readable {script 2}
testfevent cmd "fileevent $f3 readable {script 3}
- fileevent $f4 readable {script 4}"
+ fileevent $f4 readable {script 4}"
testfevent delete
set x [list [fileevent $f readable] [fileevent $f2 readable] \
[fileevent $f3 readable] [fileevent $f4 readable]]
@@ -7435,7 +7449,7 @@ test io-52.9 {TclCopyChannel & encodings} {fcopy} {
[file size $path(utf8-fcopy.txt)] \
[file size $path(utf8-rp.txt)]
} {3 5 5}
-test io-52.10 {TclCopyChannel & encodings} {fcopy notWinCI} {
+test io-52.10 {TclCopyChannel & encodings} -constraints {fcopy notWinCI} -body {
# encoding to binary (=> implies that the
# internal utf-8 is written)
@@ -7447,11 +7461,12 @@ test io-52.10 {TclCopyChannel & encodings} {fcopy notWinCI} {
fconfigure $out -translation binary
fcopy $in $out
- close $in
- close $out
file size $path(utf8-fcopy.txt)
-} 5
+} -cleanup {
+ close $in
+ close $out
+} -result 5
test io-52.11 {TclCopyChannel & encodings} -setup {
set out [open $path(utf8-fcopy.txt) w]
fconfigure $out -encoding utf-8 -translation lf
@@ -9213,6 +9228,7 @@ test io-75.7 {
} -cleanup {
close $f
removeFile io-75.7
+ unset msg f fn
} -match glob -result {1 {error reading "file*":\
invalid or incomplete multibyte or wide character}}
@@ -9250,17 +9266,16 @@ test io-75.8.eoflater {invalid utf-8 encoding eof handling (-profile strict)} -s
fconfigure $f -encoding utf-8 -buffering none -eofchar \x1A \
-translation lf -profile strict
} -body {
- set res [list [catch {read $f} cres] [eof $f]]
+ set res [list [catch {read $f} msg] [eof $f]]
chan configure $f -encoding iso8859-1
lappend res [read $f 1]
chan configure $f -encoding utf-8
- catch {read $f 1} cres
- lappend res $cres
- close $f
- set res
+ lappend res [catch {read $f 1} msg] $msg
} -cleanup {
+ close $f
removeFile io-75.8
-} -match glob -result "1 0 \x81 {error reading \"*\":\
+ unset res msg fn f
+} -match glob -result "1 0 \x81 1 {error reading \"*\":\
invalid or incomplete multibyte or wide character}"
@@ -9269,7 +9284,6 @@ test io-strict-multibyte-eof {
See issue 25cdcb7e8fb381fb
} -setup {
- set res {}
set chan [file tempfile];
fconfigure $chan -encoding binary
puts -nonewline $chan \x81\x1A
@@ -9277,10 +9291,10 @@ test io-strict-multibyte-eof {
seek $chan 0
chan configure $chan -encoding utf-8 -profile strict
} -body {
- list [catch {read $chan 1} cres] $cres
+ list [catch {read $chan 1} msg] $msg
} -cleanup {
close $chan
- unset res
+ unset msg chan
} -match glob -result {1 {error reading "*":\
invalid or incomplete multibyte or wide character}}
@@ -9296,6 +9310,7 @@ test io-75.9 {unrepresentable character write passes and is replaced by ?} -setu
} -cleanup {
close $f
removeFile io-75.9
+ unset f
} -match glob -result [list {A} {error writing "*":\
invalid or incomplete multibyte or wide character}]
@@ -9317,6 +9332,7 @@ test io-75.10 {incomplete multibyte encoding read is ignored} -setup {
} -cleanup {
close $f
removeFile io-75.10
+ unset d hd
} -result 41c0
# The current result returns the orphan byte as byte.
# This may be expected due to special utf-8 handling.
@@ -9341,6 +9357,7 @@ test io-75.11 {shiftjis encoding error read results in raw bytes} -setup {
} -cleanup {
close $f
removeFile io-75.11
+ unset d hd msg f
} -match glob -result {41 1 {error reading "file*":\
invalid or incomplete multibyte or wide character}}
@@ -9381,6 +9398,7 @@ test io-75.13 {
} -cleanup {
close $f
removeFile io-75.13
+ unset d hd msg f fn
} -match glob -result {41 1 {error reading "file*":\
invalid or incomplete multibyte or wide character}}
@@ -9398,14 +9416,16 @@ test io-75.14 {
fconfigure $chan -encoding utf-8 -buffering none -eofchar {} \
-translation auto -profile strict
} -body {
+ set res [gets $chan]
lappend res [gets $chan]
- lappend res [gets $chan]
- lappend res [catch {gets $chan} cres] $cres
+ lappend res [catch {gets $chan} msg] $msg
chan configure $chan -profile tcl8
lappend res [gets $chan]
lappend res [gets $chan]
- close $chan
return $res
+} -cleanup {
+ close $chan
+ unset chan res msg
} -match glob -result {a b 1 {error reading "*":\
invalid or incomplete multibyte or wide character} cÀ d}
@@ -9425,8 +9445,8 @@ test io-75.15 {
fconfigure $chan -encoding utf-8 -profile strict
lappend res [gets $chan]
lappend res [gets $chan]
- lappend res [catch {gets $chan} cres] $cres
- lappend res [catch {gets $chan} cres] $cres
+ lappend res [catch {gets $chan} msg] $msg
+ lappend res [catch {gets $chan} msg] $msg
chan configure $chan -translation binary
set data [read $chan 4]
foreach char [split $data {}] {
@@ -9439,6 +9459,7 @@ test io-75.15 {
return $res
} -cleanup {
close $chan
+ unset chan res msg data
} -match glob -result {hello AB 1 {error reading "*": invalid or incomplete multibyte or wide character}\
1 {error reading "*": invalid or incomplete multibyte or wide character} 43 44 c0 40 EF GHI}
diff --git a/tests/listObj.test b/tests/listObj.test
index 0f43648..55fc089 100644
--- a/tests/listObj.test
+++ b/tests/listObj.test
@@ -278,6 +278,39 @@ test listobj-13.3 {Tcl_ListObjElements memory leaks for lseq} -constraints {
}] $errorMessage
} -result {0 {}}
+# Tests for Tcl_ListObjIndex as sematics are different from lindex for
+# out of bounds indices. Out of bounds should return a null pointer and
+# not empty string.
+test listobj-14.1 {Tcl_ListObjIndex out-of-bounds index for native lists} -constraints {
+ testobj
+} -setup {
+ testobj set 1 [list a b c]
+} -cleanup {
+ testobj freeallvars
+} -body {
+ list [testlistobj index 1 -1] [testlistobj index 1 3]
+} -result {null null}
+
+test listobj-14.2 {Tcl_ListObjIndex out-of-bounds index for native lists with spans} -constraints {
+ testobj
+} -setup {
+ testobj set 1 [testlistrep new 1000 100 100]
+} -cleanup {
+ testobj freeallvars
+} -body {
+ list [testlistobj index 1 -1] [testlistobj index 1 1000]
+} -result {null null}
+
+test listobj-14.3 {Tcl_ListObjIndex out-of-bounds index for lseq} -constraints {
+ testobj
+} -setup {
+ testobj set 1 [lseq 3]
+} -cleanup {
+ testobj freeallvars
+} -body {
+ list [testlistobj index 1 -1] [testlistobj index 1 3]
+} -result {null null}
+
# cleanup
::tcltest::cleanupTests
return