Skip to content

Commit

Permalink
feat: rename option in assert_fatal_error to EXPECT_MESSAGE
Browse files Browse the repository at this point in the history
Signed-off-by: Alfi Maulana <alfi.maulana.f@gmail.com>
  • Loading branch information
threeal committed Oct 16, 2024
1 parent 26e8309 commit 4e7c787
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 118 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ assert_execute_process(
assert_fatal_error(
CALL git_clone https://github.com GITHUB_DIR
MESSAGE "failed to clone 'https://github.com'")
EXPECT_MESSAGE "failed to clone 'https://github.com'")
```

### Test Creation
Expand Down Expand Up @@ -174,7 +174,8 @@ to be defined
Asserts whether a command call throws a fatal error message.

```cmake
assert_fatal_error(CALL <command> [<arguments>...] MESSAGE <message>...)
assert_fatal_error(
CALL <command> [<arguments>...] EXPECT_MESSAGE <message>...)
```

This function asserts whether a function or macro named `<command>`, called with the specified `<arguments>`, throws a fatal error message that matches the expected `<message>`.
Expand All @@ -190,7 +191,7 @@ endfunction()
assert_fatal_error(
CALL throw_fatal_error "some message"
MESSAGE "some message")
EXPECT_MESSAGE "some message")
```

The above example asserts whether the call to `throw_fatal_error("some message")` throws a fatal error message that matches `some message`. If it somehow does not capture any fatal error message, it will throw the following fatal error message:
Expand Down
7 changes: 4 additions & 3 deletions cmake/Assertion.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,8 @@ endfunction()

# Asserts whether a command call throws a fatal error message.
#
# assert_fatal_error(CALL <command> [<arguments>...] MESSAGE <message>...)
# assert_fatal_error(
# CALL <command> [<arguments>...] EXPECT_MESSAGE <message>...)
#
# This function asserts whether a function or macro named `<command>`, called
# with the specified `<arguments>`, throws a fatal error message that matches
Expand All @@ -358,8 +359,8 @@ endfunction()
# If more than one `<message>` string is given, they are concatenated into a
# single message with no separator between the strings.
function(assert_fatal_error)
cmake_parse_arguments(PARSE_ARGV 0 ARG "" "" "CALL;MESSAGE")
string(JOIN "" EXPECTED_MESSAGE ${ARG_MESSAGE})
cmake_parse_arguments(PARSE_ARGV 0 ARG "" "" "CALL;EXPECT_MESSAGE")
string(JOIN "" EXPECTED_MESSAGE ${ARG_EXPECT_MESSAGE})

# Override the `message` function if it has not been overridden.
get_property(MESSAGE_MOCKED GLOBAL PROPERTY _assert_internal_message_mocked)
Expand Down
Loading

0 comments on commit 4e7c787

Please sign in to comment.