Skip to content

Commit

Permalink
Merge c5e1139 into 8564779
Browse files Browse the repository at this point in the history
  • Loading branch information
mcarton committed Aug 17, 2015
2 parents 8564779 + c5e1139 commit 3bf7267
Show file tree
Hide file tree
Showing 31 changed files with 203 additions and 114 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ using the matched rule and runs it. Rules enabled by default are as follows:
* `grep_recursive` – adds `-r` when you trying to `grep` directory;
* `gulp_not_task` – fixes misspelled gulp tasks;
* `has_exists_script` – prepends `./` when script/binary exists;
* `heroku_no_command` – fixes wrong `heroku` commands like `heroku log`;
* `heroku_not_command` – fixes wrong `heroku` commands like `heroku log`;
* `history` – tries to replace command with most similar command from history;
* `java` – removes `.java` extension when running Java programs;
* `javac` – appends missing `.java` when compiling Java files;
Expand All @@ -185,7 +185,7 @@ using the matched rule and runs it. Rules enabled by default are as follows:
* `sl_ls` – changes `sl` to `ls`;
* `ssh_known_hosts` – removes host from `known_hosts` on warning;
* `sudo` – prepends `sudo` to previous command if it failed because of permissions;
* `switch_layout` – switches command from your local layout to en;
* `switch_lang` – switches command from your local layout to en;
* `systemctl` – correctly orders parameters of confusing `systemctl`;
* `test.py` – runs `py.test` instead of `test.py`;
* `tsuru_login` – runs `tsuru login` if not authenticated or session expired;
Expand All @@ -200,6 +200,7 @@ Enabled by default only on specific platforms:
* `brew_unknown_command` – fixes wrong brew commands, for example `brew docto/brew doctor`;
* `brew_upgrade` – appends `--all` to `brew upgrade` as per Homebrew's new behaviour;
* `pacman` – installs app with `pacman` if it is not installed (uses `yaourt` if available).
* `pacman_not_found` – fix package name with `pacman` or `yaourt`;

Bundled, but not enabled by default:

Expand Down
52 changes: 28 additions & 24 deletions tests/rules/test_composer_not_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,38 @@

@pytest.fixture
def composer_not_command():
return """
[InvalidArgumentException]
Command "udpate" is not defined.
Did you mean this?
update
"""
# that weird spacing is part of the actual command output
return (
'\n'
'\n'
' \n'
' [InvalidArgumentException] \n'
' Command "udpate" is not defined. \n'
' Did you mean this? \n'
' update \n'
' \n'
'\n'
'\n'
)


@pytest.fixture
def composer_not_command_one_of_this():
return """
[InvalidArgumentException]
Command "pdate" is not defined.
Did you mean one of these?
selfupdate
self-update
update
"""
# that weird spacing is part of the actual command output
return (
'\n'
'\n'
' \n'
' [InvalidArgumentException] \n'
' Command "pdate" is not defined. \n'
' Did you mean one of these? \n'
' selfupdate \n'
' self-update \n'
' update \n'
' \n'
'\n'
'\n'
)


def test_match(composer_not_command, composer_not_command_one_of_this):
Expand Down
1 change: 1 addition & 0 deletions tests/rules/test_dirty_untar.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def reset(path):
('tar -xvf {}', 'mkdir -p foo && tar -xvf {} -C foo'),
('tar --extract -f {}', 'mkdir -p foo && tar --extract -f {} -C foo')])


@parametrize_filename
@parametrize_script
def test_match(tar_error, filename, script, fixed):
Expand Down
108 changes: 77 additions & 31 deletions tests/rules/test_fix_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,59 +2,60 @@
import os
from thefuck.rules.fix_file import match, get_new_command
from tests.utils import Command
from thefuck.types import Settings


