-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.nix
More file actions
49 lines (49 loc) · 2.03 KB
/
tests.nix
File metadata and controls
49 lines (49 loc) · 2.03 KB
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
pkgs: l_pkg_enum: let
mkBuildTest = lua: let
luapath = (lua.withPackages (ps: with ps; [ inspect shelua ])).interpreter;
in pkgs.runCommand ("shelua_package_test-" + lua.luaAttr) {} ''
echo 'package.path = package.path .. ";${./.}/?.lua"; require("test")' | ${luapath} - > "$out"
'';
mkCmdTest = lua:
pkgs.runLuaCommand ("runLuaCommand_test-" + lua.luaAttr) (lua.withPackages (ps: with ps; [ inspect ])).interpreter {
nativeBuildInputs = [ pkgs.makeWrapper ];
passthru.info = {
testdata = [ "some" "values" ];
notincluded = system: builtins.trace system system;
};
} /*lua*/
''
local inspect = require('inspect')
local outbin = out .. "/bin"
local outfile = outbin .. "/testpkg"
local outdrv = outbin .. "/testdrv"
local outcat = outbin .. "/newcat"
local outecho = outbin .. "/newecho"
sh.mkdir("-p", outbin)
os.env.FRIEND = "everyone"
assert(os.getenv("FRIEND") == os.env.FRIEND, "os.env failed")
print(os.getenv("FRIEND"))
os.write_file({}, outfile, [[#!${pkgs.bash}/bin/bash]])
os.write_file({ append = true, }, outfile, [[echo "hello world!"]])
os.write_file({ append = true, }, outfile, [[cat ]] .. outdrv)
os.write_file({ append = true, }, outfile, outcat)
os.write_file({}, outdrv, inspect(drv))
sh.escape_args = true
sh.makeWrapper([[${pkgs.writeShellScript "testscript" ''echo "$@"''}]], outecho, "--add-flags", "testingtesting '1 2' 3")
sh.escape_args = false
sh.makeWrapper([[${pkgs.coreutils}/bin/cat]], outcat, "--add-flags", outecho)
sh.chmod("+x", outfile)
package.path = package.path .. ";${./.}/?.lua"
require("example")
require("test")
'';
run_on = map (n: pkgs.${n}) l_pkg_enum;
in pkgs.lib.pipe run_on [
(map (li: { name = "runLuaCommand-" + li.luaAttr; value = mkCmdTest li; }))
builtins.listToAttrs
] // (
pkgs.lib.pipe run_on [
(map (li: { name = "withPackages-" + li.luaAttr; value = mkBuildTest li; }))
builtins.listToAttrs
]
)