Tcl Source Code

Check-in [706b8f486c]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Eliminate tcltest::fileEncoding, not a good idea
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | main
Files: files | file ages | folders
SHA3-256: 706b8f486c23340eb8afb274702dd65ae1c0b2ac0aa480ffc0786da080c2a0b1
User & Date: jan.nijtmans 2024-03-28 21:46:38
Context
2024-03-29
08:53
Upgrade provided libtommath with version 1.3. Still works with external libtommath 1.2 too. check-in: ee93e76625 user: jan.nijtmans tags: trunk, main
2024-03-28
21:46
Eliminate tcltest::fileEncoding, not a good idea check-in: 706b8f486c user: jan.nijtmans tags: trunk, main
21:39
Merge 8.6 check-in: a358975f05 user: jan.nijtmans tags: core-8-branch
2024-03-27
20:43
merge 8.7 (conflicts solved, merge point) check-in: 692ac81a3a user: sebres tags: trunk, main
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to library/tcltest/tcltest.tcl.

2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
    if {[llength $matchDirs] == 0} {
	DebugPuts 1 "No test directories remain after applying match\
		and skip patterns!"
    }
    return [lsort $matchDirs]
}

# tcltest::fileEncoding --
#
#	checks the file contains BOM (or coding header)
#	and returns -encoding utf-8 (or enconding),
#	otherwise an empty list
#
#	Typical header for coding:
#		# -*- coding: utf-8 -*-
#
#	For similarity with Tcl this will be also supported:
#		# -encoding utf-8 ...
#		#!/usr/bin/env tclsh -encoding utf-8 ...
#
# Arguments:
#	name of the file to check encoding
#
# Results:
#	-encoding utf-8, -encoding $enc or empty
#
# Side effects:
#	None.

proc tcltest::fileEncoding {name} {
    variable fullutf

    set f [open $name rb]
    try {
	set buf [read $f 3]
	# contains BOM?
	if {$buf eq "\xEF\xBB\xBF"} {
	    return {-encoding utf-8}
	}
	# read 2 lines in header (may contain shebang and coding hereafter):
	append buf [gets $f] \n [gets $f]
	if {[regexp -line {^#+(?:!\S+(?: \S+){0,2})? [-\*\s]*(?:en)?coding:? ([\w\-]+)} $buf {} enc]} {
	    return [list -encoding $enc]
	}
    } finally {
	close $f
    }
    return {}
}

# tcltest::runAllTests --
#
#	prints output and sources test files according to the match and
#	skip patterns provided.  after sourcing test files, it goes on
#	to source all.tcl files in matching test subdirectories.
#
# Arguments:







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







2840
2841
2842
2843
2844
2845
2846











































2847
2848
2849
2850
2851
2852
2853
    if {[llength $matchDirs] == 0} {
	DebugPuts 1 "No test directories remain after applying match\
		and skip patterns!"
    }
    return [lsort $matchDirs]
}












































# tcltest::runAllTests --
#
#	prints output and sources test files according to the match and
#	skip patterns provided.  after sourcing test files, it goes on
#	to source all.tcl files in matching test subdirectories.
#
# Arguments:
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979

    # Run each of the specified tests
    foreach file [lsort [GetMatchingFiles]] {
	set tail [file tail $file]
	puts [outputChannel] $tail
	flush [outputChannel]

	# get encoding of file (BOM or coding in header):
	set fenc [fileEncoding $file]

	if {[singleProcess]} {
	    if {[catch {
		incr numTestFiles
		uplevel 1 [list ::source {*}$fenc $file]
	    } msg]} {
		puts [outputChannel] "Test file error: $msg"
		# append the name of the test to a list to be reported
		# later
		lappend testFileFailures $file
	    }
	    if {$numTests(Failed) > 0} {







<
<
<



|







2916
2917
2918
2919
2920
2921
2922



2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933

    # Run each of the specified tests
    foreach file [lsort [GetMatchingFiles]] {
	set tail [file tail $file]
	puts [outputChannel] $tail
	flush [outputChannel]




	if {[singleProcess]} {
	    if {[catch {
		incr numTestFiles
		uplevel 1 [list ::source $file]
	    } msg]} {
		puts [outputChannel] "Test file error: $msg"
		# append the name of the test to a list to be reported
		# later
		lappend testFileFailures $file
	    }
	    if {$numTests(Failed) > 0} {
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
		set value [Configure $opt]
		# Don't bother passing default configuration options
		if {$value eq $DefaultValue($opt)} {
			continue
		}
		lappend childargv $opt $value
	    }
	    set cmd [linsert $childargv 0 | $shell {*}$fenc $file]
	    if {[catch {
		incr numTestFiles
		set pipeFd [open $cmd "r"]
		if {$fullutf} {
		    fconfigure $pipeFd -profile tcl8 -encoding utf-8
		}
		while {[gets $pipeFd line] >= 0} {







|







2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
		set value [Configure $opt]
		# Don't bother passing default configuration options
		if {$value eq $DefaultValue($opt)} {
			continue
		}
		lappend childargv $opt $value
	    }
	    set cmd [linsert $childargv 0 | $shell $file]
	    if {[catch {
		incr numTestFiles
		set pipeFd [open $cmd "r"]
		if {$fullutf} {
		    fconfigure $pipeFd -profile tcl8 -encoding utf-8
		}
		while {[gets $pipeFd line] >= 0} {

Changes to tests/string.test.

1
2
3
4
5
6
7
8
9
# -*- coding: utf-8 -*-
#
# Commands covered:  string
#
# This file contains a collection of tests for one or more of the Tcl
# built-in commands.  Sourcing this file into Tcl runs the tests and
# generates output for errors.  No output means no errors were found.
#
# Copyright © 1991-1993 The Regents of the University of California.
<
<









1
2
3
4
5
6
7


# Commands covered:  string
#
# This file contains a collection of tests for one or more of the Tcl
# built-in commands.  Sourcing this file into Tcl runs the tests and
# generates output for errors.  No output means no errors were found.
#
# Copyright © 1991-1993 The Regents of the University of California.