unusual rake behaviour

Y

Yogi

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
 
J

Jim Weirich

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

Jim Weirich

Jim Weirich said:
Yogi said:

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.

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?
 
D

David Heinemeier Hansson

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

Eric Hodel

--Apple-Mail-24--614739353
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset=US-ASCII; format=flowed

Jim Weirich said:

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 - (e-mail address removed) - http://segment7.net
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04

--Apple-Mail-24--614739353
content-type: application/pgp-signature; x-mac-type=70674453;
name=PGP.sig
content-description: This is a digitally signed message part
content-disposition: inline; filename=PGP.sig
content-transfer-encoding: 7bit

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (Darwin)

iD8DBQFB07cMMypVHHlsnwQRAkMnAJ4iB2HSNrQBvI34tkWsoW1gAx/jQACg4ZiL
O9olyo1U0xwyjAh9h4vM4AA=
=Uo3Z
-----END PGP SIGNATURE-----

--Apple-Mail-24--614739353--
 
J

Jim Weirich

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?
 
E

Eric Hodel

--Apple-Mail-28--577431685
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset=US-ASCII; format=flowed


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

--
Eric Hodel - (e-mail address removed) - http://segment7.net
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04

--Apple-Mail-28--577431685
content-type: application/pgp-signature; x-mac-type=70674453;
name=PGP.sig
content-description: This is a digitally signed message part
content-disposition: inline; filename=PGP.sig
content-transfer-encoding: 7bit

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (Darwin)

iD8DBQFB1EjHMypVHHlsnwQRAtdSAJ4/eoZQc6uQS3p2TAdMCFHIHZpQegCgx4Bh
WZvXRSqA+YA3fYLWa0zeBeM=
=w5s/
-----END PGP SIGNATURE-----

--Apple-Mail-28--577431685--
 
J

Jim Weirich

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

nobu.nokada

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).",
 
J

Jim Weirich

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

nobu.nokada

Hi,

At Mon, 3 Jan 2005 12:34:50 +0900,
Jim Weirich wrote in [ruby-talk:125009]:
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))
?
 
J

Jim Weirich

Hi,

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

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

Yes, that would work.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top