mirror of
https://gitlab.com/TECHNOFAB/nixtest.git
synced 2026-02-02 19:35:11 +01:00
Compare commits
No commits in common. "bc36c39b0929bdfaab0908d8bd852c2114e3383f" and "4a55db97979b8b06ebd68b4b0772fcb76d79d2fa" have entirely different histories.
bc36c39b09
...
4a55db9797
5 changed files with 7 additions and 94 deletions
|
|
@ -1,6 +1,4 @@
|
||||||
# Example Configs
|
# Example Configs
|
||||||
|
|
||||||
- [nixtest itself](https://gitlab.com/TECHNOFAB/nixtest)
|
|
||||||
see `flake.nix` and `tests/`
|
|
||||||
- [TECHNOFAB/nix-gitlab-ci](https://gitlab.com/TECHNOFAB/nix-gitlab-ci)
|
- [TECHNOFAB/nix-gitlab-ci](https://gitlab.com/TECHNOFAB/nix-gitlab-ci)
|
||||||
see `tests/`
|
see tests/
|
||||||
|
|
|
||||||
|
|
@ -1,53 +0,0 @@
|
||||||
# Reference
|
|
||||||
|
|
||||||
## `flakeModule`
|
|
||||||
|
|
||||||
The `flakeModule` for [flake-parts](https://flake.parts).
|
|
||||||
|
|
||||||
## `lib`
|
|
||||||
|
|
||||||
### `module`
|
|
||||||
|
|
||||||
The nix module for validation of inputs etc.
|
|
||||||
Used internally by `mkNixtestConfig`.
|
|
||||||
|
|
||||||
### `autodiscover`
|
|
||||||
|
|
||||||
```nix
|
|
||||||
autodiscover {
|
|
||||||
dir,
|
|
||||||
pattern ? ".*_test.nix",
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
Finds all test files in `dir` matching `pattern`.
|
|
||||||
Returns a list of modules (can be passed to `mkNixtest`'s `modules` arg).
|
|
||||||
|
|
||||||
### `mkNixtestConfig`
|
|
||||||
|
|
||||||
```nix
|
|
||||||
mkNixtestConfig {
|
|
||||||
modules,
|
|
||||||
args ? {},
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
Evaluates the test `modules`.
|
|
||||||
`args` are passed to the modules using `_module.args = args`.
|
|
||||||
|
|
||||||
**Noteworthy attributes**:
|
|
||||||
|
|
||||||
- `app`: nixtest wrapper
|
|
||||||
- `finalConfigJson`: derivation containing the tests json file
|
|
||||||
|
|
||||||
### `mkNixtest`
|
|
||||||
|
|
||||||
```nix
|
|
||||||
mkNixtest {
|
|
||||||
modules,
|
|
||||||
args ? {},
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
Creates the nixtest wrapper, using the tests in `modules`.
|
|
||||||
Basically `(mkNixtestConfig <arguments>).app`.
|
|
||||||
|
|
@ -2,9 +2,6 @@
|
||||||
|
|
||||||
## Flake Module
|
## Flake Module
|
||||||
|
|
||||||
The easiest way to use Nixtest is probably using the flakeModule.
|
|
||||||
Just import `nixtest.flakeModule`, then define suites and tests in `perSystem`:
|
|
||||||
|
|
||||||
```nix
|
```nix
|
||||||
{
|
{
|
||||||
inputs.nixtest.url = "gitlab:TECHNOFAB/nixtest?dir=lib";
|
inputs.nixtest.url = "gitlab:TECHNOFAB/nixtest?dir=lib";
|
||||||
|
|
@ -37,25 +34,10 @@ Just import `nixtest.flakeModule`, then define suites and tests in `perSystem`:
|
||||||
|
|
||||||
## Library
|
## Library
|
||||||
|
|
||||||
You can also use the lib directly, like this for example:
|
You can also integrate nixtest in your own workflow by using the lib functions directly.
|
||||||
|
Check out `flakeModule.nix` to see how it's used there.
|
||||||
|
|
||||||
```nix
|
<!-- TODO: more detailed? -->
|
||||||
packages.tests = ntlib.mkNixtest {
|
|
||||||
modules = ntlib.autodiscover {dir = ./tests;};
|
|
||||||
args = {
|
|
||||||
inherit pkgs ntlib;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
```
|
|
||||||
|
|
||||||
This will auto-discover all test files ending with `_test.nix`.
|
|
||||||
See [reference](reference.md) for all params to `autodiscover`.
|
|
||||||
|
|
||||||
`ntlib` can be defined like this:
|
|
||||||
|
|
||||||
```nix
|
|
||||||
ntlib = inputs.nixtests.lib {inherit pkgs;};
|
|
||||||
```
|
|
||||||
|
|
||||||
## Define Tests
|
## Define Tests
|
||||||
|
|
||||||
|
|
@ -102,17 +84,9 @@ Examples:
|
||||||
# to make it more reproducible and cleaner, use --pure to switch to pure
|
# to make it more reproducible and cleaner, use --pure to switch to pure
|
||||||
# mode which will unset all env variables before running the test. That
|
# mode which will unset all env variables before running the test. That
|
||||||
# requires you to set PATH yourself then:
|
# requires you to set PATH yourself then:
|
||||||
#
|
|
||||||
# ''
|
|
||||||
# export PATH="${lib.makeBinPath [pkgs.gnugrep]}"
|
|
||||||
# grep -q "test" ${builtins.toFile "test" "test"}
|
|
||||||
# '';
|
|
||||||
#
|
|
||||||
# you can also use the helpers to make it nicer to read:
|
|
||||||
''
|
''
|
||||||
${ntlib.helpers.path [pkgs.gnugrep]}
|
export PATH="${lib.makeBinPath [pkgs.gnugrep]}"
|
||||||
${ntlib.helpers.scriptHelpers} # this adds helpers like assert etc.
|
grep -q "test" ${builtins.toFile "test" "test"}
|
||||||
assert_file_contains ${builtins.toFile "test" "test"} "test" "file should contain 'test'"
|
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
|
@ -128,7 +102,3 @@ Examples:
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
```
|
```
|
||||||
|
|
||||||
!!! note
|
|
||||||
|
|
||||||
for more examples see [examples](./examples.md)
|
|
||||||
|
|
|
||||||
|
|
@ -106,13 +106,11 @@
|
||||||
nav = [
|
nav = [
|
||||||
{"Introduction" = "index.md";}
|
{"Introduction" = "index.md";}
|
||||||
{"Usage" = "usage.md";}
|
{"Usage" = "usage.md";}
|
||||||
{"Reference" = "reference.md";}
|
|
||||||
{"CLI" = "cli.md";}
|
{"CLI" = "cli.md";}
|
||||||
{"Example Configs" = "examples.md";}
|
{"Example Configs" = "examples.md";}
|
||||||
];
|
];
|
||||||
markdown_extensions = [
|
markdown_extensions = [
|
||||||
"pymdownx.superfences"
|
"pymdownx.superfences"
|
||||||
"admonition"
|
|
||||||
];
|
];
|
||||||
extra.analytics = {
|
extra.analytics = {
|
||||||
provider = "umami";
|
provider = "umami";
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,6 @@
|
||||||
path = pkgs: "export PATH=${lib.makeBinPath pkgs}";
|
path = pkgs: "export PATH=${lib.makeBinPath pkgs}";
|
||||||
pathAdd = pkgs: "export PATH=$PATH:${lib.makeBinPath pkgs}";
|
pathAdd = pkgs: "export PATH=$PATH:${lib.makeBinPath pkgs}";
|
||||||
scriptHelpers = builtins.readFile ./scriptHelpers.sh;
|
scriptHelpers = builtins.readFile ./scriptHelpers.sh;
|
||||||
toJsonFile = any: builtins.toFile "actual" (builtins.unsafeDiscardStringContext (builtins.toJSON any));
|
toJsonFile = any: builtins.toFile "actual" (builtins.toJSON any);
|
||||||
toPrettyFile = any: builtins.toFile "actual" (lib.generators.toPretty {} any);
|
toPrettyFile = any: builtins.toFile "actual" (lib.generators.toPretty {} any);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue