Skip to content

Commit

Permalink
Restructure logs for launching details (#247)
Browse files Browse the repository at this point in the history
* Remove logging from Command
* Log launching details from executable instead
  • Loading branch information
AlexB52 authored Jan 26, 2025
1 parent a722785 commit d817bf3
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 92 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ retest --diff origin/main # Test changes from a branch
Stay in control with an interactive shell for test management. Start Retest and enter `h` to explore available commands.

```
Setup identified: [RAKE]. Using command: 'bundle exec rake test TEST=<test>'
Setup: [RAKE]
Command: 'bundle exec rake test TEST=<test>'
Watcher: [WATCHEXEC]
Launching Retest...
Ready to refactor! You can make file changes now
Expand Down
20 changes: 17 additions & 3 deletions exe/retest
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,39 @@ program = Retest::Program.new(
runner: runner
)

# === LOGGING ===
case command
when Retest::Command::Rspec then puts "Setup: [RSPEC]"
when Retest::Command::Rails then puts "Setup: [RAILS]"
when Retest::Command::Rake then puts "Setup: [RAKE]"
when Retest::Command::Ruby then puts "Setup: [RUBY]"
else puts "Setup: [UNKNOWN]"
end

puts "Command: '#{command}'"

# === DIFF ACTION ===
if options.params[:diff]
puts
program.diff(options.params[:diff])
return
end

# === LOGGING ===
if watcher == Retest::Watcher::Watchexec
puts "Watcher: [WATCHEXEC]"
else
puts "Watcher: [LISTEN]"
end

launching_message = "Launching Retest..."
launching_message = "\nLaunching Retest..."
if options.force_polling?
launching_message = "Launching Retest with polling method..."
end

# Main action

puts launching_message

# === MAIN ACTION ===
Retest.listen(options, listener: watcher) do |modified, added, removed|
begin
repository.sync(added: added, removed: removed)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ def test_start_help
launch_retest @command

assert_output_matches <<~EXPECTED.chomp
Setup identified: [RAKE]. Using command: 'bundle exec rake test TEST=<test>'
Setup: [RAKE]
Command: 'bundle exec rake test TEST=<test>'
Watcher: [LISTEN]
Launching Retest...
Ready to refactor! You can make file changes now
Expand Down
8 changes: 6 additions & 2 deletions features/hanami-app/retest/retest_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,10 @@ def test_with_no_command
launch_retest 'retest'

assert_output_matches <<~OUTPUT
Setup identified: [RAKE]. Using command: 'bundle exec rake test TEST=<test>'
Setup: [RAKE]
Command: 'bundle exec rake test TEST=<test>'
Watcher: [LISTEN]
Launching Retest...
Ready to refactor! You can make file changes now
OUTPUT
Expand All @@ -86,8 +88,10 @@ def test_with_no_command_all
launch_retest 'retest --all'

assert_output_matches <<~OUTPUT
Setup identified: [RAKE]. Using command: 'bundle exec rake test'
Setup: [RAKE]
Command: 'bundle exec rake test'
Watcher: [LISTEN]
Launching Retest...
Ready to refactor! You can make file changes now
OUTPUT
Expand Down
12 changes: 9 additions & 3 deletions features/rails-app/retest/retest_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ def test_with_no_command
launch_retest 'retest'

assert_output_matches <<~OUTPUT
Setup identified: [RAILS]. Using command: 'bin/rails test <test>'
Setup: [RAILS]
Command: 'bin/rails test <test>'
Watcher: [LISTEN]
Launching Retest...
Ready to refactor! You can make file changes now
OUTPUT
Expand All @@ -96,8 +98,10 @@ def test_with_no_command_all
launch_retest 'retest --all'

assert_output_matches <<~OUTPUT
Setup identified: [RAILS]. Using command: 'bin/rails test'
Setup: [RAILS]
Command: 'bin/rails test'
Watcher: [LISTEN]
Launching Retest...
Ready to refactor! You can make file changes now
OUTPUT
Expand Down Expand Up @@ -142,7 +146,9 @@ def test_diffs_from_other_branch
launch_retest 'retest --diff=main'

assert_output_matches <<~EXPECTED, "7 runs, 9 assertions, 0 failures, 0 errors, 0 skips"
Setup identified: [RAILS]. Using command: 'bin/rails test <test>'
Setup: [RAILS]
Command: 'bin/rails test <test>'
Tests selected:
- test/controllers/books_controller_test.rb
- test/models/book_test.rb
Expand Down
8 changes: 6 additions & 2 deletions features/rspec-rails/retest/retest_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ def test_with_no_command
launch_retest 'retest'

assert_output_matches <<~OUTPUT
Setup identified: [RSPEC]. Using command: 'bundle exec rspec <test>'
Setup: [RSPEC]
Command: 'bundle exec rspec <test>'
Watcher: [LISTEN]
Launching Retest...
Ready to refactor! You can make file changes now
OUTPUT
Expand All @@ -96,8 +98,10 @@ def test_with_no_command_all
launch_retest 'retest --all'

assert_output_matches <<~OUTPUT
Setup identified: [RSPEC]. Using command: 'bundle exec rspec'
Setup: [RSPEC]
Command: 'bundle exec rspec'
Watcher: [LISTEN]
Launching Retest...
Ready to refactor! You can make file changes now
OUTPUT
Expand Down
4 changes: 3 additions & 1 deletion features/rspec-ruby/retest/retest_test/flags_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ def test_with_no_command
launch_retest 'retest'

assert_output_matches <<~OUTPUT
Setup identified: [RSPEC]. Using command: 'bundle exec rspec <test>'
Setup: [RSPEC]
Command: 'bundle exec rspec <test>'
Watcher: [LISTEN]
Launching Retest...
Ready to refactor! You can make file changes now
OUTPUT
Expand Down
12 changes: 9 additions & 3 deletions features/ruby-app/retest/retest_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ def test_start_retest
launch_retest(@command)

assert_output_matches <<~EXPECTED
Setup identified: [RUBY]. Using command: 'bundle exec ruby <test>'
Setup: [RUBY]
Command: 'bundle exec ruby <test>'
Watcher: [LISTEN]
Launching Retest...
Ready to refactor! You can make file changes now
EXPECTED
Expand All @@ -47,8 +49,10 @@ def test_start_retest
launch_retest(@command)

assert_output_matches <<~EXPECTED
Setup identified: [RUBY]. Using command: 'bundle exec ruby <test>'
Setup: [RUBY]
Command: 'bundle exec ruby <test>'
Watcher: [WATCHEXEC]
Launching Retest...
Ready to refactor! You can make file changes now
EXPECTED
Expand All @@ -70,8 +74,10 @@ def test_uses_watchexec_when_installed
launch_retest(@command)

assert_output_matches <<~EXPECTED
Setup identified: [RUBY]. Using command: 'bundle exec ruby <test>'
Setup: [RUBY]
Command: 'bundle exec ruby <test>'
Watcher: [WATCHEXEC]
Launching Retest...
Ready to refactor! You can make file changes now
EXPECTED
Expand Down
4 changes: 3 additions & 1 deletion features/ruby-bare/retest/scenarios/auto_flag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ def test_start_retest
launch_retest 'retest'

assert_output_matches <<~OUTPUT
Setup identified: [RUBY]. Using command: 'ruby <test>'
Setup: [RUBY]
Command: 'ruby <test>'
Watcher: [LISTEN]
Launching Retest...
Ready to refactor! You can make file changes now
OUTPUT
Expand Down
24 changes: 7 additions & 17 deletions lib/retest/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,21 @@ module Retest
class Command
extend Forwardable

def self.for_options(options, stdout: $stdout)
new(options: options, stdout: stdout).command
def self.for_options(options)
new(options: options).command
end

def_delegator :setup, :type
def_delegators :options, :params, :full_suite?, :auto?

attr_accessor :options, :setup
def initialize(options: Options.new, setup: Setup.new, stdout: $stdout)
attr_accessor :options, :setup, :setup_identified
def initialize(options: Options.new, setup: Setup.new)
@options = options
@setup = setup
@stdout = stdout
@setup_identified = nil
end

def command
options_command || default_command
options_command || setup_command
end

private
Expand All @@ -38,13 +37,8 @@ def options_command
end
end

def default_command
log "Setup identified: [#{type.upcase}]. Using command: '#{setup_command}'"
setup_command
end

def setup_command
case type
case setup.type
when :rake then rake_command
when :rspec then rspec_command
when :rails then rails_command
Expand All @@ -53,10 +47,6 @@ def setup_command
end
end

def log(message)
@stdout&.puts(message)
end

def hardcoded_command(command)
Hardcoded.new(command: command)
end
Expand Down
50 changes: 3 additions & 47 deletions test/retest/command/auto_flag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ class AutoFlagTest < MiniTest::Test

def setup
@setup = SetupFake.new
@out = StringIO.new

@subject = Command.new(setup: @setup, stdout: @out)
@subject = Command.new(setup: @setup)
end

def output
Expand All @@ -15,47 +13,27 @@ def output

def test_for_rspec_setup
@setup.type = :rspec

assert_equal 'bundle exec rspec <test>', @subject.command.to_s
assert_equal(<<~OUTPUT, output)
Setup identified: [RSPEC]. Using command: 'bundle exec rspec <test>'
OUTPUT
end

def test_for_rails_setup
@setup.type = :rails

assert_equal 'bundle exec rails test <test>', @subject.command.to_s
assert_equal(<<~OUTPUT, output)
Setup identified: [RAILS]. Using command: 'bundle exec rails test <test>'
OUTPUT
end

def test_for_ruby_setup
@setup.type = :ruby

assert_equal 'bundle exec ruby <test>', @subject.command.to_s
assert_equal(<<~OUTPUT, output)
Setup identified: [RUBY]. Using command: 'bundle exec ruby <test>'
OUTPUT
end

def test_for_rake_setup
@setup.type = :rake

assert_equal 'bundle exec rake test TEST=<test>', @subject.command.to_s
assert_equal(<<~OUTPUT, output)
Setup identified: [RAKE]. Using command: 'bundle exec rake test TEST=<test>'
OUTPUT
end

def test_for_unknown_setup
@setup.type = :unknown

assert_equal 'bundle exec ruby <test>', @subject.command.to_s
assert_equal(<<~OUTPUT, output)
Setup identified: [UNKNOWN]. Using command: 'bundle exec ruby <test>'
OUTPUT
end
end

Expand All @@ -64,12 +42,10 @@ class AutoAllFlagTest < MiniTest::Test

def setup
@setup = SetupFake.new
@out = StringIO.new

@subject = Command.new(
options: Options.new(['--all']),
setup: @setup,
stdout: @out)
setup: @setup
)
end

def output
Expand All @@ -78,47 +54,27 @@ def output

def test_for_rspec_setup
@setup.type = :rspec

assert_equal 'bundle exec rspec', @subject.command.to_s
assert_equal(<<~OUTPUT, output)
Setup identified: [RSPEC]. Using command: 'bundle exec rspec'
OUTPUT
end

def test_for_rails_setup
@setup.type = :rails

assert_equal 'bundle exec rails test', @subject.command.to_s
assert_equal(<<~OUTPUT, output)
Setup identified: [RAILS]. Using command: 'bundle exec rails test'
OUTPUT
end

def test_for_ruby_setup
@setup.type = :ruby

assert_equal 'bundle exec ruby <test>', @subject.command.to_s
assert_equal(<<~OUTPUT, output)
Setup identified: [RUBY]. Using command: 'bundle exec ruby <test>'
OUTPUT
end

def test_for_rake_setup
@setup.type = :rake

assert_equal 'bundle exec rake test', @subject.command.to_s
assert_equal(<<~OUTPUT, output)
Setup identified: [RAKE]. Using command: 'bundle exec rake test'
OUTPUT
end

def test_for_unknown_setup
@setup.type = :unknown

assert_equal 'bundle exec ruby <test>', @subject.command.to_s
assert_equal(<<~OUTPUT, output)
Setup identified: [UNKNOWN]. Using command: 'bundle exec ruby <test>'
OUTPUT
end
end
end
Loading

0 comments on commit d817bf3

Please sign in to comment.