File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ gem "stackprof"
1111gem "standard"
1212gem "ruby-prof"
1313
14+ gem "benchmark"
1415gem "benchmark-ips"
1516
1617case ENV [ "PRISM_VERSION" ] &.strip &.downcase
Original file line number Diff line number Diff line change 44
55module SyntaxSuggest
66 RSpec . describe "Integration tests that don't spawn a process (like using the cli)" do
7- before ( :each ) do
8- skip "Benchmark is not available" unless defined? ( ::Benchmark )
9- end
10-
117 it "does not timeout on massive files" do
128 next unless ENV [ "SYNTAX_SUGGEST_TIMEOUT" ]
139
@@ -17,7 +13,7 @@ module SyntaxSuggest
1713
1814 io = StringIO . new
1915
20- benchmark = Benchmark . measure do
16+ benchmark_measure do
2117 debug_perf do
2218 SyntaxSuggest . call (
2319 io : io ,
@@ -28,7 +24,6 @@ module SyntaxSuggest
2824 end
2925
3026 debug_display ( io . string )
31- debug_display ( benchmark )
3227
3328 expect ( io . string ) . to include ( <<~EOM )
3429 6 class SyntaxTree < Ripper
@@ -46,15 +41,14 @@ module SyntaxSuggest
4641 io = StringIO . new
4742
4843 debug_perf do
49- benchmark = Benchmark . measure do
44+ benchmark_measure do
5045 SyntaxSuggest . call (
5146 io : io ,
5247 source : file . read ,
5348 filename : file
5449 )
5550 end
5651 debug_display ( io . string )
57- debug_display ( benchmark )
5852 end
5953
6054 expect ( io . string ) . to_not include ( "def ruby_install_binstub_path" )
Original file line number Diff line number Diff line change @@ -85,6 +85,16 @@ def debug_perf
8585 end
8686end
8787
88+ def benchmark_measure
89+ raise "No block given" unless block_given?
90+
91+ if defined? ( ::Benchmark )
92+ debug_display ( Benchmark . measure { yield } )
93+ else
94+ yield
95+ end
96+ end
97+
8898def run! ( cmd , raise_on_nonzero_exit : true )
8999 out = `#{ cmd } 2>&1`
90100 raise "Command: #{ cmd } failed: #{ out } " if !$?. success? && raise_on_nonzero_exit
You can’t perform that action at this time.
0 commit comments