Skip to content

Commit 3f2ee2c

Browse files
committed
test: adds tests for shell hook generation
1 parent ee410c5 commit 3f2ee2c

File tree

6 files changed

+48
-8
lines changed

6 files changed

+48
-8
lines changed

flake.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
version = "2.1.0"; # x-release-please-version
2626

2727
engines = import ./engines { inherit pkgs lib; };
28-
lib = (import ./lib { inherit pkgs lib; });
28+
lib = (import ./lib { inherit pkgs lib engines; });
2929
plugins = import ./plugins { inherit pkgs lib engines; };
3030

3131
# Setup pkgs
@@ -66,7 +66,7 @@
6666
inherit engines lib plugins;
6767

6868
# Add local tests
69-
checks = import ./tests { inherit pkgs runTests; };
69+
checks = import ./tests { inherit pkgs lib engines runTests; };
7070

7171
# Configure local development shell
7272
devShells = {

lib/default.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
{ pkgs, lib }:
1+
{ pkgs, lib, engines }:
22
{
3-
inherit (import ../modules/default.nix { inherit pkgs lib; }) mkRequest;
3+
inherit (import ../modules/default.nix { inherit pkgs lib engines; }) mkRequest;
44
make = import ./make.nix { inherit pkgs lib; };
55
makeAll = import ./make_all.nix { inherit pkgs lib; };
66
makeHook = import ./hooks { inherit pkgs lib; };

lib/hooks/link.nix

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ in
1212
log "${output} link updated"
1313
1414
# Relink to the new result
15-
unlink ${output} &>/dev/null
15+
if [[ -L ${output} ]]; then
16+
unlink ${output}
17+
fi
18+
1619
ln -s ${configFile} ${output}
1720
1821
# Run extra shell hook

modules/default.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
{ pkgs, lib }:
1+
{ pkgs, lib, engines }:
22
with pkgs.lib;
33
{
44
mkRequest = modules:
55
(evalModules {
66
modules = [ ./request.nix ]
77
++ modules
8-
++ [{ _module.args = { inherit (lib) engines; }; }];
8+
++ [{ _module.args = { inherit engines; }; }];
99
}).config;
1010
}

tests/default.nix

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
{ pkgs, runTests }:
1+
{ pkgs, lib, engines, runTests }:
22
with pkgs.lib;
33
let
44
tests = fold (x: y: recursiveUpdate x y) { } [
55
(import ./nix { inherit runTests; })
66
(import ./cue { inherit runTests; })
7+
({
8+
hook = import ./hook { inherit pkgs lib engines; };
9+
})
710
];
811
in
912
tests

tests/hook/default.nix

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{ pkgs, lib, engines }:
2+
let
3+
linkRequest = {
4+
format = "json";
5+
output = "test.json";
6+
configData = {
7+
field1 = "value1";
8+
field2 = 42;
9+
field3 = false;
10+
};
11+
};
12+
13+
copyRequest = linkRequest // {
14+
hook =
15+
{ mode = "copy"; extra = "touch test.txt"; };
16+
};
17+
18+
linkHook = pkgs.writeShellScript "link" (lib.make linkRequest).shellHook;
19+
copyHook = pkgs.writeShellScript "copy" (lib.make copyRequest).shellHook;
20+
in
21+
pkgs.runCommand "test.hook" { }
22+
''
23+
echo "Testing link hook"
24+
source ${linkHook}
25+
stat test.json
26+
rm test.json
27+
28+
echo "Testing copy hook"
29+
source ${copyHook}
30+
stat test.json
31+
stat test.txt
32+
33+
touch $out
34+
''

0 commit comments

Comments
 (0)