Skip to content

Commit

Permalink
feat: add support to format executable path assertion errors (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
threeal authored Jul 6, 2024
1 parent 52370f6 commit 59724d4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cmake/Assertion.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ function(assert)
elseif(ARGV0 STREQUAL "EXISTS")
fail("expected path" ARGV1 "to exist")
return()
elseif(ARGV0 STREQUAL "IS_EXECUTABLE")
fail("expected path" ARGV1 "to be an executable")
return()
elseif(ARGV0 STREQUAL "IS_DIRECTORY")
fail("expected path" ARGV1 "to be a directory")
return()
Expand All @@ -142,6 +145,9 @@ function(assert)
elseif(ARGV1 STREQUAL "EXISTS")
fail("expected path" ARGV2 "not to exist")
return()
elseif(ARGV1 STREQUAL "IS_EXECUTABLE")
fail("expected path" ARGV2 "not to be an executable")
return()
elseif(ARGV1 STREQUAL "IS_DIRECTORY")
fail("expected path" ARGV2 "not to be a directory")
return()
Expand Down
26 changes: 26 additions & 0 deletions test/assert.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,32 @@ section("directory path condition assertions")
endsection()
endsection()

section("executable path condition assertions")
file(TOUCH some_executable)
file(
CHMOD some_executable
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE)

file(TOUCH some_file)

section("it should assert executable path conditions")
assert(IS_EXECUTABLE some_executable)
assert(NOT IS_EXECUTABLE some_file)
endsection()

section("it should fail to assert executable path conditions")
assert_fatal_error(
CALL assert IS_EXECUTABLE some_file
MESSAGE "expected path:\n some_file\nto be an executable")

assert_fatal_error(
CALL assert NOT IS_EXECUTABLE some_executable
MESSAGE "expected path:\n some_executable\nnot to be an executable")
endsection()
endsection()

section("regular expression match condition assertions")
section("given a string")
section("it should assert regular expression match conditions")
Expand Down

0 comments on commit 59724d4

Please sign in to comment.