on f43d2ee help sign in
jibb/tools/type-program-watch-test
48 lines 2.5 kB history raw
1#!/usr/bin/env python3
2"""Run direct request-value watchability checks under eval."""
3from pathlib import Path
4import argparse
5import subprocess
6import sys
7import tempfile
9root = Path(__file__).resolve().parent.parent
10parser = argparse.ArgumentParser(description=__doc__)
11parser.add_argument('--lib', default=str(root / 'jibb-dev/lib/jibb.hoon'))
12args = parser.parse_args()
13fixture = root / 'tests/type-api-paths/api.txt'
14actual = root / 'my-app/ui/api/todo.jibb'
15if fixture.read_bytes() != actual.read_bytes():
16 sys.exit('todo API fixture differs from my-app/ui/api/todo.jibb')
17reader = (root / 'jibb-dev/lib/jibb-import.hoon').read_text()
18tests = (root / 'tests/lib/jibb-program-watch.hoon').read_text()
19tests = tests[tests.index('\n|%\n') + 1:]
20names = ('sur', 'action', 'todos', 'update', 'item', 'api')
21program = ('=/ jibb .\n=/ jibb-import\n' + reader + '\n' +
22 ''.join('=/ ' + name + '=wain (to-wain:format ' + name + '-text)\n'
23 for name in names) +
24 '=/ suite\n' + tests +
25 '\n=/ failures=(list tape) (program-watch-errors:suite prelude internal (text:suite sur) (text:suite action) (text:suite todos) (text:suite update) (text:suite item) (text:suite api))\n'
26 '^- @t\n?~ failures \'program request-value watchability passed\'\n'
27 '(of-wain:format (turn failures crip))\n')
28fixtures = {'sur': 'tests/type-api-paths/todo-sur.txt',
29 'action': 'tests/type-api-paths/todo-action.txt',
30 'todos': 'tests/type-api-paths/todos.txt',
31 'update': 'tests/type-api-paths/todo-update.txt',
32 'item': 'tests/type-api-paths/todo-item.txt',
33 'api': 'tests/type-api-paths/api.txt'}
34with tempfile.TemporaryDirectory(prefix='jibb-program-watch-') as tmp:
35 path = Path(tmp) / 'program-watch.hoon'
36 path.write_text(program)
37 command = [str(root / 'tools/hoon'), '--lib', args.lib, '--raw', '-f', str(path),
38 '--cord', 'prelude=' + str(root / 'jibb-dev/lib/jibb/prelude.jibb'),
39 '--cord', 'internal=' + str(root / 'jibb-dev/lib/jibb/internal.jibb')]
40 for name, filename in fixtures.items():
41 command += ['--cord', name + '-text=' + str(root / filename)]
42 result = subprocess.run(command, stdout=subprocess.PIPE)
43if result.returncode:
44 sys.exit(result.returncode)
45if result.stdout != b'program request-value watchability passed\n':
46 sys.stderr.buffer.write(result.stdout)
47 sys.exit(1)
48print('direct request-value watchability and rejection guards passed')