-
-
Notifications
You must be signed in to change notification settings - Fork 11
Add test coverage for Acknowledgement.all() API #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7eedc94
Add tests for Acknowledgement.all() with fixture plist
MartinP7r ed77756
Update Tests/AckGenTests/AcknowledgementAllTests.swift
MartinP7r 3f309ec
Test invalid UTF-8 plist handling in Acknowledgement.all() (#34)
Copilot f67921d
Remove test helper in favor of explicit path construction (#35)
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| } | ||
|
MartinP7r marked this conversation as resolved.
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| �������������������������������� |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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:
Acknowledgement.all(fromPlist: "invalid-utf8-license", in: bundle)to actually test the invalid UTF-8 file, orAcknowledgement.all()API doesn't support loading files without the.plistextension, orThere was a problem hiding this comment.
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.