mirror of
https://github.com/nvbn/thefuck.git
synced 2025-03-14 06:38:32 +00:00
Merge f82ba5ff21b8a17494f7f8f71f7b7b323ec48497 into c7e7e1d884d3bb241ea6448f72a989434c2a35ec
This commit is contained in:
commit
8f29dfdfca
25
tests/rules/test_su.py
Normal file
25
tests/rules/test_su.py
Normal file
@ -0,0 +1,25 @@
|
||||
import pytest
|
||||
from thefuck.rules.su import match, get_new_command
|
||||
from thefuck.types import Command
|
||||
|
||||
|
||||
@pytest.mark.parametrize('output', [
|
||||
'command not found: sudo'])
|
||||
def test_match(output):
|
||||
assert match(Command('', output))
|
||||
|
||||
|
||||
def test_not_match():
|
||||
assert not match(Command('', ''))
|
||||
assert not match(Command('sudo ls', 'Permission denied'))
|
||||
assert not match(Command('su -c ls', 'Permission denied'))
|
||||
assert not match(Command('ls', 'command not found: ls'))
|
||||
|
||||
|
||||
@pytest.mark.parametrize('before, after', [
|
||||
('sudo ls', 'su -c "ls"'),
|
||||
('sudo echo a > b', 'su -c "echo a > b"'),
|
||||
('sudo echo "a" >> b', 'su -c "echo \\"a\\" >> b"'),
|
||||
('sudo mkdir && touch a', 'su -c "mkdir && touch a"')])
|
||||
def test_get_new_command(before, after):
|
||||
assert get_new_command(Command(before, '')) == after
|
12
thefuck/rules/su.py
Normal file
12
thefuck/rules/su.py
Normal file
@ -0,0 +1,12 @@
|
||||
def match(command):
|
||||
if command.script_parts and '&&' not in command.script_parts and command.script_parts[0] == 'su':
|
||||
return False
|
||||
|
||||
return 'command not found: sudo' in command.output.lower()
|
||||
|
||||
|
||||
def get_new_command(command):
|
||||
return u'su -c "{}"'.format(command.script.replace('"', '\\"').replace('sudo ', ''))
|
||||
|
||||
|
||||
priority = 1200
|
Loading…
x
Reference in New Issue
Block a user