require of a JAR file sets $!; causes Test::Unit classes not to autorun
-----------------------------------------------------------------------
Key: JRUBY-908
URL: http://jira.codehaus.org/browse/JRUBY-908
Project: JRuby
Issue Type: Bug
Components: Java Integration
Affects Versions: JRuby 0.9.9
Environment: Likely agnostic; this was Mac OS X 10.4.9 with 'java full
version "1.5.0_07-164"' on Intel.
Reporter: Andrew Geweke
Attachments: require_jar_causes_unit_test_to_not_run.rb
Doing a 'require' of a JAR file straight-up (which is a *very* cool feature, by
the way!) sets $! to an exception (NameError: cannot load Java class
<jarname>Service).
This appears to be completely legal ($! is just the last exception thrown, and
it's perfectly legal AFAIK for pretty much any routine to use any exceptions it
wants internally, as long as it doesn't throw them), but causes Test::Unit
subclasses to not "auto-run" (i.e., where you run the file containing the class
definition, and the Test::Unit framework automatically instantiates and runs
the test using the command-line runner).
While this appears to be a (very significant) flaw in the logic of Test::Unit,
it does introduce an incompatibility with MRI, and one that's very hard to
track down when you first run across it. It would probably, in the end, be
better to not set $! in such circumstances. (Adding a "$! = nil" after the
require of the JAR fixes the problem entirely and is a workaround.)
To wit, using the attached program (with any JAR you'd like, not just
commons-logging-api-1.1.jar, which is a JAR I happened to have lying around):
lenovo-7ed57871 andrew ~> jruby require_jar_causes_unit_test_to_not_run.rb
Last exception: nil
Loaded suite require_jar_causes_unit_test_to_not_run
Started
.
Finished in 0.0050 seconds.
1 tests, 0 assertions, 0 failures, 0 errors
lenovo-7ed57871 andrew ~> jruby require_jar_causes_unit_test_to_not_run.rb
with-jar
Last exception: #<NameError: cannot load Java class
Commons-logging-api-1.1Service>
lenovo-7ed57871 andrew ~>
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email