Skip to content

Add test coverage for Acknowledgement.all() API#32

Merged
MartinP7r merged 4 commits into
feature/bug-fixes-and-testsfrom
feature/add-cli-tests
Feb 6, 2026
Merged

Add test coverage for Acknowledgement.all() API#32
MartinP7r merged 4 commits into
feature/bug-fixes-and-testsfrom
feature/add-cli-tests

Conversation

@MartinP7r

Copy link
Copy Markdown
Owner

Summary

  • Add test fixtures for plist decoding
  • Add 4 new tests for Acknowledgement.all() runtime API
  • Tests cover decoding, case-insensitive sorting, and error handling

Changes

  • Package.swift - Add test resources
  • Tests/AckGenTests/Fixtures/ - Test fixture files
  • Tests/AckGenTests/AcknowledgementAllTests.swift - New test file

Test Results

10/10 tests pass (6 existing + 4 new)

Stacked On

This PR is stacked on #31 (Bug fixes, unit tests, and SwiftArgumentParser migration)

- Create test fixtures directory with sample plist and invalid UTF-8 file
- Add AcknowledgementAllTests with 4 tests covering:
  - Decoding from fixture plist
  - Case-insensitive sorting behavior
  - Graceful handling of missing plist (returns empty array)
  - Graceful handling of invalid data (returns empty array)
- Update Package.swift to include test resources
@MartinP7r MartinP7r self-assigned this Feb 6, 2026
@MartinP7r MartinP7r marked this pull request as ready for review February 6, 2026 13:31
Copilot AI review requested due to automatic review settings February 6, 2026 13:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR adds comprehensive test coverage for the Acknowledgement.all() runtime API, building on the unit tests added in PR #31. The PR introduces test fixtures (a valid plist and an invalid UTF-8 file) and 4 new tests covering decoding, sorting, and error handling scenarios.

Changes:

  • Added test resources configuration to Package.swift
  • Created test fixtures for plist decoding and invalid data scenarios
  • Added 4 new tests for the Acknowledgement.all() API covering normal operation, case-insensitive sorting, and error cases

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
Package.swift Adds .copy("Fixtures") to test target resources configuration
Tests/AckGenTests/Fixtures/Acknowledgements.plist Valid plist fixture with 3 acknowledgements for testing decoding and sorting
Tests/AckGenTests/Fixtures/invalid-utf8-license Binary file fixture for testing invalid data handling
Tests/AckGenTests/AcknowledgementAllTests.swift New test file with 4 tests for Acknowledgement.all() API

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +65 to +87

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 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 Tests/AckGenTests/AcknowledgementAllTests.swift Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings February 6, 2026 13:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Tests/AckGenTests/AcknowledgementAllTests.swift
Comment on lines +14 to +16
private func loadAcknowledgementsFromFixture(plistName: String) -> [Acknowledgement] {
return Acknowledgement.all(fromPlist: "Fixtures/\(plistName)", in: Bundle.module)
}

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.

The helper method loadAcknowledgementsFromFixture on line 15 prefixes the plistName with "Fixtures/" and the Acknowledgement.all() method automatically appends ".plist" extension. However, this creates an inconsistency:

  1. Tests use loadAcknowledgementsFromFixture(plistName: "Acknowledgements") which becomes "Fixtures/Acknowledgements"
  2. The all() method will look for "Fixtures/Acknowledgements.plist"

This works correctly for the valid plist test case, but the approach is fragile. If the helper is intended to be reusable for various fixture types (not just .plist files), the automatic ".plist" extension handling in the helper is misleading.

Consider either:

  • Documenting that this helper only works with .plist fixtures, or
  • Making the path construction more explicit in individual tests rather than hiding it in a helper

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 open a new pull request to apply changes based on this feedback
Making the path construction more explicit in individual tests rather than hiding it in a helper

Copilot AI commented Feb 6, 2026

Copy link
Copy Markdown
Contributor

@MartinP7r I've opened a new pull request, #34, to work on those changes. Once the pull request is ready, I'll request review from you.

* Initial plan

* Rename invalid-utf8-license to .plist and refactor test to actually test it

Co-authored-by: MartinP7r <2669027+MartinP7r@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: MartinP7r <2669027+MartinP7r@users.noreply.github.com>

Copilot AI commented Feb 6, 2026

Copy link
Copy Markdown
Contributor

@MartinP7r I've opened a new pull request, #35, to work on those changes. Once the pull request is ready, I'll request review from you.

* Initial plan

* Remove helper method and make path construction explicit in tests

