Add --vagrant switch to the php test-runner

Added -V|--vagrant switch to the php test-runner
to run the tests in the Vagrant VM

refs #4264
This commit is contained in:
Johannes Meyer 2013-06-14 13:01:19 +02:00
parent 7c50411270
commit 747d8b31e8
1 changed files with 46 additions and 29 deletions

View File

@ -3,6 +3,7 @@
import os import os
import sys import sys
import subprocess import subprocess
from pipes import quote
from fnmatch import fnmatch from fnmatch import fnmatch
from optparse import OptionParser, BadOptionError, AmbiguousOptionError from optparse import OptionParser, BadOptionError, AmbiguousOptionError
@ -10,6 +11,7 @@ from optparse import OptionParser, BadOptionError, AmbiguousOptionError
APPLICATION = 'phpunit' APPLICATION = 'phpunit'
DEFAULT_ARGS = ['--strict', '--static-backup'] DEFAULT_ARGS = ['--strict', '--static-backup']
VAGRANT_SCRIPT = '/vagrant/test/php/runtests'
REPORT_DIRECTORY = '../../build/log' REPORT_DIRECTORY = '../../build/log'
@ -64,14 +66,29 @@ def parse_commandline():
help='Enable reporting.') help='Enable reporting.')
parser.add_option('-v', '--verbose', action='store_true', parser.add_option('-v', '--verbose', action='store_true',
help='Be more verbose.') help='Be more verbose.')
parser.add_option('-i', '--include', metavar='PATTERN', action='store', parser.add_option('-i', '--include', metavar='PATTERN',
help='Include only specific files/test cases.') help='Include only specific files/test cases.')
parser.add_option('-V', '--vagrant', action='store_true',
help='Run in vagrant VM')
return parser.parse_args() return parser.parse_args()
def main(): def main():
options, arguments = parse_commandline() options, arguments = parse_commandline()
if options.vagrant and os.environ['USER'] != 'vagrant':
# Check if vagrant is installed
vagrant_path = execute_command('which vagrant', True, True).strip()
if not vagrant_path:
print 'ERROR: vagrant not found!'
return 2
# Call the script in the Vagrant VM with the same parameters
commandline = ' '.join(quote(p) for p in sys.argv[1:])
return execute_command('vagrant ssh -c "{0} {1}"'
''.format(VAGRANT_SCRIPT, commandline),
shell=True)
else:
# Environment preparation and verification # Environment preparation and verification
os.chdir(get_script_directory()) os.chdir(get_script_directory())
application_path = execute_command('which {0}'.format(APPLICATION), application_path = execute_command('which {0}'.format(APPLICATION),