From d8c018f1a22a3dd5e68107869456c01488a13823 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Fri, 18 Mar 2022 13:04:39 +0000 Subject: Add proper cleanup to testcases --- tests/chanio.test | 30 ++++++++++++++++++++---------- tests/http.test | 1 + tests/io.test | 30 ++++++++++++++++++++---------- 3 files changed, 41 insertions(+), 20 deletions(-) diff --git a/tests/chanio.test b/tests/chanio.test index 578dc9f..38f3d90 100644 --- a/tests/chanio.test +++ b/tests/chanio.test @@ -249,7 +249,7 @@ test chan-io-3.3 {WriteChars: compatibility with WriteBytes: flush on line} -bod } -cleanup { chan close $f } -result "\r\n12" -test chan-io-3.4 {WriteChars: loop over stage buffer} deprecated { +test chan-io-3.4 {WriteChars: loop over stage buffer} -constraints deprecated -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 @@ -257,8 +257,10 @@ test chan-io-3.4 {WriteChars: loop over stage buffer} deprecated { set x [list [contents $path(test1)]] chan close $f lappend x [contents $path(test1)] -} [list "!)!)!)!)!)!)!)!)" "!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)"] -test chan-io-3.5 {WriteChars: saved != 0} deprecated { +} -cleanup { + catch {chan close $f} +} -result [list "!)!)!)!)!)!)!)!)" "!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)"] +test chan-io-3.5 {WriteChars: saved != 0} -constraints deprecated -body { # Bytes produced by UtfToExternal from end of last channel buffer had to # be moved to beginning of next channel buffer to preserve requested # buffersize. @@ -268,8 +270,10 @@ test chan-io-3.5 {WriteChars: saved != 0} deprecated { set x [list [contents $path(test1)]] chan close $f lappend x [contents $path(test1)] -} [list "!)!)!)!)!)!)!)!)!" "!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)"] -test chan-io-3.6 {WriteChars: (stageRead + dstWrote == 0)} { +} -cleanup { + catch {chan close $f} +} -result [list "!)!)!)!)!)!)!)!)!" "!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)"] +test chan-io-3.6 {WriteChars: (stageRead + dstWrote == 0)} -body { # One incomplete UTF-8 character at end of staging buffer. Backup in src # to the beginning of that UTF-8 character and try again. # @@ -284,8 +288,10 @@ test chan-io-3.6 {WriteChars: (stageRead + dstWrote == 0)} { set x [list [contents $path(test1)]] chan close $f lappend x [contents $path(test1)] -} [list "12345678901234\x82\x60" "12345678901234\x82\x60\x82\x61"] -test chan-io-3.7 {WriteChars: (bufPtr->nextAdded > bufPtr->length)} deprecated { +} -cleanup { + catch {chan close $f} +} -result [list "12345678901234\x82\x60" "12345678901234\x82\x60\x82\x61"] +test chan-io-3.7 {WriteChars: (bufPtr->nextAdded > bufPtr->length)} -constraints deprecated -body { # When translating UTF-8 to external, the produced bytes went past end of # the channel buffer. This is done on purpose - we then truncate the bytes # at the end of the partial character to preserve the requested blocksize @@ -297,8 +303,10 @@ test chan-io-3.7 {WriteChars: (bufPtr->nextAdded > bufPtr->length)} deprecated { set x [list [contents $path(test1)]] chan close $f lappend x [contents $path(test1)] -} [list "!)!)!)!)!)!)!)!)!" "!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)"] -test chan-io-3.8 {WriteChars: reset sawLF after each buffer} { +} -cleanup { + catch {chan close $f} +} -result [list "!)!)!)!)!)!)!)!)!" "!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)"] +test chan-io-3.8 {WriteChars: reset sawLF after each buffer} -body { set f [open $path(test1) w] chan configure $f -encoding ascii -buffering line -translation lf \ -buffersize 16 @@ -306,7 +314,9 @@ test chan-io-3.8 {WriteChars: reset sawLF after each buffer} { set x [list [contents $path(test1)]] chan close $f lappend x [contents $path(test1)] -} [list "abcdefg\nhijklmno" "abcdefg\nhijklmnopqrstuvwxyz"] +} -cleanup { + catch {chan close $f} +} -result [list "abcdefg\nhijklmno" "abcdefg\nhijklmnopqrstuvwxyz"] test chan-io-4.1 {TranslateOutputEOL: lf} { # search for \n diff --git a/tests/http.test b/tests/http.test index 93998fe..a34b168 100644 --- a/tests/http.test +++ b/tests/http.test @@ -15,6 +15,7 @@ if {"::tcltest" ni [namespace children]} { package require tcltest 2.5 namespace import -force ::tcltest::* } +package require tcltests if {[catch {package require http 2} version]} { if {[info exists http2]} { diff --git a/tests/io.test b/tests/io.test index 821b11e..e22fa8a 100644 --- a/tests/io.test +++ b/tests/io.test @@ -268,7 +268,7 @@ test io-3.3 {WriteChars: compatibility with WriteBytes: flush on line} { close $f set x } "\r\n12" -test io-3.4 {WriteChars: loop over stage buffer} deprecated { +test io-3.4 {WriteChars: loop over stage buffer} -constraints deprecated -body { # stage buffer maps to more than can be queued at once. set f [open $path(test1) w] @@ -277,8 +277,10 @@ test io-3.4 {WriteChars: loop over stage buffer} deprecated { set x [list [contents $path(test1)]] close $f lappend x [contents $path(test1)] -} [list "!)!)!)!)!)!)!)!)" "!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)"] -test io-3.5 {WriteChars: saved != 0} deprecated { +} -cleanup { + catch {close $f} +} -result [list "!)!)!)!)!)!)!)!)" "!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)"] +test io-3.5 {WriteChars: saved != 0} -constraints deprecated -body { # Bytes produced by UtfToExternal from end of last channel buffer # had to be moved to beginning of next channel buffer to preserve # requested buffersize. @@ -289,7 +291,9 @@ test io-3.5 {WriteChars: saved != 0} deprecated { set x [list [contents $path(test1)]] close $f lappend x [contents $path(test1)] -} [list "!)!)!)!)!)!)!)!)!" "!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)"] +} -cleanup { + catch {close $f} +} -result [list "!)!)!)!)!)!)!)!)!" "!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)"] test io-3.6 {WriteChars: (stageRead + dstWrote == 0)} { # One incomplete UTF-8 character at end of staging buffer. Backup # in src to the beginning of that UTF-8 character and try again. @@ -307,7 +311,7 @@ test io-3.6 {WriteChars: (stageRead + dstWrote == 0)} { close $f lappend x [contents $path(test1)] } [list "12345678901234\x82\x60" "12345678901234\x82\x60\x82\x61"] -test io-3.7 {WriteChars: (bufPtr->nextAdded > bufPtr->length)} deprecated { +test io-3.7 {WriteChars: (bufPtr->nextAdded > bufPtr->length)} -constraints deprecated -body { # When translating UTF-8 to external, the produced bytes went past end # of the channel buffer. This is done purpose -- we then truncate the # bytes at the end of the partial character to preserve the requested @@ -320,7 +324,9 @@ test io-3.7 {WriteChars: (bufPtr->nextAdded > bufPtr->length)} deprecated { set x [list [contents $path(test1)]] close $f lappend x [contents $path(test1)] -} [list "!)!)!)!)!)!)!)!)!" "!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)"] +} -cleanup { + catch {close $f} +} -result [list "!)!)!)!)!)!)!)!)!" "!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)"] test io-3.8 {WriteChars: reset sawLF after each buffer} { set f [open $path(test1) w] fconfigure $f -encoding ascii -buffering line -translation lf \ @@ -1532,7 +1538,7 @@ 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} deprecated { +test io-12.9 {ReadChars: multibyte chars split} -constraints deprecated -body { set f [open $path(test1) w] fconfigure $f -translation binary puts -nonewline $f [string repeat a 9]\xC2 @@ -1542,8 +1548,10 @@ test io-12.9 {ReadChars: multibyte chars split} deprecated { set in [read $f] close $f scan [string index $in end] %c -} 194 -test io-12.10 {ReadChars: multibyte chars split} deprecated { +} -cleanup { + catch {close $f} +} -result 194 +test io-12.10 {ReadChars: multibyte chars split} -constraints deprecated -body { set f [open $path(test1) w] fconfigure $f -translation binary puts -nonewline $f [string repeat a 9]\xC2 @@ -1553,7 +1561,9 @@ test io-12.10 {ReadChars: multibyte chars split} deprecated { set in [read $f] close $f scan [string index $in end] %c -} 194 +} -cleanup { + catch {close $f} +} -result 194 test io-13.1 {TranslateInputEOL: cr mode} {} { set f [open $path(test1) w] -- cgit v0.12 From 92e97aec374dfefc0a80edf3fcd4cde7c5cda86c Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Fri, 18 Mar 2022 13:05:50 +0000 Subject: Fix meaning of "testConstraint deprepcated" in encoding.test: Those testcases tested the behavior of -DTCL_NO_DEPRECATED --- tests/encoding.test | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/encoding.test b/tests/encoding.test index bf82493..21e5df1 100644 --- a/tests/encoding.test +++ b/tests/encoding.test @@ -22,7 +22,7 @@ catch { package require -exact tcl::test [info patchlevel] } -testConstraint deprecated [expr {![info exists tcl_precision]}] +package require tcltests proc toutf {args} { variable x @@ -639,28 +639,28 @@ test encoding-24.11 {Parse valid or invalid utf-8} { } 1 test encoding-24.12 {Parse valid or invalid utf-8} -constraints deprecated -body { encoding convertfrom utf-8 "\xC0\x81" -} -returnCodes 1 -result {unexpected byte sequence starting at index 0: '\xC0'} +} -result \xC0\x81 test encoding-24.13 {Parse valid or invalid utf-8} -constraints deprecated -body { encoding convertfrom utf-8 "\xC1\xBF" -} -returnCodes 1 -result {unexpected byte sequence starting at index 0: '\xC1'} +} -result \xC1\xBF test encoding-24.14 {Parse valid or invalid utf-8} { string length [encoding convertfrom utf-8 "\xC2\x80"] } 1 test encoding-24.15 {Parse valid or invalid utf-8} -constraints deprecated -body { encoding convertfrom utf-8 "Z\xE0\x80" -} -returnCodes 1 -result {unexpected byte sequence starting at index 1: '\xE0'} -test encoding-24.16 {Parse valid or invalid utf-8} -constraints {testbytestring deprecated} -body { +} -result Z\xE0\x80 +test encoding-24.16 {Parse valid or invalid utf-8} -constraints testbytestring -body { encoding convertto utf-8 [testbytestring "Z\u4343\x80"] } -returnCodes 1 -result {expected byte sequence but character 1 was '䍃€' (U+004343)} -test encoding-24.17 {Parse valid or invalid utf-8} -constraints {testbytestring deprecated} -body { +test encoding-24.17 {Parse valid or invalid utf-8} -constraints testbytestring -body { encoding convertto utf-8 [testbytestring "Z\xE0\x80"] } -result "Z\xC3\xA0\xE2\x82\xAC" -test encoding-24.18 {Parse valid or invalid utf-8} -constraints {testbytestring deprecated} -body { +test encoding-24.18 {Parse valid or invalid utf-8} -constraints testbytestring -body { encoding convertto utf-8 [testbytestring "Z\xE0\x80xxxxxx"] } -result "Z\xC3\xA0\xE2\x82\xACxxxxxx" test encoding-24.19 {Parse valid or invalid utf-8} -constraints deprecated -body { encoding convertto utf-8 "ZX\uD800" -} -returnCodes 1 -match glob -result "unexpected character at index 2: 'U+00D800'" +} -result ZX\xED\xA0\x80 test encoding-24.20 {Parse with -nocomplain but without providing encoding} { string length [encoding convertfrom -nocomplain "\x20"] } 1 -- cgit v0.12