Skip to content

Always show absolute destination in stdout#91

Merged
MusicalNinjaDad merged 5 commits into
mainfrom
relative_dest
Nov 4, 2025
Merged

Always show absolute destination in stdout#91
MusicalNinjaDad merged 5 commits into
mainfrom
relative_dest

Conversation

@MusicalNinjaDad

@MusicalNinjaDad MusicalNinjaDad commented Nov 4, 2025

Copy link
Copy Markdown
Owner

closes #89

Summary by Sourcery

Ensure destinations are always shown as absolute paths by normalizing target directories and assertion directories, and by adding a test mode to validate both absolute and relative path handling.

New Features:

  • Add a "relative" flag in TestCases to test and display destinations relative to the working directory

Enhancements:

  • Normalize link target directories to absolute paths in the link() function
  • Convert assertion directory paths to absolute before walking in DirectoryContents

Tests:

  • Extend TestCases to include relative destination scenarios and log test case details
  • Introduce a pwd() helper in tests to retrieve the current working directory

@sourcery-ai

sourcery-ai Bot commented Nov 4, 2025

Copy link
Copy Markdown

Reviewer's Guide

This PR adds support for always showing absolute (or relative) destinations in stdout by extending the TestCases iterator with a ‘relative’ mode and computing destination paths accordingly, introduces a helper to fetch the working directory, enforces absolute path resolution in the link helper, and updates the directory‐contents assertion to operate on absolute paths.

Sequence diagram for absolute/relative destination path handling in TestCases

sequenceDiagram
    participant TestCases
    participant T_testing_T
    participant pwd_t
    participant testbody
    Note over TestCases: For each test, check 'relative' mode
    TestCases->>T_testing_T: Create TestCase with Dest
    alt relative mode
        TestCases->>pwd_t: Get working directory
        TestCases->>T_testing_T: Compute relative path for Dest
        TestCases->>TestCase: Set Dest to relative path
    else absolute mode
        TestCases->>TestCase: Dest remains absolute
    end
    TestCases->>testbody: Run test with TestCase
Loading

Class diagram for updated TestCase and Asserter usage

classDiagram
    class TestCase {
        +string Src
        +string Dest
        +[]string ExpectedStdout
        +map[string]string ExpectedFiles
        +Binary ExpectedBinary
        +[]snaggle.Option Options
        +[]string Flags
    }
    class Asserter {
        +testing.T t
        +Testify Testify
        +DirectoryContents(ExpectedContents map[string]string, dir string)
    }
    TestCase --> Binary
    Asserter --> Testify
    Asserter : DirectoryContents() now resolves dir to absolute path
    TestCase : Dest can be absolute or relative depending on test mode
Loading

Class diagram for link helper enforcing absolute targetDir

classDiagram
    class Link {
        +error link(sourcePath string, targetDir string)
        +targetDir is resolved to absolute path before use
    }
Loading

Class diagram for pwd helper function

classDiagram
    class pwd {
        +string pwd(t *testing.T)
        +calls os.Getwd()
        +returns working directory
    }
Loading

File-Level Changes

Change Details Files
Extend TestCases iterator to support relative destination paths and introduce pwd helper
  • Added outer loop over a new 'relative' boolean alongside 'inplace'
  • Appended '_relative' suffix when relative=true and computed tc.Dest via filepath.Rel
  • Refactored nested t.Run blocks to incorporate relative logic before invoking testbody
  • Implemented pwd(t) helper to retrieve current working directory with error handling
internal/testing/testiterator.go
Enforce absolute directory paths in DirectoryContents assertion
  • Called filepath.Abs on dir at start of DirectoryContents and checked the error
  • Updated WalkDir error variable handling to reuse the outer err
internal/testing/assertions.go
Resolve targetDir to absolute path in link utility
  • Inserted filepath.Abs on targetDir at the start of link and returned errors
  • Simplified error assignment when calling filepath.EvalSymlinks
snaggle.go

Assessment against linked issues

Issue Objective Addressed Explanation
#89 When the target (destination) is relative, show the absolute path or prefix it with '.' in stdout or logs.

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

@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 - here's some feedback:

  • The nested loops for relative/inplace/recursive in TestCases are duplicated in two code paths—consider refactoring the test-case setup into shared helpers to reduce redundancy and improve readability.
  • The pwd helper uses t.Error on Getwd failure but then continues execution, which can lead to confusing downstream errors—switch to t.Fatal to abort immediately on critical failures.
  • In DirectoryContents, using t.Error for filepath.Abs failures may allow the test to proceed with an invalid path—fail fast with t.Fatal to avoid masking errors.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The nested loops for relative/inplace/recursive in TestCases are duplicated in two code paths—consider refactoring the test-case setup into shared helpers to reduce redundancy and improve readability.
- The pwd helper uses t.Error on Getwd failure but then continues execution, which can lead to confusing downstream errors—switch to t.Fatal to abort immediately on critical failures.
- In DirectoryContents, using t.Error for filepath.Abs failures may allow the test to proceed with an invalid path—fail fast with t.Fatal to avoid masking errors.

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.

@codecov

codecov Bot commented Nov 4, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.37209% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.39%. Comparing base (c03e3fc) to head (7a7f80f).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
internal/testing/testiterator.go 92.10% 3 Missing and 3 partials ⚠️
internal/testing/assertions.go 60.00% 1 Missing and 1 partial ⚠️
snaggle.go 60.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #91      +/-   ##
==========================================
- Coverage   73.77%   73.39%   -0.38%     
==========================================
  Files          12       12              
  Lines         610      639      +29     
==========================================
+ Hits          450      469      +19     
- Misses        112      117       +5     
- Partials       48       53       +5     

☔ 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.

@MusicalNinjaDad MusicalNinjaDad merged commit 6e5b83d into main Nov 4, 2025
11 checks passed
@MusicalNinjaDad MusicalNinjaDad deleted the relative_dest branch November 4, 2025 15:41
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.

target is relative: show absolute or prefix with .

1 participant