From 8f6d8b1dd126bb1bab406bba304e717be2162e1e Mon Sep 17 00:00:00 2001 From: nvbn Date: Mon, 27 Jul 2015 17:28:09 +0300 Subject: [PATCH] Add tests for history changes fro bash and zsh --- tests/functional/plots.py | 12 ++++++++++++ tests/functional/test_bash.py | 8 +++++++- tests/functional/test_fish.py | 2 ++ tests/functional/test_tcsh.py | 2 ++ tests/functional/test_zsh.py | 11 ++++++++++- 5 files changed, 33 insertions(+), 2 deletions(-) diff --git a/tests/functional/plots.py b/tests/functional/plots.py index bf1907db..a0cb1892 100644 --- a/tests/functional/plots.py +++ b/tests/functional/plots.py @@ -17,6 +17,18 @@ def with_confirmation(proc): assert proc.expect([TIMEOUT, u'test']) +def history_changed(proc): + """Ensures that history changed.""" + proc.send('\033[A') + assert proc.expect([TIMEOUT, 'echo test']) + + +def history_not_changed(proc): + """Ensures that history not changed.""" + proc.send('\033[A') + assert proc.expect([TIMEOUT, 'fuck']) + + def refuse_with_confirmation(proc): """Ensures that fix can be refused when confirmation enabled.""" proc.sendline(u'mkdir -p ~/.thefuck') diff --git a/tests/functional/test_bash.py b/tests/functional/test_bash.py index 1aabf7ea..eb980c00 100644 --- a/tests/functional/test_bash.py +++ b/tests/functional/test_bash.py @@ -1,6 +1,6 @@ import pytest from tests.functional.plots import with_confirmation, without_confirmation, \ - refuse_with_confirmation + refuse_with_confirmation, history_changed, history_not_changed from tests.functional.utils import spawn, functional, images containers = images(('ubuntu-python3-bash', u''' @@ -23,7 +23,9 @@ RUN pip2 install -U pip setuptools def test_with_confirmation(tag, dockerfile): with spawn(tag, dockerfile, u'bash') as proc: proc.sendline(u'eval $(thefuck-alias)') + proc.sendline(u'touch $HISTFILE') with_confirmation(proc) + history_changed(proc) @functional @@ -31,7 +33,9 @@ def test_with_confirmation(tag, dockerfile): def test_refuse_with_confirmation(tag, dockerfile): with spawn(tag, dockerfile, u'bash') as proc: proc.sendline(u'eval $(thefuck-alias)') + proc.sendline(u'touch $HISTFILE') refuse_with_confirmation(proc) + history_not_changed(proc) @functional @@ -39,4 +43,6 @@ def test_refuse_with_confirmation(tag, dockerfile): def test_without_confirmation(tag, dockerfile): with spawn(tag, dockerfile, u'bash') as proc: proc.sendline(u'eval $(thefuck-alias)') + proc.sendline(u'touch $HISTFILE') without_confirmation(proc) + history_changed(proc) diff --git a/tests/functional/test_fish.py b/tests/functional/test_fish.py index 3f966d89..89ad11ac 100644 --- a/tests/functional/test_fish.py +++ b/tests/functional/test_fish.py @@ -49,3 +49,5 @@ def test_without_confirmation(tag, dockerfile): proc.sendline(u'thefuck-alias > ~/.config/fish/config.fish') proc.sendline(u'fish') without_confirmation(proc) + +# TODO: ensure that history changes. diff --git a/tests/functional/test_tcsh.py b/tests/functional/test_tcsh.py index f56ee55e..674c106b 100644 --- a/tests/functional/test_tcsh.py +++ b/tests/functional/test_tcsh.py @@ -43,3 +43,5 @@ def test_without_confirmation(tag, dockerfile): proc.sendline(u'tcsh') proc.sendline(u'eval `thefuck-alias`') without_confirmation(proc) + +# TODO: ensure that history changes. diff --git a/tests/functional/test_zsh.py b/tests/functional/test_zsh.py index 44ed0153..da46d94a 100644 --- a/tests/functional/test_zsh.py +++ b/tests/functional/test_zsh.py @@ -1,7 +1,7 @@ import pytest from tests.functional.utils import spawn, functional, images from tests.functional.plots import with_confirmation, without_confirmation, \ - refuse_with_confirmation + refuse_with_confirmation, history_changed, history_not_changed containers = images(('ubuntu-python3-zsh', u''' FROM ubuntu:latest @@ -23,7 +23,10 @@ RUN pip2 install -U pip setuptools def test_with_confirmation(tag, dockerfile): with spawn(tag, dockerfile, u'zsh') as proc: proc.sendline(u'eval $(thefuck-alias)') + proc.sendline(u'export HISTFILE=~/.zsh_history') + proc.sendline(u'touch $HISTFILE') with_confirmation(proc) + history_changed(proc) @functional @@ -31,7 +34,10 @@ def test_with_confirmation(tag, dockerfile): def test_refuse_with_confirmation(tag, dockerfile): with spawn(tag, dockerfile, u'zsh') as proc: proc.sendline(u'eval $(thefuck-alias)') + proc.sendline(u'export HISTFILE=~/.zsh_history') + proc.sendline(u'touch $HISTFILE') refuse_with_confirmation(proc) + history_not_changed(proc) @functional @@ -39,4 +45,7 @@ def test_refuse_with_confirmation(tag, dockerfile): def test_without_confirmation(tag, dockerfile): with spawn(tag, dockerfile, u'zsh') as proc: proc.sendline(u'eval $(thefuck-alias)') + proc.sendline(u'export HISTFILE=~/.zsh_history') + proc.sendline(u'touch $HISTFILE') without_confirmation(proc) + history_changed(proc)