Unit tests for nix functions

How are you testing your nix functions? I’m writing some helper nix functions and I’d like to add some tests, but I didn’t find much about testing nix functions.

I found this project: https://github.com/nix-community/nixt
It looks promising, but I don’t understand how to write a test with it

1 Like

There is a runTests function in nixpkgs/lib/debug.nix. It seems many (all?) nixpkgs/lib/tests are using that.

1 Like

thanks @bjornfor, I need to get my head around about how to run them. But the docs:

https://github.com/NixOS/nixpkgs/blob/6571462647d7316aff8b8597ecdf5922547bf365/lib/debug.nix#L154-L166

and this example:

https://github.com/NixOS/nixpkgs/blob/003b68aead6ecd67e9ab47c81ab2f6aae06bcf97/pkgs/test/kernel.nix#L47-L51

are a good starting point :slight_smile:

1 Like