Skip to content

Commit ad80dc7

Browse files
authored
Merge pull request #1158 from mathics/file-arg-fix
Fix mathics -f FILE arg
2 parents 70bd781 + f1dbfbe commit ad80dc7

4 files changed

Lines changed: 60 additions & 2 deletions

File tree

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ include Makefile
77
include mathics/Makefile
88
include mathics/Makefile
99
recursive-include mathics *.py
10-
recursive-include test *.py
10+
recursive-include test *.py *.m

mathics/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ def main() -> int:
323323
return exit_rc
324324

325325
if args.FILE is not None:
326-
feeder = FileLineFeeder(args.FILE)
326+
feeder = MathicsFileLineFeeder(args.FILE)
327327
try:
328328
while not feeder.empty():
329329
evaluation = Evaluation(

test/data/recursive-gcd.m

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
(* Self-contained test for testing mathicscript <file>
2+
3+
Recursive GCD from https://mathematica.stackexchange.com/questions/156990/gcd-using-euclidean-algorithm
4+
Test harness is the same used in Gries Schnieder testing.
5+
*)
6+
7+
ClearAll[expect, totalRight, totalWrong, totalTests];
8+
SetAttributes[ expect, HoldAllComplete ];
9+
totalRight = totalWrong = totalTests = 0;
10+
expect[expected_, actual_] := (* <~~~ Here's the API *)
11+
Module[{evalActualOnce = actual,
12+
evalExpectedOnce = expected},
13+
totalTests += 1;
14+
Print[ {"Test[" <> ToString[totalTests] <> "]:=\n",
15+
HoldForm[actual],
16+
"\nexpected", HoldForm[expected],
17+
"\neval'd expected", evalExpectedOnce,
18+
"\neval'd actual ", evalActualOnce,
19+
"\nright?", evalExpectedOnce === evalActualOnce} ];
20+
Print[ "" ]; (* newline *)
21+
If[ evalExpectedOnce === evalActualOnce,
22+
totalRight += 1,
23+
totalWrong += 1 ];
24+
{"total right", totalRight, "total wrong", totalWrong}
25+
];
26+
27+
RecursiveGCD[a_, 0] := a;
28+
RecursiveGCD[a_, b_] := RecursiveGCD[b, Mod[a, b]];
29+
30+
expect[6, RecursiveGCD[24, 18]]
31+
expect[1, RecursiveGCD[3, 5]]
32+
33+
x = RandomInteger[{-100, 100}]
34+
expect[x, RecursiveGCD[x, 0]]
35+
expect[x, RecursiveGCD[2 x, x]]
36+
expect[x, RecursiveGCD[x 2, x]]
37+
(** uncomment to see a failure **)
38+
(*** expect[3 x, RecursiveGCD[x 2, x]] ***)
39+
Print["Total right: ", totalRight, ". Total wrong: ", totalWrong, ". Total tests: ", totalTests]
40+
If[ Or[totalTests <= 0, totalTests != totalRight], Quit[1], Quit[0]]

test/test_returncode.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import subprocess
2+
3+
import os.path as osp
4+
5+
def get_testdir():
6+
filename = osp.normcase(osp.dirname(osp.abspath(__file__)))
7+
return osp.realpath(filename)
8+
9+
def test_returncode():
10+
assert subprocess.run(["mathics", "-e", "Quit[5]"]).returncode == 5
11+
assert subprocess.run(["mathics", "-e", "1 + 2'"]).returncode == 0
12+
assert subprocess.run(["mathics", "-e", "Quit[0]"]).returncode == 0
13+
14+
gcd_file = osp.join(get_testdir(), "data", "recursive-gcd.m")
15+
assert subprocess.run(["mathics", "-f", gcd_file]).returncode == 0
16+
17+
if __name__ == "__main__":
18+
test_returncode()

0 commit comments

Comments
 (0)