Skip to content

Tidy tests & internal#53

Merged
MusicalNinjaDad merged 26 commits into
mainfrom
tidy_tests
Oct 26, 2025
Merged

Tidy tests & internal#53
MusicalNinjaDad merged 26 commits into
mainfrom
tidy_tests

Conversation

@MusicalNinjaDad

@MusicalNinjaDad MusicalNinjaDad commented Oct 26, 2025

Copy link
Copy Markdown
Owner

Summary by Sourcery

Centralize ELF test data and file utilities into internal packages, introduce a portable libpathcmp comparator, and refactor tests across the codebase to leverage shared helpers for DRY and consistency

New Features:

  • Introduce commonElfs map and ExpectedOutput helper to compute expected Snaggle outputs
  • Add internal helper packages (comparisons, testpaths, paths, logging) to centralize file and path utilities

Enhancements:

  • Refactor tests to use shared helpers (tc.Elf, AssertSameFile, StripLines) and remove duplicated logic
  • Adopt libpathcmp for consistent library path comparisons and update elf parsing and diff to use it

Tests:

  • Simplify Snaggle and CLI tests by replacing manual expected-output construction with ExpectedOutput
  • Update elf package tests to use lowercase libpathcmp and new Diff expectations

@sourcery-ai

sourcery-ai Bot commented Oct 26, 2025

Copy link
Copy Markdown

Reviewer's Guide

This PR centralizes test fixtures and utilities by extracting common ELF definitions, introducing helper functions for expected outputs and file comparisons, refactoring tests to use these new helpers, and encapsulating path and logging logic in new internal packages.

Class diagram for updated binaryDetails and elf.Elf usage

classDiagram
    class binaryDetails {
        string Description
        elf.Elf Elf
        bool Dynamic
        bool Exe
        bool Lib
        bool HasInterpreter
    }
    class Elf {
        string Name
        string Path
        EI_CLASS Class
        Type Type
        string Interpreter
        string[] Dependencies
    }
    binaryDetails --> Elf : Elf
Loading

Class diagram for new internal comparison helpers

classDiagram
    class internal {
        +bool SameFile(path1 string, path2 string)
        +void AssertSameFile(t *testing.T, path1 string, path2 string, mustBeLink bool)
        +bool sameFile(path1 string, path2 string)
        +bool sameInode(path1 string, path2 string)
        +bool sameFilemode(path1 string, path2 string)
        +bool sameHash(path1 string, path2 string)
        +[]byte hashFile(path string)
    }
Loading

Class diagram for new internal path and logging helpers

classDiagram
    class internal {
        +string TestdataPath(path string)
        +string WorkspaceTempDir(t testing.TB)
        +*os.File PermissionDenied(t *testing.T, filename string)
        +string LinkMessage(from string, to string)
        +[]string StripLines(multiline string)
        +string findLib(filename string)
        +regexp.Regexp Ld_linux_64_RE
        +const string P_ld_linux
        +string P_libc
        +string P_libm
        +string P_libpcre2_8
        +string P_libpthread
        +string P_libselinux
        +string P_hello_pie
        +string P_hello_static
        +string P_which
        +string P_id
        +string P_ldd
        +string P_ctypes_so
    }
Loading

Class diagram for refactored CommonBinaries and commonElfs

classDiagram
    class CommonBinaries {
        +map<string, binaryDetails> CommonBinaries(t testing.TB)
    }
    class commonElfs {
        +map<string, elf.Elf> commonElfs
    }
    CommonBinaries --> binaryDetails
    binaryDetails --> Elf
    commonElfs --> Elf
Loading

Class diagram for new ExpectedOutput helper

classDiagram
    class ExpectedOutput {
        +([]string, map[string]string) ExpectedOutput(tc binaryDetails, tmp string)
    }
    ExpectedOutput --> binaryDetails
    binaryDetails --> Elf
Loading

Class diagram for new libpathcmp function

