diff --git a/Rakefile b/Rakefile index 3a13d465800..c501fbb22b1 100644 --- a/Rakefile +++ b/Rakefile @@ -34,6 +34,12 @@ desc "Alias for spec:ci" task :spec => "spec:ci" namespace :test do + desc "Compile test code" + task :compile do + ant "compile-test" + system "jar cf build/jruby-test-classes.jar -C build/classes/test ." + end + desc "Run the basic set of tests" task :short do ant "test" @@ -45,6 +51,10 @@ namespace :test do end end +file "build/jruby-test-classes.jar" do + Rake::Task['test:compile'].invoke +end + namespace :spec do desc "Run the rubyspecs expected to pass (version-frozen)" task :ci do @@ -76,4 +86,12 @@ task :gen do system 'apt -nocompile -cp lib/jruby.jar:build_lib/asm-3.0.jar:build_lib/asm-util-3.0.jar -factory org.jruby.anno.AnnotationBinder src/org/jruby/*.java' system 'javac -cp lib/jruby.jar src_gen/*.java' system 'jar -uf lib/jruby.jar -C src_gen .' -end \ No newline at end of file +end + +require 'spec/rake/spectask' +desc "Runs Java Integration Specs" +Spec::Rake::SpecTask.new("jispec" => "build/jruby-test-classes.jar") do |t| + t.spec_opts ||= [] + t.spec_opts << "--options" << "test/spec/java_integration/spec.opts" + t.spec_files = FileList['test/spec/java_integration/**/*_spec.rb'] +end diff --git a/test/spec/java_integration/README.specs b/test/spec/java_integration/README.specs new file mode 100644 index 00000000000..28b41c02213 --- /dev/null +++ b/test/spec/java_integration/README.specs @@ -0,0 +1,20 @@ +This sub-directory contains specs for JRuby's Java Integration features. + +== RUNNING + +Run the specs with "jruby -S rake jispec" from the root of the JRuby source tree. +Specdoc will be printed to the console showing what has been implemented so far. + +== NOTES + +The work to create the specs is just starting; please follow these guidelines. + +- Keep the specs free of outside dependencies. +- Create fixture Java classes in the fixtures/ subdirectory for use by the specs. + Don't use any Java classes other than those in the fixtures directory, or in the + JDK itself. +- Create new *_spec.rb files in subdirectories grouped by functional area. Create new + subdirectories if you need to. +- For speed, the "jispec" task does not recompile the fixture classes. If you're + adding new fixture classes, you will need to re-run the "test:compile" rake + task in order to pick up the changes. diff --git a/test/spec/java_integration/fixtures/SingleMethodInterface.java b/test/spec/java_integration/fixtures/SingleMethodInterface.java new file mode 100644 index 00000000000..56cb2b736cf --- /dev/null +++ b/test/spec/java_integration/fixtures/SingleMethodInterface.java @@ -0,0 +1,5 @@ +package spec.java_integration.fixtures; + +public interface SingleMethodInterface { + Object callIt(); +} \ No newline at end of file diff --git a/test/spec/java_integration/fixtures/UsesSingleMethodInterface.java b/test/spec/java_integration/fixtures/UsesSingleMethodInterface.java new file mode 100644 index 00000000000..4f6b1bd4f72 --- /dev/null +++ b/test/spec/java_integration/fixtures/UsesSingleMethodInterface.java @@ -0,0 +1,10 @@ +package spec.java_integration.fixtures; + +public class UsesSingleMethodInterface { + public static Object callIt(SingleMethodInterface obj) { + return obj.callIt(); + } + public static Object castAndCallIt(Object obj) { + return callIt((SingleMethodInterface) obj); + } +} \ No newline at end of file diff --git a/test/spec/java_integration/interfaces/implementation_spec.rb b/test/spec/java_integration/interfaces/implementation_spec.rb new file mode 100644 index 00000000000..e841a26cc84 --- /dev/null +++ b/test/spec/java_integration/interfaces/implementation_spec.rb @@ -0,0 +1,24 @@ +require File.dirname(__FILE__) + "/../spec_helper" + +import "spec.java_integration.fixtures.SingleMethodInterface" +import "spec.java_integration.fixtures.UsesSingleMethodInterface" + +describe "Single-method Java interfaces implemented in Ruby" do + class ValueHolder + include SingleMethodInterface + def initialize(val) + @value = val + end + def callIt + @value + end + end + + it "should be implemented with 'include InterfaceClass'" do + UsesSingleMethodInterface.callIt(ValueHolder.new(1)).should == 1 + end + + it "should be cast-able to the interface on the Java side" do + UsesSingleMethodInterface.castAndCallIt(ValueHolder.new(2)).should == 2 + end +end \ No newline at end of file diff --git a/test/spec/java_integration/spec.opts b/test/spec/java_integration/spec.opts new file mode 100755 index 00000000000..49fd993dfd3 --- /dev/null +++ b/test/spec/java_integration/spec.opts @@ -0,0 +1,7 @@ +--colour +--format +specdoc +--loadby +mtime +--reverse +--backtrace \ No newline at end of file diff --git a/test/spec/java_integration/spec_helper.rb b/test/spec/java_integration/spec_helper.rb new file mode 100644 index 00000000000..898ebe20bd8 --- /dev/null +++ b/test/spec/java_integration/spec_helper.rb @@ -0,0 +1,11 @@ +require 'java' +require File.dirname(__FILE__) + '/../../../build/jruby-test-classes.jar' +require 'spec' + +Spec::Runner.configure do |config| + # config.before :each do + # end + + # config.after :each do + # end +end