about summary refs log tree commit diff
path: root/nix/writeTree/tests/default.nix
blob: c5858ee96eb89db408a6f7ad26ca32ad61703b96 (plain) (blame)
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
{ depot, pkgs, lib, ... }:

let
  inherit (pkgs) runCommand writeText writeTextFile;
  inherit (depot.nix) writeTree;

  checkTree = name: tree: expected:
    runCommand "writeTree-test-${name}"
      {
        nativeBuildInputs = [ pkgs.buildPackages.lr ];
        passAsFile = [ "expected" ];
        inherit expected;
      } ''
      actualPath="$NIX_BUILD_TOP/actual"
      cd ${lib.escapeShellArg (writeTree name tree)}
      lr . > "$actualPath"
      diff -u "$expectedPath" "$actualPath" | tee "$out"
    '';
in

depot.nix.readTree.drvTargets {
  empty = checkTree "empty" { }
    ''
      .
    '';

  simple-paths = checkTree "simple"
    {
      writeTree = {
        meta = {
          "owners.txt" = ../OWNERS;
        };
        "code.nix" = ../default.nix;
        all-tests = ./.;
        nested.dirs.eval-time = builtins.toFile "owothia" ''
          hold me owo
        '';
      };
    }
    ''
      .
      ./writeTree
      ./writeTree/all-tests
      ./writeTree/all-tests/default.nix
      ./writeTree/code.nix
      ./writeTree/meta
      ./writeTree/meta/owners.txt
      ./writeTree/nested
      ./writeTree/nested/dirs
      ./writeTree/nested/dirs/eval-time
    '';

  empty-dirs = checkTree "empty-dirs"
    {
      this.dir.is.empty = { };
      so.is.this.one = { };
    }
    ''
      .
      ./so
      ./so/is
      ./so/is/this
      ./so/is/this/one
      ./this
      ./this/dir
      ./this/dir/is
      ./this/dir/is/empty
    '';

  drvs = checkTree "drvs"
    {
      file-drv = writeText "road.txt" ''
        Any road followed precisely to its end leads precisely nowhere.
      '';
      dir-drv = writeTextFile {
        name = "dir-of-text";
        destination = "/text/in/more/dirs.txt";
        text = ''
          Climb the mountain just a little bit to test that it’s a mountain.
          From the top of the mountain, you cannot see the mountain.
        '';
      };
    }
    ''
      .
      ./dir-drv
      ./dir-drv/text
      ./dir-drv/text/in
      ./dir-drv/text/in/more
      ./dir-drv/text/in/more/dirs.txt
      ./file-drv
    '';
}