summaryrefslogtreecommitdiffstats
path: root/nixos/lib/make-options-doc/tests.nix
blob: 795c0ff4fe0059a9287f930a9cf2888a62a5c7cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# Run tests: nix-build -A tests.nixosOptionsDoc

{
  lib,
  nixosOptionsDoc,
  runCommand,
}:
let
  inherit (lib) mkOption types;

  eval = lib.evalModules {
    modules = [
      {
        options.foo.bar.enable = mkOption {
          type = types.bool;
          default = false;
          description = ''
            Enable the foo bar feature.
          '';
        };
      }
    ];
  };

  doc = nixosOptionsDoc {
    inherit (eval) options;
  };
in
{
  /**
    Test that
      - the `nixosOptionsDoc` function can be invoked
      - integration of the module system and `nixosOptionsDoc` (limited coverage)

    The more interesting tests happen in the `nixos-render-docs` package.
  */
  commonMark =
    runCommand "test-nixosOptionsDoc-commonMark"
      {
        commonMarkDefault = doc.optionsCommonMark;
        commonMarkAnchors = doc.optionsCommonMark.overrideAttrs {
          extraArgs = [
            "--anchor-prefix"
            "my-opt-"
            "--anchor-style"
            "legacy"
          ];
        };
      }
      ''
        env | grep ^commonMark | sed -e 's/=/ = /'
        (
          set -x
          grep -F 'foo\.bar\.enable' $commonMarkDefault >/dev/null
          grep -F '{#my-opt-foo.bar.enable}' $commonMarkAnchors >/dev/null
        )
        touch $out
      '';
}