Test Levels
1. Unit Testing
Unit tests use the standardtesting package and github.com/alecthomas/assert/v2 to test that functions and small components behave as expected for a wide range of inputs, especially edge cases.
- Location:
internal/chezmoi/*_test.go - Purpose: Test individual functions and components in isolation
2. File System Integration Tests
Integration tests usetesting and github.com/twpayne/go-vfs/v5 to test chezmoi’s effects on the file system.
- Location:
internal/chezmoi/*_test.goandinternal/cmd/*cmd_test.go - Purpose: Test interactions with the file system in a controlled environment
3. High-Level Integration Tests
High-level integration tests usegithub.com/rogpeppe/go-internal/testscript to test complete workflows and command interactions.
- Location:
internal/cmd/testdata/scripts/*.txtar - Test runner:
internal/cmd/main_test.go - Purpose: Test complete user workflows and command-line interactions
4. Distribution and OS Tests
Full test suite execution across different environments:- Linux distributions: Run using Docker (in
assets/docker) - Other OSes: Run using Vagrant (in
assets/vagrant) - Windows: Run in GitHub Actions
- Purpose: Ensure compatibility across different operating systems and distributions
Running Tests
Run All Tests
Run Individual Tests
Run a specific test:Run Docker Tests
Test on specific Linux distributions:Run Vagrant Tests
Test on other operating systems:Code Coverage
Generate a coverage report:Test Requirements
chezmoi’s tests include integration tests with other software. If the other software is not found in$PATH, the tests will be skipped. Running the full set of tests requires:
agebase64bashbzip2gitgpggzipperlpython3ragerubysedsha256sumtrtrueunzipxzzipzstd
Platform Compatibility
Tests should, if at all possible, run unmodified on all operating systems tested in CI:- Linux
- macOS
- Windows
- FreeBSD
Shell Compatibility
If you use
fish as your primary shell, you may get warnings from Fish during tests. These can be avoided by running tests with SHELL=bash or SHELL=zsh:See Also
- Architecture - Understanding chezmoi’s architecture
- Contributing - Guidelines for contributing changes