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:
parent
7c50411270
commit
747d8b31e8
|
@ -3,6 +3,7 @@
|
|||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
from pipes import quote
|
||||
from fnmatch import fnmatch
|
||||
from optparse import OptionParser, BadOptionError, AmbiguousOptionError
|
||||
|
||||
|
@ -10,6 +11,7 @@ from optparse import OptionParser, BadOptionError, AmbiguousOptionError
|
|||
APPLICATION = 'phpunit'
|
||||
DEFAULT_ARGS = ['--strict', '--static-backup']
|
||||
|
||||
VAGRANT_SCRIPT = '/vagrant/test/php/runtests'
|
||||
REPORT_DIRECTORY = '../../build/log'
|
||||
|
||||
|
||||
|
@ -64,44 +66,59 @@ def parse_commandline():
|
|||
help='Enable reporting.')
|
||||
parser.add_option('-v', '--verbose', action='store_true',
|
||||
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.')
|
||||
parser.add_option('-V', '--vagrant', action='store_true',
|
||||
help='Run in vagrant VM')
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def main():
|
||||
options, arguments = parse_commandline()
|
||||
|
||||
# Environment preparation and verification
|
||||
os.chdir(get_script_directory())
|
||||
application_path = execute_command('which {0}'.format(APPLICATION),
|
||||
True, True).strip()
|
||||
if not application_path:
|
||||
print 'ERROR: {0} not found!'.format(APPLICATION)
|
||||
return 2
|
||||
if not os.path.isfile('./bin/extcmd_test'):
|
||||
execute_command('make', shell=True)
|
||||
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
|
||||
|
||||
# Commandline preparation
|
||||
command_options = []
|
||||
if options.verbose:
|
||||
command_options.append('--verbose')
|
||||
if options.build:
|
||||
report_directory = get_report_directory()
|
||||
command_options.append('--log-junit')
|
||||
command_options.append(os.path.join(report_directory,
|
||||
'phpunit_results.xml'))
|
||||
command_options.append('--coverage-clover')
|
||||
command_options.append(os.path.join(report_directory,
|
||||
'phpunit_coverage.xml'))
|
||||
if options.include:
|
||||
command_options.append('--filter')
|
||||
command_options.append(options.include)
|
||||
# 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
|
||||
os.chdir(get_script_directory())
|
||||
application_path = execute_command('which {0}'.format(APPLICATION),
|
||||
True, True).strip()
|
||||
if not application_path:
|
||||
print 'ERROR: {0} not found!'.format(APPLICATION)
|
||||
return 2
|
||||
if not os.path.isfile('./bin/extcmd_test'):
|
||||
execute_command('make', shell=True)
|
||||
|
||||
# Application invocation..
|
||||
execute_command([application_path] + DEFAULT_ARGS +
|
||||
command_options + arguments)
|
||||
return 0
|
||||
# Commandline preparation
|
||||
command_options = []
|
||||
if options.verbose:
|
||||
command_options.append('--verbose')
|
||||
if options.build:
|
||||
report_directory = get_report_directory()
|
||||
command_options.append('--log-junit')
|
||||
command_options.append(os.path.join(report_directory,
|
||||
'phpunit_results.xml'))
|
||||
command_options.append('--coverage-clover')
|
||||
command_options.append(os.path.join(report_directory,
|
||||
'phpunit_coverage.xml'))
|
||||
if options.include:
|
||||
command_options.append('--filter')
|
||||
command_options.append(options.include)
|
||||
|
||||
# Application invocation..
|
||||
execute_command([application_path] + DEFAULT_ARGS +
|
||||
command_options + arguments)
|
||||
return 0
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
||||
|
|
Loading…
Reference in New Issue