xonsh/tests/test_execer.py

117 lines
2.6 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
2015-02-03 02:02:57 -06:00
"""Tests the xonsh lexer."""
import os
from tools import (check_eval, check_parse,
skip_if_on_unix, skip_if_on_windows)
2016-06-22 17:32:02 -04:00
import pytest
2015-02-11 02:01:35 -06:00
@pytest.fixture(autouse=True)
def xonsh_execer_autouse(xonsh_builtins, xonsh_execer):
return xonsh_execer
2015-02-03 02:02:57 -06:00
@skip_if_on_unix
2016-06-05 16:25:43 -04:00
def test_win_ipconfig():
assert check_eval(os.environ['SYSTEMROOT'] + '\\System32\\ipconfig.exe /all')
2015-03-01 19:13:09 -06:00
@skip_if_on_unix
2016-06-05 16:25:43 -04:00
def test_ipconfig():
assert check_eval('ipconfig /all')
2015-02-11 02:01:35 -06:00
@skip_if_on_windows
2016-06-05 16:25:43 -04:00
def test_bin_ls():
assert check_eval('/bin/ls -l')
2015-02-11 02:01:35 -06:00
2016-04-09 00:25:53 -04:00
def test_ls_dashl():
assert check_parse('ls -l')
2016-04-09 00:25:53 -04:00
def test_which_ls():
assert check_parse('which ls')
2016-04-09 00:25:53 -04:00
def test_echo_hello():
assert check_parse('echo hello')
2015-07-29 23:58:25 +02:00
2017-11-09 20:20:40 -05:00
def test_echo_star_with_semi():
assert check_parse('echo * spam ; ![echo eggs]\n')
2015-03-10 21:38:11 -05:00
def test_simple_func():
code = ('def prompt():\n'
" return '{user}'.format(user='me')\n")
assert check_parse(code)
2015-03-10 21:38:11 -05:00
2016-06-11 21:02:28 -04:00
def test_lookup_alias():
code = (
'def foo(a, s=None):\n'
' return "bar"\n'
'@(foo)\n')
assert check_parse(code)
2016-06-11 21:02:28 -04:00
def test_lookup_anon_alias():
code = ('echo "hi" | @(lambda a, s=None: a[0]) foo bar baz\n')
assert check_parse(code)
2016-06-11 21:02:28 -04:00
2015-03-10 21:38:11 -05:00
def test_simple_func_broken():
code = ('def prompt():\n'
" return '{user}'.format(\n"
" user='me')\n")
assert check_parse(code)
2015-03-10 21:38:11 -05:00
2015-08-02 17:34:13 -05:00
def test_bad_indent():
code = ('if True:\n'
'x = 1\n')
2016-06-22 17:32:02 -04:00
with pytest.raises(SyntaxError):
check_parse(code)
2015-03-10 21:38:11 -05:00
def test_good_rhs_subproc():
# nonsense but parsable
code = 'str().split() | ![grep exit]\n'
assert(code)
def test_bad_rhs_subproc():
# nonsense but unparsable
code = 'str().split() | grep exit\n'
2016-06-22 17:32:02 -04:00
with pytest.raises(SyntaxError):
check_parse(code)
def test_indent_with_empty_line():
code = ('if True:\n'
'\n'
' some_command for_sub_process_mode\n')
assert check_parse(code)
def test_command_in_func():
code = ('def f():\n'
' echo hello\n')
assert check_parse(code)
def test_command_in_func_with_comment():
code = ('def f():\n'
' echo hello # comment\n')
assert check_parse(code)
2016-05-19 18:52:50 -04:00
def test_pyeval_redirect():
code = 'echo @("foo") > bar\n'
assert check_parse(code)
2016-05-19 18:52:50 -04:00
2016-05-24 23:55:07 -04:00
def test_echo_comma():
code = 'echo ,\n'
assert check_parse(code)
2016-05-24 23:55:07 -04:00
def test_echo_comma_val():
code = 'echo ,1\n'
assert check_parse(code)
2016-05-24 23:55:07 -04:00
def test_echo_comma_2val():
code = 'echo 1,2\n'
assert check_parse(code)
2017-02-15 00:58:38 -05:00
def test_echo_line_cont():
code = 'echo "1 \\\n2"\n'
assert check_parse(code)