Skip to content

Commit

Permalink
highlighting if empty targets are provided
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Guretzki committed Feb 27, 2025
1 parent c5246e7 commit f53a31e
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public struct MarkdownOutputGenerator: OutputGenerating {
let changes = Self.changeLines(changesPerModule: changesPerTarget)

var lines = [
Self.title(changesPerTarget: changesPerTarget)
Self.title(changesPerTarget: changesPerTarget, allTargets: allTargets)
]

if let oldVersionName, let newVersionName {
Expand All @@ -46,7 +46,7 @@ public struct MarkdownOutputGenerator: OutputGenerating {
lines += changes + [separator]
}

if let allTargets {
if let allTargets, !allTargets.isEmpty {
lines += [
Self.analyzedModulesInfo(allTargets: allTargets)
]
Expand All @@ -60,7 +60,15 @@ public struct MarkdownOutputGenerator: OutputGenerating {

private extension MarkdownOutputGenerator {

static func title(changesPerTarget: [String: [Change]]) -> String {
static func title(
changesPerTarget: [String: [Change]],
allTargets: [String]?
) -> String {

if let allTargets, allTargets.isEmpty {
// We got targets but the list is empty -> Show an error
return "# ‼️ No analyzable targets detected"
}

if changesPerTarget.keys.isEmpty {
return "# ✅ No changes detected"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public protocol OutputGenerating<OutputType> {
/// Generates an output from input parameters
/// - Parameters:
/// - changesPerTarget: A list of changes per target/module
/// - allTargets: A list of all targets/modules that were analysed in previous steps
/// - 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
/// - oldVersionName: The name of the old/reference version
/// - newVersionName: The name of the new/updated version
/// - warnings: A list of warnings produced in previous steps
Expand Down
70 changes: 62 additions & 8 deletions Tests/UnitTests/OutputGeneratorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
//

@testable import PADOutputGenerator
import XCTest
import Testing

class OutputGeneratorTests: XCTestCase {
class OutputGeneratorTests {

func test_noChanges_singleModule() {
@Test
func noChanges_singleModule() {

let expectedOutput = """
# ✅ No changes detected
Expand All @@ -27,10 +28,12 @@ class OutputGeneratorTests: XCTestCase {
newVersionName: "new_source",
warnings: []
)
XCTAssertEqual(output, expectedOutput)

#expect(output == expectedOutput)
}

func test_oneChange_singleModule() {
@Test
func oneChange_singleModule() {

let expectedOutput = """
# 👀 1 public change detected
Expand All @@ -57,10 +60,12 @@ class OutputGeneratorTests: XCTestCase {
newVersionName: "new_source",
warnings: []
)
XCTAssertEqual(output, expectedOutput)

#expect(output == expectedOutput)
}

func test_multipleChanges_multipleModules() {
@Test
func multipleChanges_multipleModules() {

let expectedOutput = """
# ⚠️ 4 public changes detected ⚠️
Expand Down Expand Up @@ -109,6 +114,55 @@ class OutputGeneratorTests: XCTestCase {
newVersionName: "new_source",
warnings: []
)
XCTAssertEqual(output, expectedOutput)

#expect(output == expectedOutput)
}

struct AllTargetsExpectation {
let allTargets: [String]?
let expectedTitle: String
let expectedTargetSection: String
}

@Test(
"allTargets should change the output as expected",
arguments: [
AllTargetsExpectation(
allTargets: [],
expectedTitle: "‼️ No analyzable targets detected",
expectedTargetSection: ""
),
AllTargetsExpectation(
allTargets: nil,
expectedTitle: "✅ No changes detected",
expectedTargetSection: ""
),
AllTargetsExpectation(
allTargets: ["SomeTarget"],
expectedTitle: "✅ No changes detected",
expectedTargetSection: "\n**Analyzed targets:** SomeTarget"
)
]
)
func allTargets_shouldChangeOutputAsExpected(argument: AllTargetsExpectation) {

let expectedOutput = """
# \(argument.expectedTitle)
_Comparing `new_source` to `old_repository @ old_branch`_
---\(argument.expectedTargetSection)
"""

let outputGenerator = MarkdownOutputGenerator()

let output = outputGenerator.generate(
from: [:],
allTargets: argument.allTargets,
oldVersionName: "old_repository @ old_branch",
newVersionName: "new_source",
warnings: []
)

#expect(output == expectedOutput)
}
}
2 changes: 2 additions & 0 deletions Tests/public-api-diff.xctestplan
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@
},
"testTargets" : [
{
"parallelizable" : true,
"target" : {
"containerPath" : "container:",
"identifier" : "IntegrationTests",
"name" : "IntegrationTests"
}
},
{
"parallelizable" : true,
"target" : {
"containerPath" : "container:",
"identifier" : "UnitTests",
Expand Down

0 comments on commit f53a31e

Please sign in to comment.