Merge branch 'bugfix/unified-test-and-style-scripts-4244'

This commit is contained in:
Eric Lippmann 2013-06-11 18:27:03 +02:00
commit 09302f6fb9
9 changed files with 480 additions and 110 deletions

132
test/js/checkswag Executable file
View File

@ -0,0 +1,132 @@
#!/usr/bin/env python
import os
import sys
import subprocess
from fnmatch import fnmatch
from optparse import OptionParser, BadOptionError, AmbiguousOptionError
APPLICATION = 'jshint'
DEFAULT_ARGS = []
REPORT_DIRECTORY = '../../build/log'
class PassThroughOptionParser(OptionParser):
"""
An unknown option pass-through implementation of OptionParser.
When unknown arguments are encountered, bundle with largs and try again,
until rargs is depleted.
sys.exit(status) will still be called if a known argument is passed
incorrectly (e.g. missing arguments or bad argument types, etc.)
Borrowed from: http://stackoverflow.com/a/9307174
"""
def _process_args(self, largs, rargs, values):
while rargs:
try:
OptionParser._process_args(self, largs, rargs, values)
except (BadOptionError, AmbiguousOptionError), error:
largs.append(error.opt_str)
def execute_command(command, return_output=False, shell=False):
prog = subprocess.Popen(command, shell=shell,
stdout=subprocess.PIPE
if return_output
else None)
return prog.wait() if not return_output else \
prog.communicate()[0]
def get_report_directory():
path = os.path.abspath(REPORT_DIRECTORY)
try:
os.makedirs(REPORT_DIRECTORY)
except OSError:
pass
return path
def get_script_directory():
return os.path.dirname(os.path.abspath(sys.argv[0]))
def parse_commandline():
parser = PassThroughOptionParser(usage='%prog [options] [additional arguments'
' for {0}]'.format(APPLICATION))
parser.add_option('-b', '--build', action='store_true',
help='Enable reporting.')
parser.add_option('-v', '--verbose', action='store_true',
help='Be more verbose.')
parser.add_option('-i', '--include', metavar='PATTERN', action='append',
help='Include only specific files/test cases.'
' (Can be supplied multiple times.)')
parser.add_option('-e', '--exclude', metavar='PATTERN', action='append',
help='Exclude specific files/test cases. '
'(Can be supplied multiple times.)')
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
# Commandline preparation
command_options = []
if options.build:
command_options.extend(['--reporter', 'jslint'])
else:
command_options.append('--verbose')
if options.verbose:
command_options.append('--show-non-errors')
path_args = [arguments.remove(a) or a
for a in arguments[:len(arguments)]
if os.path.isfile(a) or os.path.isdir(a)]
if not path_args:
path_args = ['../../application', '../../bin', '../../library/Icinga']
if options.include:
path_args = [os.path.join(r, f) for a in path_args
for r, _, fs in os.walk(a)
for f in fs
if any(fnmatch(os.path.join(r, f), p)
for p in options.include)]
if options.exclude:
walk = lambda p: os.walk(p) if os.path.isdir(p) else \
[(os.path.dirname(p), None, [os.path.basename(p)])]
path_args = [os.path.join(r, f)
for a in path_args
for r, _, fs in walk(a)
for f in fs
if not any(fnmatch(os.path.join(r, f), p)
for p in options.exclude)]
# Application invocation..
if options.build:
result_data = execute_command([application_path] + DEFAULT_ARGS +
command_options + arguments +
path_args, True)
result_path = os.path.join(get_report_directory(),
'jshint_results.xml')
with open(result_path, 'w') as result_file:
result_file.write(result_data)
else:
execute_command([application_path] + DEFAULT_ARGS +
command_options + arguments + path_args)
return 0
if __name__ == '__main__':
sys.exit(main())

View File

@ -1,13 +0,0 @@
#!/bin/sh
set -o nounset
SCRIPTNAME=$(readlink -f $0)
DIR=$(dirname $SCRIPTNAME)
# Make sure that the destination directory for logs and reports exists
mkdir -p $DIR/../../build/log
jshint --reporter=jslint "$@" $DIR/../.. > $DIR/../../build/log/jshint_results.xml
exit 0

130
test/js/runtests Executable file
View File

