def compile(self): if self.opts.get('type', 'test') == 'show': return [0, '\n'.join(runac.show(self.fn, None)) + '\n', bytes()] try: runac.compile(self.fn, self.bin) return [0, bytes(), bytes()] except util.Error as e: return [0, bytes(), e.show()] except util.ParseError as e: return [0, bytes(), e.show()]
def run(self, key): fullname = os.path.join(TEST_DIR, key + '.rns') base = fullname.rsplit('.rns', 1)[0] bin = base + '.test' spec = getspec(fullname) type = spec.get('type', 'test') if type == 'show': out = '\n'.join(runac.show(fullname, None)) + '\n' else: out = compile(fullname, bin) if out and sys.version_info[0] > 2: out = out.encode('utf-8') if not out: cmd = [bin] + spec.get('args', []) opts = {'stdout': subprocess.PIPE, 'stderr': subprocess.PIPE} proc = subprocess.Popen(cmd, **opts) res = [proc.wait(), proc.stdout.read(), proc.stderr.read()] proc.stdout.close() proc.stderr.close() elif type == 'show': res = [0, out, bytes()] else: res = [0, bytes(), out] expected = [spec.get('ret', 0), bytes(), bytes()] for i, ext in enumerate(('.out', '.err')): if os.path.exists(base + ext): with open(base + ext, 'rb') as f: expected[i + 1] = f.read() if self is None: return res == expected elif res[1]: self.assertEqual(expected[0], res[0]) self.assertEqual(expected[1], res[1]) self.assertEqual(expected[2], res[2]) elif res[2]: self.assertEqual(expected[2], res[2]) self.assertEqual(expected[1], res[1]) self.assertEqual(expected[0], res[0])
def show(fn, opts): '''Print syntax tree after processing the pass specified by --last''' for cfg in runac.show(fn, opts.last): print(cfg)