diff options
Diffstat (limited to 'tests/source.test')
-rw-r--r-- | tests/source.test | 96 |
1 files changed, 75 insertions, 21 deletions
diff --git a/tests/source.test b/tests/source.test index db12707..641838c 100644 --- a/tests/source.test +++ b/tests/source.test @@ -18,12 +18,7 @@ if {[catch {package require tcltest 2.1}]} { } namespace eval ::tcl::test::source { - namespace import ::tcltest::test - namespace import ::tcltest::testConstraint - namespace import ::tcltest::cleanupTests - namespace import ::tcltest::makeFile - namespace import ::tcltest::removeFile - namespace import ::tcltest::customMatch + namespace import ::tcltest::* test source-1.1 {source command} -setup { set x "old x value" @@ -40,7 +35,6 @@ test source-1.1 {source command} -setup { } -cleanup { removeFile source.file } -result {22 33 44} - test source-1.2 {source command} -setup { set sourcefile [makeFile {list result} source.file] } -body { @@ -48,7 +42,6 @@ test source-1.2 {source command} -setup { } -cleanup { removeFile source.file } -result result - test source-1.3 {source command} -setup { set sourcefile [makeFile {} source.file] set fd [open $sourcefile w] @@ -92,7 +85,6 @@ test source-2.3 {source error conditions} -setup { (file "*source.file" line 3) invoked from within "source $sourcefile"}] - test source-2.4 {source error conditions} -setup { set sourcefile [makeFile {break} source.file] } -body { @@ -100,7 +92,6 @@ test source-2.4 {source error conditions} -setup { } -cleanup { removeFile source.file } -returnCodes break - test source-2.5 {source error conditions} -setup { set sourcefile [makeFile {continue} source.file] } -body { @@ -108,7 +99,6 @@ test source-2.5 {source error conditions} -setup { } -cleanup { removeFile source.file } -returnCodes continue - test source-2.6 {source error conditions} -setup { set sourcefile [makeFile {} _non_existent_] removeFile _non_existent_ @@ -117,21 +107,18 @@ test source-2.6 {source error conditions} -setup { } -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] - set saveencoding [encoding system] } -body { - encoding system utf-8 set out [open $sourcefile w] + fconfigure $out -encoding utf-8 puts $out "\ufeffset y new-y" close $out set y old-y - source $sourcefile + source -encoding utf-8 $sourcefile return $y } -cleanup { removeFile $sourcefile - encoding system $saveencoding } -result {new-y} test source-3.1 {return in middle of source file} -setup { @@ -148,7 +135,6 @@ test source-3.1 {return in middle of source file} -setup { } -cleanup { removeFile source.file } -result {new-x old-y allDone} - test source-3.2 {return with special code etc.} -setup { set sourcefile [makeFile { set x new-x @@ -160,7 +146,6 @@ test source-3.2 {return with special code etc.} -setup { } -cleanup { removeFile source.file } -returnCodes break -result {Silly result} - test source-3.3 {return with special code etc.} -setup { set sourcefile [makeFile { set x new-x @@ -174,7 +159,6 @@ test source-3.3 {return with special code etc.} -setup { } -result {1 {Simulated error} {Simulated error while executing "source $sourcefile"} NONE} - test source-3.4 {return with special code etc.} -setup { set sourcefile [makeFile { set x new-x @@ -188,7 +172,6 @@ test source-3.4 {return with special code etc.} -setup { } -result {1 {} {Simulated errorInfo stuff invoked from within "source $sourcefile"} NONE} - test source-3.5 {return with special code etc.} -setup { set sourcefile [makeFile { set x new-x @@ -215,7 +198,6 @@ test source-6.1 {source is binary ok} -setup { } -cleanup { removeFile source.file } -result 5 - test source-6.2 {source skips everything after Ctrl-Z: Bug 2040} -setup { set sourcefile [makeFile "set x ab\32c" source.file] } -body { @@ -226,6 +208,78 @@ test source-6.2 {source skips everything after Ctrl-Z: Bug 2040} -setup { removeFile source.file } -result 2 +test source-7.1 {source -encoding test} -setup { + set sourcefile [makeFile {} source.file] + file delete $sourcefile + set f [open $sourcefile w] + fconfigure $f -encoding utf-8 + puts $f "set symbol(square-root) \u221A; set x correct" + close $f +} -body { + set x unset + source -encoding utf-8 $sourcefile + set x +} -cleanup { + removeFile source.file +} -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 (\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 \u001A in + # the indicated encoding. + set sourcefile [makeFile {} source.file] + file delete $sourcefile + set f [open $sourcefile w] + fconfigure $f -encoding unicode + puts $f "set symbol(square-root) \u221A; set x correct" + close $f +} -body { + set x unset + source -encoding unicode $sourcefile + set x +} -cleanup { + removeFile source.file +} -result correct +test source-7.3 {source -encoding: syntax} -body { + # Have to spell out the -encoding option + source -e utf-8 no_file +} -returnCodes 1 -match glob -result {bad option*} +test source-7.4 {source -encoding: syntax} -setup { + set sourcefile [makeFile {} source.file] +} -body { + source -encoding no-such-encoding $sourcefile +} -cleanup { + removeFile source.file +} -returnCodes 1 -match glob -result {unknown encoding*} +test source-7.5 {source -encoding: correct operation} -setup { + set sourcefile [makeFile {} source.file] + file delete $sourcefile + set f [open $sourcefile w] + fconfigure $f -encoding utf-8 + puts $f "proc \u20ac {} {return foo}" + close $f +} -body { + source -encoding utf-8 $sourcefile + \u20ac +} -cleanup { + removeFile source.file + 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 \u20ac {} {return foo}" + close $f +} -body { + source -encoding ascii $sourcefile + \u20ac +} -cleanup { + removeFile source.file +} -returnCodes error -match glob -result {invalid command name*} + cleanupTests } namespace delete ::tcl::test::source |