Skip to content

Commit

Permalink
Add directory/framework for new java integration specs
Browse files Browse the repository at this point in the history
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
nicksieger committed Apr 16, 2008
1 parent 0248217 commit f020805
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 1 deletion.
20 changes: 19 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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
20 changes: 20 additions & 0 deletions test/spec/java_integration/README.specs
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package spec.java_integration.fixtures;

public interface SingleMethodInterface {
Object callIt();
}
10 changes: 10 additions & 0 deletions test/spec/java_integration/fixtures/UsesSingleMethodInterface.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
24 changes: 24 additions & 0 deletions test/spec/java_integration/interfaces/implementation_spec.rb
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions test/spec/java_integration/spec.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
--colour
--format
specdoc
--loadby
mtime
--reverse
--backtrace
11 changes: 11 additions & 0 deletions test/spec/java_integration/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit f020805

Please sign in to comment.