Skip to content
Tcl Source Code View Ticket
Login

View Ticket

Tcltest -output ignores newlines

Closed / Wont Fix3377401fffffffffffffffffffffffffffffffffCreated 15 years agoUpdated 15 years ago
Descriptionplain2011-07-25 18:22:25
In a simple tcltest monitoring stdout, -output ignores any newlines passed to it.

Reproducible: http://pastebin.com/JxG9Czpr

Possible reasons:
(via irc) <ferrieux> there seems to be an implicit [string trimright] on the -output arg
<ferrieux> should not be there
kryaliplain2011-07-26 01:53:22
Ah, after following some advice, I modified the construction of the test to work. As below:

package require tcltest 2.0 
namespace import ::tcltest::*
test new-1 { match newline outputs } -setup {
    } -body {
        puts "Hello World"
    } -output {Hello World
}
ferrieuxplain2011-07-26 02:42:35
The culprit is the following  list-normalizing [concat] in tcltest.tcl. Motive unclear.

    foreach item {constraints match setup body cleanup \
    result returnCodes output errorOutput} {
if {[info exists testAttributes(-$item)]} {
    set testAttributes(-$item) [uplevel 1 \
    ::concat $testAttributes(-$item)]
}
    }
ferrieuxplain2011-07-26 02:53:18
Fossil annotate traces back to:

30eb4d542e 2000-10-24      jenn: if {[info exists testAttributes([subst -$item])]} {
30eb4d542e 2000-10-24      jenn:     set testAttributes([subst -$item]) \
30eb4d542e 2000-10-24      jenn:     [uplevel concat $testAttributes([subst -$item])]
30eb4d542e 2000-10-24      jenn: }
ferrieuxplain2011-07-26 03:05:53
Turns out that code path is strictly reserved to the options-in-one-block syntax. So the workaround you've found is simply the Right Thing To Do. I'd love to know the rationale for the old semantics though.
ferrieuxplain2011-07-27 00:50:56
The half-rationale or more accurately the apologies, are provided in the tcltest.n manpage:
So the space-collapsing is one of the many side-effects of that unfortunate,  now deprecated, but documented, single-block syntax. Hence closing as Won't Fix for lack of a Don't Do That.

       test name description optionList
              This  form  of  test was provided to enable passing many options
              spanning several lines to test as a single  argument  quoted  by
              braces,  rather  than  needing  to  backslash quote the newlines
              between arguments to test.  The optionList argument is  expected
              to be a list with an even number of elements representing option
              and value arguments to pass to test.  However, these values  are
              not  passed  directly,  as  in  the  alternate  forms of switch.
              Instead, this form makes an  unfortunate  attempt  to  overthrow
              Tcl’s  substitution rules by performing substitutions on some of
              the list elements as an attempt to implement a “do what I  mean”
              interpretation  of  a  brace-enclosed  “block”.   The  result is
              nearly impossible to document clearly, and for that reason  this
              form  is  not  recommended.
Log in (anonymous is fine) to add a comment.