mirror of
https://github.com/nvbn/thefuck.git
synced 2025-02-21 20:38:54 +00:00
#52 Use cp -a
, add tests
This commit is contained in:
parent
3665a23b9a
commit
7888315196
14
tests/rules/test_cp_omitting_directory.py
Normal file
14
tests/rules/test_cp_omitting_directory.py
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
from mock import Mock
|
||||||
|
from thefuck.rules.cp_omitting_directory import match, get_new_command
|
||||||
|
|
||||||
|
|
||||||
|
def test_match():
|
||||||
|
assert match(Mock(script='cp dir', stderr="cp: omitting directory 'dir'"),
|
||||||
|
None)
|
||||||
|
assert not match(Mock(script='some dir',
|
||||||
|
stderr="cp: omitting directory 'dir'"), None)
|
||||||
|
assert not match(Mock(script='cp dir', stderr=""), None)
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_new_command():
|
||||||
|
assert get_new_command(Mock(script='cp dir'), None) == 'cp -a dir'
|
@ -1,10 +1,10 @@
|
|||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
def match(command, settings):
|
def match(command, settings):
|
||||||
if 'cp: omitting directory' in command.stderr.lower():
|
return command.script.startswith('cp ') \
|
||||||
return True
|
and 'cp: omitting directory' in command.stderr.lower()
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def get_new_command(command, settings):
|
def get_new_command(command, settings):
|
||||||
return command.script.replace('cp', 'cp -r')
|
return re.sub(r'^cp', 'cp -a', command.script)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user