Skip to content

Commit

Permalink
BUILD: Execute RSPEC from JUnit
Browse files Browse the repository at this point in the history
Fixes #8517
  • Loading branch information
original-brownbear committed Oct 26, 2017
1 parent 95d56a0 commit 8358260
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 4 deletions.
5 changes: 4 additions & 1 deletion lib/bootstrap/rspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@
require "rspec"
require 'ci/reporter/rake/rspec_loader'

status = RSpec::Core::Runner.run(ARGV.empty? ? ["spec"] : ARGV).to_i
status = RSpec::Core::Runner.run(ARGV.empty? ? ($JUNIT_ARGV || ["spec"]) : ARGV).to_i
if ENV["IS_JUNIT_RUN"]
return status
end
exit status if status != 0
5 changes: 5 additions & 0 deletions logstash-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ configurations.archives {
extendsFrom configurations.javadoc
}

task javaTests(type: Test) {
exclude '/org/logstash/RSpecTests.class'
}

artifacts {
sources(sourcesJar) {
// Weird Gradle quirk where type will be used for the extension, but only for sources
Expand Down Expand Up @@ -113,6 +117,7 @@ dependencies {
testCompile 'net.javacrumbs.json-unit:json-unit:1.9.0'
testCompile 'org.elasticsearch:securemock:1.2'
testCompile 'org.assertj:assertj-core:3.8.0'
testCompile "org.jruby:jruby-complete:${jrubyVersion}"
provided "org.jruby:jruby-core:${jrubyVersion}"
}

38 changes: 38 additions & 0 deletions logstash-core/src/test/java/org/logstash/RSpecTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.logstash;

import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import org.assertj.core.util.Files;
import org.jruby.runtime.builtin.IRubyObject;
import org.junit.Assert;
import org.junit.Test;

/**
* Runs the Logstash RSpec suit.
*/
public final class RSpecTests {

@Test
public void rspecTests() throws Exception {
final String root = Files.currentFolder().getParent();
RubyUtil.RUBY.getENV().put("IS_JUNIT_RUN", "true");
RubyUtil.RUBY.setCurrentDirectory(root);
RubyUtil.RUBY.getGlobalVariables().set(
"$JUNIT_ARGV",
Rubyfier.deep(
RubyUtil.RUBY, Arrays.asList(
"-fd", "--pattern", "spec/unit/**/*_spec.rb,logstash-core/spec/**/*_spec.rb"
))
);
final Path rspec = Paths.get(root, "lib/bootstrap/rspec.rb");
final IRubyObject result = RubyUtil.RUBY.executeScript(
new String(java.nio.file.Files.readAllBytes(rspec), StandardCharsets.UTF_8),
rspec.toFile().getAbsolutePath()
);
if (!result.toJava(Long.class).equals(0L)) {
Assert.fail("RSpec test suit saw at least one failure.");
}
}
}
6 changes: 3 additions & 3 deletions rakelib/test.rake
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace "test" do

desc "run the java unit tests"
task "core-java" do
exit(1) unless system './gradlew clean test'
exit(1) unless system('./gradlew clean javaTests')
end

desc "run the ruby unit tests"
Expand All @@ -24,8 +24,8 @@ namespace "test" do
end

desc "run all core specs"
task "core-slow" => ["core-java"] do
exit 1 unless system(*default_spec_command)
task "core-slow" do
exit 1 unless system('./gradlew clean test')
end

desc "run core specs excluding slower tests like stress tests"
Expand Down

0 comments on commit 8358260

Please sign in to comment.