brew icon indicating copy to clipboard operation
brew copied to clipboard

Fix byebug when running tests

Open apainintheneck opened this issue 1 year ago • 3 comments

brew doctor output

Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry or file an issue; just ignore this. Thanks!

Warning: Some installed formulae are deprecated or disabled.
You should find replacements for the following formulae:
  llvm@11

Verification

  • [X] My "brew doctor output" above says Your system is ready to brew. and am still able to reproduce my issue.
  • [X] I ran brew update twice and am still able to reproduce my issue.
  • [X] This issue's title and/or description do not reference a single formula e.g. brew install wget. If they do, open an issue at https://github.com/Homebrew/homebrew-core/issues/new/choose instead.

brew config output

HOMEBREW_VERSION: 4.2.9-42-gc355461
ORIGIN: https://github.com/Homebrew/brew
HEAD: c35546167da22c3c00d34332ff84a1bb40153766
Last commit: 10 hours ago
Core tap HEAD: b0cbf72d8dfb4b17daf988b4cb48ca01f1a72052
Core tap last commit: 7 hours ago
Core tap JSON: 19 Feb 21:36 UTC
Core cask tap HEAD: 10b89b8ddeac7513b77c0d19afe6b759146b6d65
Core cask tap last commit: 8 hours ago
Core cask tap JSON: 19 Feb 21:36 UTC
HOMEBREW_PREFIX: /usr/local
HOMEBREW_AUTOREMOVE: set
HOMEBREW_CASK_OPTS: []
HOMEBREW_DEVELOPER: set
HOMEBREW_DISPLAY: /private/tmp/com.apple.launchd.A51IW62L7n/org.macosforge.xquartz:0
HOMEBREW_EDITOR: nano
HOMEBREW_MAKE_JOBS: 4
HOMEBREW_SORBET_RUNTIME: set
Homebrew Ruby: 3.1.4 => /usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/3.1.4/bin/ruby
CPU: quad-core 64-bit ivybridge
Clang: 12.0.0 build 1200
Git: 2.24.3 => /Applications/Xcode.app/Contents/Developer/usr/bin/git
Curl: 7.64.1 => /usr/bin/curl
macOS: 10.15.7-x86_64
CLT: 12.0.0.32.29
Xcode: 12.4

What were you trying to do (and why)?

This was something that came up in the team Slack channel. @dduugg first noticed that byebug wasn't working in tests even when running brew tests --byebug and setting breakpoints. I was able to reproduce the bug afterwards.

What happened (include all command output)?

I set a breakpoint with byebug and expected the tests to stop when I hit the breakpoint. That didn't work. I then added the :byebug tag to the test itself and saw the byebug prompt but it wasn't interactive and the rest of the test continued to run after that point immediately.

What did you expect to happen?

I expected to be able to set brew tests --byebug and set breakpoints and for the test suit to stop when they hit those breakpoints. This is helpful for debugging weird test failures.

Step-by-step reproduction instructions (by running brew commands)

  1. Change the tests to add a breakpoint.
diff --git a/Library/Homebrew/test/resource_spec.rb b/Library/Homebrew/test/resource_spec.rb
index e509902bd..4df9ed094 100644
--- a/Library/Homebrew/test/resource_spec.rb
+++ b/Library/Homebrew/test/resource_spec.rb
@@ -82,7 +82,8 @@ RSpec.describe Resource do
   end
 
   describe "#version" do
-    it "sets the version" do
+    it "sets the version", :byebug do
+      byebug
       resource.version("1.0")
       expect(resource.version).to eq(Version.parse("1.0"))
       expect(resource.version).not_to be_detected_from_url
  1. Run brew tests --byebug --only=resource
Randomized with seed 45405
1 process for 1 spec, ~ 1 spec per process
...
[82, 91] in /usr/local/Homebrew/Library/Homebrew/test/resource_spec.rb
   82:   end
   83: 
   84:   describe "#version" do
   85:     it "sets the version", :byebug do
   86:       byebug
=> 87:       resource.version("1.0")
   88:       expect(resource.version).to eq(Version.parse("1.0"))
   89:       expect(resource.version).not_to be_detected_from_url
   90:     end
   91: 
.......................



Took 5 seconds

apainintheneck avatar Feb 20 '24 04:02 apainintheneck

My best guess is that this was caused by https://github.com/Homebrew/brew/pull/12967 which turned off stdin to avoid flaky tests. We could probably just conditionally include stdin when running tests with --byebug set.

@issyl0 also suggested maybe moving to the debug gem since it's more actively maintained and works better with Ruby 3. It seems like we'd have to figure out how to build the psych gem which has native dependencies to make that work though. @dduugg saw some failures when he tried it locally and @Bo98 suggested that that might be related to how https://github.com/Homebrew/homebrew-portable-ruby gets built.

apainintheneck avatar Feb 20 '24 04:02 apainintheneck

Thanks for taking the time to write this u, and for your add’l investigative work. For the time being, it looks like we can include debug as long as we also pin psych to < 5.

dduugg avatar Feb 20 '24 05:02 dduugg

@issyl0 also suggested maybe moving to the debug gem since it's more actively maintained and works better with Ruby 3.

This seems ideal 👍🏻

MikeMcQuaid avatar Feb 20 '24 08:02 MikeMcQuaid