diff options
author | Junegunn Choi <junegunn.c@gmail.com> | 2015-09-15 13:21:51 +0900 |
---|---|---|
committer | Junegunn Choi <junegunn.c@gmail.com> | 2015-09-15 13:21:51 +0900 |
commit | 65d9d416b4300e85304fd158d9df2f6272590849 (patch) | |
tree | ed14402021282a9705248bdb46a6d4c7496d14ca /test | |
parent | fa2f9f1f21bb41ac915a564fbf45b1bf50e40546 (diff) |
Change exit status (0: OK, 1: No match, 2: Error/Interrupted)
A la grep. Close #345
Diffstat (limited to 'test')
-rw-r--r-- | test/test_go.rb | 46 |
1 files changed, 41 insertions, 5 deletions
diff --git a/test/test_go.rb b/test/test_go.rb index d1f45dc1..5b352647 100644 --- a/test/test_go.rb +++ b/test/test_go.rb @@ -780,11 +780,6 @@ class TestGoFZF < TestBase tmux.send_keys :Enter end - def test_invalid_term - tmux.send_keys "TERM=xxx fzf", :Enter - tmux.until { |lines| lines.any? { |l| l.include? 'Invalid $TERM: xxx' } } - end - def test_with_nth writelines tempname, ['hello world ', 'byebye'] assert_equal 'hello world ', `cat #{tempname} | #{FZF} -f"^he hehe" -x -n 2.. --with-nth 2,1,1`.chomp @@ -801,6 +796,47 @@ class TestGoFZF < TestBase assert_equal src, `cat #{tempname} | #{FZF} -fhehe -x -n 2.. --with-nth 2,1,1 --no-ansi`.chomp end + def test_exit_0_exit_code + `echo foo | #{FZF} -q bar -0` + assert_equal 1, $?.exitstatus + end + + def test_invalid_term + lines = `TERM=xxx #{FZF}` + assert_equal 2, $?.exitstatus + assert lines.include?('Invalid $TERM: xxx') + end + + def test_invalid_option + lines = `#{FZF} --foobar 2>&1` + assert_equal 2, $?.exitstatus + assert lines.include?('unknown option: --foobar'), lines + end + + def test_filter_exitstatus + # filter / streaming filter + ["", "--no-sort"].each do |opts| + assert `echo foo | #{FZF} -f foo #{opts}`.include?('foo') + assert_equal 0, $?.exitstatus + + assert `echo foo | #{FZF} -f bar #{opts}`.empty? + assert_equal 1, $?.exitstatus + end + end + + def test_exitstatus_empty + { '99' => '0', '999' => '1' }.each do |query, status| + tmux.send_keys "seq 100 | #{FZF} -q #{query}", :Enter + tmux.until { |lines| lines[-2] =~ %r{ [10]/100} } + tmux.send_keys :Enter + + tmux.send_keys 'echo --\$?--' + tmux.until { |lines| lines.last.include? "echo --$?--" } + tmux.send_keys :Enter + tmux.until { |lines| lines.last.include? "--#{status}--" } + end + end + private def writelines path, lines File.unlink path while File.exists? path |