Skip to content
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

test: Add tests for the tar writer #50

Merged
merged 5 commits into from
Jan 6, 2025
Merged

test: Add tests for the tar writer #50

merged 5 commits into from
Jan 6, 2025

Conversation

euanh
Copy link
Collaborator

@euanh euanh commented Dec 19, 2024

Motivation

The tar writer is tested by the end to end tests, but unit tests are more helpful for refactoring and extending it.

Modifications

Result

The basic helper functions underpinning the tar writer will have unit tests, making it easier to test, refactor and extend the tar writer in future.

Test Plan

This pull request adds new tests. All existing tests continue to pass.

@euanh euanh force-pushed the tar-testing branch 2 times, most recently from eb59695 to 1196f8c Compare December 20, 2024 08:49
Preparation for refactoring and unit testing
Splitting the tar function makes it easier to unit test and to
support multiple files in an archive later.
Squashing multiple swift-testing arguments onto the same line makes
the tests very hard to maintain.
Test the underlying helper methods used to write tar headers.
@euanh euanh force-pushed the tar-testing branch 2 times, most recently from 81a71c6 to 2cf2ab5 Compare December 20, 2024 18:43
@euanh euanh changed the title Tar testing test: Add tests for the tar library Jan 6, 2025
@euanh euanh changed the title test: Add tests for the tar library test: Add tests for the tar writer Jan 6, 2025
String(format:) sometimes returns an empty string even if the number
being formatted can be represented in an octal string of the requested
length.  This may be a thread-safety problem and has only been seen
when running the tests.

    swiftlang/swift-corelibs-foundation#5152

This commit changes octal6/11 to use String(value, radix:) and
handle padding directly.   This has not failed during hundreds of
test runs.

Benchmarking the old and new implementations of octal6() shows that
the new version also is about twice as fast as the old one and makes
no allocations, whereas the old version made 7 allocations.
@euanh euanh marked this pull request as ready for review January 6, 2025 13:17
@euanh euanh merged commit 9a3e7af into apple:main Jan 6, 2025
17 checks passed
@euanh euanh deleted the tar-testing branch January 6, 2025 13:20
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.

1 participant