changeset 353:31ce799dec84

test_runtime_sugar: got coverage to 100%
author Sigurd Meldgaard <stm@daimi.au.dk>
date Tue, 20 Jul 2010 14:54:28 +0200
parents f13ddb44761f
children 4f48ec3417bb
files pysmcl/test/unit/test_sugar.py
diffstat 1 files changed, 35 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/pysmcl/test/unit/test_sugar.py	Tue Jul 20 14:53:36 2010 +0200
+++ b/pysmcl/test/unit/test_sugar.py	Tue Jul 20 14:54:28 2010 +0200
@@ -3,6 +3,8 @@
 from pysmcl.pretty_print import pprint_string
 from pysmcl.runtime_sugar import runtime_sugar
 
+from pysmcl.secret_annotator import secret_analysis
+
 
 class Test(unittest.TestCase):
 
@@ -11,6 +13,7 @@
 def f():
     a = input(3)
     b = get("Nr:")
+    my_id = id
     c = output(a + b[0])
     print c
     return a
@@ -20,6 +23,7 @@
     if(1):
         a = input(runtime, 3)
         b = get("Nr:")
+        my_id = runtime.id
         c = yield(runtime.output(a + b[0]))
         print c
         returnValue(a)
@@ -29,6 +33,37 @@
 
         self.do_analysis(program, expected)
 
+    def test2(self):
+        program = """\
+def f(x):
+    return x
+
+def g():
+    return f(input("nr", 3))
+"""
+        expected = """\
+def f(runtime, x):
+    if(1):
+        returnValue(x)
+    else:
+        yield(0)
+
+def g(runtime):
+    if(1):
+        returnValue(yield(f(runtime, input(runtime, "nr", 3))))
+    else:
+        yield(0)
+"""
+
+        parsed = parse(program)
+        f = parsed.body[0]
+        g = parsed.body[1]
+        secret_analysis(f)
+        runtime_sugar(f)
+        runtime_sugar(g)
+        result = pprint_string(f) + "\n" + pprint_string(g)
+        self.assertEquals(expected, result)
+
     def do_analysis(self, program, expected):
         parsed = parse(program)
         f = parsed.body[0]