Diff
Not logged in

Differences From Artifact [1f7a4a7241]:

To Artifact [67828e1e6b]:


7496
7497
7498
7499
7500
7501
7502
7503

7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519


7520
7521
7522
7523
7524
7525
7526
7496
7497
7498
7499
7500
7501
7502

7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518

7519
7520
7521
7522
7523
7524
7525
7526
7527







-
+















-
+
+







    close $in
    close $out

    list [file size $path(kyrillic.txt)] \
	    [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 -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]

    fconfigure $in  -encoding koi8-r -translation lf
    # -translation binary is also -encoding binary
    fconfigure $out -translation binary

    fcopy $in $out
    close $in
    close $out

    file size $path(utf8-fcopy.txt)
} 5
} -returnCodes 1 -match glob -result {error writing "*":\
    invalid or incomplete multibyte or wide character}
test io-52.11 {TclCopyChannel & encodings} -setup {
    set out [open $path(utf8-fcopy.txt) w]
    fconfigure $out -encoding utf-8 -translation lf -profile strict
    puts $out АА
    close $out
} -constraints {fcopy} -body {
    set in  [open $path(utf8-fcopy.txt) r]
8370
8371
8372
8373
8374
8375
8376
8377

8378
8379
8380
8381
8382
8383
8384
8371
8372
8373
8374
8375
8376
8377

8378
8379
8380
8381
8382
8383
8384
8385







-
+







    set out [open $outFile wb]
    chan copy $in $out
} -cleanup {
    catch {close $in}
    catch {close $out}
    removeFile out
    rename driver {}
} -result {error reading "*": *} -returnCodes error -match glob
} -result {error reading "rc*": *} -returnCodes error -match glob
test io-53.14 {TclCopyChannel: write error reporting} -setup {
    proc driver {cmd args} {
        variable buffer
        variable index
        set chan [lindex $args 0]
        switch -- $cmd {
            initialize {
9260
9261
9262
9263
9264
9265
9266
9267

9268
9269
9270
9271
9272
9273
9274
9275
9276
9277
9278
9279
9280
9281


9282
9283
9284
9285
9286
9287
9288
9289
9290
9291
9292
9293
9294
9295
9296
9297


9298
9299
9300
9301
9302
9303
9304
9261
9262
9263
9264
9265
9266
9267

9268
9269
9270
9271
9272
9273
9274
9275
9276
9277
9278
9279
9280
9281

9282
9283
9284
9285
9286
9287
9288
9289
9290
9291
9292
9293
9294
9295
9296
9297
9298

9299
9300
9301
9302
9303
9304
9305
9306
9307







-
+













-
+
+















-
+
+







    binary scan $d H* hd
    set hd
} -cleanup {
    close $f
    removeFile io-75.5
} -result 4181

test io-75.6 {invalid utf-8 encoding gets is not ignored (-profile strict)} -setup {
test io-75.6 {invalid utf-8 encoding, gets is not ignored (-profile 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 -profile strict
} -body {
    gets $f
} -cleanup {
    close $f
    removeFile io-75.6
} -match glob -returnCodes 1 -result {error reading "*": invalid or incomplete multibyte or wide character}
} -match glob -returnCodes 1 -result {error reading "file*":\
	invalid or incomplete multibyte or wide character}

test io-75.7 {invalid utf-8 encoding gets is not ignored (-profile strict)} -setup {
    set fn [makeFile {} io-75.7]
    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 -profile strict
} -body {
    read $f
} -cleanup {
    close $f
    removeFile io-75.7
} -match glob -returnCodes 1 -result {error reading "*": invalid or incomplete multibyte or wide character}
} -match glob -returnCodes 1 -result {error reading "file*":\
    invalid or incomplete multibyte or wide character}

test io-75.8 {invalid utf-8 encoding eof handling (-profile strict)} -setup {
    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
9326
9327
9328
9329
9330
9331
9332
9333

9334
9335
9336




9337
9338
9339
9340
9341
9342
9343
9344




9345
9346

9347

9348
9349
9350
9351




9352
9353
9354
9355
9356
9357
9358
9329
9330
9331
9332
9333
9334
9335

9336



9337
9338
9339
9340
9341
9342
9343
9344
9345
9346
9347
9348
9349
9350
9351
9352
9353
9354
9355

9356
9357
9358
9359

9360
9361
9362
9363
9364
9365
9366
9367
9368
9369
9370







-
+
-
-
-
+
+
+
+








+
+
+
+


+
-
+



-
+
+
+
+







    seek $f 0
    list [read $f] $msg
} -cleanup {
    close $f
    removeFile io-75.9
} -match glob -result [list {A} {error writing "*": invalid or incomplete multibyte or wide character}]

# Incomplete sequence test.
test io-75.10 {
# 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 {
    incomplete multibyte encoding read is not ignored because "binary" sets
    profile to strict
} -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 -buffering none
} -body {
    catch {read $f} errmsg
    lappend res $errmsg
    seek $f 0
    chan configure $f -profile tcl8
    set d [read $f]
    binary scan $d H* hd
    lappend res $hd
    set hd
    return $res
} -cleanup {
    close $f
    removeFile io-75.10
} -result 41c0
    unset result
} -match glob -result {{error reading "file*":\
    invalid or incomplete multibyte or wide character} 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]
9368
9369
9370
9371
9372
9373
9374
9375


9376
9377





9378
9379
9380
9381
9382
9383
9384
9385




9386
9387

9388

9389
9390
9391
9392



9393
9394
9395
9396
9397
9398
9399
9400
9401
9402
9403
9404
9405
9406
9407
9408
9409
9410

9411
9412
9413
9414
9415
9416
9417
9380
9381
9382
9383
9384
9385
9386

9387
9388
9389

9390
9391
9392
9393
9394
9395
9396
9397
9398
9399
9400
9401
9402
9403
9404
9405
9406
9407
9408
9409

9410
9411
9412
9413

9414
9415
9416
9417
9418
9419
9420
9421
9422
9423
9424
9425
9426
9427
9428
9429
9430
9431
9432
9433

9434
9435
9436
9437
9438
9439
9440
9441







-
+
+

-
+
+
+
+
+








+
+
+
+


+
-
+



-
+
+
+

















-
+







    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 "*": invalid or incomplete multibyte or wide character}}
} -match glob -result {41 1 {error reading "file*":\
    invalid or incomplete multibyte or wide character}}

