This is an archive of the discontinued LLVM Phabricator instance.

[libcxx] [test] Use LIBCPP_ASSERT for libc++-specific checks
ClosedPublic

Authored by jwakely on Mar 28 2022, 4:47 AM.

Details

Summary

This makes it a little easier to reuse the libc++ tests for another
std::lib (specifically libstdc++).

The regex_error::what() strings are different in other
implementations, so should be tested with LIBCPP_ASSERT so that those
checks are skipped for other implementations.

The value of ECMAScript constant is non-zero in other implementations,
and conditionally for libc++, so adjust the preprocessor condition for
that too.

Diff Detail

Event Timeline

jwakely created this revision.Mar 28 2022, 4:47 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 28 2022, 4:47 AM
jwakely requested review of this revision.Mar 28 2022, 4:47 AM
Herald added a reviewer: Restricted Project. · View Herald TranscriptMar 28 2022, 4:47 AM
jwakely added inline comments.Mar 28 2022, 4:49 AM
libcxx/test/std/re/re.const/re.synopt/syntax_option_type.pass.cpp
41

An alternative to this would be for me to define _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO in test/support/test_macros.h when libstdc++ is detected.

It seems slightly more correct to check this, rather than have non-libc++ implementations define a macro about the libc++ ABI variant, but I'll do it whichever way you like.

jwakely edited the summary of this revision. (Show Details)Mar 28 2022, 4:50 AM
philnik requested changes to this revision.Mar 28 2022, 7:12 AM
philnik added a subscriber: philnik.
philnik added inline comments.
libcxx/test/std/re/re.badexp/regex_error.pass.cpp
116–119

You can use LIBCPP_ASSERT for all of these instead.

libcxx/test/std/re/re.const/re.synopt/syntax_option_type.pass.cpp
41–46

If this isn't portable this should be a LIBCPP_ASSERT IMO.

This revision now requires changes to proceed.Mar 28 2022, 7:12 AM
jwakely added inline comments.Mar 28 2022, 7:37 AM
libcxx/test/std/re/re.badexp/regex_error.pass.cpp
116–119

Ah yes, that would be better.

libcxx/test/std/re/re.const/re.synopt/syntax_option_type.pass.cpp
41–46

How would that work? The standard guarantees that it's non-zero, and libstdc++ implements that. Libc++ makes it zero by default, or non-zero with a non-default ABI setting. So it's portable that the constant exists, but whether it's non-zero is not portable even among different builds of libc++.

jwakely updated this revision to Diff 418588.Mar 28 2022, 7:46 AM
jwakely retitled this revision from [libcxx] [test] Guard libc++-specific checks with _LIBCPP_VERSION to [libcxx] [test] Use LIBCPP_ASSERT for libc++-specific checks.
jwakely edited the summary of this revision. (Show Details)

Update to use LIBCPP_ASSERT as suggested by @philnik

ldionne accepted this revision.Mar 28 2022, 11:18 AM

LGTM with a suggestion. Thanks for catching those Jonathan!

libcxx/test/std/re/re.const/re.synopt/syntax_option_type.pass.cpp
41–42

Would you mind reversing those conditions? For some reason, I find #if !defined(_LIBCPP_VERSION) || defined(_LIBCPP_ABI_REGEX_CONSTANTS_NONZERO) to be much easier to understand.

jwakely updated this revision to Diff 418694.Mar 28 2022, 1:52 PM
jwakely marked an inline comment as done and 2 inline comments as not done.

Reverse conditions in test/std/re/re.const/re.synopt/syntax_option_type.pass.cpp as requested by Louis.

jwakely marked an inline comment as done.Mar 28 2022, 1:53 PM
philnik accepted this revision.Mar 28 2022, 8:27 PM

LGTM.

libcxx/test/std/re/re.const/re.synopt/syntax_option_type.pass.cpp
41–46

Oh, sorry. I didn't realize that there is a standard behaviour and libc++ just gets it wrong.

This revision is now accepted and ready to land.Mar 28 2022, 8:27 PM
Mordante accepted this revision.Mar 29 2022, 9:49 AM
Mordante added a subscriber: Mordante.

Nice cleanup, LGTM!

@jwakely Would you like us to land this for you?

Yes please, I don't have commit access.

@jwakely Could you provide "You Name" <your.email@example.com> for attribution?

Jonathan Wakely <jwakely@redhat.com>

(Shouldn't phabricator preserve that when a Git commit containing that info is uploaded as the diff?)

Jonathan Wakely <jwakely@redhat.com>

(Shouldn't phabricator preserve that when a Git commit containing that info is uploaded as the diff?)

It normally does, but it looks like phabricator didn't store any commits in this case. Did you upload the patch through arc diff?

This revision was automatically updated to reflect the committed changes.