10
10
//
11
11
//===----------------------------------------------------------------------===//
12
12
13
- import Foundation
13
+ @testable import Commands
14
+ @testable import CoreCommands
14
15
16
+ import Foundation
15
17
import Basics
16
- import Commands
17
18
import struct SPMBuildCore. BuildSystemProvider
18
19
import enum PackageModel. BuildConfiguration
19
20
import PackageModel
20
21
import _InternalTestSupport
21
22
import TSCTestSupport
22
23
import Testing
23
24
25
+ import struct ArgumentParser. ExitCode
26
+ import protocol ArgumentParser. AsyncParsableCommand
27
+ import class TSCBasic. BufferedOutputByteStream
28
+
24
29
fileprivate func execute(
25
30
_ args: [ String ] ,
26
31
packagePath: AbsolutePath ? = nil ,
@@ -1178,165 +1183,117 @@ struct TestCommandTests {
1178
1183
struct LLDBTests {
1179
1184
@Test ( arguments: SupportedBuildSystemOnAllPlatforms)
1180
1185
func lldbWithParallelThrowsError( buildSystem: BuildSystemProvider . Kind ) async throws {
1181
- let configuration = BuildConfiguration . debug
1182
- try await fixture ( name: " Miscellaneous/EchoExecutable " ) { fixturePath in
1183
- let error = await #expect( throws: SwiftPMError . self) {
1184
- try await execute (
1185
- [ " --debugger " , " --parallel " ] ,
1186
- packagePath: fixturePath,
1187
- configuration: configuration,
1188
- buildSystem: buildSystem
1189
- )
1190
- }
1186
+ let args = args ( [ " --debugger " , " --parallel " ] , for: buildSystem)
1187
+ let command = try #require( SwiftTestCommand . parseAsRoot ( args) as? SwiftTestCommand )
1188
+ let ( state, outputStream) = try commandState ( )
1191
1189
1192
- guard case let SwiftPMError . executionFailure( _, stdout, stderr) = try #require( error) else {
1193
- Issue . record ( " Incorrect error was raised. " )
1194
- return
1195
- }
1196
-
1197
- #expect(
1198
- stderr. contains ( " error: --debugger cannot be used with --parallel (debugging requires sequential execution) " ) ,
1199
- " got stdout: \( stdout) , stderr: \( stderr) " ,
1200
- )
1190
+ let error = await #expect( throws: ExitCode . self) {
1191
+ try await command. run ( state)
1201
1192
}
1193
+
1194
+ #expect( error == ExitCode . failure, " Expected ExitCode.failure, got \( String ( describing: error) ) " )
1195
+
1196
+ let errorDescription = outputStream. bytes. description
1197
+ #expect(
1198
+ errorDescription. contains ( " --debugger cannot be used with --parallel " ) ,
1199
+ " Expected error about incompatible flags, got: \( errorDescription) "
1200
+ )
1202
1201
}
1203
1202
1204
1203
@Test ( arguments: SupportedBuildSystemOnAllPlatforms)
1205
1204
func lldbWithNumWorkersThrowsError( buildSystem: BuildSystemProvider . Kind ) async throws {
1206
- let configuration = BuildConfiguration . debug
1207
- try await fixture ( name: " Miscellaneous/EchoExecutable " ) { fixturePath in
1208
- let error = await #expect( throws: SwiftPMError . self) {
1209
- try await execute (
1210
- [ " --debugger " , " --parallel " , " --num-workers " , " 2 " ] ,
1211
- packagePath: fixturePath,
1212
- configuration: configuration,
1213
- buildSystem: buildSystem,
1214
- )
1215
- }
1216
- guard case let SwiftPMError . executionFailure( _, stdout, stderr) = try #require( error) else {
1217
- Issue . record ( " Incorrect error was raised. " )
1218
- return
1219
- }
1205
+ let args = args ( [ " --debugger " , " --parallel " , " --num-workers " , " 2 " ] , for: buildSystem)
1206
+ let command = try #require( SwiftTestCommand . parseAsRoot ( args) as? SwiftTestCommand )
1207
+ let ( state, outputStream) = try commandState ( )
1220
1208
1221
- // Should hit the --parallel error first since validation is done in order
1222
- #expect(
1223
- stderr. contains ( " error: --debugger cannot be used with --parallel (debugging requires sequential execution) " ) ,
1224
- " got stdout: \( stdout) , stderr: \( stderr) " ,
1225
- )
1209
+ let error = await #expect( throws: ExitCode . self) {
1210
+ try await command. run ( state)
1226
1211
}
1212
+
1213
+ #expect( error == ExitCode . failure, " Expected ExitCode.failure, got \( String ( describing: error) ) " )
1214
+
1215
+ let errorDescription = outputStream. bytes. description
1216
+ // Should hit the --parallel error first since validation is done in order
1217
+ #expect(
1218
+ errorDescription. contains ( " --debugger cannot be used with --parallel " ) ,
1219
+ " Expected error about incompatible flags, got: \( errorDescription) "
1220
+ )
1227
1221
}
1228
1222
1229
1223
@Test ( arguments: SupportedBuildSystemOnAllPlatforms)
1230
1224
func lldbWithNumWorkersOnlyThrowsError( buildSystem: BuildSystemProvider . Kind ) async throws {
1231
- let configuration = BuildConfiguration . debug
1232
- try await fixture ( name: " Miscellaneous/EchoExecutable " ) { fixturePath in
1233
- let error = await #expect( throws: SwiftPMError . self) {
1234
- try await execute (
1235
- [ " --debugger " , " --num-workers " , " 2 " ] ,
1236
- packagePath: fixturePath,
1237
- configuration: configuration,
1238
- buildSystem: buildSystem,
1239
- )
1240
- }
1241
- guard case let SwiftPMError . executionFailure( _, stdout, stderr) = try #require( error) else {
1242
- Issue . record ( " Incorrect error was raised. " )
1243
- return
1244
- }
1225
+ let args = args ( [ " --debugger " , " --num-workers " , " 2 " ] , for: buildSystem)
1226
+ let command = try #require( SwiftTestCommand . parseAsRoot ( args) as? SwiftTestCommand )
1227
+ let ( state, outputStream) = try commandState ( )
1245
1228
1246
- #expect(
1247
- stderr. contains ( " error: --debugger cannot be used with --num-workers (debugging requires sequential execution) " ) ,
1248
- " got stdout: \( stdout) , stderr: \( stderr) " ,
1249
- )
1229
+ let error = await #expect( throws: ExitCode . self) {
1230
+ try await command. run ( state)
1250
1231
}
1232
+
1233
+ #expect( error == ExitCode . failure, " Expected ExitCode.failure, got \( String ( describing: error) ) " )
1234
+
1235
+ let errorDescription = outputStream. bytes. description
1236
+ #expect(
1237
+ errorDescription. contains ( " --debugger cannot be used with --num-workers " ) ,
1238
+ " Expected error about incompatible flags, got: \( errorDescription) "
1239
+ )
1251
1240
}
1252
1241
1253
1242
@Test ( arguments: SupportedBuildSystemOnAllPlatforms)
1254
1243
func lldbWithListTestsThrowsError( buildSystem: BuildSystemProvider . Kind ) async throws {
1255
- let configuration = BuildConfiguration . debug
1256
- try await fixture ( name: " Miscellaneous/EchoExecutable " ) { fixturePath in
1257
- let error = await #expect( throws: SwiftPMError . self) {
1258
- try await execute (
1259
- [ " --debugger " , " --list-tests " ] ,
1260
- packagePath: fixturePath,
1261
- configuration: configuration,
1262
- buildSystem: buildSystem,
1263
- )
1264
- }
1265
- guard case let SwiftPMError . executionFailure( _, stdout, stderr) = try #require( error) else {
1266
- Issue . record ( " Incorrect error was raised. " )
1267
- return
1268
- }
1244
+ let args = args ( [ " --debugger " , " --list-tests " ] , for: buildSystem)
1245
+ let command = try #require( SwiftTestCommand . parseAsRoot ( args) as? SwiftTestCommand )
1246
+ let ( state, outputStream) = try commandState ( )
1269
1247
1270
- #expect(
1271
- stderr. contains ( " error: --debugger cannot be used with --list-tests (use 'swift test list' for listing tests) " ) ,
1272
- " got stdout: \( stdout) , stderr: \( stderr) " ,
1273
- )
1248
+ let error = await #expect( throws: ExitCode . self) {
1249
+ try await command. run ( state)
1274
1250
}
1251
+
1252
+ #expect( error == ExitCode . failure, " Expected ExitCode.failure, got \( String ( describing: error) ) " )
1253
+
1254
+ let errorDescription = outputStream. bytes. description
1255
+ #expect(
1256
+ errorDescription. contains ( " --debugger cannot be used with --list-tests " ) ,
1257
+ " Expected error about incompatible flags, got: \( errorDescription) "
1258
+ )
1275
1259
}
1276
1260
1277
1261
@Test ( arguments: SupportedBuildSystemOnAllPlatforms)
1278
1262
func lldbWithShowCodecovPathThrowsError( buildSystem: BuildSystemProvider . Kind ) async throws {
1279
- let configuration = BuildConfiguration . debug
1280
- try await fixture ( name: " Miscellaneous/EchoExecutable " ) { fixturePath in
1281
- let error = await #expect( throws: SwiftPMError . self) {
1282
- try await execute (
1283
- [ " --debugger " , " --show-codecov-path " ] ,
1284
- packagePath: fixturePath,
1285
- configuration: configuration,
1286
- buildSystem: buildSystem,
1287
- )
1288
- }
1289
- guard case let SwiftPMError . executionFailure( _, stdout, stderr) = try #require( error) else {
1290
- Issue . record ( " Incorrect error was raised. " )
1291
- return
1292
- }
1263
+ let args = args ( [ " --debugger " , " --show-codecov-path " ] , for: buildSystem)
1264
+ let command = try #require( SwiftTestCommand . parseAsRoot ( args) as? SwiftTestCommand )
1265
+ let ( state, outputStream) = try commandState ( )
1293
1266
1294
- #expect(
1295
- stderr. contains ( " error: --debugger cannot be used with --show-codecov-path (debugging session cannot show paths) " ) ,
1296
- " got stdout: \( stdout) , stderr: \( stderr) " ,
1297
- )
1267
+ let error = await #expect( throws: ExitCode . self) {
1268
+ try await command. run ( state)
1298
1269
}
1270
+
1271
+ #expect( error == ExitCode . failure, " Expected ExitCode.failure, got \( String ( describing: error) ) " )
1272
+
1273
+ let errorDescription = outputStream. bytes. description
1274
+ #expect(
1275
+ errorDescription. contains ( " --debugger cannot be used with --show-codecov-path " ) ,
1276
+ " Expected error about incompatible flags, got: \( errorDescription) "
1277
+ )
1299
1278
}
1300
1279
1301
1280
@Test ( arguments: SupportedBuildSystemOnAllPlatforms)
1302
1281
func lldbWithReleaseConfigurationThrowsError( buildSystem: BuildSystemProvider . Kind ) async throws {
1303
- try await fixture ( name: " Miscellaneous/EchoExecutable " ) { fixturePath in
1304
- let error = await #expect( throws: SwiftPMError . self) {
1305
- try await execute (
1306
- [ " --debugger " , " -c " , " release " ] ,
1307
- packagePath: fixturePath,
1308
- configuration: . release,
1309
- buildSystem: buildSystem,
1310
- )
1311
- }
1312
- guard case let SwiftPMError . executionFailure( _, stdout, stderr) = try #require( error) else {
1313
- Issue . record ( " Incorrect error was raised. " )
1314
- return
1315
- }
1282
+ let args = args ( [ " --debugger " ] , for: buildSystem, buildConfiguration: . release)
1283
+ let command = try #require( SwiftTestCommand . parseAsRoot ( args) as? SwiftTestCommand )
1284
+ let ( state, outputStream) = try commandState ( )
1316
1285
1317
- #expect(
1318
- stderr. contains ( " error: --debugger cannot be used with release configuration (debugging requires debug symbols) " ) ,
1319
- " got stdout: \( stdout) , stderr: \( stderr) " ,
1320
- )
1286
+ let error = await #expect( throws: ExitCode . self) {
1287
+ try await command. run ( state)
1321
1288
}
1322
- }
1323
1289
1324
- @Test ( arguments: SupportedBuildSystemOnAllPlatforms)
1325
- func lldbWithCompatibleFlagsDoesNotThrowValidationError( buildSystem: BuildSystemProvider . Kind ) async throws {
1326
- let configuration = BuildConfiguration . debug
1327
- try await fixture ( name: " Miscellaneous/EchoExecutable " ) { fixturePath in
1328
- let ( stdout, stderr) = try await execute (
1329
- [ " --debugger " , " --filter " , " .* " , " --skip " , " sometest " , " --enable-testable-imports " ] ,
1330
- packagePath: fixturePath,
1331
- configuration: configuration,
1332
- buildSystem: buildSystem,
1333
- )
1290
+ #expect( error == ExitCode . failure, " Expected ExitCode.failure, got \( String ( describing: error) ) " )
1334
1291
1335
- #expect (
1336
- !stderr . contains ( " error: --debugger cannot be used with " ) ,
1337
- " got stdout: \( stdout ) , stderr: \( stderr ) " ,
1338
- )
1339
- }
1292
+ let errorDescription = outputStream . bytes . description
1293
+ #expect (
1294
+ errorDescription . contains ( " --debugger cannot be used with release configuration " ) ,
1295
+ " Expected error about incompatible flags, got: \( errorDescription ) "
1296
+ )
1340
1297
}
1341
1298
1342
1299
@Test ( arguments: SupportedBuildSystemOnAllPlatforms)
@@ -1355,8 +1312,14 @@ struct TestCommandTests {
1355
1312
" got stdout: \( stdout) , stderr: \( stderr) " ,
1356
1313
)
1357
1314
1315
+ #if os(macOS)
1316
+ let targetName = " xctest "
1317
+ #else
1318
+ let targetName = buildSystem == . swiftbuild ? " test-runner " : " xctest "
1319
+ #endif
1320
+
1358
1321
#expect(
1359
- stdout. contains ( " target create " ) && stdout. contains ( " xctest " ) ,
1322
+ stdout. contains ( " target create " ) && stdout. contains ( targetName ) ,
1360
1323
" Expected LLDB to target xctest binary, got stdout: \( stdout) , stderr: \( stderr) " ,
1361
1324
)
1362
1325
@@ -1383,8 +1346,14 @@ struct TestCommandTests {
1383
1346
" got stdout: \( stdout) , stderr: \( stderr) " ,
1384
1347
)
1385
1348
1349
+ #if os(macOS)
1350
+ let targetName = " swiftpm-testing-helper "
1351
+ #else
1352
+ let targetName = " TestDebuggingTests-test-runner "
1353
+ #endif
1354
+
1386
1355
#expect(
1387
- stdout. contains ( " target create " ) && stdout. contains ( " swiftpm-testing-helper " ) ,
1356
+ stdout. contains ( " target create " ) && stdout. contains ( targetName ) ,
1388
1357
" Expected LLDB to target swiftpm-testing-helper binary, got stdout: \( stdout) , stderr: \( stderr) " ,
1389
1358
)
1390
1359
@@ -1427,5 +1396,49 @@ struct TestCommandTests {
1427
1396
)
1428
1397
}
1429
1398
}
1399
+
1400
+ func args( _ args: [ String ] , for buildSystem: BuildSystemProvider . Kind , buildConfiguration: BuildConfiguration = . debug) -> [ String ] {
1401
+ return args + buildConfiguration. args + getBuildSystemArgs( for: buildSystem)
1402
+ }
1403
+
1404
+ func commandState( ) throws -> ( SwiftCommandState , BufferedOutputByteStream ) {
1405
+ let outputStream = BufferedOutputByteStream ( )
1406
+
1407
+ let state = try SwiftCommandState (
1408
+ outputStream: outputStream,
1409
+ options: try GlobalOptions . parse ( [ ] ) ,
1410
+ toolWorkspaceConfiguration: . init( shouldInstallSignalHandlers: false ) ,
1411
+ workspaceDelegateProvider: {
1412
+ CommandWorkspaceDelegate (
1413
+ observabilityScope: $0,
1414
+ outputHandler: $1,
1415
+ progressHandler: $2,
1416
+ inputHandler: $3
1417
+ )
1418
+ } ,
1419
+ workspaceLoaderProvider: {
1420
+ XcodeWorkspaceLoader (
1421
+ fileSystem: $0,
1422
+ observabilityScope: $1
1423
+ )
1424
+ } ,
1425
+ createPackagePath: false
1426
+ )
1427
+ return ( state, outputStream)
1428
+ }
1430
1429
}
1431
1430
}
1431
+
1432
+ fileprivate extension BuildConfiguration {
1433
+ var args : [ String ] {
1434
+ var args = [ " --configuration " ]
1435
+ switch self {
1436
+ case . debug:
1437
+ args. append ( " debug " )
1438
+ case . release:
1439
+ args. append ( " release " )
1440
+ }
1441
+ return args
1442
+ }
1443
+ }
1444
+
0 commit comments