-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentryTestRunner.nim
155 lines (107 loc) · 3.73 KB
/
entryTestRunner.nim
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import std/strformat
import std/parseutils
#import system/io
import strutils
import tables
import nar
import term
# runner for automated tests
var derivedConcls: seq[SentenceObj] = @[]
proc derivedConclCallback(s: SentenceObj) =
echo(&"|-{convSentenceToStr(s)}")
derivedConcls.add(s)
var invokedOpTerms: seq[TermObj] = @[]
proc invokeOpCallback(opTerm: TermObj) =
invokedOpTerms.add(opTerm)
# reads a narsese file and runs it as a automated test
# immediatly returns false when a automated check failed
proc readNarseseAndRunTest(path: string): bool =
panicDbgModel = true # panicDbg() causes program to exit with error!
derivedConcls = @[]
invokedOpTerms = @[]
narInit()
globalNarInstance.conclCallback = derivedConclCallback
globalNarInstance.invokeOpCallback = invokeOpCallback
# op for testing
proc op0(args: seq[TermObj]) =
echo("main: ^op0 was invoked")
globalNarInstance.opRegistry.ops["^op0"] = op0
globalNarInstance.opRegistry.ops["^n9ExecAndInj"] = opLibNal9ExecAndInj # NAL-9
let fileContent: string = readFile(path)
for iLine in split(fileContent, '\n'):
if iLine.startsWith("//expectDeriv "):
let expectedNarsese: string = iLine[14..iLine.len-1]
# check in derived messages if it exists
var found = false
for iKnownConclusion in derivedConcls:
let iKnownConclusionStr: string = convSentenceToStr(iKnownConclusion)
if iKnownConclusionStr == expectedNarsese:
found = true
break
if found:
continue
# we are here when it doesn't exist!
echo(iLine)
echo("FAIL: didn't find expected conclusion! EXIT")
quit(1)
if iLine.startsWith("//expectExeced "):
let expectedNarsese: string = iLine[15..iLine.len-1]
# check in derived messages if it exists
var found = false
for iKnownConclusion in invokedOpTerms:
let iKnownConclusionStr: string = convTermToStr(iKnownConclusion)
if iKnownConclusionStr == expectedNarsese:
found = true
break
if found:
continue
# we are here when it doesn't exist!
echo(iLine)
echo("FAIL: didn't find expected op execution! EXIT")
quit(1)
if iLine.startsWith("//"):
continue # ignore comments
if iLine == "":
continue # ignore empty lines
# parse command
if false:
discard
elif iLine == "!sm": # show memory
proceduralShowAllBeliefs("mem")
#proceduralShowAllBeliefs(goalMem, "goalMem")
continue
elif iLine == "!sp": # step procedural
proceduralStep()
proceduralAdvanceTime(1) # advance time implicitly
else:
block:
var steps: int
let parsedChars = parseInt(iLine, steps)
if parsedChars != 0:
# do inference steps
if steps > 0:
for iStep in 0..steps-1:
ctrlStep()
ctrlQaStep()
continue
# fallback to parsing narsese
parseNarInputAndPut(iLine)
return true
var testFiles: seq[string] = @[]
##testFiles.add("./nalTest/opCall0.narsese")
#testFiles.add("./nalTest/procDeriv1.narsese")
#testFiles.add("./nalTest/procDeriv0.narsese")
#testFiles.add("./nalTest/opCallNal9.narsese")
#testFiles.add("./nalTest/procDeriv2multi.narsese")
#testFiles.add("./nalTest/procDeriv3multiComplicated.nal")
#testFiles.add("./nalTest/procDeriv4img.nal")
#testFiles.add("./nalTest/procDeriv5RftNlu.nal")
#testFiles.add("./nalTest/nal2a.narsese")
testFiles.add("./nalTest/nal6a.narsese")
# call readNarseseAndRunTest for all test-files
for iPath in testFiles:
if not readNarseseAndRunTest(iPath):
quit(1)
echo("FIN: all done!")
quit(0)
# TODO< implement check for //expectExeced <({SELF}*dummy0) --> ^op0> >