Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ let package = Package(
),
.testTarget(
name: "AckGenTests",
dependencies: ["AckGenCore"]),
dependencies: ["AckGenCore"],
resources: [.copy("Fixtures")]),
]
)
66 changes: 66 additions & 0 deletions Tests/AckGenTests/AcknowledgementAllTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//
// AcknowledgementAllTests.swift
// AckGenTests
//
// Created by Martin Pfundmair on 2026-01-13.
//

import XCTest
@testable import AckGenCore

final class AcknowledgementAllTests: XCTestCase {

func testAllDecodesFixturePlist() {
// Given: A fixture plist in the test bundle's Fixtures directory
// When: Loading acknowledgements from the fixture
let acks = Acknowledgement.all(fromPlist: "Fixtures/Acknowledgements", in: Bundle.module)

// Then: All entries should be decoded correctly
XCTAssertEqual(acks.count, 3)

// Verify the content is decoded properly
let titles = acks.map(\.title)
XCTAssertTrue(titles.contains("Zebra"))
XCTAssertTrue(titles.contains("apple"))
XCTAssertTrue(titles.contains("Banana"))

// Verify license content is present
let zebra = acks.first { $0.title == "Zebra" }
XCTAssertEqual(zebra?.license, "MIT License for Zebra package")
}

func testAllSortsCaseInsensitively() {
// Given: A fixture plist with mixed case titles (Zebra, apple, Banana)
// When: Loading acknowledgements (which applies case-insensitive sorting)
let acks = Acknowledgement.all(fromPlist: "Fixtures/Acknowledgements", in: Bundle.module)

// Then: Should be sorted case-insensitively: apple, Banana, Zebra
XCTAssertEqual(acks.count, 3)
XCTAssertEqual(acks[0].title, "apple") // 'a' comes first
XCTAssertEqual(acks[1].title, "Banana") // 'B' (as 'b') comes second
XCTAssertEqual(acks[2].title, "Zebra") // 'Z' (as 'z') comes last
}

func testAllReturnsEmptyArrayForMissingPlist() {
// Given: A non-existent plist name
let bundle = Bundle.module

// When: Loading from a non-existent plist
let acks = Acknowledgement.all(fromPlist: "NonExistent", in: bundle)

// Then: Should return empty array instead of crashing
XCTAssertTrue(acks.isEmpty)
}

func testAllReturnsEmptyArrayForInvalidPlist() {
// Given: An invalid plist file (the invalid-utf8-license fixture)
// Note: This test verifies graceful handling of invalid data
// The all() method should return empty array for any decode failure

// When: Attempting to decode a plist with invalid UTF-8 content
let acks = Acknowledgement.all(fromPlist: "Fixtures/invalid-utf8-license", in: Bundle.module)

// Then: Should return empty array instead of crashing
XCTAssertTrue(acks.isEmpty)
}
Comment on lines +54 to +65

Copilot AI Feb 6, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test has a logic error. It loads the path to the "invalid-utf8-license" fixture (line 74) and verifies it exists (line 80), but then calls Acknowledgement.all(fromPlist: "NonExistent", in: bundle) on line 83. This means the test is not actually testing the invalid UTF-8 file handling - it's just testing a non-existent file again (which is already covered by the previous test).

The test should either:

  1. Call Acknowledgement.all(fromPlist: "invalid-utf8-license", in: bundle) to actually test the invalid UTF-8 file, or
  2. Be removed if the Acknowledgement.all() API doesn't support loading files without the .plist extension, or
  3. Be simplified to just duplicate the missing file test without the misleading comments about invalid UTF-8.
Suggested change
func testAllReturnsEmptyArrayForInvalidPlist() {
// Given: An invalid file (the invalid-utf8-license fixture)
// Note: This test verifies graceful handling of invalid data
// The all() method should return empty array for any decode failure
let bundle = Bundle.module
// When: Loading from a plist that would fail to decode
// (Using Fixtures subdirectory path)
guard let path = bundle.path(forResource: "invalid-utf8-license", ofType: nil, inDirectory: "Fixtures") else {
XCTFail("Could not find invalid-utf8-license fixture")
return
}
// Verify the file exists and contains invalid data
XCTAssertNotNil(FileManager.default.contents(atPath: path))
// When: Attempting to decode as plist, it should fail gracefully
let acks = Acknowledgement.all(fromPlist: "NonExistent", in: bundle)
// Then: Should return empty array instead of crashing
XCTAssertTrue(acks.isEmpty)
}

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot instead of removing the test I'd rather test the actual invalid-utf8-license. let's rename it with correct extension and remove guard statement.

Comment thread
MartinP7r marked this conversation as resolved.
}
30 changes: 30 additions & 0 deletions Tests/AckGenTests/Fixtures/Acknowledgements.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<dict>
<key>Title</key>
<string>Zebra</string>
<key>FooterText</key>
<string>MIT License for Zebra package</string>
<key>Type</key>
<string>PSGroupSpecifier</string>
</dict>
<dict>
<key>Title</key>
<string>apple</string>
<key>FooterText</key>
<string>Apache 2.0 License for apple package</string>
<key>Type</key>
<string>PSGroupSpecifier</string>
</dict>
<dict>
<key>Title</key>
<string>Banana</string>
<key>FooterText</key>
<string>BSD License for Banana package</string>
<key>Type</key>
<string>PSGroupSpecifier</string>
</dict>
</array>
</plist>
1 change: 1 addition & 0 deletions Tests/AckGenTests/Fixtures/invalid-utf8-license.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
��������������������������������