Skip to content
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

Expand Readme File #24

Merged
merged 4 commits into from
May 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 61 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,66 @@
# Assertion.cmake

A [CMake](https://cmake.org/) module that contains a collection of assertion functions for testing purposes.
A [CMake](https://cmake.org/) module containing a collection of assertion functions for testing purposes.

## Key Features

- Contains a collection of assertion functions for testing purposes.
- Supports mocking and asserting the `message` function.

## Integration

This module can be integrated into a CMake project in the following ways:

- Manually download the [`Assertion.cmake`](./cmake/Assertion.cmake) file and include it in the CMake project:
```cmake
include(path/to/Assertion.cmake)
```
- Use [`file(DOWNLOAD)`](https://cmake.org/cmake/help/latest/command/file.html#download) to automatically download the `Assertion.cmake` file:
```cmake
file(
DOWNLOAD https://threeal.github.io/assertion-cmake/v0.1.0
${CMAKE_BINARY_DIR}/Assertion.cmake
)
include(${CMAKE_BINARY_DIR}/Assertion.cmake)
```
- Use [CPM.cmake](https://github.com/cpm-cmake/CPM.cmake) to add this package to the CMake project:
```cmake
cpmaddpackage(gh:threeal/assertion-cmake@0.1.0)
include(${Assertion_SOURCE_DIR}/cmake/Assertion.cmake)
```

## Example Usages

This example demonstrates how to use functions from this module to perform assertions:

```cmake
assert_true(TRUE)
assert_false(FALSE)

set(SOME_VARIABLE "some value")

assert_defined(SOME_VARIABLE)
assert_strequal("${SOME_VALUE}" "some value")

file(TOUCH some-file)

assert_exists(some-file)
assert_not_directory(some-file)
```

### Mock and Assert Messages

Use the `mock_message` function to mock the `message` function, allowing assertions on the `message` function as shown in the following example:

```cmake
mock_message()
message(STATUS "some status message")
message(ERROR "some error message")
end_mock_message()

assert_message(STATUS "some status message")
assert_message(ERROR "some error message")
```

## License

Expand Down