From 9fe2393a007fd3771f3e6b7badf4c1c2686c065d Mon Sep 17 00:00:00 2001 From: "yoshida.shinya" Date: Sat, 6 Mar 2021 14:48:48 +0900 Subject: [PATCH] Add test cases for killing input command on terminate (#2381 #2382) --- test/test_go.rb | 94 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/test/test_go.rb b/test/test_go.rb index 9ac1be76..74c4db66 100755 --- a/test/test_go.rb +++ b/test/test_go.rb @@ -1922,6 +1922,100 @@ class TestGoFZF < TestBase tmux.send_keys 99 tmux.until { |lines| assert_equal 1, lines.match_count } end + + def test_kill_default_command_on_abort + script = tempname + '.sh' + writelines(script, + ['#!/usr/bin/env bash', + "echo 'Started'", + 'while :; do sleep 1; done']) + system("chmod +x #{script}") + + tmux.send_keys fzf.sub('FZF_DEFAULT_COMMAND=', "FZF_DEFAULT_COMMAND=#{script}"), :Enter + tmux.until { |lines| assert_equal 1, lines.item_count } + tmux.send_keys 'C-c' + tmux.send_keys 'C-l', 'closed' + tmux.until { |lines| assert_includes lines[0], 'closed' } + wait { refute system("pgrep -f #{script}") } + ensure + system("pkill -9 -f #{script}") + begin + File.unlink(script) + rescue StandardError + nil + end + end + + def test_kill_default_command_on_accept + script = tempname + '.sh' + writelines(script, + ['#!/usr/bin/env bash', + "echo 'Started'", + 'while :; do sleep 1; done']) + system("chmod +x #{script}") + + tmux.send_keys fzf.sub('FZF_DEFAULT_COMMAND=', "FZF_DEFAULT_COMMAND=#{script}"), :Enter + tmux.until { |lines| assert_equal 1, lines.item_count } + tmux.send_keys :Enter + assert_equal 'Started', readonce.chomp + wait { refute system("pgrep -f #{script}") } + ensure + system("pkill -9 -f #{script}") + begin + File.unlink(script) + rescue StandardError + nil + end + end + + def test_kill_reload_command_on_abort + script = tempname + '.sh' + writelines(script, + ['#!/usr/bin/env bash', + "echo 'Started'", + 'while :; do sleep 1; done']) + system("chmod +x #{script}") + + tmux.send_keys "seq 1 3 | #{fzf("--bind 'ctrl-r:reload(#{script})'")}", :Enter + tmux.until { |lines| assert_equal 3, lines.item_count } + tmux.send_keys 'C-r' + tmux.until { |lines| assert_equal 1, lines.item_count } + tmux.send_keys 'C-c' + tmux.send_keys 'C-l', 'closed' + tmux.until { |lines| assert_includes lines[0], 'closed' } + wait { refute system("pgrep -f #{script}") } + ensure + system("pkill -9 -f #{script}") + begin + File.unlink(script) + rescue StandardError + nil + end + end + + def test_kill_reload_command_on_accept + script = tempname + '.sh' + writelines(script, + ['#!/usr/bin/env bash', + "echo 'Started'", + 'while :; do sleep 1; done']) + system("chmod +x #{script}") + + tmux.send_keys "seq 1 3 | #{fzf("--bind 'ctrl-r:reload(#{script})'")}", :Enter + tmux.until { |lines| assert_equal 3, lines.item_count } + tmux.send_keys 'C-r' + tmux.until { |lines| assert_equal 1, lines.item_count } + tmux.send_keys :Enter + assert_equal 'Started', readonce.chomp + wait { refute system("pgrep -f #{script}") } + ensure + system("pkill -9 -f #{script}") + begin + File.unlink(script) + rescue StandardError + nil + end + end end module TestShell