r357562 - [libclang][test] Suppress annoying 'LIBCLANG TOOLING ERROR' output

Fangrui Song via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 3 00:25:04 PDT 2019


Author: maskray
Date: Wed Apr  3 00:25:04 2019
New Revision: 357562

URL: http://llvm.org/viewvc/llvm-project?rev=357562&view=rev
Log:
[libclang][test] Suppress annoying 'LIBCLANG TOOLING ERROR' output

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.

Modified:
    cfe/trunk/bindings/python/tests/cindex/test_cdb.py

Modified: cfe/trunk/bindings/python/tests/cindex/test_cdb.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/tests/cindex/test_cdb.py?rev=357562&r1=357561&r2=357562&view=diff
==============================================================================
--- cfe/trunk/bindings/python/tests/cindex/test_cdb.py (original)
+++ cfe/trunk/bindings/python/tests/cindex/test_cdb.py Wed Apr  3 00:25:04 2019
@@ -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)




More information about the cfe-commits mailing list