]> git.saurik.com Git - apple/security.git/blob - tests/TrustTests/gen_test_plist.py
Security-59754.41.1.tar.gz
[apple/security.git] / tests / TrustTests / gen_test_plist.py
1 #!/usr/bin/python
2 import sys
3 import Foundation
4 from glob import glob
5 import re
6 import os
7
8 test_dir = sys.argv[1]
9 outfile = sys.argv[2]
10
11 test_plist = Foundation.NSMutableDictionary.dictionary()
12 test_plist['Project'] = 'Security'
13 test_list = Foundation.NSMutableArray.array()
14
15 test_files = glob(test_dir + '/*/*.m')
16
17 for filename in test_files:
18 f = open(filename, 'r')
19 for line in f:
20 match = re.search('@interface ([a-zA-Z0-9_]+) ?: ?Trust[a-zA-Z0-9_]+TestCase', line)
21 if match:
22 regex_string = test_dir + '/([a-zA-Z0-9_]+/)'
23 test_dir_match = re.search(regex_string, filename)
24 if not test_dir_match:
25 print 'failed to find test dir name for ' + filename + " with regex " + regex_string
26 sys.exit(1)
27 test_dictionary = Foundation.NSMutableDictionary.dictionary()
28 test_dictionary['TestName'] = test_dir_match.group(1) + match.group(1)
29 test_dictionary['ShowSubtestResults']= True
30 test_dictionary['WorkingDirectory'] = '/AppleInternal/XCTests/com.apple.security/'
31 test_dictionary['AsRoot'] = True
32
33 test_command = Foundation.NSMutableArray.array()
34 test_command.append('/AppleInternal/CoreOS/tests/Security/TrustTests')
35 test_command.append('-c')
36 test_command.append(match.group(1))
37 test_command.append('-t')
38 test_command.append('TrustTests')
39
40 test_dictionary['Command'] = test_command
41
42 test_list.append(test_dictionary)
43 f.close()
44
45 test_plist['Tests'] = test_list
46
47 out_dir = os.path.dirname(outfile)
48 if not os.path.exists(out_dir):
49 os.makedirs(out_dir)
50 success = test_plist.writeToFile_atomically_(outfile, 1)
51 if not success:
52 print "test plist failed to write, error!"
53 sys.exit(1)