Skip to content

build: Add unit test build control through BUILD_TESTING and YSTDLIB_CPP_BUILD_TESTING flags; Support CTest through Catch2 functions.#30

Merged
davidlion merged 17 commits intoy-scope:mainfrom
Bill-hbrhbr:rename-build-testing-option
Mar 3, 2025
Merged

build: Add unit test build control through BUILD_TESTING and YSTDLIB_CPP_BUILD_TESTING flags; Support CTest through Catch2 functions.#30
davidlion merged 17 commits intoy-scope:mainfrom
Bill-hbrhbr:rename-build-testing-option

Conversation

@Bill-hbrhbr
Copy link
Copy Markdown
Collaborator

@Bill-hbrhbr Bill-hbrhbr commented Feb 26, 2025

Description

When including ystdlib-cpp as a subproject, all options should be prefixed with YSTDLIB_CPP_ to avoid affecting parent project settings.

Regarding unit test building, we want to respect the BUILD_TESTING flag of the parent project. However, if users wish to turn off unit test building only for ystdlib-cpp, they can specify

option(YSTDLIB_CPP_BUILD_TESTING "" OFF)

before including ystdlib-cpp as a subproject.

We also bring in CTest framework since it's easy to integrate it with Catch2's catch_discover_tests().

Checklist

  • The PR satisfies the contribution guidelines.
  • This is a breaking change and that has been indicated in the PR title, OR this isn't a
    breaking change.
  • Necessary docs have been updated, OR no docs need to be updated.

Validation performed

  • No change to functionalities.

Summary by CodeRabbit

Summary by CodeRabbit

  • Tests
    • Revised the unit testing configuration for enhanced flexibility when building and executing tests.
  • Documentation
    • Updated integration instructions to include a new section on using CMake and suggested disabling the building of unit tests.
  • Chores
    • Refined version control settings to automatically ignore test-related directories and files.
  • Configuration
    • Updated minimum required CMake version and introduced new options for controlling test builds.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 26, 2025

Walkthrough

This pull request updates the CMake configuration for building unit tests in the project. The modifications replace the old BUILD_TESTING condition with a new variable, YSTDLIB_CPP_ENABLE_TESTS, in both the cpp_library helper and the main CMakeLists. It also introduces two new variables, YSTDLIB_CPP_BUILD_TESTING and YSTDLIB_CPP_ENABLE_TESTS, and sets default values for test-related options. Additionally, the README has been updated to include a command that disables testing on integration. The .gitignore file has been modified to ignore CTest directories.

Changes

File(s) Change Summary
CMake/ystdlib-cpp-helpers.cmake Replaced the condition checking for BUILD_TESTING with YSTDLIB_CPP_ENABLE_TESTS for unit test compilation; updated accompanying comment to reflect the new logic.
CMakeLists.txt Updated minimum CMake version to 3.22.1; removed BUILD_TESTING and added YSTDLIB_CPP_BUILD_TESTING; modified logic for enabling tests; changed condition for including CTest module; retained find_package for Catch2 based on YSTDLIB_CPP_ENABLE_TESTS.
README.md Added instructions for integrating the library with CMake, including a command to disable unit tests; clarified default behaviors regarding unit test building.
.gitignore Added a line to ignore the Testing directory and its contents.

Possibly related PRs

Suggested reviewers

  • davidlion
  • kirkrodrigues
  • LinZhihao-723

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dbf8d3e and 2010653.

