def test_load_compdb_path_file_exists(capsys): compdb_path = os.path.join(data_dir, 'compile_commands2.json') expected_compdb = [{ 'file': 'bar.cpp', 'directory': 'data', 'arguments': ['g++', 'bar.cpp', '-o', 'bar.o'] }] assert load_json_compdb(compdb_path) == expected_compdb assert ('Loaded compilation database with 1 entries from ' + compdb_path in capsys.readouterr().out)
def test_load_no_compdb_path_default_file_exists(capsys): try: orig_pwd = os.getcwd() os.chdir(data_dir) expected_compdb = [{ 'file': 'foo.cpp', 'directory': 'data', 'arguments': ['g++', 'foo.cpp', '-o', 'foo.o'] }] assert load_json_compdb() == expected_compdb assert ( 'Loaded compilation database with 1 entries from compile_commands.json' in capsys.readouterr().out) finally: os.chdir(orig_pwd)
def test_load_compdb_path_file_exists(caplog): try: orig_pwd = os.getcwd() os.chdir(data_dir) expected_compdb = [{ 'file': 'foo.cpp', 'directory': 'data', 'arguments': ['g++', 'foo.cpp', '-o', 'foo.o'] }] with input_file('compile_commands.json') as outfile: assert load_json_compdb(outfile) == expected_compdb assert ( 'Loaded compilation database with 1 entries from compile_commands.json' in caplog.text) finally: os.chdir(orig_pwd)
def test_load_compdb_ignores_stdout_filename(caplog): assert load_json_compdb(sys.stdout) == [] assert caplog.text == ''
def test_load_compdb_path_verbose_file_not_exist(capsys): compdb_path = os.path.join(data_dir, 'nonexistent.json') assert load_json_compdb('nonexistent.json', True) == [] assert 'Failed to read previous nonexistent.json' in capsys.readouterr( ).out
def test_load_no_compdb_path_verbose_default_file_not_exist(capsys): assert load_json_compdb(verbose=True) == [] assert 'Failed to read previous compile_commands.json' in capsys.readouterr( ).out
def test_load_no_compdb_path_default_file_not_exist(capsys): assert load_json_compdb() == [] assert capsys.readouterr().out == ''