From 4b74f882c79600e4a988146d037eabf1fc484c7d Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Mon, 27 Jan 2025 02:08:52 +0900 Subject: [PATCH] [test] Prefer match_count over item_count match_count can lag behind item_count and can cause intermittent failures. --- test/test_core.rb | 18 +++++++++--------- test/test_exec.rb | 28 ++++++++++++++-------------- test/test_preview.rb | 22 +++++++++++----------- test/test_server.rb | 4 ++-- 4 files changed, 36 insertions(+), 36 deletions(-) diff --git a/test/test_core.rb b/test/test_core.rb index 75cf3d77060..21e400d40ce 100644 --- a/test/test_core.rb +++ b/test/test_core.rb @@ -111,7 +111,7 @@ def test_multi_order 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| assert_equal 10, lines.item_count } + tmux.until { |lines| assert_equal 10, lines.match_count } tmux.send_keys '1' tmux.until do |lines| @@ -177,7 +177,7 @@ def test_multi_max def test_multi_action tmux.send_keys "seq 10 | #{FZF} --bind 'a:change-multi,b:change-multi(3),c:change-multi(xxx),d:change-multi(0)'", :Enter - tmux.until { |lines| assert_equal 10, lines.item_count } + tmux.until { |lines| assert_equal 10, lines.match_count } tmux.until { |lines| assert lines[-2]&.start_with?(' 10/10 ') } tmux.send_keys 'a' tmux.until { |lines| assert lines[-2]&.start_with?(' 10/10 (0)') } @@ -1176,7 +1176,7 @@ def test_select_deselect def test_unbind_rebind tmux.send_keys "seq 100 | #{FZF} --bind 'c:clear-query,d:unbind(c,d),e:rebind(c,d)'", :Enter - tmux.until { |lines| assert_equal 100, lines.item_count } + tmux.until { |lines| assert_equal 100, lines.match_count } tmux.send_keys 'ab' tmux.until { |lines| assert_equal '> ab', lines[-1] } tmux.send_keys 'c' @@ -1189,7 +1189,7 @@ def test_unbind_rebind def test_scroll_off tmux.send_keys "seq 1000 | #{FZF} --scroll-off=3 --bind l:last", :Enter - tmux.until { |lines| assert_equal 1000, lines.item_count } + tmux.until { |lines| assert_equal 1000, lines.match_count } height = tmux.until { |lines| lines }.first.to_i tmux.send_keys :PgUp tmux.until do |lines| @@ -1208,7 +1208,7 @@ def test_scroll_off def test_scroll_off_large tmux.send_keys "seq 1000 | #{FZF} --scroll-off=9999", :Enter - tmux.until { |lines| assert_equal 1000, lines.item_count } + tmux.until { |lines| assert_equal 1000, lines.match_count } height = tmux.until { |lines| lines }.first.to_i tmux.send_keys :PgUp tmux.until { |lines| assert_equal "> #{height}", lines[height / 2].strip } @@ -1253,7 +1253,7 @@ def test_focus_event def test_result_event tmux.send_keys '(echo 0; seq 10) | fzf --bind "result:pos(2)"', :Enter - tmux.until { |lines| assert_equal 11, lines.item_count } + tmux.until { |lines| assert_equal 11, lines.match_count } tmux.until { |lines| assert_includes lines, '> 1' } tmux.send_keys '9' tmux.until { |lines| assert_includes lines, '> 9' } @@ -1397,7 +1397,7 @@ def test_info_command_and_focus def test_prev_next_selected tmux.send_keys 'seq 10 | fzf --multi --bind ctrl-n:next-selected,ctrl-p:prev-selected', :Enter - tmux.until { |lines| assert_equal 10, lines.item_count } + tmux.until { |lines| assert_equal 10, lines.match_count } tmux.send_keys :BTab, :BTab, :Up, :BTab tmux.until { |lines| assert_equal 3, lines.select_count } tmux.send_keys 'C-n' @@ -1530,7 +1530,7 @@ def test_one_and_zero def test_height_range_with_exit_0 tmux.send_keys "seq 10 | #{FZF} --height ~10% --exit-0", :Enter - tmux.until { |lines| assert_equal 10, lines.item_count } + tmux.until { |lines| assert_equal 10, lines.match_count } tmux.send_keys :c tmux.until { |lines| assert_equal 0, lines.match_count } end @@ -1542,7 +1542,7 @@ def test_delete_with_modifiers skip('CTRL-DELETE is not properly handled in GitHub Actions environment') end tmux.send_keys "seq 100 | #{FZF} --bind 'ctrl-delete:up+up,shift-delete:down,focus:transform-prompt:echo [{}]'", :Enter - tmux.until { |lines| assert_equal 100, lines.item_count } + tmux.until { |lines| assert_equal 100, lines.match_count } tmux.send_keys 'C-Delete' tmux.until { |lines| assert_equal '[3]', lines[-1] } tmux.send_keys 'S-Delete' diff --git a/test/test_exec.rb b/test/test_exec.rb index 9232ce9e93d..c02e8c94d39 100644 --- a/test/test_exec.rb +++ b/test/test_exec.rb @@ -9,7 +9,7 @@ def test_execute opts = %[--bind "alt-a:execute(echo /{}/ >> #{output})+change-header(alt-a),alt-b:execute[echo /{}{}/ >> #{output}]+change-header(alt-b),C:execute(echo /{}{}{}/ >> #{output})+change-header(C)"] writelines(%w[foo'bar foo"bar foo$bar]) tmux.send_keys "cat #{tempname} | #{FZF} #{opts}", :Enter - tmux.until { |lines| assert_equal 3, lines.item_count } + tmux.until { |lines| assert_equal 3, lines.match_count } ready = ->(s) { tmux.until { |lines| assert_includes lines[-3], s } } tmux.send_keys :Escape, :a @@ -142,11 +142,11 @@ def test_execute_shell def test_interrupt_execute tmux.send_keys "seq 100 | #{FZF} --bind 'ctrl-l:execute:echo executing {}; sleep 100'", :Enter - tmux.until { |lines| assert_equal 100, lines.item_count } + tmux.until { |lines| assert_equal 100, lines.match_count } tmux.send_keys 'C-l' tmux.until { |lines| assert lines.any_include?('executing 1') } tmux.send_keys 'C-c' - tmux.until { |lines| assert_equal 100, lines.item_count } + tmux.until { |lines| assert_equal 100, lines.match_count } tmux.send_keys 99 tmux.until { |lines| assert_equal 1, lines.match_count } end @@ -158,7 +158,7 @@ def test_kill_default_command_on_abort system("chmod +x #{tempname}") tmux.send_keys FZF.sub('FZF_DEFAULT_COMMAND=', "FZF_DEFAULT_COMMAND=#{tempname}"), :Enter - tmux.until { |lines| assert_equal 1, lines.item_count } + tmux.until { |lines| assert_equal 1, lines.match_count } tmux.send_keys 'C-c' tmux.send_keys 'C-l', 'closed' tmux.until { |lines| assert_includes lines[0], 'closed' } @@ -189,9 +189,9 @@ def test_kill_reload_command_on_abort system("chmod +x #{tempname}") tmux.send_keys "seq 1 3 | #{FZF} --bind 'ctrl-r:reload(#{tempname})'", :Enter - tmux.until { |lines| assert_equal 3, lines.item_count } + tmux.until { |lines| assert_equal 3, lines.match_count } tmux.send_keys 'C-r' - tmux.until { |lines| assert_equal 1, lines.item_count } + tmux.until { |lines| assert_equal 1, lines.match_count } tmux.send_keys 'C-c' tmux.send_keys 'C-l', 'closed' tmux.until { |lines| assert_includes lines[0], 'closed' } @@ -207,9 +207,9 @@ def test_kill_reload_command_on_accept system("chmod +x #{tempname}") tmux.send_keys "seq 1 3 | #{fzf("--bind 'ctrl-r:reload(#{tempname})'")}", :Enter - tmux.until { |lines| assert_equal 3, lines.item_count } + tmux.until { |lines| assert_equal 3, lines.match_count } tmux.send_keys 'C-r' - tmux.until { |lines| assert_equal 1, lines.item_count } + tmux.until { |lines| assert_equal 1, lines.match_count } tmux.send_keys :Enter assert_equal 'Started', fzf_output wait { refute system("pgrep -f #{tempname}") } @@ -245,7 +245,7 @@ def test_reload_even_when_theres_no_match def test_reload_should_terminate_standard_input_stream tmux.send_keys %(ruby -e "STDOUT.sync = true; loop { puts 1; sleep 0.1 }" | fzf --bind 'start:reload(seq 100)'), :Enter - tmux.until { |lines| assert_equal 100, lines.item_count } + tmux.until { |lines| assert_equal 100, lines.match_count } end def test_clear_list_when_header_lines_changed_due_to_reload @@ -264,7 +264,7 @@ def test_item_index_reset_on_reload tmux.until { |lines| assert_includes lines[1], '[[0]]' } tmux.send_keys :Space tmux.until do |lines| - assert_equal 100, lines.item_count + assert_equal 100, lines.match_count assert_includes lines[1], '[[0]]' end tmux.send_keys :Up @@ -280,16 +280,16 @@ def test_reload_should_update_preview def test_reload_and_change_preview_should_update_preview tmux.send_keys "seq 3 | #{FZF} --bind 'ctrl-t:reload(echo 4)+change-preview(echo {})'", :Enter - tmux.until { |lines| assert_equal 3, lines.item_count } + tmux.until { |lines| assert_equal 3, lines.match_count } tmux.until { |lines| refute_includes lines[1], '1' } tmux.send_keys 'C-t' - tmux.until { |lines| assert_equal 1, lines.item_count } + tmux.until { |lines| assert_equal 1, lines.match_count } tmux.until { |lines| assert_includes lines[1], '4' } end def test_reload_sync tmux.send_keys "seq 100 | #{FZF} --bind 'load:reload-sync(sleep 1; seq 1000)+unbind(load)'", :Enter - tmux.until { |lines| assert_equal 100, lines.item_count } + tmux.until { |lines| assert_equal 100, lines.match_count } tmux.send_keys '00' tmux.until { |lines| assert_equal 1, lines.match_count } # After 1 second @@ -404,7 +404,7 @@ def test_start_on_reload def test_become tmux.send_keys "seq 100 | #{FZF} --bind 'enter:become:seq {} | #{FZF}'", :Enter - tmux.until { |lines| assert_equal 100, lines.item_count } + tmux.until { |lines| assert_equal 100, lines.match_count } tmux.send_keys 999 tmux.until { |lines| assert_equal 0, lines.match_count } tmux.send_keys :Enter diff --git a/test/test_preview.rb b/test/test_preview.rb index 356d23a4a38..c3659af05d4 100644 --- a/test/test_preview.rb +++ b/test/test_preview.rb @@ -123,7 +123,7 @@ def test_preview_hidden def test_preview_size_0 tmux.send_keys %(seq 100 | #{FZF} --reverse --preview 'echo {} >> #{tempname}; echo ' --preview-window 0 --bind space:toggle-preview), :Enter tmux.until do |lines| - assert_equal 100, lines.item_count + assert_equal 100, lines.match_count assert_equal ' 100/100', lines[1] assert_equal '> 1', lines[2] end @@ -147,7 +147,7 @@ def test_preview_size_0 def test_preview_size_0_hidden tmux.send_keys %(seq 100 | #{FZF} --reverse --preview 'echo {} >> #{tempname}; echo ' --preview-window 0,hidden --bind space:toggle-preview), :Enter - tmux.until { |lines| assert_equal 100, lines.item_count } + tmux.until { |lines| assert_equal 100, lines.match_count } tmux.send_keys :Down, :Down tmux.until { |lines| assert_includes lines, '> 3' } wait { refute_path_exists tempname } @@ -217,7 +217,7 @@ def test_preview_q_no_match_with_initial_query def test_preview_update_on_select tmux.send_keys %(seq 10 | fzf -m --preview 'echo {+}' --bind a:toggle-all), :Enter - tmux.until { |lines| assert_equal 10, lines.item_count } + tmux.until { |lines| assert_equal 10, lines.match_count } tmux.send_keys 'a' tmux.until { |lines| assert(lines.any? { |line| line.include?(' 1 2 3 4 5 ') }) } tmux.send_keys 'a' @@ -232,7 +232,7 @@ def test_preview_correct_tab_width_after_ansi_reset_code def test_preview_bindings_with_default_preview tmux.send_keys "seq 10 | #{FZF} --preview 'echo [{}]' --bind 'a:preview(echo [{}{}]),b:preview(echo [{}{}{}]),c:refresh-preview'", :Enter - tmux.until { |lines| lines.item_count == 10 } + tmux.until { |lines| lines.match_count == 10 } tmux.until { |lines| assert_includes lines[1], '[1]' } tmux.send_keys 'a' tmux.until { |lines| assert_includes lines[1], '[11]' } @@ -246,7 +246,7 @@ def test_preview_bindings_with_default_preview def test_preview_bindings_without_default_preview tmux.send_keys "seq 10 | #{FZF} --bind 'a:preview(echo [{}{}]),b:preview(echo [{}{}{}]),c:refresh-preview'", :Enter - tmux.until { |lines| lines.item_count == 10 } + tmux.until { |lines| lines.match_count == 10 } tmux.until { |lines| refute_includes lines[1], '1' } tmux.send_keys 'a' tmux.until { |lines| assert_includes lines[1], '[11]' } @@ -283,7 +283,7 @@ def test_preview_scroll_begin_and_offset def test_preview_clear_screen tmux.send_keys %{seq 100 | #{FZF} --preview 'for i in $(seq 300); do (( i % 200 == 0 )) && printf "\\033[2J"; echo "[$i]"; sleep 0.001; done'}, :Enter - tmux.until { |lines| lines.item_count == 100 } + tmux.until { |lines| lines.match_count == 100 } tmux.until { |lines| lines[1]&.include?('[200]') } end @@ -292,7 +292,7 @@ def test_preview_window_follow file.sync = true tmux.send_keys %(seq 100 | #{FZF} --preview 'echo start; tail -f "#{file.path}"' --preview-window follow --bind 'up:preview-up,down:preview-down,space:change-preview-window:follow|nofollow' --preview-window '~4'), :Enter - tmux.until { |lines| lines.item_count == 100 } + tmux.until { |lines| lines.match_count == 100 } # Write to the temporary file, and check if the preview window is showing # the last line of the file @@ -382,7 +382,7 @@ def test_close def test_preview_header tmux.send_keys "seq 100 | #{FZF} --bind ctrl-k:preview-up+preview-up,ctrl-j:preview-down+preview-down+preview-down --preview 'seq 1000' --preview-window 'top:+{1}:~3'", :Enter - tmux.until { |lines| assert_equal 100, lines.item_count } + tmux.until { |lines| assert_equal 100, lines.match_count } top5 = ->(lines) { lines.drop(1).take(5).map { |s| s[/[0-9]+/] } } tmux.until do |lines| assert_includes lines[1], '4/1000' @@ -412,7 +412,7 @@ def test_change_preview_window 'b:change-preview-window(down)+change-preview(echo =={}==)+change-preview-window(up),' \ 'c:change-preview(),d:change-preview-window(hidden),' \ "e:preview(printf ::%${FZF_PREVIEW_COLUMNS}s{})+change-preview-window(up),f:change-preview-window(up,wrap)'", :Enter - tmux.until { |lines| assert_equal 1000, lines.item_count } + tmux.until { |lines| assert_equal 1000, lines.match_count } tmux.until { |lines| assert_includes lines[0], '[[1]]' } # change-preview action permanently changes the preview command set by --preview @@ -515,7 +515,7 @@ def test_change_preview_window_rotate_hidden_down def test_toggle_alternative_preview_window tmux.send_keys "seq 10 | #{FZF} --bind space:toggle-preview --preview-window '<100000(hidden,up,border-none)' --preview 'echo /{}/{}/'", :Enter - tmux.until { |lines| assert_equal 10, lines.item_count } + tmux.until { |lines| assert_equal 10, lines.match_count } tmux.until { |lines| refute_includes lines, '/1/1/' } tmux.send_keys :Space tmux.until { |lines| assert_includes lines, '/1/1/' } @@ -523,7 +523,7 @@ def test_toggle_alternative_preview_window def test_alternative_preview_window_opts tmux.send_keys "seq 10 | #{FZF} --preview-window '~5,2,+0,<100000(~0,+100,wrap,noinfo)' --preview 'seq 1000'", :Enter - tmux.until { |lines| assert_equal 10, lines.item_count } + tmux.until { |lines| assert_equal 10, lines.match_count } tmux.until do |lines| assert_equal ['╭────╮', '│ 10 │', '│ 0 │', '│ 10 │', '│ 1 │'], lines.take(5).map(&:strip) end diff --git a/test/test_server.rb b/test/test_server.rb index e30d50c90eb..1f019bca5cf 100644 --- a/test/test_server.rb +++ b/test/test_server.rb @@ -9,7 +9,7 @@ def test_listen "--listen --sync --bind 'start:execute-silent:echo $FZF_PORT > /tmp/fzf-port'" => -> { URI("http://localhost:#{File.read('/tmp/fzf-port').chomp}") } }.each do |opts, fn| tmux.send_keys "seq 10 | fzf #{opts}", :Enter - tmux.until { |lines| assert_equal 10, lines.item_count } + tmux.until { |lines| assert_equal 10, lines.match_count } state = JSON.parse(Net::HTTP.get(fn.call), symbolize_names: true) assert_equal 10, state[:totalCount] assert_equal 10, state[:matchCount] @@ -33,7 +33,7 @@ def test_listen def test_listen_with_api_key post_uri = URI('http://localhost:6266') tmux.send_keys 'seq 10 | FZF_API_KEY=123abc fzf --listen 6266', :Enter - tmux.until { |lines| assert_equal 10, lines.item_count } + tmux.until { |lines| assert_equal 10, lines.match_count } # Incorrect API Key [nil, { 'x-api-key' => '' }, { 'x-api-key' => '124abc' }].each do |headers| res = Net::HTTP.post(post_uri, 'change-query(yo)+reload(seq 100)+change-prompt:hundred> ', headers)