2015-11-16 14:04:32 -08:00
|
|
|
# -*- coding: utf-8 -*-
|
2015-02-03 02:02:57 -06:00
|
|
|
"""Tests the xonsh lexer."""
|
|
|
|
import os
|
|
|
|
|
2016-07-01 15:43:16 +03:00
|
|
|
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
|
|
|
|
2016-07-01 15:43:16 +03:00
|
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
2016-07-01 21:52:37 +03:00
|
|
|
def xonsh_execer_autouse(xonsh_builtins, xonsh_execer):
|
2016-07-01 15:43:16 +03:00
|
|
|
return xonsh_execer
|
|
|
|
|
2015-02-03 02:02:57 -06:00
|
|
|
|
2016-07-01 15:43:16 +03:00
|
|
|
@skip_if_on_unix
|
2016-06-05 16:25:43 -04:00
|
|
|
def test_win_ipconfig():
|
2016-07-01 15:43:16 +03:00
|
|
|
assert check_eval(os.environ['SYSTEMROOT'] + '\\System32\\ipconfig.exe /all')
|
2015-03-01 19:13:09 -06:00
|
|
|
|
2016-07-01 15:43:16 +03:00
|
|
|
@skip_if_on_unix
|
2016-06-05 16:25:43 -04:00
|
|
|
def test_ipconfig():
|
2016-07-01 15:43:16 +03:00
|
|
|
assert check_eval('ipconfig /all')
|
2015-02-11 02:01:35 -06:00
|
|
|
|
2016-07-01 15:43:16 +03:00
|
|
|
@skip_if_on_windows
|
2016-06-05 16:25:43 -04:00
|
|
|
def test_bin_ls():
|
2016-07-01 15:43:16 +03:00
|
|
|
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():
|
2016-07-01 15:43:16 +03:00
|
|
|
assert check_parse('ls -l')
|
2015-05-09 01:58:51 -04:00
|
|
|
|
2016-04-09 00:25:53 -04:00
|
|
|
def test_which_ls():
|
2016-07-01 15:43:16 +03:00
|
|
|
assert check_parse('which ls')
|
2015-05-09 01:58:51 -04:00
|
|
|
|
2016-04-09 00:25:53 -04:00
|
|
|
def test_echo_hello():
|
2016-07-01 15:43:16 +03:00
|
|
|
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")
|
2016-07-01 15:43:16 +03:00
|
|
|
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')
|
2016-07-01 15:43:16 +03:00
|
|
|
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')
|
2016-07-01 15:43:16 +03:00
|
|
|
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")
|
2016-07-01 15:43:16 +03:00
|
|
|
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
|
|
|
|
2016-05-19 20:12:07 -04:00
|
|
|
def test_good_rhs_subproc():
|
2017-06-07 11:51:17 -04:00
|
|
|
# nonsense but parsable
|
2016-05-19 20:12:07 -04:00
|
|
|
code = 'str().split() | ![grep exit]\n'
|
2016-07-01 15:43:16 +03:00
|
|
|
assert(code)
|
2016-05-19 20:12:07 -04:00
|
|
|
|
|
|
|
def test_bad_rhs_subproc():
|
2017-06-07 11:51:17 -04:00
|
|
|
# nonsense but unparsable
|
2016-05-19 20:12:07 -04:00
|
|
|
code = 'str().split() | grep exit\n'
|
2016-06-22 17:32:02 -04:00
|
|
|
with pytest.raises(SyntaxError):
|
|
|
|
check_parse(code)
|
2016-05-19 20:12:07 -04:00
|
|
|
|
2015-08-05 12:05:13 +03:00
|
|
|
def test_indent_with_empty_line():
|
|
|
|
code = ('if True:\n'
|
|
|
|
'\n'
|
|
|
|
' some_command for_sub_process_mode\n')
|
2016-07-01 15:43:16 +03:00
|
|
|
assert check_parse(code)
|
2015-08-05 12:05:13 +03:00
|
|
|
|
2016-02-21 14:37:03 -05:00
|
|
|
def test_command_in_func():
|
|
|
|
code = ('def f():\n'
|
|
|
|
' echo hello\n')
|
2016-07-01 15:43:16 +03:00
|
|
|
assert check_parse(code)
|
2016-02-21 14:37:03 -05:00
|
|
|
|
|
|
|
def test_command_in_func_with_comment():
|
|
|
|
code = ('def f():\n'
|
|
|
|
' echo hello # comment\n')
|
2016-07-01 15:43:16 +03:00
|
|
|
assert check_parse(code)
|
2016-02-21 14:37:03 -05:00
|
|
|
|
2016-05-19 18:52:50 -04:00
|
|
|
def test_pyeval_redirect():
|
|
|
|
code = 'echo @("foo") > bar\n'
|
2016-07-01 15:43:16 +03:00
|
|
|
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'
|
2016-07-01 15:43:16 +03:00
|
|
|
assert check_parse(code)
|
2016-05-24 23:55:07 -04:00
|
|
|
|
|
|
|
def test_echo_comma_val():
|
|
|
|
code = 'echo ,1\n'
|
2016-07-01 15:43:16 +03:00
|
|
|
assert check_parse(code)
|
2016-05-24 23:55:07 -04:00
|
|
|
|
|
|
|
def test_echo_comma_2val():
|
|
|
|
code = 'echo 1,2\n'
|
2016-07-01 15:43:16 +03:00
|
|
|
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)
|