From 6363819a22f4944174acd688eb3fedcf4b6ad52c Mon Sep 17 00:00:00 2001 From: Zsolt Kozaroczy Date: Sat, 13 May 2023 00:28:32 +0200 Subject: [PATCH] Fix $TEST_ENV_NUMBER replacing code to not affect all processes (#905) --- lib/parallel_tests/test/runner.rb | 2 +- spec/integration_spec.rb | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/parallel_tests/test/runner.rb b/lib/parallel_tests/test/runner.rb index 47651012..17376782 100644 --- a/lib/parallel_tests/test/runner.rb +++ b/lib/parallel_tests/test/runner.rb @@ -95,7 +95,7 @@ def execute_command(cmd, process_number, num_processes, options) cmd = ["nice", *cmd] if options[:nice] # being able to run with for example `-output foo-$TEST_ENV_NUMBER` worked originally and is convenient - cmd.map! { |c| c.gsub("$TEST_ENV_NUMBER", number).gsub("${TEST_ENV_NUMBER}", number) } + cmd = cmd.map { |c| c.gsub("$TEST_ENV_NUMBER", number).gsub("${TEST_ENV_NUMBER}", number) } print_command(cmd, env) if report_process_command?(options) && !options[:serialize_stdout] diff --git a/spec/integration_spec.rb b/spec/integration_spec.rb index 19ea69d2..88c6c5bc 100644 --- a/spec/integration_spec.rb +++ b/spec/integration_spec.rb @@ -288,6 +288,11 @@ def test_unicode expect(result.gsub('"', '').chars.sort).to eq(['0', '2', '3', '4']) end + it "can exec given commands with $TEST_ENV_NUMBER" do + result = run_tests ['-e', 'echo foo-$TEST_ENV_NUMBER'], processes: 4 + expect(result.split(/\n+/).sort).to eq(['foo-', 'foo-2', 'foo-3', 'foo-4']) + end + it "can exec given command non-parallel" do result = run_tests( ['-e', 'ruby -e "sleep(rand(10)/100.0); puts ENV[:TEST_ENV_NUMBER.to_s].inspect"'],