1{ lib, runCommandLocal, recurseIntoAttrs, installShellFiles }:
2
3let
4 runTest = name: env: buildCommand:
5 runCommandLocal "install-shell-files--${name}" ({
6 nativeBuildInputs = [ installShellFiles ];
7 meta.platforms = lib.platforms.all;
8 } // env) buildCommand;
9in
10
11recurseIntoAttrs {
12 # installManPage
13
14 install-manpage = runTest "install-manpage" {} ''
15 mkdir -p doc
16 echo foo > doc/foo.1
17 echo bar > doc/bar.2.gz
18 echo baz > doc/baz.3
19
20 installManPage doc/*
21
22 cmp doc/foo.1 $out/share/man/man1/foo.1
23 cmp doc/bar.2.gz $out/share/man/man2/bar.2.gz
24 cmp doc/baz.3 $out/share/man/man3/baz.3
25 '';
26 install-manpage-outputs = runTest "install-manpage-outputs" {
27 outputs = [ "out" "man" "devman" ];
28 } ''
29 mkdir -p doc
30 echo foo > doc/foo.1
31 echo bar > doc/bar.3
32
33 installManPage doc/*
34
35 # assert they didn't go into $out
36 [[ ! -f $out/share/man/man1/foo.1 && ! -f $out/share/man/man3/bar.3 ]]
37
38 # foo.1 alone went into man
39 cmp doc/foo.1 ''${!outputMan:?}/share/man/man1/foo.1
40 [[ ! -f ''${!outputMan:?}/share/man/man3/bar.3 ]]
41
42 # bar.3 alone went into devman
43 cmp doc/bar.3 ''${!outputDevman:?}/share/man/man3/bar.3
44 [[ ! -f ''${!outputDevman:?}/share/man/man1/foo.1 ]]
45
46 touch $out
47 '';
48
49 # installShellCompletion
50
51 install-completion = runTest "install-completion" {} ''
52 echo foo > foo
53 echo bar > bar
54 echo baz > baz
55 echo qux > qux.zsh
56 echo quux > quux
57
58 installShellCompletion --bash foo bar --zsh baz qux.zsh --fish quux
59
60 cmp foo $out/share/bash-completion/completions/foo
61 cmp bar $out/share/bash-completion/completions/bar
62 cmp baz $out/share/zsh/site-functions/_baz
63 cmp qux.zsh $out/share/zsh/site-functions/_qux
64 cmp quux $out/share/fish/vendor_completions.d/quux
65 '';
66 install-completion-output = runTest "install-completion-output" {
67 outputs = [ "out" "bin" ];
68 } ''
69 echo foo > foo
70
71 installShellCompletion --bash foo
72
73 # assert it didn't go into $out
74 [[ ! -f $out/share/bash-completion/completions/foo ]]
75
76 cmp foo ''${!outputBin:?}/share/bash-completion/completions/foo
77
78 touch $out
79 '';
80 install-completion-name = runTest "install-completion-name" {} ''
81 echo foo > foo
82 echo bar > bar
83 echo baz > baz
84
85 installShellCompletion --bash --name foobar.bash foo --zsh --name _foobar bar --fish baz
86
87 cmp foo $out/share/bash-completion/completions/foobar.bash
88 cmp bar $out/share/zsh/site-functions/_foobar
89 cmp baz $out/share/fish/vendor_completions.d/baz
90 '';
91 install-completion-inference = runTest "install-completion-inference" {} ''
92 echo foo > foo.bash
93 echo bar > bar.zsh
94 echo baz > baz.fish
95
96 installShellCompletion foo.bash bar.zsh baz.fish
97
98 cmp foo.bash $out/share/bash-completion/completions/foo.bash
99 cmp bar.zsh $out/share/zsh/site-functions/_bar
100 cmp baz.fish $out/share/fish/vendor_completions.d/baz.fish
101 '';
102 install-completion-cmd = runTest "install-completion-cmd" {} ''
103 echo foo > foo.bash
104 echo bar > bar.zsh
105 echo baz > baz.fish
106 echo qux > qux.fish
107
108 installShellCompletion --cmd foobar --bash foo.bash --zsh bar.zsh --fish baz.fish --name qux qux.fish
109
110 cmp foo.bash $out/share/bash-completion/completions/foobar.bash
111 cmp bar.zsh $out/share/zsh/site-functions/_foobar
112 cmp baz.fish $out/share/fish/vendor_completions.d/foobar.fish
113 cmp qux.fish $out/share/fish/vendor_completions.d/qux
114 '';
115 install-completion-fifo = runTest "install-completion-fifo" {} ''
116 installShellCompletion \
117 --bash --name foo.bash <(echo foo) \
118 --zsh --name _foo <(echo bar) \
119 --fish --name foo.fish <(echo baz)
120
121 [[ $(<$out/share/bash-completion/completions/foo.bash) == foo ]] || { echo "foo.bash comparison failed"; exit 1; }
122 [[ $(<$out/share/zsh/site-functions/_foo) == bar ]] || { echo "_foo comparison failed"; exit 1; }
123 [[ $(<$out/share/fish/vendor_completions.d/foo.fish) == baz ]] || { echo "foo.fish comparison failed"; exit 1; }
124 '';
125}