Unusual rake behaviour

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

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://onestepback.org
-----------------------------------------------------------------
"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 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://onestepback.org
-----------------------------------------------------------------
"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)

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! :slight_smile:

Please advice.

···

--
David Heinemeier Hansson,
http://www.basecamphq.com/ -- Web-based Project Management
http://www.rubyonrails.org/ -- Web-application framework for Ruby
http://macromates.com/ -- TextMate: Code and markup editor (OS X)
http://www.loudthinking.com/ -- Broadcasting Brain

What's wrong with ruby -Ilib testfile?

PGP.sig (186 Bytes)

···

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.

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

I asked this question to ruby-core

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

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! :slight_smile:

Please advice.
--
David Heinemeier Hansson,
http://www.basecamphq.com/ -- Web-based Project Management
http://www.rubyonrails.org/ -- Web-application framework for Ruby
http://macromates.com/ -- TextMate: Code and markup editor (OS X)
http://www.loudthinking.com/ -- Broadcasting Brain

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?

···

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?

--
-- Jim Weirich jim@weirichhouse.org http://onestepback.org
-----------------------------------------------------------------
"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)

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-core/4008

PGP.sig (186 Bytes)

···

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

On Thursday 30 December 2004 03:06 am, Eric Hodel wrote:

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

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://onestepback.org
-----------------------------------------------------------------
"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)

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

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.

···

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

--
-- Jim Weirich jim@weirichhouse.org http://onestepback.org
-----------------------------------------------------------------
"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)

Hi,

At Mon, 3 Jan 2005 12:34:50 +0900,
Jim Weirich wrote in [ruby-talk:125009]:

···

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).

So, it should be
  $LOAD_PATH.unshift(*dirs.split(File::PATH_SEPARATOR))
?

--
Nobu Nakada

Yes, that would work.

···

On Sunday 02 January 2005 11:31 pm, nobu.nokada@softhome.net wrote:

Hi,

At Mon, 3 Jan 2005 12:34:50 +0900,

Jim Weirich wrote in [ruby-talk:125009]:
> 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).

So, it should be
  $LOAD_PATH.unshift(*dirs.split(File::PATH_SEPARATOR))
?

--
-- Jim Weirich jim@weirichhouse.org http://onestepback.org
-----------------------------------------------------------------
"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)