Skip to content

Commit 818b296

Browse files
authored
bring back env replacement behavior (#875)
1 parent 3fc0d4a commit 818b296

3 files changed

Lines changed: 14 additions & 2 deletions

File tree

lib/parallel_tests/test/runner.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,17 @@ def tests_with_size(tests, options)
8686
end
8787

8888
def execute_command(cmd, process_number, num_processes, options)
89+
number = test_env_number(process_number, options).to_s
8990
env = (options[:env] || {}).merge(
90-
"TEST_ENV_NUMBER" => test_env_number(process_number, options).to_s,
91+
"TEST_ENV_NUMBER" => number,
9192
"PARALLEL_TEST_GROUPS" => num_processes.to_s,
9293
"PARALLEL_PID_FILE" => ParallelTests.pid_file_path
9394
)
9495
cmd = ["nice", *cmd] if options[:nice]
9596

97+
# being able to run with for example `-output foo-$TEST_ENV_NUMBER` worked originally and is convenient
98+
cmd.map! { |c| c.gsub("$TEST_ENV_NUMBER", number).gsub("${TEST_ENV_NUMBER}", number) }
99+
96100
puts Shellwords.shelljoin(cmd) if report_process_command?(options) && !options[:serialize_stdout]
97101

98102
execute_command_and_capture_output(env, cmd, options)

spec/parallel_tests/cli_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def call(*args)
201201
end
202202
end
203203

204-
describe ".report_failure_rerun_commmand" do
204+
describe ".report_failure_rerun_command" do
205205
let(:single_failed_command) { [{ exit_status: 1, command: ['foo'], seed: nil, output: 'blah' }] }
206206

207207
it "prints nothing if there are no failures" do

spec/parallel_tests/test/runner_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,14 @@ def run_with_file(content)
581581
end
582582
end
583583

584+
it "allows using TEST_ENV_NUMBER in arguments" do
585+
run_with_file("puts ARGV") do |path|
586+
result = call(["ruby", path, "$TEST_ENV_NUMBER"], 1, 4, {})
587+
expect(result[:stdout].chomp).to eq '2'
588+
expect(result[:exit_status]).to eq 0
589+
end
590+
end
591+
584592
describe "rspec seed" do
585593
it "includes seed when provided" do
586594
run_with_file("puts 'Run options: --seed 555'") do |path|

0 commit comments

Comments
 (0)