@@ -1665,61 +1665,67 @@ final class SwiftDriverTests: XCTestCase {
16651665 }
16661666
16671667 func testProfileArgValidation( ) throws {
1668- XCTAssertThrowsError ( try Driver ( args: [ " swiftc " , " foo.swift " , " -profile-generate " , " -profile-use=profile.profdata " ] ) ) {
1669- XCTAssertEqual ( $0 as? Driver . Error , . conflictingOptions( . profileGenerate, . profileUse) )
1668+ try assertDriverDiagnostics ( args: [ " swiftc " , " foo.swift " , " -profile-generate " , " -profile-use=profile.profdata " ] ) {
1669+ $1. expect ( . error( Driver . Error. conflictingOptions ( . profileGenerate, . profileUse) ) )
1670+ $1. expect ( . error( Driver . Error. missingProfilingData ( " profile.profdata " ) ) )
16701671 }
16711672
1672- XCTAssertThrowsError ( try Driver ( args: [ " swiftc " , " foo.swift " , " -profile-use=profile.profdata " ] ) ) {
1673- XCTAssertEqual ( $0 as? Driver . Error , . missingProfilingData( " profile.profdata " ) )
1673+ try assertDriverDiagnostics ( args: [ " swiftc " , " foo.swift " , " -profile-use=profile.profdata " ] ) {
1674+ $1 . expect ( . error ( Driver . Error. missingProfilingData ( " profile.profdata " ) ) )
16741675 }
16751676
16761677 try withTemporaryDirectory { path in
16771678 try localFileSystem. writeFileContents ( path. appending ( component: " profile.profdata " ) , bytes: . init( ) )
1678- XCTAssertNoThrow ( try Driver ( args: [ " swiftc " , " -working-directory " , path. pathString, " foo.swift " , " -profile-use=profile.profdata " ] ) )
1679+ try assertNoDriverDiagnostics ( args: " swiftc " , " -working-directory " , path. pathString, " foo.swift " , " -profile-use=profile.profdata " )
16791680 }
16801681
16811682 try withTemporaryDirectory { path in
16821683 try localFileSystem. writeFileContents ( path. appending ( component: " profile.profdata " ) , bytes: . init( ) )
1683- XCTAssertThrowsError ( try Driver ( args: [ " swiftc " , " -working-directory " , path. pathString, " foo.swift " ,
1684- " -profile-use=profile.profdata,profile2.profdata " ] ) ) {
1685- guard case Driver . Error . missingProfilingData = $0 else {
1686- XCTFail ( )
1687- return
1688- }
1684+ try assertDriverDiagnostics ( args: [ " swiftc " , " -working-directory " , path. pathString, " foo.swift " ,
1685+ " -profile-use=profile.profdata,profile2.profdata " ] ) {
1686+ $1. expect ( . error( Driver . Error. missingProfilingData ( path. appending ( component: " profile2.profdata " ) . pathString) ) )
16891687 }
16901688 }
16911689 }
16921690
16931691 func testConditionalCompilationArgValidation( ) throws {
1694- XCTAssertThrowsError ( try Driver ( args: [ " swiftc " , " foo.swift " , " -DFOO=BAR " ] ) ) {
1695- XCTAssertEqual ( $0 as? Driver . Error , . cannotAssignToConditionalCompilationFlag( " FOO=BAR " ) )
1692+ try assertDriverDiagnostics ( args: [ " swiftc " , " foo.swift " , " -DFOO=BAR " ] ) {
1693+ $1 . expect ( . error ( Driver . Error. cannotAssignToConditionalCompilationFlag ( " FOO=BAR " ) ) )
16961694 }
16971695
1698- XCTAssertThrowsError ( try Driver ( args: [ " swiftc " , " foo.swift " , " -D-DFOO " ] ) ) {
1699- XCTAssertEqual ( $0 as? Driver . Error , . conditionalCompilationFlagHasRedundantPrefix( " -DFOO " ) )
1696+ try assertDriverDiagnostics ( args: [ " swiftc " , " foo.swift " , " -D-DFOO " ] ) {
1697+ $1 . expect ( . error ( Driver . Error. conditionalCompilationFlagHasRedundantPrefix ( " -DFOO " ) ) )
17001698 }
17011699
1702- XCTAssertThrowsError ( try Driver ( args: [ " swiftc " , " foo.swift " , " -Dnot-an-identifier " ] ) ) {
1703- XCTAssertEqual ( $0 as? Driver . Error , . conditionalCompilationFlagIsNotValidIdentifier( " not-an-identifier " ) )
1700+ try assertDriverDiagnostics ( args: [ " swiftc " , " foo.swift " , " -Dnot-an-identifier " ] ) {
1701+ $1 . expect ( . error ( Driver . Error. conditionalCompilationFlagIsNotValidIdentifier ( " not-an-identifier " ) ) )
17041702 }
17051703
1706- XCTAssertNoThrow ( try Driver ( args: [ " swiftc " , " foo.swift " , " -DFOO " ] ) )
1704+ try assertNoDriverDiagnostics ( args: " swiftc " , " foo.swift " , " -DFOO " )
17071705 }
17081706
17091707 func testFrameworkSearchPathArgValidation( ) throws {
1710- XCTAssertThrowsError ( try Driver ( args: [ " swiftc " , " foo.swift " , " -F/some/dir/xyz.framework " ] ) ) {
1711- XCTAssertEqual ( $0 as? Driver . Error , . frameworkSearchPathIncludesExtension( " /some/dir/xyz.framework " ) )
1708+ try assertDriverDiagnostics ( args: [ " swiftc " , " foo.swift " , " -F/some/dir/xyz.framework " ] ) {
1709+ $1 . expect ( . error ( Driver . Error. frameworkSearchPathIncludesExtension ( " /some/dir/xyz.framework " ) ) )
17121710 }
17131711
1714- XCTAssertThrowsError ( try Driver ( args: [ " swiftc " , " foo.swift " , " -F/some/dir/xyz.framework/ " ] ) ) {
1715- XCTAssertEqual ( $0 as? Driver . Error , . frameworkSearchPathIncludesExtension( " /some/dir/xyz.framework/ " ) )
1712+ try assertDriverDiagnostics ( args: [ " swiftc " , " foo.swift " , " -F/some/dir/xyz.framework/ " ] ) {
1713+ $1 . expect ( . error ( Driver . Error. frameworkSearchPathIncludesExtension ( " /some/dir/xyz.framework/ " ) ) )
17161714 }
17171715
1718- XCTAssertThrowsError ( try Driver ( args: [ " swiftc " , " foo.swift " , " -Fsystem " , " /some/dir/xyz.framework " ] ) ) {
1719- XCTAssertEqual ( $0 as? Driver . Error , . frameworkSearchPathIncludesExtension( " /some/dir/xyz.framework " ) )
1716+ try assertDriverDiagnostics ( args: [ " swiftc " , " foo.swift " , " -Fsystem " , " /some/dir/xyz.framework " ] ) {
1717+ $1 . expect ( . error ( Driver . Error. frameworkSearchPathIncludesExtension ( " /some/dir/xyz.framework " ) ) )
17201718 }
17211719
1722- XCTAssertNoThrow ( try Driver ( args: [ " swiftc " , " foo.swift " , " -Fsystem " , " /some/dir/ " ] ) )
1720+ try assertNoDriverDiagnostics ( args: " swiftc " , " foo.swift " , " -Fsystem " , " /some/dir/ " )
1721+ }
1722+
1723+ func testMultipleValidationFailures( ) throws {
1724+ try assertDiagnostics { engine, verifier in
1725+ verifier. expect ( . error( Driver . Error. conditionalCompilationFlagIsNotValidIdentifier ( " not-an-identifier " ) ) )
1726+ verifier. expect ( . error( Driver . Error. frameworkSearchPathIncludesExtension ( " /some/dir/xyz.framework " ) ) )
1727+ _ = try Driver ( args: [ " swiftc " , " foo.swift " , " -Dnot-an-identifier " , " -F/some/dir/xyz.framework " ] , diagnosticsEngine: engine)
1728+ }
17231729 }
17241730
17251731 // Test cases ported from Driver/macabi-environment.swift
@@ -2368,8 +2374,8 @@ final class SwiftDriverTests: XCTestCase {
23682374 }
23692375
23702376 do {
2371- XCTAssertThrowsError ( try Driver ( args: [ " swift " , " -no-warnings-as-errors " , " -warnings-as-errors " , " -suppress-warnings " , " foo.swift " ] ) ) {
2372- XCTAssertEqual ( $0 as? Driver . Error , Driver . Error. conflictingOptions ( . warningsAsErrors, . suppressWarnings) )
2377+ try assertDriverDiagnostics ( args: [ " swift " , " -no-warnings-as-errors " , " -warnings-as-errors " , " -suppress-warnings " , " foo.swift " ] ) {
2378+ $1 . expect ( . error ( Driver . Error. conflictingOptions ( . warningsAsErrors, . suppressWarnings) ) )
23732379 }
23742380 }
23752381
0 commit comments