1{
2 lib,
3 resholve,
4 fetchFromGitHub,
5 bash,
6 coreutils,
7 gnused,
8 gnugrep,
9 findutils,
10 ncurses,
11}:
12
13resholve.mkDerivation rec {
14 pname = "shunit2";
15 version = "2.1.8";
16
17 src = fetchFromGitHub {
18 owner = "kward";
19 repo = "shunit2";
20 rev = "v${version}";
21 hash = "sha256-IZHkgkVqzeh+eEKCDJ87sqNhSA+DU6kBCNDdQaUEeiM=";
22 };
23
24 installPhase = ''
25 mkdir -p $out/bin/
26 cp ./shunit2 $out/bin/shunit2
27 chmod +x $out/bin/shunit2
28 '';
29
30 doInstallCheck = true;
31 installCheckPhase = ''
32 $out/bin/shunit2
33 '';
34
35 solutions = {
36 shunit = {
37 # Caution: see __SHUNIT_CMD_ECHO_ESC before changing
38 interpreter = "${bash}/bin/sh";
39 scripts = [ "bin/shunit2" ];
40 inputs = [
41 coreutils
42 gnused
43 gnugrep
44 findutils
45 ncurses
46 ];
47 # resholve's Nix API is analogous to the CLI flags
48 # documented in 'man resholve'
49 fake = {
50 # "missing" functions shunit2 expects the user to declare
51 function = [
52 "oneTimeSetUp"
53 "oneTimeTearDown"
54 "setUp"
55 "tearDown"
56 "suite"
57 "noexec"
58 ];
59 # shunit2 is both bash and zsh compatible, and in
60 # some zsh-specific code it uses this non-bash builtin
61 builtin = [ "setopt" ];
62 };
63 fix = {
64 # stray absolute path; make it resolve from coreutils
65 "/usr/bin/od" = true;
66 /*
67 Caution: this one is contextually debatable. shunit2
68 sets this variable after testing whether `echo -e test`
69 yields `test` or `-e test`. Since we're setting the
70 interpreter, we can pre-test this. But if we go fiddle
71 the interpreter later, I guess we _could_ break it.
72 */
73 "$__SHUNIT_CMD_ECHO_ESC" = [ "echo -e" ];
74 "$SHUNIT_CMD_TPUT" = [ "tput" ]; # from ncurses
75 };
76 keep = {
77 # dynamically defined in shunit2:_shunit_mktempFunc
78 eval = [
79 "shunit_condition_"
80 "_shunit_test_"
81 "_shunit_prepForSourcing"
82 ];
83
84 # dynamic based on CLI flag
85 "$_SHUNIT_LINENO_" = true;
86 };
87 execer = [
88 # drop after https://github.com/abathur/binlore/issues/2
89 "cannot:${ncurses}/bin/tput"
90 ];
91 };
92 };
93
94 meta = with lib; {
95 homepage = "https://github.com/kward/shunit2";
96 description = "XUnit based unit test framework for Bourne based shell scripts";
97 maintainers = with maintainers; [
98 abathur
99 utdemir
100 ];
101 license = licenses.asl20;
102 platforms = platforms.unix;
103 mainProgram = "shunit2";
104 };
105}