Skip to content

Commit

Permalink
feat: add support to format path writability assertion errors (#181)
Browse files Browse the repository at this point in the history
  • Loading branch information
threeal authored Jul 7, 2024
1 parent 9ae9f25 commit 7106824
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
6 changes: 6 additions & 0 deletions cmake/Assertion.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ function(assert)
elseif(ARGV0 STREQUAL "IS_READABLE")
fail("expected path" ARGV1 "to be readable")
return()
elseif(ARGV0 STREQUAL "IS_WRITABLE")
fail("expected path" ARGV1 "to be writable")
return()
elseif(ARGV0 STREQUAL "IS_EXECUTABLE")
fail("expected path" ARGV1 "to be an executable")
return()
Expand Down Expand Up @@ -168,6 +171,9 @@ function(assert)
elseif(ARGV1 STREQUAL "IS_READABLE")
fail("expected path" ARGV2 "not to be readable")
return()
elseif(ARGV1 STREQUAL "IS_WRITABLE")
fail("expected path" ARGV2 "not to be writable")
return()
elseif(ARGV1 STREQUAL "IS_EXECUTABLE")
fail("expected path" ARGV2 "not to be an executable")
return()
Expand Down
25 changes: 23 additions & 2 deletions test/assert.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,7 @@ section("path readability condition assertions")

file(REMOVE non_readable_file)
file(TOUCH non_readable_file)
file(CHMOD non_readable_file
PERMISSIONS OWNER_WRITE OWNER_EXECUTE GROUP_EXECUTE WORLD_EXECUTE)
file(CHMOD non_readable_file PERMISSIONS OWNER_WRITE)

section("it should assert path readability conditions")
assert(IS_READABLE some_file)
Expand All @@ -268,6 +267,28 @@ section("path readability condition assertions")
endsection()
endsection()

section("path writability condition assertions")
file(TOUCH some_file)

file(TOUCH non_writable_file)
file(CHMOD non_writable_file PERMISSIONS OWNER_READ GROUP_READ WORLD_READ)

section("it should assert path writability conditions")
assert(IS_WRITABLE some_file)
assert(NOT IS_WRITABLE non_writable_file)
endsection()

section("it should fail to assert path writability conditions")
assert_fatal_error(
CALL assert IS_WRITABLE non_writable_file
MESSAGE "expected path:\n non_writable_file\nto be writable")

assert_fatal_error(
CALL assert NOT IS_WRITABLE some_file
MESSAGE "expected path:\n some_file\nnot to be writable")
endsection()
endsection()

section("executable path condition assertions")
file(TOUCH some_executable)
file(
Expand Down

0 comments on commit 7106824

Please sign in to comment.