Skip to content

Commit

Permalink
Stream RubyGems patch to make Windows work
Browse files Browse the repository at this point in the history
  • Loading branch information
deivid-rodriguez committed Apr 5, 2024
1 parent 3843e81 commit 0ccfb16
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/turbo_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,5 @@ def notification
end
end
end

require "turbo_tests/windows" if RUBY_PLATFORM.match?(/mingw|mswin/)
75 changes: 75 additions & 0 deletions lib/turbo_tests/windows.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# frozen_string_literal: true

module TurboTests
class Runner
private

def start_subprocess(env, extra_args, tests, process_id, record_runtime:)
if tests.empty?
@messages << {
type: "exit",
process_id: process_id,
}
else
require "securerandom"
env["RSPEC_FORMATTER_OUTPUT_ID"] = SecureRandom.uuid
env["RUBYOPT"] = ["-I#{File.expand_path("..", __dir__)}", ENV["RUBYOPT"]].compact.join(" ")

command_name = Gem.win_platform? ? [Gem.ruby, "bin/rspec"] : "bin/rspec"

command = [
*command_name,
*extra_args,
"--seed", rand(0xFFFF).to_s,
"--format", "ParallelTests::RSpec::RuntimeLogger",
"--out", @runtime_log,
"--require", File.expand_path("windows_json_rows_formatter", __dir__),
"--format", "TurboTests::WindowsJsonRowsFormatter",
*tests
]

if @verbose
command_str = [
env.map {|k, v| "#{k}=#{v}" }.join(" "),
command.join(" "),
].select {|x| x.size > 0 }.join(" ")

warn "Process #{process_id}: #{command_str}"
end

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

@threads <<
Thread.new do
require "json"
stdout.each_line do |line|
result = line.split(env["RSPEC_FORMATTER_OUTPUT_ID"])

output = result.shift
print(output) unless output.empty?

message = result.shift
next unless message

message = JSON.parse(message, symbolize_names: true)
message[:process_id] = process_id
@messages << message
end

@messages << { type: "exit", process_id: process_id }
end

@threads << start_copy_thread(stderr, STDERR)

@threads << Thread.new do
unless wait_thr.value.success?
@messages << { type: "error" }
end
end

wait_thr
end
end
end
end

0 comments on commit 0ccfb16

Please sign in to comment.