@ -0,0 +1,130 @@
#!/usr/bin/env python
import os
import sys
import subprocess
from optparse import OptionParser, BadOptionError, AmbiguousOptionError
APPLICATION = 'mocha'
DEFAULT_ARGS = ['--recursive', '--require', 'should']
REPORT_DIRECTORY = '../../build/log'
class PassThroughOptionParser(OptionParser):
"""
An unknown option pass-through implementation of OptionParser.
When unknown arguments are encountered, bundle with largs and try again,
until rargs is depleted.
sys.exit(status) will still be called if a known argument is passed
incorrectly (e.g. missing arguments or bad argument types, etc.)
Borrowed from: http://stackoverflow.com/a/9307174
"""
def _process_args(self, largs, rargs, values):
while rargs:
try:
OptionParser._process_args(self, largs, rargs, values)
except (BadOptionError, AmbiguousOptionError), error:
largs.append(error.opt_str)
def execute_command(command, return_output=False, shell=False):
prog = subprocess.Popen(command, shell=shell,
stdout=subprocess.PIPE
if return_output
else None)
return prog.wait() if not return_output else \
prog.communicate()[0]
def get_report_directory():
path = os.path.abspath(REPORT_DIRECTORY)
try:
os.makedirs(REPORT_DIRECTORY)
except OSError:
pass
return path
def get_script_directory():
return os.path.dirname(os.path.abspath(sys.argv[0]))
def parse_commandline():
parser = PassThroughOptionParser(usage='%prog [options] [additional arguments'
' for {0}]'.format(APPLICATION))
parser.add_option('-b', '--build', action='store_true',
help='Enable reporting.')
parser.add_option('-v', '--verbose', action='store_true',
help='Be more verbose.')
parser.add_option('-i', '--include', metavar='PATTERN', action='append',
help='Include only specific files/test cases.'
' (Can be supplied multiple times.)')
parser.add_option('-e', '--exclude', metavar='PATTERN', action='append',
help='Exclude specific files/test cases. '
'(Can be supplied multiple times.)')
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
os.environ['NODE_PATH'] = os.environ.get('NODE_PATH', '') + \
':/usr/local/lib/node_modules' \
':/usr/lib/node_modules'
# Commandline preparation
command_options, more_command_options = [], None
if options.include or options.exclude:
for pattern in (options.include or options.exclude):
command_options.append('--grep')
command_options.append(pattern)
if options.exclude:
command_options.append('--invert')
if options.build:
more_command_options = command_options[:len(command_options)] + \
['--reporter', 'mocha-cobertura-reporter']
command_options.extend(['--reporter', 'xunit'])
elif options.verbose:
command_options.extend(['--reporter', 'spec'])
else:
command_options.extend(['--reporter', 'nyan'])
if not any(os.path.isfile(a) or os.path.isdir(a) for a in arguments):
arguments.append('.')
# Application invocation..
if more_command_options is None:
execute_command([application_path] + DEFAULT_ARGS +
command_options + arguments)
else:
result_data = execute_command([application_path] + DEFAULT_ARGS +
command_options + arguments, True)
coverage_data = execute_command([application_path] + DEFAULT_ARGS +
more_command_options + arguments, True)
# Result storage
report_directory = get_report_directory()
result_path = os.path.join(report_directory, 'mocha_results.xml')
coverage_path = os.path.join(report_directory, 'mocha_coverage.xml')
with open(result_path, 'w') as result_file:
result_file.write(result_data)
with open(coverage_path, 'w') as coverage_file:
coverage_file.write(coverage_data)
return 0
if __name__ == '__main__':
sys.exit(main())

View File

@ -1,26 +0,0 @@
#!/bin/sh
set -o nounset
SCRIPTNAME=$(readlink -f $0)
DIR=$(dirname $SCRIPTNAME)
MOCHA=$(which mocha)
DEFAULT="--recursive --require should"
if [[ ! -x $MOCHA ]]; then
echo "mocha not found!";
exit 1
fi
# Make sure that the destination directory for logs and reports exists
mkdir -p $DIR/../../build/log
cd $DIR
# Don't know where node modules are
export NODE_PATH=.:/usr/local/lib/node_modules:/usr/lib/node_modules
$MOCHA --reporter "xunit" $DEFAULT "$@" . > $DIR/../../build/log/mocha_results.xml
$MOCHA --reporter "mocha-cobertura-reporter" $DEFAULT "$@" . > $DIR/../../build/log/mocha_coverage.xml
exit 0

109
test/php/checkswag Executable file
View File

@ -0,0 +1,109 @@
#!/usr/bin/env python
import os
import sys
import subprocess
from optparse import OptionParser, BadOptionError, AmbiguousOptionError
APPLICATION = 'phpcs'
DEFAULT_ARGS = ['-p', '--standard=PSR2', '--extensions=php',
'--encoding=utf-8']
REPORT_DIRECTORY = '../../build/log'
class PassThroughOptionParser(OptionParser):
"""
An unknown option pass-through implementation of OptionParser.
When unknown arguments are encountered, bundle with largs and try again,
until rargs is depleted.
sys.exit(status) will still be called if a known argument is passed
incorrectly (e.g. missing arguments or bad argument types, etc.)
Borrowed from: http://stackoverflow.com/a/9307174
"""
def _process_args(self, largs, rargs, values):
while rargs:
try:
OptionParser._process_args(self, largs, rargs, values)
except (BadOptionError, AmbiguousOptionError), error:
largs.append(error.opt_str)
def execute_command(command, return_output=False, shell=False):
prog = subprocess.Popen(command, shell=shell,
stdout=subprocess.PIPE
if return_output
else None)
return prog.wait() if not return_output else \
prog.communicate()[0]
def get_report_directory():
path = os.path.abspath(REPORT_DIRECTORY)
try:
os.makedirs(REPORT_DIRECTORY)
except OSError:
pass
return path
def get_script_directory():
return os.path.dirname(os.path.abspath(sys.argv[0]))
def parse_commandline():
parser = PassThroughOptionParser(usage='%prog [options] [additional arguments'
' for {0}]'.format(APPLICATION))
parser.add_option('-b', '--build', action='store_true',
help='Enable reporting.')
parser.add_option('-v', '--verbose', action='store_true',
help='Be more verbose.')
parser.add_option('-i', '--include', metavar='PATTERN', action='append',
help='Include only specific files/test cases.'
' (Can be supplied multiple times.)')
parser.add_option('-e', '--exclude', metavar='PATTERN', action='append',
help='Exclude specific files/test cases. '
'(Can be supplied multiple times.)')
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
# Commandline preparation
command_options = []
if options.verbose:
command_options.append('-v')
if options.build:
command_options.append('--report-checkstyle=' + os.path.join(get_report_directory(), 'phpcs_results.xml'))
if options.exclude:
command_options.extend(['--ignore=' + ','.join(options.exclude)])
if options.include:
arguments.extend(options.include)
else:
arguments.extend(['../../application', '../../bin',
'../../library/Icinga'])
# Application invocation..
execute_command([application_path] + DEFAULT_ARGS +
command_options + arguments)
return 0
if __name__ == '__main__':
sys.exit(main())

