Skip to content

Commit 28c7e3b

Browse files
authored
fix: don't add test target if there are no tests (#36)
1 parent 9f339ce commit 28c7e3b

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

Sources/CapacitorPluginTools/PackageFileGenerator.swift

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,22 @@ import Foundation
33
public class PackageFileGenerator {
44
let packageName: String
55
let targetName: String
6+
let hasTests: Bool
67
let capRepoName = "capacitor-swift-pm"
78
let capLocation = "https://github.com/ionic-team/capacitor-swift-pm.git"
89
let capVersion = "8.0.0"
910

1011
var packageText: String {
12+
var testTargetText = ""
13+
if hasTests {
14+
testTargetText = """
15+
,
16+
.testTarget(
17+
name: "\(targetName)Tests",
18+
dependencies: ["\(targetName)"],
19+
path: "ios/Tests/\(targetName)Tests")
20+
"""
21+
}
1122
return """
1223
// swift-tools-version: 5.9
1324
import PackageDescription
@@ -30,19 +41,16 @@ public class PackageFileGenerator {
3041
.product(name: "Capacitor", package: "\(capRepoName)"),
3142
.product(name: "Cordova", package: "\(capRepoName)")
3243
],
33-
path: "ios/Sources/\(targetName)"),
34-
.testTarget(
35-
name: "\(targetName)Tests",
36-
dependencies: ["\(targetName)"],
37-
path: "ios/Tests/\(targetName)Tests")
44+
path: "ios/Sources/\(targetName)")\(testTargetText)
3845
]
3946
)
4047
"""
4148
}
4249

43-
public init(packageName: String, targetName: String) {
50+
public init(packageName: String, targetName: String, hasTests: Bool) {
4451
self.packageName = packageName
4552
self.targetName = targetName
53+
self.hasTests = hasTests
4654
}
4755

4856
public func generateFile(at fileURL: URL) throws {

Sources/CommandLineTool/cap2spm.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ struct Cap2SPM: ParsableCommand {
5050
try? modifyTestsFile(at: swiftTestsFileURL, with: capPlugin.identifier)
5151
}
5252

53-
let packageGenerator = PackageFileGenerator(packageName: podspec.podName, targetName: capPlugin.identifier)
53+
let packageGenerator = PackageFileGenerator(packageName: podspec.podName, targetName: capPlugin.identifier, hasTests: swiftTestsFileURL != nil)
5454

5555
try packageGenerator.generateFile(at: podspecFileURL)
5656

Tests/CapacitorPluginToolsTests/PackageFileGenerator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ struct PackageFileGeneratorTests {
66
let packageFileGenerator: PackageFileGenerator
77

88
init() {
9-
packageFileGenerator = PackageFileGenerator(packageName: "CapacitorAppPlugin", targetName: "AppPlugin")
9+
packageFileGenerator = PackageFileGenerator(packageName: "CapacitorAppPlugin", targetName: "AppPlugin", hasTests: true)
1010
}
1111

1212
@Test("Generates expected Package.swift Text")

0 commit comments

Comments
 (0)