From 27514d7ed2347387eeeee0a5acf4756a06911fab Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Sun, 7 Jul 2024 18:24:19 +0700 Subject: [PATCH] feat: add support to format symbolic link path assertion errors --- cmake/Assertion.cmake | 6 ++++++ test/assert.cmake | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/cmake/Assertion.cmake b/cmake/Assertion.cmake index 1dc22e7..2f0f606 100644 --- a/cmake/Assertion.cmake +++ b/cmake/Assertion.cmake @@ -146,6 +146,9 @@ function(assert) elseif(ARGV0 STREQUAL "IS_DIRECTORY") fail("expected path" ARGV1 "to be a directory") return() + elseif(ARGV0 STREQUAL "IS_SYMLINK") + fail("expected path" ARGV1 "to be a symbolic link") + return() endif() endif() elseif(ARGC EQUAL 3) @@ -180,6 +183,9 @@ function(assert) elseif(ARGV1 STREQUAL "IS_DIRECTORY") fail("expected path" ARGV2 "not to be a directory") return() + elseif(ARGV1 STREQUAL "IS_SYMLINK") + fail("expected path" ARGV2 "not to be a symbolic link") + return() endif() else() if(ARGV1 STREQUAL "IN_LIST") diff --git a/test/assert.cmake b/test/assert.cmake index 6234fae..0556765 100644 --- a/test/assert.cmake +++ b/test/assert.cmake @@ -315,6 +315,26 @@ section("executable path condition assertions") endsection() endsection() +section("symbolic link path condition assertions") + file(TOUCH some_file) + file(CREATE_LINK some_file some_symlink SYMBOLIC) + + section("it should assert symbolic link path conditions") + assert(IS_SYMLINK some_symlink) + assert(NOT IS_SYMLINK some_file) + endsection() + + section("it should fail to assert symbolic link path conditions") + assert_fatal_error( + CALL assert IS_SYMLINK some_file + MESSAGE "expected path:\n some_file\nto be a symbolic link") + + assert_fatal_error( + CALL assert NOT IS_SYMLINK some_symlink + MESSAGE "expected path:\n some_symlink\nnot to be a symbolic link") + endsection() +endsection() + section("regular expression match condition assertions") section("given a string") section("it should assert regular expression match conditions")