@@ -16,7 +16,7 @@ import XCTest
16
16
import CToolingTestShim
17
17
18
18
final class SwiftDriverToolingInterfaceTests : XCTestCase {
19
- func testCreateCompilerInvocation ( ) throws {
19
+ func testCreateCompilerInvocationV2 ( ) throws {
20
20
try withTemporaryDirectory { path in
21
21
let inputFile = path. appending ( components: " test.swift " )
22
22
try localFileSystem. writeFileContents ( inputFile) { $0. send ( " public func foo() " ) }
@@ -93,6 +93,100 @@ final class SwiftDriverToolingInterfaceTests: XCTestCase {
93
93
}
94
94
}
95
95
96
+ func testCreateCompilerInvocationV3( ) throws {
97
+ try withTemporaryDirectory { path in
98
+ let inputFile = path. appending ( components: " test.swift " )
99
+ try localFileSystem. writeFileContents ( inputFile) { $0. send ( " public func foo() " ) }
100
+
101
+ let env = ProcessEnv . vars
102
+ let resolver = try ArgsResolver ( fileSystem: localFileSystem)
103
+ let executor = SimpleExecutor ( resolver: resolver, fileSystem: localFileSystem, env: env)
104
+
105
+ // Expected success scenarios:
106
+ do {
107
+ let testCommand = inputFile. description
108
+ var emittedDiagnostics : [ Diagnostic ] = [ ]
109
+ XCTAssertFalse ( getSingleFrontendInvocationFromDriverArgumentsV3 ( driverPath: " swiftc " ,
110
+ argList: testCommand. components ( separatedBy: " " ) ,
111
+ action: { _ in false } ,
112
+ diagnostics: & emittedDiagnostics,
113
+ diagnosticCallback: { _, _ in } ,
114
+ env: env,
115
+ executor: executor) )
116
+ }
117
+ do {
118
+ let testCommand = " -emit-executable " + inputFile. description + " main.swift lib.swift -module-name createCompilerInvocation -emit-module -emit-objc-header -o t.out "
119
+ var emittedDiagnostics : [ Diagnostic ] = [ ]
120
+ XCTAssertFalse ( getSingleFrontendInvocationFromDriverArgumentsV3 ( driverPath: " swiftc " ,
121
+ argList: testCommand. components ( separatedBy: " " ) ,
122
+ action: { _ in false } ,
123
+ diagnostics: & emittedDiagnostics,
124
+ diagnosticCallback: { _, _ in } ,
125
+ env: env,
126
+ executor: executor) )
127
+ }
128
+ do {
129
+ let testCommand = " -c " + inputFile. description + " main.swift lib.swift -module-name createCompilerInvocation -emit-module -emit-objc-header "
130
+ var emittedDiagnostics : [ Diagnostic ] = [ ]
131
+ XCTAssertFalse ( getSingleFrontendInvocationFromDriverArgumentsV3 ( driverPath: " swiftc " ,
132
+ argList: testCommand. components ( separatedBy: " " ) ,
133
+ action: { _ in false } ,
134
+ diagnostics: & emittedDiagnostics,
135
+ diagnosticCallback: { _, _ in } ,
136
+ env: env,
137
+ executor: executor) )
138
+ }
139
+ do {
140
+ let testCommand = inputFile. description + " -enable-batch-mode "
141
+ var emittedDiagnostics : [ Diagnostic ] = [ ]
142
+ XCTAssertFalse ( getSingleFrontendInvocationFromDriverArgumentsV3 ( driverPath: " swiftc " ,
143
+ argList: testCommand. components ( separatedBy: " " ) ,
144
+ action: { _ in false } ,
145
+ diagnostics: & emittedDiagnostics,
146
+ diagnosticCallback: { _, _ in } ,
147
+ env: env,
148
+ executor: executor) )
149
+ }
150
+ do { // Force no outputs
151
+ let testCommand = " -module-name foo -emit-module -emit-module-path /tmp/foo.swiftmodule -emit-objc-header -emit-objc-header-path /tmp/foo.h -enable-library-evolution -emit-module-interface -emit-module-interface-path /tmp/foo.swiftinterface -emit-library -emit-tbd -emit-tbd-path /tmp/foo.tbd -emit-dependencies -serialize-diagnostics " + inputFile. description
152
+ var resultingFrontendArgs : [ String ] = [ ]
153
+ var emittedDiagnostics : [ Diagnostic ] = [ ]
154
+ XCTAssertFalse ( getSingleFrontendInvocationFromDriverArgumentsV3 ( driverPath: " swiftc " ,
155
+ argList: testCommand. components ( separatedBy: " " ) ,
156
+ action: { args in
157
+ resultingFrontendArgs = args
158
+ return false
159
+ } ,
160
+ diagnostics: & emittedDiagnostics,
161
+ diagnosticCallback: { _, _ in } ,
162
+ env: env,
163
+ executor: executor,
164
+ forceNoOutputs: true ) )
165
+ XCTAssertFalse ( resultingFrontendArgs. contains ( " -emit-module-interface-path " ) )
166
+ XCTAssertFalse ( resultingFrontendArgs. contains ( " -emit-objc-header " ) )
167
+ XCTAssertFalse ( resultingFrontendArgs. contains ( " -emit-objc-header-path " ) )
168
+ XCTAssertFalse ( resultingFrontendArgs. contains ( " -emit-module-path " ) )
169
+ XCTAssertFalse ( resultingFrontendArgs. contains ( " -emit-tbd-path " ) )
170
+ }
171
+
172
+ // Expected failure scenarios:
173
+ do {
174
+ let testCommand = " -v " // No inputs
175
+ var emittedDiagnostics : [ Diagnostic ] = [ ]
176
+ XCTAssertTrue ( getSingleFrontendInvocationFromDriverArgumentsV3 ( driverPath: " swiftc " ,
177
+ argList: testCommand. components ( separatedBy: " " ) ,
178
+ action: { _ in false } ,
179
+ diagnostics: & emittedDiagnostics,
180
+ diagnosticCallback: { _, _ in } ,
181
+ env: env,
182
+ executor: executor) )
183
+ let errorMessage = try XCTUnwrap ( emittedDiagnostics. first? . message. text)
184
+ XCTAssertEqual ( errorMessage, " unable to handle compilation, expected exactly one frontend job " )
185
+ }
186
+ }
187
+ }
188
+
189
+
96
190
func testCreateCompilerInvocationCAPI( ) throws {
97
191
try withTemporaryDirectory { path in
98
192
let inputFile = path. appending ( components: " test.swift " )
0 commit comments