Skip to content

Commit

Permalink
Fix mathics -f FILE arg
Browse files Browse the repository at this point in the history
  • Loading branch information
rocky committed Feb 18, 2021
1 parent 70bd781 commit f1dbfbe
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 2 deletions.
2 changes: 1 addition & 1 deletion MANIFEST.in
Expand Up @@ -7,4 +7,4 @@ include Makefile
include mathics/Makefile
include mathics/Makefile
recursive-include mathics *.py
recursive-include test *.py
recursive-include test *.py *.m
2 changes: 1 addition & 1 deletion mathics/main.py
Expand Up @@ -323,7 +323,7 @@ def main() -> int:
return exit_rc

if args.FILE is not None:
feeder = FileLineFeeder(args.FILE)
feeder = MathicsFileLineFeeder(args.FILE)
try:
while not feeder.empty():
evaluation = Evaluation(
Expand Down
40 changes: 40 additions & 0 deletions test/data/recursive-gcd.m
@@ -0,0 +1,40 @@
(* Self-contained test for testing mathicscript <file>
Recursive GCD from https://mathematica.stackexchange.com/questions/156990/gcd-using-euclidean-algorithm
Test harness is the same used in Gries Schnieder testing.
*)

ClearAll[expect, totalRight, totalWrong, totalTests];
SetAttributes[ expect, HoldAllComplete ];
totalRight = totalWrong = totalTests = 0;
expect[expected_, actual_] := (* <~~~ Here's the API *)
Module[{evalActualOnce = actual,
evalExpectedOnce = expected},
totalTests += 1;
Print[ {"Test[" <> ToString[totalTests] <> "]:=\n",
HoldForm[actual],
"\nexpected", HoldForm[expected],
"\neval'd expected", evalExpectedOnce,
"\neval'd actual ", evalActualOnce,
"\nright?", evalExpectedOnce === evalActualOnce} ];
Print[ "" ]; (* newline *)
If[ evalExpectedOnce === evalActualOnce,
totalRight += 1,
totalWrong += 1 ];
{"total right", totalRight, "total wrong", totalWrong}
];

RecursiveGCD[a_, 0] := a;
RecursiveGCD[a_, b_] := RecursiveGCD[b, Mod[a, b]];

expect[6, RecursiveGCD[24, 18]]
expect[1, RecursiveGCD[3, 5]]

x = RandomInteger[{-100, 100}]
expect[x, RecursiveGCD[x, 0]]
expect[x, RecursiveGCD[2 x, x]]
expect[x, RecursiveGCD[x 2, x]]
(** uncomment to see a failure **)
(*** expect[3 x, RecursiveGCD[x 2, x]] ***)
Print["Total right: ", totalRight, ". Total wrong: ", totalWrong, ". Total tests: ", totalTests]
If[ Or[totalTests <= 0, totalTests != totalRight], Quit[1], Quit[0]]
18 changes: 18 additions & 0 deletions test/test_returncode.py
@@ -0,0 +1,18 @@
import subprocess

import os.path as osp

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

def test_returncode():
assert subprocess.run(["mathics", "-e", "Quit[5]"]).returncode == 5
assert subprocess.run(["mathics", "-e", "1 + 2'"]).returncode == 0
assert subprocess.run(["mathics", "-e", "Quit[0]"]).returncode == 0

gcd_file = osp.join(get_testdir(), "data", "recursive-gcd.m")
assert subprocess.run(["mathics", "-f", gcd_file]).returncode == 0

if __name__ == "__main__":
test_returncode()

0 comments on commit f1dbfbe

Please sign in to comment.