nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{ resholve
2, lib
3, stdenv
4, fetchFromGitHub
5, bash
6, coreutils
7, gnugrep
8, ncurses
9, findutils
10, hostname
11, parallel
12, flock
13, ps
14, bats
15, lsof
16, doInstallCheck ? true
17}:
18
19resholve.mkDerivation rec {
20 pname = "bats";
21 version = "1.7.0";
22
23 src = fetchFromGitHub {
24 owner = "bats-core";
25 repo = "bats-core";
26 rev = "v${version}";
27 sha256 = "sha256-joNne/dDVCNtzdTQ64rK8GimT+DOWUa7f410hml2s8Q=";
28 };
29
30 patchPhase = ''
31 patchShebangs .
32 '';
33
34 installPhase = ''
35 ./install.sh $out
36 '';
37
38 solutions = {
39 bats = {
40 scripts = [
41 "bin/bats"
42 "libexec/bats-core/*"
43 "lib/bats-core/*"
44 ];
45 interpreter = "${bash}/bin/bash";
46 inputs = [
47 bash
48 coreutils
49 gnugrep
50 ncurses
51 findutils
52 hostname
53 parallel
54 flock
55 "lib/bats-core"
56 "libexec/bats-core"
57 ];
58 fake = {
59 external = [
60 "greadlink"
61 "shlock"
62 ];
63 };
64 fix = {
65 "$BATS_ROOT" = [ "${placeholder "out"}" ];
66 "$BATS_LIBEXEC" = [ "${placeholder "out"}/libexec/bats-core" ];
67 };
68 keep = {
69 "${placeholder "out"}/libexec/bats-core/bats" = true;
70 source = [
71 "${placeholder "out"}/lib/bats-core/validator.bash"
72 "${placeholder "out"}/lib/bats-core/preprocessing.bash"
73 "$BATS_TEST_SOURCE"
74 "${placeholder "out"}/lib/bats-core/tracing.bash"
75 "${placeholder "out"}/lib/bats-core/test_functions.bash"
76 "$library_load_path"
77 "${placeholder "out"}/lib/bats-core/common.bash"
78 "${placeholder "out"}/lib/bats-core/semaphore.bash"
79 "${placeholder "out"}/lib/bats-core/formatter.bash"
80 "${placeholder "out"}/lib/bats-core/warnings.bash"
81 "$setup_suite_file" # via cli arg
82 ];
83 "$report_formatter" = true;
84 "$formatter" = true;
85 "$pre_command" = true;
86 "$BATS_TEST_NAME" = true;
87 "${placeholder "out"}/libexec/bats-core/bats-exec-test" = true;
88 };
89 execer = [
90 /*
91 both blatant lies for expedience; these can certainly exec args
92 they may be safe here, because they may always run things that
93 are ultimately in libexec?
94 TODO: handle parallel and flock in binlore/resholve
95 */
96 "cannot:${parallel}/bin/parallel"
97 "cannot:${flock}/bin/flock"
98
99 "cannot:libexec/bats-core/bats-preprocess"
100
101 # these do exec, but other internal files
102 "cannot:libexec/bats-core/bats-exec-file"
103 "cannot:libexec/bats-core/bats-exec-suite"
104 ];
105 };
106 };
107
108 passthru.tests.upstream = bats.unresholved.overrideAttrs (old: {
109 name = "${bats.name}-tests";
110 dontInstall = true; # just need the build directory
111 installCheckInputs = [
112 ncurses
113 parallel # skips some tests if it can't detect
114 flock # skips some tests if it can't detect
115 ps
116 ] ++ lib.optionals stdenv.isDarwin [ lsof ];
117 inherit doInstallCheck;
118 installCheckPhase = ''
119 # TODO: cut if https://github.com/bats-core/bats-core/issues/418 allows
120 sed -i '/test works even if PATH is reset/a skip "disabled for nix build"' test/bats.bats
121
122 # skip tests that assume bats `install.sh` will be in BATS_ROOT
123 rm test/root.bats
124
125 # test generates file with absolute shebang dynamically
126 substituteInPlace test/install.bats --replace \
127 "/usr/bin/env bash" "${bash}/bin/bash"
128
129 ${bats}/bin/bats test
130 touch $out
131 '';
132 });
133
134 meta = with lib; {
135 homepage = "https://github.com/bats-core/bats-core";
136 description = "Bash Automated Testing System";
137 maintainers = with maintainers; [ abathur ];
138 license = licenses.mit;
139 platforms = platforms.unix;
140 };
141}