-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[NFC][libc++][test] Refactor new ftm generator tests. #134490
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This uses the python unit test framework instead of just asserts. This improves the diagnostics when a test fails.
@llvm/pr-subscribers-libcxx Author: Mark de Wever (mordante) ChangesThis uses the python unit test framework instead of just asserts. This improves the diagnostics when a test fails. Full diff: https://github.com/llvm/llvm-project/pull/134490.diff 6 Files Affected:
diff --git a/libcxx/test/libcxx/feature_test_macro/ftm_metadata.sh.py b/libcxx/test/libcxx/feature_test_macro/ftm_metadata.sh.py
index 4f23773f9a0a5..52696d8bc3605 100644
--- a/libcxx/test/libcxx/feature_test_macro/ftm_metadata.sh.py
+++ b/libcxx/test/libcxx/feature_test_macro/ftm_metadata.sh.py
@@ -9,39 +9,48 @@
# RUN: %{python} %s %{libcxx-dir}/utils %{libcxx-dir}/test/libcxx/feature_test_macro/test_data.json
import sys
+import unittest
-sys.path.append(sys.argv[1])
+UTILS = sys.argv[1]
+TEST_DATA = sys.argv[2]
+del sys.argv[1:3]
+
+sys.path.append(UTILS)
from generate_feature_test_macro_components import FeatureTestMacros, Metadata
-def test(output, expected):
- assert output == expected, f"expected\n{expected}\n\noutput\n{output}"
-
-
-ftm = FeatureTestMacros(sys.argv[2])
-
-test(
- ftm.ftm_metadata,
- {
- "__cpp_lib_any": Metadata(
- headers=["any"], test_suite_guard=None, libcxx_guard=None
- ),
- "__cpp_lib_barrier": Metadata(
- headers=["barrier"],
- test_suite_guard="!defined(_LIBCPP_VERSION) || (_LIBCPP_HAS_THREADS && _LIBCPP_AVAILABILITY_HAS_SYNC)",
- libcxx_guard="_LIBCPP_HAS_THREADS && _LIBCPP_AVAILABILITY_HAS_SYNC",
- ),
- "__cpp_lib_format": Metadata(
- headers=["format"], test_suite_guard=None, libcxx_guard=None
- ),
- "__cpp_lib_parallel_algorithm": Metadata(
- headers=["algorithm", "numeric"], test_suite_guard=None, libcxx_guard=None
- ),
- "__cpp_lib_variant": Metadata(
- headers=["variant"], test_suite_guard=None, libcxx_guard=None
- ),
- "__cpp_lib_missing_FTM_in_older_standard": Metadata(
- headers=[], test_suite_guard=None, libcxx_guard=None
- ),
- },
-)
+class Test(unittest.TestCase):
+ def setUp(self):
+ self.ftm = FeatureTestMacros(TEST_DATA)
+ self.maxDiff = None # This causes the diff to be printed when the test fails
+
+ def test_implementation(self):
+ expected = {
+ "__cpp_lib_any": Metadata(
+ headers=["any"], test_suite_guard=None, libcxx_guard=None
+ ),
+ "__cpp_lib_barrier": Metadata(
+ headers=["barrier"],
+ test_suite_guard="!defined(_LIBCPP_VERSION) || (_LIBCPP_HAS_THREADS && _LIBCPP_AVAILABILITY_HAS_SYNC)",
+ libcxx_guard="_LIBCPP_HAS_THREADS && _LIBCPP_AVAILABILITY_HAS_SYNC",
+ ),
+ "__cpp_lib_format": Metadata(
+ headers=["format"], test_suite_guard=None, libcxx_guard=None
+ ),
+ "__cpp_lib_parallel_algorithm": Metadata(
+ headers=["algorithm", "numeric"],
+ test_suite_guard=None,
+ libcxx_guard=None,
+ ),
+ "__cpp_lib_variant": Metadata(
+ headers=["variant"], test_suite_guard=None, libcxx_guard=None
+ ),
+ "__cpp_lib_missing_FTM_in_older_standard": Metadata(
+ headers=[], test_suite_guard=None, libcxx_guard=None
+ ),
+ }
+ self.assertEqual(self.ftm.ftm_metadata, expected)
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/libcxx/test/libcxx/feature_test_macro/implemented_ftms.sh.py b/libcxx/test/libcxx/feature_test_macro/implemented_ftms.sh.py
index 942cd4b608760..92e14757ddd49 100644
--- a/libcxx/test/libcxx/feature_test_macro/implemented_ftms.sh.py
+++ b/libcxx/test/libcxx/feature_test_macro/implemented_ftms.sh.py
@@ -9,51 +9,61 @@
# RUN: %{python} %s %{libcxx-dir}/utils %{libcxx-dir}/test/libcxx/feature_test_macro/test_data.json
import sys
+import unittest
-sys.path.append(sys.argv[1])
+UTILS = sys.argv[1]
+TEST_DATA = sys.argv[2]
+del sys.argv[1:3]
+
+sys.path.append(UTILS)
from generate_feature_test_macro_components import FeatureTestMacros
-def test(output, expected):
- assert output == expected, f"expected\n{expected}\n\noutput\n{output}"
-
-
-ftm = FeatureTestMacros(sys.argv[2])
-test(
- ftm.implemented_ftms,
- {
- "__cpp_lib_any": {
- "c++17": "201606L",
- "c++20": "201606L",
- "c++23": "201606L",
- "c++26": "201606L",
- },
- "__cpp_lib_barrier": {
- "c++20": "201907L",
- "c++23": "201907L",
- "c++26": "299900L",
- },
- "__cpp_lib_format": {
- "c++20": None,
- "c++23": None,
- "c++26": None,
- },
- "__cpp_lib_parallel_algorithm": {
- "c++17": "201603L",
- "c++20": "201603L",
- "c++23": "201603L",
- "c++26": "201603L",
- },
- "__cpp_lib_variant": {
- "c++17": "202102L",
- "c++20": "202102L",
- "c++23": "202102L",
- "c++26": "202102L",
- },
- "__cpp_lib_missing_FTM_in_older_standard": {
- "c++17": None,
- "c++20": None,
- "c++26": None,
- },
- },
-)
+class Test(unittest.TestCase):
+ def setUp(self):
+ self.ftm = FeatureTestMacros(TEST_DATA)
+ self.maxDiff = None # This causes the diff to be printed when the test fails
+
+ def test_implementation(self):
+
+ expected = {
+ "__cpp_lib_any": {
+ "c++17": "201606L",
+ "c++20": "201606L",
+ "c++23": "201606L",
+ "c++26": "201606L",
+ },
+ "__cpp_lib_barrier": {
+ "c++20": "201907L",
+ "c++23": "201907L",
+ "c++26": "299900L",
+ },
+ "__cpp_lib_format": {
+ "c++20": None,
+ "c++23": None,
+ "c++26": None,
+ },
+ "__cpp_lib_parallel_algorithm": {
+ "c++17": "201603L",
+ "c++20": "201603L",
+ "c++23": "201603L",
+ "c++26": "201603L",
+ },
+ "__cpp_lib_variant": {
+ "c++17": "202102L",
+ "c++20": "202102L",
+ "c++23": "202102L",
+ "c++26": "202102L",
+ },
+ "__cpp_lib_missing_FTM_in_older_standard": {
+ "c++17": None,
+ "c++20": None,
+ "c++26": None,
+ },
+ }
+
+ self.assertEqual(self.ftm.implemented_ftms, expected)
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/libcxx/test/libcxx/feature_test_macro/standard_ftms.sh.py b/libcxx/test/libcxx/feature_test_macro/standard_ftms.sh.py
index 95c9b9baaf2fa..ac3e284261d03 100644
--- a/libcxx/test/libcxx/feature_test_macro/standard_ftms.sh.py
+++ b/libcxx/test/libcxx/feature_test_macro/standard_ftms.sh.py
@@ -9,52 +9,61 @@
# RUN: %{python} %s %{libcxx-dir}/utils %{libcxx-dir}/test/libcxx/feature_test_macro/test_data.json
import sys
+import unittest
-sys.path.append(sys.argv[1])
+UTILS = sys.argv[1]
+TEST_DATA = sys.argv[2]
+del sys.argv[1:3]
+
+sys.path.append(UTILS)
from generate_feature_test_macro_components import FeatureTestMacros
-def test(output, expected):
- assert output == expected, f"expected\n{expected}\n\noutput\n{output}"
-
-
-ftm = FeatureTestMacros(sys.argv[2])
-test(
- ftm.standard_ftms,
- {
- "__cpp_lib_any": {
- "c++17": "201606L",
- "c++20": "201606L",
- "c++23": "201606L",
- "c++26": "201606L",
- },
- "__cpp_lib_barrier": {
- "c++20": "201907L",
- "c++23": "201907L",
- "c++26": "299900L",
- },
- "__cpp_lib_format": {
- "c++20": "202110L",
- "c++23": "202207L",
- "c++26": "202311L",
- },
- "__cpp_lib_parallel_algorithm": {
- "c++17": "201603L",
- "c++20": "201603L",
- "c++23": "201603L",
- "c++26": "201603L",
- },
- "__cpp_lib_variant": {
- "c++17": "202102L",
- "c++20": "202106L",
- "c++23": "202106L",
- "c++26": "202306L",
- },
- "__cpp_lib_missing_FTM_in_older_standard": {
- "c++17": "2017L",
- "c++20": "2020L",
- "c++23": "2020L",
- "c++26": "2026L",
- },
- },
-)
+class Test(unittest.TestCase):
+ def setUp(self):
+ self.ftm = FeatureTestMacros(TEST_DATA)
+ self.maxDiff = None # This causes the diff to be printed when the test fails
+
+ def test_implementation(self):
+ expected = {
+ "__cpp_lib_any": {
+ "c++17": "201606L",
+ "c++20": "201606L",
+ "c++23": "201606L",
+ "c++26": "201606L",
+ },
+ "__cpp_lib_barrier": {
+ "c++20": "201907L",
+ "c++23": "201907L",
+ "c++26": "299900L",
+ },
+ "__cpp_lib_format": {
+ "c++20": "202110L",
+ "c++23": "202207L",
+ "c++26": "202311L",
+ },
+ "__cpp_lib_parallel_algorithm": {
+ "c++17": "201603L",
+ "c++20": "201603L",
+ "c++23": "201603L",
+ "c++26": "201603L",
+ },
+ "__cpp_lib_variant": {
+ "c++17": "202102L",
+ "c++20": "202106L",
+ "c++23": "202106L",
+ "c++26": "202306L",
+ },
+ "__cpp_lib_missing_FTM_in_older_standard": {
+ "c++17": "2017L",
+ "c++20": "2020L",
+ "c++23": "2020L",
+ "c++26": "2026L",
+ },
+ }
+
+ self.assertEqual(self.ftm.standard_ftms, expected)
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/libcxx/test/libcxx/feature_test_macro/std_dialects.sh.py b/libcxx/test/libcxx/feature_test_macro/std_dialects.sh.py
index 368020c91e1d2..e3cca860f9ce6 100644
--- a/libcxx/test/libcxx/feature_test_macro/std_dialects.sh.py
+++ b/libcxx/test/libcxx/feature_test_macro/std_dialects.sh.py
@@ -9,22 +9,31 @@
# RUN: %{python} %s %{libcxx-dir}/utils %{libcxx-dir}/test/libcxx/feature_test_macro/test_data.json
import sys
+import unittest
-sys.path.append(sys.argv[1])
+UTILS = sys.argv[1]
+TEST_DATA = sys.argv[2]
+del sys.argv[1:3]
+
+sys.path.append(UTILS)
from generate_feature_test_macro_components import FeatureTestMacros
-def test(output, expected):
- assert output == expected, f"expected\n{expected}\n\noutput\n{output}"
+class Test(unittest.TestCase):
+ def setUp(self):
+ self.ftm = FeatureTestMacros(TEST_DATA)
+ self.maxDiff = None # This causes the diff to be printed when the test fails
+
+ def test_implementation(self):
+ expected = [
+ "c++17",
+ "c++20",
+ "c++23",
+ "c++26",
+ ]
+
+ self.assertEqual(self.ftm.std_dialects, expected)
-ftm = FeatureTestMacros(sys.argv[2])
-test(
- ftm.std_dialects,
- [
- "c++17",
- "c++20",
- "c++23",
- "c++26",
- ],
-)
+if __name__ == "__main__":
+ unittest.main()
diff --git a/libcxx/test/libcxx/feature_test_macro/version_header.sh.py b/libcxx/test/libcxx/feature_test_macro/version_header.sh.py
index 1e53d5fd92830..e3053c18a5211 100644
--- a/libcxx/test/libcxx/feature_test_macro/version_header.sh.py
+++ b/libcxx/test/libcxx/feature_test_macro/version_header.sh.py
@@ -9,19 +9,23 @@
# RUN: %{python} %s %{libcxx-dir}/utils %{libcxx-dir}/test/libcxx/feature_test_macro/test_data.json
import sys
+import unittest
-sys.path.append(sys.argv[1])
-from generate_feature_test_macro_components import FeatureTestMacros
+UTILS = sys.argv[1]
+TEST_DATA = sys.argv[2]
+del sys.argv[1:3]
+sys.path.append(UTILS)
+from generate_feature_test_macro_components import FeatureTestMacros
-def test(output, expected):
- assert output == expected, f"expected\n{expected}\n\noutput\n{output}"
+class Test(unittest.TestCase):
+ def setUp(self):
+ self.ftm = FeatureTestMacros(TEST_DATA)
+ self.maxDiff = None # This causes the diff to be printed when the test fails
-ftm = FeatureTestMacros(sys.argv[2])
-test(
- ftm.version_header,
- """// -*- C++ -*-
+ def test_implementeation(self):
+ expected = """// -*- C++ -*-
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
@@ -70,5 +74,9 @@ def test(output, expected):
#endif // _LIBCPP_STD_VER >= 26
#endif // _LIBCPP_VERSIONH
-""",
-)
+"""
+ self.assertEqual(self.ftm.version_header, expected)
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/libcxx/test/libcxx/feature_test_macro/version_header_implementation.sh.py b/libcxx/test/libcxx/feature_test_macro/version_header_implementation.sh.py
index 2771a2f7d8abf..2ab6a9be7339b 100644
--- a/libcxx/test/libcxx/feature_test_macro/version_header_implementation.sh.py
+++ b/libcxx/test/libcxx/feature_test_macro/version_header_implementation.sh.py
@@ -18,10 +18,11 @@
sys.path.append(UTILS)
from generate_feature_test_macro_components import FeatureTestMacros, VersionHeader
+
class Test(unittest.TestCase):
def setUp(self):
self.ftm = FeatureTestMacros(TEST_DATA)
- self.maxDiff = None # This causes the diff to be printed when the test fails
+ self.maxDiff = None # This causes the diff to be printed when the test fails
def test_implementation(self):
expected = {
@@ -51,11 +52,11 @@ def test_implementation(self):
),
},
{
- "__cpp_lib_missing_FTM_in_older_standard" : VersionHeader(
- value = "2017L",
- implemented = False,
- need_undef = False,
- condition = None,
+ "__cpp_lib_missing_FTM_in_older_standard": VersionHeader(
+ value="2017L",
+ implemented=False,
+ need_undef=False,
+ condition=None,
),
},
],
@@ -85,11 +86,11 @@ def test_implementation(self):
),
},
{
- "__cpp_lib_missing_FTM_in_older_standard" : VersionHeader(
- value = "2020L",
- implemented = False,
- need_undef = False,
- condition = None,
+ "__cpp_lib_missing_FTM_in_older_standard": VersionHeader(
+ value="2020L",
+ implemented=False,
+ need_undef=False,
+ condition=None,
),
},
],
@@ -129,11 +130,11 @@ def test_implementation(self):
),
},
{
- "__cpp_lib_missing_FTM_in_older_standard" : VersionHeader(
- value = "2026L",
- implemented = False,
- need_undef = False,
- condition = None,
+ "__cpp_lib_missing_FTM_in_older_standard": VersionHeader(
+ value="2026L",
+ implemented=False,
+ need_undef=False,
+ condition=None,
),
},
],
@@ -141,5 +142,6 @@ def test_implementation(self):
self.assertEqual(self.ftm.version_header_implementation, expected)
-if __name__ == '__main__':
+
+if __name__ == "__main__":
unittest.main()
|
You can test this locally with the following command:darker --check --diff -r HEAD~1...HEAD libcxx/test/libcxx/feature_test_macro/ftm_metadata.sh.py libcxx/test/libcxx/feature_test_macro/implemented_ftms.sh.py libcxx/test/libcxx/feature_test_macro/standard_ftms.sh.py libcxx/test/libcxx/feature_test_macro/std_dialects.sh.py libcxx/test/libcxx/feature_test_macro/version_header.sh.py libcxx/test/libcxx/feature_test_macro/version_header_implementation.sh.py View the diff from darker here.--- implemented_ftms.sh.py 2025-04-05 10:16:21.000000 +0000
+++ implemented_ftms.sh.py 2025-04-05 10:20:45.412225 +0000
@@ -23,11 +23,10 @@
def setUp(self):
self.ftm = FeatureTestMacros(TEST_DATA)
self.maxDiff = None # This causes the diff to be printed when the test fails
def test_implementation(self):
-
expected = {
"__cpp_lib_any": {
"c++17": "201606L",
"c++20": "201606L",
"c++23": "201606L",
|
ldionne
approved these changes
Apr 8, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This uses the python unit test framework instead of just asserts. This improves the diagnostics when a test fails.