I think this fixes tests, and makes them runnable from continuous integration.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3161 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
		| @@ -1,36 +1,68 @@ | ||||
| #!/bin/bash | ||||
| #!/usr/bin/python | ||||
|  | ||||
| export ROOT=$(cd $(dirname ${BASH_SOURCE[0]})/..; pwd) | ||||
| TMP=$ROOT/tmp | ||||
| LOGS=$ROOT/logs | ||||
| TESTS=$ROOT/tests | ||||
| export SANDBOXOS=$ROOT/sandboxos | ||||
| import argparse | ||||
| import glob | ||||
| import os | ||||
| import shutil | ||||
| import subprocess | ||||
| import sys | ||||
|  | ||||
| mkdir $TMP 2> /dev/null | ||||
| mkdir $LOGS 2> /dev/null | ||||
| if sys.platform != 'linux2': | ||||
| 	print 'Tests are only enabled on Linux.' | ||||
| 	exit(0) | ||||
|  | ||||
| REQUESTED_TESTS=$* | ||||
| if [[ -z $REQUESTED_TESTS ]]; then | ||||
| 	REQUESTED_TESTS=$(ls $TESTS/* | xargs basename -a) | ||||
| fi | ||||
| parser = argparse.ArgumentParser() | ||||
| parser.add_argument('tests', nargs=argparse.REMAINDER) | ||||
| arguments = parser.parse_args() | ||||
|  | ||||
| for NAME in $REQUESTED_TESTS; do | ||||
| 	TEST=$TESTS/$NAME | ||||
| 	echo -n "$(basename $TEST) " | ||||
| 	rm -rf $TMP/* | ||||
| 	pushd $TMP > /dev/null | ||||
| 	export LOGDIR=$LOGS/$NAME | ||||
| 	mkdir $LOGDIR 2> /dev/null | ||||
| 	unbuffer $TEST > $LOGDIR/stdout.log 2> $LOGDIR/stderr.log | ||||
| 	RESULT=$? | ||||
| 	popd > /dev/null | ||||
| 	if [[ $RESULT != 0 ]]; then | ||||
| 		echo "FAILED (with exit code $RESULT)" | ||||
| 		exit $RESULT | ||||
| 	else | ||||
| 		echo "SUCCESS" | ||||
| 	fi | ||||
| done | ||||
| root = os.path.dirname(os.path.join(os.getcwd(), os.path.dirname(__file__))) | ||||
| tmp = os.path.join(root, 'tmp') | ||||
| logs = os.path.join(root, 'logs') | ||||
| tests = os.path.join(root, 'tests') | ||||
| executable = os.path.join(root, 'tildefriends') | ||||
|  | ||||
| echo | ||||
| echo "All tests completed successfully." | ||||
| if not os.path.isdir(logs): | ||||
| 	os.makedirs(logs) | ||||
|  | ||||
| selectedTests = set() | ||||
| if not arguments.tests: | ||||
| 	for test in glob.glob(os.path.join(tests, '*')): | ||||
| 		selectedTests.add(test) | ||||
| for pattern in arguments.tests: | ||||
| 	for match in glob.glob(os.path.join(tests, '*' + pattern + '*')): | ||||
| 		selectedTests.add(match) | ||||
|  | ||||
| env = os.environ.copy() | ||||
| env['TILDEFRIENDS'] = executable | ||||
| env['LOGDIR'] = logs | ||||
|  | ||||
| def indent(text): | ||||
| 	return '\n'.join('\t' + line for line in text.split('\n')) | ||||
|  | ||||
| passCount = 0 | ||||
| failCount = 0 | ||||
|  | ||||
| for test in selectedTests: | ||||
| 	if os.path.isdir(tmp): | ||||
| 		shutil.rmtree(tmp) | ||||
| 	if not os.path.isdir(tmp): | ||||
| 		os.makedirs(tmp) | ||||
|  | ||||
| 	process = subprocess.Popen(['bash', test], stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=tmp, env=env) | ||||
| 	stdout, stderr = process.communicate() | ||||
| 	if process.returncode == 0: | ||||
| 		print 'PASSED', test | ||||
| 		passCount += 1 | ||||
| 	else: | ||||
| 		print 'FAILED', test | ||||
| 		print 'RETURNED:', process.returncode | ||||
| 		print 'STDOUT:' | ||||
| 		print indent(stdout) | ||||
| 		print 'STDERR:' | ||||
| 		print indent(stderr) | ||||
| 		failCount += 1 | ||||
|  | ||||
| 	if os.path.isdir(tmp): | ||||
| 		shutil.rmtree(tmp) | ||||
|  | ||||
| print passCount, 'tests passed. ', failCount, 'tests failed.' | ||||
|   | ||||
		Reference in New Issue
	
	Block a user