diff options
author | Jack Bates <jack@nottheoilrig.com> | 2020-04-20 18:12:00 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-21 10:12:00 +0900 |
commit | a6d3e3687ba2ee26266400db6c77a07bc4ff8fca (patch) | |
tree | 4c463bdbef87971a1b3273fde98bce9692f2c9ae /test | |
parent | 08c2bcb952a0abbead263dcb0026eab58e736e1d (diff) |
Improve error messages (#1962)
* Add RuboCop Minitest extension
* Improve error messages
* Use chomp option
Diffstat (limited to 'test')
-rwxr-xr-x | test/test_go.rb | 1002 |
1 files changed, 525 insertions, 477 deletions
diff --git a/test/test_go.rb b/test/test_go.rb index 6f600620..e7a7dd62 100755 --- a/test/test_go.rb +++ b/test/test_go.rb @@ -23,28 +23,16 @@ BASE = File.expand_path('..', __dir__) Dir.chdir(BASE) FZF = "FZF_DEFAULT_OPTS= FZF_DEFAULT_COMMAND= #{BASE}/bin/fzf" -class NilClass - def include?(_str) - false - end - - def start_with?(_str) - false - end - - def end_with?(_str) - false - end -end - def wait since = Time.now - while Time.now - since < DEFAULT_TIMEOUT - return if yield + begin + yield + rescue Minitest::Assertion + raise if Time.now - since > DEFAULT_TIMEOUT sleep(0.05) + retry end - raise 'timeout' end class Shell @@ -89,7 +77,7 @@ class Tmux return unless shell == :fish send_keys 'function fish_prompt; end; clear', :Enter - self.until(&:empty?) + self.until { |lines| raise Minitest::Assertion unless lines.empty? } end def kill @@ -146,7 +134,7 @@ class Tmux send_keys 'C-l' if refresh && !ok end end - rescue StandardError + rescue Minitest::Assertion puts $ERROR_INFO.backtrace puts '>' * 80 puts lines @@ -160,10 +148,10 @@ class Tmux tries = 0 begin self.until do |lines| - send_keys ' ', 'C-u', 'hello', :Left, :Right - lines[-1].end_with?('hello') + send_keys ' ', 'C-u', :Enter, 'hello', :Left, :Right + raise Minitest::Assertion unless lines[-1] == 'hello' end - rescue StandardError + rescue Minitest::Assertion (tries += 1) < 5 ? retry : raise end send_keys 'C-u' @@ -184,17 +172,17 @@ class TestBase < Minitest::Test def tempname @temp_suffix ||= 0 [TEMPNAME, - caller_locations.map(&:label).find { |l| l =~ /^test_/ }, + caller_locations.map(&:label).find { |l| l.start_with?('test_') }, @temp_suffix].join('-') end def writelines(path, lines) File.unlink(path) while File.exist?(path) - File.open(path, 'w') { |f| f << lines.join($INPUT_RECORD_SEPARATOR) + $INPUT_RECORD_SEPARATOR } + File.open(path, 'w') { |f| f.puts lines } end def readonce - wait { File.exist?(tempname) } + wait { assert_path_exists tempname } File.read(tempname) ensure File.unlink(tempname) while File.exist?(tempname) @@ -232,7 +220,10 @@ class TestGoFZF < TestBase def test_vanilla tmux.send_keys "seq 1 100000 | #{fzf}", :Enter - tmux.until { |lines| lines.last =~ /^>/ && lines[-2] =~ /^ 100000/ } + tmux.until do |lines| + assert_equal '>', lines.last + assert_equal ' 100000/100000', lines[-2] + end lines = tmux.capture assert_equal ' 2', lines[-4] assert_equal '> 1', lines[-3] @@ -242,10 +233,10 @@ class TestGoFZF < TestBase # Testing basic key bindings tmux.send_keys '99', 'C-a', '1', 'C-f', '3', 'C-b', 'C-h', 'C-u', 'C-e', 'C-y', 'C-k', 'Tab', 'BTab' tmux.until do |lines| - lines[-4] == '> 3910' && - lines[-3] == ' 391' && - lines[-2] == ' 856/100000' && - lines[-1] == '> 391' + assert_equal '> 3910', lines[-4] + assert_equal ' 391', lines[-3] + assert_equal ' 856/100000', lines[-2] + assert_equal '> 391', lines[-1] end tmux.send_keys :Enter @@ -254,7 +245,7 @@ class TestGoFZF < TestBase def test_fzf_default_command tmux.send_keys fzf.sub('FZF_DEFAULT_COMMAND=', "FZF_DEFAULT_COMMAND='echo hello'"), :Enter - tmux.until { |lines| lines[-3] == '> hello' } + tmux.until { |lines| assert_equal '> hello', lines[-3] } tmux.send_keys :Enter assert_equal 'hello', readonce.chomp @@ -262,78 +253,78 @@ class TestGoFZF < TestBase def test_fzf_default_command_failure tmux.send_keys fzf.sub('FZF_DEFAULT_COMMAND=', 'FZF_DEFAULT_COMMAND=false'), :Enter - tmux.until { |lines| lines[-2].include?('Command failed: false') } + tmux.until { |lines| assert_equal ' [Command failed: false]', lines[-2] } tmux.send_keys :Enter end def test_key_bindings tmux.send_keys "#{FZF} -q 'foo bar foo-bar'", :Enter - tmux.until { |lines| lines.last =~ /^>/ } + tmux.until { |lines| assert_equal '> foo bar foo-bar', lines.last } # CTRL-A tmux.send_keys 'C-A', '(' - tmux.until { |lines| lines.last == '> (foo bar foo-bar' } + tmux.until { |lines| assert_equal '> (foo bar foo-bar', lines.last } # META-F tmux.send_keys :Escape, :f, ')' - tmux.until { |lines| lines.last == '> (foo) bar foo-bar' } + tmux.until { |lines| assert_equal '> (foo) bar foo-bar', lines.last } # CTRL-B tmux.send_keys 'C-B', 'var' - tmux.until { |lines| lines.last == '> (foovar) bar foo-bar' } + tmux.until { |lines| assert_equal '> (foovar) bar foo-bar', lines.last } # Left, CTRL-D tmux.send_keys :Left, :Left, 'C-D' - tmux.until { |lines| lines.last == '> (foovr) bar foo-bar' } + tmux.until { |lines| assert_equal '> (foovr) bar foo-bar', lines.last } # META-BS tmux.send_keys :Escape, :BSpace - tmux.until { |lines| lines.last == '> (r) bar foo-bar' } + tmux.until { |lines| assert_equal '> (r) bar foo-bar', lines.last } # CTRL-Y tmux.send_keys 'C-Y', 'C-Y' - tmux.until { |lines| lines.last == '> (foovfoovr) bar foo-bar' } + tmux.until { |lines| assert_equal '> (foovfoovr) bar foo-bar', lines.last } # META-B tmux.send_keys :Escape, :b, :Space, :Space - tmux.until { |lines| lines.last == '> ( foovfoovr) bar foo-bar' } + tmux.until { |lines| assert_equal '> ( foovfoovr) bar foo-bar', lines.last } # CTRL-F / Right tmux.send_keys 'C-F', :Right, '/' - tmux.until { |lines| lines.last == '> ( fo/ovfoovr) bar foo-bar' } + tmux.until { |lines| assert_equal '> ( fo/ovfoovr) bar foo-bar', lines.last } # CTRL-H / BS tmux.send_keys 'C-H', :BSpace - tmux.until { |lines| lines.last == '> ( fovfoovr) bar foo-bar' } + tmux.until { |lines| assert_equal '> ( fovfoovr) bar foo-bar', lines.last } # CTRL-E tmux.send_keys 'C-E', 'baz' - tmux.until { |lines| lines.last == '> ( fovfoovr) bar foo-barbaz' } + tmux.until { |lines| assert_equal '> ( fovfoovr) bar foo-barbaz', lines.last } # CTRL-U tmux.send_keys 'C-U' - tmux.until { |lines| lines.last == '>' } + tmux.until { |lines| assert_equal '>', lines.last } # CTRL-Y tmux.send_keys 'C-Y' - tmux.until { |lines| lines.last == '> ( fovfoovr) bar foo-barbaz' } + tmux.until { |lines| assert_equal '> ( fovfoovr) bar foo-barbaz', lines.last } # CTRL-W tmux.send_keys 'C-W', 'bar-foo' - tmux.until { |lines| lines.last == '> ( fovfoovr) bar bar-foo' } + tmux.until { |lines| assert_equal '> ( fovfoovr) bar bar-foo', lines.last } # META-D tmux.send_keys :Escape, :b, :Escape, :b, :Escape, :d, 'C-A', 'C-Y' - tmux.until { |lines| lines.last == '> bar( fovfoovr) bar -foo' } + tmux.until { |lines| assert_equal '> bar( fovfoovr) bar -foo', lines.last } # CTRL-M tmux.send_keys 'C-M' - tmux.until { |lines| lines.last !~ /^>/ } + tmux.until { |lines| refute_equal '>', lines.last } end def test_file_word tmux.send_keys "#{FZF} -q '--/foo bar/foo-bar/baz' --filepath-word", :Enter - tmux.until { |lines| lines.last =~ /^>/ } + tmux.until { |lines| assert_equal '> --/foo bar/foo-bar/baz', lines.last } tmux.send_keys :Escape, :b tmux.send_keys :Escape, :b @@ -341,77 +332,85 @@ class TestGoFZF < TestBase tmux.send_keys :Escape, :d tmux.send_keys :Escape, :f tmux.send_keys :Escape, :BSpace - tmux.until { |lines| lines.last == '> --///baz' } + tmux.until { |lines| assert_equal '> --///baz', lines.last } end def test_multi_order tmux.send_keys "seq 1 10 | #{fzf(:multi)}", :Enter - tmux.until { |lines| lines.last =~ /^>/ } + tmux.until { |lines| assert_equal '>', lines.last } tmux.send_keys :Tab, :Up, :Up, :Tab, :Tab, :Tab, # 3, 2 'C-K', 'C-K', 'C-K', 'C-K', :BTab, :BTab, # 5, 6 :PgUp, 'C-J', :Down, :Tab, :Tab # 8, 7 - tmux.until { |lines| lines[-2].include?('(6)') } + tmux.until { |lines| assert_equal ' 10/10 (6)', lines[-2] } tmux.send_keys 'C-M' - assert_equal %w[3 2 5 6 8 7], readonce.split($INPUT_RECORD_SEPARATOR) + assert_equal %w[3 2 5 6 8 7], readonce.lines(chomp: true) end def test_multi_max tmux.send_keys "seq 1 10 | #{FZF} -m 3 --bind A:select-all,T:toggle-all --preview 'echo [{+}]/{}'", :Enter - tmux.until { |lines| lines.item_count == 10 } + tmux.until { |lines| assert_equal 10, lines.item_count } tmux.send_keys '1' tmux.until do |lines| - lines[1].include?('[1]/1') && lines[-2].include?('2/10') + assert_includes lines[1], ' [1]/1 ' + assert lines[-2]&.start_with?(' 2/10 ') end tmux.send_keys 'A' tmux.until do |lines| - lines[1].include?('[1 10]/1') && lines[-2].include?('2/10 (2/3)') + assert_includes lines[1], ' [1 10]/1 ' + assert lines[-2]&.start_with?(' 2/10 (2/3)') end tmux.send_keys :BSpace - tmux.until { |lines| lines[-2].include?('10/10 (2/3)') } + tmux.until { |lines| assert lines[-2]&.start_with?(' 10/10 (2/3)') } tmux.send_keys 'T' tmux.until do |lines| - lines[1].include?('[2 3 4]/1') && lines[-2].include?('10/10 (3/3)') + assert_includes lines[1], ' [2 3 4]/1 ' + assert lines[-2]&.start_with?(' 10/10 (3/3)') end %w[T A].each do |key| tmux.send_keys key tmux.until do |lines| - lines[1].include?('[1 5 6]/1') && lines[-2].include?('10/10 (3/3)') + assert_includes lines[1], ' [1 5 6]/1 ' + assert lines[-2]&.start_with?(' 10/10 (3/3)') end end tmux.send_keys :BTab tmux.until do |lines| - lines[1].include?('[5 6]/2') && lines[-2].include?('10/10 (2/3)') + assert_includes lines[1], ' [5 6]/2 ' + assert lines[-2]&.start_with?(' 10/10 (2/3)') end [:BTab, :BTab, 'A'].each do |key| tmux.send_keys key tmux.until do |lines| - lines[1].include?('[5 6 2]/3') && lines[-2].include?('10/10 (3/3)') + assert_includes lines[1], ' [5 6 2]/3 ' + assert lines[-2]&.start_with?(' 10/10 (3/3)') end end tmux.send_keys '2' - tmux.until { |lines| lines[-2].include?('1/10 (3/3)') } + tmux.until { |lines| assert lines[-2]&.start_with?(' 1/10 (3/3)') } tmux.send_keys 'T' tmux.until do |lines| - lines[1].include?('[5 6]/2') && lines[-2].include?('1/10 (2/3)') + assert_includes lines[1], ' [5 6]/2 ' + assert lines[-2]&.start_with?(' 1/10 (2/3)') end tmux.send_keys :BSpace - tmux.until { |lines| lines[-2].include?('10/10 (2/3)') } + tmux.until { |lines| assert lines[-2]&.start_with?(' 10/10 (2/3)') } tmux.send_keys 'A' tmux.until do |lines| - lines[1].include?('[5 6 1]/1') && lines[-2].include?('10/10 (3/3)') + assert_includes lines[1], ' [5 6 1]/1 ' + assert lines[-2]&.start_with?(' 10/10 (3/3)') end end @@ -421,7 +420,7 @@ class TestGoFZF < TestBase echo ' first second third/') | #{fzf(multi && :multi, :x, :nth, 2, :with_nth, '2,-1,1')}", :Enter - tmux.until { |lines| lines[-2].include?('2/2') } + tmux.until { |lines| assert_equal ' 2/2', lines[-2] } # Transformed list lines = tmux.capture @@ -431,14 +430,14 @@ class TestGoFZF < TestBase # However, the output must not be transformed if multi tmux.send_keys :BTab, :BTab - tmux.until { |lines| lines[-2].include?('(2)') } + tmux.until { |lines| assert_equal ' 2/2 (2)', lines[-2] } tmux.send_keys :Enter - assert_equal [' 1st 2nd 3rd/', ' first second third/'], readonce.split($INPUT_RECORD_SEPARATOR) + assert_equal [' 1st 2nd 3rd/', ' first second third/'], readonce.lines(chomp: true) else tmux.send_keys '^', '3' - tmux.until { |lines| lines[-2].include?('1/2') } + tmux.until { |lines| assert_equal ' 1/2', lines[-2] } tmux.send_keys :Enter - assert_equal [' 1st 2nd 3rd/'], readonce.split($INPUT_RECORD_SEPARATOR) + assert_equal [' 1st 2nd 3rd/'], readonce.lines(chomp: true) end end end @@ -446,9 +445,9 @@ class TestGoFZF < TestBase def test_scroll [true, false].each do |rev| tmux.send_keys "seq 1 100 | #{fzf(rev && :reverse)}", :Enter - tmux.until { |lines| lines.include?(' 100/100') } + tmux.until { |lines| assert_includes lines, ' 100/100' } tmux.send_keys(*Array.new(110) { rev ? :Down : :Up }) - tmux.until { |lines| lines.include?('> 100') } + tmux.until { |lines| assert_includes lines, '> 100' } tmux.send_keys :Enter assert_equal '100', readonce.chomp end @@ -456,85 +455,85 @@ class TestGoFZF < TestBase def test_select_1 tmux.send_keys "seq 1 100 | #{fzf(:with_nth, '..,..', :print_query, :q, 5555, :'1')}", :Enter - assert_equal %w[5555 55], readonce.split($INPUT_RECORD_SEPARATOR) + assert_equal %w[5555 55], readonce.lines(chomp: true) end def test_exit_0 tmux.send_keys "seq 1 100 | #{fzf(:with_nth, '..,..', :print_query, :q, 555_555, :'0')}", :Enter - assert_equal %w[555555], readonce.split($INPUT_RECORD_SEPARATOR) + assert_equal %w[555555], readonce.lines(chomp: true) end def test_select_1_exit_0_fail [:'0', :'1', %i[1 0]].each do |opt| tmux.send_keys "seq 1 100 | #{fzf(:print_query, :multi, :q, 5, *opt)}", :Enter - tmux.until { |lines| lines.last =~ /^> 5/ } + tmux.until { |lines| assert_equal '> 5', lines.last } tmux.send_keys :BTab, :BTab, :BTab - tmux.until { |lines| lines[-2].include?('(3)') } + tmux.until { |lines| assert_equal ' 19/100 (3)', lines[-2] } tmux.send_keys :Enter - assert_equal %w[5 5 50 51], readonce.split($INPUT_RECORD_SEPARATOR) + assert_equal %w[5 5 50 51], readonce.lines(chomp: true) end end def test_query_unicode tmux.paste "(echo abc; echo $'\\352\\260\\200\\353\\202\\230\\353\\213\\244') | #{fzf(:query, "$'\\352\\260\\200\\353\\213\\244'")}" - tmux.until { |lines| lines[-2].include?('1/2') } + tmux.until { |lines| assert_equal ' 1/2', lines[-2] } tmux.send_keys :Enter - assert_equal %w[가나다], readonce.split($INPUT_RECORD_SEPARATOR) + assert_equal %w[가나다], readonce.lines(chomp: true) end def test_sync tmux.send_keys "seq 1 100 | #{fzf!(:multi)} | awk '{print $1 $1}' | #{fzf(:sync)}", :Enter - tmux.until { |lines| lines[-1] == '>' } + tmux.until { |lines| assert_equal '>', lines[-1] } tmux.send_keys 9 - tmux.until { |lines| lines[-2] == ' 19/100' } + tmux.until { |lines| assert_equal ' 19/100', lines[-2] } tmux.send_keys :BTab, :BTab, :BTab - tmux.until { |lines| lines[-2].include?('(3)') } + tmux.until { |lines| assert_equal ' 19/100 (3)', lines[-2] } tmux.send_keys :Enter - tmux.until { |lines| lines[-1] == '>' } + tmux.until { |lines| assert_equal '>', lines[-1] } tmux.send_keys 'C-K', :Enter - assert_equal %w[9090], readonce.split($INPUT_RECORD_SEPARATOR) + assert_equal %w[9090], readonce.lines(chomp: true) end def test_tac tmux.send_keys "seq 1 1000 | #{fzf(:tac, :multi)}", :Enter - tmux.until { |lines| lines[-2].include?('1000/1000') } + tmux.until { |lines| assert_equal ' 1000/1000', lines[-2] } tmux.send_keys :BTab, :BTab, :BTab - tmux.until { |lines| lines[-2].include?('(3)') } + tmux.until { |lines| assert_equal ' 1000/1000 (3)', lines[-2] } tmux.send_keys :Enter - assert_equal %w[1000 999 998], readonce.split($INPUT_RECORD_SEPARATOR) + assert_equal %w[1000 999 998], readonce.lines(chomp: true) end def test_tac_sort tmux.send_keys "seq 1 1000 | #{fzf(:tac, :multi)}", :Enter - tmux.until { |lines| lines[-2].include?('1000/1000') } + tmux.until { |lines| assert_equal ' 1000/1000', lines[-2] } tmux.send_keys '99' - tmux.until { |lines| lines[-2].include?('28/1000') } + tmux.until { |lines| assert_equal ' 28/1000', lines[-2] } tmux.send_keys :BTab, :BTab, :BTab - tmux.until { |lines| lines[-2].include?('(3)') } + tmux.until { |lines| assert_equal ' 28/1000 (3)', lines[-2] } tmux.send_keys :Enter - assert_equal %w[99 999 998], readonce.split($INPUT_RECORD_SEPARATOR) + assert_equal %w[99 999 998], readonce.lines(chomp: true) end def test_tac_nosort tmux.send_keys "seq 1 1000 | #{fzf(:tac, :no_sort, :multi)}", :Enter - tmux.until { |lines| lines[-2].include?('1000/1000') } + tmux.until { |lines| assert_equal ' 1000/1000', lines[-2] } tmux.send_keys '00' - tmux.until { |lines| lines[-2].include?('10/1000') } + tmux.until { |lines| assert_equal ' 10/1000', lines[-2] } tmux.send_keys :BTab, :BTab, :BTab - tmux.until { |lines| lines[-2].include?('(3)') } + tmux.until { |lines| assert_equal ' 10/1000 (3)', lines[-2] } tmux.send_keys :Enter - assert_equal %w[1000 900 800], readonce.split($INPUT_RECORD_SEPARATOR) + assert_equal %w[1000 900 800], readonce.lines(chomp: true) end def test_expect test = lambda do |key, feed, expected = key| tmux.send_keys "seq 1 100 | #{fzf(:expect, key)}", :Enter - tmux.until { |lines| lines[-2].include?('100/100') } + tmux.until { |lines| assert_equal ' 100/100', lines[-2] } tmux.send_keys '55' - tmux.until { |lines| lines[-2].include?('1/100') } + tmux.until { |lines| assert_equal ' 1/100', lines[-2] } tmux.send_keys(*feed) tmux.prepare - assert_equal [expected, '55'], readonce.split($INPUT_RECORD_SEPARATOR) + assert_equal [expected, '55'], readonce.lines(chomp: true) end test.call('ctrl-t', 'C-T') test.call('ctrl-t', 'Enter', '') @@ -553,46 +552,46 @@ class TestGoFZF < TestBase def test_expect_print_query tmux.send_keys "seq 1 100 | #{fzf('--expect=alt-z', :print_query)}", :Enter - tmux.until { |lines| lines[-2].include?('100/100') } + tmux.until { |lines| assert_equal ' 100/100', lines[-2] } tmux.send_keys '55' - tmux.until { |lines| lines[-2].include?('1/100') } + tmux.until { |lines| assert_equal ' 1/100', lines[-2] } tmux.send_keys :Escape, :z - assert_equal %w[55 alt-z 55], readonce.split($INPUT_RECORD_SEPARATOR) + assert_equal %w[55 alt-z 55], readonce.lines(chomp: true) end def test_expect_printable_character_print_query tmux.send_keys "seq 1 100 | #{fzf('--expect=z --print-query')}", :Enter - tmux.until { |lines| lines[-2].include?('100/100') } + tmux.until { |lines| assert_equal ' 100/100', lines[-2] } tmux.send_keys '55' - tmux.until { |lines| lines[-2].include?('1/100') } + tmux.until { |lines| assert_equal ' 1/100', lines[-2] } tmux.send_keys 'z' - assert_equal %w[55 z 55], readonce.split($INPUT_RECORD_SEPARATOR) + assert_equal %w[55 z 55], readonce.lines(chomp: true) end def test_expect_print_query_select_1 tmux.send_keys "seq 1 100 | #{fzf('-q55 -1 --expect=alt-z --print-query')}", :Enter - assert_equal ['55', '', '55'], readonce.split($INPUT_RECORD_SEPARATOR) + assert_equal ['55', '', '55'], readonce.lines(chomp: true) end def test_toggle_sort ['--toggle-sort=ctrl-r', '--bind=ctrl-r:toggle-sort'].each do |opt| tmux.send_keys "seq 1 111 | #{fzf("-m +s --tac #{opt} -q11")}", :Enter - tmux.until { |lines| lines[-3].include?('> 111') } + tmux.until { |lines| assert_equal '> 111', lines[-3] } tmux.send_keys :Tab - tmux.until { |lines| lines[-2].include?('4/111 -S (1)') } + tmux.until { |lines| assert_equal ' 4/111 -S (1)', lines[-2] } tmux.send_keys 'C-R' - tmux.until { |lines| lines[-3].include?('> 11') } + tmux.until { |lines| assert_equal '> 11', lines[-3] } tmux.send_keys :Tab - tmux.until { |lines| lines[-2].include?('4/111 +S (2)') } + tmux.until { |lines| assert_equal ' 4/111 +S (2)', lines[-2] } tmux.send_keys :Enter - assert_equal %w[111 11], readonce.split($INPUT_RECORD_SEPARATOR) + assert_equal %w[111 11], readonce.lines(chomp: true) end end def test_unicode_case writelines(tempname, %w[строКА1 СТРОКА2 строка3 Строка4]) - assert_equal %w[СТРОКА2 Строка4], `#{FZF} -fС < #{tempname}`.split($INPUT_RECORD_SEPARATOR) - assert_equal %w[строКА1 СТРОКА2 строка3 Строка4], `#{FZF} -fс < #{tempname}`.split($INPUT_RECORD_SEPARATOR) + assert_equal %w[СТРОКА2 Строка4], `#{FZF} -fС < #{tempname}`.lines(chomp: true) + assert_equal %w[строКА1 СТРОКА2 строка3 Строка4], `#{FZF} -fс < #{tempname}`.lines(chomp: true) end def test_tiebreak @@ -604,7 +603,7 @@ class TestGoFZF < TestBase ] writelines(tempname, input) - assert_equal input, `#{FZF} -ffoobar --tiebreak=index < #{tempname}`.split($INPUT_RECORD_SEPARATOR) + assert_equal input, `#{FZF} -ffoobar --tiebreak=index < #{tempname}`.lines(chomp: true) by_length = %w[ ----foobar-- @@ -612,8 +611,8 @@ class TestGoFZF < TestBase -------foobar- --foobar-------- ] - assert_equal by_length, `#{FZF} -ffoobar < #{tempname}`.split($INPUT_RECORD_SEPARATOR) - assert_equal by_length, `#{FZF} -ffoobar --tiebreak=length < #{tempname}`.split($INPUT_RECORD_SEPARATOR) + assert_equal by_length, `#{FZF} -ffoobar < #{tempname}`.lines(chomp: true) + assert_equal by_length, `#{FZF} -ffoobar --tiebreak=length < #{tempname}`.lines(chomp: true) by_begin = %w[ --foobar-------- @@ -621,17 +620,17 @@ class TestGoFZF < TestBase -----foobar--- -------foobar- ] - assert_equal by_begin, `#{FZF} -ffoobar --tiebreak=begin < #{tempname}`.split($INPUT_RECORD_SEPARATOR) - assert_equal by_begin, `#{FZF} -f"!z foobar" -x --tiebreak begin < #{tempname}`.split($INPUT_RECORD_SEPARATOR) + assert_equal by_begin, `#{FZF} -ffoobar --tiebreak=begin < #{tempname}`.lines(chomp: true) + assert_equal by_begin, `#{FZF} -f"!z foobar" -x --tiebreak begin < #{tempname}`.lines(chomp: true) assert_equal %w[ -------foobar- ----foobar-- -----foobar--- --foobar-------- - ], `#{FZF} -ffoobar --tiebreak end < #{tempname}`.split($INPUT_RECORD_SEPARATOR) + ], `#{FZF} -ffoobar --tiebreak end < #{tempname}`.lines(chomp: true) - assert_equal input, `#{FZF} -f"!z" -x --tiebreak end < #{tempname}`.split($INPUT_RECORD_SEPARATOR) + assert_equal input, `#{FZF} -f"!z" -x --tiebreak end < #{tempname}`.lines(chomp: true) end def test_tiebreak_index_begin @@ -651,7 +650,7 @@ class TestGoFZF < TestBase 'xxoxxxoxx', 'xoxxxxxox', 'xoxxxxxoxx' - ], `#{FZF} -foo < #{tempname}`.split($INPUT_RECORD_SEPARATOR) + ], `#{FZF} -foo < #{tempname}`.lines(chomp: true) assert_equal [ 'xxxoxoxxx', @@ -660,7 +659,7 @@ class TestGoFZF < TestBase 'xxoxxxoxx', 'xoxxxxxoxx', 'xoxxxxxox' - ], `#{FZF} -foo --tiebreak=index < #{tempname}`.split($INPUT_RECORD_SEPARATOR) + ], `#{FZF} -foo --tiebreak=index < #{tempname}`.lines(chomp: true) # Note that --tiebreak=begin is now based on the first occurrence of the # first character on the pattern @@ -671,7 +670,7 @@ class TestGoFZF < TestBase 'xxoxxxoxx', 'xoxxxxxoxx', 'xoxxxxxox' - ], `#{FZF} -foo --tiebreak=begin < #{tempname}`.split($INPUT_RECORD_SEPARATOR) + ], `#{FZF} -foo --tiebreak=begin < #{tempname}`.lines(chomp: true) assert_equal [ ' xxoxoxxx', @@ -680,7 +679,7 @@ class TestGoFZF < TestBase 'xxoxxxoxx', 'xoxxxxxox', 'xoxxxxxoxx' - ], `#{FZF} -foo --tiebreak=begin,length < #{tempname}`.split($INPUT_RECORD_SEPARATOR) + ], `#{FZF} -foo --tiebreak=begin,length < #{tempname}`.lines(chomp: true) end def test_tiebreak_begin_algo_v2 @@ -691,7 +690,7 @@ class TestGoFZF < TestBase assert_equal [ 'foo bar baz', 'baz foo bar' - ], `#{FZF} -fbar --tiebreak=begin --algo=v2 < #{tempname}`.split($INPUT_RECORD_SEPARATOR) + ], `#{FZF} -fbar --tiebreak=begin --algo=v2 < #{tempname}`.lines(chomp: true) end def test_tiebreak_end @@ -711,7 +710,7 @@ class TestGoFZF < TestBase 'xoxxxxxxxx', 'xxoxxxxxxx', 'xxxoxxxxxx' - ], `#{FZF} -fo < #{tempname}`.split($INPUT_RECORD_SEPARATOR) + ], `#{FZF} -fo < #{tempname}`.lines(chomp: true) assert_equal [ 'xxxxxoxxx', @@ -720,7 +719,7 @@ class TestGoFZF < TestBase 'xxxoxxxxxx', 'xxoxxxxxxx', 'xoxxxxxxxx' - ], `#{FZF} -fo --tiebreak=end < #{tempname}`.split($INPUT_RECORD_SEPARATOR) + ], `#{FZF} -fo --tiebreak=end < #{tempname}`.lines(chomp: true) assert_equal [ 'xxxxxoxxx', @@ -729,7 +728,7 @@ class TestGoFZF < TestBase 'xxxoxxxxxx', 'xxoxxxxxxx', 'xoxxxxxxxx' - ], `#{FZF} -fo --tiebreak=end,length,begin < #{tempname}`.split($INPUT_RECORD_SEPARATOR) + ], `#{FZF} -fo --tiebreak=end,length,begin < #{tempname}`.lines(chomp: true) end def test_tiebreak_length_with_nth @@ -747,19 +746,19 @@ class TestGoFZF < TestBase 123:hello 1234567:h ] - assert_equal output, `#{FZF} -fh < #{tempname}`.split($INPUT_RECORD_SEPARATOR) + assert_equal output, `#{FZF} -fh < #{tempname}`.lines(chomp: true) # Since 0.16.8, --nth doesn't affect --tiebreak - assert_equal output, `#{FZF} -fh -n2 -d: < #{tempname}`.split($INPUT_RECORD_SEPARATOR) + assert_equal output, `#{FZF} -fh -n2 -d: < #{tempname}`.lines(chomp: true) end def test_invalid_cache tmux.send_keys "(echo d; echo D; echo x) | #{fzf('-q d')}", :Enter - tmux.until { |lines| lines[-2].include?('2/3') } + tmux.until { |lines| assert_equal ' 2/3', lines[-2] } tmux.send_keys :BSpace - tmux.until { |lines| lines[-2].include?('3/3') } + tmux.until { |lines| assert_equal ' 3/3', lines[-2] } tmux.send_keys :D - tmux.until { |lines| lines[-2].include?('1/3') } + tmux.until { |lines| assert_equal ' 1/3', lines[-2] } tmux.send_keys :Enter end @@ -768,31 +767,31 @@ class TestGoFZF < TestBase # Suffix match tmux.send_keys command, :Enter - tmux.until { |lines| lines.match_count == 104 } + tmux.until { |lines| assert_equal 104, lines.match_count } tmux.send_keys 'foo$' - tmux.until { |lines| lines.match_count == 1 } + tmux.until { |lines| assert_equal 1, lines.match_count } tmux.send_keys 'bar' - tmux.until { |lines| lines.match_count == 1 } + tmux.until { |lines| assert_equal 1, lines.match_count } tmux.send_keys :Enter # Prefix match tmux.prepare tmux.send_keys command, :Enter - tmux.until { |lines| lines.match_count == 104 } + tmux.until { |lines| assert_equal 104, lines.match_count } tmux.send_keys '^bar' - tmux.until { |lines| lines.match_count == 1 } + tmux.until { |lines| assert_equal 1, lines.match_count } tmux.send_keys 'C-a', 'foo' - tmux.until { |lines| lines.match_count == 1 } + tmux.until { |lines| assert_equal 1, lines.match_count } tmux.send_keys :Enter # Exact match tmux.prepare tmux.send_keys command, :Enter - tmux.until { |lines| lines.match_count == 104 } + tmux.until { |lines| assert_equal 104, lines.match_count } tmux.send_keys "'12" - tmux.until { |lines| lines.match_count == 1 } + tmux.until { |lines| assert_equal 1, lines.match_count } tmux.send_keys 'C-a', 'foo' - tmux.until { |lines| lines.match_count == 1 } + tmux.until { |lines| assert_equal 1, lines.match_count } end def test_smart_case_for_each_term @@ -801,25 +800,25 @@ class TestGoFZF < TestBase def test_bind tmux.send_keys "seq 1 1000 | #{fzf('-m --bind=ctrl-j:accept,u:up,T:toggle-up,t:toggle')}", :Enter - tmux.until { |lines| lines[-2].end_with?('/1000') } + tmux.until { |lines| assert_equal ' 1000/1000', lines[-2] } tmux.send_keys 'uuu', 'TTT', 'tt', 'uu', 'ttt', 'C-j' - assert_equal %w[4 5 6 9], readonce.split($INPUT_RECORD_SEPARATOR) + assert_equal %w[4 5 6 9], readonce.lines(chomp: true) end def test_bind_print_query tmux.send_keys "seq 1 1000 | #{fzf('-m --bind=ctrl-j:print-query')}", :Enter - tmux.until { |lines| lines[-2].end_with?('/1000') } + tmux.until { |lines| assert_equal ' 1000/1000', lines[-2] } tmux.send_keys 'print-my-query', 'C-j' - assert_equal %w[print-my-query], readonce.split($INPUT_RECORD_SEPARATOR) + assert_equal %w[print-my-query], readonce.lines(chomp: true) end def test_bind_replace_query tmux.send_keys "seq 1 1000 | #{fzf('--print-query --bind=ctrl-j:replace-query')}", :Enter tmux.send_keys '1' - tmux.until { |lines| lines[-2].end_with?('272/1000') } + tmux.until { |lines| assert_equal ' 272/1000', lines[-2] } tmux.send_keys 'C-k', 'C-j' - tmux.until { |lines| lines[-2].end_with?('29/1000') } - tmux.until { |lines| lines[-1].end_with?('> 10') } + tmux.until { |lines| assert_equal ' 29/1000', lines[-2] } + tmux.until { |lines| assert_equal '> 10', lines[-1] } end def test_long_line @@ -831,7 +830,7 @@ class TestGoFZF < TestBase end def test_read0 - lines = `find .`.split($INPUT_RECORD_SEPARATOR) + lines = `find .`.lines(chomp: true) assert_equal lines.last, `find . | #{FZF} -e -f "^#{lines.last}$"`.chomp assert_equal \ lines.last, @@ -840,32 +839,32 @@ class TestGoFZF < TestBase def test_select_all_deselect_all_toggle_all tmux.send_keys "seq 100 | #{fzf('--bind ctrl-a:select-all,ctrl-d:deselect-all,ctrl-t:toggle-all --multi')}", :Enter - tmux.until { |lines| lines[-2].include?('100/100') } + tmux.until { |lines| assert_equal ' 100/100', lines[-2] } tmux.send_keys :BTab, :BTab, :BTab - tmux.until { |lines| lines[-2].include?('(3)') } + tmux.until { |lines| assert_equal ' 100/100 (3)', lines[-2] } tmux.send_keys 'C-t' - tmux.until { |lines| lines[-2].include?('(97)') } + tmux.until { |lines| assert_equal ' 100/100 (97)', lines[-2] } tmux.send_keys 'C-a' - tmux.until { |lines| lines[-2].include?('(100)') } + tmux.until { |lines| assert_equal ' 100/100 (100)', lines[-2] } tmux.send_keys :Tab, :Tab - tmux.until { |lines| lines[-2].include?('(98)') } + tmux.until { |lines| assert_equal ' 100/100 (98)', lines[-2] } tmux.send_keys '100' - tmux.until { |lines| lines.match_count == 1 } + tmux.until { |lines| assert_equal 1, lines.match_count } tmux.send_keys 'C-d' - tmux.until { |lines| lines[-2].include?('(97)') } + tmux.until { |lines| assert_equal ' 1/100 (97)', lines[-2] } tmux.send_keys 'C-u' - tmux.until { |lines| lines.match_count == 100 } + tmux.until { |lines| assert_equal 100, lines.match_count } tmux.send_keys 'C-d' - tmux.until { |lines| !lines[-2].include?('(') } + tmux.until { |lines| assert_equal ' 100/100', lines[-2] } tmux.send_keys :BTab, :BTab - tmux.until { |lines| lines[-2].include?('(2)') } + tmux.until { |lines| assert_equal ' 100/100 (2)', lines[-2] } tmux.send_keys 0 - tmux.until { |lines| lines[-2].include?('10/100') } + tmux.until { |lines| assert_equal ' 10/100 (2)', lines[-2] } tmux.send_keys 'C-a' - tmux.until { |lines| lines[-2].include?('(12)') } + tmux.until { |lines| assert_equal ' 10/100 (12)', lines[-2] } tmux.send_keys :Enter assert_equal %w[1 2 10 20 30 40 50 60 70 80 90 100], - readonce.split($INPUT_RECORD_SEPARATOR) + readonce.lines(chomp: true) end def test_history @@ -878,42 +877,48 @@ class TestGoFZF < TestBase nil end opts = "--history=#{history_file} --history-size=4" - input = %w[00 11 22 33 44].map { |e| e + $INPUT_RECORD_SEPARATOR } + input = %w[00 11 22 33 44] input.each do |keys| tmux.prepare tmux.send_keys "seq 100 | #{fzf(opts)}", :Enter - tmux.until { |lines| lines[-2].include?('100/100') } + tmux.until { |lines| assert_equal ' 100/100', lines[-2] } tmux.send_keys keys - tmux.until { |lines| lines[-2].include?('1/100') } + tmux.until { |lines| assert_equal ' 1/100', lines[-2] } tmux.send_keys :Enter end - wait { File.exist?(history_file) && File.readlines(history_file) == input[1..-1] } + wait do + assert_path_exists history_file + assert_equal input[1..-1], File.readlines(history_file, chomp: true) + end # Update history entries (not changed on disk) tmux.send_keys "seq 100 | #{fzf(opts)}", :Enter - tmux.until { |lines| lines[-2].include?('100/100') } + tmux.until { |lines| assert_equal ' 100/100', lines[-2] } tmux.send_keys 'C-p' - tmux.until { |lines| lines[-1].end_with?('> 44') } + tmux.until { |lines| assert_equal '> 44', lines[-1] } tmux.send_keys 'C-p' - tmux.until { |lines| lines[-1].end_with?('> 33') } + tmux.until { |lines| assert_equal '> 33', lines[-1] } tmux.send_keys :BSpace - tmux.until { |lines| lines[-1].end_with?('> 3') } + tmux.until { |lines| assert_equal '> 3', lines[-1] } tmux.send_keys 1 - tmux.until { |lines| lines[-1].end_with?('> 31') } + tmux.until { |lines| assert_equal '> 31', lines[-1] } tmux.send_keys 'C-p' - tmux.until { |lines| lines[-1].end_with?('> 22') } + tmux.until { |lines| assert_equal '> 22', lines[-1] } tmux.send_keys 'C-n' - tmux.until { |lines| lines[-1].end_with?('> 31') } + tmux.until { |lines| assert_equal '> 31', lines[-1] } tmux.send_keys 0 - tmux.until { |lines| lines[-1].end_with?('> 310') } + tmux.until { |lines| assert_equal '> 310', lines[-1] } tmux.send_keys :Enter - wait { File.exist?(history_file) && File.readlines(history_file) == %w[22 33 44 310].map { |e| e + $INPUT_RECORD_SEPARATOR } } + wait do + assert_path_exists history_file + assert_equal %w[22 33 44 310], File.readlines(history_file, chomp: true) + end # Respect --bind option tmux.send_keys "seq 100 | #{fzf(opts + ' --bind ctrl-p:next-history,ctrl-n:previous-history')}", :Enter - tmux.until { |lines| lines[-2].include?('100/100') } + tmux.until { |lines| assert_equal ' 100/100', lines[-2] } tmux.send_keys 'C-n', 'C-n', 'C-n', 'C-n', 'C-p' - tmux.until { |lines| lines[-1].end_with?('33') } + tmux.until { |lines| assert_equal '> 33', lines[-1] } tmux.send_keys :Enter ensure File.unlink(history_file) @@ -924,7 +929,7 @@ class TestGoFZF < TestBase opts = %[--bind "alt-a:execute(echo /{}/ >> #{output}),alt-b:execute[echo /{}{}/ >> #{output}],C:execute:echo /{}{}{}/ >> #{output}"] writelines(tempname, %w[foo'bar foo"bar foo$bar]) tmux.send_keys "cat #{tempname} | #{fzf(opts)}", :Enter - tmux.until { |lines| lines[-2] == ' 3/3' } + tmux.until { |lines| assert_equal ' 3/3', lines[-2] } tmux.send_keys :Escape, :a tmux.send_keys :Escape, :a tmux.send_keys :Up @@ -933,15 +938,16 @@ class TestGoFZF < TestBase tmux.send_keys :Up tmux.send_keys :C tmux.send_keys 'barfoo' - tmux.until { |lines| lines[-2] == ' 0/3' } + tmux.until { |lines| assert_equal ' 0/3', lines[-2] } tmux.send_keys :Escape, :a tmux.send_keys :Escape, :b wait do - File.exist?(output) && File.readlines(output).map(&:chomp) == %w[ + assert_path_exists output + assert_equal %w[ /foo'bar/ /foo'bar/ /foo"barfoo"bar/ /foo"barfoo"bar/ /foo$barfoo$barfoo$bar/ - ] + ], File.readlines(output, chomp: true) end ensure begin @@ -956,20 +962,21 @@ class TestGoFZF < TestBase opts = %[--multi --bind "alt-a:execute-multi(echo {}/{+} >> #{output})"] writelines(tempname, %w[foo'bar foo"bar foo$bar foobar]) tmux.send_keys "cat #{tempname} | #{fzf(opts)}", :Enter - tmux.until { |lines| lines[-2].include?('4/4') } + tmux.until { |lines| assert_equal ' 4/4', lines[-2] } tmux.send_keys :Escape, :a - tmux.until { |lines| lines[-2].include?('/4') } tmux.send_keys :BTab, :BTab, :BTab + tmux.until { |lines| assert_equal ' 4/4 (3)', lines[-2] } tmux.send_keys :Escape, :a - tmux.until { |lines| lines[-2].include?('/4') } tmux.send_keys :Tab, :Tab + tmux.until { |lines| assert_equal ' 4/4 (3)', lines[-2] } tmux.send_keys :Escape, :a wait do - File.exist?(output) && File.readlines(output).map(&:chomp) == [ + assert_path_exists output + assert_equal [ %(foo'bar/foo'bar), %(foo'bar foo"bar foo$bar/foo'bar foo"bar foo$bar), %(foo'bar foo"bar foobar/foo'bar foo"bar foobar) - ] + ], File.readlines(output, chomp: true) end ensure begin @@ -990,29 +997,32 @@ class TestGoFZF < TestBase tmux.send_keys "cat #{tempname} | #{FZF} --multi --bind 'x:execute-silent(echo {+}/{}/{+2}/{2} >> #{output})'", :Enter - execute = lambda do - tmux.send_keys 'x', 'y' - tmux.until { |lines| lines[-2].include?('0/2') } - tmux.send_keys :BSpace - tmux.until { |lines| lines[-2].include?('2/2') } - end - - tmux.until { |lin |