Commits

ebo  committed 110be59

Implement the --seed option; add friendlier output

Example output:

Using random seed 2107150189
Iteration 1: PASS
Iteration 2: PASS
All tests successful!

Patch by Collin Winter

  • Participants
  • Parent commits 8641f96

Comments (0)

Files changed (1)

File pygen-example.py

         return
 
     rng = random.Random()
+    seed = options.seed
+    if seed is None:
+        seed = int(rng.random() * sys.maxint)
+    print "Using random seed", seed
+    rng.seed(seed)
     
     pgen = ProgGenerator(pgen_opts, rng)
     
     totaltime = 0.0
     time_test = 0.0
     time_base = 0.0
+    failed_a_test = False
     
     for i in xrange(options.iterations):
         
+        failed_this_test = False
         clock = time.time()
         mod = pgen.generate()
         fixed = fix.generate(mod)
             print "------- Encountered crash: Test -------"
             print code
             print "---------------------------------------"
+            failed_this_test = True
             if options.break_on_error:
                 return
 
             print "------- Encountered crash: Base -------"
             print code
             print "---------------------------------------"
+            failed_this_test = True
             if options.break_on_error:
                 return
 
             print "---------------------------------------"
             print code
             print "---------------------------------------"
+            failed_this_test = True
             if options.break_on_error:
                 return
 
 #        if clock > 10.0:
 #            print code
         
+        failed_a_test |= failed_this_test
+        if not failed_this_test:
+            print "Iteration %s: PASS" % (i + 1,)
         if (i+1) % 10 == 0:
             print "%f Functions per Second" % (i/totaltime,)
             print "Test: %f calls/sec | Base: %f calls/sec" % (i/time_test, i/time_base)
-            
-        
-        
-        
+
+    if failed_a_test:
+        print "Some tests failed; consult diagnostic output above."
+    else:
+        print "All tests successful!"
+
+
 
 if __name__ == '__main__':
     _main()