From 59724d4095fa0e7fdafad00803ccf28a08fe0920 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Sat, 6 Jul 2024 11:35:03 +0700 Subject: [PATCH] feat: add support to format executable path assertion errors (#165) --- cmake/Assertion.cmake | 6 ++++++ test/assert.cmake | 26 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/cmake/Assertion.cmake b/cmake/Assertion.cmake index 27df0b1..4c7f700 100644 --- a/cmake/Assertion.cmake +++ b/cmake/Assertion.cmake @@ -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() @@ -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() diff --git a/test/assert.cmake b/test/assert.cmake index ee3f3fe..dc39b3f 100644 --- a/test/assert.cmake +++ b/test/assert.cmake @@ -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")