mirror of
https://github.com/Llewellynvdm/fzf.git
synced 2024-11-25 22:27:41 +00:00
Fix flaky tests
This commit is contained in:
parent
c3a198d0c7
commit
3d39ab5ded
@ -15,18 +15,10 @@ class Tmux
|
|||||||
attr_reader :win
|
attr_reader :win
|
||||||
|
|
||||||
def initialize shell = 'bash'
|
def initialize shell = 'bash'
|
||||||
@win = go("new-window -P -F '#I' 'bash --rcfile ~/.fzf.#{shell}'").first
|
@win = go("new-window -d -P -F '#I' 'PS1= bash --rcfile ~/.fzf.#{shell}'").first
|
||||||
@lines = `tput lines`.chomp.to_i
|
@lines = `tput lines`.chomp.to_i
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.current
|
|
||||||
`tmux display-message -p '#I'`.split($/).first
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.select id
|
|
||||||
system "tmux select-window -t #{id}"
|
|
||||||
end
|
|
||||||
|
|
||||||
def closed?
|
def closed?
|
||||||
!go("list-window -F '#I'").include?(win)
|
!go("list-window -F '#I'").include?(win)
|
||||||
end
|
end
|
||||||
@ -85,6 +77,12 @@ class TestGoFZF < MiniTest::Unit::TestCase
|
|||||||
'/tmp/output'
|
'/tmp/output'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def rmtemp
|
||||||
|
while File.exists? tempname
|
||||||
|
File.unlink tempname rescue nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def readtemp
|
def readtemp
|
||||||
waited = 0
|
waited = 0
|
||||||
while waited < 5
|
while waited < 5
|
||||||
@ -101,14 +99,12 @@ class TestGoFZF < MiniTest::Unit::TestCase
|
|||||||
def setup
|
def setup
|
||||||
ENV.delete 'FZF_DEFAULT_OPTS'
|
ENV.delete 'FZF_DEFAULT_OPTS'
|
||||||
ENV.delete 'FZF_DEFAULT_COMMAND'
|
ENV.delete 'FZF_DEFAULT_COMMAND'
|
||||||
@prev = Tmux.current
|
|
||||||
@tmux = Tmux.new
|
@tmux = Tmux.new
|
||||||
File.unlink tempname rescue nil
|
rmtemp
|
||||||
end
|
end
|
||||||
|
|
||||||
def teardown
|
def teardown
|
||||||
@tmux.kill
|
@tmux.kill
|
||||||
Tmux.select @prev
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_vanilla
|
def test_vanilla
|
||||||
@ -210,7 +206,7 @@ class TestGoFZF < MiniTest::Unit::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_multi_order
|
def test_multi_order
|
||||||
tmux.send_keys "seq 1 10 | fzf --multi > #{tempname}", :Enter
|
tmux.send_keys "seq 1 10 | fzf --multi > #{tempname} && echo -n done", :Enter
|
||||||
tmux.until { |lines| lines.last =~ /^>/ }
|
tmux.until { |lines| lines.last =~ /^>/ }
|
||||||
|
|
||||||
tmux.send_keys :Tab, :Up, :Up, :Tab, :Tab, :Tab, # 3, 2
|
tmux.send_keys :Tab, :Up, :Up, :Tab, :Tab, :Tab, # 3, 2
|
||||||
@ -218,15 +214,18 @@ class TestGoFZF < MiniTest::Unit::TestCase
|
|||||||
:PgUp, 'C-J', :Down, :Tab, :Tab # 8, 7
|
:PgUp, 'C-J', :Down, :Tab, :Tab # 8, 7
|
||||||
tmux.until { |lines| lines[-2].include? '(6)' }
|
tmux.until { |lines| lines[-2].include? '(6)' }
|
||||||
tmux.send_keys "C-M"
|
tmux.send_keys "C-M"
|
||||||
|
tmux.until { |lines| lines[-1].include?('done') }
|
||||||
assert_equal %w[3 2 5 6 8 7], readtemp.split($/)
|
assert_equal %w[3 2 5 6 8 7], readtemp.split($/)
|
||||||
tmux.close
|
tmux.close
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_with_nth
|
def test_with_nth
|
||||||
[true, false].each do |multi|
|
[true, false].each do |multi|
|
||||||
|
rmtemp
|
||||||
|
|
||||||
tmux.send_keys "(echo ' 1st 2nd 3rd/';
|
tmux.send_keys "(echo ' 1st 2nd 3rd/';
|
||||||
echo ' first second third/') |
|
echo ' first second third/') |
|
||||||
fzf #{"--multi" if multi} -x --nth 2 --with-nth 2,-1,1 > #{tempname}",
|
fzf #{"--multi" if multi} -x --nth 2 --with-nth 2,-1,1 > #{tempname} && echo -n done",
|
||||||
:Enter
|
:Enter
|
||||||
tmux.until { |lines| lines[-2].include?('2/2') }
|
tmux.until { |lines| lines[-2].include?('2/2') }
|
||||||
|
|
||||||
@ -238,12 +237,12 @@ class TestGoFZF < MiniTest::Unit::TestCase
|
|||||||
# However, the output must not be transformed
|
# However, the output must not be transformed
|
||||||
if multi
|
if multi
|
||||||
tmux.send_keys :BTab, :BTab, :Enter
|
tmux.send_keys :BTab, :BTab, :Enter
|
||||||
|
tmux.until { |lines| lines[-1].include?('done') }
|
||||||
assert_equal [' 1st 2nd 3rd/', ' first second third/'], readtemp.split($/)
|
assert_equal [' 1st 2nd 3rd/', ' first second third/'], readtemp.split($/)
|
||||||
else
|
else
|
||||||
tmux.send_keys '^', '3'
|
tmux.send_keys '^', '3'
|
||||||
tmux.until { |lines| lines[-2].include?('1/2') }
|
tmux.until { |lines| lines[-2].include?('1/2') }
|
||||||
tmux.send_keys :Enter
|
tmux.send_keys :Enter
|
||||||
tmux.send_keys 'echo -n done', :Enter
|
|
||||||
tmux.until { |lines| lines[-1].include?('done') }
|
tmux.until { |lines| lines[-1].include?('done') }
|
||||||
assert_equal [' 1st 2nd 3rd/'], readtemp.split($/)
|
assert_equal [' 1st 2nd 3rd/'], readtemp.split($/)
|
||||||
end
|
end
|
||||||
@ -252,14 +251,13 @@ class TestGoFZF < MiniTest::Unit::TestCase
|
|||||||
|
|
||||||
def test_scroll
|
def test_scroll
|
||||||
[true, false].each do |rev|
|
[true, false].each do |rev|
|
||||||
tmux.send_keys "seq 1 100 | fzf #{'--reverse' if rev} > #{tempname}", :Enter
|
rmtemp
|
||||||
tmux.until { |lines| rev ? lines.first == '>' : lines.last == '>' }
|
|
||||||
|
|
||||||
110.times do
|
tmux.send_keys "seq 1 100 | fzf #{'--reverse' if rev} > #{tempname} && echo -n done", :Enter
|
||||||
tmux.send_keys rev ? :Down : :Up
|
tmux.until { |lines| rev ? lines.first == '>' : lines.last == '>' }
|
||||||
end
|
tmux.send_keys *110.times.map { rev ? :Down : :Up }
|
||||||
|
tmux.until { |lines| lines.include? '> 100' }
|
||||||
tmux.send_keys :Enter
|
tmux.send_keys :Enter
|
||||||
tmux.send_keys 'echo -n done', :Enter
|
|
||||||
tmux.until { |lines| lines[-1].include?('done') }
|
tmux.until { |lines| lines[-1].include?('done') }
|
||||||
assert_equal '100', readtemp.chomp
|
assert_equal '100', readtemp.chomp
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user