Skip to content

Commit 8480fd4

Browse files
committed
Run tests on Travis under JRuby
This required fixing the tests so that they could run on JRuby. JRuby seems to not fully support `spawn`, in the sense that even if you explicitly tell it to redirect stdout and stderr in the child process using `out: writer, err: [:child, :out]`, it doesn't work: stdout from the process leaks through. The `childprocess` gem, however, does work, so we use that instead.
1 parent 70819e3 commit 8480fd4

File tree

6 files changed

+46
-17
lines changed

6 files changed

+46
-17
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
language: ruby
22
rvm:
33
- 2.5.1
4+
- jruby-9.2.0.0

Gemfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ source "https://rubygems.org"
44

55
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
66

7+
gem "childprocess"
8+
gem "pry-nav", platform: :jruby
79
gem "rake"
810
gem "rubocop"
911
gem "rspec-core", github: "rspec/rspec-core"
1012
gem "rspec-support", github: "rspec/rspec-support"
1113
gem "rspec-expectations", github: "rspec/rspec-expectations"
1214
gem "rspec-mocks", github: "rspec/rspec-mocks"
13-
gem "pry-byebug", platform: :mri
1415

1516
gemspec

Gemfile.lock

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,32 @@ GEM
3838
remote: https://rubygems.org/
3939
specs:
4040
ast (2.4.0)
41-
byebug (10.0.2)
41+
childprocess (0.9.0)
42+
ffi (~> 1.0, >= 1.0.11)
4243
coderay (1.1.2)
4344
diff-lcs (1.3)
45+
ffi (1.9.25)
46+
ffi (1.9.25-java)
4447
jaro_winkler (1.5.1)
45-
method_source (0.9.0)
48+
jaro_winkler (1.5.1-java)
49+
method_source (0.8.2)
4650
parallel (1.12.1)
4751
parser (2.5.1.2)
4852
ast (~> 2.4.0)
4953
patience_diff (1.1.0)
5054
trollop (~> 1.16)
5155
powerpack (0.1.2)
52-
pry (0.11.3)
56+
pry (0.10.4)
5357
coderay (~> 1.1.0)
54-
method_source (~> 0.9.0)
55-
pry-byebug (3.6.0)
56-
byebug (~> 10.0)
57-
pry (~> 0.10)
58+
method_source (~> 0.8.1)
59+
slop (~> 3.4)
60+
pry (0.10.4-java)
61+
coderay (~> 1.1.0)
62+
method_source (~> 0.8.1)
63+
slop (~> 3.4)
64+
spoon (~> 0.0)
65+
pry-nav (0.2.4)
66+
pry (>= 0.9.10, < 0.11.0)
5867
rainbow (3.0.0)
5968
rake (12.3.1)
6069
rubocop (0.58.2)
@@ -66,14 +75,19 @@ GEM
6675
ruby-progressbar (~> 1.7)
6776
unicode-display_width (~> 1.0, >= 1.0.1)
6877
ruby-progressbar (1.10.0)
78+
slop (3.6.0)
79+
spoon (0.0.6)
80+
ffi
6981
trollop (1.16.2)
7082
unicode-display_width (1.4.0)
7183

7284
PLATFORMS
85+
java
7386
ruby
7487

7588
DEPENDENCIES
76-
pry-byebug
89+
childprocess
90+
pry-nav
7791
rake
7892
rspec-core!
7993
rspec-expectations!
@@ -83,4 +97,4 @@ DEPENDENCIES
8397
super_diff!
8498

8599
BUNDLED WITH
86-
1.16.4
100+
1.16.5

lib/super_diff.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
require "patience_diff"
22
require "diff-lcs"
3-
require "pry-byebug"
43

54
require_relative "super_diff/csi"
65
require_relative "super_diff/errors"

spec/spec_helper.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
require_relative "../lib/super_diff"
22
require_relative "../lib/super_diff/rspec"
33

4+
begin
5+
require "pry-byebug"
6+
rescue LoadError
7+
end
8+
9+
begin
10+
require "pry-nav"
11+
rescue LoadError
12+
end
13+
414
Dir.glob(File.expand_path("../support/**/*.rb", __FILE__)).each do |file|
515
require file
616
end

spec/support/command_runner.rb

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require "childprocess"
2+
13
require "English"
24
require "shellwords"
35
require "timeout"
@@ -109,11 +111,14 @@ def initialize(*args)
109111
@args = args
110112
@options = options.merge(
111113
err: [:child, :out],
112-
out: writer
114+
out: @writer
113115
)
114116
@env = extract_env_from(@options)
115117

116-
@wrapper = ->(block) { block.call }
118+
@process = ChildProcess.build(*command)
119+
@process.io.stdout = @process.io.stderr = @writer
120+
121+
@wrapper = -> (block) { block.call }
117122
self.directory = Dir.pwd
118123
@run_quickly = false
119124
@run_successfully = false
@@ -203,7 +208,7 @@ def has_output?(expected_output)
203208

204209
protected
205210

206-
attr_reader :args, :reader, :writer, :wrapper
211+
attr_reader :args, :reader, :writer, :wrapper, :process
207212

208213
private
209214

@@ -222,9 +227,8 @@ def formatted_env
222227
end
223228

224229
def run_freely
225-
pid = spawn(env, *command, options)
226-
Process.waitpid(pid)
227-
@status = $CHILD_STATUS
230+
process.start
231+
process.wait
228232
end
229233

230234
def run_with_wrapper

0 commit comments

Comments
 (0)