summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2015-06-14 02:44:22 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2015-06-14 02:44:22 +0900
commit8b618f743914311662b09ecc549e4c9aa53540dc (patch)
tree53f05c6a96c5c40e86d5d6d6ddbf271682ab4216
parent8973207bb4e1b27c3123e2d5132001ea7d8bb67d (diff)
Test refactoring
-rw-r--r--test/test_go.rb38
1 files changed, 9 insertions, 29 deletions
diff --git a/test/test_go.rb b/test/test_go.rb
index d36bc4d9..43fb5559 100644
--- a/test/test_go.rb
+++ b/test/test_go.rb
@@ -72,17 +72,6 @@ class Tmux
end
end
- def closed?
- !go("list-window -F '#I'").include?(win)
- end
-
- def close
- wait do
- send_keys 'C-c', 'C-u', 'exit', :Enter
- closed?
- end
- end
-
def kill
go("kill-window -t #{win} 2> /dev/null")
end
@@ -152,21 +141,25 @@ class TestBase < Minitest::Test
attr_reader :tmux
+ def tempname
+ [TEMPNAME,
+ caller_locations.map(&:label).find { |l| l =~ /^test_/ }].join '-'
+ end
+
def setup
ENV.delete 'FZF_DEFAULT_OPTS'
ENV.delete 'FZF_DEFAULT_COMMAND'
- File.unlink TEMPNAME while File.exists?(TEMPNAME)
end
def readonce
- wait { File.exists?(TEMPNAME) }
- File.read(TEMPNAME)
+ wait { File.exists?(tempname) }
+ File.read(tempname)
ensure
- File.unlink TEMPNAME while File.exists?(TEMPNAME)
+ File.unlink tempname while File.exists?(tempname)
end
def fzf(*opts)
- fzf!(*opts) + " > #{TEMPNAME}.tmp; mv #{TEMPNAME}.tmp #{TEMPNAME}"
+ fzf!(*opts) + " > #{tempname}.tmp; mv #{tempname}.tmp #{tempname}"
end
def fzf!(*opts)
@@ -214,7 +207,6 @@ class TestGoFZF < TestBase
assert_equal '> 391', lines[-1]
tmux.send_keys :Enter
- tmux.close
assert_equal '1391', readonce.chomp
end
@@ -223,7 +215,6 @@ class TestGoFZF < TestBase
tmux.until { |lines| lines.last =~ /^>/ }
tmux.send_keys :Enter
- tmux.close
assert_equal 'hello', readonce.chomp
end
@@ -290,7 +281,6 @@ class TestGoFZF < TestBase
# CTRL-M
tmux.send_keys "C-M"
tmux.until { |lines| lines.last !~ /^>/ }
- tmux.close
end
def test_multi_order
@@ -303,7 +293,6 @@ class TestGoFZF < TestBase
tmux.until { |lines| lines[-2].include? '(6)' }
tmux.send_keys "C-M"
assert_equal %w[3 2 5 6 8 7], readonce.split($/)
- tmux.close
end
def test_with_nth
@@ -454,16 +443,12 @@ class TestGoFZF < TestBase
end
def test_unicode_case
- tempname = TEMPNAME + Time.now.to_f.to_s
writelines tempname, %w[строКА1 СТРОКА2 строка3 Строка4]
assert_equal %w[СТРОКА2 Строка4], `cat #{tempname} | #{FZF} -fС`.split($/)
assert_equal %w[строКА1 СТРОКА2 строка3 Строка4], `cat #{tempname} | #{FZF} -fс`.split($/)
- rescue
- File.unlink tempname
end
def test_tiebreak
- tempname = TEMPNAME + Time.now.to_f.to_s
input = %w[
--foobar--------
-----foobar---
@@ -500,8 +485,6 @@ class TestGoFZF < TestBase
], `cat #{tempname} | #{FZF} -ffoobar --tiebreak end`.split($/)
assert_equal input, `cat #{tempname} | #{FZF} -f"!z" -x --tiebreak end`.split($/)
- rescue
- File.unlink tempname
end
def test_invalid_cache
@@ -527,14 +510,11 @@ class TestGoFZF < TestBase
end
def test_long_line
- tempname = TEMPNAME + Time.now.to_f.to_s
data = '.' * 256 * 1024
File.open(tempname, 'w') do |f|
f << data
end
assert_equal data, `cat #{tempname} | #{FZF} -f .`.chomp
- ensure
- File.unlink tempname
end
def test_null