summaryrefslogtreecommitdiffstats
path: root/tests/source.test
diff options
context:
space:
mode:
Diffstat (limited to 'tests/source.test')
-rw-r--r--tests/source.test67
1 files changed, 26 insertions, 41 deletions
diff --git a/tests/source.test b/tests/source.test
index f5f9f0f..dc3c2d8 100644
--- a/tests/source.test
+++ b/tests/source.test
@@ -4,22 +4,22 @@
# 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.
-# Copyright © 1994-1996 Sun Microsystems, Inc.
-# Copyright © 1998-2000 Scriptics Corporation.
+# Copyright (c) 1991-1993 The Regents of the University of California.
+# Copyright (c) 1994-1996 Sun Microsystems, Inc.
+# Copyright (c) 1998-2000 by Scriptics Corporation.
# Contributions from Don Porter, NIST, 2003. (not subject to US copyright)
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
-if {[catch {package require tcltest 2.5}]} {
- puts stderr "Skipping tests in [info script]. tcltest 2.5 required."
+if {[catch {package require tcltest 2.1}]} {
+ puts stderr "Skipping tests in [info script]. tcltest 2.1 required."
return
}
namespace eval ::tcl::test::source {
namespace import ::tcltest::*
-
+
test source-1.1 {source command} -setup {
set x "old x value"
set y "old y value"
@@ -103,15 +103,16 @@ test source-2.6 {source error conditions} -setup {
set sourcefile [makeFile {} _non_existent_]
removeFile _non_existent_
} -body {
- source $sourcefile
-} -match glob -result {couldn't read file "*_non_existent_": no such file or directory} \
- -errorCode {POSIX ENOENT {no such file or directory}}
+ list [catch {source $sourcefile} msg] $msg $::errorCode
+} -match listGlob -result [list 1 \
+ {couldn't read file "*_non_existent_": no such file or directory} \
+ {POSIX ENOENT {no such file or directory}}]
test source-2.7 {utf-8 with BOM} -setup {
set sourcefile [makeFile {} source.file]
} -body {
set out [open $sourcefile w]
fconfigure $out -encoding utf-8
- puts $out "\uFEFFset y new-y"
+ puts $out "\ufeffset y new-y"
close $out
set y old-y
source -encoding utf-8 $sourcefile
@@ -199,7 +200,7 @@ test source-4.1 {continuation line parsing} -setup {
test source-6.1 {source is binary ok} -setup {
# Note [makeFile] writes in the system encoding.
# [source] defaults to reading in the system encoding.
- set sourcefile [makeFile [list set x "a b\x00c"] source.file]
+ set sourcefile [makeFile [list set x "a b\0c"] source.file]
} -body {
set x {}
source $sourcefile
@@ -208,7 +209,7 @@ test source-6.1 {source is binary ok} -setup {
removeFile source.file
} -result 5
test source-6.2 {source skips everything after Ctrl-Z: Bug 2040} -setup {
- set sourcefile [makeFile "set x ab\x1Ac" source.file]
+ set sourcefile [makeFile "set x ab\32c" source.file]
} -body {
set x {}
source $sourcefile
@@ -222,7 +223,7 @@ test source-7.1 {source -encoding test} -setup {
file delete $sourcefile
set f [open $sourcefile w]
fconfigure $f -encoding utf-8
- puts $f "set symbol(square-root) √; set x correct"
+ puts $f "set symbol(square-root) \u221A; set x correct"
close $f
} -body {
set x unset
@@ -233,19 +234,19 @@ test source-7.1 {source -encoding test} -setup {
} -result correct
test source-7.2 {source -encoding test} -setup {
# This tests for bad interactions between [source -encoding]
- # and use of the Control-Z character (\x1A) as a cross-platform
+ # and use of the Control-Z character (\u001A) as a cross-platform
# EOF character by [source]. Here we write out and the [source] a
- # file that contains the byte \x1A, although not the character \x1A in
+ # file that contains the byte \x1A, although not the character \u001A in
# the indicated encoding.
set sourcefile [makeFile {} source.file]
file delete $sourcefile
set f [open $sourcefile w]
- fconfigure $f -encoding utf-16
- puts $f "set symbol(square-root) √; set x correct"
+ fconfigure $f -encoding unicode
+ puts $f "set symbol(square-root) \u221A; set x correct"
close $f
} -body {
set x unset
- source -encoding utf-16 $sourcefile
+ source -encoding unicode $sourcefile
set x
} -cleanup {
removeFile source.file
@@ -266,46 +267,30 @@ test source-7.5 {source -encoding: correct operation} -setup {
file delete $sourcefile
set f [open $sourcefile w]
fconfigure $f -encoding utf-8
- puts $f "proc € {} {return foo}"
+ puts $f "proc \u20ac {} {return foo}"
close $f
} -body {
source -encoding utf-8 $sourcefile
- €
+ \u20ac
} -cleanup {
removeFile source.file
- rename € {}
+ rename \u20ac {}
} -result foo
test source-7.6 {source -encoding: mismatch encoding error} -setup {
set sourcefile [makeFile {} source.file]
file delete $sourcefile
set f [open $sourcefile w]
fconfigure $f -encoding utf-8
- puts $f "proc € {} {return foo}"
+ puts $f "proc \u20ac {} {return foo}"
close $f
} -body {
- source -encoding iso8859-1 $sourcefile
- €
+ source -encoding ascii $sourcefile
+ \u20ac
} -cleanup {
removeFile source.file
-} -returnCodes error -result {invalid command name "€"}
+} -returnCodes error -match glob -result {invalid command name*}
-test source-8.1 {source and coroutine/yield} -setup {
- set sourcefile [makeFile {} source.file]
- file delete $sourcefile
-} -body {
- makeFile {yield 1; yield 2; return 3;} $sourcefile
- coroutine coro apply {f {yield;source $f}} $sourcefile
- list [coro] [coro] [coro] [info exist coro]
-} -cleanup {
- catch {rename coro {}}
- removeFile source.file
-} -result {1 2 3 0}
-
cleanupTests
}
namespace delete ::tcl::test::source
return
-
-# Local Variables:
-# mode: tcl
-# End: