Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions clang/bindings/python/tests/cindex/test_cdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@ def test_create_fail(self):

# clang_CompilationDatabase_fromDirectory calls fprintf(stderr, ...)
# Suppress its output.
stderr = os.dup(2)
with open(os.devnull, "wb") as null:
os.dup2(null.fileno(), 2)
with self.assertRaises(CompilationDatabaseError) as cm:
CompilationDatabase.fromDirectory(path)
os.dup2(stderr, 2)
os.close(stderr)
try:
stderr = os.dup(2)
with open(os.devnull, "wb") as null:
os.dup2(null.fileno(), 2)
with self.assertRaises(CompilationDatabaseError) as cm:
CompilationDatabase.fromDirectory(path)
# Ensures that stderr is reset even if the above code crashes
finally:
os.dup2(stderr, 2)
os.close(stderr)

e = cm.exception
self.assertEqual(e.cdb_error, CompilationDatabaseError.ERROR_CANNOTLOADDATABASE)
Expand Down
Loading