From 710682471992160ae83f79cf0b37187c28a61c65 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Sun, 7 Jul 2024 18:17:29 +0700 Subject: [PATCH] feat: add support to format path writability assertion errors (#181) --- cmake/Assertion.cmake | 6 ++++++ test/assert.cmake | 25 +++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/cmake/Assertion.cmake b/cmake/Assertion.cmake index 588ae8b..1dc22e7 100644 --- a/cmake/Assertion.cmake +++ b/cmake/Assertion.cmake @@ -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() @@ -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() diff --git a/test/assert.cmake b/test/assert.cmake index 81ad9e8..6234fae 100644 --- a/test/assert.cmake +++ b/test/assert.cmake @@ -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) @@ -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(