CMake Best Practices by Dominik Berner Mustafa Kemal Gilor
Author:Dominik Berner, Mustafa Kemal Gilor
Language: eng
Format: epub
Publisher: Packt Publishing Pvt. Ltd.
Published: 2022-05-12T00:00:00+00:00
Catch2 and GoogleTest are just two of the many testing frameworks out there; there might be more test suites that bring this functionality with them that might be unknown to the authors. Now, let's move on from finding tests and have a closer look at how to control test behavior.
Advanced ways to determine test success or failure
By default, CTest determines whether a test failed or passed based on the return value of the command. 0 means all tests were successful, anything other than 0 is interpreted as a failure.
Sometimes, the return value is not enough to determine whether a test passes or fails. If you need to check program output for a certain string, the FAIL_REGULAR_EXPRESSION and PASS_REGULAR_EXPRESSION test properties can be used, as shown in the following example:
set_tests_properties(some_test PROPERTIES
FAIL_REGULAR_EXPRESSION "[W|w]arning|[E|e]rror"
PASS_REGULAR_EXPRESSION "[S|s]uccess")
These properties would cause the some_test test to fail if the output contains either "Warning" or "Error". If the "Success" string is found, the test is considered passed. If PASS_REGULAR_EXPRESSION is set, the test is considered passed only if the string is present. In both cases, the return value will be ignored. If a certain return value of a test needs to be ignored, it can be passed with the SKIP_RETURN_CODE option.
Sometimes, a test is expected to fail. In those, setting WILL_FAIL to true will cause the test result to be inverted:
add_test(NAME SomeFailingTerst COMMAND SomeFailingTest)
set_tests_properties(SomeFailingTest PROPERTIES WILL_FAIL True)
This is often better than disabling the test because the test will still be executed on each test run, and if the test unexpectedly starts to pass again, the developer is made aware of it. A special case of test failures is when tests fail to return or take too much time to complete. For this case, CTest provides the means of adding timeouts of tests and even retrying tests in the case of failure.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
C | C++ |
Tutorials | Visual C++ |
Hello! Python by Anthony Briggs(9918)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9797)
The Mikado Method by Ola Ellnestam Daniel Brolund(9780)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8303)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(7784)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7764)
Grails in Action by Glen Smith Peter Ledbrook(7699)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7559)
Windows APT Warfare by Sheng-Hao Ma(6868)
Layered Design for Ruby on Rails Applications by Vladimir Dementyev(6602)
Blueprints Visual Scripting for Unreal Engine 5 - Third Edition by Marcos Romero & Brenden Sewell(6470)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6420)
Kotlin in Action by Dmitry Jemerov(5068)
Hands-On Full-Stack Web Development with GraphQL and React by Sebastian Grebe(4320)
Functional Programming in JavaScript by Mantyla Dan(4040)
Solidity Programming Essentials by Ritesh Modi(4021)
WordPress Plugin Development Cookbook by Yannick Lefebvre(3812)
Unity 3D Game Development by Anthony Davis & Travis Baptiste & Russell Craig & Ryan Stunkel(3755)
The Ultimate iOS Interview Playbook by Avi Tsadok(3731)
