haskell-te: c52f56c77a573d095f119bc3d16de57fee85b21a

     1: { bash, fail, haskellPkgToAsts, jq, lib, makeHaskellPkgNixable, mkBin,
     2:   quickspecAsts, runCommand, testData, unpack, withDeps, writeScript }:
     3: 
     4: with lib;
     5: with rec {
     6:   quickspec = mkBin {
     7:     name   = "quickspec";
     8:     paths  = [ bash fail (haskellPkgToAsts {}) jq makeHaskellPkgNixable
     9:                quickspecAsts ];
    10:     script = ''
    11:       #!${bash}/bin/bash
    12:       set -e
    13:       set -o pipefail
    14: 
    15:       [[ "$#" -gt 0 ]] || fail 'quickspec: No Haskell dirs given as args'
    16: 
    17:       DIRS=()
    18:       for D in "$@"
    19:       do
    20:         D_ARG=$(readlink -f "$D")
    21:         [[ -d "$D_ARG" ]] || fail "quickspec arg '$D' isn't dir (or link)"
    22: 
    23:         DIR=$(makeHaskellPkgNixable "$D_ARG") || fail "Couldn't nixify '$D'"
    24:         DIRS+=($DIR)
    25:       done
    26: 
    27:       function getAsts {
    28:         for DIR in "''${DIRS[@]}"
    29:         do
    30:           haskellPkgToAsts "$DIR"
    31:         done | jq -s 'reduce .[] as $x ([]; . + $x)'
    32:       }
    33: 
    34:       getAsts | quickspecAsts "''${DIRS[@]}"
    35:     '';
    36:   };
    37: 
    38:   testGarbage = runCommand "check-garbage"
    39:     {
    40:       buildInputs  = [ fail quickspec ];
    41:       IN_SELF_TEST = "1";
    42:     }
    43:     ''
    44:       if echo '!"£$%^&*()' | quickspec 1> /dev/null 2> garbage.err
    45:       then
    46:         cat garbage.err 1>&2
    47:         fail "Shouldn't have accepted garbage"
    48:       fi
    49:       echo "pass" > "$out"
    50:     '';
    51: 
    52:   testMultiple = runCommand "quickcheck-multiple"
    53:     {
    54:       plus  = testData.commands.haskellPkg {
    55:         name = "plus";
    56:         tip  = writeScript "plus.smt2" ''
    57:           (declare-datatypes () ((Nat (Z) (S (p Nat)))))
    58: 
    59:           (define-fun succ ((n Nat)) Nat
    60:             (as (S n) Nat))
    61: 
    62:           (define-fun-rec plus ((x Nat) (y Nat)) Nat
    63:              (match x
    64:                (case  Z      y)
    65:                (case (S x2) (S (plus x2 y)))))
    66: 
    67:           (check-sat)
    68:         '';
    69:       };
    70:       loop = testData.commands.haskellPkg {
    71:         name = "loop";
    72:         tip  = writeScript "loop.smt2" ''
    73:           (declare-datatypes () ((Nat (Z) (S (p Nat)))))
    74: 
    75:           (define-fun-rec
    76:             (par (a)
    77:               (loop ((f (=> a a)) (x a) (n Nat)) a
    78:                 (match n
    79:                   (case  Z     x)
    80:                   (case (S m) (loop f (@ f x) m))))))
    81: 
    82:           (check-sat)
    83:         '';
    84:       };
    85:       buildInputs  = [ fail jq quickspec ];
    86:       IN_SELF_TEST = "1";
    87:       CHECK = ''
    88:         . as $in | [paths(type == "object" and has("symbol"))]          |
    89:                    map(. as $p | $in | getpath($p) | .symbol | . == $f) |
    90:                    any
    91:       '';
    92:     }
    93:     ''
    94:       set -e
    95: 
    96:       echo "Patching loop pkg to avoid conflicting with plus pkg" 1>&2
    97:       cp -r "$loop" ./loop
    98:       chmod +w -R   ./loop
    99: 
   100:       mv  ./loop/src/A.hs                  ./loop/src/Loop.hs
   101:       sed -e 's/module A/module Loop/g' -i ./loop/src/Loop.hs
   102: 
   103: 
   104:       mv ./loop/tip-benchmark-sig.cabal                        ./loop/loop.cabal
   105:       sed -e 's/tip-benchmark-sig/loop-pkg/g'               -i ./loop/loop.cabal
   106:       sed -e 's/exposed-modules:.*/exposed-modules: Loop/g' -i ./loop/loop.cabal
   107: 
   108:       echo "Exploring..." 1>&2
   109:       EQS=$(quickspec "$plus" ./loop)
   110: 
   111:       echo "Checking expression" 1>&2
   112:       echo "$EQS" | jq -e --arg f "shouldNotExist" "$CHECK | not"
   113: 
   114:       for F in plus loop
   115:       do
   116:         echo "Checking for equations with $F" 1>&2
   117:         echo "$EQS" | jq -e --arg f "$F" "$CHECK"
   118:       done
   119:       mkdir "$out"
   120:     '';
   121: 
   122:   checks = [ testGarbage testMultiple ] ++ attrValues testHsPkgs;
   123: 
   124:   testHsPkgs =
   125:     mapAttrs (n: eqs: runCommand "test-quickspec-${n}"
   126:                         {
   127:                           inherit eqs;
   128:                           buildInputs = [ fail jq ];
   129:                         }
   130:                         ''
   131:                           set -e
   132:                           RESULTS=$(jq 'length' < "$eqs") ||
   133:                             fail "Couldn't get equation array"
   134: 
   135:                           [[ "$RESULTS" -gt 0 ]] ||
   136:                             fail "Found no equations $eqs"
   137:                           mkdir "$out"
   138:                         '')
   139:              (testData.finalEqs { script = quickspec; });
   140: };
   141: 
   142: withDeps checks quickspec

Generated by git2html.