def parse_error(): """Test that two structs with the same name raises an error.""" code = 'struct a {int c;}; \nstruct b { int d; \nstruct a {int d;}; };' ast = cparser.parse(code, 'test') with contexts.raises(cparser.ParseError) as error: cparser.find_structs(ast) assert str(error).startswith('Two structs with same name a')
def cli_no_file(cli): """Test that providing no header or config prints usage message.""" with contexts.capture_output() as (out, err): with contexts.raises(SystemExit) as error: headers, configs = csjark.parse_args(['-v', '-d']) assert str(error) == '2' assert out[0].startswith('usage:')
def cli_file_dont_existing(cli): """Test if a file is missing""" config = os.path.join(os.path.dirname(__file__), 'sprint2.yml') with contexts.capture_output() as (out, err): with contexts.raises(SystemExit) as error: headers, configs = csjark.parse_args(['404.h', config]) assert str(error) == '2' assert out[0].startswith('Unknown file(s): 404.h')
def req_1f(): """Test requirement FR1-F: Detect same name structs.""" cparser.StructVisitor.all_protocols = {} code = 'struct a {int c;};\nstruct b { int d;\nstruct a {int d;}; };' ast = cparser.parse(code, 'test') with contexts.raises(cparser.ParseError) as error: cparser.find_structs(ast) assert str(error).startswith('Two structs with same name a') cparser.StructVisitor.all_protocols = {}