@@ -2219,6 +2219,26 @@ final class SwiftDriverTests: XCTestCase {
2219
2219
}
2220
2220
}
2221
2221
}
2222
+
2223
+ func testVFSOverlay( ) throws {
2224
+ do {
2225
+ var driver = try Driver ( args: [ " swiftc " , " -c " , " -vfsoverlay " , " overlay.yaml " , " foo.swift " ] )
2226
+ let plannedJobs = try driver. planBuild ( )
2227
+ XCTAssertEqual ( plannedJobs. count, 1 )
2228
+ XCTAssertEqual ( plannedJobs [ 0 ] . kind, . compile)
2229
+ XCTAssert ( plannedJobs [ 0 ] . commandLine. contains ( subsequence: [ . flag( " -vfsoverlay " ) , . path( . relative( RelativePath ( " overlay.yaml " ) ) ) ] ) )
2230
+ }
2231
+
2232
+ // Verify that the overlays are passed to the frontend in the same order.
2233
+ do {
2234
+ var driver = try Driver ( args: [ " swiftc " , " -c " , " -vfsoverlay " , " overlay1.yaml " , " -vfsoverlay " , " overlay2.yaml " , " -vfsoverlay " , " overlay3.yaml " , " foo.swift " ] )
2235
+ let plannedJobs = try driver. planBuild ( )
2236
+ XCTAssertEqual ( plannedJobs. count, 1 )
2237
+ XCTAssertEqual ( plannedJobs [ 0 ] . kind, . compile)
2238
+ print ( plannedJobs [ 0 ] . commandLine)
2239
+ XCTAssert ( plannedJobs [ 0 ] . commandLine. contains ( subsequence: [ . flag( " -vfsoverlay " ) , . path( . relative( RelativePath ( " overlay1.yaml " ) ) ) , . flag( " -vfsoverlay " ) , . path( . relative( RelativePath ( " overlay2.yaml " ) ) ) , . flag( " -vfsoverlay " ) , . path( . relative( RelativePath ( " overlay3.yaml " ) ) ) ] ) )
2240
+ }
2241
+ }
2222
2242
}
2223
2243
2224
2244
func assertString(
@@ -2231,3 +2251,26 @@ func assertString(
2231
2251
\( message. isEmpty ? " " : " : " + message)
2232
2252
""" , file: file, line: line)
2233
2253
}
2254
+
2255
+ fileprivate extension Array where Element: Equatable {
2256
+ /// Returns true if the receiver contains the given elements as a subsequence
2257
+ /// (i.e., all elements are present, contiguous, and in the same order).
2258
+ ///
2259
+ /// A naïve implementation has been used here rather than a more efficient
2260
+ /// general purpose substring search algorithm since the arrays being tested
2261
+ /// are relatively small.
2262
+ func contains< Elements: Collection > (
2263
+ subsequence: Elements
2264
+ ) -> Bool where Elements. Element == Element {
2265
+ precondition ( !subsequence. isEmpty, " Subsequence may not be empty " )
2266
+
2267
+ let subsequenceCount = subsequence. count
2268
+ for index in 0 ..< ( self . count - subsequence. count) {
2269
+ let subsequenceEnd = index + subsequenceCount
2270
+ if self [ index..< subsequenceEnd] . elementsEqual ( subsequence) {
2271
+ return true
2272
+ }
2273
+ }
2274
+ return false
2275
+ }
2276
+ }
0 commit comments