174 parser.add_option("--shell", type="string", |
174 parser.add_option("--shell", type="string", |
175 help="shell to use (default: $%s or %s)" % defaults['shell']) |
175 help="shell to use (default: $%s or %s)" % defaults['shell']) |
176 parser.add_option("-t", "--timeout", type="int", |
176 parser.add_option("-t", "--timeout", type="int", |
177 help="kill errant tests after TIMEOUT seconds" |
177 help="kill errant tests after TIMEOUT seconds" |
178 " (default: $%s or %d)" % defaults['timeout']) |
178 " (default: $%s or %d)" % defaults['timeout']) |
|
179 parser.add_option("--time", action="store_true", |
|
180 help="time how long each test takes") |
179 parser.add_option("--tmpdir", type="string", |
181 parser.add_option("--tmpdir", type="string", |
180 help="run tests in the given temporary directory" |
182 help="run tests in the given temporary directory" |
181 " (implies --keep-tmpdir)") |
183 " (implies --keep-tmpdir)") |
182 parser.add_option("-v", "--verbose", action="store_true", |
184 parser.add_option("-v", "--verbose", action="store_true", |
183 help="output verbose messages") |
185 help="output verbose messages") |
262 if options.debug: |
264 if options.debug: |
263 if options.timeout != defaults['timeout']: |
265 if options.timeout != defaults['timeout']: |
264 sys.stderr.write( |
266 sys.stderr.write( |
265 'warning: --timeout option ignored with --debug\n') |
267 'warning: --timeout option ignored with --debug\n') |
266 options.timeout = 0 |
268 options.timeout = 0 |
|
269 if options.time: |
|
270 sys.stderr.write( |
|
271 'warning: --time option ignored with --debug\n') |
|
272 options.time = False |
267 if options.py3k_warnings: |
273 if options.py3k_warnings: |
268 if sys.version_info[:2] < (2, 6) or sys.version_info[:2] >= (3, 0): |
274 if sys.version_info[:2] < (2, 6) or sys.version_info[:2] >= (3, 0): |
269 parser.error('--py3k-warnings can only be used on Python 2.6+') |
275 parser.error('--py3k-warnings can only be used on Python 2.6+') |
270 if options.blacklist: |
276 if options.blacklist: |
271 options.blacklist = parselistfiles(options.blacklist, 'blacklist') |
277 options.blacklist = parselistfiles(options.blacklist, 'blacklist') |
445 rc = os.path.join(TESTDIR, '.coveragerc') |
451 rc = os.path.join(TESTDIR, '.coveragerc') |
446 vlog('# Installing coverage rc to %s' % rc) |
452 vlog('# Installing coverage rc to %s' % rc) |
447 os.environ['COVERAGE_PROCESS_START'] = rc |
453 os.environ['COVERAGE_PROCESS_START'] = rc |
448 fn = os.path.join(INST, '..', '.coverage') |
454 fn = os.path.join(INST, '..', '.coverage') |
449 os.environ['COVERAGE_FILE'] = fn |
455 os.environ['COVERAGE_FILE'] = fn |
|
456 |
|
457 def outputtimes(options): |
|
458 vlog('# Producing time report') |
|
459 times.sort(key=lambda t: (t[1], t[0]), reverse=True) |
|
460 cols = '%7.3f %s' |
|
461 print '\n%-7s %s' % ('Time', 'Test') |
|
462 for test, timetaken in times: |
|
463 print cols % (timetaken, test) |
450 |
464 |
451 def outputcoverage(options): |
465 def outputcoverage(options): |
452 |
466 |
453 vlog('# Producing coverage report') |
467 vlog('# Producing coverage report') |
454 os.chdir(PYTHONDIR) |
468 os.chdir(PYTHONDIR) |
885 for c in testtmp), '$TESTTMP')) |
899 for c in testtmp), '$TESTTMP')) |
886 else: |
900 else: |
887 replacements.append((re.escape(testtmp), '$TESTTMP')) |
901 replacements.append((re.escape(testtmp), '$TESTTMP')) |
888 |
902 |
889 os.mkdir(testtmp) |
903 os.mkdir(testtmp) |
|
904 if options.time: |
|
905 starttime = time.time() |
890 ret, out = runner(testpath, testtmp, options, replacements) |
906 ret, out = runner(testpath, testtmp, options, replacements) |
|
907 if options.time: |
|
908 endtime = time.time() |
|
909 times.append((test, endtime - starttime)) |
891 vlog("# Ret was:", ret) |
910 vlog("# Ret was:", ret) |
892 |
911 |
893 mark = '.' |
912 mark = '.' |
894 |
913 |
895 skipped = (ret == SKIPPED_STATUS) |
914 skipped = (ret == SKIPPED_STATUS) |
1070 passed += len(childresults['p']) |
1089 passed += len(childresults['p']) |
1071 skipped += len(childresults['s']) |
1090 skipped += len(childresults['s']) |
1072 failed += len(childresults['f']) |
1091 failed += len(childresults['f']) |
1073 skips.extend(childresults['s']) |
1092 skips.extend(childresults['s']) |
1074 fails.extend(childresults['f']) |
1093 fails.extend(childresults['f']) |
|
1094 if options.time: |
|
1095 childtimes = pickle.load(fp) |
|
1096 times.extend(childtimes) |
1075 |
1097 |
1076 vlog('pid %d exited, status %d' % (pid, status)) |
1098 vlog('pid %d exited, status %d' % (pid, status)) |
1077 failures |= status |
1099 failures |= status |
1078 print |
1100 print |
1079 skipped += len(blacklisted) |
1101 skipped += len(blacklisted) |
1087 |
1109 |
1088 _checkhglib("Tested") |
1110 _checkhglib("Tested") |
1089 print "# Ran %d tests, %d skipped, %d failed." % ( |
1111 print "# Ran %d tests, %d skipped, %d failed." % ( |
1090 passed + failed, skipped, failed) |
1112 passed + failed, skipped, failed) |
1091 |
1113 |
|
1114 if options.time: |
|
1115 outputtimes(options) |
1092 if options.anycoverage: |
1116 if options.anycoverage: |
1093 outputcoverage(options) |
1117 outputcoverage(options) |
1094 sys.exit(failures != 0) |
1118 sys.exit(failures != 0) |
1095 |
1119 |
1096 results = dict(p=[], f=[], s=[], i=[]) |
1120 results = dict(p=[], f=[], s=[], i=[]) |
|
1121 times = [] |
1097 iolock = threading.Lock() |
1122 iolock = threading.Lock() |
1098 |
1123 |
1099 def runqueue(options, tests, results): |
1124 def runqueue(options, tests, results): |
1100 for test in tests: |
1125 for test in tests: |
1101 ret = runone(options, test) |
1126 ret = runone(options, test) |
1130 ignored = len(results['i']) |
1155 ignored = len(results['i']) |
1131 |
1156 |
1132 if options.child: |
1157 if options.child: |
1133 fp = os.fdopen(options.child, 'w') |
1158 fp = os.fdopen(options.child, 'w') |
1134 pickle.dump(results, fp, pickle.HIGHEST_PROTOCOL) |
1159 pickle.dump(results, fp, pickle.HIGHEST_PROTOCOL) |
|
1160 if options.time: |
|
1161 pickle.dump(times, fp, pickle.HIGHEST_PROTOCOL) |
1135 fp.close() |
1162 fp.close() |
1136 else: |
1163 else: |
1137 print |
1164 print |
1138 for s in results['s']: |
1165 for s in results['s']: |
1139 print "Skipped %s: %s" % s |
1166 print "Skipped %s: %s" % s |
1140 for s in results['f']: |
1167 for s in results['f']: |
1141 print "Failed %s: %s" % s |
1168 print "Failed %s: %s" % s |
1142 _checkhglib("Tested") |
1169 _checkhglib("Tested") |
1143 print "# Ran %d tests, %d skipped, %d failed." % ( |
1170 print "# Ran %d tests, %d skipped, %d failed." % ( |
1144 tested, skipped + ignored, failed) |
1171 tested, skipped + ignored, failed) |
|
1172 if options.time: |
|
1173 outputtimes(options) |
1145 |
1174 |
1146 if options.anycoverage: |
1175 if options.anycoverage: |
1147 outputcoverage(options) |
1176 outputcoverage(options) |
1148 except KeyboardInterrupt: |
1177 except KeyboardInterrupt: |
1149 failed = True |
1178 failed = True |