]> hydra-www.ietfng.org Git - dyna2/commitdiff
use doctests
authorTim Vieira <tim.f.vieira@gmail.com>
Fri, 5 Jul 2013 23:25:59 +0000 (19:25 -0400)
committerTim Vieira <tim.f.vieira@gmail.com>
Fri, 5 Jul 2013 23:25:59 +0000 (19:25 -0400)
run-doctests.py [new file with mode: 0644]
src/Dyna/Backend/Python/Selftest.hs
src/Dyna/Backend/Python/dyna_doctest.py [moved from src/Dyna/Backend/Python/dyna-doctest.py with 78% similarity, mode: 0644]
test/repl/colon-equals.dynadoc [moved from test/repl/colon-equals.doctest with 100% similarity]
test/repl/equals-errors.dynadoc [moved from test/repl/equals-errors.doctest with 100% similarity]
test/repl/load.dynadoc
test/repl/retract-bc.dynadoc
test/repl/retract-rule.dynadoc [moved from test/repl/retract-rule.doctest with 100% similarity]

diff --git a/run-doctests.py b/run-doctests.py
new file mode 100644 (file)
index 0000000..8eb36a3
--- /dev/null
@@ -0,0 +1,29 @@
+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)
index 652750c1dd27ae033f1ff47ffd46a97c8ab99238..67a3dc3882306454ef8da693ce6aeab973159a62 100644 (file)
@@ -80,11 +80,11 @@ test_End_To_End = map mkExample
   [ "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                                                     {{{
old mode 100755 (executable)
new mode 100644 (file)
similarity index 78%
rename from src/Dyna/Backend/Python/dyna-doctest.py
rename to src/Dyna/Backend/Python/dyna_doctest.py
index 6522705..d3cd5ad
@@ -33,17 +33,21 @@ def clean(x):
     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()
@@ -62,22 +66,21 @@ def run(code):
             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__':
index 1036591276fca0391de350c879148c2b936ae9c1..aa00c51281c2e314cc89bbf3e096952cd9a55803 100644 (file)
@@ -59,5 +59,3 @@ tree(0) = ['ROOT', ['S', ['NP', 'George'], ['VP', ['V', ['V', 'love'], '-s'], ['
 > query sentence_length(10)
 
 sentence_length(10) = 9.
-
-> *resume*
index f6ba303fd597a1d224c69c8a00255731ca64dea7..0055bc63c4be0dc134b4e8a982acf821a1e7989f 100644 (file)
@@ -38,12 +38,3 @@ f(5) = null.
 > 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