import sys
import Foundation
from glob import glob
import re
import os
import pprint
test_dir = sys.argv[1]
outfile = sys.argv[2]
test_plist = Foundation.NSMutableDictionary.dictionary()
test_plist['BATSConfigVersion'] = '0.1.0'
test_plist['Project'] = 'Security'
test_list = Foundation.NSMutableArray.array()
test_files = glob(test_dir + '/*.m') + glob(test_dir + '/*.h')
def get_class_names():
test_classes = ['CKKSLaunchSequenceTests']
for filename in test_files:
f = open(filename, 'r')
for line in f:
match = re.search('@interface ([a-zA-Z0-9_]+) ?: ?CloudKitKeychain[a-zA-Z0-9_]*TestsBase', line)
if match:
test_classes.append(match.group(1))
match = re.search('@interface ([a-zA-Z0-9_]+) ?: ?XCTestCase', line)
if match:
test_classes.append(match.group(1))
match = re.search('@interface ([a-zA-Z0-9_]+) ?: ?CloudKitMockXCTest', line)
if match:
test_classes.append(match.group(1))
f.close()
base_classes = ['CloudKitMockXCTest', 'CloudKitKeychainSyncingMockXCTest', 'CKKSCloudKitTests']
for base_class in base_classes:
test_classes = [x for x in test_classes if base_class != x]
return test_classes
for x in get_class_names():
test_dictionary = Foundation.NSMutableDictionary.dictionary()
test_dictionary['TestName'] = x
test_dictionary['Timeout']= 1200
test_dictionary['ShowSubtestResults']= True
test_dictionary['WorkingDirectory'] = '/AppleInternal/XCTests/com.apple.security/'
test_command = Foundation.NSMutableArray.array()
test_command.append('BATS_XCTEST_CMD')
test_command.append('-XCTest')
test_command.append('{}'.format(x))
test_command.append('CKKSTests.xctest')
test_dictionary['Command'] = test_command
test_list.append(test_dictionary)
test_plist['Tests'] = test_list
out_dir = os.path.dirname(outfile)
if not os.path.exists(out_dir):
os.makedirs(out_dir)
success = test_plist.writeToFile_atomically_(outfile, 1)
if not success:
print "test plist failed to write, error!"
sys.exit(1)