test io-75.12 {invalid utf-8 encoding read is ignored} -setup {
test io-75.12 {
    invalid utf-8 encoding read is not ignored because setting the encoding to
    "binary" also set the profile to strict
} -setup {
    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
} -body {
    catch {read $f} errmsg
    lappend res $errmsg
    chan configure $f -profile tcl8
    seek $f 0
    set d [read $f]
    binary scan $d H* hd
    lappend res $hd
    set hd
    return $res
} -cleanup {
    close $f
    removeFile io-75.12
} -result 4181
    unset res
} -match glob -result {{error reading "file*":\
    invalid or incomplete multibyte or wide character} 4181}
test io-75.13 {invalid utf-8 encoding read is not ignored (-profile strict)} -setup {
    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 -blocking 0 -eofchar "" -translation lf -profile strict
} -body {
    set d [read $f]
    binary scan $d H* hd
    lappend hd [catch {read $f} msg]
    lappend hd $msg
} -cleanup {
    close $f
    removeFile io-75.13
} -match glob -result {41 1 {error reading "*": invalid or incomplete multibyte or wide character}}
} -match glob -result {41 1 {error reading "file*": invalid or incomplete multibyte or wide character}}

# ### ### ### ######### ######### #########



test io-76.0 {channel modes} -setup {
    set datafile [makeFile {some characters} dummy]