[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

puts behaviour

James Byrne

2/22/2006 4:29:00 PM

I have a number of "puts" in my testcase file. When I run my test
harness using ruby -w test/testcase.rb the first "puts" in the second
method prefixes the output string with a '.' I cannot seem to locate
any reference to this behaviour. Under what circumstances does "puts"
without any argument produce '.' as output?

Regards,
Jim

--
Posted via http://www.ruby-....


3 Answers

Jim Weirich

2/23/2006 12:33:00 PM

0

James Byrne wrote:
> I have a number of "puts" in my testcase file. When I run my test
> harness using ruby -w test/testcase.rb the first "puts" in the second
> method prefixes the output string with a '.' I cannot seem to locate
> any reference to this behaviour. Under what circumstances does "puts"
> without any argument produce '.' as output?

If you are running this as part of the standard Test::Unit test case
runner, then it is probably Test::Unit printing the ".". It prints one
period for each test case run.

--
-- Jim Weirich

--
Posted via http://www.ruby-....


Daniel Harple

2/23/2006 7:28:00 PM

0

On Feb 23, 2006, at 7:29 PM, James Byrne wrote:

> Are these '.'s pushed onto some sort of string variable in TestUnit
> wherein 'puts' is redefined so that the string is prefaced to any
> argument passed to puts and then cleared?

I don't quite know what you are asking, but --

If you do not want buffered output, set $stdout.sync = true (or
$stderr). If $stdout.sync is false (and it is by default), the line
will not be flushed until a newline. You could also just call IO#flush.

-- Daniel


Yuu

2/23/2006 8:09:00 PM

0

James Byrne wrote:
> Daniel Harple wrote:
>
>>
>> I don't quite know what you are asking, but --
>>
>> If you do not want buffered output, set $stdout.sync = true (or
>> $stderr). If $stdout.sync is false (and it is by default), the line
>> will not be flushed until a newline. You could also just call IO#flush.
>>
>> -- Daniel
>
> Without examining the code, which is probably the next step, I speculate
> that these '.'s are set by Test::Unit to provide support for some sort
> of progress status bar. I am not sufficently well versed in Ruby (I
> wrote my first non trival program in it last week) to have encountered
> things like $stdout.sync and IO.flush. However, having this new
> information combined with my previous experience with the mysterous '.'s
> leads me to the inference above.
>
> This is no more than an inquiry as to why these things appeared
> unexpectedly in my output, which happened to be directory strings
> wherein a prefix of . has rather profound implications.

Right, no, the '.' is just a progress indicator, one for each
successful test_* method in your test case (you will see an 'F'
for each failure and an 'E' for each error). The dots are output
using #print rather than #puts, so they are not followed by newlines
which means that your string will appear immediately after one.
There should be a newline after your string, though (if not, then
the framework strips those--I do not have access to test right now).

> Thanks for the information. It clarifies a few items of confusion.
>
> Regards,
> Jim


E

--
Posted via http://www.ruby-....