summary refs log tree commit diff
path: root/pkgs/tools/misc/shunit2/default.nix
blob: 1120c756895b3d0ad4822544be2d481290eff7c8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
{ lib
, resholve
, fetchFromGitHub
, bash
, coreutils
, gnused
, gnugrep
, findutils
, ncurses
}:

resholve.mkDerivation rec {
  pname = "shunit2";
  version = "2.1.8";

  src = fetchFromGitHub {
    owner = "kward";
    repo = pname;
    rev = "v${version}";
    hash = "sha256-IZHkgkVqzeh+eEKCDJ87sqNhSA+DU6kBCNDdQaUEeiM=";
  };

  installPhase = ''
    mkdir -p $out/bin/
    cp ./shunit2 $out/bin/shunit2
    chmod +x $out/bin/shunit2
  '';

  doInstallCheck = true;
  installCheckPhase = ''
    $out/bin/shunit2
  '';

  solutions = {
    shunit = {
      # Caution: see __SHUNIT_CMD_ECHO_ESC before changing
      interpreter = "${bash}/bin/sh";
      scripts = [ "bin/shunit2" ];
      inputs = [ coreutils gnused gnugrep findutils ncurses ];
      # resholve's Nix API is analogous to the CLI flags
      # documented in 'man resholve'
      fake = {
        # "missing" functions shunit2 expects the user to declare
        function = [
          "oneTimeSetUp"
          "oneTimeTearDown"
          "setUp"
          "tearDown"
          "suite"
          "noexec"
        ];
        # shunit2 is both bash and zsh compatible, and in
        # some zsh-specific code it uses this non-bash builtin
        builtin = [ "setopt" ];
      };
      fix = {
        # stray absolute path; make it resolve from coreutils
        "/usr/bin/od" = true;
        /*
        Caution: this one is contextually debatable. shunit2
        sets this variable after testing whether `echo -e test`
        yields `test` or `-e test`. Since we're setting the
        interpreter, we can pre-test this. But if we go fiddle
        the interpreter later, I guess we _could_ break it.
        */
        "$__SHUNIT_CMD_ECHO_ESC" = [ "echo -e" ];
        "$SHUNIT_CMD_TPUT" = [ "tput" ]; # from ncurses
      };
      keep = {
        # dynamically defined in shunit2:_shunit_mktempFunc
        eval = [ "shunit_condition_" "_shunit_test_" "_shunit_prepForSourcing" ];

        # dynamic based on CLI flag
        "$_SHUNIT_LINENO_" = true;
      };
      execer = [
        # drop after https://github.com/abathur/binlore/issues/2
        "cannot:${ncurses}/bin/tput"
      ];
    };
  };

  meta = with lib; {
    homepage = "https://github.com/kward/shunit2";
    description = "An xUnit based unit test framework for Bourne based shell scripts";
    maintainers = with maintainers; [ abathur utdemir ];
    license = licenses.asl20;
    platforms = platforms.unix;
  };
}