Skip to content

Commit 876a33d

Browse files
authored
Merge pull request #50 from deivid-rodriguez/windows-support
Windows support
2 parents 6ada9df + 1f714bf commit 876a33d

File tree

6 files changed

+38
-31
lines changed

6 files changed

+38
-31
lines changed

.github/workflows/tests.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ jobs:
1313
strategy:
1414
fail-fast: true
1515
matrix:
16-
ruby: [ 2.7, "3.0", 3.1, 3.2 ]
16+
ruby: [ 2.7, "3.0", 3.1, 3.2, 3.3 ]
17+
os: [ ubuntu-latest, windows-latest ]
1718

1819
steps:
1920
- uses: actions/checkout@v3

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
turbo_tests (2.2.1)
4+
turbo_tests (2.2.2)
55
json (~> 2.3)
66
parallel_tests (>= 3.3.0, < 5)
77
rspec (>= 3.10)

lib/turbo_tests.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# frozen_string_literal: true
22

3+
require "securerandom"
34
require "open3"
45
require "fileutils"
56
require "json"
7+
68
require "rspec"
79

810
require "parallel_tests"

lib/turbo_tests/json_rows_formatter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def group_to_json(notification)
164164
end
165165

166166
def output_row(obj)
167-
output.puts(obj.to_json)
167+
output.puts ENV["RSPEC_FORMATTER_OUTPUT_ID"] + obj.to_json
168168
output.flush
169169
end
170170
end

lib/turbo_tests/runner.rb

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def self.run(opts = {})
2424
seed_used = !opts[:seed].nil?
2525

2626
if verbose
27-
STDERR.puts "VERBOSE"
27+
warn "VERBOSE"
2828
end
2929

3030
reporter = Reporter.from_config(formatters, start_time)
@@ -134,19 +134,19 @@ def start_subprocess(env, extra_args, tests, process_id, record_runtime:)
134134
if tests.empty?
135135
@messages << {
136136
type: "exit",
137-
process_id: process_id
137+
process_id: process_id,
138138
}
139139
else
140-
tmp_filename = "tmp/test-pipes/subprocess-#{process_id}"
141-
142-
begin
143-
File.mkfifo(tmp_filename)
144-
rescue Errno::EEXIST
145-
end
146-
140+
env["RSPEC_FORMATTER_OUTPUT_ID"] = SecureRandom.uuid
147141
env["RUBYOPT"] = ["-I#{File.expand_path("..", __dir__)}", ENV["RUBYOPT"]].compact.join(" ")
148142
env["RSPEC_SILENCE_FILTER_ANNOUNCEMENTS"] = "1"
149143

144+
if ENV["BUNDLE_BIN_PATH"]
145+
command_name = [ENV["BUNDLE_BIN_PATH"], "exec", "rspec"]
146+
else
147+
command_name = "rspec"
148+
end
149+
150150
record_runtime_options =
151151
if record_runtime
152152
[
@@ -158,50 +158,54 @@ def start_subprocess(env, extra_args, tests, process_id, record_runtime:)
158158
end
159159

160160
command = [
161-
"rspec",
161+
*command_name,
162162
*extra_args,
163-
"--seed", @seed,
163+
"--seed", rand(0xFFFF).to_s,
164+
"--format", "ParallelTests::RSpec::RuntimeLogger",
165+
"--out", @runtime_log,
164166
"--format", "TurboTests::JsonRowsFormatter",
165-
"--out", tmp_filename,
166167
*record_runtime_options,
167-
*tests
168+
*tests,
168169
]
169-
command.unshift(ENV["BUNDLE_BIN_PATH"], "exec") if ENV["BUNDLE_BIN_PATH"]
170170

171171
if @verbose
172172
command_str = [
173173
env.map { |k, v| "#{k}=#{v}" }.join(" "),
174-
command.join(" ")
174+
command.join(" "),
175175
].select { |x| x.size > 0 }.join(" ")
176176

177-
STDERR.puts "Process #{process_id}: #{command_str}"
177+
warn "Process #{process_id}: #{command_str}"
178178
end
179179

180180
stdin, stdout, stderr, wait_thr = Open3.popen3(env, *command)
181181
stdin.close
182182

183183
@threads <<
184184
Thread.new do
185-
File.open(tmp_filename) do |fd|
186-
fd.each_line do |line|
187-
message = JSON.parse(line, symbolize_names: true)
185+
stdout.each_line do |line|
186+
result = line.split(env["RSPEC_FORMATTER_OUTPUT_ID"])
187+
188+
output = result.shift
189+
print(output) unless output.empty?
190+
191+
message = result.shift
192+
next unless message
188193

189-
message[:process_id] = process_id
190-
@messages << message
191-
end
194+
message = JSON.parse(message, symbolize_names: true)
195+
message[:process_id] = process_id
196+
@messages << message
192197
end
193198

194-
@messages << {type: "exit", process_id: process_id}
199+
@messages << { type: "exit", process_id: process_id }
195200
end
196201

197-
@threads << start_copy_thread(stdout, STDOUT)
198202
@threads << start_copy_thread(stderr, STDERR)
199203

200-
@threads << Thread.new {
204+
@threads << Thread.new do
201205
unless wait_thr.value.success?
202-
@messages << {type: "error"}
206+
@messages << { type: "error" }
203207
end
204-
}
208+
end
205209

206210
wait_thr
207211
end

lib/turbo_tests/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module TurboTests
2-
VERSION = "2.2.1"
2+
VERSION = "2.2.2"
33
end

0 commit comments

Comments
 (0)