Tcl Source Code

Artifact [761657a52f]
Login

Artifact 761657a52fbfac578df6187bb669b759597df927:

Attachment "patch" to ticket [512214ffff] added by kenstir 2002-02-03 04:13:56.
Some of the tcltest constraint initialization code is nontrivial.  A
caller may want to avoid running the initialization code.  In my case,
running the constraint initialization code hangs my application.

This patch uses [info exists] to test a constraint first, and runs the
code to set the constraint if it doesn't already exist.

This patch is incomplete; it only handles the (stdio) constraint.  If you
agree with this style of test-first constraint setting, I can patch the
other constraints and submit them.

My example: I have a client app which opens an exclusive connection to a
server.  When this app tries to spawn itself (while setting the stdio
constraint), it deadlocks waiting for the exclusive connection to the
server.  Whether this is good app design is outside the scope of this
patch!

Most of this patch is whitespace-only change.

Index: tcltest.tcl
===================================================================
RCS file: /cvsroot/tcl/tcl/library/tcltest/tcltest.tcl,v
retrieving revision 1.33
diff -u -r1.33 tcltest.tcl
--- tcltest.tcl	2001/09/06 17:51:00	1.33
+++ tcltest.tcl	2002/02/02 21:08:38
@@ -1492,21 +1492,23 @@
 	}
     }
 
-    tcltest::testConstraint stdio 0
-    catch {
-	catch {file delete -force tmp}
-	set f [open tmp w]
-	puts $f {
-	    exit
-	}
-	close $f
+    if {![info exists tcltest::testConstraints(stdio)]} {
+	tcltest::testConstraint stdio 0
+	catch {
+	    catch {file delete -force tmp}
+	    set f [open tmp w]
+	    puts $f {
+		exit
+	    }
+	    close $f
 
-	set f [open "|[list $tcltest::tcltest tmp]" r]
-	close $f
-	
-	tcltest::testConstraint stdio 1
+	    set f [open "|[list $tcltest::tcltest tmp]" r]
+	    close $f
+	    
+	    tcltest::testConstraint stdio 1
+	} msg
+	catch {file delete -force tmp}
     }
-    catch {file delete -force tmp}
 
     # Deliberately call socket with the wrong number of arguments.  The error
     # message you get will indicate whether sockets are available on this