changeset 644:d8913b7869b5

Add --keep option to run-example
author Bryan O'Sullivan <bos@serpentine.com>
date Thu, 29 Jan 2009 22:11:10 -0800
parents f5ab40759789
children 4cf5c332a9c1
files en/examples/run-example
diffstat 1 files changed, 14 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/en/examples/run-example	Thu Jan 29 22:10:57 2009 -0800
+++ b/en/examples/run-example	Thu Jan 29 22:11:10 2009 -0800
@@ -61,9 +61,10 @@
     
     timeout = 10
 
-    def __init__(self, name, verbose):
+    def __init__(self, name, verbose, keep_change):
         self.name = name
         self.verbose = verbose
+        self.keep_change = keep_change
         self.poll = select.poll()
 
     def parse(self):
@@ -320,7 +321,11 @@
             return False
         else:
             print >> sys.stderr, '\nOutput of %s has changed!' % base
-            os.system('diff -u %s %s 1>&2' % (oldname, errname))
+            if self.keep_change:
+                os.rename(errname, oldname)
+                return False
+            else:
+                os.system('diff -u %s %s 1>&2' % (oldname, errname))
             return True
 
 def print_help(exit, msg=None):
@@ -330,19 +335,23 @@
     print >> sys.stderr, 'Options:'
     print >> sys.stderr, '  -a --all       run all tests in this directory'
     print >> sys.stderr, '  -h --help      print this help message'
+    print >> sys.stderr, '     --help      keep new output as desired output'
     print >> sys.stderr, '  -v --verbose   display extra debug output'
     sys.exit(exit)
 
 def main(path='.'):
     opts, args = getopt.getopt(sys.argv[1:], '?ahv',
-                               ['all', 'help', 'verbose'])
+                               ['all', 'help', 'keep', 'verbose'])
     verbose = False
     run_all = False
+    keep_change = False
     for o, a in opts:
         if o in ('-h', '-?', '--help'):
             print_help(0)
         if o in ('-a', '--all'):
             run_all = True
+        if o in ('--keep',):
+            keep_change = True
         if o in ('-v', '--verbose'):
             verbose = True
     errs = 0
@@ -355,7 +364,7 @@
                 errs += 1
                 continue
             if stat.S_ISREG(st.st_mode) and st.st_mode & 0111:
-                if example(a, verbose).run():
+                if example(a, verbose, keep_change).run():
                     errs += 1
             else:
                 print >> sys.stderr, '%s: not a file, or not executable' % a
@@ -376,7 +385,7 @@
                     raise
                 continue
             if stat.S_ISREG(st.st_mode) and st.st_mode & 0111:
-                if example(pathname, verbose).run():
+                if example(pathname, verbose, keep_change).run():
                     errs += 1
         print >> open(os.path.join(path, '.run'), 'w'), time.asctime()
     else: