Page MenuHomePhabricator

[libc++] Add a script to automatize updating test for a new header.
ClosedPublic

Authored by curdeius on Dec 4 2020, 6:57 AM.

Details

Summary

Idea from D92525.
This script globs include/ directory and updates the tests in test/libcxx.
This patch does not generate module.modulemap nor CMakeLists.txt.

Diff Detail

Event Timeline

curdeius created this revision.Dec 4 2020, 6:57 AM
curdeius requested review of this revision.Dec 4 2020, 6:57 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 4 2020, 6:57 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript
curdeius added inline comments.Dec 4 2020, 6:58 AM
libcxx/docs/Contributing.rst
26–31

That's a drive-by fix.

ldionne requested changes to this revision.Dec 4 2020, 9:14 AM

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?

libcxx/docs/Contributing.rst
29

That doesn't seem right -- you don't need to modify <version> yourself, the script does it. Am I misunderstanding what you meant here?

38

I don't think it's necessary to keep the list of tests -- it'll only get out of date.

This revision now requires changes to proceed.Dec 4 2020, 9:14 AM

I like your approach. It will indeed make it easier to add new tests and update current ones.

libcxx/docs/Contributing.rst
29

Oh, you're right. I thought it wasn't changing that.

38

OK. Will remove.

curdeius updated this revision to Diff 310550.Dec 9 2020, 8:39 AM

Modify files between boundary markers.
I haven't modified the way TEST_MACROS() stuff is done though. I'd be inclined to rethink it if it becomes a problem and we have more tests.

ldionne accepted this revision.Dec 9 2020, 8:42 AM

Love it! Thanks for the automation!

This revision is now accepted and ready to land.Dec 9 2020, 8:42 AM
curdeius marked 2 inline comments as done.Dec 9 2020, 8:45 AM
curdeius updated this revision to Diff 310559.Dec 9 2020, 9:02 AM
  • Minor change: move clang-format comments into the generated part.
ldionne accepted this revision.Dec 9 2020, 9:08 AM