Skip to content

Commit

Permalink
improve test support
Browse files Browse the repository at this point in the history
  • Loading branch information
mackoj committed May 3, 2024
1 parent 888775d commit 208ab39
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 6 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ let package = Package(
targets: [
.binaryTarget(
name: "package-generator-cli",
url: "https://github.com/mackoj/PackageGeneratorCLI/releases/download/0.5.0/package-generator-cli-arm64-apple-macosx.artifactbundle.zip",
checksum: "8ffa941438b678085c45e6caab195cdb0a6b4a6fb6e4425589869a1a2dc1e8da"
url: "https://github.com/mackoj/PackageGeneratorCLI/releases/download/0.5.1/package-generator-cli-arm64-apple-macosx.artifactbundle.zip",
checksum: "758615aeda296df2870341b311eaac5deb518a2f9a2e1c438520901f96d0fa74"
),
// .binaryTarget(
// name: "package-generator-cli",
// path: "../PackageGeneratorCLI/package-generator-cli-arm64-apple-macosx.artifactbundle.zip"
// ),
.plugin(
name: "Package Generator",
capability: .command(
Expand Down
6 changes: 4 additions & 2 deletions Plugins/PackageGenerator/PackageGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ struct PackageGenerator {

var last: String = ""
for parsedPackage in parsedPackages.sorted(by: \.name, order: <) {
if parsedPackage.isTest { continue }
if last.isEmpty == false {
outputFileHandle.write("\(last),\n".data(using: .utf8)!)
}
Expand Down Expand Up @@ -365,14 +366,15 @@ struct PackageGenerator {

private static func fakeTargetToSwiftCode(_ fakeTarget: ParsedPackage, _ configuration: PackageGeneratorConfiguration) -> String {
let spaces = String(repeating: " ", count: configuration.spaces)
let name = fakeTarget.name + (fakeTarget.isTest ? "Tests" : "")
let localDependencies = fakeTarget.dependencies
var dependencies = ""
if localDependencies.isEmpty == false {
dependencies = "\n\(spaces)\(spaces)dependencies: [\n" + localDependencies.map{ "\(spaces)\(spaces)\(spaces)\(configuration.mappers.imports[$0, default: "\"\($0)\""])" }.sorted(by: <).joined(separator: ",\n") + "\n\(spaces)\(spaces)],"
}

var otherParameters = ""
if let targetParameters = configuration.targetsParameters?[fakeTarget.name], targetParameters.isEmpty == false {
if let targetParameters = configuration.targetsParameters?[name], targetParameters.isEmpty == false {
otherParameters = ",\n" + targetParameters.map { "\(spaces)\(spaces)\($0)" } .joined(separator: ",\n")
}

Expand All @@ -381,7 +383,7 @@ struct PackageGenerator {

return """
\(spaces).\(fakeTarget.isTest ? "testTarget" : "target")(
\(spaces)\(spaces)name: "\(fakeTarget.name)",\(isLeaf)\(dependencies)
\(spaces)\(spaces)name: "\(name)",\(isLeaf)\(dependencies)
\(spaces)\(spaces)path: "\(fakeTarget.path)"\(otherParameters)
\(spaces))
"""
Expand Down

0 comments on commit 208ab39

Please sign in to comment.