Repository navigation
[beman-tidy] Implement cmake.skip_tests #346
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
neatudarius
merged 1 commit into
bemanproject:main
from
neatudarius:implement/issue-73-cmake-skip-tests
Jul 26, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| #!/usr/bin/env python3 | ||
| # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
|
||
| import re | ||
|
|
||
| from cmake_parser.ast import Command, If | ||
|
|
||
|
|
||
| def cmake_is_subdirectory(command, subdir_name): | ||
| if getattr(command, "identifier", None) != "add_subdirectory" or not command.args: | ||
| return False | ||
| arg = command.args[0].value.strip('"') | ||
| return arg == subdir_name or arg.startswith(f"{subdir_name}/") | ||
|
|
||
|
|
||
| def cmake_has_unguarded_subdirectory(nodes, subdir_name, option_name, inside_guard=False): | ||
| for item in nodes: | ||
| if isinstance(item, Command): | ||
| if cmake_is_subdirectory(item, subdir_name) and not inside_guard: | ||
| return True | ||
| elif isinstance(item, If): | ||
| guard = bool(item.args and item.args[0].value == option_name) | ||
| if cmake_has_unguarded_subdirectory( | ||
| item.if_true or [], subdir_name, option_name, inside_guard or guard | ||
| ): | ||
| return True | ||
| if cmake_has_unguarded_subdirectory( | ||
| item.if_false or [], subdir_name, option_name, inside_guard | ||
| ): | ||
| return True | ||
| return False | ||
|
|
||
|
|
||
| def cmake_build_skip_subdir_option_pattern(option_name): | ||
| return re.compile( | ||
| r"option\s*\(\s*" | ||
| + re.escape(option_name) | ||
| + r'\s*"(?:[^"\\]|\\.)*"\s*' | ||
| + re.escape("${PROJECT_IS_TOP_LEVEL}") | ||
| + r"\s*\)", | ||
| ) |
49 changes: 49 additions & 0 deletions
49
tests/lib/checks/beman_standard/cmake/data/invalid/invalid-skip_tests-v1.txt
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
|
||
| cmake_minimum_required(VERSION 3.30...4.3) | ||
|
|
||
| project( | ||
| beman.exemplar # CMake Project Name, which is also the name of the top-level | ||
| # targets (e.g., library, executable, etc.). | ||
| DESCRIPTION "A Beman Library Exemplar" | ||
| LANGUAGES CXX | ||
| VERSION 0.1.0 | ||
| ) | ||
|
|
||
| # [CMAKE.SKIP_EXAMPLES] | ||
| option( | ||
| BEMAN_EXEMPLAR_BUILD_EXAMPLES | ||
| "Enable building examples. Default: ${PROJECT_IS_TOP_LEVEL}. Values: { ON, OFF }." | ||
| ${PROJECT_IS_TOP_LEVEL} | ||
| ) | ||
|
|
||
| # for find of beman_install_library and configure_build_telemetry | ||
| include(infra/cmake/beman-install-library.cmake) | ||
| include(infra/cmake/BuildTelemetryConfig.cmake) | ||
|
|
||
| add_library(beman.exemplar INTERFACE) | ||
| add_library(beman::exemplar ALIAS beman.exemplar) | ||
|
|
||
| target_sources( | ||
| beman.exemplar | ||
| PUBLIC FILE_SET HEADERS BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/include" | ||
| ) | ||
|
|
||
| set_target_properties( | ||
| beman.exemplar | ||
| PROPERTIES VERIFY_INTERFACE_HEADER_SETS ${PROJECT_IS_TOP_LEVEL} | ||
| ) | ||
|
|
||
| add_subdirectory(include/beman/exemplar) | ||
|
|
||
| beman_install_library(beman.exemplar TARGETS beman.exemplar) | ||
| configure_build_telemetry() | ||
|
|
||
| if(BEMAN_EXEMPLAR_BUILD_TESTS) | ||
| enable_testing() | ||
| add_subdirectory(tests/beman/exemplar) | ||
| endif() | ||
|
|
||
| if(BEMAN_EXEMPLAR_BUILD_EXAMPLES) | ||
| add_subdirectory(examples) | ||
| endif() |
56 changes: 56 additions & 0 deletions
56
tests/lib/checks/beman_standard/cmake/data/invalid/invalid-skip_tests-v2.txt
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
|
||
| cmake_minimum_required(VERSION 3.30...4.3) | ||
|
|
||
| project( | ||
| beman.exemplar # CMake Project Name, which is also the name of the top-level | ||
| # targets (e.g., library, executable, etc.). | ||
| DESCRIPTION "A Beman Library Exemplar" | ||
| LANGUAGES CXX | ||
| VERSION 0.1.0 | ||
| ) | ||
|
|
||
| # [CMAKE.SKIP_TESTS] | ||
| option( | ||
| BEMAN_EXEMPLAR_BUILD_TESTS | ||
| "Enable building tests and test infrastructure. Default: ON. Values: { ON, OFF }." | ||
| ON | ||
| ) | ||
|
|
||
| # [CMAKE.SKIP_EXAMPLES] | ||
| option( | ||
| BEMAN_EXEMPLAR_BUILD_EXAMPLES | ||
| "Enable building examples. Default: ${PROJECT_IS_TOP_LEVEL}. Values: { ON, OFF }." | ||
| ${PROJECT_IS_TOP_LEVEL} | ||
| ) | ||
|
|
||
| # for find of beman_install_library and configure_build_telemetry | ||
| include(infra/cmake/beman-install-library.cmake) | ||
| include(infra/cmake/BuildTelemetryConfig.cmake) | ||
|
|
||
| add_library(beman.exemplar INTERFACE) | ||
| add_library(beman::exemplar ALIAS beman.exemplar) | ||
|
|
||
| target_sources( | ||
| beman.exemplar | ||
| PUBLIC FILE_SET HEADERS BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/include" | ||
| ) | ||
|
|
||
| set_target_properties( | ||
| beman.exemplar | ||
| PROPERTIES VERIFY_INTERFACE_HEADER_SETS ${PROJECT_IS_TOP_LEVEL} | ||
| ) | ||
|
|
||
| add_subdirectory(include/beman/exemplar) | ||
|
|
||
| beman_install_library(beman.exemplar TARGETS beman.exemplar) | ||
| configure_build_telemetry() | ||
|
|
||
| if(BEMAN_EXEMPLAR_BUILD_TESTS) | ||
| enable_testing() | ||
| add_subdirectory(tests/beman/exemplar) | ||
| endif() | ||
|
|
||
| if(BEMAN_EXEMPLAR_BUILD_EXAMPLES) | ||
| add_subdirectory(examples) | ||
| endif() |
54 changes: 54 additions & 0 deletions
54
tests/lib/checks/beman_standard/cmake/data/invalid/invalid-skip_tests-v3.txt
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
|
||
| cmake_minimum_required(VERSION 3.30...4.3) | ||
|
|
||
| project( | ||
| beman.exemplar # CMake Project Name, which is also the name of the top-level | ||
| # targets (e.g., library, executable, etc.). | ||
| DESCRIPTION "A Beman Library Exemplar" | ||
| LANGUAGES CXX | ||
| VERSION 0.1.0 | ||
| ) | ||
|
|
||
| # [CMAKE.SKIP_TESTS] | ||
| option( | ||
| BEMAN_EXEMPLAR_BUILD_TESTS | ||
| "Enable building tests and test infrastructure. Default: ${PROJECT_IS_TOP_LEVEL}. Values: { ON, OFF }." | ||
| ${PROJECT_IS_TOP_LEVEL} | ||
| ) | ||
|
|
||
| # [CMAKE.SKIP_EXAMPLES] | ||
| option( | ||
| BEMAN_EXEMPLAR_BUILD_EXAMPLES | ||
| "Enable building examples. Default: ${PROJECT_IS_TOP_LEVEL}. Values: { ON, OFF }." | ||
| ${PROJECT_IS_TOP_LEVEL} | ||
| ) | ||
|
|
||
| # for find of beman_install_library and configure_build_telemetry | ||
| include(infra/cmake/beman-install-library.cmake) | ||
| include(infra/cmake/BuildTelemetryConfig.cmake) | ||
|
|
||
| add_library(beman.exemplar INTERFACE) | ||
| add_library(beman::exemplar ALIAS beman.exemplar) | ||
|
|
||
| target_sources( | ||
| beman.exemplar | ||
| PUBLIC FILE_SET HEADERS BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/include" | ||
| ) | ||
|
|
||
| set_target_properties( | ||
| beman.exemplar | ||
| PROPERTIES VERIFY_INTERFACE_HEADER_SETS ${PROJECT_IS_TOP_LEVEL} | ||
| ) | ||
|
|
||
| add_subdirectory(include/beman/exemplar) | ||
|
|
||
| beman_install_library(beman.exemplar TARGETS beman.exemplar) | ||
| configure_build_telemetry() | ||
|
|
||
| enable_testing() | ||
| add_subdirectory(tests/beman/exemplar) | ||
|
|
||
| if(BEMAN_EXEMPLAR_BUILD_EXAMPLES) | ||
| add_subdirectory(examples) | ||
| endif() |
26 changes: 26 additions & 0 deletions
26
tests/lib/checks/beman_standard/cmake/data/invalid/invalid-skip_tests-v4.txt
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
|
||
| cmake_minimum_required(VERSION 3.30...4.3) | ||
|
|
||
| project( | ||
| beman.exemplar | ||
| DESCRIPTION "A Beman Library Exemplar" | ||
| LANGUAGES CXX | ||
| VERSION 0.1.0 | ||
| ) | ||
|
|
||
| option( | ||
| BEMAN_EXEMPLAR_BUILD_TESTS | ||
| "Enable building tests and test infrastructure. Default: ${PROJECT_IS_TOP_LEVEL}. Values: { ON, OFF }." | ||
| ${PROJECT_IS_TOP_LEVEL} | ||
| ) | ||
|
|
||
| add_library(beman.exemplar INTERFACE) | ||
| add_library(beman::exemplar ALIAS beman.exemplar) | ||
|
|
||
| if(BEMAN_EXEMPLAR_BUILD_TESTS) | ||
| enable_testing() | ||
| add_subdirectory(tests/beman/exemplar) | ||
| endif() | ||
|
|
||
| add_subdirectory(tests/beman/exemplar) |
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.