-
Notifications
You must be signed in to change notification settings - Fork 0
/
CompatTests.m
executable file
·91 lines (77 loc) · 3.01 KB
/
CompatTests.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
systemFullName[] := Module[{systemName, versionName},
systemName = Which[
MatchQ[SystemInformation["Kernel", "LicenseID"], _String],
"Mathematica",
MemberQ[Attributes[ExpreduceFactorConstant], Protected],
"Expreduce"
];
versionName = StringTrim[ToString[$VersionNumber], "."];
systemName <> "_" <> versionName
];
Clear[TapSuite, TapComment, TapTestSame, TapTestSameBROKEN,
TapTestSameDISABLED];
SetAttributes[TapTestSame, HoldAllComplete];
SetAttributes[TapTestSameBROKEN, HoldAllComplete];
SetAttributes[TapTestSameDISABLED, HoldAllComplete];
TapComment[txt_] := {"Comment", txt};
lastOutputVar = Null;
TapTestSame[in_, out_, isDisabled_] :=
Module[{inExpr, outExpr, inStrEvaluated, outStrEvaluated, inStr,
outStr, result}, Clear[inExpr, outExpr, inStr, outStr, result];
result = False;
inStr = ToString[Unevaluated@InputForm[in]];
outStr = ToString[Unevaluated@InputForm[out]];
inExpr = ReleaseHold[in] /. % -> lastOutputVar;
outExpr = ReleaseHold[out];
lastOutputVar = outExpr;
inStrEvaluated = ToString[inExpr, OutputForm];
outStrEvaluated = ToString[outExpr, OutputForm];
result = inStrEvaluated === outStrEvaluated;
{"Test", inStr, outStr, inStrEvaluated, outStrEvaluated,
isDisabled, result}];
TapTestSame[in_, out_] := TapTestSame[in, out, False];
TapTestSameBROKEN[in_, out_] := TapTestSame[in, out, True];
TapTestSameDISABLED[in_, out_] := TapTestSame[in, out, True];
TapSuite[tests__] :=
UsingFrontEnd[TimeConstrained[Module[{outputTapStream, PrintTap, json, testName, runTestOrComment, failed, total, disabled,
testResults}, (
PrintTap[arg___]:= (
WriteString["stdout", arg];
);
PrintTap["# SYSTEM: ",systemFullName[], "\n"];
testName = FileBaseName[$InputFileName];
PrintTap["# TEST: ", testName, "\n"];
failed = 0;
total = 0;
disabled = 0;
runTestOrComment[a_] :=
Module[{type, comment, inStr, outStr, inExpr, outExpr,
isDisabled, result},
If[a[[1]] == "Comment", ({type, comment} = a;
PrintTap["# ", comment, "\n"];
{"Comment" -> comment}), (
{type, inStr, outStr, inExpr, outExpr, isDisabled, result} = a;
total++;
If[! isDisabled, (
If[! result, (
failed++;
)];
), disabled++
];
PrintTap[If[result||isDisabled, "ok ", "not ok "],
" ", inStr, " \[DoubleLongRightArrow] ", outStr];
If[!isDisabled, PrintTap[
"\n ---\n",
" data:\n",
" got: ",inExpr,"\n",
" expect: ",outStr,"\n",
" expect_evaluated: ",outExpr,"\n",
" ...\n"
], PrintTap[" # skip\n"]];
{"Test" -> {inStr, outStr, ToString[inExpr],
ToString[outExpr], isDisabled, result}})]];
Scan[runTestOrComment, {tests}];
json = {(* "Tests" -> testResults, *)
"Stats" -> {"Total" -> total, "Failed" -> failed,
"Disabled" -> disabled}};
)], 60]];