Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add directory/framework for new java integration specs

Two specs to get things started


git-svn-id: http://svn.codehaus.org/jruby/trunk/jruby@6509 961051c9-f516-0410-bf72-c9f7e237a7b7
  • Loading branch information...
commit f0208052be5e2c622c0b003583073ce983a4eada 1 parent 0248217
@nicksieger nicksieger authored
View
20 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
+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
View
20 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.
View
5 test/spec/java_integration/fixtures/SingleMethodInterface.java
@@ -0,0 +1,5 @@
+package spec.java_integration.fixtures;
+
+public interface SingleMethodInterface {
+ Object callIt();
+}
View
10 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);
+ }
+}
View
24 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
View
7 test/spec/java_integration/spec.opts
@@ -0,0 +1,7 @@
+--colour
+--format
+specdoc
+--loadby
+mtime
+--reverse
+--backtrace
View
11 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
Please sign in to comment.
Something went wrong with that request. Please try again.