[libcxx-commits] [PATCH] D92656: [libc++] Add a script to automatize updating test for a new header.

Louis Dionne via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Fri Dec 4 09:14:34 PST 2020


ldionne requested changes to this revision.
ldionne added a comment.
This revision now requires changes to proceed.

Another approach for generating those tests would be to instead insert just the header part between two markers. This would allow writing the new test mostly outside of the script, and only the header part would be inserted (between the markers) by the script. Something like this:

  // -*- C++ -*-
  //===----------------------------------------------------------------------===//
  //
  // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  // See https://llvm.org/LICENSE.txt for license information.
  // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  //
  //===----------------------------------------------------------------------===//
  
  // Test that we can include each header in two TU's and link them together.
  
  // RUN: %{cxx} -c %s -o %t.first.o %{flags} %{compile_flags}
  // RUN: %{cxx} -c %s -o %t.second.o -DWITH_MAIN %{flags} %{compile_flags}
  // RUN: %{cxx} -o %t.exe %t.first.o %t.second.o %{flags} %{link_flags}
  // RUN: %{run}
  
  // GCC 5 pretends it supports C++17 features, but some features like static_assert
  // without a message are not actually supported. This causes some headers to fail
  // when included.
  // UNSUPPORTED: gcc-5 && c++17
  
  // Prevent <ext/hash_map> from generating deprecated warnings for this test.
  #if defined(__DEPRECATED)
  #undef __DEPRECATED
  #endif
  
  //////////////////////////////////////////////////////////////////////////////
  // BEGIN-GENERATED-HEADERS
  //////////////////////////////////////////////////////////////////////////////
  
  // ... This content is generated ...
  
  //////////////////////////////////////////////////////////////////////////////
  // END-GENERATED-HEADERS
  //////////////////////////////////////////////////////////////////////////////
  
  #if defined(WITH_MAIN)
  int main(int, char**) { return 0; }
  #endif

The main benefit of doing that is that the script could stay simple as we add more tests, and adding a new test might be only a matter of adding the path of the test in the script.

We'd have to find a way to accommodate stuff like using `TEST_MACROS();` after each include, but one way we could do that is by always defining some macro like `TEST_POST_INCLUDES` in the test file before the generated content. It would always be empty, except when you want to include something after each header.

Do you have thoughts about this?



================
Comment at: libcxx/docs/Contributing.rst:29
+
+When adding or updating feature test macros, apart from modifying the ``include/version`` header, you should update the corresponding tests.
+To do that, modify ``feature_test_macros`` table in the script ``utils/generate_feature_test_macro_components.py``, run it, and commit updated files.
----------------
That doesn't seem right -- you don't need to modify `<version>` yourself, the script does it. Am I misunderstanding what you meant here?


================
Comment at: libcxx/docs/Contributing.rst:39
+2. Run ``python utils/generate_header_tests.py``, verify and commit the modifications.
+   The script updates the following test files to include the new header:
 
----------------
I don't think it's necessary to keep the list of tests -- it'll only get out of date.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D92656/new/

https://reviews.llvm.org/D92656



More information about the libcxx-commits mailing list