Skip to content

Commit

Permalink
test: organize sections in test/assert_execute_process.cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
threeal committed Jul 4, 2024
1 parent c4f5d83 commit 6857a79
Showing 1 changed file with 60 additions and 42 deletions.
102 changes: 60 additions & 42 deletions test/assert_execute_process.cmake
Original file line number Diff line number Diff line change
@@ -1,55 +1,73 @@
section("execute process assertions")
file(TOUCH some-file)
section("process execution assertion")
section("it should assert a process execution")
assert_execute_process("${CMAKE_COMMAND}" -E true)
endsection()

assert_execute_process("${CMAKE_COMMAND}" -E true)
section("it should fail to assert a process execution")
assert_fatal_error(
CALL assert_execute_process "${CMAKE_COMMAND}" -E true ERROR .*
MESSAGE "expected command:\n ${CMAKE_COMMAND} -E true\nto fail")
endsection()
endsection()

assert_execute_process(
"${CMAKE_COMMAND}" -E make_directory some-file ERROR .*)
section("failed process execution assertion")
file(TOUCH some-file)

assert_fatal_error(
CALL assert_execute_process "${CMAKE_COMMAND}" -E true ERROR .*
MESSAGE "expected command:\n ${CMAKE_COMMAND} -E true\nto fail")
section("it should assert a failed process execution")
assert_execute_process(
"${CMAKE_COMMAND}" -E make_directory some-file ERROR .*)
endsection()

assert_fatal_error(
CALL assert_execute_process "${CMAKE_COMMAND}" -E make_directory some-file
MESSAGE "expected command:\n"
" ${CMAKE_COMMAND} -E make_directory some-file\n"
"not to fail with error:\n"
" Error creating directory \"some-file\".")
section("it should fail to assert a failed process execution")
assert_fatal_error(
CALL assert_execute_process "${CMAKE_COMMAND}" -E make_directory some-file
MESSAGE "expected command:\n"
" ${CMAKE_COMMAND} -E make_directory some-file\n"
"not to fail with error:\n"
" Error creating directory \"some-file\".")
endsection()
endsection()

section("execute process output assertions")
assert_execute_process(
COMMAND "${CMAKE_COMMAND}" -E echo "Hello world!"
OUTPUT "Hello" ".*!")

assert_fatal_error(
CALL assert_execute_process
section("process execution output assertion")
section("it should assert a process execution output")
assert_execute_process(
COMMAND "${CMAKE_COMMAND}" -E echo "Hello world!"
OUTPUT "Hello" ".*earth!"
MESSAGE "expected the output:\n"
".*\n"
"of command:\n"
" ${CMAKE_COMMAND} -E echo Hello world!\n"
"to match:\n"
" Hello.*earth!")
OUTPUT "Hello" ".*!")
endsection()

section("it should fail to assert a process execution output")
assert_fatal_error(
CALL assert_execute_process
COMMAND "${CMAKE_COMMAND}" -E echo "Hello world!"
OUTPUT "Hello" ".*earth!"
MESSAGE "expected the output:\n"
".*\n"
"of command:\n"
" ${CMAKE_COMMAND} -E echo Hello world!\n"
"to match:\n"
" Hello.*earth!")
endsection()
endsection()

section("execute process error assertions")
section("process execution error assertion")
file(TOUCH some-file)

assert_execute_process(
COMMAND "${CMAKE_COMMAND}" -E make_directory some-file
ERROR "Error creating directory" ".*some-file")

assert_fatal_error(
CALL assert_execute_process
section("it should assert a process execution error")
assert_execute_process(
COMMAND "${CMAKE_COMMAND}" -E make_directory some-file
ERROR "Error creating directory" ".*some-other-file"
MESSAGE "expected the error:\n"
".*\n"
"of command:\n"
" ${CMAKE_COMMAND} -E make_directory some-file\n"
"to match:\n"
" Error creating directory.*some-other-file")
ERROR "Error creating directory" ".*some-file")
endsection()

section("it should fail to assert a process execution error")
assert_fatal_error(
CALL assert_execute_process
COMMAND "${CMAKE_COMMAND}" -E make_directory some-file
ERROR "Error creating directory" ".*some-other-file"
MESSAGE "expected the error:\n"
".*\n"
"of command:\n"
" ${CMAKE_COMMAND} -E make_directory some-file\n"
"to match:\n"
" Error creating directory.*some-other-file")
endsection()
endsection()

0 comments on commit 6857a79

Please sign in to comment.