]> granicus.if.org Git - clang/commitdiff
[libclang][test] Suppress annoying 'LIBCLANG TOOLING ERROR' output
authorFangrui Song <maskray@google.com>
Wed, 3 Apr 2019 07:25:04 +0000 (07:25 +0000)
committerFangrui Song <maskray@google.com>
Wed, 3 Apr 2019 07:25:04 +0000 (07:25 +0000)
check-all invokes check-clang-python which prints the annoying message:

LIBCLANG TOOLING ERROR: fixed-compilation-database: Error while opening fixed database: No such file or directory
json-compilation-database: Error while opening JSON database: No such file or directory

Let's fix it now with os.dup os.dup2 trick.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@357562 91177308-0d34-0410-b5e6-96231b3b80d8

bindings/python/tests/cindex/test_cdb.py

index 589fc72856bd5d5f67d70f6ea5ccc3314be8b3f2..e2a48f14cdeb9be238c72764a632a01fc2215dd8 100644 (file)
@@ -23,8 +23,17 @@ class TestCDB(unittest.TestCase):
     def test_create_fail(self):
         """Check we fail loading a database with an assertion"""
         path = os.path.dirname(__file__)
+
+        # 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:
             cdb = CompilationDatabase.fromDirectory(path)
+        os.dup2(stderr, 2)
+        os.close(stderr)
+
         e = cm.exception
         self.assertEqual(e.cdb_error,
             CompilationDatabaseError.ERROR_CANNOTLOADDATABASE)