Co-authored-by: MartinP7r <2669027+MartinP7r@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: MartinP7r <2669027+MartinP7r@users.noreply.github.com>
Copilot AI review requested due to automatic review settings February 6, 2026 14:13
@MartinP7r MartinP7r merged commit d7ef9d3 into feature/bug-fixes-and-tests Feb 6, 2026
4 checks passed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

MartinP7r added a commit that referenced this pull request Feb 7, 2026
* Add tests for Acknowledgement.all() with fixture plist

- Create test fixtures directory with sample plist and invalid UTF-8 file
- Add AcknowledgementAllTests with 4 tests covering:
  - Decoding from fixture plist
  - Case-insensitive sorting behavior
  - Graceful handling of missing plist (returns empty array)
  - Graceful handling of invalid data (returns empty array)
- Update Package.swift to include test resources

* Update Tests/AckGenTests/AcknowledgementAllTests.swift

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Test invalid UTF-8 plist handling in Acknowledgement.all() (#34)

* Initial plan

* Rename invalid-utf8-license to .plist and refactor test to actually test it

Co-authored-by: MartinP7r <2669027+MartinP7r@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: MartinP7r <2669027+MartinP7r@users.noreply.github.com>

* Remove test helper in favor of explicit path construction (#35)

* Initial plan

* Remove helper method and make path construction explicit in tests

Co-authored-by: MartinP7r <2669027+MartinP7r@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: MartinP7r <2669027+MartinP7r@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: MartinP7r <2669027+MartinP7r@users.noreply.github.com>
MartinP7r added a commit that referenced this pull request Mar 8, 2026
* empty commit

* Add CLAUDE.md and improvement plan documentation

* Add unit tests for AckGenCore

- Replace broken integration test with 6 comprehensive unit tests
- Test initialization, Comparable, encoding/decoding, and array operations
- All tests passing

This fixes the issue where 'swift test' was running 0 tests

* Migrate CLI to SwiftArgumentParser and fix critical bugs

Breaking changes:
- Migrate from positional arguments to named flags
  Old: ackgen path/to/file.plist 1 "Title"
  New: ackgen --output path/to/file.plist --settings --title "Title"
- Add --help and --version commands (auto-generated)

Bug fixes:
- Fix force unwrap crash when LICENSE files contain invalid UTF-8
- Add proper exit codes (Darwin.exit) so Xcode build phases fail on errors
- Replace error returns with ValidationError throws for better error messages

Dependencies:
- Add swift-argument-parser 1.3.0

Updated Example scripts to use new CLI syntax.

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>

* Add validation for empty acknowledgements

Throws ValidationError when no license files are found, preventing
silent generation of empty plist files. Includes helpful message
directing users to resolve SPM packages.

* Add test coverage for Acknowledgement.all() API (#32)

* Add tests for Acknowledgement.all() with fixture plist

- Create test fixtures directory with sample plist and invalid UTF-8 file
- Add AcknowledgementAllTests with 4 tests covering:
  - Decoding from fixture plist
  - Case-insensitive sorting behavior
  - Graceful handling of missing plist (returns empty array)
  - Graceful handling of invalid data (returns empty array)
- Update Package.swift to include test resources

* Update Tests/AckGenTests/AcknowledgementAllTests.swift

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Test invalid UTF-8 plist handling in Acknowledgement.all() (#34)

* Initial plan

* Rename invalid-utf8-license to .plist and refactor test to actually test it

Co-authored-by: MartinP7r <2669027+MartinP7r@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: MartinP7r <2669027+MartinP7r@users.noreply.github.com>

* Remove test helper in favor of explicit path construction (#35)

* Initial plan

* Remove helper method and make path construction explicit in tests

Co-authored-by: MartinP7r <2669027+MartinP7r@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: MartinP7r <2669027+MartinP7r@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: MartinP7r <2669027+MartinP7r@users.noreply.github.com>

* Update Tests/AckGenTests/AcknowledgementTests.swift

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update CLAUDE.md

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update Tests/AckGenTests/AcknowledgementAllTests.swift

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update Sources/AckGenCLI/AckGen.swift

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* docs: update README and CLAUDE.md to reflect ArgumentParser migration

- Update CLI usage examples from positional args to --output/--settings/--title flags
- Fix CLAUDE.md claiming "no external dependencies" (now has swift-argument-parser)
- Fix --settings flag syntax in CLAUDE.md (it's a flag, not an option)
- Mark "Add tests" as done in README TODO list
- Document Settings.bundle generation in README

---------

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Happy <yesreply@happy.engineering>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: MartinP7r <2669027+MartinP7r@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants