Skip to content

Conversation

@MichaelRWolf
Copy link

@MichaelRWolf MichaelRWolf commented Jan 21, 2025

Summary for Pull Request

This update introduces enhancements and improvements to the Bash test scripts:

  1. New Test Case:

    • Added an unspecified test case in test.sh that verifies input without a name using the meld diff tool.
    • Introduced a new approval file: unspecified_test_name.approved.
  2. Enhancements to verify.sh:

    • Implemented set -euo pipefail for improved script robustness.
    • Added support for Git-configured diff tools and fallback to Visual Studio Code (code --diff).
    • Introduced functions for better code organization, including:
      • warn() for error messaging.
      • debug_arguments() for debugging script arguments.
      • pass(), fail(), fail_and_diff(), and compare_and_approve() for improved test processing.
    • Added a -D flag to allow debugging without running the full comparison and approval process.
    • Improved handling of unspecified test names by defaulting to unspecified_test_name.
    • Refactored code for better readability and maintainability.

These changes enhance script flexibility, error handling, and debugging capabilities while maintaining backward compatibility.

Summary by Sourcery

Tests:

  • Add a test case for verifying input without a name.

@sourcery-ai
Copy link

sourcery-ai bot commented Jan 21, 2025

Reviewer's Guide by Sourcery

This pull request enhances the test scripts by adding a new test case, improving script robustness, and adding debugging capabilities. The changes include the addition of a new test case in test.sh that verifies input without a name using the meld diff tool, and enhancements to verify.sh to support Git-configured diff tools, improved error handling, and debugging capabilities.

Sequence diagram for verify.sh test execution

sequenceDiagram
    participant Script as verify.sh
    participant Git as Git Config
    participant Files as File System
    participant DiffTool as Diff Tool

    Script->>Git: Check git diff.tool config
    Git-->>Script: Return configured tool
    Script->>Files: Create/update received file
    Script->>Files: Check approved file
    alt Files match
        Script->>Files: Remove received file
        Script->>+Script: Display pass message
    else Files differ
        Script->>DiffTool: Show differences
        DiffTool-->>Script: Display diff view
        Script->>+Script: Display fail message
    end
Loading

Class diagram for verify.sh functions

classDiagram
    class VerifyScript {
        +warn(message)
        +debug_arguments()
        +main()
        +pass(test_name)
        +fail(test_name)
        +fail_and_diff(test_name)
        +pass_and_rm_received(test_name)
        +compare_and_approve(test_name)
    }
    note for VerifyScript "New modular function structure"

    class Configuration {
        +difftool
        +test_name
        +received_text
        +debug_mode
    }

    VerifyScript --> Configuration: uses
Loading

Flow diagram of enhanced verify.sh script

flowchart TD
    Start([Start]) --> Init[Initialize difftool]
    Init --> ParseArgs[Parse command line arguments]
    ParseArgs --> CheckName{Test name
specified?}
    CheckName -->|No| SetDefault[Set default test name]
    CheckName -->|Yes| ProcessInput
    SetDefault --> ProcessInput[Process input text]
    ProcessInput --> Debug{Debug mode?}
    Debug -->|Yes| ShowDebug[Show debug info]
    Debug -->|No| Compare[Compare files]
    Compare --> Match{Files match?}
    Match -->|Yes| Pass[Pass test & remove received]
    Match -->|No| Fail[Fail test & show diff]
    ShowDebug --> End([End])
    Pass --> End
    Fail --> End
Loading

File-Level Changes

Change Details Files
Added a new test case to test.sh that verifies input without a name using the meld diff tool.
  • Added a new test case to test.sh that uses verify.sh without the -t option.
  • Created a new approval file unspecified_test_name.approved.
bash/test.sh
bash/unspecified_test_name.approved
Implemented set -euo pipefail for improved script robustness in verify.sh.
  • Added set -euo pipefail to the beginning of the script to ensure that the script exits immediately if a command exits with a non-zero status or if a pipe fails.
bash/verify.sh
Added support for Git-configured diff tools and fallback to Visual Studio Code in verify.sh.
  • The script now checks for a Git-configured diff tool using git config --get diff.tool.
  • If a Git diff tool is configured, it will be used with git difftool --tool <tool> --no-index.
  • If no Git diff tool is configured, the script will fall back to Visual Studio Code (code --diff) if it is available.
  • If neither a Git diff tool nor Visual Studio Code is available, the script will not use a diff tool.
bash/verify.sh
Introduced functions for better code organization in verify.sh.
  • Added a warn() function for error messaging.
  • Added a debug_arguments() function for debugging script arguments.
  • Added pass(), fail(), fail_and_diff(), and compare_and_approve() functions for improved test processing.
bash/verify.sh
Added a -D flag to allow debugging without running the full comparison and approval process in verify.sh.
  • Added a -D flag to the script to enable debugging without running the full comparison and approval process.
  • When the -D flag is used, the script will output the arguments and exit without comparing the received and approved files.
bash/verify.sh
Improved handling of unspecified test names by defaulting to unspecified_test_name in verify.sh.
  • If the -t option is not provided, the script will now default to using unspecified_test_name as the test name.
bash/verify.sh
Refactored code for better readability and maintainability in verify.sh.
  • The main logic of the script is now encapsulated in a main function.
  • The code has been reorganized to improve readability and maintainability.
bash/verify.sh

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.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a 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. You can also use
    this command to specify where the summary should be inserted.

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

@nitsanavni
Copy link
Collaborator

Captura de pantalla 2025-01-21 a las 10 32 25

@nitsanavni
Copy link
Collaborator

@MichaelRWolf Thanks for your 2 year old contribution :)
Shall we walk through it together?
Also - can you see the failing CI workflow?

@MichaelRWolf
Copy link
Author

Happy to walk through it some time. Would Thursday work? If so, send an invitaiton to MichaelRWolf@att.net.

I do see the CI broken pipe. It would be good pair on either fixing this or creating a better test.

Thanks for reminding me (on Monday) about ApprovalTests.shell. I had forgotten about it, and to see how much better at git PR's I am now versus 2 years ago (i.e. creating a fork then creating a PR versus dead-end changes in my own local repo). ;-)

It even felt like a great opportunity to try it out as we slice/peel Diana's fork of Byron's AoB code. Nice synergy.

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.

2 participants