View File

@ -1,24 +0,0 @@
#!/bin/sh
set -o nounset
SCRIPTNAME=$(readlink -f $0)
DIR=$(dirname $SCRIPTNAME)
PHPCS=$(which phpcs)
if [[ ! -x $PHPCS ]]; then
echo "PHPCS not found!"
exit 1
fi
# Make sure that the destination directory for logs and reports exists
mkdir -p $DIR/../../build/log
phpcs -p --standard=PSR2 --extensions=php --encoding=utf-8 \
--report-checkstyle=$DIR/../../build/log/phpcs_results.xml \
"$@" \
$DIR/../../application \
$DIR/../../library/Icinga \
$DIR/../../bin
exit 0

View File

@ -1,24 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<phpunit backupGlobals="true"
backupStaticAttributes="true"
colors="false"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
forceCoversAnnotation="false"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
strict="false"
verbose="false">
<logging>
<log type="coverage-clover" target="../../build/log/phpunit_coverage.xml"/>
<log type="junit" target="../../build/log/phpunit_results.xml" logIncompleteSkipped="true"/>
</logging>
<phpunit>
<testsuites>
<!--
Unit testing
@ -36,4 +17,4 @@
<directory>regression/</directory>
</testsuite>
</testsuites>
</phpunit>
</phpunit>

107
test/php/runtests Executable file
View File

@ -0,0 +1,107 @@
#!/usr/bin/env python
import os
import sys
import subprocess
from fnmatch import fnmatch
from optparse import OptionParser, BadOptionError, AmbiguousOptionError
APPLICATION = 'phpunit'
DEFAULT_ARGS = ['--strict', '--static-backup']
REPORT_DIRECTORY = '../../build/log'
class PassThroughOptionParser(OptionParser):
"""
An unknown option pass-through implementation of OptionParser.
When unknown arguments are encountered, bundle with largs and try again,
until rargs is depleted.
sys.exit(status) will still be called if a known argument is passed
incorrectly (e.g. missing arguments or bad argument types, etc.)
Borrowed from: http://stackoverflow.com/a/9307174
"""
def _process_args(self, largs, rargs, values):
while rargs:
try:
OptionParser._process_args(self, largs, rargs, values)
except (BadOptionError, AmbiguousOptionError), error:
largs.append(error.opt_str)
def execute_command(command, return_output=False, shell=False):
prog = subprocess.Popen(command, shell=shell,
stdout=subprocess.PIPE
if return_output
else None)
return prog.wait() if not return_output else \
prog.communicate()[0]
def get_report_directory():
path = os.path.abspath(REPORT_DIRECTORY)
try:
os.makedirs(REPORT_DIRECTORY)
except OSError:
pass
return path
def get_script_directory():
return os.path.dirname(os.path.abspath(sys.argv[0]))
def parse_commandline():
parser = PassThroughOptionParser(usage='%prog [options] [additional arguments'
' for {0}]'.format(APPLICATION))
parser.add_option('-b', '--build', action='store_true',
help='Enable reporting.')
parser.add_option('-v', '--verbose', action='store_true',
help='Be more verbose.')
parser.add_option('-i', '--include', metavar='PATTERN', action='store',
help='Include only specific files/test cases.')
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)
# 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())

View File

@ -1,26 +0,0 @@
#!/bin/sh
set -o nounset
SCRIPTNAME=$(readlink -f $0)
DIR=$(dirname $SCRIPTNAME)
PHPUNIT=$(which phpunit)
if [[ ! -x $PHPUNIT ]]; then
echo "PHPUnit not found!"
exit 1
fi
# Make sure that the destination directory for logs and reports exists
mkdir -p $DIR/../../build/log
cd $DIR
if [[ ! -x ./bin/extcmd_test ]]; then
make
fi;
$PHPUNIT "$@"
exit 0