Skip to content

Commit

Permalink
feat: add support to format file recency assertion errors
Browse files Browse the repository at this point in the history
  • Loading branch information
threeal committed Jul 9, 2024
1 parent 78ca271 commit c8e3fc3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cmake/Assertion.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down
20 changes: 20 additions & 0 deletions test/assert.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c8e3fc3

Please sign in to comment.