1 # This test file covers POSIX file locking
3 # This file contains a collection of tests for one or more of the Tcl built-in
4 # commands. Sourcing this file into Tcl runs the tests and generates output
5 # for errors. No output means no errors were found.
7 # Copyright (c) 2003-2009 Donal K. Fellows
8 # See the file "license.terms" for information on usage and redistribution of
9 # this file, and for a DISCLAIMER OF ALL WARRANTIES.
11 source [file dirname [info script]]/testing.tcl
14 # Really we want to check if locking is supported, but there
15 # is no easy way to do that, so use the existence of os.wait as a proxy
18 set fh [open locktest.file w]
20 test lock-1.1 {grab lock} {
24 test lock-1.2 {grab lock again} {
28 test lock-1.j {release lock} {
32 test lock-1.4 {release lock again} {
36 test lock-1.5 {grab lock from sub-process} {
37 # Run a child process that grabs the lock for 0.5 seconds
38 set pid [exec [info nameofexecutable] -e {set fh [open locktest.file r+]; $fh lock; sleep 0.5} >/dev/null &]
40 # Try to grab the lock - should fail
47 file delete locktest.file