hgbook
changeset 545:d8913b7869b5
Add --keep option to run-example
author | Bryan O'Sullivan <bos@serpentine.com> |
---|---|
date | Thu Jan 29 22:11:10 2009 -0800 (2009-01-29) |
parents | f5ab40759789 |
children | 4cf5c332a9c1 |
files | en/examples/run-example |
line diff
1.1 --- a/en/examples/run-example Thu Jan 29 22:10:57 2009 -0800 1.2 +++ b/en/examples/run-example Thu Jan 29 22:11:10 2009 -0800 1.3 @@ -61,9 +61,10 @@ 1.4 1.5 timeout = 10 1.6 1.7 - def __init__(self, name, verbose): 1.8 + def __init__(self, name, verbose, keep_change): 1.9 self.name = name 1.10 self.verbose = verbose 1.11 + self.keep_change = keep_change 1.12 self.poll = select.poll() 1.13 1.14 def parse(self): 1.15 @@ -320,7 +321,11 @@ 1.16 return False 1.17 else: 1.18 print >> sys.stderr, '\nOutput of %s has changed!' % base 1.19 - os.system('diff -u %s %s 1>&2' % (oldname, errname)) 1.20 + if self.keep_change: 1.21 + os.rename(errname, oldname) 1.22 + return False 1.23 + else: 1.24 + os.system('diff -u %s %s 1>&2' % (oldname, errname)) 1.25 return True 1.26 1.27 def print_help(exit, msg=None): 1.28 @@ -330,19 +335,23 @@ 1.29 print >> sys.stderr, 'Options:' 1.30 print >> sys.stderr, ' -a --all run all tests in this directory' 1.31 print >> sys.stderr, ' -h --help print this help message' 1.32 + print >> sys.stderr, ' --help keep new output as desired output' 1.33 print >> sys.stderr, ' -v --verbose display extra debug output' 1.34 sys.exit(exit) 1.35 1.36 def main(path='.'): 1.37 opts, args = getopt.getopt(sys.argv[1:], '?ahv', 1.38 - ['all', 'help', 'verbose']) 1.39 + ['all', 'help', 'keep', 'verbose']) 1.40 verbose = False 1.41 run_all = False 1.42 + keep_change = False 1.43 for o, a in opts: 1.44 if o in ('-h', '-?', '--help'): 1.45 print_help(0) 1.46 if o in ('-a', '--all'): 1.47 run_all = True 1.48 + if o in ('--keep',): 1.49 + keep_change = True 1.50 if o in ('-v', '--verbose'): 1.51 verbose = True 1.52 errs = 0 1.53 @@ -355,7 +364,7 @@ 1.54 errs += 1 1.55 continue 1.56 if stat.S_ISREG(st.st_mode) and st.st_mode & 0111: 1.57 - if example(a, verbose).run(): 1.58 + if example(a, verbose, keep_change).run(): 1.59 errs += 1 1.60 else: 1.61 print >> sys.stderr, '%s: not a file, or not executable' % a 1.62 @@ -376,7 +385,7 @@ 1.63 raise 1.64 continue 1.65 if stat.S_ISREG(st.st_mode) and st.st_mode & 0111: 1.66 - if example(pathname, verbose).run(): 1.67 + if example(pathname, verbose, keep_change).run(): 1.68 errs += 1 1.69 print >> open(os.path.join(path, '.run'), 'w'), time.asctime() 1.70 else: