@@ -303,100 +303,18 @@ private struct BasicTests {
303
303
}
304
304
305
305
@Test
306
- func testSwiftTestWithResources( ) throws {
307
- try withTemporaryDirectory { tempDir in
308
- let packagePath = tempDir. appending ( component: " swiftTestResources " )
309
- try localFileSystem. createDirectory ( packagePath)
310
- try localFileSystem. writeFileContents (
311
- packagePath. appending ( component: " Package.swift " ) ,
312
- bytes: ByteString (
313
- encodingAsUTF8: """
314
- // swift-tools-version:5.3
315
- import PackageDescription
316
-
317
- let package = Package(
318
- name: " AwesomeResources " ,
319
- targets: [
320
- .target(name: " AwesomeResources " , resources: [.copy( " hello.txt " )]),
321
- .testTarget(name: " AwesomeResourcesTest " , dependencies: [ " AwesomeResources " ], resources: [.copy( " world.txt " )])
322
- ]
323
- )
324
- """
325
- )
326
- )
327
- try localFileSystem. createDirectory ( packagePath. appending ( component: " Sources " ) )
328
- try localFileSystem. createDirectory (
329
- packagePath. appending ( components: " Sources " , " AwesomeResources " )
330
- )
331
- try localFileSystem. writeFileContents (
332
- packagePath. appending (
333
- components: " Sources " , " AwesomeResources " , " AwesomeResource.swift "
334
- ) ,
335
- bytes: ByteString (
336
- encodingAsUTF8: """
337
- import Foundation
338
-
339
- public struct AwesomeResource {
340
- public init() {}
341
- public let hello = try! String(contentsOf: Bundle.module.url(forResource: " hello " , withExtension: " txt " )!)
342
- }
306
+ func testSwiftTestWithResources( ) async throws {
307
+ try await fixture ( name: " Miscellaneous/PackageWithResource/ " ) { packagePath in
343
308
344
- """
345
- )
346
- )
347
-
348
- try localFileSystem. writeFileContents (
349
- packagePath. appending ( components: " Sources " , " AwesomeResources " , " hello.txt " ) ,
350
- bytes: ByteString ( encodingAsUTF8: " hello " )
351
- )
352
-
353
- try localFileSystem. createDirectory ( packagePath. appending ( component: " Tests " ) )
354
- try localFileSystem. createDirectory (
355
- packagePath. appending ( components: " Tests " , " AwesomeResourcesTest " )
356
- )
357
-
358
- try localFileSystem. writeFileContents (
359
- packagePath. appending ( components: " Tests " , " AwesomeResourcesTest " , " world.txt " ) ,
360
- bytes: ByteString ( encodingAsUTF8: " world " )
361
- )
362
-
363
- try localFileSystem. writeFileContents (
364
- packagePath. appending ( components: " Tests " , " AwesomeResourcesTest " , " MyTests.swift " ) ,
365
- bytes: ByteString (
366
- encodingAsUTF8: """
367
- import XCTest
368
- import Foundation
369
- import AwesomeResources
370
-
371
- final class MyTests: XCTestCase {
372
- func testFoo() {
373
- XCTAssertTrue(AwesomeResource().hello == " hello " )
374
- }
375
- func testBar() {
376
- let world = try! String(contentsOf: Bundle.module.url(forResource: " world " , withExtension: " txt " )!)
377
- XCTAssertTrue(world == " world " )
378
- }
379
- }
380
- """
381
- )
382
- )
383
-
384
- let shOutput = try await executeSwiftTest (
309
+ let result = try await executeSwiftTest (
385
310
packagePath, extraArgs: [ " --filter " , " MyTests.* " , " --vv " ]
386
311
)
387
312
388
313
// Check the test log.
389
- let checker = StringChecker ( string: shOutput. stdout)
390
- let testSuitePassedCheck : String
391
- #if os(Windows)
392
- // CHORE: This is not the right solution
393
- testSuitePassedCheck = #"Test Suite \'MyTests\' passed"#
394
- #else
395
- testSuitePassedCheck = " Test Suite 'MyTests' passed "
396
- #endif
397
- #expect( checker. check ( . contains( " Test Suite 'MyTests' started " ) ) , " stdout: ' \( shOutput. stdout) ' \n stderr:' \( shOutput. stderr) ' " )
398
- #expect( checker. check ( . contains( testSuitePassedCheck) ) , " stdout: ' \( shOutput. stdout) ' \n stderr:' \( shOutput. stderr) ' " )
399
- #expect( checker. check ( . contains( " Executed 2 tests, with 0 failures " ) ) , " stdout: ' \( shOutput. stdout) ' \n stderr:' \( shOutput. stderr) ' " )
314
+ let checker = StringChecker ( string: result. stdout)
315
+ #expect( checker. check ( . contains( " Test Suite 'MyTests' started " ) ) , " stdout: ' \( result. stdout) ' \n stderr:' \( result. stderr) ' " )
316
+ #expect( checker. check ( . contains( " Test Suite 'MyTests' passed " ) ) , " stdout: ' \( result. stdout) ' \n stderr:' \( result. stderr) ' " )
317
+ #expect( checker. check ( . contains( " Executed 2 tests, with 0 failures " ) ) , " stdout: ' \( result. stdout) ' \n stderr:' \( result. stderr) ' " )
400
318
}
401
319
}
402
320
}
0 commit comments