Allow logical operators within aliases

This fixes #3270 and logical operators within aliases now resolve correctly.

I've added in `&&`, `||`, `and`, and `or`

```
(base)   ~/githu/xonsh/xonsh logical_op_aliases $ aliases['echocat'] = 'echo "hi" and echo "there"'
(base)   ~/githu/xonsh/xonsh logical_op_aliases $ echocat
hi
there
(base)   ~/githu/xonsh/xonsh logical_op_aliases $ aliases['echocat'] = 'echo "hi" or echo "there"'
(base)   ~/githu/xonsh/xonsh logical_op_aliases $ echocat
hi
(base)   ~/githu/xonsh/xonsh logical_op_aliases $ aliases['echocat'] = 'echo "hi" && echo "there"'
(base)   ~/githu/xonsh/xonsh logical_op_aliases $ echocat
hi
there
(base)   ~/githu/xonsh/xonsh logical_op_aliases $ aliases['echocat'] = 'echo "hi" || echo "there"'
(base)   ~/githu/xonsh/xonsh logical_op_aliases $ echocat
hi
```
This commit is contained in:
Gil Forsyth 2019-08-16 15:17:31 -04:00
parent 59a042010f
commit e4fada56b0
3 changed files with 45 additions and 2 deletions

View file

@ -0,0 +1,28 @@
**Added:**
* <news item>
**Changed:**
* <news item>
**Deprecated:**
* <news item>
**Removed:**
* <news item>
**Fixed:**
* Logical operators in aliases are now executed as expected, e.g.
``aliases['echocat'] = 'echo "hi" and echo "there"'`` will, when run, return
.. code-block::
hi
there
**Security:**
* <news item>

View file

@ -7,7 +7,7 @@ import os
import pytest
import xonsh.built_ins as built_ins
from xonsh.aliases import Aliases
from xonsh.aliases import Aliases, ExecAlias
from xonsh.environ import Env
from tools import skip_if_on_windows
@ -113,3 +113,18 @@ def test_recursive_callable_partial_none(xonsh_execer, xonsh_builtins):
args, obs = alias()
assert args == "wakka"
assert len(obs) == 0
@pytest.mark.parametrize(
"alias",
[
"echo 'hi' and echo 'there'",
"echo 'hi' or echo 'there'",
"echo 'hi' && echo 'there'",
"echo 'hi' || echo 'there'",
"echo 'hi'; echo 'there'",
],
)
def test_subprocess_logical_operators(xonsh_execer, xonsh_builtins, alias):
ales = make_aliases()
ales["echocat"] = alias
assert isinstance(ales["echocat"], ExecAlias)

View file

@ -44,7 +44,7 @@ import xonsh.xoreutils.which as xxw
@lazyobject
def SUB_EXEC_ALIAS_RE():
return re.compile(r"@\(|\$\(|!\(|\$\[|!\[")
return re.compile(r"@\(|\$\(|!\(|\$\[|!\[|\&\&|\|\||and|or")
class Aliases(cabc.MutableMapping):