⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.test

📁 tcl是工具命令语言
💻 TEST
📖 第 1 页 / 共 2 页
字号:
# This file contains a collection of tests for generic/tclMain.c.## RCS: @(#) $Id$if {[catch {package require tcltest 2.0.2}]} {    puts stderr "Skipping tests in [info script]. tcltest 2.0.2 required."    return}namespace eval ::tcl::test::main {    namespace import ::tcltest::test    namespace import ::tcltest::testConstraint    namespace import ::tcltest::interpreter    namespace import ::tcltest::cleanupTests    namespace import ::tcltest::makeFile    namespace import ::tcltest::removeFile    namespace import ::tcltest::temporaryDirectory    namespace import ::tcltest::workingDirectory    # Is [exec] defined?    testConstraint exec [llength [info commands exec]]    # Is the Tcltest package loaded?    #	- that is, the special C-coded testing commands in tclTest.c    #   - tests use testing commands introduced in Tcltest 8.4    testConstraint Tcltest [expr {	[llength [package provide Tcltest]]	&& [package vsatisfies [package provide Tcltest] 8.4]}]    # Procedure to simulate interactive typing of commands, line by line    proc type {chan script} {	foreach line [split $script \n] {	    if {[catch {	        puts $chan $line	        flush $chan	    }]} {		return	    }	    # Grrr... Behavior depends on this value.	    after 1000	}    }    cd [temporaryDirectory]    # Tests Tcl_Main-1.*: variable initializations    test Tcl_Main-1.1 {	Tcl_Main: startup script - normal    } -constraints {	stdio    } -setup {	makeFile {puts [list $argv0 $argv $tcl_interactive]} script	catch {set f [open "|[list [interpreter] script]" r]}    } -body {	read $f    } -cleanup {	close $f	removeFile script    } -result [list script {} 0]\n    test Tcl_Main-1.2 {	Tcl_Main: startup script - can't begin with '-'    } -constraints {	stdio    } -setup {	makeFile {puts [list $argv0 $argv $tcl_interactive]} -script	catch {set f [open "|[list [interpreter] -script]" w+]}    } -body {	puts $f {puts [list $argv0 $argv $tcl_interactive]; exit}	flush $f	read $f    } -cleanup {	close $f	removeFile -script    } -result [list [interpreter] -script 0]\n    test Tcl_Main-1.3 {	Tcl_Main: encoding of arguments: done by system encoding	Note the shortcoming explained in Tcl Feature Request 491789    } -constraints {	stdio    } -setup {	makeFile {puts [list $argv0 $argv $tcl_interactive]} script	catch {set f [open "|[list [interpreter] script \u00c0]" r]}    } -body {	read $f    } -cleanup {	close $f	removeFile script    } -result [list script [list [encoding convertfrom [encoding system] \	[encoding convertto [encoding system] \u00c0]]] 0]\n    test Tcl_Main-1.4 {	Tcl_Main: encoding of arguments: done by system encoding	Note the shortcoming explained in Tcl Feature Request 491789    } -constraints {	stdio tempNotWin    } -setup {	makeFile {puts [list $argv0 $argv $tcl_interactive]} script	catch {set f [open "|[list [interpreter] script \u20ac]" r]}    } -body {	read $f    } -cleanup {	close $f	removeFile script    } -result [list script [list [encoding convertfrom [encoding system] \	[encoding convertto [encoding system] \u20ac]]] 0]\n    test Tcl_Main-1.5 {	Tcl_Main: encoding of script name: system encoding loss	Note the shortcoming explained in Tcl Feature Request 491789    } -constraints {	stdio    } -setup {	makeFile {puts [list $argv0 $argv $tcl_interactive]} \u00c0	catch {set f [open "|[list [interpreter] \u00c0]" r]}    } -body {	read $f    } -cleanup {	close $f	removeFile \u00c0    } -result [list [list [encoding convertfrom [encoding system] \	[encoding convertto [encoding system] \u00c0]]] {} 0]\n    test Tcl_Main-1.6 {	Tcl_Main: encoding of script name: system encoding loss	Note the shortcoming explained in Tcl Feature Request 491789    } -constraints {	stdio tempNotWin    } -setup {	makeFile {puts [list $argv0 $argv $tcl_interactive]} \u20ac	catch {set f [open "|[list [interpreter] \u20ac]" r]}    } -body {	read $f    } -cleanup {	close $f	removeFile \u20ac    } -result [list [list [encoding convertfrom [encoding system] \	[encoding convertto [encoding system] \u20ac]]] {} 0]\n    # Tests Tcl_Main-2.*: application-initialization procedure    test Tcl_Main-2.1 {	Tcl_Main: appInitProc returns error    } -constraints {	exec Tcltest    } -setup {	makeFile {puts "In script"} script    } -body {	exec [interpreter] script -appinitprocerror >& result	set f [open result]	read $f    } -cleanup {	close $f	file delete result	removeFile script    } -result "application-specific initialization failed: \nIn script\n"    test Tcl_Main-2.2 {	Tcl_Main: appInitProc returns error    } -constraints {	exec Tcltest    } -body {	exec [interpreter] << {puts "In script"} -appinitprocerror >& result	set f [open result]	read $f    } -cleanup {	close $f	file delete result    } -result "application-specific initialization failed: \nIn script\n"    test Tcl_Main-2.3 {	Tcl_Main: appInitProc deletes interp    } -constraints {	exec Tcltest    } -setup {	makeFile {puts "In script"} script    } -body {	exec [interpreter] script -appinitprocdeleteinterp >& result	set f [open result]	read $f    } -cleanup {	close $f	file delete result	removeFile script    } -result "application-specific initialization failed: \n"    test Tcl_Main-2.4 {	Tcl_Main: appInitProc deletes interp    } -constraints {	exec Tcltest    } -body {	exec [interpreter] << {puts "In script"} \		-appinitprocdeleteinterp >& result	set f [open result]	read $f    } -cleanup {	close $f	file delete result    } -result "application-specific initialization failed: \n"    test Tcl_Main-2.5 {	Tcl_Main: appInitProc closes stderr    } -constraints {	exec Tcltest    } -body {	exec [interpreter] << {puts "In script"} \		-appinitprocclosestderr >& result	set f [open result]	read $f    } -cleanup {	close $f	file delete result    } -result "In script\n"    # Tests Tcl_Main-3.*: startup script evaluation    test Tcl_Main-3.1 {	Tcl_Main: startup script does not exist    } -constraints {	exec    } -setup {	if {[file exists no-such-file]} {	    error "Can't run test Tcl_Main-3.1\		    where a file named \"no-such-file\" exists"	}    } -body {	set code [catch {exec [interpreter] no-such-file >& result} result]	set f [open result]	list $code $result [read $f]    } -cleanup {	close $f	file delete result    } -match glob -result [list 1 {child process exited abnormally} \	{couldn't read file "no-such-file":*}]    test Tcl_Main-3.2 {	Tcl_Main: startup script raises error    } -constraints {	exec    } -setup {	makeFile {error ERROR} script    } -body {	set code [catch {exec [interpreter] script >& result} result]	set f [open result]	list $code $result [read $f]    } -cleanup {	close $f	file delete result	removeFile script    } -match glob -result [list 1 {child process exited abnormally} \	"ERROR\n    while executing*"]    test Tcl_Main-3.3 {	Tcl_Main: startup script closes stderr    } -constraints {	exec    } -setup {	makeFile {close stderr; error ERROR} script    } -body {	set code [catch {exec [interpreter] script >& result} result]	set f [open result]	list $code $result [read $f]    } -cleanup {	close $f	file delete result	removeFile script    } -result [list 1 {child process exited abnormally} {}]    test Tcl_Main-3.4 {	Tcl_Main: startup script holds incomplete script    } -constraints {	exec    } -setup {	makeFile "if 1 \{" script    } -body {	set code [catch {exec [interpreter] script >& result} result]	set f [open result]	join [list $code $result [read $f]] \n    } -cleanup {	close $f	file delete result	removeFile script    } -match glob -result [join [list 1 {child process exited abnormally}\	"missing close-brace\n    while executing*"] \n]    test Tcl_Main-3.5 {	Tcl_Main: startup script sets main loop    } -constraints {	exec Tcltest    } -setup {	makeFile {		rename exit _exit		proc exit {code} {		    puts "In exit"		    _exit $code		}		after 0 {			puts event			testexitmainloop		}		testexithandler create 0		testsetmainloop	} script    } -body {	exec [interpreter] script >& result	set f [open result]	read $f    } -cleanup {	close $f	file delete result	removeFile script    } -result "event\nExit MainLoop\nIn exit\neven 0\n"    test Tcl_Main-3.6 {	Tcl_Main: startup script sets main loop and closes stdin    } -constraints {	exec Tcltest    } -setup {	makeFile {		close stdin		testsetmainloop		rename exit _exit		proc exit {code} {		    puts "In exit"		    _exit $code		}		after 0 {			puts event			testexitmainloop		}		testexithandler create 0	} script    } -body {	exec [interpreter] script >& result	set f [open result]	read $f    } -cleanup {	close $f	file delete result	removeFile script    } -result "event\nExit MainLoop\nIn exit\neven 0\n"    test Tcl_Main-3.7 {	Tcl_Main: startup script deletes interp    } -constraints {	exec Tcltest    } -setup {	makeFile {		rename exit _exit		proc exit {code} {		    puts "In exit"		    _exit $code		}		testexithandler create 0		testinterpdelete {}	} script    } -body {	exec [interpreter] script >& result	set f [open result]	read $f    } -cleanup {	close $f	file delete result	removeFile script    } -result "even 0\n"    test Tcl_Main-3.8 {	Tcl_Main: startup script deletes interp and sets mainloop    } -constraints {	exec Tcltest    } -setup {	makeFile {		testsetmainloop		rename exit _exit		proc exit {code} {		    puts "In exit"		    _exit $code		}		testexitmainloop		testexithandler create 0		testinterpdelete {}	} script    } -body {	exec [interpreter] script >& result	set f [open result]	read $f    } -cleanup {	close $f	file delete result	removeFile script    } -result "Exit MainLoop\neven 0\n"    test Tcl_Main-3.9 {	Tcl_Main: startup script can set tcl_interactive without limit    } -constraints {	exec    } -setup {	makeFile {set tcl_interactive foo} script    } -body {	exec [interpreter] script >& result	set f [open result]	read $f    } -cleanup {	close $f	file delete result	removeFile script    } -result {}    # Tests Tcl_Main-4.*: rc file evaluation    test Tcl_Main-4.1 {	Tcl_Main: rcFile evaluation deletes interp    } -constraints {	exec Tcltest    } -setup {	set rc [makeFile {testinterpdelete {}} rc]    } -body {	exec [interpreter] << {puts "In script"} \		-appinitprocsetrcfile $rc >& result	set f [open result]	read $f    } -cleanup {	close $f	file delete result	removeFile rc    } -result "application-specific initialization failed: \n"    test Tcl_Main-4.2 {	Tcl_Main: rcFile evaluation closes stdin    } -constraints {	exec Tcltest    } -setup {	set rc [makeFile {close stdin} rc]    } -body {	exec [interpreter] << {puts "In script"} \		-appinitprocsetrcfile $rc >& result	set f [open result]	read $f    } -cleanup {	close $f	file delete result	removeFile rc    } -result "application-specific initialization failed: \n"    test Tcl_Main-4.3 {	Tcl_Main: rcFile evaluation closes stdin and sets main loop    } -constraints {	exec Tcltest    } -setup {	set rc [makeFile {		close stdin		testsetmainloop		after 0 testexitmainloop		testexithandler create 0		rename exit _exit		proc exit code {		    puts "In exit"		    _exit $code		}	} rc]    } -body {	exec [interpreter] << {puts "In script"} \		-appinitprocsetrcfile $rc >& result	set f [open result]	read $f    } -cleanup {	close $f	file delete result	removeFile rc    } -result "application-specific initialization failed:\	\nExit MainLoop\nIn exit\neven 0\n"    test Tcl_Main-4.4 {	Tcl_Main: rcFile evaluation sets main loop    } -constraints {	exec Tcltest    } -setup {	set rc [makeFile {		testsetmainloop		after 0 testexitmainloop		testexithandler create 0		rename exit _exit		proc exit code {		    puts "In exit"		    _exit $code		}	} rc]    } -body {	exec [interpreter] << {puts "In script"} \		-appinitprocsetrcfile $rc >& result	set f [open result]	read $f    } -cleanup {	close $f	file delete result	removeFile rc    } -result "application-specific initialization failed:\	\nIn script\nExit MainLoop\nIn exit\neven 0\n"    # Tests Tcl_Main-5.*: interactive operations    test Tcl_Main-5.1 {	Tcl_Main: tcl_interactive must be boolean    } -constraints {	exec    } -body {	exec [interpreter] << {set tcl_interactive foo} >& result	set f [open result]	read $f    } -cleanup {	close $f	file delete result    } -result "can't set \"tcl_interactive\":\	     variable must have boolean value\n"    test Tcl_Main-5.2 {	Tcl_Main able to handle non-blocking stdin    } -constraints {	exec    } -setup {	catch {set f [open "|[list [interpreter]]" w+]}    } -body {	type $f {	    fconfigure stdin -blocking 0	    puts SUCCESS	}	list [catch {gets $f} line] $line    } -cleanup {	close $f    } -result [list 0 SUCCESS]    test Tcl_Main-5.3 {	Tcl_Main handles stdin EOF in mid-command    } -constraints {	exec    } -setup {	catch {set f [open "|[list [interpreter]]" w+]}	catch {fconfigure $f -blocking 0}    } -body {	type $f "fconfigure stdin -eofchar \\032	    if 1 \{\n\032"	variable wait	fileevent $f readable \		[list set [namespace which -variable wait] "child exit"]	set id [after 2000 [list set [namespace which -variable wait] timeout]]	vwait [namespace which -variable wait]	after cancel $id	set wait    } -cleanup {	if {[string equal timeout $wait]		&& [string equal unix $::tcl_platform(platform)]} {	    exec kill [pid $f]	}	close $f    } -result {child exit}    test Tcl_Main-5.4 {	Tcl_Main handles stdin EOF in mid-command    } -constraints {	exec    } -setup {	set cmd {makeFile "if 1 \{" script}	catch {set f [open "|[list [interpreter]] < [list [eval $cmd]]" r]}	catch {fconfigure $f -blocking 0}    } -body {	variable wait	fileevent $f readable \		[list set [namespace which -variable wait] "child exit"]	set id [after 2000 [list set [namespace which -variable wait] timeout]]	vwait [namespace which -variable wait]	after cancel $id	set wait    } -cleanup {	if {[string equal timeout $wait]		&& [string equal unix $::tcl_platform(platform)]} {	    exec kill [pid $f]	}	close $f	removeFile script    } -result {child exit}    test Tcl_Main-5.5 {	Tcl_Main: error raised in interactive mode    } -constraints {	exec    } -body {	exec [interpreter] << {error foo} >& result	set f [open result]	read $f    } -cleanup {	close $f

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -