on master help sign in
jibb/tools/type-module-scope-test
39 lines 2.1 kB history raw
1#!/usr/bin/env python3
2"""Compare the module/prelude scope report under urbit eval."""
4from pathlib import Path
5import difflib
6import subprocess
7import sys
8import tempfile
10root = Path(__file__).resolve().parent.parent
11fixture = root / 'tests/type-module-scope/expected.txt'
12tests = (root / 'tests/lib/jibb-module-scope.hoon').read_text()
13tests = tests[tests.index('\n|%\n') + 1:]
14expression = ('=/ jibb .\n=/ expected=wain (to-wain:format expected-text)\n'
15 '=/ real-prelude=@t prelude-text\n=/ real-source=@t source-text\n'
16 '=/ real-left=@t left-text\n=/ real-right=@t right-text\n'
17 '=/ real-expected=wain (to-wain:format types-text)\n'
18 '=/ suite\n' + tests + '\nscope-output:suite\n')
19with tempfile.TemporaryDirectory(prefix='jibb-module-scope-') as tmp:
20 program = Path(tmp) / 'scope.hoon'
21 program.write_text(expression)
22 result = subprocess.run([str(root / 'tools/hoon'), '--raw', '-f', str(program),
23 '--cord', 'expected-text=' + str(fixture),
24 '--cord', 'prelude-text=' + str(root / 'jibb-dev/lib/jibb/prelude.jibb'),
25 '--cord', 'source-text=' + str(root / 'tests/golden/types-prelude-interface/source.jibb'),
26 '--cord', 'left-text=' + str(root / 'tests/golden/types-prelude-interface/modules/ui/left.jibb'),
27 '--cord', 'right-text=' + str(root / 'tests/golden/types-prelude-interface/modules/ui/right.jibb'),
28 '--cord', 'types-text=' + str(root / 'tests/golden/types-prelude-interface/types.txt')],
29 stdout=subprocess.PIPE)
30if result.returncode:
31 sys.exit(result.returncode)
32expected = fixture.read_bytes()
33if result.stdout != expected:
34 sys.stderr.writelines(difflib.unified_diff(
35 expected.decode().splitlines(keepends=True),
36 result.stdout.decode().splitlines(keepends=True),
37 fromfile='expected.txt', tofile='actual types'))
38 sys.exit(1)
39print('module/prelude scope golden passed')