haskell-te: 277dc9d038979bd8f7aa97bc0235cc8e96bbee51

     1: { annotateRawAstsFrom, bash, extractedEnv, fail, haskellPkgToRawAsts, jq, lib,
     2:   makeHaskellPkgNixable, mkBin, runCommand, testData, withDeps, withNix }:
     3: 
     4: { script ? haskellPkgToRawAsts }:
     5: with lib;
     6: with rec {
     7:   haskellPkgToAsts = mkBin {
     8:     name   = "haskellPkgToAsts";
     9:     paths  = [ annotateRawAstsFrom bash fail script makeHaskellPkgNixable ];
    10:     vars   = {
    11:       usage = ''
    12:         haskellPkgToAsts extracts ASTs from the definitions made in a given
    13:         Haskell project. A Haskell project is a directory containing a file
    14:         whose name has a '.cabal' suffix.
    15: 
    16:         If the project doesn't have a default.nix file, we will try to make
    17:         one using cabal2nix; if this causes problems, consider adding your
    18:         own default.nix.
    19: 
    20:         ASTs are returned as JSON on stdout.
    21:       '';
    22:     };
    23:     script = ''
    24:       #!${bash}/bin/bash
    25:       set   -e
    26:       set   -o pipefail
    27:       shopt -s nullglob
    28: 
    29:       [[ -n "$1" ]] || fail "Need argument (see --help)"
    30: 
    31:       if [[ "x$1" = "x--help" ]]
    32:       then
    33:         echo "$usage" 1>&2
    34:         exit 0
    35:       fi
    36: 
    37:       # Get a Nix expression for this package
    38:       D=$(makeHaskellPkgNixable "$1") ||
    39:         fail "Couldn't get Nix expression for package '$1'"
    40: 
    41:       haskellPkgToRawAsts "$D" | annotateRawAstsFrom "$D"
    42:     '';
    43:   };
    44: 
    45:   check = n: p: runCommand "test-haskellPkgToAsts-example"
    46:     (withNix {
    47:       inherit p;
    48:       buildInputs = [ fail haskellPkgToAsts jq (extractedEnv {
    49:         standalone = p;
    50:       }) ];
    51:       IN_SELF_TEST = "1";
    52:       SKIP_NIX     = "1";
    53:     })
    54:     ''
    55:       set -e
    56:       ASTS=$(haskellPkgToAsts "$p" ) || fail "Command failed"
    57: 
    58:       T=$(echo "$ASTS" | jq -r 'type') || fail "Couldn't parse ASTs"
    59:       [[ "x$T" = "xarray" ]] || fail "Expected array, got '$T'"
    60: 
    61:       L=$(echo "$ASTS" | jq 'length') || fail "Couldn't get length"
    62:       [[ "$L" -gt 3 ]] || fail "Expected a few ASTs, found '$L'"
    63: 
    64:       mkdir "$out"
    65:     '';
    66: 
    67:   checks = attrValues (mapAttrs check {
    68:     inherit (testData.haskellNixed {}) test-theory;
    69:   });
    70: };
    71: 
    72: withDeps checks haskellPkgToAsts

Generated by git2html.