def setUp(self): self.lexer = IDLLexer() cur_dir = os.path.dirname(os.path.realpath(__file__)) self.filenames = [ os.path.join(cur_dir, 'test_lexer/values.in'), os.path.join(cur_dir, 'test_lexer/keywords.in') ]
def main(argv): nodes = [] parser = IDLParser(IDLLexer()) errors = 0 for filename in argv: filenode = ParseFile(parser, filename) errors += filenode.GetProperty('ERRORS') nodes.append(filenode) ast = IDLNode('AST', '__AST__', 0, 0, nodes) print '\n'.join(ast.Tree(accept_props=['PROD'])) if errors: print '\nFound %d errors.\n' % errors return errors
def TestErrors(filename, filenode): nodelist = filenode.GetChildren() lexer = IDLLexer() data = open(filename).read() lexer.SetData(filename, data) pass_comments = [] fail_comments = [] while True: tok = lexer.lexobj.token() if tok == None: break if tok.type == 'COMMENT': args = tok.value[3:-3].split() if args[0] == 'OK': pass_comments.append((tok.lineno, ' '.join(args[1:]))) else: if args[0] == 'FAIL': fail_comments.append((tok.lineno, ' '.join(args[1:]))) obj_list = [] for node in nodelist: obj_list.extend(FlattenTree(node)) errors = 0 # # Check for expected successes # obj_cnt = len(obj_list) pass_cnt = len(pass_comments) if obj_cnt != pass_cnt: InfoOut.Log("Mismatched pass (%d) vs. nodes built (%d)." % (pass_cnt, obj_cnt)) InfoOut.Log("PASS: %s" % [x[1] for x in pass_comments]) InfoOut.Log("OBJS: %s" % obj_list) errors += 1 if pass_cnt > obj_cnt: pass_cnt = obj_cnt for i in range(pass_cnt): line, comment = pass_comments[i] if obj_list[i] != comment: ErrOut.LogLine(filename, line, None, "OBJ %s : EXPECTED %s\n" % (obj_list[i], comment)) errors += 1 # # Check for expected errors # err_list = ErrOut.DrainLog() err_cnt = len(err_list) fail_cnt = len(fail_comments) if err_cnt != fail_cnt: InfoOut.Log("Mismatched fail (%d) vs. errors seen (%d)." % (fail_cnt, err_cnt)) InfoOut.Log("FAIL: %s" % [x[1] for x in fail_comments]) InfoOut.Log("ERRS: %s" % err_list) errors += 1 if fail_cnt > err_cnt: fail_cnt = err_cnt for i in range(fail_cnt): line, comment = fail_comments[i] err = err_list[i].strip() if err_list[i] != comment: ErrOut.Log("%s(%d) Error\n\tERROR : %s\n\tEXPECT: %s" % (filename, line, err_list[i], comment)) errors += 1 # Clear the error list for the next run err_list = [] return errors
def setUp(self): self.lexer = IDLLexer() self.filenames = [ 'test_lexer/values.in', 'test_lexer/keywords.in' ]
def setUp(self): self.parser = IDLParser(IDLLexer(), mute_error=True) self.filenames = glob.glob('test_parser/*_web.idl')
def setUp(self): self.parser = IDLParser(IDLLexer(), mute_error=True)
def setUp(self): self.parser = IDLParser(IDLLexer(), mute_error=True) test_dir = os.path.abspath( os.path.join(os.path.dirname(__file__), 'test_parser')) self.filenames = glob.glob('%s/*_web.idl' % test_dir)