Skip to content

Latest commit

 

History

History
149 lines (107 loc) · 3.78 KB

File metadata and controls

149 lines (107 loc) · 3.78 KB

Icon Grabber Tests

This directory contains the test suite for Icon Grabber CLI.

Running Tests

Run all tests

make test

Or directly:

./tests/run_tests.sh

Test Suite

The test suite includes the following tests:

Functional Tests

  1. Basic extraction - Default 512x512 PNG extraction
  2. Custom size - 256x256 icon extraction
  3. Small size - 64x64 icon extraction
  4. Large size - 1024x1024 icon extraction
  5. File size validation - Ensures output files are reasonable size
  6. Default naming - Tests automatic filename generation (AppName.png)
  7. Custom output path - Tests directory creation and custom paths
  8. Positional arguments - Tests CLI argument parsing
  9. Help flag - Ensures --help works
  10. Version flag - Ensures --version works

Error Handling Tests

  1. Invalid app path - Graceful failure with non-existent apps
  2. Missing arguments - Proper error handling
  3. Multiple sizes - Tests various standard icon sizes (16, 32, 128, 256, 512)

File Overwrite Protection Tests

  1. Force flag - Tests --force flag overwrites without prompting
  2. Non-interactive mode - Ensures CI-safe behavior (rejects overwrite without --force)
  3. Force in non-interactive - Tests force flag works in CI/piped environments
  4. Short form -f flag - Tests both -f and --force work identically

Test Output

Tests create temporary files that are automatically cleaned up:

  • test_*.png - Various test output files
  • Safari.png / Calculator.png - Default named output files
  • test_output/ - Test directory for path tests

All artifacts are removed after test completion.

CI/Non-Interactive Behavior

The tool detects when running in non-interactive mode (CI, piped input, etc.) using isatty(). In such environments:

  • File overwrite prompts are skipped
  • Returns error code 1 if file exists and --force not used
  • Prevents tests from hanging waiting for user input
  • Ensures CI-safe operation

GitHub Actions

Tests run automatically on:

  • Pull requests to main or development branches
  • Manual workflow dispatch

See .github/workflows/ci.yml for the full CI configuration.

CI Jobs

  1. Test Job

    • Runs full integration test suite
    • Uploads test artifacts for inspection
    • Tests help and version commands
  2. Multi-Version Build Test

    • Tests on macOS 11, 12, and latest
    • Ensures compatibility across macOS versions
    • Runs quick smoke tests
  3. Lint and Format

    • Checks Swift syntax
    • Verifies project structure
  4. Installation Test

    • Tests build and installation process
    • Verifies binary works after installation
    • Tests user-level installation (no sudo)

Requirements

  • macOS (tests use macOS system apps like Safari or Calculator)
  • Swift compiler
  • Built binary at ./bin/icongrabber

Exit Codes

  • 0 - All tests passed
  • 1 - One or more tests failed

Adding New Tests

To add a new test:

  1. Add a test case in run_tests.sh
  2. Use the helper functions:
    • print_test <number> <description>
    • pass_test or fail_test <reason>
    • assert_file_exists <path>
    • assert_file_size <path> <min_bytes>
    • assert_exit_code <expected> <actual>

Example:

print_test 15 "My new test description"
$CLI /Applications/Safari.app -o test_new.png
assert_file_exists "test_new.png"

Debugging Failed Tests

If tests fail:

  1. Check the test output for specific failure messages
  2. Run individual tests by commenting out others in run_tests.sh
  3. Remove the cleanup trap to inspect test artifacts:
    # Comment out: trap cleanup EXIT
  4. Check GitHub Actions artifacts for test outputs

Local Testing

Before pushing changes:

# Build
make build

# Run tests
make test

# Clean up
make clean