@@ -1014,15 +1014,41 @@ final class BuildPlanTests: XCTestCase {
1014
1014
1015
1015
func testParseAsLibraryFlagForExe( ) throws {
1016
1016
let fs = InMemoryFileSystem ( emptyFiles:
1017
- // First executable has a single source file not named `main.swift`.
1017
+ // executable has a single source file not named `main.swift`, without @main .
1018
1018
" /Pkg/Sources/exe1/foo.swift " ,
1019
- // Second executable has a single source file named `main.swift`.
1019
+ // executable has a single source file named `main.swift`, without @main .
1020
1020
" /Pkg/Sources/exe2/main.swift " ,
1021
- // Third executable has multiple source files.
1022
- " /Pkg/Sources/exe3/bar.swift " ,
1023
- " /Pkg/Sources/exe3/main.swift "
1021
+ // executable has a single source file not named `main.swift`, with @main.
1022
+ " /Pkg/Sources/exe3/foo.swift " ,
1023
+ // executable has a single source file named `main.swift`, with @main
1024
+ " /Pkg/Sources/exe4/main.swift " ,
1025
+ // executable has multiple source files.
1026
+ " /Pkg/Sources/exe5/bar.swift " ,
1027
+ " /Pkg/Sources/exe5/main.swift "
1024
1028
)
1025
1029
1030
+ try fs. writeFileContents ( AbsolutePath ( " /Pkg/Sources/exe3/foo.swift " ) ) {
1031
+ """
1032
+ @main
1033
+ struct Runner {
1034
+ static func main() {
1035
+ print( " hello world " )
1036
+ }
1037
+ }
1038
+ """
1039
+ }
1040
+
1041
+ try fs. writeFileContents ( AbsolutePath ( " /Pkg/Sources/exe4/main.swift " ) ) {
1042
+ """
1043
+ @main
1044
+ struct Runner {
1045
+ static func main() {
1046
+ print( " hello world " )
1047
+ }
1048
+ }
1049
+ """
1050
+ }
1051
+
1026
1052
let observability = ObservabilitySystem . makeForTesting ( )
1027
1053
let graph = try loadPackageGraph (
1028
1054
fileSystem: fs,
@@ -1035,6 +1061,8 @@ final class BuildPlanTests: XCTestCase {
1035
1061
TargetDescription ( name: " exe1 " , type: . executable) ,
1036
1062
TargetDescription ( name: " exe2 " , type: . executable) ,
1037
1063
TargetDescription ( name: " exe3 " , type: . executable) ,
1064
+ TargetDescription ( name: " exe4 " , type: . executable) ,
1065
+ TargetDescription ( name: " exe5 " , type: . executable) ,
1038
1066
] ) ,
1039
1067
] ,
1040
1068
observabilityScope: observability. topScope
@@ -1048,22 +1076,30 @@ final class BuildPlanTests: XCTestCase {
1048
1076
observabilityScope: observability. topScope
1049
1077
) )
1050
1078
1051
- result. checkProductsCount ( 3 )
1052
- result. checkTargetsCount ( 3 )
1079
+ result. checkProductsCount ( 5 )
1080
+ result. checkTargetsCount ( 5 )
1053
1081
1054
1082
XCTAssertNoDiagnostics ( observability. diagnostics)
1055
1083
1056
- // Check that the first target ( single source file not named main) has -parse-as-library.
1084
+ // single source file not named main, and without @main should not have -parse-as-library.
1057
1085
let exe1 = try result. target ( for: " exe1 " ) . swiftTarget ( ) . emitCommandLine ( )
1058
- XCTAssertMatch ( exe1, [ " -parse-as-library " ] )
1086
+ XCTAssertNoMatch ( exe1, [ " -parse-as-library " ] )
1059
1087
1060
- // Check that the second target ( single source file named main) does not have -parse-as-library.
1088
+ // single source file named main, and without @main should not have -parse-as-library.
1061
1089
let exe2 = try result. target ( for: " exe2 " ) . swiftTarget ( ) . emitCommandLine ( )
1062
1090
XCTAssertNoMatch ( exe2, [ " -parse-as-library " ] )
1063
1091
1064
- // Check that the third target (multiple source files) does not have -parse-as-library.
1092
+ // single source file not named main, with @main should have -parse-as-library.
1065
1093
let exe3 = try result. target ( for: " exe3 " ) . swiftTarget ( ) . emitCommandLine ( )
1066
- XCTAssertNoMatch ( exe3, [ " -parse-as-library " ] )
1094
+ XCTAssertMatch ( exe3, [ " -parse-as-library " ] )
1095
+
1096
+ // single source file named main, with @main should have -parse-as-library.
1097
+ let exe4 = try result. target ( for: " exe4 " ) . swiftTarget ( ) . emitCommandLine ( )
1098
+ XCTAssertMatch ( exe4, [ " -parse-as-library " ] )
1099
+
1100
+ // multiple source files should not have -parse-as-library.
1101
+ let exe5 = try result. target ( for: " exe5 " ) . swiftTarget ( ) . emitCommandLine ( )
1102
+ XCTAssertNoMatch ( exe5, [ " -parse-as-library " ] )
1067
1103
}
1068
1104
1069
1105
func testCModule( ) throws {
0 commit comments