@@ -1206,15 +1206,41 @@ final class BuildPlanTests: XCTestCase {
1206
1206
1207
1207
func testParseAsLibraryFlagForExe( ) throws {
1208
1208
let fs = InMemoryFileSystem ( emptyFiles:
1209
- // First executable has a single source file not named `main.swift`.
1209
+ // executable has a single source file not named `main.swift`, without @main .
1210
1210
" /Pkg/Sources/exe1/foo.swift " ,
1211
- // Second executable has a single source file named `main.swift`.
1211
+ // executable has a single source file named `main.swift`, without @main .
1212
1212
" /Pkg/Sources/exe2/main.swift " ,
1213
- // Third executable has multiple source files.
1214
- " /Pkg/Sources/exe3/bar.swift " ,
1215
- " /Pkg/Sources/exe3/main.swift "
1213
+ // executable has a single source file not named `main.swift`, with @main.
1214
+ " /Pkg/Sources/exe3/foo.swift " ,
1215
+ // executable has a single source file named `main.swift`, with @main
1216
+ " /Pkg/Sources/exe4/main.swift " ,
1217
+ // executable has multiple source files.
1218
+ " /Pkg/Sources/exe5/bar.swift " ,
1219
+ " /Pkg/Sources/exe5/main.swift "
1216
1220
)
1217
1221
1222
+ try fs. writeFileContents ( AbsolutePath ( " /Pkg/Sources/exe3/foo.swift " ) ) {
1223
+ """
1224
+ @main
1225
+ struct Runner {
1226
+ static func main() {
1227
+ print( " hello world " )
1228
+ }
1229
+ }
1230
+ """
1231
+ }
1232
+
1233
+ try fs. writeFileContents ( AbsolutePath ( " /Pkg/Sources/exe4/main.swift " ) ) {
1234
+ """
1235
+ @main
1236
+ struct Runner {
1237
+ static func main() {
1238
+ print( " hello world " )
1239
+ }
1240
+ }
1241
+ """
1242
+ }
1243
+
1218
1244
let observability = ObservabilitySystem . makeForTesting ( )
1219
1245
let graph = try loadPackageGraph (
1220
1246
fileSystem: fs,
@@ -1227,6 +1253,8 @@ final class BuildPlanTests: XCTestCase {
1227
1253
TargetDescription ( name: " exe1 " , type: . executable) ,
1228
1254
TargetDescription ( name: " exe2 " , type: . executable) ,
1229
1255
TargetDescription ( name: " exe3 " , type: . executable) ,
1256
+ TargetDescription ( name: " exe4 " , type: . executable) ,
1257
+ TargetDescription ( name: " exe5 " , type: . executable) ,
1230
1258
] ) ,
1231
1259
] ,
1232
1260
observabilityScope: observability. topScope
@@ -1240,22 +1268,30 @@ final class BuildPlanTests: XCTestCase {
1240
1268
observabilityScope: observability. topScope
1241
1269
) )
1242
1270
1243
- result. checkProductsCount ( 3 )
1244
- result. checkTargetsCount ( 3 )
1271
+ result. checkProductsCount ( 5 )
1272
+ result. checkTargetsCount ( 5 )
1245
1273
1246
1274
XCTAssertNoDiagnostics ( observability. diagnostics)
1247
1275
1248
- // Check that the first target ( single source file not named main) has -parse-as-library.
1276
+ // single source file not named main, and without @main should not have -parse-as-library.
1249
1277
let exe1 = try result. target ( for: " exe1 " ) . swiftTarget ( ) . emitCommandLine ( )
1250
- XCTAssertMatch ( exe1, [ " -parse-as-library " ] )
1278
+ XCTAssertNoMatch ( exe1, [ " -parse-as-library " ] )
1251
1279
1252
- // Check that the second target ( single source file named main) does not have -parse-as-library.
1280
+ // single source file named main, and without @main should not have -parse-as-library.
1253
1281
let exe2 = try result. target ( for: " exe2 " ) . swiftTarget ( ) . emitCommandLine ( )
1254
1282
XCTAssertNoMatch ( exe2, [ " -parse-as-library " ] )
1255
1283
1256
- // Check that the third target (multiple source files) does not have -parse-as-library.
1284
+ // single source file not named main, with @main should have -parse-as-library.
1257
1285
let exe3 = try result. target ( for: " exe3 " ) . swiftTarget ( ) . emitCommandLine ( )
1258
- XCTAssertNoMatch ( exe3, [ " -parse-as-library " ] )
1286
+ XCTAssertMatch ( exe3, [ " -parse-as-library " ] )
1287
+
1288
+ // single source file named main, with @main should have -parse-as-library.
1289
+ let exe4 = try result. target ( for: " exe4 " ) . swiftTarget ( ) . emitCommandLine ( )
1290
+ XCTAssertMatch ( exe4, [ " -parse-as-library " ] )
1291
+
1292
+ // multiple source files should not have -parse-as-library.
1293
+ let exe5 = try result. target ( for: " exe5 " ) . swiftTarget ( ) . emitCommandLine ( )
1294
+ XCTAssertNoMatch ( exe5, [ " -parse-as-library " ] )
1259
1295
}
1260
1296
1261
1297
func testCModule( ) throws {
0 commit comments