about summary refs log tree commit diff
path: root/nix/readTree/tests/default.nix
blob: 676cc9e6d988e0c4dd804b3e0ce38dcc5da5283e (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
{ depot, lib, ... }:

let
  inherit (depot.nix.runTestsuite)
    runTestsuite
    it
    assertEq
    assertThrows
    ;

  tree-ex = depot.nix.readTree {} ./test-example;

  example = it "corresponds to the README example" [
    (assertEq "third_party attrset"
      (lib.isAttrs tree-ex.third_party
      && (! lib.isDerivation tree-ex.third_party))
      true)
    (assertEq "third_party attrset other attribute"
      tree-ex.third_party.favouriteColour
      "orange")
    (assertEq "rustpkgs attrset aho-corasick"
      tree-ex.third_party.rustpkgs.aho-corasick
      "aho-corasick")
    (assertEq "rustpkgs attrset serde"
      tree-ex.third_party.rustpkgs.serde
      "serde")
    (assertEq "tools cheddear"
      "cheddar"
      tree-ex.tools.cheddar)
    (assertEq "tools roquefort"
      tree-ex.tools.roquefort
      "roquefort")
  ];

  tree-tl = depot.nix.readTree {} ./test-tree-traversal;

  traversal-logic = it "corresponds to the traversal logic in the README" [
    (assertEq "skip subtree default.nix is read"
      tree-tl.skip-subtree.but
      "the default.nix is still read")
    (assertEq "skip subtree a/default.nix is skipped"
      (tree-tl.skip-subtree ? a)
      false)
    (assertEq "skip subtree b/c.nix is skipped"
      (tree-tl.skip-subtree ? b)
      false)
    (assertEq "skip subtree a/default.nix would be read without .skip-subtree"
      (tree-tl.no-skip-subtree.a)
      "am I subtree yet?")
    (assertEq "skip subtree b/c.nix would be read without .skip-subtree"
      (tree-tl.no-skip-subtree.b.c)
      "cool")

    (assertEq "default.nix attrset is merged with siblings"
      tree-tl.default-nix.no
      "siblings should be read")
    (assertEq "default.nix means sibling isn’t read"
      (tree-tl.default-nix ? sibling)
      false)
    (assertEq "default.nix means subdirs are still read and merged into default.nix"
      (tree-tl.default-nix.subdir.a)
      "but I’m picked up")

    (assertEq "default.nix can be not an attrset"
      tree-tl.default-nix.no-merge
      "I’m not merged with any children")
    (assertEq "default.nix is not an attrset -> children are not merged"
      (tree-tl.default-nix.no-merge ? subdir)
      false)

    (assertEq "default.nix can contain a derivation"
      (lib.isDerivation tree-tl.default-nix.can-be-drv)
      true)
    (assertEq "Even if default.nix is a derivation, children are traversed and merged"
      tree-tl.default-nix.can-be-drv.subdir.a
      "Picked up through the drv")
    (assertEq "default.nix drv is not changed by readTree"
      tree-tl.default-nix.can-be-drv
      (import ./test-tree-traversal/default-nix/can-be-drv/default.nix {}))
  ];

in runTestsuite "readTree" [
  example
  traversal-logic
]