From 2e2da60bd41af1072289035d579de333b228685f Mon Sep 17 00:00:00 2001 From: dgp Date: Fri, 18 Jul 2003 21:01:32 +0000 Subject: * doc/tcltest.n: Restored the [Eval] proc to replace * library/tcltest/tcltest.tcl: the [::puts] command when either the -output or -error option for [test] is in use, in order to capture data written to the output or error channels for comparison against what is expected. This is easier to document and agrees better with most user expectations than the previous attempt to replace [puts] only in the caller's namespace. Documentation made more precise on the subject. [Bug 706359] --- ChangeLog | 9 +++++++++ doc/tcltest.n | 14 +++++++------- library/tcltest/tcltest.tcl | 22 ++++++---------------- 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1fecf5d..9376de0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -9,6 +9,15 @@ 2003-07-18 Don Porter + * doc/tcltest.n: Restored the [Eval] proc to replace + * library/tcltest/tcltest.tcl: the [::puts] command when either the + -output or -error option for [test] is in use, in order to capture + data written to the output or error channels for comparison against + what is expected. This is easier to document and agrees better with + most user expectations than the previous attempt to replace [puts] + only in the caller's namespace. Documentation made more precise on + the subject. [Bug 706359] + * doc/AddErrInfo.3: Improved consistency of documentation * doc/CrtTrace.3: by using "null" everywhere to refer to * doc/Encoding.3: the character '\0', and using "NULL" diff --git a/doc/tcltest.n b/doc/tcltest.n index 86af612..f6067ee 100644 --- a/doc/tcltest.n +++ b/doc/tcltest.n @@ -8,7 +8,7 @@ '\" See the file "license.terms" for information on usage and redistribution '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. '\" -'\" RCS: @(#) $Id: tcltest.n,v 1.38.2.2 2003/03/26 23:51:25 dgp Exp $ +'\" RCS: @(#) $Id: tcltest.n,v 1.38.2.3 2003/07/18 21:01:32 dgp Exp $ '\" .so man.macros .TH "tcltest" n 2.2 tcltest "Tcl Bundled Packages" @@ -476,7 +476,7 @@ an empty string. The \fB-output\fR attribute supplies the \fIexpectedValue\fR against which any output sent to \fBstdout\fR or [\fBoutputChannel\fR] during evaluation of the script(s) will be compared. Note that only output printed using -[\fBputs\fR] is used for comparison. If \fB-output\fR is not specified, +[\fB::puts\fR] is used for comparison. If \fB-output\fR is not specified, output sent to \fBstdout\fR and [\fBoutputChannel\fR] is not processed for comparison. .TP @@ -484,7 +484,7 @@ comparison. The \fB-errorOutput\fR attribute supplies the \fIexpectedValue\fR against which any output sent to \fBstderr\fR or [\fBerrorChannel\fR] during evaluation of the script(s) will be compared. Note that only output -printed using [\fBputs\fR] is used for comparison. If \fB-errorOutput\fR +printed using [\fB::puts\fR] is used for comparison. If \fB-errorOutput\fR is not specified, output sent to \fBstderr\fR and [\fBerrorChannel\fR] is not processed for comparison. .TP @@ -512,7 +512,7 @@ In default operation, a successful test produces no output. The output messages produced by [\fBtest\fR] are controlled by the [\fBconfigure -verbose\fR] option as described in \fBCONFIGURABLE OPTIONS\fR below. Any output produced by the test scripts themselves should be -produced using [\fBputs\fR] to [\fBoutputChannel\fR] or +produced using [\fB::puts\fR] to [\fBoutputChannel\fR] or [\fBerrorChannel\fR], so that users of the test suite may easily capture output with the [\fBconfigure -outfile\fR] and [\fBconfigure -errfile\fR] options, and so that the \fB-output\fR @@ -1050,13 +1050,13 @@ where 'm', 'n', 'o', and 'p' refer to tests that were run at the same test level as test level-1.1. .PP Implementation of output and error comparison in the test command -depends on usage of puts in your application code. Output is -intercepted by redefining the puts command while the defined test +depends on usage of ::puts in your application code. Output is +intercepted by redefining the ::puts command while the defined test script is being run. Errors thrown by C procedures or printed directly from C applications will not be caught by the test command. Therefore, usage of the \fB-output\fR and \fB-errorOuput\fR options to [\fBtest\fR] is useful only for pure Tcl applications -that use [\fBputs\fR] to produce output. +that use [\fB::puts\fR] to produce output. .SH KEYWORDS test, test harness, test suite diff --git a/library/tcltest/tcltest.tcl b/library/tcltest/tcltest.tcl index 1bc0037..934f8f0 100644 --- a/library/tcltest/tcltest.tcl +++ b/library/tcltest/tcltest.tcl @@ -16,7 +16,7 @@ # Contributions from Don Porter, NIST, 2002. (not subject to US copyright) # All rights reserved. # -# RCS: @(#) $Id: tcltest.tcl,v 1.78.2.4 2003/07/16 14:31:35 dgp Exp $ +# RCS: @(#) $Id: tcltest.tcl,v 1.78.2.5 2003/07/18 21:01:32 dgp Exp $ package require Tcl 8.3 ;# uses [glob -directory] namespace eval tcltest { @@ -1605,26 +1605,16 @@ proc tcltest::Eval {script {ignoreOutput 1}} { if {!$ignoreOutput} { set outData {} set errData {} - set callerHasPuts [llength [uplevel 1 { - ::info commands [::namespace current]::puts - }]] - if {$callerHasPuts} { - uplevel 1 [list ::rename puts [namespace current]::Replace::Puts] - } else { - interp alias {} [namespace current]::Replace::Puts {} ::puts - } - uplevel 1 [list ::namespace import [namespace origin Replace::puts]] + rename ::puts [namespace current]::Replace::Puts + namespace eval :: \ + [list namespace import [namespace origin Replace::puts]] namespace import Replace::puts } set result [uplevel 1 $script] if {!$ignoreOutput} { namespace forget puts - uplevel 1 ::namespace forget puts - if {$callerHasPuts} { - uplevel 1 [list ::rename [namespace current]::Replace::Puts puts] - } else { - interp alias {} [namespace current]::Replace::Puts {} - } + namespace eval :: namespace forget puts + rename [namespace current]::Replace::Puts ::puts } return $result } -- cgit v0.12