diff options
Diffstat (limited to 'doc/build-helpers/testers.chapter.md')
| -rw-r--r-- | doc/build-helpers/testers.chapter.md | 104 |
1 files changed, 64 insertions, 40 deletions
diff --git a/doc/build-helpers/testers.chapter.md b/doc/build-helpers/testers.chapter.md index fe1a0954348d..9e46635c600c 100644 --- a/doc/build-helpers/testers.chapter.md +++ b/doc/build-helpers/testers.chapter.md @@ -98,7 +98,8 @@ It has two modes: ```nix { "https://nix\\.dev/manual/nix/[a-z0-9.-]*" = "${nix.doc}/share/doc/nix/manual"; - "https://nixos\\.org/manual/nix/(un)?stable" = "${emptyDirectory}/placeholder-to-disallow-old-nix-docs-urls"; + "https://nixos\\.org/manual/nix/(un)?stable" = + "${emptyDirectory}/placeholder-to-disallow-old-nix-docs-urls"; } ``` @@ -302,18 +303,22 @@ While `testBuildFailure` is designed to keep changes to the original builder's e # Check that a build fails, and verify the changes made during build ```nix -runCommand "example" { - failed = testers.testBuildFailure (runCommand "fail" {} '' - echo ok-ish >$out - echo failing though - exit 3 - ''); -} '' - grep -F 'ok-ish' $failed/result - grep -F 'failing though' $failed/testBuildFailure.log - [[ 3 = $(cat $failed/testBuildFailure.exit) ]] - touch $out -'' +runCommand "example" + { + failed = testers.testBuildFailure ( + runCommand "fail" { } '' + echo ok-ish >$out + echo failing though + exit 3 + '' + ); + } + '' + grep -F 'ok-ish' $failed/result + grep -F 'failing though' $failed/testBuildFailure.log + [[ 3 = $(cat $failed/testBuildFailure.exit) ]] + touch $out + '' ``` ::: @@ -396,15 +401,18 @@ testers.testEqualContents { expected = writeText "expected" '' foo baz baz ''; - actual = runCommand "actual" { - # not really necessary for a package that's in stdenv - nativeBuildInputs = [ gnused ]; - base = writeText "base" '' - foo bar baz - ''; - } '' - sed -e 's/bar/baz/g' $base >$out - ''; + actual = + runCommand "actual" + { + # not really necessary for a package that's in stdenv + nativeBuildInputs = [ gnused ]; + base = writeText "base" '' + foo bar baz + ''; + } + '' + sed -e 's/bar/baz/g' $base >$out + ''; } ``` @@ -515,10 +523,11 @@ Otherwise, the build log explains the difference via `nix-diff`. # Check that two packages produce the same derivation ```nix -testers.testEqualDerivation - "The hello package must stay the same when enabling checks." - hello - (hello.overrideAttrs(o: { doCheck = true; })) +testers.testEqualDerivation "The hello package must stay the same when enabling checks." hello ( + hello.overrideAttrs (o: { + doCheck = true; + }) +) ``` ::: @@ -586,7 +595,10 @@ testers.runCommand { curl -o /dev/null https://example.com touch $out ''; - nativeBuildInputs = with pkgs; [ cacert curl ]; + nativeBuildInputs = with pkgs; [ + cacert + curl + ]; } ``` @@ -603,15 +615,20 @@ If your test is part of the Nixpkgs repository, or if you need a more general en # Run a NixOS test using `runNixOSTest` ```nix -pkgs.testers.runNixOSTest ({ lib, ... }: { - name = "hello"; - nodes.machine = { pkgs, ... }: { - environment.systemPackages = [ pkgs.hello ]; - }; - testScript = '' - machine.succeed("hello") - ''; -}) +pkgs.testers.runNixOSTest ( + { lib, ... }: + { + name = "hello"; + nodes.machine = + { pkgs, ... }: + { + environment.systemPackages = [ pkgs.hello ]; + }; + testScript = '' + machine.succeed("hello") + ''; + } +) ``` ::: @@ -634,10 +651,17 @@ A [NixOS VM test network](https://nixos.org/nixos/manual/index.html#sec-nixos-te { name = "my-test"; nodes = { - machine1 = { lib, pkgs, nodes, ... }: { - environment.systemPackages = [ pkgs.hello ]; - services.foo.enable = true; - }; + machine1 = + { + lib, + pkgs, + nodes, + ... + }: + { + environment.systemPackages = [ pkgs.hello ]; + services.foo.enable = true; + }; # machine2 = ...; }; testScript = '' |
