2016-03-02 23:19:22 +01:00
|
|
|
|
# -*- coding: utf-8 -*-
|
2016-03-04 00:20:33 +03:00
|
|
|
|
import pytest
|
2016-03-02 17:48:20 +01:00
|
|
|
|
from thefuck.rules.ln_no_hard_link import match, get_new_command
|
2017-08-31 17:58:56 +02:00
|
|
|
|
from thefuck.types import Command
|
2016-03-02 17:48:20 +01:00
|
|
|
|
|
2016-03-04 00:20:33 +03:00
|
|
|
|
error = "hard link not allowed for directory"
|
|
|
|
|
|
|
|
|
|
|
2017-08-31 17:58:56 +02:00
|
|
|
|
@pytest.mark.parametrize('script, output', [
|
2016-03-04 00:20:33 +03:00
|
|
|
|
("ln barDir barLink", "ln: ‘barDir’: {}"),
|
|
|
|
|
("sudo ln a b", "ln: ‘a’: {}"),
|
|
|
|
|
("sudo ln -nbi a b", "ln: ‘a’: {}")])
|
2017-08-31 17:58:56 +02:00
|
|
|
|
def test_match(script, output):
|
|
|
|
|
command = Command(script, output.format(error))
|
2016-03-04 00:20:33 +03:00
|
|
|
|
assert match(command)
|
|
|
|
|
|
|
|
|
|
|
2017-08-31 17:58:56 +02:00
|
|
|
|
@pytest.mark.parametrize('script, output', [
|
2016-03-04 00:20:33 +03:00
|
|
|
|
('', ''),
|
|
|
|
|
("ln a b", "... hard link"),
|
|
|
|
|
("sudo ln a b", "... hard link"),
|
|
|
|
|
("a b", error)])
|
2017-08-31 17:58:56 +02:00
|
|
|
|
def test_not_match(script, output):
|
|
|
|
|
command = Command(script, output)
|
2016-03-04 00:20:33 +03:00
|
|
|
|
assert not match(command)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('script, result', [
|
|
|
|
|
("ln barDir barLink", "ln -s barDir barLink"),
|
|
|
|
|
("sudo ln barDir barLink", "sudo ln -s barDir barLink"),
|
|
|
|
|
("sudo ln -nbi a b", "sudo ln -s -nbi a b"),
|
|
|
|
|
("ln -nbi a b && ls", "ln -s -nbi a b && ls"),
|
|
|
|
|
("ln a ln", "ln -s a ln"),
|
|
|
|
|
("sudo ln a ln", "sudo ln -s a ln")])
|
|
|
|
|
def test_get_new_command(script, result):
|
2017-08-31 17:58:56 +02:00
|
|
|
|
command = Command(script, '')
|
2016-03-04 00:20:33 +03:00
|
|
|
|
assert get_new_command(command) == result
|