Add --vagrant switch to the javascript test-runner

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

refs #4264
This commit is contained in:
Johannes Meyer 2013-06-14 13:29:40 +02:00
parent a7a8836b5b
commit d7ebe7fa08

View File

@ -3,12 +3,14 @@
import os import os
import sys import sys
import subprocess import subprocess
from pipes import quote
from optparse import OptionParser, BadOptionError, AmbiguousOptionError from optparse import OptionParser, BadOptionError, AmbiguousOptionError
APPLICATION = 'mocha' APPLICATION = 'mocha'
DEFAULT_ARGS = ['--recursive', '--require', 'should'] DEFAULT_ARGS = ['--recursive', '--require', 'should']
VAGRANT_SCRIPT = '/vagrant/test/js/runtests'
REPORT_DIRECTORY = '../../build/log' REPORT_DIRECTORY = '../../build/log'
@ -69,12 +71,27 @@ def parse_commandline():
parser.add_option('-e', '--exclude', metavar='PATTERN', action='append', parser.add_option('-e', '--exclude', metavar='PATTERN', action='append',
help='Exclude specific files/test cases. ' help='Exclude specific files/test cases. '
'(Can be supplied multiple times.)') '(Can be supplied multiple times.)')
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),
@ -114,7 +131,8 @@ def main():
result_data = execute_command([application_path] + DEFAULT_ARGS + result_data = execute_command([application_path] + DEFAULT_ARGS +
command_options + arguments, True) command_options + arguments, True)
coverage_data = execute_command([application_path] + DEFAULT_ARGS + coverage_data = execute_command([application_path] + DEFAULT_ARGS +
more_command_options + arguments, True) more_command_options + arguments,
return_output=True)
# Result storage # Result storage
report_directory = get_report_directory() report_directory = get_report_directory()
result_path = os.path.join(report_directory, 'mocha_results.xml') result_path = os.path.join(report_directory, 'mocha_results.xml')