PASS_REGULAR_EXPRESSION.rst 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. PASS_REGULAR_EXPRESSION
  2. -----------------------
  3. The test output (stdout or stderr) must match this regular expression
  4. for the test to pass. The process exit code is ignored. Tests that exceed
  5. the timeout specified by :prop_test:`TIMEOUT` still fail regardless of
  6. ``PASS_REGULAR_EXPRESSION``. System-level test failures including
  7. segmentation faults, signal abort, or heap errors may fail the test even
  8. if ``PASS_REGULAR_EXPRESSION`` is matched.
  9. Example:
  10. .. code-block:: cmake
  11. add_test(NAME mytest COMMAND ${CMAKE_COMMAND} -E echo "Passed this test")
  12. set_property(TEST mytest PROPERTY
  13. PASS_REGULAR_EXPRESSION "pass;Passed"
  14. )
  15. ``PASS_REGULAR_EXPRESSION`` expects a list of regular expressions.
  16. To run a test that may have a system-level failure, but still pass if
  17. ``PASS_REGULAR_EXPRESSION`` matches, use a CMake command to wrap the
  18. executable run. Note that this will prevent automatic handling of the
  19. :prop_tgt:`CROSSCOMPILING_EMULATOR` and :prop_tgt:`TEST_LAUNCHER`
  20. target property.
  21. .. code-block:: cmake
  22. add_executable(main main.c)
  23. add_test(NAME sigabrt COMMAND ${CMAKE_COMMAND} -E env $<TARGET_FILE:main>)
  24. set_property(TEST sigabrt PROPERTY PROPERTY_REGULAR_EXPRESSION "pass;Passed")
  25. .. code-block:: c
  26. #include <signal.h>
  27. #include <stdio.h>
  28. int main(void){
  29. fprintf(stdout, "Passed\n");
  30. fflush(stdout); /* ensure the output buffer is seen */
  31. raise(SIGABRT);
  32. return 0;
  33. }
  34. See also the :prop_test:`FAIL_REGULAR_EXPRESSION` and
  35. :prop_test:`SKIP_REGULAR_EXPRESSION` test properties.