mirror of
https://github.com/nix-community/home-manager.git
synced 2025-03-10 02:36:54 +00:00
Having the tests available in the main Nix Flake introduces unnecessary evaluation for non-developer users and, worse, a dependency on the nmt library. Fixes #6354
44 lines
1.2 KiB
Markdown
44 lines
1.2 KiB
Markdown
# Tests {#sec-tests}
|
|
|
|
Home Manager includes a basic test suite and it is highly recommended to
|
|
include at least one test when adding a module. Tests are typically in
|
|
the form of \"golden tests\" where, for example, a generated
|
|
configuration file is compared to a known correct file.
|
|
|
|
It is relatively easy to create tests by modeling the existing tests,
|
|
found in the `tests` project directory. For a full reference to the
|
|
functions available in test scripts, you can look at NMT's
|
|
[bash-lib](https://git.sr.ht/~rycee/nmt/tree/master/item/bash-lib).
|
|
|
|
The full Home Manager test suite can be run by executing
|
|
|
|
``` shell
|
|
$ nix-shell --pure tests -A run.all
|
|
```
|
|
|
|
in the project root. List all test cases through
|
|
|
|
``` shell
|
|
$ nix-shell --pure tests -A list
|
|
```
|
|
|
|
and run an individual test, for example `alacritty-empty-settings`,
|
|
through
|
|
|
|
``` shell
|
|
$ nix-shell --pure tests -A run.alacritty-empty-settings
|
|
```
|
|
|
|
However, those invocations will impurely source the system's Nixpkgs,
|
|
and may cause failures. To run against the Nixpkgs from the `flake.lock` file,
|
|
use instead e.g.
|
|
|
|
``` shell
|
|
$ nix build --reference-lock-file flake.lock ./tests#test-all
|
|
```
|
|
|
|
or
|
|
|
|
``` shell
|
|
$ nix build --reference-lock-file flake.lock ./tests#test-alacritty-empty-settings
|
|
```
|