@@ -38,4 +38,105 @@ public class ParserTests: XCTestCase {
38
38
} ( ) )
39
39
}
40
40
}
41
+
42
+ func testSDKParse( ) throws {
43
+ if #available( macOS 13 . 0 , * ) {
44
+ let platformsRoot = URL ( fileURLWithPath: " /Applications/Xcode-SummitE.app/Contents/Developer/Platforms " )
45
+ let platformURLs = try FileManager . default
46
+ . contentsOfDirectory ( at: platformsRoot, includingPropertiesForKeys: nil )
47
+ . filter ( { $0. pathExtension == " platform " } )
48
+ for platformURL in platformURLs {
49
+ print ( " ====================== STARTING \( platformURL. lastPathComponent) ======================== " )
50
+ defer {
51
+ print ( " ====================== LEAVING \( platformURL. lastPathComponent) ======================== " )
52
+ }
53
+ let sdkRoot = platformURL
54
+ . appending ( path: " Developer " )
55
+ . appending ( path: " SDKs " )
56
+ guard
57
+ let sdkURLs = try ? FileManager . default
58
+ . contentsOfDirectory ( at: sdkRoot, includingPropertiesForKeys: nil )
59
+ . filter ( { $0. pathExtension == " sdk " } )
60
+ else {
61
+ print ( " ====================== SKIPPING \( platformURL. lastPathComponent) ======================== " )
62
+ continue
63
+ }
64
+ for sdkURL in sdkURLs {
65
+ var passed = 0
66
+ var failed = 0
67
+ var skipped = 0
68
+ print ( " ====================== STARTING \( sdkURL. lastPathComponent) ======================== " )
69
+ defer {
70
+ print ( " >>> STATS Passed: \( passed) , Failed: \( failed) , Skipped: \( skipped) " )
71
+ print ( " ====================== LEAVING \( sdkURL. lastPathComponent) ======================== " )
72
+ }
73
+
74
+ let frameworksRoot = sdkURL
75
+ . appending ( path: " System " )
76
+ . appending ( path: " Library " )
77
+ . appending ( path: " Frameworks " )
78
+ guard
79
+ let frameworkURLs = try ? FileManager . default
80
+ . contentsOfDirectory ( at: frameworksRoot, includingPropertiesForKeys: nil )
81
+ . filter ( { $0. pathExtension == " framework " } )
82
+ else {
83
+ continue
84
+ }
85
+ for frameworkURL in frameworkURLs {
86
+ let modulesRoot = frameworkURL
87
+ . appending ( path: " Modules " )
88
+ var isDir : ObjCBool = false
89
+ guard FileManager . default. fileExists ( atPath: modulesRoot. path ( ) , isDirectory: & isDir) , isDir. boolValue else {
90
+ print ( " >>> Skipping \( frameworkURL. lastPathComponent) : It is not modular " )
91
+ skipped += 1
92
+ continue
93
+ }
94
+
95
+ let expectedSwiftModuleName = frameworkURL. deletingPathExtension ( ) . lastPathComponent. appending ( " .swiftmodule " )
96
+ let swiftModuleRoot = modulesRoot. appending ( path: expectedSwiftModuleName)
97
+ guard FileManager . default. fileExists ( atPath: swiftModuleRoot. path ( ) , isDirectory: & isDir) , isDir. boolValue else {
98
+ print ( " >>> Skipping \( frameworkURL. lastPathComponent) : It does not contain Swift " )
99
+ skipped += 1
100
+ continue
101
+ }
102
+
103
+ let interfaceURLs = FileManager . default
104
+ . enumerator ( at: swiftModuleRoot, includingPropertiesForKeys: nil ) !
105
+ . compactMap ( { $0 as? URL } )
106
+ . filter ( { $0. pathExtension == " swiftinterface " } )
107
+
108
+ for interfaceURL in interfaceURLs {
109
+ XCTAssertNoThrow ( try {
110
+ let fileContents = try String ( contentsOf: interfaceURL)
111
+ let parsed = try Parser . parse ( source: fileContents)
112
+ AssertStringsEqualWithDiff ( " \( parsed) " , fileContents)
113
+ let diagnostics = ParseDiagnosticsGenerator . diagnostics ( for: parsed)
114
+ if !diagnostics. isEmpty {
115
+ var locationAndDiagnostics : [ String ] = [ ]
116
+ let locationConverter = SourceLocationConverter ( file: interfaceURL. lastPathComponent, tree: parsed)
117
+ for diag in diagnostics {
118
+ let location = diag. location ( converter: locationConverter)
119
+ let message = diag. message
120
+ locationAndDiagnostics. append ( " \( location) : \( message) " )
121
+ }
122
+ XCTFail ( """
123
+ Received the following diagnostics while parsing \( interfaceURL)
124
+ \( locationAndDiagnostics. joined ( separator: " \n " ) )
125
+ """ )
126
+ failed += 1
127
+ } else {
128
+ passed += 1
129
+ }
130
+ } ( ) )
131
+ }
132
+ }
133
+
134
+ let privateFrameworksRoot = sdkURL
135
+ . appending ( path: " System " )
136
+ . appending ( path: " Library " )
137
+ . appending ( path: " PrivateFrameworks " )
138
+ }
139
+ }
140
+ }
141
+ }
41
142
}
0 commit comments