From 4425e06b4c16917b3dc6dba0964394993a9a746e Mon Sep 17 00:00:00 2001 From: priceline-rosenfeld <99750625+priceline-rosenfeld@users.noreply.github.com> Date: Thu, 25 Apr 2024 16:55:45 -0300 Subject: [PATCH] Restore back options --verbose-process-command and --verbose-rerun-command (#952) * Restore back options --verbose-process-command and --verbose-rerun-command implements issue #951 * Reference Github PR in Changelog * Remove :verbose_command option It's now just an alias to --verbose-process-command and --verbose-rerun-command combined. --- CHANGELOG.md | 3 +++ Readme.md | 4 +++- lib/parallel_tests/cli.rb | 6 ++++-- lib/parallel_tests/test/runner.rb | 2 +- spec/integration_spec.rb | 14 ++++++++++++++ spec/parallel_tests/cli_spec.rb | 18 +++++++++++++++--- 6 files changed, 40 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c64c101..11b7d724 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Changelog ## Unreleased +- Restored the `--verbose-process-command` and `--verbose-rerun-command` options, removed in version 4.0.0. +See [#952](https://github.com/grosser/parallel_tests/pull/952). +`--verbose-command` continues to be supported and is equivalent to set the 2 options above. ### Breaking Changes diff --git a/Readme.md b/Readme.md index 983d941c..465a110c 100644 --- a/Readme.md +++ b/Readme.md @@ -284,7 +284,9 @@ Options are: --first-is-1 Use "1" as TEST_ENV_NUMBER to not reuse the default test environment --fail-fast Stop all groups when one group fails (best used with --test-options '--fail-fast' if supported --verbose Print debug output - --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 + --verbose-command Combines options --verbose-process-command and --verbose-rerun-command + --verbose-process-command Print the command that will be executed by each process before it begins + --verbose-rerun-command After a process fails, print the command executed by that process --quiet Print only tests output -v, --version Show Version -h, --help Show this. diff --git a/lib/parallel_tests/cli.rb b/lib/parallel_tests/cli.rb index 161fda29..54367544 100644 --- a/lib/parallel_tests/cli.rb +++ b/lib/parallel_tests/cli.rb @@ -146,7 +146,7 @@ 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_command] + if options[:verbose] || options[:verbose_rerun_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] @@ -291,7 +291,9 @@ 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-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("--verbose-command", "Combines options --verbose-process-command and --verbose-rerun-command") { options.merge! verbose_process_command: true, verbose_rerun_command: true } + opts.on("--verbose-process-command", "Print the command that will be executed by each process before it begins") { options[:verbose_process_command] = true } + opts.on("--verbose-rerun-command", "After a process fails, print the command executed by that process") { options[:verbose_rerun_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 25841d73..d77a40bb 100644 --- a/lib/parallel_tests/test/runner.rb +++ b/lib/parallel_tests/test/runner.rb @@ -293,7 +293,7 @@ def set_unknown_runtime(tests, options) end def report_process_command?(options) - options[:verbose] || options[:verbose_command] + options[:verbose] || options[:verbose_process_command] end end end diff --git a/spec/integration_spec.rb b/spec/integration_spec.rb index 88c6c5bc..294d21eb 100644 --- a/spec/integration_spec.rb +++ b/spec/integration_spec.rb @@ -241,6 +241,20 @@ def test_unicode 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 match 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 match 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 7ac87691..5816496b 100644 --- a/spec/parallel_tests/cli_spec.rb +++ b/spec/parallel_tests/cli_spec.rb @@ -57,7 +57,19 @@ def call(*args) it "parses --verbose-command" do expect(call(['test', '--verbose-command'])).to eq( - defaults.merge(verbose_command: true) + defaults.merge(verbose_process_command: true, verbose_rerun_command: 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) ) end @@ -239,10 +251,10 @@ def self.it_prints_nothing_about_rerun_commands(options) it_prints_nothing_about_rerun_commands(verbose: false) end - context "with verbose command" do + context "with verbose rerun command" do it "prints command if there is a failure" do expect do - subject.send(:report_failure_rerun_commmand, single_failed_command, verbose_command: true) + 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\nTEST_ENV_NUMBER= PARALLEL_TEST_GROUPS= foo\n").to_stdout end end