From 768f5ec301d26bbf052b001df5b6b73bf8d6aa11 Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Sat, 30 Jan 2021 07:03:20 +0100 Subject: feat(nix/readTree): add tests of the README example First step to slowly giving readTree some coverage, so we can do refactoring without breaking functionality. Change-Id: If25a8c0fa9c4ac7472c0473372f10a9326cccaf7 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2465 Reviewed-by: tazjin Tested-by: BuildkiteCI --- nix/readTree/tests/.skip-subtree | 1 + nix/readTree/tests/default.nix | 37 ++++++++++++++++++++++ .../tests/test-example/third_party/default.nix | 5 +++ .../third_party/rustpkgs/aho-corasick.nix | 1 + .../test-example/third_party/rustpkgs/serde.nix | 1 + .../tests/test-example/tools/cheddar/default.nix | 1 + .../tests/test-example/tools/roquefort.nix | 1 + 7 files changed, 47 insertions(+) create mode 100644 nix/readTree/tests/.skip-subtree create mode 100644 nix/readTree/tests/default.nix create mode 100644 nix/readTree/tests/test-example/third_party/default.nix create mode 100644 nix/readTree/tests/test-example/third_party/rustpkgs/aho-corasick.nix create mode 100644 nix/readTree/tests/test-example/third_party/rustpkgs/serde.nix create mode 100644 nix/readTree/tests/test-example/tools/cheddar/default.nix create mode 100644 nix/readTree/tests/test-example/tools/roquefort.nix diff --git a/nix/readTree/tests/.skip-subtree b/nix/readTree/tests/.skip-subtree new file mode 100644 index 000000000000..46952a4ca635 --- /dev/null +++ b/nix/readTree/tests/.skip-subtree @@ -0,0 +1 @@ +These tests call their own readTree, so the toplevel one shouldn’t bother diff --git a/nix/readTree/tests/default.nix b/nix/readTree/tests/default.nix new file mode 100644 index 000000000000..e591dc9fe94d --- /dev/null +++ b/nix/readTree/tests/default.nix @@ -0,0 +1,37 @@ +{ depot, lib, ... }: + +let + inherit (depot.nix.runTestsuite) + runTestsuite + it + assertEq + assertThrows + ; + + tree-ex = depot.nix.readTree {} ./test-example; + + example = it "corresponds to the 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") + ]; + +in runTestsuite "readTree" [ + example +] diff --git a/nix/readTree/tests/test-example/third_party/default.nix b/nix/readTree/tests/test-example/third_party/default.nix new file mode 100644 index 000000000000..27d87242189d --- /dev/null +++ b/nix/readTree/tests/test-example/third_party/default.nix @@ -0,0 +1,5 @@ +{ ... }: + +{ + favouriteColour = "orange"; +} diff --git a/nix/readTree/tests/test-example/third_party/rustpkgs/aho-corasick.nix b/nix/readTree/tests/test-example/third_party/rustpkgs/aho-corasick.nix new file mode 100644 index 000000000000..f964fa583c43 --- /dev/null +++ b/nix/readTree/tests/test-example/third_party/rustpkgs/aho-corasick.nix @@ -0,0 +1 @@ +{ ... }: "aho-corasick" diff --git a/nix/readTree/tests/test-example/third_party/rustpkgs/serde.nix b/nix/readTree/tests/test-example/third_party/rustpkgs/serde.nix new file mode 100644 index 000000000000..54b3c0503f12 --- /dev/null +++ b/nix/readTree/tests/test-example/third_party/rustpkgs/serde.nix @@ -0,0 +1 @@ +{ ... }: "serde" diff --git a/nix/readTree/tests/test-example/tools/cheddar/default.nix b/nix/readTree/tests/test-example/tools/cheddar/default.nix new file mode 100644 index 000000000000..a1919442d86d --- /dev/null +++ b/nix/readTree/tests/test-example/tools/cheddar/default.nix @@ -0,0 +1 @@ +{ ... }: "cheddar" diff --git a/nix/readTree/tests/test-example/tools/roquefort.nix b/nix/readTree/tests/test-example/tools/roquefort.nix new file mode 100644 index 000000000000..03c7492bb6b1 --- /dev/null +++ b/nix/readTree/tests/test-example/tools/roquefort.nix @@ -0,0 +1 @@ +{ ... }: "roquefort" -- cgit 1.4.1