1# This file contains tests for tclUnixNotfy.c. 2# 3# This file contains a collection of tests for one or more of the Tcl 4# built-in commands. Sourcing this file into Tcl runs the tests and 5# generates output for errors. No output means no errors were found. 6# 7# Copyright © 1997 Sun Microsystems, Inc. 8# Copyright © 1998-1999 Scriptics Corporation. 9# 10# See the file "license.terms" for information on usage and redistribution 11# of this file, and for a DISCLAIMER OF ALL WARRANTIES. 12 13if {"::tcltest" ni [namespace children]} { 14 package require tcltest 2.5 15 namespace import -force ::tcltest::* 16} 17 18# When run in a Tk shell, these tests hang. 19testConstraint noTk [expr {0 != [catch {package present Tk}]}] 20testConstraint thread [expr {0 == [catch {package require Thread 2.7-}]}] 21 22# The next two tests will hang if threads are enabled because the notifier 23# will not necessarily wait for ever in this case, so it does not generate 24# an error. 25test unixNotfy-1.1 {Tcl_DeleteFileHandler} -constraints nonPortable -body { 26 catch {vwait x} 27 set f [open [makeFile "" foo] w] 28 fileevent $f writable {set x 1} 29 vwait x 30 close $f 31 list [catch {vwait x} msg] $msg 32} -result {1 {can't wait for variable "x": would wait forever}} -cleanup { 33 catch { close $f } 34 catch { removeFile foo } 35} 36test unixNotfy-1.2 {Tcl_DeleteFileHandler} -constraints nonPortable -body { 37 catch {vwait x} 38 set f1 [open [makeFile "" foo] w] 39 set f2 [open [makeFile "" foo2] w] 40 fileevent $f1 writable {set x 1} 41 fileevent $f2 writable {set y 1} 42 vwait x 43 close $f1 44 vwait y 45 close $f2 46 list [catch {vwait x} msg] $msg 47} -result {1 {can't wait for variable "x": would wait forever}} -cleanup { 48 catch { close $f1 } 49 catch { close $f2 } 50 catch { removeFile foo } 51 catch { removeFile foo2 } 52} 53 54test unixNotfy-2.1 {Tcl_DeleteFileHandler} \ 55 -constraints {noTk unix thread} \ 56 -body { 57 update 58 set f [open [makeFile "" foo] w] 59 fileevent $f writable {set x 1} 60 vwait x 61 close $f 62 thread::create "thread::send [thread::id] {set x ok}" 63 vwait x 64 set x 65 } \ 66 -result {ok} \ 67 -cleanup { 68 catch { close $f } 69 catch { removeFile foo } 70 } 71test unixNotfy-2.2 {Tcl_DeleteFileHandler} \ 72 -constraints {noTk unix thread} \ 73 -body { 74 update 75 set f1 [open [makeFile "" foo] w] 76 set f2 [open [makeFile "" foo2] w] 77 fileevent $f1 writable {set x 1} 78 fileevent $f2 writable {set y 1} 79 vwait x 80 close $f1 81 vwait y 82 close $f2 83 thread::create "thread::send [thread::id] {set x ok}" 84 vwait x 85 set x 86 } \ 87 -result {ok} \ 88 -cleanup { 89 catch { close $f1 } 90 catch { close $f2 } 91 catch { removeFile foo } 92 catch { removeFile foo2 } 93 } 94 95# cleanup 96::tcltest::cleanupTests 97return 98