--- /dev/null
+from path import path
+from cStringIO import StringIO
+
+import sys
+sys.path.append('src/Dyna/Backend/Python')
+
+from dyna_doctest import run
+from utils import red, green
+
+failures = []
+for x in path('test/repl').glob("*.dynadoc"):
+ print x,
+ with file(x) as f:
+ g = StringIO()
+ if run(f.read(), g):
+ failures.append([x, g.getvalue()])
+ print red % 'fail'
+ else:
+ print green % 'pass'
+
+for f, log in failures:
+ print
+ print '================================================'
+ print f
+ print '================================================'
+ print log
+
+if failures:
+ exit(1)
[ "simple", "equalities", "fib-limit", "dijkstra", "papa2", "matrixops"
, "factorial-bc", "geom", "lists", "dijkstra-backpointers" ]
-test_REPL :: [Test]
-test_REPL = map (\n -> testProgramRuns n ("./test/repl/"++n) [])
- [ "aggregator-conflict"
- , "retract-rule"
- , "late-aggregator-assignment" ]
+--test_REPL :: [Test]
+--test_REPL = map (\n -> testProgramRuns n ("./test/repl/"++n) [])
+-- [ "aggregator-conflict"
+-- , "retract-rule"
+-- , "late-aggregator-assignment" ]
------------------------------------------------------------------------}}}
-- Harness toplevel {{{
return re.compile('(\s*)$', re.MULTILINE).sub('', re.sub('\033\[\d+m', '', strip_comments(x)).strip())
-def run(code):
+def run(code, out=None):
+
+ if out is None:
+ out = sys.stdout
+
interp = Interpreter()
repl = REPL(interp)
errors = 0
for cmd, expect in extract(code):
if not clean(cmd):
- print
+ print >> out
continue
- print yellow % '> %s' % cmd
+ print >> out, yellow % '> %s' % cmd
if clean(cmd) == '*resume*':
repl.cmdloop()
continue
if expect != got:
- print green % expect
- print red % got
+ print >> out, green % expect
+ print >> out, red % got
errors += 1
else:
- print
- print got
+ print >> out
+ print >> out, got
- print
+ print >> out
if not errors:
- print green % 'PASS!'
- print
+ print >> out, green % 'PASS!'
+ return 0
else:
- print yellow % '>>>', red % '%s errors' % errors
- print
- sys.exit(1)
+ print >> out, yellow % '>>>', red % '%s errors' % errors
+ return 1
if __name__ == '__main__':
> query sentence_length(10)
sentence_length(10) = 9.
-
-> *resume*
> sol
Solution empty.
-
-> :- backchain g/2.
-| g(X,Y) dict= X*Y.
-| h(1,2). h(2,3).
-| f(X,Y) = h(X,Y), g(X,Y).
-
-> query g(1,2)
-> rules
-> retract_rule 6
\ No newline at end of file