255 ret = signal.SIGTERM << 8 |
255 ret = signal.SIGTERM << 8 |
256 output += ("\n### Abort: timeout after %d seconds.\n" |
256 output += ("\n### Abort: timeout after %d seconds.\n" |
257 % options.timeout) |
257 % options.timeout) |
258 return ret, splitnewlines(output) |
258 return ret, splitnewlines(output) |
259 |
259 |
260 def run_one(test): |
260 def run_one(test, skips): |
261 '''tristate output: |
261 '''tristate output: |
262 None -> skipped |
262 None -> skipped |
263 True -> passed |
263 True -> passed |
264 False -> failed''' |
264 False -> failed''' |
265 |
265 |
|
266 def skip(msg): |
|
267 if not verbose: |
|
268 skips.append((test, msg)) |
|
269 sys.stdout.write('s') |
|
270 sys.stdout.flush() |
|
271 else: |
|
272 print "\nSkipping %s: %s" % (test, msg) |
|
273 return None |
|
274 |
266 vlog("# Test", test) |
275 vlog("# Test", test) |
267 if not verbose: |
|
268 sys.stdout.write('.') |
|
269 sys.stdout.flush() |
|
270 |
276 |
271 # create a fresh hgrc |
277 # create a fresh hgrc |
272 hgrc = file(HGRCPATH, 'w+') |
278 hgrc = file(HGRCPATH, 'w+') |
273 hgrc.write('[ui]\n') |
279 hgrc.write('[ui]\n') |
274 hgrc.write('slash = True\n') |
280 hgrc.write('slash = True\n') |
297 if lctest.endswith('.py') or firstline == '#!/usr/bin/env python': |
303 if lctest.endswith('.py') or firstline == '#!/usr/bin/env python': |
298 cmd = '%s "%s"' % (python, testpath) |
304 cmd = '%s "%s"' % (python, testpath) |
299 elif lctest.endswith('.bat'): |
305 elif lctest.endswith('.bat'): |
300 # do not run batch scripts on non-windows |
306 # do not run batch scripts on non-windows |
301 if os.name != 'nt': |
307 if os.name != 'nt': |
302 print '\nSkipping %s: batch script' % test |
308 return skip("batch script") |
303 return None |
|
304 # To reliably get the error code from batch files on WinXP, |
309 # To reliably get the error code from batch files on WinXP, |
305 # the "cmd /c call" prefix is needed. Grrr |
310 # the "cmd /c call" prefix is needed. Grrr |
306 cmd = 'cmd /c call "%s"' % testpath |
311 cmd = 'cmd /c call "%s"' % testpath |
307 else: |
312 else: |
308 # do not run shell scripts on windows |
313 # do not run shell scripts on windows |
309 if os.name == 'nt': |
314 if os.name == 'nt': |
310 print '\nSkipping %s: shell script' % test |
315 return skip("shell script") |
311 return None |
|
312 # do not try to run non-executable programs |
316 # do not try to run non-executable programs |
313 if not os.access(testpath, os.X_OK): |
317 if not os.access(testpath, os.X_OK): |
314 print '\nSkipping %s: not executable' % test |
318 return skip("not executable") |
315 return None |
|
316 cmd = '"%s"' % testpath |
319 cmd = '"%s"' % testpath |
317 |
320 |
318 if options.timeout > 0: |
321 if options.timeout > 0: |
319 signal.alarm(options.timeout) |
322 signal.alarm(options.timeout) |
320 |
323 |
340 show_diff(ref_out, out) |
343 show_diff(ref_out, out) |
341 if skipped: |
344 if skipped: |
342 missing = extract_missing_features(out) |
345 missing = extract_missing_features(out) |
343 if not missing: |
346 if not missing: |
344 missing = ['irrelevant'] |
347 missing = ['irrelevant'] |
345 print '\nSkipping %s: %s' % (test, missing[-1]) |
348 skip(missing[-1]) |
346 elif ret: |
349 elif ret: |
347 print "\nERROR: %s failed with error code %d" % (test, ret) |
350 print "\nERROR: %s failed with error code %d" % (test, ret) |
348 elif diffret: |
351 elif diffret: |
349 ret = diffret |
352 ret = diffret |
|
353 |
|
354 if not verbose: |
|
355 sys.stdout.write('.') |
|
356 sys.stdout.flush() |
350 |
357 |
351 if ret != 0 and not skipped: |
358 if ret != 0 and not skipped: |
352 # Save errors to a file for diagnosis |
359 # Save errors to a file for diagnosis |
353 f = open(err, "wb") |
360 f = open(err, "wb") |
354 for line in out: |
361 for line in out: |
451 vlog(' '.join(cmdline)) |
458 vlog(' '.join(cmdline)) |
452 fps[os.spawnvp(os.P_NOWAIT, cmdline[0], cmdline)] = os.fdopen(rfd, 'r') |
459 fps[os.spawnvp(os.P_NOWAIT, cmdline[0], cmdline)] = os.fdopen(rfd, 'r') |
453 os.close(wfd) |
460 os.close(wfd) |
454 failures = 0 |
461 failures = 0 |
455 tested, skipped, failed = 0, 0, 0 |
462 tested, skipped, failed = 0, 0, 0 |
|
463 skips = [] |
456 while fps: |
464 while fps: |
457 pid, status = os.wait() |
465 pid, status = os.wait() |
458 fp = fps.pop(pid) |
466 fp = fps.pop(pid) |
459 test, skip, fail = map(int, fp.read().splitlines()) |
467 l = fp.read().splitlines() |
|
468 test, skip, fail = map(int, l[:3]) |
|
469 for s in l[3:]: |
|
470 skips.append(s.split(" ", 1)) |
460 tested += test |
471 tested += test |
461 skipped += skip |
472 skipped += skip |
462 failed += fail |
473 failed += fail |
463 vlog('pid %d exited, status %d' % (pid, status)) |
474 vlog('pid %d exited, status %d' % (pid, status)) |
464 failures |= status |
475 failures |= status |
465 print "\n# Ran %d tests, %d skipped, %d failed." % ( |
476 print |
|
477 for s in skips: |
|
478 print "Skipped %s: %s" % (s[0], s[1]) |
|
479 print "# Ran %d tests, %d skipped, %d failed." % ( |
466 tested, skipped, failed) |
480 tested, skipped, failed) |
467 sys.exit(failures != 0) |
481 sys.exit(failures != 0) |
468 |
482 |
469 def run_tests(tests): |
483 def run_tests(tests): |
470 global DAEMON_PIDS, HGRCPATH |
484 global DAEMON_PIDS, HGRCPATH |
496 tests.pop(0) |
510 tests.pop(0) |
497 if not tests: |
511 if not tests: |
498 print "running all tests" |
512 print "running all tests" |
499 tests = orig |
513 tests = orig |
500 |
514 |
|
515 skips = [] |
501 for test in tests: |
516 for test in tests: |
502 if options.retest and not os.path.exists(test + ".err"): |
517 if options.retest and not os.path.exists(test + ".err"): |
503 skipped += 1 |
518 skipped += 1 |
504 continue |
519 continue |
505 ret = run_one(test) |
520 ret = run_one(test, skips) |
506 if ret is None: |
521 if ret is None: |
507 skipped += 1 |
522 skipped += 1 |
508 elif not ret: |
523 elif not ret: |
509 if options.interactive: |
524 if options.interactive: |
510 print "Accept this change? [n] ", |
525 print "Accept this change? [n] ", |
519 tested += 1 |
534 tested += 1 |
520 |
535 |
521 if options.child: |
536 if options.child: |
522 fp = os.fdopen(options.child, 'w') |
537 fp = os.fdopen(options.child, 'w') |
523 fp.write('%d\n%d\n%d\n' % (tested, skipped, failed)) |
538 fp.write('%d\n%d\n%d\n' % (tested, skipped, failed)) |
|
539 for s in skips: |
|
540 fp.write("%s %s\n" % s) |
524 fp.close() |
541 fp.close() |
525 else: |
542 else: |
526 print "\n# Ran %d tests, %d skipped, %d failed." % ( |
543 print |
|
544 for s in skips: |
|
545 print "Skipped %s: %s" % s |
|
546 print "# Ran %d tests, %d skipped, %d failed." % ( |
527 tested, skipped, failed) |
547 tested, skipped, failed) |
528 |
548 |
529 if coverage: |
549 if coverage: |
530 output_coverage() |
550 output_coverage() |
531 except KeyboardInterrupt: |
551 except KeyboardInterrupt: |