Skip to content

Commit f53a31e

Browse files
committed
highlighting if empty targets are provided
1 parent c5246e7 commit f53a31e

File tree

4 files changed

+76
-12
lines changed

4 files changed

+76
-12
lines changed

Sources/PublicModules/PADOutputGenerator/MarkdownOutputGenerator.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public struct MarkdownOutputGenerator: OutputGenerating {
2525
let changes = Self.changeLines(changesPerModule: changesPerTarget)
2626

2727
var lines = [
28-
Self.title(changesPerTarget: changesPerTarget)
28+
Self.title(changesPerTarget: changesPerTarget, allTargets: allTargets)
2929
]
3030

3131
if let oldVersionName, let newVersionName {
@@ -46,7 +46,7 @@ public struct MarkdownOutputGenerator: OutputGenerating {
4646
lines += changes + [separator]
4747
}
4848

49-
if let allTargets {
49+
if let allTargets, !allTargets.isEmpty {
5050
lines += [
5151
Self.analyzedModulesInfo(allTargets: allTargets)
5252
]
@@ -60,7 +60,15 @@ public struct MarkdownOutputGenerator: OutputGenerating {
6060

6161
private extension MarkdownOutputGenerator {
6262

63-
static func title(changesPerTarget: [String: [Change]]) -> String {
63+
static func title(
64+
changesPerTarget: [String: [Change]],
65+
allTargets: [String]?
66+
) -> String {
67+
68+
if let allTargets, allTargets.isEmpty {
69+
// We got targets but the list is empty -> Show an error
70+
return "# ‼️ No analyzable targets detected"
71+
}
6472

6573
if changesPerTarget.keys.isEmpty {
6674
return "# ✅ No changes detected"

Sources/PublicModules/PADOutputGenerator/OutputGenerating.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public protocol OutputGenerating<OutputType> {
1515
/// Generates an output from input parameters
1616
/// - Parameters:
1717
/// - changesPerTarget: A list of changes per target/module
18-
/// - allTargets: A list of all targets/modules that were analysed in previous steps
18+
/// - allTargets: A list of all targets/modules that were analysed in previous steps - if targets are provided but the list is empty it is treated like a failure
1919
/// - oldVersionName: The name of the old/reference version
2020
/// - newVersionName: The name of the new/updated version
2121
/// - warnings: A list of warnings produced in previous steps

Tests/UnitTests/OutputGeneratorTests.swift

Lines changed: 62 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
//
66

77
@testable import PADOutputGenerator
8-
import XCTest
8+
import Testing
99

10-
class OutputGeneratorTests: XCTestCase {
10+
class OutputGeneratorTests {
1111

12-
func test_noChanges_singleModule() {
12+
@Test
13+
func noChanges_singleModule() {
1314

1415
let expectedOutput = """
1516
# ✅ No changes detected
@@ -27,10 +28,12 @@ class OutputGeneratorTests: XCTestCase {
2728
newVersionName: "new_source",
2829
warnings: []
2930
)
30-
XCTAssertEqual(output, expectedOutput)
31+
32+
#expect(output == expectedOutput)
3133
}
3234

33-
func test_oneChange_singleModule() {
35+
@Test
36+
func oneChange_singleModule() {
3437

3538
let expectedOutput = """
3639
# 👀 1 public change detected
@@ -57,10 +60,12 @@ class OutputGeneratorTests: XCTestCase {
5760
newVersionName: "new_source",
5861
warnings: []
5962
)
60-
XCTAssertEqual(output, expectedOutput)
63+
64+
#expect(output == expectedOutput)
6165
}
6266

63-
func test_multipleChanges_multipleModules() {
67+
@Test
68+
func multipleChanges_multipleModules() {
6469

6570
let expectedOutput = """
6671
# ⚠️ 4 public changes detected ⚠️
@@ -109,6 +114,55 @@ class OutputGeneratorTests: XCTestCase {
109114
newVersionName: "new_source",
110115
warnings: []
111116
)
112-
XCTAssertEqual(output, expectedOutput)
117+
118+
#expect(output == expectedOutput)
119+
}
120+
121+
struct AllTargetsExpectation {
122+
let allTargets: [String]?
123+
let expectedTitle: String
124+
let expectedTargetSection: String
125+
}
126+
127+
@Test(
128+
"allTargets should change the output as expected",
129+
arguments: [
130+
AllTargetsExpectation(
131+
allTargets: [],
132+
expectedTitle: "‼️ No analyzable targets detected",
133+
expectedTargetSection: ""
134+
),
135+
AllTargetsExpectation(
136+
allTargets: nil,
137+
expectedTitle: "✅ No changes detected",
138+
expectedTargetSection: ""
139+
),
140+
AllTargetsExpectation(
141+
allTargets: ["SomeTarget"],
142+
expectedTitle: "✅ No changes detected",
143+
expectedTargetSection: "\n**Analyzed targets:** SomeTarget"
144+
)
145+
]
146+
)
147+
func allTargets_shouldChangeOutputAsExpected(argument: AllTargetsExpectation) {
148+
149+
let expectedOutput = """
150+
# \(argument.expectedTitle)
151+
_Comparing `new_source` to `old_repository @ old_branch`_
152+
153+
---\(argument.expectedTargetSection)
154+
"""
155+
156+
let outputGenerator = MarkdownOutputGenerator()
157+
158+
let output = outputGenerator.generate(
159+
from: [:],
160+
allTargets: argument.allTargets,
161+
oldVersionName: "old_repository @ old_branch",
162+
newVersionName: "new_source",
163+
warnings: []
164+
)
165+
166+
#expect(output == expectedOutput)
113167
}
114168
}

Tests/public-api-diff.xctestplan

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,15 @@
4545
},
4646
"testTargets" : [
4747
{
48+
"parallelizable" : true,
4849
"target" : {
4950
"containerPath" : "container:",
5051
"identifier" : "IntegrationTests",
5152
"name" : "IntegrationTests"
5253
}
5354
},
5455
{
56+
"parallelizable" : true,
5557
"target" : {
5658
"containerPath" : "container:",
5759
"identifier" : "UnitTests",

0 commit comments

Comments
 (0)