Fix flaky tests
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Junegunn Choi · committed by Junegunn Choi · parent c3a198d · Browse files · 1 file·+19 added−21 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+19 added−21 removed
- tests:+19 added−21 removed
Provenance
- Commit
3d39ab5- Tree
a31f89f- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
c3a198d
1 file changed+19 added−21 removed
modified:test/test_go.rb+19 added-21 removed
13 unmodified lines14 15 attr_reader :win16 17 def initialize shell = 'bash'18- @win = go("new-window -P -F '#I' 'bash --rcfile ~/.fzf.#{shell}'").first18+ @win = go("new-window -d -P -F '#I' 'PS1= bash --rcfile ~/.fzf.#{shell}'").first19 @lines = `tput lines`.chomp.to_i20 end21 22- def self.current23- `tmux display-message -p '#I'`.split($/).first24- end25-26- def self.select id27- system "tmux select-window -t #{id}"28- end29-22 def closed?23 !go("list-window -F '#I'").include?(win)24 end25 50 unmodified lines76 def tempname77 '/tmp/output'78 end79 80+ def rmtemp81+ while File.exists? tempname82+ File.unlink tempname rescue nil83+ end84+ end85+86 def readtemp87 waited = 088 while waited < 589 begin8 unmodified lines98 99 def setup100 ENV.delete 'FZF_DEFAULT_OPTS'101 ENV.delete 'FZF_DEFAULT_COMMAND'104- @prev = Tmux.current102 @tmux = Tmux.new106- File.unlink tempname rescue nil103+ rmtemp104 end105 106 def teardown107 @tmux.kill111- Tmux.select @prev108 end109 110 def test_vanilla111 tmux.send_keys "seq 1 100000 | fzf > #{tempname}", :Enter93 unmodified lines205 tmux.close206 end207 208 def test_multi_order213- tmux.send_keys "seq 1 10 | fzf --multi > #{tempname}", :Enter209+ tmux.send_keys "seq 1 10 | fzf --multi > #{tempname} && echo -n done", :Enter210 tmux.until { |lines| lines.last =~ /^>/ }211 212 tmux.send_keys :Tab, :Up, :Up, :Tab, :Tab, :Tab, # 3, 2213 'C-K', 'C-K', 'C-K', 'C-K', :BTab, :BTab, # 5, 6214 :PgUp, 'C-J', :Down, :Tab, :Tab # 8, 7215 tmux.until { |lines| lines[-2].include? '(6)' }216 tmux.send_keys "C-M"217+ tmux.until { |lines| lines[-1].include?('done') }218 assert_equal %w[3 2 5 6 8 7], readtemp.split($/)219 tmux.close220 end221 222 def test_with_nth223 [true, false].each do |multi|224+ rmtemp225+226 tmux.send_keys "(echo ' 1st 2nd 3rd/';227 echo ' first second third/') |229- fzf #{"--multi" if multi} -x --nth 2 --with-nth 2,-1,1 > #{tempname}",228+ fzf #{"--multi" if multi} -x --nth 2 --with-nth 2,-1,1 > #{tempname} && echo -n done",229 :Enter230 tmux.until { |lines| lines[-2].include?('2/2') }231 232 # Transformed list3 unmodified lines236 237 # However, the output must not be transformed238 if multi239 tmux.send_keys :BTab, :BTab, :Enter240+ tmux.until { |lines| lines[-1].include?('done') }241 assert_equal [' 1st 2nd 3rd/', ' first second third/'], readtemp.split($/)242 else243 tmux.send_keys '^', '3'244 tmux.until { |lines| lines[-2].include?('1/2') }245 tmux.send_keys :Enter246- tmux.send_keys 'echo -n done', :Enter246 tmux.until { |lines| lines[-1].include?('done') }247 assert_equal [' 1st 2nd 3rd/'], readtemp.split($/)248 end249 end250 end251 252 def test_scroll253 [true, false].each do |rev|255- tmux.send_keys "seq 1 100 | fzf #{'--reverse' if rev} > #{tempname}", :Enter256- tmux.until { |lines| rev ? lines.first == '>' : lines.last == '>' }254+ rmtemp255 258- 110.times do259- tmux.send_keys rev ? :Down : :Up260- end256+ tmux.send_keys "seq 1 100 | fzf #{'--reverse' if rev} > #{tempname} && echo -n done", :Enter257+ tmux.until { |lines| rev ? lines.first == '>' : lines.last == '>' }258+ tmux.send_keys *110.times.map { rev ? :Down : :Up }259+ tmux.until { |lines| lines.include? '> 100' }260 tmux.send_keys :Enter262- tmux.send_keys 'echo -n done', :Enter261 tmux.until { |lines| lines[-1].include?('done') }262 assert_equal '100', readtemp.chomp263 end264 end14 unmodified lines