From 12bb5cac36c5225d09bdd029147ea46eb1337133 Mon Sep 17 00:00:00 2001
From: "Meredith L. Patterson" <mlp@thesmartpolitenerd.com>
Date: Tue, 19 Nov 2013 17:26:01 -0600
Subject: [PATCH] more verbose tests; should run w/o hammer installed
 system-wide

---
 src/bindings/python/SConscript      | 12 +++++++-----
 src/bindings/python/hammer_tests.py | 30 +++++++++++++++++------------
 2 files changed, 25 insertions(+), 17 deletions(-)

diff --git a/src/bindings/python/SConscript b/src/bindings/python/SConscript
index 718f8b91..30d387c3 100644
--- a/src/bindings/python/SConscript
+++ b/src/bindings/python/SConscript
@@ -1,21 +1,23 @@
 # -*- python -*-
-Import('env')
+import os.path
+Import('env libhammer_shared')
 
 pythonenv = env.Clone(IMPLICIT_COMMAND_DEPENDENCIES = 0)
 
 pythonenv.Append(CPPPATH = ['../../', '/usr/include/python2.7'])
 pythonenv.Append(CCFLAGS = ['-fpic', '-DSWIG', '-Wno-all', '-Wno-extra', '-Wno-error'])
-pythonenv.Append(LIBS = ['hammer'])
-pythonenv.Append(LIBPATH = ['../../'])
+#pythonenv.Append(LIBS = ['hammer'])
+#pythonenv.Append(LIBPATH = ['../../'])
 pythonenv.Append(SWIGFLAGS = ['-DHAMMER_INTERNAL__NO_STDARG_H', '-Isrc/', '-python'])
 
 pythonenv.Command("hammer.i", "../swig/hammer.i", Copy("$TARGET", "$SOURCE"))
 
 swig = ['hammer.i']
 
-libhammer_python = pythonenv.SharedLibrary('hammer', swig, SHLIBPREFIX='_')
+libhammer_python = pythonenv.SharedLibrary('hammer', libhammer_shared + swig, SHLIBPREFIX='_')
 
 pytestenv = pythonenv.Clone()
-pytestenv.Command(None, 'hammer_tests.py', "nosetests -v $SOURCE")
+pytestenv['ENV']['LD_LIBRARY_PATH'] = os.path.dirname(str(libhammer_shared[0]))
+pytestenv.Command(None, ['hammer_tests.py', libhammer_python], "nosetests -vv $SOURCE")
 
 Clean('.', ['hammer.pyc', 'hammer_tests.py', 'hammer_tests.pyc']) 
diff --git a/src/bindings/python/hammer_tests.py b/src/bindings/python/hammer_tests.py
index c776520d..9d0c4875 100644
--- a/src/bindings/python/hammer_tests.py
+++ b/src/bindings/python/hammer_tests.py
@@ -477,18 +477,24 @@ class TestNot2(unittest.TestCase):
 # #    def test_failure(self):
 # #        pass
 
-# class TestRightrec(unittest.TestCase):
-#     @classmethod
-#     def setUpClass(cls):
-#         cls.parser = h.h_indirect()
-#         a = h.h_ch("a")
-#         h.h_bind_indirect(cls.parser, h.h_choice__a([h.h_sequence__a([a, cls.parser, None]), h.h_epsilon_p()]))
-#     def test_success(self):
-#         self.assertEqual([x.token_data.uint for x in h.h_parse(self.parser, "a", 1).ast.token_data.seq], [ord(y) for y in ["a"]])
-#         self.assertEqual([x.token_data.uint for x in h.h_parse(self.parser, "aa", 2).ast.token_data.seq], ["a", ["a"]])
-#         self.assertEqual([x.token_data.uint for x in h.h_parse(self.parser, "aaa", 3).ast.token_data.seq], ["a", ["a", ["a"]]])
-#     def test_failure(self):
-#         pass
+class TestARightrec(unittest.TestCase):
+    @classmethod
+    def setUpClass(cls):
+        cls.parser = h.h_indirect()
+        a = h.h_ch("a")
+        h.h_bind_indirect(cls.parser, h.h_choice__a([h.h_sequence__a([a, cls.parser, None]), h.h_epsilon_p(), None]))
+    def test_success(self):
+        tree = h.h_parse(self.parser, "a", 1).ast.token_data.seq
+        self.assertEqual(tree[0].token_data.uint, ord("a"))
+        tree = h_parse(self.parser, "aa", 2).ast.token_data.seq
+        self.assertEqual(tree[0].token_data.uint, ord("a"))
+        self.assertEqual(tree[1].token_data.seq[0].token_data.uint, ord("a"))
+        tree = h_parse(self.parser, "aaa", 3).ast.token_data.seq
+        self.assertEqual(tree[0].token_data.uint, ord("a"))
+        self.assertEqual(tree[1].token_data.seq[0].token_data.uint, ord("a"))
+        self.assertEqual(tree[1].token_data.seq[1].token_data.seq[0].uint, ord("a"))
+    def test_failure(self):
+        pass
 
 # ### this is just for GLR
 # #class TestAmbiguous(unittest.TestCase):
-- 
GitLab