classDiagram
    class Elf {
        +[]string Diff(o Elf)
    }
    class libpathcmp {
        +int libpathcmp(path1 string, path2 string)
    }
    Elf --> libpathcmp : uses
Loading

File-Level Changes

Change Details Files
Extract common ELF definitions and enhance binaryDetails
  • Added HasInterpreter field to binaryDetails
  • Created commonElfs map with predefined elf.Elf entries
  • Updated CommonBinaries to reference commonElfs and set HasInterpreter
internal/testing/testdata.go
Introduce ExpectedOutput helper for test assertions
  • Implemented ExpectedOutput to compute link messages and file mappings
  • Replaced inline expected output logic in tests with ExpectedOutput
internal/testing/testdata.go
Refactor snaggle tests to use shared helpers
  • Swapped inline stdout setup for shared builder and StripLines
  • Replaced manual inode checks with AssertSameFile
  • Removed redundant iter and slices usage in favor of internal logging and comparison utilities
snaggle_test.go
snaggle/cli_test.go
Rename and unify path comparison logic in elf package
  • Replaced internal.Libpathcmp calls with new libpathcmp
  • Added libpathcmp implementation comparing base names for absolute paths
  • Updated dependencies sorting and Diff method to use libpathcmp
elf/elf.go
Extend elf unit tests with portable dependency assertions
  • Lowercased Libpathcmp to libpathcmp in tests
  • Added AssertDependenciesEqual helper for cross-platform path comparisons
elf/elf_unit_test.go
Simplify elf.New tests to use updated binaryDetails
  • Replaced tc.ExpectedElf with tc.Elf
  • Updated Diff assertions to match new field
elf/elf_test.go
Add internal utility packages for testing support
  • Created internal/comparisons.go for file equality and link checks
  • Created internal/testpaths.go for test data path resolution and temp workspace
  • Created internal/paths.go for interpreter and library path discovery
  • Created internal/logging.go with StripLines and LinkMessage
internal/comparisons.go
internal/testpaths.go
internal/paths.go
internal/logging.go

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@codecov

codecov Bot commented Oct 26, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.50314% with 31 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.86%. Comparing base (cdd04ab) to head (cd3b264).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
internal/comparisons.go 71.21% 14 Missing and 5 partials ⚠️
internal/testpaths.go 68.00% 4 Missing and 4 partials ⚠️
elf/elf.go 57.14% 1 Missing and 2 partials ⚠️
internal/paths.go 85.71% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #53      +/-   ##
==========================================
- Coverage   74.13%   73.86%   -0.28%     
==========================================
  Files           5        8       +3     
  Lines         406      417      +11     
==========================================
+ Hits          301      308       +7     
- Misses         71       77       +6     
+ Partials       34       32       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `internal/comparisons.go:37` </location>
<code_context>
+	assert.Truef(t, same, "%s & %s are different files", path1, path2)
+}
+
+func sameFile(path1 string, path2 string) (bool, error) {
+	same, err := sameInode(path1, path2)
+	switch {
</code_context>

<issue_to_address>
**suggestion (performance):** Consider short-circuiting on file size before hashing.

Checking file sizes first can reduce unnecessary hashing and improve performance, especially with large files.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread internal/comparisons.go
@MusicalNinjaDad MusicalNinjaDad enabled auto-merge (squash) October 26, 2025 15:16
@MusicalNinjaDad MusicalNinjaDad enabled auto-merge (squash) October 26, 2025 15:19
@MusicalNinjaDad MusicalNinjaDad enabled auto-merge (squash) October 26, 2025 15:23
@MusicalNinjaDad MusicalNinjaDad merged commit 366d9b3 into main Oct 26, 2025
8 checks passed
@MusicalNinjaDad MusicalNinjaDad deleted the tidy_tests branch October 26, 2025 15:24
This was linked to issues Oct 26, 2025
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.

Tidy CommonBinaries & testing expected stdout tidy internal

1 participant