# Weird test/unit behavior

**URL:** <https://www.ruby-forum.com/t/weird-test-unit-behavior/108781>\
**Category:** Ruby\
**Created:** [July 6, 2007, 11:28pm UTC](https://www.ruby-forum.com/t/weird-test-unit-behavior/108781 "2007-07-06T23:28:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nasir\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/838e76/32.png) [@Nasir\_K](https://www.ruby-forum.com/u/Nasir_K)\
**Post date:** [July 6, 2007, 11:28pm UTC](https://www.ruby-forum.com/t/weird-test-unit-behavior/108781/1 "2007-07-06T23:28:43Z")

</div>

Consider a simple test -

## my\_test.rb:

require ‘test/unit’

class MyTest \< Test::Unit::TestCase

def test1  
assert(true)  
end

## end

Now consider a simple script to run this.

## run2.rb:

## if ARGV.length == 0 puts “usage run testfile” else type = ARGV.shift if type == “-t” f = ARGV.shift load f end end

So if you run it then you get the expected result.

run2 -t my\_test.rb  
Loaded suite ~sparkle:/nasir/misc/test/run2  
Started  
.  
Finished in 0.0 seconds.

1 tests, 1 assertions, 0 failures, 0 errors

But now consider another script to run the same test.

## run1.rb:

## D:\nasir\misc\test\>cat run1.rb if ARGV.length == 0 puts “usage: run testfile” else ARGV.each\_with\_index do |arg, i| if arg == “-t” load ARGV[i+1] end end end

When you run it the testcase is loaded alright but it doesnt run!

run1.rb -t my\_test.rb  
Loaded suite ~sparkle:/nasir/misc/test/run1  
Started

Finished in 0.0 seconds.

0 tests, 0 assertions, 0 failures, 0 errors

* * *

Apparently the testsuite is not run/loaded in this case.

Any help in finding out what is going on is appreciated.

- nasir

---

<div class="post-metadata">

**Author:** ![Nasir\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/838e76/32.png) [@Nasir\_K](https://www.ruby-forum.com/u/Nasir_K)\
**Post date:** [July 7, 2007, 12:02am UTC](https://www.ruby-forum.com/t/weird-test-unit-behavior/108781/2 "2007-07-07T00:02:46Z")

</div>

Ah Gotcha!

It is a side effect of having commandline arguments. ARGV is also used  
by  
autorunner.rb.  
using shift in run2.rb clears the ARGV array.
