Mercurial > hg > mercurial-source
comparison tests/run-tests.py @ 11740:e5c79e31feb6
tests: move script execution in runner helpers
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Mon, 02 Aug 2010 15:44:54 -0500 |
parents | 8f951ed6c63c |
children | 431e2bf37ae7 |
comparison
equal
deleted
inserted
replaced
11739:a614666bbba4 | 11740:e5c79e31feb6 |
---|---|
439 pass | 439 pass |
440 | 440 |
441 def alarmed(signum, frame): | 441 def alarmed(signum, frame): |
442 raise Timeout | 442 raise Timeout |
443 | 443 |
444 def pytest(test, options): | |
445 py3kswitch = options.py3k_warnings and ' -3' or '' | |
446 cmd = '%s%s "%s"' % (PYTHON, py3kswitch, test) | |
447 vlog("# Running", cmd) | |
448 return run(cmd, options) | |
449 | |
450 def shtest(test, options): | |
451 cmd = '"%s"' % test | |
452 vlog("# Running", cmd) | |
453 return run(cmd, options) | |
454 | |
455 def battest(test, options): | |
456 # To reliably get the error code from batch files on WinXP, | |
457 # the "cmd /c call" prefix is needed. Grrr | |
458 cmd = 'cmd /c call "%s"' % testpath | |
459 vlog("# Running", cmd) | |
460 return run(cmd, options) | |
461 | |
444 def run(cmd, options): | 462 def run(cmd, options): |
445 """Run command in a sub-process, capturing the output (stdout and stderr). | 463 """Run command in a sub-process, capturing the output (stdout and stderr). |
446 Return a tuple (exitcode, output). output is None in debug mode.""" | 464 Return a tuple (exitcode, output). output is None in debug mode.""" |
447 # TODO: Use subprocess.Popen if we're running on Python 2.4 | 465 # TODO: Use subprocess.Popen if we're running on Python 2.4 |
448 if options.debug: | 466 if options.debug: |
535 except: | 553 except: |
536 firstline = '' | 554 firstline = '' |
537 lctest = test.lower() | 555 lctest = test.lower() |
538 | 556 |
539 if lctest.endswith('.py') or firstline == '#!/usr/bin/env python': | 557 if lctest.endswith('.py') or firstline == '#!/usr/bin/env python': |
540 py3kswitch = options.py3k_warnings and ' -3' or '' | 558 runner = pytest |
541 cmd = '%s%s "%s"' % (PYTHON, py3kswitch, testpath) | |
542 elif lctest.endswith('.bat'): | 559 elif lctest.endswith('.bat'): |
543 # do not run batch scripts on non-windows | 560 # do not run batch scripts on non-windows |
544 if os.name != 'nt': | 561 if os.name != 'nt': |
545 return skip("batch script") | 562 return skip("batch script") |
546 # To reliably get the error code from batch files on WinXP, | 563 runner = battest |
547 # the "cmd /c call" prefix is needed. Grrr | |
548 cmd = 'cmd /c call "%s"' % testpath | |
549 else: | 564 else: |
550 # do not run shell scripts on windows | 565 # do not run shell scripts on windows |
551 if os.name == 'nt': | 566 if os.name == 'nt': |
552 return skip("shell script") | 567 return skip("shell script") |
553 # do not try to run non-executable programs | 568 # do not try to run non-executable programs |
554 if not os.path.exists(testpath): | 569 if not os.path.exists(testpath): |
555 return fail("does not exist") | 570 return fail("does not exist") |
556 elif not os.access(testpath, os.X_OK): | 571 elif not os.access(testpath, os.X_OK): |
557 return skip("not executable") | 572 return skip("not executable") |
558 cmd = '"%s"' % testpath | 573 runner = shtest |
559 | 574 |
560 # Make a tmp subdirectory to work in | 575 # Make a tmp subdirectory to work in |
561 tmpd = os.path.join(HGTMP, test) | 576 tmpd = os.path.join(HGTMP, test) |
562 os.mkdir(tmpd) | 577 os.mkdir(tmpd) |
563 os.chdir(tmpd) | 578 os.chdir(tmpd) |
564 | 579 |
565 if options.timeout > 0: | 580 if options.timeout > 0: |
566 signal.alarm(options.timeout) | 581 signal.alarm(options.timeout) |
567 | 582 |
568 vlog("# Running", cmd) | 583 ret, out = runner(testpath, options) |
569 ret, out = run(cmd, options) | |
570 vlog("# Ret was:", ret) | 584 vlog("# Ret was:", ret) |
571 | 585 |
572 if options.timeout > 0: | 586 if options.timeout > 0: |
573 signal.alarm(0) | 587 signal.alarm(0) |
574 | 588 |