Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ gem "stackprof"
gem "standard"
gem "ruby-prof"

gem "benchmark"
gem "benchmark-ips"

case ENV["PRISM_VERSION"]&.strip&.downcase
Expand Down
10 changes: 2 additions & 8 deletions spec/integration/syntax_suggest_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@

module SyntaxSuggest
RSpec.describe "Integration tests that don't spawn a process (like using the cli)" do
before(:each) do
skip "Benchmark is not available" unless defined?(::Benchmark)
end

it "does not timeout on massive files" do
next unless ENV["SYNTAX_SUGGEST_TIMEOUT"]

Expand All @@ -17,7 +13,7 @@ module SyntaxSuggest

io = StringIO.new

benchmark = Benchmark.measure do
benchmark_measure do
debug_perf do
SyntaxSuggest.call(
io: io,
Expand All @@ -28,7 +24,6 @@ module SyntaxSuggest
end

debug_display(io.string)
debug_display(benchmark)

expect(io.string).to include(<<~EOM)
6 class SyntaxTree < Ripper
Expand All @@ -46,15 +41,14 @@ module SyntaxSuggest
io = StringIO.new

debug_perf do
benchmark = Benchmark.measure do
benchmark_measure do
SyntaxSuggest.call(
io: io,
source: file.read,
filename: file
)
end
debug_display(io.string)
debug_display(benchmark)
end

expect(io.string).to_not include("def ruby_install_binstub_path")
Expand Down
10 changes: 10 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ def debug_perf
end
end

def benchmark_measure
raise "No block given" unless block_given?

if defined?(::Benchmark)
debug_display(Benchmark.measure { yield })
else
yield
end
end

def run!(cmd, raise_on_nonzero_exit: true)
out = `#{cmd} 2>&1`
raise "Command: #{cmd} failed: #{out}" if !$?.success? && raise_on_nonzero_exit
Expand Down