[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

unusual rake behaviour

Yogi

12/29/2004 3:44:00 PM

Hello all!

I've been getting some odd behaviour in rake. The foll cmd doesn't
seem to run the tests in foo_test.rb. I'm using ruby 1.8.2, rake
0.4.13, on linux (fedora core 2)

------------------
$ rake
(in /home/yogi/tmp)
ruby -Ilib -e0 -rfoo_test
Loaded suite .
Started

Finished in 0.001298 seconds.

0 tests, 0 assertions, 0 failures, 0 errors

---the rakefile is---

require 'rake'
require 'rake/testtask'

desc "Default Task"
task :default => [ :test ]

test_file_pattern = '**/*_test.rb'
fl = FileList.new(test_file_pattern)
Rake::TestTask.new { |t|
t.test_files = fl
t.verbose = true
}

--- foo_test.rb ---
require 'test/unit'

class FooTest < Test::Unit::TestCase
def test_someting
assert(true)
end
end

I've also tried running "ruby -Ilib -e0 -rfoo_test", and it gives the
same output.

Thanks,
- Yogi


13 Answers

Jim Weirich

12/29/2004 4:41:00 PM

0


Yogi said:
> Hello all!
>
> I've been getting some odd behaviour in rake. The foll cmd doesn't
> seem to run the tests in foo_test.rb. I'm using ruby 1.8.2, rake
> 0.4.13, on linux (fedora core 2)

Hmm ... I just tried the code you supplied on a windows box and a debian
box and had no problems. I tried with the foo_test.rb file in the same
directory as the Rakefile and also with it in a subdirectory named test.

> I've also tried running "ruby -Ilib -e0 -rfoo_test", and it gives the
> same output.

Hmmm ... This leads me to believe the problem lies in your setup somewhere
and not with rake itself. The -r syntax essentially does a "require
'foo_test'" at the start of your code. If you have multiple foo_test
files in your ruby load path, it may be picking up the wrong one.

--
-- Jim Weirich jim@weirichhouse.org http://onest...
-----------------------------------------------------------------
"Beware of bugs in the above code; I have only proved it correct,
not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)



Jim Weirich

12/29/2004 9:29:00 PM

0


Jim Weirich said:
>
> Yogi said:
>> Hello all!
>>
>> I've been getting some odd behaviour in rake. The foll cmd doesn't
>> seem to run the tests in foo_test.rb. I'm using ruby 1.8.2, rake
>> 0.4.13, on linux (fedora core 2)
>
> Hmm ... I just tried the code you supplied on a windows box and a debian
> box and had no problems. I tried with the foo_test.rb file in the same
> directory as the Rakefile and also with it in a subdirectory named test.
>
>> I've also tried running "ruby -Ilib -e0 -rfoo_test", and it gives the
>> same output.

Someone just informed me that in 1.8.2 test/unit does not work with the
ruby -e0 -rtestfile technique that Rake is using to load the unit tests.
I haven't been able to verify this. I'm not running 1.8.2 yet, so I am
not able to validate this.

Nathaniel ... is this intentional? What's the story?

--
-- Jim Weirich jim@weirichhouse.org http://onest...
-----------------------------------------------------------------
"Beware of bugs in the above code; I have only proved it correct,
not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)



David Heinemeier Hansson

12/30/2004 1:39:00 AM

0

> Nathaniel ... is this intentional? What's the story?

I'd much like to hear the story too. Rails has long since committed its
allegiance to rake and that means its not possible to use Rails with
1.8.2 and rake as the test runner. Quite the travesty! :)

Please advice.
--
David Heinemeier Hansson,
http://www.basec... -- Web-based Project Management
http://www.rubyon... -- Web-application framework for Ruby
http://macro... -- TextMate: Code and markup editor (OS X)
http://www.loudthi... -- Broadcasting Brain



Eric Hodel

12/30/2004 8:07:00 AM

0

On 29 Dec 2004, at 13:28, Jim Weirich wrote:

>
> Jim Weirich said:
>>
>> Yogi said:
>>
>>> I've also tried running "ruby -Ilib -e0 -rfoo_test", and it gives
>>> the
>>> same output.
>
> Someone just informed me that in 1.8.2 test/unit does not work with the
> ruby -e0 -rtestfile technique that Rake is using to load the unit
> tests.
> I haven't been able to verify this. I'm not running 1.8.2 yet, so I am
> not able to validate this.

What's wrong with ruby -Ilib testfile?

--
Eric Hodel - drbrain@segment7.net - http://se...
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04

Kent Sibilev

12/30/2004 11:18:00 AM

0

I asked this question to ruby-core

http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby...

and I was advised to instead use testrb script.

Cheers,
Kent.
On Dec 29, 2004, at 8:38 PM, David Heinemeier Hansson wrote:

>> Nathaniel ... is this intentional? What's the story?
>
> I'd much like to hear the story too. Rails has long since committed
> its allegiance to rake and that means its not possible to use Rails
> with 1.8.2 and rake as the test runner. Quite the travesty! :)
>
> Please advice.
> --
> David Heinemeier Hansson,
> http://www.basec... -- Web-based Project Management
> http://www.rubyon... -- Web-application framework for Ruby
> http://macro... -- TextMate: Code and markup editor (OS X)
> http://www.loudthi... -- Broadcasting Brain
>
>



Jim Weirich

12/30/2004 12:36:00 PM

0

On Thursday 30 December 2004 03:06 am, Eric Hodel wrote:
> > Someone just informed me that in 1.8.2 test/unit does not work with the
> > ruby -e0 -rtestfile technique that Rake is using to load the unit
> > tests.
>
> What's wrong with ruby -Ilib testfile?

