Hi,

Forwarding a message from Kouhei Sutou regarding an issue we found in
the Rake that ships with Ruby by default.

The issue stems around his test-unit2 library, where it's loading the
wrong test/unit because of $LOAD_PATH handling when it uses the
default Rake. He provides an explanation for the problem and has
provided a diff near the bottom. There's a workaround, too.

I wasn't sure who should get this, so I sent it to both lists hoping
someone could chime in.

While I think this is a minor issue now, it could be a larger issue
down the road if/when more of the stdlib is turned into gems with the
same name.

Regards,

Dan

---------- Forwarded message ----------
From: Kouhei Sutou <kou / cozmixng.org>
Date: Fri, May 11, 2012 at 7:19 AM
Subject: [test-unit-users-en:00074] Re: Having problems with startup
when combined with Rake
To: test-unit-users-en / rubyforge.org


Hi,

In <CAGSpibmdyopjdfGRsmDOPRck5L76L82RMMjZC9K0+e2cmjH-jA / mail.gmail.com>
=A0"[test-unit-users-en:00073] Re: Having problems with startup when
combined with Rake" on Thu, 10 May 2012 09:16:09 -0600,
=A0Daniel Berger <djberg96 / gmail.com> wrote:

> I think I figured it out. Somehow it was picking up the old test-unit
> library. Once I renamed that old test-unit directory, everything
> worked. I'm not sure why it was happening though, since I was
> requiring 'test-unit', not 'test/unit'.
>
> I did not have my RUBYOPT environment variable set, but I didn't think
> it was necessary.
>
> I'm not sure why it would work with 1.8.7 and not 1.9.3, though.

I found the problem. :-)

First, here are workarounds:

=A01. Use :diret loader:

=A0 =A0 Rake::TestTask.new('test_foo') do |t|
=A0 =A0 =A0 ...
=A0 =A0 =A0 t.loader =3D :direct
=A0 =A0 =A0 ...
=A0 =A0 end

=A02. Use Rake installed by gem:

=A0 =A0 % gem install rake


The cause of the problem is rake/testtask.rb prepends the
directory where rake.rb is to $LOAD_PATH. The directory is
Ruby's default library diretory when you are using bundled
rake.

> c:\Users\djberge\Repositories\foo>rake test_foo
> c:/usr/bin/ruby.exe -w -I"lib" -I"c:/usr/lib/ruby/1.9.1" "c:/usr/lib/ruby=
/1.9.1/rake/rake_test_loader.rb" "test/test_foo.rb"

In your case, "c:/usr/lib/ruby/1.9.1" is the direcotry.

The directory should not be prepended because RubyGems
inserts test-unit's library directory after load paths added
by -I.

In your case:

=A0p $LOAD_PATH ->
=A0 =A0["lib", "c:/usr/lib/ruby/1.9.1", "#{Gem.path}/gems/test-unit-2.4.9/l=
ib", ...]

test/unit (that is a minitest wrapper not test-unit gem!) is
in "c:/usr/lib/ruby/1.9.1". So 'require "test/unit"'
requires minitest wrapper instead of test-unit gem. This is
the reason for the problem.


The solution of this problem is rake/testtask.rb doesn't add
-I"c:/usr/lib/ruby/1.9.1" if it's not
needed. "c:/usr/lib/ruby/1.9.1" is n't needed because the
path is in $LOAD_PATH in default. The directory is
"#{Gem.path}/gems/rake-X.Y.Z/lib" if you are using Rake
installed by gem. In the case, the -I"..." is needed.

OK. Here is a patch against the master of Rake:

--
diff --git a/lib/rake/testtask.rb b/lib/rake/testtask.rb
index 04d3ae4..98b8c61 100644
--- a/lib/rake/testtask.rb
+++ b/lib/rake/testtask.rb
@@ -157,7 +157,12 @@ module Rake
=A0 =A0 =A0 when :testrb
=A0 =A0 =A0 =A0 "-S testrb #{fix}"
=A0 =A0 =A0 when :rake
- =A0 =A0 =A0 =A0"-I\"#{rake_lib_dir}\" \"#{rake_loader}\""
+ =A0 =A0 =A0 =A0loarder_code =3D "\"#{rake_loader}\""
+ =A0 =A0 =A0 =A0lib_dir_for_loader =3D rake_lib_dir
+ =A0 =A0 =A0 =A0if RbConfig::CONFIG["rubylibdir"] !=3D lib_dir_for_loader
+ =A0 =A0 =A0 =A0 =A0loader_code =3D "-I\"#{lib_dir_for_loader}\" #{loader_=
code}"
+ =A0 =A0 =A0 =A0end
+ =A0 =A0 =A0 =A0loader_code
=A0 =A0 =A0 end
=A0 =A0 end
--

Could you send the patch to Rake(*)? I don't have time to
send it and discuss about the problem... :<

(*) https://github.com/jimweirich/rake


Thanks,
--
kou
_______________________________________________
test-unit-users-en mailing list
test-unit-users-en / rubyforge.org
http://rubyforge.org/mailman/listinfo/test-unit-users-en