Skip to content

Commit 8cea713

Browse files
committed
Tests: add tests where package has multiple products with same name
Add tests to ensure SwiftPM support products with same name, but with different case sensitivity. relates to #9184 Issue: rdar://161264250
1 parent 1d29fcd commit 8cea713

6 files changed

Lines changed: 97 additions & 1 deletion

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// swift-tools-version: 6.1
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import PackageDescription
5+
6+
let package = Package(
7+
name: "TwoProductsHaveSameNameButDifferentCaseSensitivity",
8+
products: [
9+
.library(
10+
name: "MyProduct",
11+
targets: [
12+
"MyProduct",
13+
],
14+
),
15+
.executable(
16+
name: "myproduct",
17+
targets: [
18+
"execTargetNoMainFunction",
19+
],
20+
),
21+
.executable(
22+
name: "myProduct",
23+
targets: [
24+
"execTargetWithAtMain",
25+
],
26+
),
27+
.executable(
28+
name: "Myproduct",
29+
targets: [
30+
"execTargetNoAtMainButHasMainDotSwift",
31+
],
32+
),
33+
],
34+
targets: [
35+
.target(
36+
name: "MyProduct",
37+
),
38+
.executableTarget(
39+
name: "execTargetNoMainFunction",
40+
),
41+
.executableTarget(
42+
name: "execTargetWithAtMain"
43+
),
44+
.executableTarget(
45+
name: "execTargetNoAtMainButHasMainDotSwift"
46+
),
47+
],
48+
)

Fixtures/MyltipleProductsHaveSameNameButDifferentCaseSensitivity/Sources/MyProduct/lib1.swift

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
func main() {
3+
print("Hello, world with main function")
4+
}
5+
6+
main()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
print("Hello, world. with main.swift inline as a script")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
@main
3+
struct ExecTargetWithAtMainMain {
4+
static func main() {
5+
print("Hello, world with @main")
6+
}
7+
}

Tests/CommandsTests/RunCommandTests.swift

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import enum PackageModel.BuildConfiguration
2424
import class Basics.AsyncProcess
2525

2626
@Suite(
27-
.serialized, // to limit the number of swift executable running.
2827
.tags(
2928
Tag.TestSize.large,
3029
Tag.Feature.Command.Run,
@@ -135,6 +134,40 @@ struct RunCommandTests {
135134
}
136135
}
137136

137+
@Test(
138+
arguments: SupportedBuildSystemOnAllPlatforms, [
139+
(
140+
fixtureNameUT: "MyltipleProductsHaveSameNameButDifferentCaseSensitivity",
141+
productUT: "myproduct",
142+
expectedOutput: "Hello, world. with main.swift inline as a script",
143+
),
144+
(
145+
fixtureNameUT: "MyltipleProductsHaveSameNameButDifferentCaseSensitivity",
146+
productUT: "myProduct",
147+
expectedOutput: "Hello, world with @main",
148+
),
149+
(
150+
fixtureNameUT: "MyltipleProductsHaveSameNameButDifferentCaseSensitivity",
151+
productUT: "Myproduct",
152+
expectedOutput: "Hello, world with main function",
153+
),
154+
],
155+
)
156+
func testPackageHasMultipleProductsWithSameNameButDifferentCaseSensitivity(
157+
buildSystem: BuildSystemProvider.Kind,
158+
data: (fixtureNameUT: String, productUT: String, expectedOutput: String),
159+
) async throws {
160+
try await fixture(name: data.fixtureNameUT) { fixturePath in
161+
let (stdout, _) = try await executeSwiftRun(
162+
fixturePath,
163+
data.productUT,
164+
buildSystem: buildSystem,
165+
)
166+
167+
#expect(stdout.contains(data.expectedOutput))
168+
}
169+
}
170+
138171
@Test(
139172
.tags(
140173
.Feature.TargetType.Executable,

0 commit comments

Comments
 (0)