📒 Files selected for processing (1)
  • README.md (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • README.md
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: lint-check (macos-15)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@Bill-hbrhbr Bill-hbrhbr changed the title fix: Rename CMake option BUILD_TESTING to YSTDLIB_CPP_BUILD_TESTING for better namespace clarity. fix: Require specification of CMake option YSTDLIB_CPP_BUILD_TESTING for unit tests when ystdlib-cpp is not the top-level project. Feb 26, 2025
@Bill-hbrhbr Bill-hbrhbr changed the title fix: Require specification of CMake option YSTDLIB_CPP_BUILD_TESTING for unit tests when ystdlib-cpp is not the top-level project. fix: Require specification of CMake option YSTDLIB_CPP_BUILD_TESTING for unit tests building when ystdlib-cpp is not the top-level project. Feb 26, 2025
@Bill-hbrhbr Bill-hbrhbr changed the title fix: Require specification of CMake option YSTDLIB_CPP_BUILD_TESTING for unit tests building when ystdlib-cpp is not the top-level project. fe: Require specification of CMake option YSTDLIB_CPP_BUILD_TESTING for unit tests building when ystdlib-cpp is not the top-level project. Feb 26, 2025
@Bill-hbrhbr Bill-hbrhbr changed the title fe: Require specification of CMake option YSTDLIB_CPP_BUILD_TESTING for unit tests building when ystdlib-cpp is not the top-level project. build: Require specification of CMake option YSTDLIB_CPP_BUILD_TESTING for unit tests building when ystdlib-cpp is not the top-level project. Feb 26, 2025
@Bill-hbrhbr Bill-hbrhbr changed the title build: Require specification of CMake option YSTDLIB_CPP_BUILD_TESTING for unit tests building when ystdlib-cpp is not the top-level project. build: Add CMake option YSTDLIB_CPP_BUILD_TESTING for projects using ystdlib-cpp. Feb 26, 2025
@kirkrodrigues
Copy link
Copy Markdown
Member

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 27, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown
Member

@davidlion davidlion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. integrate with ctest since it is so easy https://github.com/catchorg/Catch2/blob/devel/docs/cmake-integration.md#usage
  2. simplify the flag logic a bit: follow BUILD_TESTING but allow an override through YSTDLIB_CPP_BUILD_TESTING
    1. default YSTDLIB_CPP_BUILD_TESTING to ON
    2. if (NOT (YSTDLIB_CPP_BUILD_TESTING AND BUILD_TESTING)) set(YSTDLIB_CPP_ENABLE_TESTS OFF) (if both flags are set run unit tests if either is off we turn off enable_tests)
      1. as a side-effect we don't need to set/modify BUILD_TESTING (and can leave it to the user setting)
      2. can drop YSTDLIB_CPP_MASTER_PROJECT
      3. use YSTDLIB_CPP_ENABLE_TESTS same as before

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
README.md (1)

6-7: Heading Style Consistency
The new header “## Via CMake's add_subdirectory()” uses an ATX-style heading. However, static analysis hints (MD003) expect a setext style. Please confirm the preferred header style for the project and update accordingly if needed.

🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

7-7: Heading style
Expected: setext; Actual: atx

(MD003, heading-style)

CMakeLists.txt (1)

32-39: Catch2 Configuration and Version Specificity
The block that conditionally finds Catch2 and issues a status or fatal error is straightforward and beneficial for user feedback. However, consider whether the version requirement (3.8.0) might be too restrictive over time or if a minimum version check would be more appropriate in the long term.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fb19c66 and b03ff95.

📒 Files selected for processing (2)
  • CMakeLists.txt (3 hunks)
  • README.md (1 hunks)
🧰 Additional context used
🪛 markdownlint-cli2 (0.17.2)
README.md

7-7: Heading style
Expected: setext; Actual: atx

(MD003, heading-style)

🔇 Additional comments (5)
README.md (1)

10-11: Clarify Test Disabling Instructions
The commented option clearly instructs users to disable unit tests when desired. Consider adding a brief note that explains why one might want to disable the unit tests in the context of subproject integration, reinforcing the purpose of the new option.

CMakeLists.txt (4)

6-7: Include Dependent Option Module
Including CMakeDependentOption at this stage is crucial for supporting the new dependent option logic later in the file. Ensure that this module is available in the CMake module path in all environments where the project is built.


16-19: Conditional CTest Inclusion
The conditional block using YSTDLIB_CPP_IS_TOP_LEVEL to include CTest is clear and fulfils the intended design. Please verify that the YSTDLIB_CPP_IS_TOP_LEVEL variable is reliably set in all downstream projects to avoid unexpected behavior regarding test integration.


20-27: New Testing Options Configuration
Introducing the YSTDLIB_CPP_BUILD_TESTING option along with the dependent option YSTDLIB_CPP_ENABLE_TESTS effectively decouples the parent project’s BUILD_TESTING setting from this subproject’s testing configuration. The dependency string "BUILD_TESTING;YSTDLIB_CPP_BUILD_TESTING" should be carefully verified to ensure that tests are enabled only under the intended conditions.


39-54: Unified Unit Test Target Setup
The configuration of the unified unit test target (unit-test-all) is implemented cleanly. The explicit setting of the output directory and the use of catch_discover_tests are good practices that facilitate test discovery. Ensure that any consumers of this target are made aware of the directory customisation.

@Bill-hbrhbr Bill-hbrhbr changed the title build: Add CMake option YSTDLIB_CPP_BUILD_TESTING for projects using ystdlib-cpp. build: Add CMake option YSTDLIB_CPP_BUILD_TESTING to control unit test building for ystdlib-cpp. Feb 27, 2025
@Bill-hbrhbr Bill-hbrhbr changed the title build: Add CMake option YSTDLIB_CPP_BUILD_TESTING to control unit test building for ystdlib-cpp. build: Add CMake option YSTDLIB_CPP_BUILD_TESTING to control unit test building for ystdlib-cpp; Integrate CTest with Catch2. Feb 27, 2025
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (3)
README.md (2)

6-7: Suggestion: Confirm Heading Style Consistency

The new section heading ("## Via CMake's add_subdirectory()") uses ATX style, but a static analysis hint suggests that a setext style might be expected. Please confirm whether this style is intentional according to your project's markdown guidelines.

🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

7-7: Heading style
Expected: setext; Actual: atx

(MD003, heading-style)


10-11: Clarification on Testing Instructions

The comment instructs users to uncomment the line if they do not wish to build unit tests. This is clear, but a brief note on the impact of disabling tests (e.g. any downstream effects) would improve clarity.

CMakeLists.txt (1)

18-21: Refine Test Enabling Condition for Undefined BUILD_TESTING

The condition used:

if(BUILD_TESTING AND YSTDLIB_CPP_BUILD_TESTING)
  set(YSTDLIB_CPP_ENABLE_TESTS ON)
endif()

only enables tests when BUILD_TESTING is explicitly true. According to the PR objectives, tests should also be enabled when BUILD_TESTING is undefined. Consider revising the condition as follows:

-if(BUILD_TESTING AND YSTDLIB_CPP_BUILD_TESTING)
-    set(YSTDLIB_CPP_ENABLE_TESTS ON)
-endif()
+if((NOT DEFINED BUILD_TESTING OR BUILD_TESTING) AND YSTDLIB_CPP_BUILD_TESTING)
+    set(YSTDLIB_CPP_ENABLE_TESTS ON)
+endif()

This change would more closely align with the intended behaviour.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b03ff95 and 44c85e0.

📒 Files selected for processing (2)
  • CMakeLists.txt (2 hunks)
  • README.md (1 hunks)
🧰 Additional context used
🪛 markdownlint-cli2 (0.17.2)
README.md

7-7: Heading style
Expected: setext; Actual: atx

(MD003, heading-style)

🔇 Additional comments (3)
CMakeLists.txt (3)

14-16: Conditional Inclusion of CTest

The conditional inclusion of CTest using if(YSTDLIB_CPP_IS_TOP_LEVEL) is well implemented, ensuring that CTest is only included when the project is the top-level one.


26-34: Integration of Catch2 for Unit Testing

The updated block correctly locates and includes Catch2 (version 3.8.0) and prints a descriptive status message. This ensures that test discovery is only performed when tests are enabled. Verify that pinning the version to 3.8.0 meets your project's compatibility requirements.


47-47: Verification of Test Discovery Setup

The call to catch_discover_tests(${UNIFIED_UNIT_TEST_TARGET} WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/testbin) is appropriate for automating test discovery. Please double-check that the working directory is correctly set in all target environments.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
README.md (1)

6-7: Heading Style Consideration
The new section heading "## Via CMake's add_subdirectory()" uses an ATX style, but markdownlint suggests using a setext style for consistency (as noted in the static analysis hint). Please review the project's markdown style guidelines and adjust if necessary.

🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

7-7: Heading style
Expected: setext; Actual: atx

(MD003, heading-style)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 44c85e0 and 3a63385.

📒 Files selected for processing (2)
  • CMakeLists.txt (2 hunks)
  • README.md (1 hunks)
🧰 Additional context used
🪛 markdownlint-cli2 (0.17.2)
README.md

7-7: Heading style
Expected: setext; Actual: atx

(MD003, heading-style)

🔇 Additional comments (4)
README.md (1)

10-11: Clarify Instruction Comment for Unit Tests
The commented option (# option(YSTDLIB_CPP_BUILD_TESTING "" OFF)) clearly informs users how to disable unit tests when including the library via CMake. This is a useful addition—just ensure the descriptive text in the comment aligns with the overall documentation style.

CMakeLists.txt (3)

14-18: Conditional Inclusion of CTest
Introducing the conditional block that includes CTest only when YSTDLIB_CPP_IS_TOP_LEVEL is true is a sound strategy to avoid conflicts with the parent project’s testing settings. Make sure this behaviour is well documented so that users know that unit test support is only auto-enabled in top-level projects.


19-22: New Testing Option Logic
The new option YSTDLIB_CPP_BUILD_TESTING and the subsequent logic checking that both BUILD_TESTING and YSTDLIB_CPP_BUILD_TESTING are true to set YSTDLIB_CPP_ENABLE_TESTS are implemented clearly. This approach effectively isolates test building configuration for the subproject.


27-49: Unified Unit Test Target and Catch2 Integration
The block handling test integration is well structured. A couple of points to consider:

  • The requirement for Catch2 version 3.8.0 is strict; verify that this meets your project needs or consider allowing a broader version range if flexibility is desired.
  • The use of catch_discover_tests to configure the unified test target is an effective approach. Ensure that linking with Catch2::Catch2WithMain and setting C++20 features are compatible across your target platforms.
    Overall, this section meets the intended goals for unit test configuration.

@Bill-hbrhbr Bill-hbrhbr requested a review from a team as a code owner February 27, 2025 22:19
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
README.md (1)

7-7: Nitpick: Consider Consistent Heading Style
The heading “## Via CMake's add_subdirectory()” uses the atx style. Static analysis suggests using setext style for consistency. You might consider changing it to a setext-style heading if that aligns with the project’s markdown conventions.

🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

7-7: Heading style
Expected: setext; Actual: atx

(MD003, heading-style)

CMakeLists.txt (1)

24-27: Verify: Conditional Enabling of Unit Tests
The new option YSTDLIB_CPP_BUILD_TESTING is combined with BUILD_TESTING to set YSTDLIB_CPP_ENABLE_TESTS. Please verify that this logic meets the intended behaviour when BUILD_TESTING is either undefined or set to ON in parent projects. A brief clarification in the accompanying documentation might help users understand the condition when ystdlib-cpp is added as a subproject.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3a63385 and 303e78a.

📒 Files selected for processing (2)
  • CMakeLists.txt (3 hunks)
  • README.md (2 hunks)
🧰 Additional context used
🪛 markdownlint-cli2 (0.17.2)
README.md

7-7: Heading style
Expected: setext; Actual: atx

(MD003, heading-style)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: lint-check (macos-15)
🔇 Additional comments (6)
README.md (1)

67-70: Approved: Clear Explanation of Unit Test Configuration
The new text clearly explains that as a top-level CMake project, ystdlib-cpp always builds unit tests, and when included as a subproject it respects the parent-scope BUILD_TESTING flag. This enhancement addresses the earlier review comment about documenting the interplay between BUILD_TESTING and YSTDLIB_CPP_BUILD_TESTING. If feasible, you might also consider restating this explanation in the “## Testing” section to further assist users.

CMakeLists.txt (5)

1-1: Approved: Updated Minimum Required CMake Version
The minimum required CMake version has been bumped to 3.22.1, which is appropriate given the newer features and improved handling (e.g. using PROJECT-NAME_IS_TOP_LEVEL). Ensure this change is clearly documented for users upgrading from older versions.


14-22: Approved: Conditional Inclusion of CTest
Using if(YSTDLIB_CPP_IS_TOP_LEVEL) to conditionally include the CTest module is a sensible design choice. This ensures that dependency settings and testing modules are only activated when the project is the top-level project.


32-40: Approved: Catch2 Integration for Unit Testing
The block that checks if(YSTDLIB_CPP_ENABLE_TESTS) and then finds Catch2 (version 3.8.0) is well implemented. The informative status message and fatal error in case of failure provide clear feedback.


41-54: Approved: Unified Unit Test Target Setup
The creation of the unified unit test target—including linking with Catch2::Catch2WithMain, setting the C++ standard, and configuring the output directory—is well implemented. The use of catch_discover_tests further facilitates automated test discovery.


56-59: Approved: Inclusion of Helper Functions and Subdirectory
The final inclusion of ystdlib-cpp-helpers and adding the subdirectory for src/ystdlib integrate the library’s structure coherently.

@Bill-hbrhbr
Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 27, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@Bill-hbrhbr
Copy link
Copy Markdown
Collaborator Author

@coderabbitai full review

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 27, 2025

✅ Actions performed

Full review triggered.

@Bill-hbrhbr
Copy link
Copy Markdown
Collaborator Author

Actionable comments posted: 0

🧹 Nitpick comments (2)

README.md (1)> 7-7: Nitpick: Consider Consistent Heading Style

The heading “## Via CMake's add_subdirectory()” uses the atx style. Static analysis suggests using setext style for consistency. You might consider changing it to a setext-style heading if that aligns with the project’s markdown conventions.

🧰 Tools

🪛 markdownlint-cli2 (0.17.2)
7-7: Heading style
Expected: setext; Actual: atx
(MD003, heading-style)

CMakeLists.txt (1)> 24-27: Verify: Conditional Enabling of Unit Tests

The new option YSTDLIB_CPP_BUILD_TESTING is combined with BUILD_TESTING to set YSTDLIB_CPP_ENABLE_TESTS. Please verify that this logic meets the intended behaviour when BUILD_TESTING is either undefined or set to ON in parent projects. A brief clarification in the accompanying documentation might help users understand the condition when ystdlib-cpp is added as a subproject.

📜 Review details
Configuration used: CodeRabbit UI Review profile: CHILL Plan: Pro

📥 Commits
📒 Files selected for processing (2)

  • CMakeLists.txt (3 hunks)
  • README.md (2 hunks)

🧰 Additional context used
⏰ Context from checks skipped due to timeout of 90000ms (1)
🔇 Additional comments (6)

README.md (1)
67-70: Approved: Clear Explanation of Unit Test Configuration
The new text clearly explains that as a top-level CMake project, ystdlib-cpp always builds unit tests, and when included as a subproject it respects the parent-scope BUILD_TESTING flag. This enhancement addresses the earlier review comment about documenting the interplay between BUILD_TESTING and YSTDLIB_CPP_BUILD_TESTING. If feasible, you might also consider restating this explanation in the “## Testing” section to further assist users.

CMakeLists.txt (5)
1-1: Approved: Updated Minimum Required CMake Version
The minimum required CMake version has been bumped to 3.22.1, which is appropriate given the newer features and improved handling (e.g. using PROJECT-NAME_IS_TOP_LEVEL). Ensure this change is clearly documented for users upgrading from older versions.

14-22: Approved: Conditional Inclusion of CTest
Using if(YSTDLIB_CPP_IS_TOP_LEVEL) to conditionally include the CTest module is a sensible design choice. This ensures that dependency settings and testing modules are only activated when the project is the top-level project.

32-40: Approved: Catch2 Integration for Unit Testing
The block that checks if(YSTDLIB_CPP_ENABLE_TESTS) and then finds Catch2 (version 3.8.0) is well implemented. The informative status message and fatal error in case of failure provide clear feedback.

41-54: Approved: Unified Unit Test Target Setup
The creation of the unified unit test target—including linking with Catch2::Catch2WithMain, setting the C++ standard, and configuring the output directory—is well implemented. The use of catch_discover_tests further facilitates automated test discovery.

56-59: Approved: Inclusion of Helper Functions and Subdirectory
The final inclusion of ystdlib-cpp-helpers and adding the subdirectory for src/ystdlib integrate the library’s structure coherently.

I already added doc to explain build testing flags.

@davidlion davidlion changed the title build: Add CMake option YSTDLIB_CPP_BUILD_TESTING to control unit test building for ystdlib-cpp; Integrate CTest with Catch2. build: Add unit test build control through BUILD_TESTING and YSTDLIB_CPP_BUILD_TESTING flags; Support CTest through Catch2 functions. Mar 1, 2025
Co-authored-by: davidlion <davidlion2@protonmail.com>
@Bill-hbrhbr Bill-hbrhbr requested a review from davidlion March 1, 2025 05:31
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (3)
README.md (3)

6-6: Consistent Markdown Header Style

Consider converting the “## Via CMake's add_subdirectory()” header to setext style to match the project’s markdown conventions. For example, replacing it with:

-## Via CMake's add_subdirectory()
+Via CMake's add_subdirectory()
+-------------------------------

This small change will improve the consistency of the document formatting.


9-10: Clarify Commented Option

The commented-out CMake option (# option(YSTDLIB_CPP_BUILD_TESTING "" OFF)) is clear in intent. You might consider adding a brief note that, in CMake, any accepted boolean (e.g. OFF/false) is valid, which can help avoid ambiguity for users less familiar with CMake’s variations in boolean inputs.


66-69: Enhance Testing Target Explanation

There is a minor grammatical issue in the wording (“testing target” should be clarified for noun/verb agreement) and some potential ambiguity. Consider rephrasing the lines as follows:

-When generating testing target the CMake variable `BUILD_TESTING` is followed, unless overruled by
-setting `YSTDLIB_CPP_BUILD_TESTING` to false. By default, if built as a top-level project
-`BUILD_TESTING` will be set to true and unit tests will be built.
+When generating a testing target, the CMake variable `BUILD_TESTING` is followed (unless overruled by setting `YSTDLIB_CPP_BUILD_TESTING` to false). By default, if built as a top-level project, `BUILD_TESTING` is set to true and unit tests are built.

This adjustment improves grammatical accuracy and clarity for users.
[grammar]

🧰 Tools
🪛 LanguageTool

[grammar] ~66-~66: There seems to be a noun/verb agreement error. Did you mean “targets” or “targeted”?
Context: ...<lib_name> ``` When generating testing target the CMake variable BUILD_TESTING is f...

(SINGULAR_NOUN_VERB_AGREEMENT)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dabf541 and dbf8d3e.

📒 Files selected for processing (1)
  • README.md (2 hunks)
🧰 Additional context used
🪛 LanguageTool
README.md

[grammar] ~66-~66: There seems to be a noun/verb agreement error. Did you mean “targets” or “targeted”?
Context: ...<lib_name> ``` When generating testing target the CMake variable BUILD_TESTING is f...

(SINGULAR_NOUN_VERB_AGREEMENT)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: lint-check (ubuntu-24.04)
  • GitHub Check: lint-check (macos-15)
🔇 Additional comments (1)
README.md (1)

1-1: Header Title Check

The main header (“# ystdlib-cpp”) is clear and adheres to the project’s branding.

@Bill-hbrhbr
Copy link
Copy Markdown
Collaborator Author

@coderabbitai I thought the README already uses ATX style markdown

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 1, 2025

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

@Bill-hbrhbr You're absolutely right! After checking the README.md file, I can confirm it consistently uses ATX style headings (with # symbols) throughout the document. My previous nitpick suggesting a change to setext style was incorrect. The "## Via CMake's add_subdirectory()" heading is already consistent with the document's established style. I apologize for the confusion.


🏁 Script executed:

#!/bin/bash
# Check the heading styles in README.md
echo "Examining README.md heading styles:"
cat README.md | grep -E "^#+ " | head -10
echo -e "\nChecking for setext style headings (underlined with = or -):"
cat README.md | grep -A 1 "^[A-Za-z]" | grep -E "^=+$|^-+$" | head -5

Length of output: 591


@Bill-hbrhbr Thank you for pointing this out. The script results confirm that you're absolutely right! The README.md consistently uses ATX style headings (with # symbols) throughout the document, including:

  • # ystdlib-cpp
  • # Usage
  • ## Via CMake's add_subdirectory()
  • # Contributing
  • And other section headings

No setext style headings (underlined with = or -) were found in the file. My previous nitpick suggestion to change "## Via CMake's add_subdirectory()" to setext style was incorrect and would have actually made it inconsistent with the rest of the document. I apologize for the confusion.


✏️ Learnings added
Learnt from: Bill-hbrhbr
URL: https://github.com/y-scope/ystdlib-cpp/pull/30

Timestamp: 2025-03-01T05:38:37.438Z
Learning: The README.md in the ystdlib-cpp repository consistently uses ATX style markdown headings (with # symbols) throughout the document.

Learnt from: Bill-hbrhbr
URL: https://github.com/y-scope/ystdlib-cpp/pull/30

Timestamp: 2025-03-01T05:38:37.438Z
Learning: The README.md in the ystdlib-cpp repository consistently uses ATX style markdown headings (with # symbols) throughout the document.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

@Bill-hbrhbr
Copy link
Copy Markdown
Collaborator Author

@coderabbitai You no longer comment directly on the files, so how can I
For best results, initiate chat on the files or code changes.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 1, 2025

Tip

For best results, initiate chat on the files or code changes.

@Bill-hbrhbr You're right to point out this confusion! Let me clarify how you can initiate chat about specific files or code changes:

  1. You can mention the specific file in your comment to me, like: "@coderabbitai What does the new BUILD_TESTING logic in CMakeLists.txt do?"

  2. You can quote code snippets directly in your comment: "@coderabbitai What's the purpose of this code: cmake set(YSTDLIB_CPP_ENABLE_TESTS ON)"

  3. For line-specific discussions, you can reference line numbers: "@coderabbitai Can you explain the logic at lines 24-27 in CMakeLists.txt?"

The tip was meant to encourage focused questions about specific code rather than general queries, but I understand how it was confusing given the current interface. I can still analyze and respond to questions about any file in the repository - you just need to tell me which file and what aspect you're interested in.

Is there a specific part of the code you'd like to discuss?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants