def test_compile(path): dir = os.path.dirname(path) text = open(path).read() maybe_xfail(text) base = os.path.splitext(path)[0] c = Compiler() try: c.parse(os.path.basename(path), text) c.compile() for ast in c.root.files: astname = os.path.splitext(ast.filename)[0] + ".astc" astpath = os.path.join(dir, astname) assert_file(astpath, ast.pprint()) except (CompileError, ParseError), e: expected = base + ".err" computed = str(e) assert_file(expected, computed)
def test_emit(path, Backend): text = open(path).read() maybe_xfail(text) base = os.path.splitext(path)[0] comp = Compiler() comp.parse(os.path.basename(path), text) comp.compile() backend = Backend() comp.emit(backend) extbase = os.path.join(base, backend.ext) if not os.path.exists(extbase): os.makedirs(extbase) srcs = [] assertions = [] for name in backend.files: path = os.path.join(extbase, name) srcs.append(path) computed = backend.files[name] expected = check_file(path, computed) assertions.append((expected, computed)) for expected, computed in assertions: assert expected == computed assert len(backend.files) == len(walk(extbase, ".%s" % backend.ext)) BUILDERS[backend.ext](comp, extbase, srcs)
def main(args): if args["--version"]: sys.stderr.write("Adaptive %s\n" % _metadata.__version__) return compiler = Compiler() compiler.annotator("value", generate.value) if args["client"]: compiler.annotator("service", generate.service_client) elif args["server"]: compiler.annotator("service", generate.service_server) else: assert False java = args["--java"] python = args["--python"] if java: compiler.emitter(Java, java) if python: compiler.emitter(Python, python) try: for name in args["<file>"]: with open(name, "rb") as fd: compiler.parse(name, fd.read()) compiler.compile() except IOError, e: return e