2015-09-09 10:53:56 +03:00
|
|
|
import pytest
|
|
|
|
from thefuck.rules.touch import match, get_new_command
|
2017-08-31 17:58:56 +02:00
|
|
|
from thefuck.types import Command
|
2015-09-09 10:53:56 +03:00
|
|
|
|
|
|
|
|
2018-07-29 17:18:42 +01:00
|
|
|
def output(is_bsd):
|
|
|
|
if is_bsd:
|
|
|
|
return "touch: /a/b/c: No such file or directory"
|
|
|
|
return "touch: cannot touch '/a/b/c': No such file or directory"
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('script, is_bsd', [
|
|
|
|
('touch /a/b/c', False),
|
|
|
|
('touch /a/b/c', True)])
|
2018-11-21 19:43:01 +01:00
|
|
|
def test_match(script, is_bsd):
|
|
|
|
command = Command(script, output(is_bsd))
|
2015-09-09 10:53:56 +03:00
|
|
|
assert match(command)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('command', [
|
2017-08-31 17:58:56 +02:00
|
|
|
Command('touch /a/b/c', ''),
|
2018-07-29 17:18:42 +01:00
|
|
|
Command('ls /a/b/c', output(False))])
|
2015-09-09 10:53:56 +03:00
|
|
|
def test_not_match(command):
|
|
|
|
assert not match(command)
|
|
|
|
|
|
|
|
|
2018-07-29 17:18:42 +01:00
|
|
|
@pytest.mark.parametrize('script, is_bsd', [
|
|
|
|
('touch /a/b/c', False),
|
|
|
|
('touch /a/b/c', True)])
|
2018-11-21 19:43:01 +01:00
|
|
|
def test_get_new_command(script, is_bsd):
|
|
|
|
command = Command(script, output(is_bsd))
|
2015-09-09 10:53:56 +03:00
|
|
|
fixed_command = get_new_command(command)
|
|
|
|
assert fixed_command == 'mkdir -p /a/b && touch /a/b/c'
|