You can only explicitly run one script at a time. Most projects have more than
one test file to be included in a test run. Rake use to use a script to find
all the tests files and load them, but the -r technique accomplishes the same
thing without polluting the test environment with any extraneous rake code. I
suppose you could explicitly load the first (or last) test file and require
all the others. There are plenty of workarounds.

I'm just curious about /why/ this change was introduced. What does it fix?

--
-- Jim Weirich jim@weirichhouse.org http://onest...
-----------------------------------------------------------------
"Beware of bugs in the above code; I have only proved it correct,
not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)


Eric Hodel

12/30/2004 6:29:00 PM

0


On 30 Dec 2004, at 04:35, Jim Weirich wrote:

> On Thursday 30 December 2004 03:06 am, Eric Hodel wrote:
>>> Someone just informed me that in 1.8.2 test/unit does not work with
>>> the
>>> ruby -e0 -rtestfile technique that Rake is using to load the unit
>>> tests.
>>
>> What's wrong with ruby -Ilib testfile?
>
> You can only explicitly run one script at a time. Most projects have
> more than
> one test file to be included in a test run. Rake use to use a script
> to find
> all the tests files and load them, but the -r technique accomplishes
> the same
> thing without polluting the test environment with any extraneous rake
> code. I
> suppose you could explicitly load the first (or last) test file and
> require
> all the others. There are plenty of workarounds.

Oh, right.

Use testrb instead.

> I'm just curious about /why/ this change was introduced. What does it
> fix?

I'm not sure, but see:

http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby...

--
Eric Hodel - drbrain@segment7.net - http://se...
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04

Jim Weirich

12/30/2004 7:09:00 PM

0


Eric Hodel said:
> > [...] There are plenty of workarounds.
>
> Oh, right.
>
> Use testrb instead.

At first I thought that this wouldn't work because I need to use the -I
option to put the developement libraries at the front of the load path
(otherwise you will probably end up testing the installed production
software rather than the test software).

testrb doesn't take a -I flag and I wanted to avoid locating testrb in the
file system to pass to the Ruby command, but then I remembered the -S
flag.

So, this is what I'm currently considering using in the test task:

ruby -Ilib -S testrb test1.rb test2.rb ...

Anyone see any problems? Barring complications, we should have a new
version out later this evening.

--
-- Jim Weirich jim@weirichhouse.org http://onest...
-----------------------------------------------------------------
"Beware of bugs in the above code; I have only proved it correct,
not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)



nobu.nokada

1/3/2005 2:51:00 AM

0

Hi,

At Fri, 31 Dec 2004 04:08:47 +0900,
Jim Weirich wrote in [ruby-talk:124849]:
> testrb doesn't take a -I flag and I wanted to avoid locating testrb in the
> file system to pass to the Ruby command, but then I remembered the -S
> flag.

I did want lib/test/unit.rb to be equal to test/runner.rb, but
it seems weird.

Anyway, testrb would better to take -I flags.


Index: lib/test/unit.rb
===================================================================
RCS file: /cvs/ruby/src/ruby/lib/test/unit.rb,v
retrieving revision 1.11
diff -U2 -p -r1.11 unit.rb
--- lib/test/unit.rb 19 Dec 2004 02:01:38 -0000 1.11
+++ lib/test/unit.rb 3 Jan 2005 02:03:28 -0000
@@ -274,5 +274,5 @@ end
at_exit do
unless $! || Test::Unit.run?
- exit Test::Unit::AutoRunner.run($0 != "-e" && $0)
+ exit Test::Unit::AutoRunner.run($0)
end
end
Index: lib/test/unit/autorunner.rb
===================================================================
RCS file: /cvs/ruby/src/ruby/lib/test/unit/autorunner.rb,v
retrieving revision 1.11
diff -U2 -p -r1.11 autorunner.rb
--- lib/test/unit/autorunner.rb 19 Dec 2004 02:01:39 -0000 1.11
+++ lib/test/unit/autorunner.rb 3 Jan 2005 02:14:02 -0000
@@ -148,4 +148,9 @@ module Test
end

+ o.on('-I', "--load-path=DIR[#{File::PATH_SEPARATOR}DIR...]",
+ "Appends directory list to $LOAD_PATH.") do |dirs|
+ $LOAD_PATH.concat(dirs.split(File::PATH_SEPARATOR))
+ end
+
o.on('-v', '--verbose=[LEVEL]', OUTPUT_LEVELS,
"Set the output level (default is verbose).",


--
Nobu Nakada


Jim Weirich

1/3/2005 3:35:00 AM

0

On Sunday 02 January 2005 09:51 pm, nobu.nokada@softhome.net wrote:
> Anyway, testrb would better to take -I flags.
>
> + o.on('-I', "--load-path=DIR[#{File::PATH_SEPARATOR}DIR...]",
> + "Appends directory list to $LOAD_PATH.") do |dirs|
> + $LOAD_PATH.concat(dirs.split(File::PATH_SEPARATOR))
> + end

Actually, for it to be useful to Rake, the list of directories must be put at
the front of the list (as the Ruby command does), not at the end of the list
(as the example does).

Otherwise the unit tests will run the code installed in the standard
locations, not the code in development.

Actually, the irb program puts them at the end too (and doesn't bother to
split on File::PATH_SEPARATOR). It would be nice if irb were consistent with
ruby and put them at the front of the list.

--
-- Jim Weirich jim@weirichhouse.org http://onest...
-----------------------------------------------------------------
"Beware of bugs in the above code; I have only proved it correct,
not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)