diff --git a/cmake/Assertion.cmake b/cmake/Assertion.cmake index 0c0489f..bef6f07 100644 --- a/cmake/Assertion.cmake +++ b/cmake/Assertion.cmake @@ -232,6 +232,9 @@ function(assert) if(ARGV1 STREQUAL "IN_LIST") fail("expected string" ARGV0 "to exist in" ARGV2) return() + elseif(ARGV1 STREQUAL "IS_NEWER_THAN") + fail("expected file" ARGV0 "to be newer than" ARGV2) + return() elseif(ARGV1 STREQUAL "MATCHES") fail("expected string" ARGV0 "to match" ARGV2) return() @@ -245,6 +248,9 @@ function(assert) if(ARGV2 STREQUAL "IN_LIST") fail("expected string" ARGV1 "not to exist in" ARGV3) return() + elseif(ARGV2 STREQUAL "IS_NEWER_THAN") + fail("expected file" ARGV1 "not to be newer than" ARGV3) + return() elseif(ARGV2 STREQUAL "MATCHES") fail("expected string" ARGV1 "not to match" ARGV3) return() diff --git a/test/assert.cmake b/test/assert.cmake index 65e0b56..c7b27dd 100644 --- a/test/assert.cmake +++ b/test/assert.cmake @@ -295,6 +295,26 @@ section("executable path condition assertions") endsection() endsection() +section("file recency condition assertions") + file(WRITE old_file "something") + file(WRITE new_file "something") + + section("it should assert file recency conditions") + assert(new_file IS_NEWER_THAN old_file) + assert(NOT old_file IS_NEWER_THAN new_file) + endsection() + + section("it should fail to assert file recency conditions") + assert_fatal_error( + CALL assert old_file IS_NEWER_THAN new_file + MESSAGE "expected file:\n old_file\nto be newer than:\n new_file") + + assert_fatal_error( + CALL assert NOT new_file IS_NEWER_THAN old_file + MESSAGE "expected file:\n new_file\nnot to be newer than:\n old_file") + endsection() +endsection() + section("directory path condition assertions") file(MAKE_DIRECTORY some_directory) file(TOUCH some_file)