This directory contains the test suite for Icon Grabber CLI.
make testOr directly:
./tests/run_tests.shThe test suite includes the following tests:
- Basic extraction - Default 512x512 PNG extraction
- Custom size - 256x256 icon extraction
- Small size - 64x64 icon extraction
- Large size - 1024x1024 icon extraction
- File size validation - Ensures output files are reasonable size
- Default naming - Tests automatic filename generation (AppName.png)
- Custom output path - Tests directory creation and custom paths
- Positional arguments - Tests CLI argument parsing
- Help flag - Ensures
--helpworks - Version flag - Ensures
--versionworks
- Invalid app path - Graceful failure with non-existent apps
- Missing arguments - Proper error handling
- Multiple sizes - Tests various standard icon sizes (16, 32, 128, 256, 512)
- Force flag - Tests
--forceflag overwrites without prompting - Non-interactive mode - Ensures CI-safe behavior (rejects overwrite without --force)
- Force in non-interactive - Tests force flag works in CI/piped environments
- Short form -f flag - Tests both
-fand--forcework identically
Tests create temporary files that are automatically cleaned up:
test_*.png- Various test output filesSafari.png/Calculator.png- Default named output filestest_output/- Test directory for path tests
All artifacts are removed after test completion.
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
--forcenot used - Prevents tests from hanging waiting for user input
- Ensures CI-safe operation
Tests run automatically on:
- Pull requests to
mainordevelopmentbranches - Manual workflow dispatch
See .github/workflows/ci.yml for the full CI configuration.
-
Test Job
- Runs full integration test suite
- Uploads test artifacts for inspection
- Tests help and version commands
-
Multi-Version Build Test
- Tests on macOS 11, 12, and latest
- Ensures compatibility across macOS versions
- Runs quick smoke tests
-
Lint and Format
- Checks Swift syntax
- Verifies project structure
-
Installation Test
- Tests build and installation process
- Verifies binary works after installation
- Tests user-level installation (no sudo)
- macOS (tests use macOS system apps like Safari or Calculator)
- Swift compiler
- Built binary at
./bin/icongrabber
0- All tests passed1- One or more tests failed
To add a new test:
- Add a test case in
run_tests.sh - Use the helper functions:
print_test <number> <description>pass_testorfail_test <reason>assert_file_exists <path>assert_file_size <path> <min_bytes>assert_exit_code <expected> <actual>
print_test 15 "My new test description"
$CLI /Applications/Safari.app -o test_new.png
assert_file_exists "test_new.png"If tests fail:
- Check the test output for specific failure messages
- Run individual tests by commenting out others in
run_tests.sh - Remove the cleanup trap to inspect test artifacts:
# Comment out: trap cleanup EXIT - Check GitHub Actions artifacts for test outputs
Before pushing changes:
# Build
make build
# Run tests
make test
# Clean up
make clean