Fossil SCM

Make utf.test work with Tcl 9. Not sure if this is the best fix, but it does seem to work with 8.6 as well under assorted inputs.

danshearer 2026-11-11 09:16 UTC test-suite-new
Commit ab45d34c9dd727cc609659cab15f8f50826c8efee958b0db121eb25288fe0575
1 file changed +28 -6
+28 -6
--- test/utf.test
+++ test/utf.test
@@ -285,30 +285,52 @@
285285
incr fn
286286
}
287287
}
288288
}
289289
}
290
+
291
+# Returns S converted to the encoding ENC. Tcl 9 refuses an unpaired
292
+# surrogate unless the conversion uses the tcl8 profile, which Tcl 8 does
293
+# not have.
294
+proc convert_to {enc s} {
295
+ if {[package vsatisfies [package provide Tcl] 9-]} {
296
+ return [encoding convertto -profile tcl8 $enc $s]
297
+ }
298
+ return [encoding convertto $enc $s]
299
+}
300
+
301
+# Returns the bytes that Tcl 8 writes for S to a channel in the binary
302
+# encoding: the low byte of each UTF-16 unit. Tcl 9 does not have the
303
+# binary encoding.
304
+proc binary_bytes {s} {
305
+ if {![package vsatisfies [package provide Tcl] 9-]} {
306
+ return $s
307
+ }
308
+ set format [expr {$::tcl_platform(byteOrder) eq "littleEndian" ? "s*" : "S*"}]
309
+ binary scan [convert_to unicode $s] $format units
310
+ return [binary format c* $units]
311
+}
290312
291313
proc createTestFiles {path num} {
292314
set fn $num
293315
for {set i 0} {$i < [array size ::bom]} {incr i} {
294316
for {set j 0} {$j < [array size ::data]} {incr j} {
295317
for {set k 0} {$k < [array size ::extraData]} {incr k} {
296318
set f [open [file join $path utf-check-$fn-$i-$j-$k.jnk] \
297319
{WRONLY CREAT TRUNC}]; incr fn
298
- fconfigure $f -encoding binary -translation binary
320
+ fconfigure $f -translation binary
299321
puts -nonewline $f $::bom($i)
300322
switch -exact $::enc($i) {
301323
binary {
302
- puts -nonewline $f $::data($j)
324
+ puts -nonewline $f [binary_bytes $::data($j)]
303325
}
304326
unicode-reverse {
305
- puts -nonewline $f [swap_byte_order \
306
- [encoding convertto unicode $::data($j)]]
327
+ puts -nonewline $f [binary_bytes \
328
+ [swap_byte_order [convert_to unicode $::data($j)]]]
307329
}
308330
default {
309
- puts -nonewline $f [encoding convertto $::enc($i) $::data($j)]
331
+ puts -nonewline $f [convert_to $::enc($i) $::data($j)]
310332
}
311333
}
312334
puts -nonewline $f $::extraData($k)
313335
flush $f; close $f
314336
}
@@ -326,11 +348,11 @@
326348
set f [open [file join $path utf-check.txt] {WRONLY CREAT APPEND}]
327349
set fn $num
328350
for {set i 0} {$i < [array size ::bom]} {incr i} {
329351
for {set j 0} {$j < [array size ::data]} {incr j} {
330352
for {set k 0} {$k < [array size ::extraData]} {incr k} {
331
- fconfigure $f -encoding binary -translation binary
353
+ fconfigure $f -translation binary
332354
set data \n\n
333355
append data {utf-check $fn }
334356
append data {utf-check-$fn-$i-$j-$k.jnk \\\n}
335357
append data {{%OUT%}}
336358
fossil test-looks-like-utf [file join $path utf-check-$fn-$i-$j-$k.jnk]
337359
--- test/utf.test
+++ test/utf.test
@@ -285,30 +285,52 @@
285 incr fn
286 }
287 }
288 }
289 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
290
291 proc createTestFiles {path num} {
292 set fn $num
293 for {set i 0} {$i < [array size ::bom]} {incr i} {
294 for {set j 0} {$j < [array size ::data]} {incr j} {
295 for {set k 0} {$k < [array size ::extraData]} {incr k} {
296 set f [open [file join $path utf-check-$fn-$i-$j-$k.jnk] \
297 {WRONLY CREAT TRUNC}]; incr fn
298 fconfigure $f -encoding binary -translation binary
299 puts -nonewline $f $::bom($i)
300 switch -exact $::enc($i) {
301 binary {
302 puts -nonewline $f $::data($j)
303 }
304 unicode-reverse {
305 puts -nonewline $f [swap_byte_order \
306 [encoding convertto unicode $::data($j)]]
307 }
308 default {
309 puts -nonewline $f [encoding convertto $::enc($i) $::data($j)]
310 }
311 }
312 puts -nonewline $f $::extraData($k)
313 flush $f; close $f
314 }
@@ -326,11 +348,11 @@
326 set f [open [file join $path utf-check.txt] {WRONLY CREAT APPEND}]
327 set fn $num
328 for {set i 0} {$i < [array size ::bom]} {incr i} {
329 for {set j 0} {$j < [array size ::data]} {incr j} {
330 for {set k 0} {$k < [array size ::extraData]} {incr k} {
331 fconfigure $f -encoding binary -translation binary
332 set data \n\n
333 append data {utf-check $fn }
334 append data {utf-check-$fn-$i-$j-$k.jnk \\\n}
335 append data {{%OUT%}}
336 fossil test-looks-like-utf [file join $path utf-check-$fn-$i-$j-$k.jnk]
337
--- test/utf.test
+++ test/utf.test
@@ -285,30 +285,52 @@
285 incr fn
286 }
287 }
288 }
289 }
290
291 # Returns S converted to the encoding ENC. Tcl 9 refuses an unpaired
292 # surrogate unless the conversion uses the tcl8 profile, which Tcl 8 does
293 # not have.
294 proc convert_to {enc s} {
295 if {[package vsatisfies [package provide Tcl] 9-]} {
296 return [encoding convertto -profile tcl8 $enc $s]
297 }
298 return [encoding convertto $enc $s]
299 }
300
301 # Returns the bytes that Tcl 8 writes for S to a channel in the binary
302 # encoding: the low byte of each UTF-16 unit. Tcl 9 does not have the
303 # binary encoding.
304 proc binary_bytes {s} {
305 if {![package vsatisfies [package provide Tcl] 9-]} {
306 return $s
307 }
308 set format [expr {$::tcl_platform(byteOrder) eq "littleEndian" ? "s*" : "S*"}]
309 binary scan [convert_to unicode $s] $format units
310 return [binary format c* $units]
311 }
312
313 proc createTestFiles {path num} {
314 set fn $num
315 for {set i 0} {$i < [array size ::bom]} {incr i} {
316 for {set j 0} {$j < [array size ::data]} {incr j} {
317 for {set k 0} {$k < [array size ::extraData]} {incr k} {
318 set f [open [file join $path utf-check-$fn-$i-$j-$k.jnk] \
319 {WRONLY CREAT TRUNC}]; incr fn
320 fconfigure $f -translation binary
321 puts -nonewline $f $::bom($i)
322 switch -exact $::enc($i) {
323 binary {
324 puts -nonewline $f [binary_bytes $::data($j)]
325 }
326 unicode-reverse {
327 puts -nonewline $f [binary_bytes \
328 [swap_byte_order [convert_to unicode $::data($j)]]]
329 }
330 default {
331 puts -nonewline $f [convert_to $::enc($i) $::data($j)]
332 }
333 }
334 puts -nonewline $f $::extraData($k)
335 flush $f; close $f
336 }
@@ -326,11 +348,11 @@
348 set f [open [file join $path utf-check.txt] {WRONLY CREAT APPEND}]
349 set fn $num
350 for {set i 0} {$i < [array size ::bom]} {incr i} {
351 for {set j 0} {$j < [array size ::data]} {incr j} {
352 for {set k 0} {$k < [array size ::extraData]} {incr k} {
353 fconfigure $f -translation binary
354 set data \n\n
355 append data {utf-check $fn }
356 append data {utf-check-$fn-$i-$j-$k.jnk \\\n}
357 append data {{%OUT%}}
358 fossil test-looks-like-utf [file join $path utf-check-$fn-$i-$j-$k.jnk]
359

Keyboard Shortcuts

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