Debian Codegraph @

tests/unixNotfy.test

raw
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 (c) 1997 by Sun Microsystems, Inc.
8 # Copyright (c) 1998-1999 by 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
13 if {"::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.
19 testConstraint noTk [expr {0 != [catch {package present Tk}]}]
20 testConstraint thread [expr {0 == [catch {package require Thread 2.7-}]}]
21 # Darwin always uses a threaded notifier
22 testConstraint unthreaded [expr {
23 ![::tcl::pkgconfig get threaded]
24 && $tcl_platform(os) ne "Darwin"
25 }]
26
27 # The next two tests will hang if threads are enabled because the notifier
28 # will not necessarily wait for ever in this case, so it does not generate
29 # an error.
30 test unixNotfy-1.1 {Tcl_DeleteFileHandler} -constraints {noTk unix unthreaded} -body {
31 catch {vwait x}
32 set f [open [makeFile "" foo] w]
33 fileevent $f writable {set x 1}
34 vwait x
35 close $f
36 list [catch {vwait x} msg] $msg
37 } -result {1 {can't wait for variable "x": would wait forever}} -cleanup {
38 catch { close $f }
39 catch { removeFile foo }
40 }
41 test unixNotfy-1.2 {Tcl_DeleteFileHandler} -constraints {noTk unix unthreaded} -body {
42 catch {vwait x}
43 set f1 [open [makeFile "" foo] w]
44 set f2 [open [makeFile "" foo2] w]
45 fileevent $f1 writable {set x 1}
46 fileevent $f2 writable {set y 1}
47 vwait x
48 close $f1
49 vwait y
50 close $f2
51 list [catch {vwait x} msg] $msg
52 } -result {1 {can't wait for variable "x": would wait forever}} -cleanup {
53 catch { close $f1 }
54 catch { close $f2 }
55 catch { removeFile foo }
56 catch { removeFile foo2 }
57 }
58
59 test unixNotfy-2.1 {Tcl_DeleteFileHandler} \
60 -constraints {noTk unix thread} \
61 -body {
62 update
63 set f [open [makeFile "" foo] w]
64 fileevent $f writable {set x 1}
65 vwait x
66 close $f
67 thread::create "thread::send [thread::id] {set x ok}"
68 vwait x
69 set x
70 } \
71 -result {ok} \
72 -cleanup {
73 catch { close $f }
74 catch { removeFile foo }
75 }
76 test unixNotfy-2.2 {Tcl_DeleteFileHandler} \
77 -constraints {noTk unix thread} \
78 -body {
79 update
80 set f1 [open [makeFile "" foo] w]
81 set f2 [open [makeFile "" foo2] w]
82 fileevent $f1 writable {set x 1}
83 fileevent $f2 writable {set y 1}
84 vwait x
85 close $f1
86 vwait y
87 close $f2
88 thread::create "thread::send [thread::id] {set x ok}"
89 vwait x
90 set x
91 } \
92 -result {ok} \
93 -cleanup {
94 catch { close $f1 }
95 catch { close $f2 }
96 catch { removeFile foo }
97 catch { removeFile foo2 }
98 }
99
100 # cleanup
101 ::tcltest::cleanupTests
102 return