@@ -998,23 +998,133 @@ class PackageBuilderTests: XCTestCase {
998
998
}
999
999
}
1000
1000
1001
- func testManifestTargetDeclErrors( ) throws {
1001
+ /// Starting with tools version 5.9, packages are permitted to place
1002
+ /// sources anywhere in ./Sources when a package has a single target.
1003
+ func testRelaxedSourceLocationSingleTarget( ) throws {
1002
1004
do {
1003
- // Reference a target which doesn't exist .
1005
+ // Single target: Sources are expected in ./Sources .
1004
1006
let fs = InMemoryFileSystem ( emptyFiles:
1005
- " /Foo.swift " )
1007
+ " /Sources/Foo.swift " )
1008
+
1009
+ let manifest = Manifest . createRootManifest (
1010
+ displayName: " pkg " ,
1011
+ toolsVersion: . v5_9,
1012
+ targets: [
1013
+ try TargetDescription ( name: " Random " ) ,
1014
+ ]
1015
+ )
1016
+ PackageBuilderTester ( manifest, in: fs) { package , diagnostics in
1017
+ package . checkModule ( " Random " ) { result in
1018
+ XCTAssertEqual ( " /Sources " , result. target. path)
1019
+ }
1020
+ }
1021
+ }
1022
+
1023
+ do {
1024
+ // Single target: Sources are expected in ./Sources.
1025
+ // In this case, there is a stray source file at the top-level, and no sources
1026
+ // under ./Sources, so the target Random has no sources.
1027
+ // This results in a *warning* that there are no sources for the target.
1028
+ let fs = InMemoryFileSystem ( emptyFiles:
1029
+ " /Stray.swift " )
1006
1030
1007
1031
let manifest = Manifest . createRootManifest (
1008
1032
displayName: " pkg " ,
1033
+ toolsVersion: . v5_9,
1009
1034
targets: [
1010
1035
try TargetDescription ( name: " Random " ) ,
1011
1036
]
1012
1037
)
1013
1038
PackageBuilderTester ( manifest, in: fs) { _, diagnostics in
1014
- diagnostics. check ( diagnostic: . contains( " Source files for target Random should be located under 'Sources/Random' " ) , severity: . error)
1039
+ diagnostics. check ( diagnostic: . contains( " Source files for target Random should be located under /Sources " ) , severity: . warning)
1040
+ }
1041
+ }
1042
+
1043
+ do {
1044
+ // Single target: Sources are expected in ./Sources. In this case,
1045
+ // there is a stray source file at the top-level which is ignored.
1046
+ let fs = InMemoryFileSystem ( emptyFiles:
1047
+ " /Stray.swift " ,
1048
+ " /Sources/Random.swift " )
1049
+
1050
+ let manifest = Manifest . createRootManifest (
1051
+ displayName: " pkg " ,
1052
+ toolsVersion: . v5_9,
1053
+ targets: [
1054
+ try TargetDescription ( name: " Random " ) ,
1055
+ ]
1056
+ )
1057
+ PackageBuilderTester ( manifest, in: fs) { package , diagnostics in
1058
+ package . checkModule ( " Random " )
1015
1059
}
1016
1060
}
1017
1061
1062
+ do {
1063
+ // Multiple targets: Sources are expected in their respective subdirectories
1064
+ // under Sources
1065
+ let fs = InMemoryFileSystem ( emptyFiles:
1066
+ " /Foo.swift " )
1067
+
1068
+ let manifest = Manifest . createRootManifest (
1069
+ displayName: " pkg " ,
1070
+ toolsVersion: . v5_9,
1071
+ targets: [
1072
+ try TargetDescription ( name: " TargetA " ) ,
1073
+ try TargetDescription ( name: " TargetB " ) ,
1074
+ ]
1075
+ )
1076
+ PackageBuilderTester ( manifest, in: fs) { _, diagnostics in
1077
+ diagnostics. check ( diagnostic: . contains( " Source files for target TargetA should be located under 'Sources/TargetA' " ) , severity: . error)
1078
+ }
1079
+ }
1080
+ }
1081
+
1082
+ func testStrictSourceLocation( ) throws {
1083
+ do {
1084
+ for fs in [
1085
+ InMemoryFileSystem ( emptyFiles:
1086
+ " /Sources/Foo.swift " ) ,
1087
+ InMemoryFileSystem ( emptyFiles:
1088
+ " /Stray.swift " ) ,
1089
+ InMemoryFileSystem ( emptyFiles:
1090
+ " /Stray.swift " ,
1091
+ " /Sources/Random.swift " ) ,
1092
+ ] {
1093
+ let manifest = Manifest . createRootManifest (
1094
+ displayName: " pkg " ,
1095
+ targets: [
1096
+ try TargetDescription ( name: " Random " ) ,
1097
+ ]
1098
+ )
1099
+ PackageBuilderTester ( manifest, in: fs) { _, diagnostics in
1100
+ diagnostics. check ( diagnostic: . contains( " Source files for target Random should be located under 'Sources/Random' " ) , severity: . error)
1101
+ }
1102
+ }
1103
+ }
1104
+
1105
+ do {
1106
+ // Multiple targets: Sources are expected in their respective subdirectories
1107
+ // under Sources
1108
+ let fs = InMemoryFileSystem ( emptyFiles:
1109
+ " /Foo.swift " )
1110
+
1111
+ let manifest = Manifest . createRootManifest (
1112
+ displayName: " pkg " ,
1113
+ toolsVersion: . v5_9,
1114
+ targets: [
1115
+ try TargetDescription ( name: " TargetA " ) ,
1116
+ try TargetDescription ( name: " TargetB " ) ,
1117
+ ]
1118
+ )
1119
+ PackageBuilderTester ( manifest, in: fs) { _, diagnostics in
1120
+ diagnostics. check ( diagnostic: . contains( " Source files for target TargetA should be located under 'Sources/TargetA' " ) , severity: . error)
1121
+ }
1122
+ }
1123
+
1124
+ }
1125
+
1126
+ func testManifestTargetDeclErrors( ) throws {
1127
+
1018
1128
do {
1019
1129
let fs = InMemoryFileSystem ( emptyFiles:
1020
1130
" /src/pkg/Foo.swift " )
@@ -1060,21 +1170,6 @@ class PackageBuilderTests: XCTestCase {
1060
1170
}
1061
1171
}
1062
1172
1063
- do {
1064
- let fs = InMemoryFileSystem ( emptyFiles:
1065
- " /Source/pkg/Foo.swift " )
1066
- // Reference invalid target.
1067
- let manifest = Manifest . createRootManifest (
1068
- displayName: " pkg " ,
1069
- targets: [
1070
- try TargetDescription ( name: " foo " ) ,
1071
- ]
1072
- )
1073
- PackageBuilderTester ( manifest, in: fs) { _, diagnotics in
1074
- diagnotics. check ( diagnostic: . contains( " Source files for target foo should be located under 'Sources/foo' " ) , severity: . error)
1075
- }
1076
- }
1077
-
1078
1173
do {
1079
1174
let fs = InMemoryFileSystem ( )
1080
1175
// Binary target.
0 commit comments