Improve test coverage for System.Formats.Tar APIs#123989
Improve test coverage for System.Formats.Tar APIs#123989
Conversation
Co-authored-by: rzikm <32671551+rzikm@users.noreply.github.com>
Co-authored-by: rzikm <32671551+rzikm@users.noreply.github.com>
src/libraries/System.Formats.Tar/tests/TarEntry/TarEntry.AdditionalCoverage.Tests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Formats.Tar/tests/TarEntry/TarEntry.AdditionalCoverage.Tests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Formats.Tar/tests/TarEntry/TarEntry.AdditionalCoverage.Tests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Formats.Tar/tests/TarEntry/TarEntry.AdditionalCoverage.Tests.cs
Outdated
Show resolved
Hide resolved
…est file Co-authored-by: rzikm <32671551+rzikm@users.noreply.github.com>
|
@copilot There seem to be test failures, can you investigate? |
Co-authored-by: rzikm <32671551+rzikm@users.noreply.github.com>
Fixed in commit 1e738b3. The The fix: Calculate the checksum by treating bytes 148-155 (the checksum field) as spaces, then write the calculated checksum to that location. This follows the tar header specification. |
src/libraries/System.Formats.Tar/tests/TarReader/TarReader.GetNextEntry.Tests.cs
Show resolved
Hide resolved
…orted_EntryType test Co-authored-by: rzikm <32671551+rzikm@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds additional unit tests to increase coverage of System.Formats.Tar behaviors around file creation/extraction and reader handling of unsupported entry types.
Changes:
- Added a Unix test ensuring executable permissions are preserved when archiving and extracting a file.
- Added a reader test that validates a
NotSupportedExceptionis thrown when encountering an unsupported tar entry type. - Added a Unix test validating
TarWriter.WriteEntrycan create an entry from a dot-prefixed (“hidden”) file.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntry.File.Tests.Unix.cs | Adds a test for writing a dot-prefixed (“hidden”) file into an archive and reading it back. |
| src/libraries/System.Formats.Tar/tests/TarReader/TarReader.GetNextEntry.Tests.cs | Adds a test building a minimal tar header for an unsupported entry type and asserting GetNextEntry throws. |
| src/libraries/System.Formats.Tar/tests/TarEntry/TarEntry.ExtractToFile.Tests.Unix.cs | Adds a test for executable-bit preservation across archive + extraction on Unix. |
src/libraries/System.Formats.Tar/tests/TarEntry/TarEntry.ExtractToFile.Tests.Unix.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Formats.Tar/tests/TarReader/TarReader.GetNextEntry.Tests.cs
Show resolved
Hide resolved
…ctToFile.Tests.Unix.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
🤖 Copilot Code Review — PR #123989Holistic AssessmentMotivation: This PR adds test coverage for three items from the pending Tar API feedback issue #68230: executable bit preservation, reading unsupported entry types, and hidden file support. These are reasonable edge cases that warrant test coverage. Approach: The tests follow established patterns in the test files and use appropriate conditional attributes for Unix-specific tests. The manual TAR header construction for the unsupported entry type test is acceptable for this specific scenario. Summary: Detailed Findings✅ Correctness — Executable bit preservation test is properly implementedThe UnixFileMode expectedExecutableBits = executableMode & ~UMask & executeBitsMask;
UnixFileMode actualExecutableBits = extractedMode & executeBitsMask;
Assert.Equal(expectedExecutableBits, actualExecutableBits);This is correct because ✅ Correctness — Checksum calculation for unsupported entry type testThe manual header construction in
Verified that this exception is thrown from TarEntryType.SparseFile => throw new NotSupportedException(SR.Format(SR.TarEntryTypeNotSupported, header._typeFlag)),
|
|
@copilot Address the concerns from the above comment:
|
…oss-platform Co-authored-by: rzikm <32671551+rzikm@users.noreply.github.com>
Done in commit 1ed2f0a:
|
Description
This PR adds test coverage for three items from issue #68230:
Executable permission preservation: Tests that executable permissions survive archive creation and extraction across all tar formats (V7, Ustar, Pax, Gnu). The test properly accounts for umask when verifying permissions.
Unsupported entry types: Tests that TarReader can read archives containing unsupported entry types (MultiVolume, SparseFile, TapeVolume) without throwing exceptions. The test manually creates a valid GNU tar header with proper checksum calculation and documented header fields.
Hidden file support: Tests that files starting with '.' can be successfully added to tar archives and extracted. This test runs on all platforms since dot-prefixed filenames are valid everywhere.
Changes Made
Added
Archive_And_Extract_Executable_PreservesExecutableBittest toTarEntry.ExtractToFile.Tests.Unix.cs:Added
Read_Archive_With_Unsupported_EntryTypetest toTarReader.GetNextEntry.Tests.cs:Added
Create_Entry_From_HiddenFiletest toTarWriter.WriteEntry.File.Tests.Unix.cs:Technical Notes
Tests follow established patterns in the repository
Platform-specific tests use appropriate
ConditionalTheoryattributes where neededManual tar header construction in unsupported entry type test includes proper checksum calculation where the checksum field (bytes 148-155) is treated as 8 space characters during calculation
Executable permission test accounts for umask to avoid flaky test failures
Contributes to Tar APIs pending feedback to address #68230
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.