on f43d2ee help sign in
jibb/tools/type-empty-test
55 lines 2.8 kB history raw
1#!/usr/bin/env python3
2"""Check source-backed empty molds and uninhabited union cases under eval."""
3from pathlib import Path
4import argparse
5import difflib
6import subprocess
7import sys
8import tempfile
10root = Path(__file__).resolve().parent.parent
11parser = argparse.ArgumentParser(description=__doc__)
12parser.add_argument('--lib', default=str(root / 'jibb-dev/lib/jibb.hoon'))
13parser.add_argument('--update', action='store_true')
14args = parser.parse_args()
15fixture = root / 'tests/type-empty'
16source = (root / 'tests/lib/jibb-empty.hoon').read_text()
17source = source[source.index('\n|%\n') + 1:]
18names = ['good', 'overlap', 'dead', 'missing', 'standard-good', 'list-dead', 'unit-dead', 'late-cap', 'list-live', 'list-open', 'face-source']
19cords = [item for name in names for item in ('--cord', f'{name}-text={fixture / (name + ".txt")}')]
20cords += ['--cord', f'prelude={root / "jibb-dev/lib/jibb/prelude.jibb"}',
21 '--cord', f'internal={root / "jibb-dev/lib/jibb/internal.jibb"}']
22if not args.update:
23 cords += ['--cord', f'expected-text={fixture / "expected.txt"}']
24bindings = ''.join(f'=/ {name}=wain (to-wain:format {name}-text)\n' for name in names)
25program = ('=/ jibb .\n=/ real-prelude=@t prelude\n'
26 '=/ real-internal=@t internal\n' + bindings +
27 ('=/ expected=wain ~\n' if args.update else '=/ expected=wain (to-wain:format expected-text)\n') +
28 '=/ suite\n' + source +
29 '\n=/ output=@t (empty-output:suite prelude internal ' +
30 ' '.join(name + '-text' for name in names) + ')\n' +
31 ('output\n' if args.update else
32 "=/ actual-test=tang test-empty:suite\n?~ actual-test output\n'BAD ship test arm'\n"))
33with tempfile.TemporaryDirectory(prefix='jibb-empty-') as tmp:
34 path = Path(tmp) / 'test.hoon'
35 path.write_text(program)
36 result = subprocess.run([str(root / 'tools/hoon'), '--lib', args.lib, '--raw',
37 '-f', str(path), *cords], stdout=subprocess.PIPE)
38if result.returncode:
39 sys.exit(result.returncode)
40if any(line.startswith(b'BAD ') or line.endswith(b': BAD') for line in result.stdout.splitlines()):
41 sys.stderr.write('empty-mold guard assertion failed:\n')
42 sys.stderr.buffer.write(result.stdout)
43 sys.exit(1)
44expected_path = fixture / 'expected.txt'
45if args.update:
46 expected_path.write_bytes(result.stdout)
47else:
48 expected = expected_path.read_bytes()
49 if result.stdout != expected:
50 sys.stderr.writelines(difflib.unified_diff(
51 expected.decode().splitlines(keepends=True),
52 result.stdout.decode().splitlines(keepends=True),
53 fromfile='expected.txt', tofile='actual'))
54 sys.exit(1)
55print('source-backed empty-mold guards passed')