diff --git a/CHANGELOG.md b/CHANGELOG.md index f79ef208..2e8ea26b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Unreleased ### Breaking Changes +- The `--verbose-process-command` and `--verbose-rerun-command` are combined into `--verbose-command`. See [#884](https://github.com/grosser/parallel_tests/pull/884). ### Added diff --git a/lib/parallel_tests/cli.rb b/lib/parallel_tests/cli.rb index 8c3872c4..33ad63e0 100644 --- a/lib/parallel_tests/cli.rb +++ b/lib/parallel_tests/cli.rb @@ -131,12 +131,12 @@ def report_failure_rerun_commmand(test_results, options) failing_sets = test_results.reject { |r| r[:exit_status] == 0 } return if failing_sets.none? - if options[:verbose] || options[:verbose_rerun_command] + if options[:verbose] || options[:verbose_command] puts "\n\nTests have failed for a parallel_test group. Use the following command to run the group again:\n\n" failing_sets.each do |failing_set| command = failing_set[:command] command = @runner.command_with_seed(command, failing_set[:seed]) if failing_set[:seed] - puts Shellwords.shelljoin(command) + @runner.print_command(command, failing_set[:env] || {}) end end end @@ -261,8 +261,7 @@ def parse_options!(argv) opts.on("--first-is-1", "Use \"1\" as TEST_ENV_NUMBER to not reuse the default test environment") { options[:first_is_1] = true } opts.on("--fail-fast", "Stop all groups when one group fails (best used with --test-options '--fail-fast' if supported") { options[:fail_fast] = true } opts.on("--verbose", "Print debug output") { options[:verbose] = true } - opts.on("--verbose-process-command", "Displays only the command that will be executed by each process") { options[:verbose_process_command] = true } - opts.on("--verbose-rerun-command", "When there are failures, displays the command executed by each process that failed") { options[:verbose_rerun_command] = true } + opts.on("--verbose-command", "Displays the command that will be executed by each process and when there are failures displays the command executed by each process that failed") { options[:verbose_command] = true } opts.on("--quiet", "Print only tests output") { options[:quiet] = true } opts.on("-v", "--version", "Show Version") do puts ParallelTests::VERSION diff --git a/lib/parallel_tests/test/runner.rb b/lib/parallel_tests/test/runner.rb index d61bec44..90007bfe 100644 --- a/lib/parallel_tests/test/runner.rb +++ b/lib/parallel_tests/test/runner.rb @@ -97,11 +97,16 @@ def execute_command(cmd, process_number, num_processes, options) # 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) } - puts Shellwords.shelljoin(cmd) if report_process_command?(options) && !options[:serialize_stdout] + print_command(cmd, env) if report_process_command?(options) && !options[:serialize_stdout] execute_command_and_capture_output(env, cmd, options) end + def print_command(command, env) + env_str = ['TEST_ENV_NUMBER', 'PARALLEL_TEST_GROUPS'].map { |e| "#{e}=#{env[e]}" }.join(' ') + puts [env_str, Shellwords.shelljoin(command)].compact.join(' ') + end + def execute_command_and_capture_output(env, cmd, options) pid = nil @@ -119,7 +124,7 @@ def execute_command_and_capture_output(env, cmd, options) output = "#{Shellwords.shelljoin(cmd)}\n#{output}" if report_process_command?(options) && options[:serialize_stdout] - { stdout: output, exit_status: exitstatus, command: cmd, seed: seed } + { env: env, stdout: output, exit_status: exitstatus, command: cmd, seed: seed } end def find_results(test_output) @@ -286,7 +291,7 @@ def set_unknown_runtime(tests, options) end def report_process_command?(options) - options[:verbose] || options[:verbose_process_command] + options[:verbose] || options[:verbose_command] end end end diff --git a/spec/integration_spec.rb b/spec/integration_spec.rb index 3e364281..f3e54439 100644 --- a/spec/integration_spec.rb +++ b/spec/integration_spec.rb @@ -66,8 +66,8 @@ def self.it_runs_the_default_folder_if_it_exists(type, test_folder) end end - let(:printed_commands) { /specs? per process\nbundle exec rspec/ } - let(:printed_rerun) { "run the group again:\n\nbundle exec rspec" } + let(:printed_commands) { /specs? per process\nTEST_ENV_NUMBER=(\d+)? PARALLEL_TEST_GROUPS=\d+ bundle exec rspec/ } + let(:printed_rerun) { /run the group again:\n\nTEST_ENV_NUMBER=(\d+)? PARALLEL_TEST_GROUPS=\d+ bundle exec rspec/ } context "running tests sequentially" do it "exits with 0 when each run is successful" do @@ -231,30 +231,16 @@ def test_unicode expect(result).to include('Took') end - it "shows command and rerun with --verbose" do + it "shows command and rerun with --verbose-command" do write 'spec/xxx_spec.rb', 'describe("it"){it("should"){puts "TEST1"}}' write 'spec/xxx2_spec.rb', 'describe("it"){it("should"){expect(1).to eq(2)}}' - result = run_tests ["spec", "--verbose"], type: 'rspec', fail: true + result = run_tests ["spec", "--verbose-command"], type: 'rspec', fail: true expect(result).to match printed_commands - expect(result).to include printed_rerun + expect(result).to match printed_rerun expect(result).to include "bundle exec rspec spec/xxx_spec.rb" expect(result).to include "bundle exec rspec spec/xxx2_spec.rb" end - it "shows only rerun with --verbose-rerun-command" do - write 'spec/xxx_spec.rb', 'describe("it"){it("should"){expect(1).to eq(2)}}' - result = run_tests ["spec", "--verbose-rerun-command"], type: 'rspec', fail: true - expect(result).to include printed_rerun - expect(result).to_not match printed_commands - end - - it "shows only process with --verbose-process-command" do - write 'spec/xxx_spec.rb', 'describe("it"){it("should"){expect(1).to eq(2)}}' - result = run_tests ["spec", "--verbose-process-command"], type: 'rspec', fail: true - expect(result).to_not include printed_rerun - expect(result).to match printed_commands - end - it "fails when tests fail" do write 'spec/xxx_spec.rb', 'describe("it"){it("should"){puts "TEST1"}}' write 'spec/xxx2_spec.rb', 'describe("it"){it("should"){expect(1).to eq(2)}}' diff --git a/spec/parallel_tests/cli_spec.rb b/spec/parallel_tests/cli_spec.rb index 417367fa..b41ed8b6 100644 --- a/spec/parallel_tests/cli_spec.rb +++ b/spec/parallel_tests/cli_spec.rb @@ -55,15 +55,9 @@ def call(*args) expect(call(["test", "--verbose"])).to eq(defaults.merge(verbose: true)) end - it "parses --verbose-process-command" do - expect(call(['test', '--verbose-process-command'])).to eq( - defaults.merge(verbose_process_command: true) - ) - end - - it "parses --verbose-rerun-command" do - expect(call(['test', '--verbose-rerun-command'])).to eq( - defaults.merge(verbose_rerun_command: true) + it "parses --verbose-command" do + expect(call(['test', '--verbose-command'])).to eq( + defaults.merge(verbose_command: true) ) end @@ -225,6 +219,10 @@ def self.it_prints_nothing_about_rerun_commands(options) end describe "failure" do + before do + subject.instance_variable_set(:@runner, ParallelTests::Test::Runner) + end + context 'without options' do it_prints_nothing_about_rerun_commands({}) end @@ -233,11 +231,11 @@ def self.it_prints_nothing_about_rerun_commands(options) it_prints_nothing_about_rerun_commands(verbose: false) end - context "with verbose rerun" do + context "with verbose command" do it "prints command if there is a failure" do expect do - subject.send(:report_failure_rerun_commmand, single_failed_command, verbose_rerun_command: true) - end.to output("\n\nTests have failed for a parallel_test group. Use the following command to run the group again:\n\nfoo\n").to_stdout + subject.send(:report_failure_rerun_commmand, single_failed_command, verbose_command: true) + end.to output("\n\nTests have failed for a parallel_test group. Use the following command to run the group again:\n\nTEST_ENV_NUMBER= PARALLEL_TEST_GROUPS= foo\n").to_stdout end end @@ -245,7 +243,7 @@ def self.it_prints_nothing_about_rerun_commands(options) it "prints a message and the command if there is a failure" do expect do subject.send(:report_failure_rerun_commmand, single_failed_command, verbose: true) - end.to output("\n\nTests have failed for a parallel_test group. Use the following command to run the group again:\n\nfoo\n").to_stdout + end.to output("\n\nTests have failed for a parallel_test group. Use the following command to run the group again:\n\nTEST_ENV_NUMBER= PARALLEL_TEST_GROUPS= foo\n").to_stdout end it "prints multiple commands if there are multiple failures" do @@ -259,7 +257,7 @@ def self.it_prints_nothing_about_rerun_commands(options) ], { verbose: true } ) - end.to output(/foo\nbar\nbaz/).to_stdout + end.to output(/\sfoo\n.+?\sbar\n.+?\sbaz/).to_stdout end it "only includes failures" do @@ -273,14 +271,13 @@ def self.it_prints_nothing_about_rerun_commands(options) ], { verbose: true } ) - end.to output(/foo --color\nbaz/).to_stdout + end.to output(/\sfoo --color\n.+?\sbaz/).to_stdout end it "prints the command with the seed added by the runner" do command = ['rspec', '--color', 'spec/foo_spec.rb'] seed = 555 - subject.instance_variable_set(:@runner, ParallelTests::Test::Runner) expect(ParallelTests::Test::Runner).to receive(:command_with_seed).with(command, seed) .and_return(['my', 'seeded', 'command', 'result', '--seed', seed]) single_failed_command[0].merge!(seed: seed, command: command)