mirror of
https://github.com/nvbn/thefuck.git
synced 2025-02-22 12:58:33 +00:00
On a Mac, also on NetBSD or OpenBSD, `touch` errs differently: ``` $ uname; touch a/b/c Darwin touch: a/b/c: No such file or directory ``` That gets matched by the rule but not fixed by it. Thus the regex pattern is now a bit more tolerant.
This commit is contained in:
parent
4e755e4799
commit
cc6d90963e
@ -4,24 +4,32 @@ from thefuck.types import Command
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def output():
|
def output(is_bsd):
|
||||||
return "touch: cannot touch '/a/b/c':" \
|
print(is_bsd)
|
||||||
" No such file or directory"
|
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"
|
||||||
|
|
||||||
|
|
||||||
def test_match(output):
|
@pytest.mark.parametrize('script, is_bsd', [
|
||||||
command = Command('touch /a/b/c', output)
|
('touch /a/b/c', False),
|
||||||
|
('touch /a/b/c', True)])
|
||||||
|
def test_match(script, is_bsd, output):
|
||||||
|
command = Command(script, output)
|
||||||
assert match(command)
|
assert match(command)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('command', [
|
@pytest.mark.parametrize('command', [
|
||||||
Command('touch /a/b/c', ''),
|
Command('touch /a/b/c', ''),
|
||||||
Command('ls /a/b/c', output())])
|
Command('ls /a/b/c', output(False))])
|
||||||
def test_not_match(command):
|
def test_not_match(command):
|
||||||
assert not match(command)
|
assert not match(command)
|
||||||
|
|
||||||
|
|
||||||
def test_get_new_command(output):
|
@pytest.mark.parametrize('script, is_bsd', [
|
||||||
command = Command('touch /a/b/c', output)
|
('touch /a/b/c', False),
|
||||||
|
('touch /a/b/c', True)])
|
||||||
|
def test_get_new_command(script, is_bsd, output):
|
||||||
|
command = Command(script, output)
|
||||||
fixed_command = get_new_command(command)
|
fixed_command = get_new_command(command)
|
||||||
assert fixed_command == 'mkdir -p /a/b && touch /a/b/c'
|
assert fixed_command == 'mkdir -p /a/b && touch /a/b/c'
|
||||||
|
@ -9,5 +9,6 @@ def match(command):
|
|||||||
|
|
||||||
|
|
||||||
def get_new_command(command):
|
def get_new_command(command):
|
||||||
path = re.findall(r"touch: cannot touch '(.+)/.+':", command.output)[0]
|
path = path = re.findall(
|
||||||
|
r"touch: (?:cannot touch ')?(.+)/.+'?:", command.output)[0]
|
||||||
return shell.and_(u'mkdir -p {}'.format(path), command.script)
|
return shell.and_(u'mkdir -p {}'.format(path), command.script)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user