2021-01-30 07:03:20 +01:00
|
|
|
|
{ depot, lib, ... }:
|
|
|
|
|
|
|
|
|
|
let
|
|
|
|
|
inherit (depot.nix.runTestsuite)
|
|
|
|
|
runTestsuite
|
|
|
|
|
it
|
|
|
|
|
assertEq
|
|
|
|
|
assertThrows
|
|
|
|
|
;
|
|
|
|
|
|
2021-09-08 17:16:11 +02:00
|
|
|
|
tree-ex = depot.nix.readTree {
|
|
|
|
|
path = ./test-example;
|
|
|
|
|
args = {};
|
|
|
|
|
};
|
2021-01-30 07:03:20 +01:00
|
|
|
|
|
2021-01-30 07:40:33 +01:00
|
|
|
|
example = it "corresponds to the README example" [
|
2021-01-30 07:03:20 +01:00
|
|
|
|
(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")
|
|
|
|
|
];
|
|
|
|
|
|
2021-09-08 17:16:11 +02:00
|
|
|
|
tree-tl = depot.nix.readTree {
|
|
|
|
|
path = ./test-tree-traversal;
|
|
|
|
|
args = {};
|
|
|
|
|
};
|
2021-01-30 07:40:33 +01:00
|
|
|
|
|
|
|
|
|
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 {}))
|
|
|
|
|
];
|
|
|
|
|
|
2021-01-30 09:25:05 +01:00
|
|
|
|
# these each call readTree themselves because the throws have to happen inside assertThrows
|
|
|
|
|
wrong = it "cannot read these files and will complain" [
|
|
|
|
|
(assertThrows "this file is not a function"
|
2021-09-08 17:16:11 +02:00
|
|
|
|
(depot.nix.readTree {
|
|
|
|
|
path = ./test-wrong-not-a-function;
|
|
|
|
|
args = {};
|
|
|
|
|
}).not-a-function)
|
2021-01-30 09:25:05 +01:00
|
|
|
|
# can’t test for that, assertThrows can’t catch this error
|
|
|
|
|
# (assertThrows "this file is a function but doesn’t have dots"
|
|
|
|
|
# (depot.nix.readTree {} ./test-wrong-no-dots).no-dots-in-function)
|
|
|
|
|
];
|
|
|
|
|
|
2021-09-30 14:46:12 +02:00
|
|
|
|
read-markers = depot.nix.readTree {
|
|
|
|
|
path = ./test-marker;
|
|
|
|
|
args = {};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
assertMarkerByPath = path:
|
|
|
|
|
assertEq "${lib.concatStringsSep "." path} is marked correctly"
|
|
|
|
|
(lib.getAttrFromPath path read-markers).__readTree path;
|
|
|
|
|
|
|
|
|
|
markers = it "marks nodes correctly" [
|
|
|
|
|
(assertMarkerByPath [ "directory-marked" ])
|
|
|
|
|
(assertMarkerByPath [ "directory-marked" "nested" ])
|
|
|
|
|
(assertMarkerByPath [ "file-children" "one" ])
|
|
|
|
|
(assertMarkerByPath [ "file-children" "two" ])
|
|
|
|
|
(assertEq "nix file children are marked correctly"
|
|
|
|
|
read-markers.file-children.__readTreeChildren [ "one" "two" ])
|
|
|
|
|
(assertEq "directory children are marked correctly"
|
|
|
|
|
read-markers.directory-marked.__readTreeChildren [ "nested" ])
|
|
|
|
|
(assertEq "absence of children is marked"
|
|
|
|
|
read-markers.directory-marked.nested.__readTreeChildren [ ])
|
|
|
|
|
];
|
|
|
|
|
|
2021-01-30 07:03:20 +01:00
|
|
|
|
in runTestsuite "readTree" [
|
|
|
|
|
example
|
2021-01-30 07:40:33 +01:00
|
|
|
|
traversal-logic
|
2021-01-30 09:25:05 +01:00
|
|
|
|
wrong
|
2021-09-30 14:46:12 +02:00
|
|
|
|
markers
|
2021-01-30 07:03:20 +01:00
|
|
|
|
]
|