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 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,44 +66,59 @@ 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()
|
||||||
|
|
||||||
# Environment preparation and verification
|
if options.vagrant and os.environ['USER'] != 'vagrant':
|
||||||
os.chdir(get_script_directory())
|
# Check if vagrant is installed
|
||||||
application_path = execute_command('which {0}'.format(APPLICATION),
|
vagrant_path = execute_command('which vagrant', True, True).strip()
|
||||||
True, True).strip()
|
if not vagrant_path:
|
||||||
if not application_path:
|
print 'ERROR: vagrant not found!'
|
||||||
print 'ERROR: {0} not found!'.format(APPLICATION)
|
return 2
|
||||||
return 2
|
|
||||||
if not os.path.isfile('./bin/extcmd_test'):
|
|
||||||
execute_command('make', shell=True)
|
|
||||||
|
|
||||||
# Commandline preparation
|
# Call the script in the Vagrant VM with the same parameters
|
||||||
command_options = []
|
commandline = ' '.join(quote(p) for p in sys.argv[1:])
|
||||||
if options.verbose:
|
return execute_command('vagrant ssh -c "{0} {1}"'
|
||||||
command_options.append('--verbose')
|
''.format(VAGRANT_SCRIPT, commandline),
|
||||||
if options.build:
|
shell=True)
|
||||||
report_directory = get_report_directory()
|
else:
|
||||||
command_options.append('--log-junit')
|
# Environment preparation and verification
|
||||||
command_options.append(os.path.join(report_directory,
|
os.chdir(get_script_directory())
|
||||||
'phpunit_results.xml'))
|
application_path = execute_command('which {0}'.format(APPLICATION),
|
||||||
command_options.append('--coverage-clover')
|
True, True).strip()
|
||||||
command_options.append(os.path.join(report_directory,
|
if not application_path:
|
||||||
'phpunit_coverage.xml'))
|
print 'ERROR: {0} not found!'.format(APPLICATION)
|
||||||
if options.include:
|
return 2
|
||||||
command_options.append('--filter')
|
if not os.path.isfile('./bin/extcmd_test'):
|
||||||
command_options.append(options.include)
|
execute_command('make', shell=True)
|
||||||
|
|
||||||
# Application invocation..
|
# Commandline preparation
|
||||||
execute_command([application_path] + DEFAULT_ARGS +
|
command_options = []
|
||||||
command_options + arguments)
|
if options.verbose:
|
||||||
return 0
|
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__':
|
if __name__ == '__main__':
|
||||||
sys.exit(main())
|
sys.exit(main())
|
||||||
|
|
Loading…
Reference in New Issue