#!/usr/bin/env python3 """Run transactional direct-program update context checks under eval.""" from pathlib import Path import argparse import subprocess import sys import tempfile root = Path(__file__).resolve().parent.parent parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('--lib', default=str(root / 'jibb-dev/lib/jibb.hoon')) args = parser.parse_args() def body(name): text = (root / 'tests/lib' / name).read_text() return text[text.index('\n|%\n') + 1:] names = ('source', 'consumer', 'wrong-result', 'wrong-model', 'wrong-message', 'malformed-sample', 'three-slot-sample', 'non-main', 'unrelated-tag', 'missing-list') expression = ('=/ jibb .\n=/ prelude=@t prelude-text\n' '=/ internal=@t internal-text\n' + ''.join('=/ ' + name + '=wain (to-wain:format ' + name + '-text)\n' for name in names) + '=/ suite\n' + body('jibb-program-update.hoon') + '\n=/ negatives=(list @t)\n :~ (text:suite wrong-result)\n' ' (text:suite wrong-model)\n (text:suite wrong-message)\n' ' (text:suite malformed-sample)\n (text:suite three-slot-sample)\n' ' (text:suite non-main)\n (text:suite unrelated-tag)\n (text:suite missing-list)\n ==\n' '=/ failures=(list tape) (program-update-errors:suite prelude internal (text:suite source) (text:suite consumer) negatives)\n' '^- @t\n?~ failures \'program update checks passed\'\n' '(of-wain:format (turn failures crip))\n') with tempfile.TemporaryDirectory(prefix='jibb-program-update-') as tmp: program = Path(tmp) / 'program-update.hoon' program.write_text(expression) command = [str(root / 'tools/hoon'), '--lib', args.lib, '--raw', '-f', str(program), '--cord', 'prelude-text=' + str(root / 'jibb-dev/lib/jibb/prelude.jibb'), '--cord', 'internal-text=' + str(root / 'jibb-dev/lib/jibb/internal.jibb')] for name in names: command += ['--cord', name + '-text=' + str(root / 'tests/type-program-update' / (name + '.txt'))] result = subprocess.run(command, stdout=subprocess.PIPE) if result.returncode: sys.exit(result.returncode) if result.stdout != b'program update checks passed\n': sys.stderr.buffer.write(result.stdout) sys.exit(1) print('transactional direct-program update context guards passed')