Testing framework for Nix code
Find a file
2024-01-02 12:44:07 +00:00
test add tests 2024-01-02 12:44:07 +00:00
tix add tests 2024-01-02 12:44:07 +00:00
flake.lock document throws, run alejandra 2024-01-02 11:13:47 +00:00
flake.nix add tests 2024-01-02 12:44:07 +00:00
mytest.nix document throws, run alejandra 2024-01-02 11:13:47 +00:00
README.md document throws, run alejandra 2024-01-02 11:13:47 +00:00
result add tests 2024-01-02 12:44:07 +00:00

Tix

Test your Nix is only ticks.

Usage

Make a test file:

{ it, ... }:
[
    (it "can add numbers" {
        actual = 2 + 2;
        expected = 4;
    })
    (it "loves big brother" {
        actual = 2 + 2;
        expected = 5;
    })
    (it "throws a party" {
        actual = throw "a party";
        throws = true;
    })
]

Add tix as an input to your flake, and use it to build a test output.

{
    description = "My test driven flake";

    inputs = {
        tix.url = "git+https://git.tristans.cloud/tristan/tix";
    };

    outpts = {self, tix, ...}: {
        packages.x86_64-linux.test = tix.run [
            ./mytest.nix
        ];
    };
}

Then run the generated package.

nix run .#test --show-trace

Watch for changes while you are developing your package by adding a new output.

tix.watch "nix run .#test | ${pkgs.fx}/bin/fx" "fx";

I am piping the output into fx so I can navigate it easier.

"fx" is the process name that must be killed before rerunning.