| 
									
										
										
										
											2016-03-13 13:37:58 +00:00
										 |  |  | #!/usr/bin/python | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import argparse | 
					
						
							|  |  |  | import glob | 
					
						
							|  |  |  | import os | 
					
						
							|  |  |  | import shutil | 
					
						
							|  |  |  | import subprocess | 
					
						
							|  |  |  | import sys | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-17 12:56:46 +00:00
										 |  |  | if sys.platform not in ('darwin', 'linux2'): | 
					
						
							| 
									
										
										
										
											2016-03-13 13:37:58 +00:00
										 |  |  | 	print 'Tests are only enabled on Linux.' | 
					
						
							|  |  |  | 	exit(0) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | parser = argparse.ArgumentParser() | 
					
						
							|  |  |  | parser.add_argument('tests', nargs=argparse.REMAINDER) | 
					
						
							|  |  |  | arguments = parser.parse_args() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 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') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-21 20:19:23 +00:00
										 |  |  | for test in sorted(selectedTests): | 
					
						
							| 
									
										
										
										
											2016-03-13 13:37:58 +00:00
										 |  |  | 	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) | 
					
						
							| 
									
										
										
										
											2016-12-21 20:19:23 +00:00
										 |  |  | 	interrupted = False | 
					
						
							| 
									
										
										
										
											2016-03-13 13:37:58 +00:00
										 |  |  | 	stdout, stderr = process.communicate() | 
					
						
							| 
									
										
										
										
											2016-12-21 20:19:23 +00:00
										 |  |  | 	if interrupted or process.returncode == 0: | 
					
						
							| 
									
										
										
										
											2016-04-17 12:56:46 +00:00
										 |  |  | 		if stdout.strip() == "SKIP": | 
					
						
							|  |  |  | 			print 'SKIPPED', test | 
					
						
							|  |  |  | 		else: | 
					
						
							|  |  |  | 			print 'PASSED', test | 
					
						
							| 
									
										
										
										
											2016-03-13 13:37:58 +00:00
										 |  |  | 		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.' | 
					
						
							| 
									
										
										
										
											2016-03-13 14:18:47 +00:00
										 |  |  | exit(failCount) |