haskell-te: 00f7590e62bdde5980233a6144ac94e888addffe
1: { mkBin, python, runCommand, withDeps, wrap }:
2:
3: with rec {
4: inherit (builtins) toJSON;
5:
6: filterToSampled = mkBin {
7: name = "filterToSampled";
8: paths = [ python ];
9: script = ''
10: #!${python}/bin/python
11: import json
12: import os
13: import sys
14:
15: var = os.getenv('SAMPLE')
16: if var.startswith('/'):
17: raise Exception('SAMPLE variable "{0}" looks like a path'.format(var))
18: sample = var.split('\n')
19:
20: def sampled(ast):
21: """Whether the given AST is part of our chosen sample."""
22: return ast['name'] in sample and ast['module' ] == 'A' \
23: and ast['package'] == 'tip-benchmark-sig'
24:
25: def choose(ast):
26: """Tells QuickSpec script to only include those ASTS we've sampled."""
27: ast['quickspecable'] = ast['quickspecable'] and sampled(ast)
28: return ast
29:
30: asts = json.loads(sys.stdin.read())
31: print(json.dumps(map(choose, asts)))
32: '';
33: };
34:
35: checker = mkBin {
36: name = "checker";
37: paths = [ filterToSampled python ];
38: vars = {
39: SAMPLE = ''
40: foo
41: bar
42: baz
43: quux
44: '';
45: input = toJSON [
46: {
47: name = "foo";
48: module = "B";
49: package = "tip-benchmark-sig";
50: quickspecable = true;
51: }
52: {
53: name = "quux";
54: module = "A";
55: package = "tip-benchmark-sig";
56: quickspecable = true;
57: }
58: {
59: name = "foo";
60: module = "A";
61: package = "not-benchmark-sig";
62: quickspecable = true;
63: }
64: {
65: name = "foo";
66: module = "A";
67: package = "tip-benchmark-sig";
68: quickspecable = true;
69: }
70: {
71: name = "bar";
72: module = "A";
73: package = "tip-benchmark-sig";
74: quickspecable = false;
75: }
76: ];
77: output = toJSON [
78: {
79: name = "foo";
80: module = "B";
81: package = "tip-benchmark-sig";
82: quickspecable = false;
83: }
84: {
85: name = "quux";
86: module = "A";
87: package = "tip-benchmark-sig";
88: quickspecable = true;
89: }
90: {
91: name = "foo";
92: module = "A";
93: package = "not-benchmark-sig";
94: quickspecable = false;
95: }
96: {
97: name = "foo";
98: module = "A";
99: package = "tip-benchmark-sig";
100: quickspecable = true;
101: }
102: {
103: name = "bar";
104: module = "A";
105: package = "tip-benchmark-sig";
106: quickspecable = false;
107: }
108: ];
109: };
110: script = ''
111: #!${python}/bin/python
112: from os import getenv
113: from json import loads
114: from subprocess import PIPE, Popen
115:
116: p = Popen(['filterToSampled'], stdin=PIPE, stdout=PIPE)
117: (output, _) = p.communicate(getenv('input'))
118:
119: result = None
120: try:
121: result = loads(output)
122: except:
123: raise Exception(
124: "Couldn't decode output:\n{0}\nEnd output".format(output))
125:
126: expect = loads(getenv('output'))
127: if result != expect:
128: raise Exception('Got {0}, expected {1}'.format(repr(result),
129: repr(expect)))
130:
131: print('pass')
132: '';
133: };
134:
135: check = runCommand "test-filterToSampled" { buildInputs = [ checker ]; }
136: ''checker > "$out"'';
137: };
138: withDeps [ check ] filterToSampled
Generated by git2html.