Testunit Gotcha!

So there I was building a wee test with testunit-0.1.4 and ruby 1.6.7 when
the test suite ran but ran no test cases.

Weird.

After much fiddling I worked out why.

I was doing an all-in-one-file program and test. However I wanted the
program to print out a help if no args were found and run the test if the
command line arg was “test”.

Something deep and undocumented in TestRunner looks at ARGV and does
something with them and then doesn’t run my test cases.

Sad.

Here is a minimal bit of code to generate the glitch…
===the file boo====
require ‘test/unit’

class TC_Normalize < Test::Unit::TestCase
def test_missingheader
puts “Huh?”
end
end

···

=================

ruby boo
ruby ./boo
Loaded suite ./boo
Started…
…Huh?

Finished in 0.026578 seconds.
1 runs, 0 assertions, 0 failures, 0 errors

So that worked OK.

Now add an argument…

ruby ./boo bah
Loaded suite ./boo
Started…

Finished in 0.018516 seconds.
0 runs, 0 assertions, 0 failures, 0 errors

Whoops, 0 runs.

Ooh, lets try a wild guess…

ruby ./boo test_missingheader
Loaded suite ./boo
Started…
.Huh?

Finished in 0.000962 seconds.
1 runs, 0 assertions, 0 failures, 0 errors

Yip, definitely an undocumented feature down there somewhere…

Yip, in unit.rb is a bunch of code that does something, err, interesting
with ARGV.

John Carter Phone : (64)(3) 358 6639
Tait Electronics Fax : (64)(3) 359 4632
PO Box 1645 Christchurch Email : john.carter@tait.co.nz
New Zealand

Good Ideas:
Ruby - http://www.ruby-lang-org - The best of perl,python,scheme without the pain.
Valgrind - Valgrind Home - memory debugger for x86-GNU/Linux
Free your books - http://www.bookcrossing.com

So there I was building a wee test with testunit-0.1.4 and
ruby 1.6.7 when the test suite ran but ran no test cases.

Weird.

After much fiddling I worked out why.

I was doing an all-in-one-file program and test. However I
wanted the program to print out a help if no args were found
and run the test if the command line arg was “test”.

Something deep and undocumented in TestRunner looks at ARGV
and does something with them and then doesn’t run my test cases.

Sad.

Sorry… I don’t usually work in the program & test in one file mode,
and so hadn’t even thought about this. My general thought is that if you
do want to work in that mode, you should run your test explicitly, not
automatically. Then you can keep ARGV all to yourself. FWIW, that
‘interesting’ code allows you to filter out which tests are run from the
commandline.

On a semi-related and possibly helpful note, I am doing some pretty
heavy refactoring in the unit.rb area right now. This involves both
testing & documenting the stuff that’s going on in there, and making it
more pluggable.

Anyhow, if you have any ideas for how to fix the issue you’re having
(while keeping the feature that others are using), I’m all ears…

Thanks,

Nathaniel

<:((><

···

John Carter [mailto:john.carter@tait.co.nz] wrote:

RoleModel Software, Inc.
EQUIP VI