summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorapnadkarni <apnmbx-wits@yahoo.com>2023-02-07 17:10:07 (GMT)
committerapnadkarni <apnmbx-wits@yahoo.com>2023-02-07 17:10:07 (GMT)
commit615082f1faad662be8cead6e3fd4f5182f5d75f7 (patch)
tree1d1cb60b51f6e1cff49de198e77ba5ed3e69216c /tests
parentb741dab392a7e58c23568bd821d7eff982c2ec14 (diff)
parent597d3b9e7bae377b0d1e04270c733542cd3b983c (diff)
downloadtcl-615082f1faad662be8cead6e3fd4f5182f5d75f7.zip
tcl-615082f1faad662be8cead6e3fd4f5182f5d75f7.tar.gz
tcl-615082f1faad662be8cead6e3fd4f5182f5d75f7.tar.bz2
Merge core-8-branch
Diffstat (limited to 'tests')
-rw-r--r--tests/chanio.test6
-rw-r--r--tests/cmdAH.test62
-rw-r--r--tests/encoding.test12
-rw-r--r--tests/io.test472
-rw-r--r--tests/safe.test8
5 files changed, 428 insertions, 132 deletions
diff --git a/tests/chanio.test b/tests/chanio.test
index 7c9857d..6a387f1 100644
--- a/tests/chanio.test
+++ b/tests/chanio.test
@@ -252,7 +252,7 @@ test chan-io-3.3 {WriteChars: compatibility with WriteBytes: flush on line} -bod
test chan-io-3.4 {WriteChars: loop over stage buffer} -body {
# stage buffer maps to more than can be queued at once.
set f [open $path(test1) w]
- chan configure $f -encoding jis0208 -buffersize 16 -profile tcl8
+ chan configure $f -encoding jis0208 -buffersize 16 -encodingprofile tcl8
chan puts -nonewline $f "\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"
set x [list [contents $path(test1)]]
chan close $f
@@ -265,7 +265,7 @@ test chan-io-3.5 {WriteChars: saved != 0} -body {
# be moved to beginning of next channel buffer to preserve requested
# buffersize.
set f [open $path(test1) w]
- chan configure $f -encoding jis0208 -buffersize 17 -profile tcl8
+ chan configure $f -encoding jis0208 -buffersize 17 -encodingprofile tcl8
chan puts -nonewline $f "\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"
set x [list [contents $path(test1)]]
chan close $f
@@ -298,7 +298,7 @@ test chan-io-3.7 {WriteChars: (bufPtr->nextAdded > bufPtr->length)} -body {
# on flush. The truncated bytes are moved to the beginning of the next
# channel buffer.
set f [open $path(test1) w]
- chan configure $f -encoding jis0208 -buffersize 17 -profile tcl8
+ chan configure $f -encoding jis0208 -buffersize 17 -encodingprofile tcl8
chan puts -nonewline $f "\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"
set x [list [contents $path(test1)]]
chan close $f
diff --git a/tests/cmdAH.test b/tests/cmdAH.test
index 22dc2a4..ad5e540 100644
--- a/tests/cmdAH.test
+++ b/tests/cmdAH.test
@@ -344,11 +344,11 @@ badnumargs cmdAH-4.3.4 {encoding convertfrom} {-failindex VAR -profile strict AB
badnumargs cmdAH-4.3.5 {encoding convertfrom} {-profile strict -failindex VAR ABC}
# Test that last two args always treated as ENCODING DATA
-unknownencodingtest 4.3.6 {convertfrom -failindex ABC}
-unknownencodingtest 4.3.7 {convertfrom -profile ABC}
-unknownencodingtest 4.3.8 {convertfrom nosuchencoding ABC}
-unknownencodingtest 4.3.9 {convertfrom -failindex VAR -profile ABC}
-unknownencodingtest 4.3.10 {convertfrom -profile strict -failindex ABC}
+unknownencodingtest cmdAH-4.3.6 {convertfrom -failindex ABC}
+unknownencodingtest cmdAH-4.3.7 {convertfrom -profile ABC}
+unknownencodingtest cmdAH-4.3.8 {convertfrom nosuchencoding ABC}
+unknownencodingtest cmdAH-4.3.9 {convertfrom -failindex VAR -profile ABC}
+unknownencodingtest cmdAH-4.3.10 {convertfrom -profile strict -failindex ABC}
testconvert cmdAH-4.3.11 {
encoding convertfrom jis0208 \x38\x43
} \u4e4e -setup {
@@ -379,21 +379,21 @@ proc testfailindex {id converter enc data result {profile default}} {
# -failindex - valid data
foreach {enc string bytes} $encValidStrings {
- testfailindex 4.3.13.$enc convertfrom $enc $bytes [list $string -1]
+ testfailindex cmdAH-4.3.13.$enc convertfrom $enc $bytes [list $string -1]
if {"utf-16$endian" eq $enc} {
# utf-16le ->utf-16, utf-32be -> utf32 etc.
set enc [string range $enc 0 5]
- testfailindex 4.3.13.$enc convertfrom $enc $bytes [list $string -1]
+ testfailindex cmdAH-4.3.13.$enc convertfrom $enc $bytes [list $string -1]
}
}
# -failindex - invalid data
foreach {enc bytes profile prefix failidx tag} $encInvalidBytes {
- testfailindex 4.3.14.$enc.$profile.$tag convertfrom $enc $bytes [list $prefix $failidx] $profile
+ testfailindex cmdAH-4.3.14.$enc.$profile.$tag convertfrom $enc $bytes [list $prefix $failidx] $profile
if {"utf-16$endian" eq $enc} {
# utf-16le ->utf-16, utf-32be -> utf32 etc.
set enc [string range $enc 0 5]
- testfailindex 4.3.14.$enc.$profile.$tag convertfrom $enc $bytes [list $prefix $failidx] $profile
+ testfailindex cmdAH-4.3.14.$enc.$profile.$tag convertfrom $enc $bytes [list $prefix $failidx] $profile
}
}
@@ -403,11 +403,11 @@ foreach {enc bytes profile prefix failidx tag} $encInvalidBytes {
foreach profile $encProfiles {
set i 0
foreach {enc string bytes} $encValidStrings {
- testconvert 4.3.15.$enc.$profile.[incr i] [list encoding convertfrom $enc $bytes] $string
+ testconvert cmdAH-4.3.15.$enc.$profile.[incr i] [list encoding convertfrom $enc $bytes] $string
if {"utf-16$endian" eq $enc} {
# utf-16le ->utf-16, utf-32be -> utf32 etc.
set enc [string range $enc 0 5]
- testconvert 4.3.15.$enc.$profile.[incr i] [list encoding convertfrom $enc $bytes] $string
+ testconvert cmdAH-4.3.15.$enc.$profile.[incr i] [list encoding convertfrom $enc $bytes] $string
}
}
}
@@ -424,18 +424,18 @@ foreach {enc bytes profile prefix failidx tag} $encInvalidBytes {
set result [list "unexpected byte sequence starting at index $failidx: *" -returnCodes error -match glob]
}
if {$profile eq "default"} {
- testconvert 4.3.15.$enc.$profile.$tag [list encoding convertfrom $enc $bytes] {*}$result
+ testconvert cmdAH-4.3.15.$enc.$profile.$tag [list encoding convertfrom $enc $bytes] {*}$result
if {"utf-16$endian" eq $enc} {
# utf-16le ->utf-16, utf-32be -> utf32 etc.
set enc [string range $enc 0 5]
- testconvert 4.3.15.$enc.$profile.$tag [list encoding convertfrom $enc $bytes] {*}$result
+ testconvert cmdAH-4.3.15.$enc.$profile.$tag [list encoding convertfrom $enc $bytes] {*}$result
}
} else {
- testconvert 4.3.15.$enc.$profile.$tag [list encoding convertfrom -profile $profile $enc $bytes] {*}$result
+ testconvert cmdAH-4.3.15.$enc.$profile.$tag [list encoding convertfrom -profile $profile $enc $bytes] {*}$result
if {"utf-16$endian" eq $enc} {
# utf-16le ->utf-16, utf-32be -> utf32 etc.
set enc [string range $enc 0 5]
- testconvert 4.3.15.$enc.$profile.$tag [list encoding convertfrom -profile $profile $enc $bytes] {*}$result
+ testconvert cmdAH-4.3.15.$enc.$profile.$tag [list encoding convertfrom -profile $profile $enc $bytes] {*}$result
}
}
}
@@ -450,11 +450,11 @@ badnumargs cmdAH-4.4.4 {encoding convertto} {-failindex VAR -profile strict ABC}
badnumargs cmdAH-4.4.5 {encoding convertto} {-profile strict -failindex VAR ABC}
# Test that last two args always treated as ENCODING DATA
-unknownencodingtest 4.4.6 {convertto -failindex ABC}
-unknownencodingtest 4.4.7 {convertto -profile ABC}
-unknownencodingtest 4.4.8 {convertto nosuchencoding ABC}
-unknownencodingtest 4.4.9 {convertto -failindex VAR -profile ABC}
-unknownencodingtest 4.4.10 {convertto -profile strict -failindex ABC}
+unknownencodingtest cmdAH-4.4.6 {convertto -failindex ABC}
+unknownencodingtest cmdAH-4.4.7 {convertto -profile ABC}
+unknownencodingtest cmdAH-4.4.8 {convertto nosuchencoding ABC}
+unknownencodingtest cmdAH-4.4.9 {convertto -failindex VAR -profile ABC}
+unknownencodingtest cmdAH-4.4.10 {convertto -profile strict -failindex ABC}
testconvert cmdAH-4.4.11 {
encoding convertto jis0208 \u4e4e
} \x38\x43 -setup {
@@ -476,21 +476,21 @@ testconvert cmdAH-4.4.12 {
# -failindex - valid data
foreach {enc string bytes} $encValidStrings {
- testfailindex 4.4.13.$enc convertto $enc $string [list $bytes -1]
+ testfailindex cmdAH-4.4.13.$enc convertto $enc $string [list $bytes -1]
if {"utf-16$endian" eq $enc} {
# utf-16le ->utf-16, utf-32be -> utf32 etc.
set enc [string range $enc 0 5]
- testfailindex 4.4.13.$enc convertto $enc $string [list $bytes -1]
+ testfailindex cmdAH-4.4.13.$enc convertto $enc $string [list $bytes -1]
}
}
# -failindex - invalid data
foreach {enc string profile bytes failidx tag} $encUnencodableStrings {
- testfailindex 4.4.14.$enc.$profile.$tag convertto $enc $string [list $bytes $failidx] $profile
+ testfailindex cmdAH-4.4.14.$enc.$profile.$tag convertto $enc $string [list $bytes $failidx] $profile
if {"utf-16$endian" eq $enc} {
# utf-16le ->utf-16, utf-32be -> utf32 etc.
set enc [string range $enc 0 5]
- testfailindex 4.4.14.$enc.$profile.$tag convertto $enc $string [list $bytes $failidx] $profile
+ testfailindex cmdAH-4.4.14.$enc.$profile.$tag convertto $enc $string [list $bytes $failidx] $profile
}
}
@@ -500,11 +500,11 @@ foreach {enc string profile bytes failidx tag} $encUnencodableStrings {
foreach profile $encProfiles {
set i 0
foreach {enc string bytes} $encValidStrings {
- testconvert 4.4.15.$enc.$profile.[incr i] [list encoding convertto $enc $string] $bytes
+ testconvert cmdAH-4.4.15.$enc.$profile.[incr i] [list encoding convertto $enc $string] $bytes
if {"utf-16$endian" eq $enc} {
# utf-16le ->utf-16, utf-32be -> utf32 etc.
set enc [string range $enc 0 5]
- testconvert 4.4.15.$enc.$profile.[incr i] [list encoding convertto $enc $string] $bytes
+ testconvert cmdAH-4.4.15.$enc.$profile.[incr i] [list encoding convertto $enc $string] $bytes
}
}
}
@@ -520,23 +520,23 @@ foreach {enc string profile bytes failidx tag} $encUnencodableStrings {
set result [list "unexpected character at index $failidx: *" -returnCodes error -match glob]
}
if {$profile eq "default"} {
- testconvert 4.4.15.$enc.$profile.$tag [list encoding convertto $enc $string] {*}$result
+ testconvert cmdAH-4.4.15.$enc.$profile.$tag [list encoding convertto $enc $string] {*}$result
if {"utf-16$endian" eq $enc} {
# utf-16le ->utf-16, utf-32be -> utf32 etc.
set enc [string range $enc 0 5]
- testconvert 4.3.15.$enc.$profile.$tag [list encoding convertto $enc $string] {*}$result
+ testconvert cmdAH-4.4.15.$enc.$profile.$tag [list encoding convertto $enc $string] {*}$result
}
} else {
- testconvert 4.4.15.$enc.$profile.$tag [list encoding convertto -profile $profile $enc $string] {*}$result
+ testconvert cmdAH-4.4.15.$enc.$profile.$tag [list encoding convertto -profile $profile $enc $string] {*}$result
if {"utf-16$endian" eq $enc} {
# utf-16le ->utf-16, utf-32be -> utf32 etc.
set enc [string range $enc 0 5]
- testconvert 4.4.15.$enc.$profile.$tag [list encoding convertto -profile $profile $enc $string] {*}$result
+ testconvert cmdAH-4.4.15.$enc.$profile.$tag [list encoding convertto -profile $profile $enc $string] {*}$result
}
}
}
-test cmdAH-4.5.1 {convertto -profile strict} -constraints {testbytestring knownBug} -body {
+test cmdAH-4.4.xx {convertto -profile strict} -constraints {testbytestring knownBug} -body {
# TODO - what does testbytestring even test? Invalid UTF8 in the Tcl_Obj bytes field
encoding convertto -profile strict utf-8 A[testbytestring \x80]B
} -returnCodes error -result {unexpected byte sequence starting at index 1: '\x80'}
diff --git a/tests/encoding.test b/tests/encoding.test
index e4a2acb..55c83df 100644
--- a/tests/encoding.test
+++ b/tests/encoding.test
@@ -481,8 +481,12 @@ test encoding-16.7 {Utf32ToUtfProc} -body {
set val [encoding convertfrom utf-32be \0\0NN]
list $val [format %x [scan $val %c]]
} -result "乎 4e4e"
+test encoding-16.8 {Utf32ToUtfProc} -body {
+ set val [encoding convertfrom -profile tcl8 utf-32 \x41\x00\x00\x41]
+ list $val [format %x [scan $val %c]]
+} -result "\uFFFD fffd"
-test encoding-16.8 {
+test encoding-16.9 {
Utf16ToUtfProc, Tcl_UniCharToUtf, surrogate pairs in utf-16
} -body {
apply [list {} {
@@ -930,7 +934,9 @@ test encoding-27.2 {encoding dirs basic behavior} -returnCodes error -body {
test encoding-28.0 {all encodings load} -body {
set string hello
foreach name [encoding names] {
- incr count
+ if {$name ne "unicode"} {
+ incr count
+ }
encoding convertto -profile tcl8 $name $string
# discard the cached internal representation of Tcl_Encoding
@@ -938,7 +944,7 @@ test encoding-28.0 {all encodings load} -body {
llength $name
}
return $count
-} -result [expr {[info exists ::tcl_precision] ? 92 : 91}]
+} -result 91
runtests
diff --git a/tests/io.test b/tests/io.test
index efc6374..b748aeb 100644
--- a/tests/io.test
+++ b/tests/io.test
@@ -1547,19 +1547,53 @@ test io-12.8 {ReadChars: multibyte chars split} {
close $f
scan [string index $in end] %c
} 160
-test io-12.9 {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 10
- set in [read $f]
- close $f
- scan [string index $in end] %c
-} -cleanup {
- catch {close $f}
-} -result 194
+
+
+apply [list {} {
+ set template {
+ test io-12.9.@variant@ {ReadChars: multibyte chars split, default (strict)} -body {
+ set res {}
+ 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 @strict@ -buffersize 10
+ set status [catch {read $f} cres copts]
+ #set in [dict get $copts -result]
+ #lappend res $in
+ lappend res $status $cres
+ set status [catch {read $f} cres copts]
+ #set in [dict get $copts -result]
+ #lappend res $in
+ lappend res $status $cres
+ set res
+ } -cleanup {
+ catch {close $f}
+ } -match glob\
+ }
+
+ #append template {\
+ # -result {{read aaaaaaaaa} 1\
+ # {error reading "*": illegal byte sequence}\
+ # {read {}} 1 {error reading "*": illegal byte sequence}}
+ #}
+
+ append template {\
+ -result {1\
+ {error reading "*": illegal byte sequence}\
+ 1 {error reading "*": illegal byte sequence}}
+ }
+
+ # strict encoding may be the default in Tcl 9, but in 8 it is not
+ foreach variant {encodingstrict} strict {{-encodingprofile strict}} {
+ set script [string map [
+ list @variant@ $variant @strict@ $strict] $template]
+ uplevel 1 $script
+ }
+} [namespace current]]
+
+
test io-12.10 {ReadChars: multibyte chars split} -body {
set f [open $path(test1) w]
fconfigure $f -translation binary
@@ -9046,31 +9080,94 @@ test io-75.5 {invalid utf-8 encoding read is ignored (-encodingprofile tcl8)} -s
removeFile io-75.5
} -result 4181
-test io-75.6 {invalid utf-8 encoding read is not ignored (-encodingprofile strict)} -setup {
- set fn [makeFile {} io-75.6]
- set f [open $fn w+]
- fconfigure $f -encoding binary
- # \x81 is invalid in utf-8
- puts -nonewline $f A\x81
- flush $f
- seek $f 0
- fconfigure $f -encoding utf-8 -buffering none -eofchar "" -translation lf -encodingprofile strict
-} -body {
- set d [read $f]
- binary scan $d H* hd
- lappend hd [catch {read $f} msg]
- close $f
- lappend hd $msg
-} -cleanup {
- removeFile io-75.6
-} -match glob -result {41 1 {error reading "*": illegal byte sequence}}
-test io-75.7 {invalid utf-8 encoding eof handling (-encodingprofile strict)} -setup {
- set fn [makeFile {} io-75.7]
+apply [list {} {
+
+
+ set test {
+ test io-75.6 {invalid utf-8 encoding read is not ignored (-encodingprofile strict)} -setup {
+ set hd {}
+ set fn [makeFile {} io-75.6]
+ set f [open $fn w+]
+ fconfigure $f -encoding binary
+ # \x81 is invalid in utf-8
+ puts -nonewline $f A\x81
+ flush $f
+ seek $f 0
+ fconfigure $f -encoding utf-8 -buffering none -eofchar "" -translation lf -encodingprofile strict
+ } -body {
+ set status [catch {read $f} cres copts]
+ #set d [dict get $copts -result read]
+ #binary scan $d H* hd
+ lappend hd $status $cres
+ } -cleanup {
+ close $f
+ removeFile io-75.6
+ } -match glob\
+ }
+
+ #append test {\
+ # -result {41 1 {error reading "*": illegal byte sequence}}
+ #}
+
+ append test {\
+ -result {1 {error reading "*": illegal byte sequence}}
+ }
+
+ uplevel 1 $test
+
+ set test {
+ test io-75.7 {invalid utf-8 encoding eof handling (-encodingprofile strict)} -setup {
+ set hd {}
+ set fn [makeFile {} io-75.7]
+ set f [open $fn w+]
+ fconfigure $f -encoding binary
+ # \xA1 is invalid in utf-8. -eofchar is not detected, because it comes later.
+ puts -nonewline $f A\xA1\x1A
+ flush $f
+ seek $f 0
+ fconfigure $f -encoding utf-8 -buffering none -eofchar \x1A -translation lf -encodingprofile strict
+ } -body {
+ set status [catch {read $f} cres copts]
+ #set d [dict get $copts -result read]
+ #binary scan $d H* hd
+ lappend hd [eof $f]
+ lappend hd $status
+ lappend hd $cres
+ fconfigure $f -encoding iso8859-1
+ lappend hd [read $f];# We changed encoding, so now we can read the \xA1
+ close $f
+ set hd
+ } -cleanup {
+ removeFile io-75.7
+ } -match glob\
+ }
+
+ #append test {\
+ # -result {41 0 1 {error reading "*": illegal byte sequence} ¡}
+ #}
+
+ append test {\
+ -result {0 1 {error reading "*": illegal byte sequence} ¡}
+ }
+
+ uplevel 1 $test
+
+
+} [namespace current]]
+
+
+
+test io-75.8.incomplete {
+ incomplete uft-8 char after eof char is not an error (-encodingprofile strict)
+} -setup {
+ set hd {}
+ set fn [makeFile {} io-75.8]
set f [open $fn w+]
fconfigure $f -encoding binary
- # \xA1 is invalid in utf-8. -eofchar is not detected, because it comes later.
- puts -nonewline $f A\xA1\x1A
+ # \x81 is invalid and also incomplete utf-8 data, but because the eof
+ # character \x1A appears first, it's not an error.
+ puts -nonewline $f A\x1A\x81
flush $f
seek $f 0
fconfigure $f -encoding utf-8 -buffering none -eofchar \x1A -translation lf -encodingprofile strict
@@ -9078,36 +9175,41 @@ test io-75.7 {invalid utf-8 encoding eof handling (-encodingprofile strict)} -se
set d [read $f]
binary scan $d H* hd
lappend hd [eof $f]
- lappend hd [catch {read $f} msg]
- lappend hd $msg
- fconfigure $f -encoding iso8859-1
- lappend hd [read $f];# We changed encoding, so now we can read the \xA1
+ # there should be no error on additional reads
+ lappend hd [read $f]
close $f
set hd
} -cleanup {
- removeFile io-75.7
-} -match glob -result {41 0 1 {error reading "*": illegal byte sequence} ¡}
+ removeFile io-75.8
+} -result {41 1 {}}
-test io-75.8 {invalid utf-8 encoding eof handling (-encodingprofile strict)} -setup {
+
+test io-75.8.invalid {invalid utf-8 after eof char is not an error (-encodingprofile strict)} -setup {
+ set res {}
set fn [makeFile {} io-75.8]
set f [open $fn w+]
fconfigure $f -encoding binary
- # \x81 is invalid in utf-8, but since \x1A comes first, -eofchar takes precedence.
- puts -nonewline $f A\x1A\x81
+ # \xc0\x80 is invalid utf-8 data, but because the eof character \x1A
+ # appears first, it's not an error.
+ puts -nonewline $f A\x1a\xc0\x80
flush $f
seek $f 0
fconfigure $f -encoding utf-8 -buffering none -eofchar \x1A -translation lf -encodingprofile strict
} -body {
set d [read $f]
- binary scan $d H* hd
- lappend hd [eof $f]
- lappend hd [read $f]
+ foreach char [split $d {}] {
+ lappend res [format %x [scan $char %c]]
+ }
+ lappend res [eof $f]
+ # there should be no error on additional reads
+ lappend res [read $f]
close $f
- set hd
+ set res
} -cleanup {
removeFile io-75.8
} -result {41 1 {}}
+
test io-75.9 {unrepresentable character write passes and is replaced by ?} -setup {
set fn [makeFile {} io-75.9]
set f [open $fn w+]
@@ -9122,9 +9224,7 @@ test io-75.9 {unrepresentable character write passes and is replaced by ?} -setu
removeFile io-75.9
} -match glob -result [list {A} {error writing "*": illegal byte sequence}]
-# Incomplete sequence test.
-# This error may IMHO only be detected with the close.
-# But the read already returns the incomplete sequence.
+
test io-75.10 {incomplete multibyte encoding read is ignored} -setup {
set fn [makeFile {} io-75.10]
set f [open $fn w+]
@@ -9132,7 +9232,7 @@ test io-75.10 {incomplete multibyte encoding read is ignored} -setup {
puts -nonewline $f A\xC0
flush $f
seek $f 0
- fconfigure $f -encoding utf-8 -buffering none
+ fconfigure $f -encoding utf-8 -encodingprofile tcl8 -buffering none
} -body {
set d [read $f]
close $f
@@ -9141,39 +9241,135 @@ test io-75.10 {incomplete multibyte encoding read is ignored} -setup {
} -cleanup {
removeFile io-75.10
} -result 41c0
-# The current result returns the orphan byte as byte.
-# This may be expected due to special utf-8 handling.
-# As utf-8 has a special treatment in multi-byte decoding, also test another
-# one.
-test io-75.11 {shiftjis encoding error read results in raw bytes} -setup {
- set fn [makeFile {} io-75.11]
- set f [open $fn w+]
- fconfigure $f -encoding binary
- # In shiftjis, \x81 starts a two-byte sequence.
- # But 2nd byte \xFF is not allowed
- puts -nonewline $f A\x81\xFFA
- flush $f
- seek $f 0
- fconfigure $f -encoding shiftjis -buffering none -eofchar "" -translation lf -encodingprofile strict
-} -body {
- set d [read $f]
- binary scan $d H* hd
- lappend hd [catch {set d [read $f]} msg]
- lappend hd $msg
-} -cleanup {
- close $f
- removeFile io-75.11
-} -match glob -result {41 1 {error reading "*": illegal byte sequence}}
-test io-75.12 {invalid utf-8 encoding read is ignored} -setup {
+apply [list {} {
+
+ set test {
+ test io-75.10_strict {incomplete multibyte encoding read is an error} -setup {
+ set res {}
+ set fn [makeFile {} io-75.10]
+ set f [open $fn w+]
+ fconfigure $f -encoding binary
+ puts -nonewline $f A\xC0
+ flush $f
+ seek $f 0
+ fconfigure $f -encoding utf-8 -encodingprofile strict -buffering none
+ } -body {
+ set status [catch {read $f} cres copts]
+
+ #set d [dict get $copts -result read]
+ #binary scan $d H* hd
+ #lappend res $hd $cres
+ lappend res $cres
+
+ chan configure $f -encoding iso8859-1
+
+ set d [read $f]
+ binary scan $d H* hd
+ lappend res $hd
+ close $f
+ return $res
+ } -cleanup {
+ removeFile io-75.10
+ } -match glob\
+ }
+
+ #append test {\
+ # -result {41 {error reading "*": illegal byte sequence} c0}
+ #}
+
+ append test {\
+ -result {{error reading "*": illegal byte sequence} c0}
+ }
+
+ uplevel 1 $test
+
+
+
+ set test {
+ # As utf-8 has a special treatment in multi-byte decoding, also test another
+ # one.
+ test io-75.11 {shiftjis encoding error read results in raw bytes} -setup {
+ set hd {}
+ set fn [makeFile {} io-75.11]
+ set f [open $fn w+]
+ fconfigure $f -encoding binary
+ # In shiftjis, \x81 starts a two-byte sequence.
+ # But 2nd byte \xFF is not allowed
+ puts -nonewline $f A\x81\xFFA
+ flush $f
+ seek $f 0
+ fconfigure $f -encoding shiftjis -buffering none -eofchar "" \
+ -translation lf -encodingprofile strict
+ } -body {
+ set status [catch {read $f} cres copts]
+ #set d [dict get $copts -result read]
+ #binary scan $d H* hd
+ lappend hd $status
+ lappend hd $cres
+ } -cleanup {
+ close $f
+ removeFile io-75.11
+ } -match glob
+ }
+
+ #append test {\
+ # -result {41 1 {error reading "*": illegal byte sequence}}
+ #}
+
+ append test {\
+ -result {1 {error reading "*": illegal byte sequence}}
+ }
+
+
+ set test {
+ test io-75.12 {invalid utf-8 encoding read is an error} -setup {
+ set hd {}
+ set res {}
+ set fn [makeFile {} io-75.12]
+ set f [open $fn w+]
+ fconfigure $f -encoding binary
+ puts -nonewline $f A\x81
+ flush $f
+ seek $f 0
+ fconfigure $f -encoding utf-8 -buffering none -eofchar {} -translation lf \
+ -encodingprofile strict
+ } -body {
+ set status [catch {read $f} cres copts]
+ #set d [dict get $copts -result read]
+ #binary scan $d H* hd
+ #lappend res $hd
+ lappend res $status $cres
+ return $res
+ } -cleanup {
+ catch {close $f}
+ removeFile io-75.12
+ } -match glob\
+ }
+
+ #append test {\
+ # -result {41 1 {error reading "*": illegal byte sequence}}
+ #}
+
+
+ append test {\
+ -result {1 {error reading "*": illegal byte sequence}}
+ }
+
+ uplevel 1 $test
+} [namespace current]]
+
+
+test io-75.12_ignore {invalid utf-8 encoding read is ignored} -setup {
set fn [makeFile {} io-75.12]
set f [open $fn w+]
fconfigure $f -encoding binary
puts -nonewline $f A\x81
flush $f
seek $f 0
- fconfigure $f -encoding utf-8 -buffering none -eofchar "" -translation lf
+ fconfigure $f -encoding utf-8 -buffering none -eofchar {} \
+ -translation lf -encodingprofile tcl8
} -body {
set d [read $f]
close $f
@@ -9182,28 +9378,122 @@ test io-75.12 {invalid utf-8 encoding read is ignored} -setup {
} -cleanup {
removeFile io-75.12
} -result 4181
-test io-75.13 {invalid utf-8 encoding read is not ignored (-encodingprofile strict)} -setup {
- set fn [makeFile {} io-75.13]
+
+
+apply [list {} {
+
+ set test {
+ test io-75.13 {invalid utf-8 encoding read is not ignored (-encodingprofile strict)} -setup {
+ set hd {}
+ set fn [makeFile {} io-75.13]
+ set f [open $fn w+]
+ fconfigure $f -encoding binary
+ # \x81 is invalid in utf-8
+ puts -nonewline $f A\x81
+ flush $f
+ seek $f 0
+ fconfigure $f -encoding utf-8 -buffering none -eofchar "" \
+ -translation lf -encodingprofile strict
+ } -body {
+ set status [catch {read $f} cres copts]
+ #set d [dict get $copts -result read]
+ #binary scan $d H* hd
+ lappend hd $status
+ lappend hd $cres
+ } -cleanup {
+ catch {close $f}
+ removeFile io-75.13
+ } -match glob\
+ }
+
+ #append test {\
+ # -result {41 1 {error reading "*": illegal byte sequence}}
+ #}
+
+ append test {\
+ -result {1 {error reading "*": illegal byte sequence}}
+ }
+
+ uplevel 1 $test
+
+ set test {
+ }
+
+} [namespace current]]
+
+
+test io-75.14 {
+ invalid utf-8 encoding [gets] continues in non-strict mode after error
+} -setup {
+ set res {}
+ set fn [makeFile {} io-75.14]
set f [open $fn w+]
- fconfigure $f -encoding binary
- # \x81 is invalid in utf-8
- puts -nonewline $f "A\x81"
+ fconfigure $f -translation binary
+ # \xc0 is invalid in utf-8
+ puts -nonewline $f a\nb\xc0\nc\n
flush $f
seek $f 0
- fconfigure $f -encoding utf-8 -buffering none -eofchar "" -translation lf -encodingprofile strict
+ fconfigure $f -encoding utf-8 -buffering none -eofchar {} -translation lf -encodingprofile strict
} -body {
- set d [read $f]
- binary scan $d H* hd
- lappend hd [catch {read $f} msg]
- close $f
- lappend hd $msg
+ lappend res [gets $f]
+ set status [catch {gets $f} cres copts]
+ lappend res $status $cres
+ chan configure $f -encodingprofile tcl8
+ lappend res [gets $f]
+ lappend res [gets $f]
+ close $f
+ return $res
} -cleanup {
- removeFile io-75.13
-} -match glob -result {41 1 {error reading "*": illegal byte sequence}}
+ removeFile io-75.14
+} -match glob -result {a 1 {error reading "*": illegal byte sequence} bÀ c}
-# ### ### ### ######### ######### #########
+apply [list {} {
+ set test {
+ test io-75.15 {invalid utf-8 encoding strict gets should not hang} -setup {
+ set res {}
+ set fn [makeFile {} io-75.15]
+ set chan [open $fn w+]
+ fconfigure $chan -encoding binary
+ # This is not valid UTF-8
+ puts $chan hello\nAB\xc0\x40CD\nEFG
+ close $chan
+ } -body {
+ #Now try to read it with [gets]
+ set chan [open $fn]
+ fconfigure $chan -encoding utf-8 -encodingprofile strict
+ lappend res [gets $chan]
+ set status [catch {gets $chan} cres copts]
+ lappend res $status $cres
+ set status [catch {gets $chan} cres copts]
+ lappend res $status $cres
+ #lappend res [dict get $copts -result]
+ chan configur $chan -encoding binary
+ foreach char [split [read $chan 2] {}] {
+ lappend res [format %x [scan $char %c]]
+ }
+ return $res
+ } -cleanup {
+ close $chan
+ removeFile io-75.15
+ } -match glob\
+ }
+
+ #append test {\
+ # -result {hello 1 {error reading "*": illegal byte sequence}\
+ # 1 {error reading "*": illegal byte sequence} {read AB} c0 40}
+ #}
+
+ append test {\
+ -result {hello 1 {error reading "*": illegal byte sequence}\
+ 1 {error reading "*": illegal byte sequence} c0 40}
+ }
+
+ uplevel 1 $test
+
+} [namespace current]]
+
test io-76.0 {channel modes} -setup {
set datafile [makeFile {some characters} dummy]
diff --git a/tests/safe.test b/tests/safe.test
index ee81783..8c8382a 100644
--- a/tests/safe.test
+++ b/tests/safe.test
@@ -1473,7 +1473,7 @@ test safe-11.7 {testing safe encoding} -setup {
interp eval $i encoding convertfrom
} -returnCodes error -cleanup {
safe::interpDelete $i
-} -result {wrong # args: should be "encoding convertfrom ?-strict? ?-failindex var? ?encoding? data" or "encoding convertfrom -nocomplain ?encoding? data"}
+} -result {wrong # args: should be "encoding convertfrom ??-profile profile? ?-failindex var? ?encoding?? data"}
test safe-11.7.1 {testing safe encoding} -setup {
set i [safe::interpCreate]
} -body {
@@ -1482,7 +1482,7 @@ test safe-11.7.1 {testing safe encoding} -setup {
} -match glob -cleanup {
unset -nocomplain m o
safe::interpDelete $i
-} -result {wrong # args: should be "encoding convertfrom ?-strict? ?-failindex var? ?encoding? data" or "encoding convertfrom -nocomplain ?encoding? data"
+} -result {wrong # args: should be "encoding convertfrom ??-profile profile? ?-failindex var? ?encoding?? data"
while executing
"encoding convertfrom"
invoked from within
@@ -1495,7 +1495,7 @@ test safe-11.8 {testing safe encoding} -setup {
interp eval $i encoding convertto
} -returnCodes error -cleanup {
safe::interpDelete $i
-} -result {wrong # args: should be "encoding convertto ?-strict? ?-failindex var? ?encoding? data" or "encoding convertto -nocomplain ?encoding? data"}
+} -result {wrong # args: should be "encoding convertto ??-profile profile? ?-failindex var? ?encoding?? data"}
test safe-11.8.1 {testing safe encoding} -setup {
set i [safe::interpCreate]
} -body {
@@ -1504,7 +1504,7 @@ test safe-11.8.1 {testing safe encoding} -setup {
} -match glob -cleanup {
unset -nocomplain m o
safe::interpDelete $i
-} -result {wrong # args: should be "encoding convertto ?-strict? ?-failindex var? ?encoding? data" or "encoding convertto -nocomplain ?encoding? data"
+} -result {wrong # args: should be "encoding convertto ??-profile profile? ?-failindex var? ?encoding?? data"
while executing
"encoding convertto"
invoked from within