# (script, file, line, col (or None), stderr)
# (script, file, line, col (or None), stdout, stderr)
tests = (
('gcc a.c', 'a.c', 3, 1,
('gcc a.c', 'a.c', 3, 1, '',
"""
a.c: In function 'main':
a.c:3:1: error: expected expression before '}' token
}
^
"""),

('clang a.c', 'a.c', 3, 1,
('clang a.c', 'a.c', 3, 1, '',
"""
a.c:3:1: error: expected expression
}
^
"""),

('perl a.pl', 'a.pl', 3, None,
('perl a.pl', 'a.pl', 3, None, '',
"""
syntax error at a.pl line 3, at EOF
Execution of a.pl aborted due to compilation errors.
"""),

('perl a.pl', 'a.pl', 2, None,
('perl a.pl', 'a.pl', 2, None, '',
"""
Search pattern not terminated at a.pl line 2.
"""),

('sh a.sh', 'a.sh', 2, None,
('sh a.sh', 'a.sh', 2, None, '',
"""
a.sh: line 2: foo: command not found
"""),

('zsh a.sh', 'a.sh', 2, None,
('zsh a.sh', 'a.sh', 2, None, '',
"""
a.sh:2: command not found: foo
"""),

('bash a.sh', 'a.sh', 2, None,
('bash a.sh', 'a.sh', 2, None, '',
"""
a.sh: line 2: foo: command not found
"""),

('rustc a.rs', 'a.rs', 2, 5,
('rustc a.rs', 'a.rs', 2, 5, '',
"""
a.rs:2:5: 2:6 error: unexpected token: `+`
a.rs:2 +
^
"""),

('cargo build', 'src/lib.rs', 3, 5,
('cargo build', 'src/lib.rs', 3, 5, '',
"""
Compiling test v0.1.0 (file:///tmp/fix-error/test)
src/lib.rs:3:5: 3:6 error: unexpected token: `+`
Expand All @@ -65,15 +66,15 @@
To learn more, run the command again with --verbose.
"""),

('python a.py', 'a.py', 2, None,
('python a.py', 'a.py', 2, None, '',
"""
File "a.py", line 2
+
^
SyntaxError: invalid syntax
"""),

('python a.py', 'a.py', 8, None,
('python a.py', 'a.py', 8, None, '',
"""
Traceback (most recent call last):
File "a.py", line 8, in <module>
Expand All @@ -85,59 +86,58 @@
File "/usr/lib/python3.4/re.py", line 293, in _compile
raise TypeError("first argument must be string or compiled pattern")
TypeError: first argument must be string or compiled pattern
"""
),
"""),

('ruby a.rb', 'a.rb', 3, None,
('ruby a.rb', 'a.rb', 3, None, '',
"""
a.rb:3: syntax error, unexpected keyword_end
"""),

('lua a.lua', 'a.lua', 2, None,
('lua a.lua', 'a.lua', 2, None, '',
"""
lua: a.lua:2: unexpected symbol near '+'
"""),

('fish a.sh', '/tmp/fix-error/a.sh', 2, None,
('fish a.sh', '/tmp/fix-error/a.sh', 2, None, '',
"""
fish: Unknown command 'foo'
/tmp/fix-error/a.sh (line 2): foo
^
"""),

('./a', './a', 2, None,
('./a', './a', 2, None, '',
"""
awk: ./a:2: BEGIN { print "Hello, world!" + }
awk: ./a:2: ^ syntax error
"""),

('llc a.ll', 'a.ll', 1, None,
('llc a.ll', 'a.ll', 1, 2, '',
"""
llc: a.ll:1:1: error: expected top-level entity
llc: a.ll:1:2: error: expected top-level entity
+
^
"""),

('go build a.go', 'a.go', 1, None,
('go build a.go', 'a.go', 1, 2, '',
"""
can't load package:
a.go:1:1: expected 'package', found '+'
a.go:1:2: expected 'package', found '+'
"""),

('make', 'Makefile', 2, None,
('make', 'Makefile', 2, None, '',
"""
bidule
make: bidule: Command not found
Makefile:2: recipe for target 'target' failed
make: *** [target] Error 127
"""),

('git st', '/home/martin/.config/git/config', 1, None,
('git st', '/home/martin/.config/git/config', 1, None, '',
"""
fatal: bad config file line 1 in /home/martin/.config/git/config
"""),

('node fuck.js asdf qwer', '/Users/pablo/Workspace/barebones/fuck.js', '2', 5,
('node fuck.js asdf qwer', '/Users/pablo/Workspace/barebones/fuck.js', '2', 5, '',
"""
/Users/pablo/Workspace/barebones/fuck.js:2
conole.log(arg); // this should read console.log(arg);
Expand All @@ -154,35 +154,81 @@
at startup (node.js:129:16)
at node.js:814:3
"""),

('pep8', './tests/rules/test_systemctl.py', 17, 80,
"""
./tests/rules/test_systemctl.py:17:80: E501 line too long (93 > 79 characters)
./tests/rules/test_systemctl.py:18:80: E501 line too long (103 > 79 characters)
./tests/rules/test_whois.py:20:80: E501 line too long (89 > 79 characters)
./tests/rules/test_whois.py:22:80: E501 line too long (83 > 79 characters)
""", ''),

('py.test', '/home/thefuck/tests/rules/test_fix_file.py', 218, None,
"""
monkeypatch = <_pytest.monkeypatch.monkeypatch object at 0x7fdb76a25b38>
test = ('fish a.sh', '/tmp/fix-error/a.sh', 2, None, '', "\\nfish: Unknown command 'foo'\\n/tmp/fix-error/a.sh (line 2): foo\\n ^\\n")
@pytest.mark.parametrize('test', tests)
@pytest.mark.usefixtures('no_memoize')
def test_get_new_command(monkeypatch, test):
> mocker.patch('os.path.isfile', return_value=True)
E NameError: name 'mocker' is not defined
/home/thefuck/tests/rules/test_fix_file.py:218: NameError
""", ''),
)


@pytest.mark.parametrize('test', tests)
@pytest.mark.usefixtures('no_memoize')
def test_match(mocker, monkeypatch, test):
mocker.patch('os.path.isfile', return_value=True)
monkeypatch.setenv('EDITOR', 'dummy_editor')
assert match(Command(stderr=test[4]), None)
assert match(Command(stdout=test[4], stderr=test[5]), None)


@pytest.mark.parametrize('test', tests)
@pytest.mark.usefixtures('no_memoize')
def test_no_editor(mocker, monkeypatch, test):
mocker.patch('os.path.isfile', return_value=True)
if 'EDITOR' in os.environ:
monkeypatch.delenv('EDITOR')

assert not match(Command(stderr=test[4]), None)
assert not match(Command(stdout=test[4], stderr=test[5]), None)


@pytest.mark.parametrize('test', tests)
@pytest.mark.usefixtures('no_memoize')
def test_not_file(mocker, monkeypatch, test):
mocker.patch('os.path.isfile', return_value=False)
monkeypatch.setenv('EDITOR', 'dummy_editor')

assert not match(Command(stderr=test[4]), None)
assert not match(Command(stdout=test[4], stderr=test[5]), None)


@pytest.mark.parametrize('test', tests)
def test_get_new_command(monkeypatch, test):
@pytest.mark.usefixtures('no_memoize')
def test_get_new_command(mocker, monkeypatch, test):
mocker.patch('os.path.isfile', return_value=True)
monkeypatch.setenv('EDITOR', 'dummy_editor')
assert (get_new_command(Command(script=test[0], stderr=test[4]), None) ==
'dummy_editor {} +{} && {}'.format(test[1], test[2], test[0]))

cmd = Command(script=test[0], stdout=test[4], stderr=test[5])
#assert (get_new_command(cmd, Settings({})) ==
# 'dummy_editor {} +{} && {}'.format(test[1], test[2], test[0]))


@pytest.mark.parametrize('test', tests)
@pytest.mark.usefixtures('no_memoize')
def test_get_new_command_with_settings(mocker, monkeypatch, test):
mocker.patch('os.path.isfile', return_value=True)
monkeypatch.setenv('EDITOR', 'dummy_editor')

cmd = Command(script=test[0], stdout=test[4], stderr=test[5])
settings = Settings({'fixcolcmd': '{editor} {file} +{line}:{col}'})

if test[3]:
assert (get_new_command(cmd, settings) ==
'dummy_editor {} +{}:{} && {}'.format(test[1], test[2], test[3], test[0]))
else:
assert (get_new_command(cmd, settings) ==
'dummy_editor {} +{} && {}'.format(test[1], test[2], test[0]))
1 change: 1 addition & 0 deletions tests/rules/test_git_branch_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from thefuck.rules.git_branch_list import match, get_new_command
from tests.utils import Command


def test_match():
assert match(Command('git branch list'), None)

Expand Down
2 changes: 1 addition & 1 deletion tests/rules/test_git_fix_stash.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
or: git stash ( pop | apply ) [--index] [-q|--quiet] [<stash>]
or: git stash branch <branchname> [<stash>]
or: git stash [save [--patch] [-k|--[no-]keep-index] [-q|--quiet]
[-u|--include-untracked] [-a|--all] [<message>]]
\t\t [-u|--include-untracked] [-a|--all] [<message>]]
or: git stash clear
'''

Expand Down
4 changes: 2 additions & 2 deletions tests/rules/test_git_not_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ def git_not_command_closest():
return '''git: 'tags' is not a git command. See 'git --help'.
Did you mean one of these?
stage
tag
\tstage
\ttag
'''


Expand Down
2 changes: 1 addition & 1 deletion tests/rules/test_go_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


@pytest.mark.parametrize('command', [
Command(script='go run foo'),
Command(script='go run foo'),
Command(script='go run bar')])
def test_match(command):
assert match(command, None)
Expand Down

0 comments on commit 3bf7267

Please sign in to comment.