haskell-te: 5bdbbf8d50affe0065f79155e81f422f681002d3
1: { bash, dumpToNixScripts, fail, haskellPkgNameVersion, inNixedDir, jq, lib,
2: makeHaskellPkgNixable, mkBin, nix, nixEnv, runCommand, testData, withDeps }:
3:
4: with builtins;
5: with lib;
6: with rec {
7: impureGetAsts = mkBin {
8: name = "impureGetAsts";
9: paths = [ dumpToNixScripts.main nix ];
10: vars = { EXPR = toString ./dumpEnv.nix; };
11: script = ''
12: #!${bash}/bin/bash
13: set -e
14:
15: nix-shell --show-trace -p "import $EXPR" \
16: --run "dumpToNix '$OUT_DIR'" > ./rawAsts.json
17: '';
18: };
19:
20: haskellPkgToRawAsts = mkBin {
21: name = "haskellPkgToRawAsts";
22: paths = [
23: fail haskellPkgNameVersion impureGetAsts inNixedDir jq
24: makeHaskellPkgNixable
25: ];
26: script = ''
27: #!${bash}/bin/bash
28: set -e
29:
30: [[ -n "$1" ]] || fail "haskellPkgToRawAsts needs an arg"
31: [[ -e "$1" ]] || fail "haskellPkgToRawAsts arg '$1' doesn't exist"
32:
33: # Get name and version from .cabal file
34: nameVersion=$(haskellPkgNameVersion "$1")
35: export nameVersion
36:
37: pName=$(echo "$nameVersion" | jq -r '.package')
38: export pName
39:
40: OUT_DIR=$(makeHaskellPkgNixable "$1")
41: export OUT_DIR
42:
43: D=$(inNixedDir impureGetAsts "getRawAstsFrom")
44: [[ -f "$D/rawAsts.json" ]] || fail "Couldn't find raw ASTs"
45:
46: cat "$D/rawAsts.json"
47: '';
48: };
49:
50: testExamplePkg = n: asts: runCommand "testRawAstsOf-${n}"
51: (nixEnv // {
52: inherit asts;
53: buildInputs = [ fail jq ];
54: })
55: ''
56: set -o pipefail
57: T=$(jq 'type' < "$asts") || fail "Couldn't get type of: $asts"
58: [[ "x$T" = 'x"array"' ]] || fail "Got '$T' instead of array"
59:
60: L=$(jq 'length' < "$asts") || fail "Couldn't get length"
61: [[ "$L" -gt 3 ]] || fail "Length '$L', expected a few"
62:
63: mkdir "$out"
64: '';
65:
66: checks = mapAttrs testExamplePkg
67: (testData.asts { script = haskellPkgToRawAsts; });
68: };
69:
70: withDeps (attrValues checks) haskellPkgToRawAsts
Generated by git2html.