Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix weird results when combining -script and -e #1455

Merged
merged 2 commits into from
Jun 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions mathics/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,25 +340,6 @@ def main() -> int:

definitions.set_line_no(0)

if args.execute:
for expr in args.execute:
evaluation = Evaluation(shell.definitions, output=TerminalOutput(shell))
result = evaluation.parse_evaluate(expr, timeout=settings.TIMEOUT)
shell.print_result(
result, no_out_prompt=True, strict_wl_output=args.strict_wl_output
)
if evaluation.exc_result == Symbol("Null"):
exit_rc = 0
elif evaluation.exc_result == Symbol("$Aborted"):
exit_rc = -1
elif evaluation.exc_result == Symbol("Overflow"):
exit_rc = -2
else:
exit_rc = -3

if not args.persist:
return exit_rc

if args.FILE is not None:
feeder = MathicsFileLineFeeder(args.FILE)
try:
Expand All @@ -377,7 +358,26 @@ def main() -> int:

if args.persist:
definitions.set_line_no(0)
else:
elif not args.execute:
return exit_rc

if args.execute:
for expr in args.execute:
evaluation = Evaluation(shell.definitions, output=TerminalOutput(shell))
result = evaluation.parse_evaluate(expr, timeout=settings.TIMEOUT)
shell.print_result(
result, no_out_prompt=True, strict_wl_output=args.strict_wl_output
)
if evaluation.exc_result == Symbol("Null"):
exit_rc = 0
elif evaluation.exc_result == Symbol("$Aborted"):
exit_rc = -1
elif evaluation.exc_result == Symbol("Overflow"):
exit_rc = -2
else:
exit_rc = -3

if not args.persist:
return exit_rc

if not args.quiet:
Expand Down
1 change: 1 addition & 0 deletions test/data/script.m
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Print["Hello"];
30 changes: 30 additions & 0 deletions test/test_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
import subprocess

import os.path as osp
import re
import pytest
import sys


def get_testdir():
filename = osp.normcase(osp.dirname(osp.abspath(__file__)))
return osp.realpath(filename)


@pytest.mark.skipif(sys.version_info < (3, 7), reason="requires Python 3.7 or higher")
def test_cli():
script_file = osp.join(get_testdir(), "data", "script.m")

# asserts output contains 'Hello' and '2'
assert re.match(
r"Hello\s+2",
subprocess.run(
["mathics", "-e", "Print[1+1];", "-script", script_file],
capture_output=True,
).stdout.decode("utf-8"),
)


if __name__ == "__main__":
test_cli()