"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "googletest/test/gtest_throw_on_failure_ex_test.cc" between
googletest-release-1.11.0.tar.gz and googletest-release-1.12.0.tar.gz

About: GoogleTest is Google's (unit) testing and mocking framework for C++ tests.

gtest_throw_on_failure_ex_test.cc  (googletest-release-1.11.0):gtest_throw_on_failure_ex_test.cc  (googletest-release-1.12.0)
skipping to change at line 32 skipping to change at line 32
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Tests Google Test's throw-on-failure mode with exceptions enabled. // Tests Google Test's throw-on-failure mode with exceptions enabled.
#include "gtest/gtest.h"
#include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdexcept> #include <stdexcept>
#include "gtest/gtest.h"
// Prints the given failure message and exits the program with // Prints the given failure message and exits the program with
// non-zero. We use this instead of a Google Test assertion to // non-zero. We use this instead of a Google Test assertion to
// indicate a failure, as the latter is been tested and cannot be // indicate a failure, as the latter is been tested and cannot be
// relied on. // relied on.
void Fail(const char* msg) { void Fail(const char* msg) {
printf("FAILURE: %s\n", msg); printf("FAILURE: %s\n", msg);
fflush(stdout); fflush(stdout);
exit(1); exit(1);
} }
// Tests that an assertion failure throws a subclass of // Tests that an assertion failure throws a subclass of
// std::runtime_error. // std::runtime_error.
void TestFailureThrowsRuntimeError() { void TestFailureThrowsRuntimeError() {
testing::GTEST_FLAG(throw_on_failure) = true; GTEST_FLAG_SET(throw_on_failure, true);
// A successful assertion shouldn't throw. // A successful assertion shouldn't throw.
try { try {
EXPECT_EQ(3, 3); EXPECT_EQ(3, 3);
} catch(...) { } catch (...) {
Fail("A successful assertion wrongfully threw."); Fail("A successful assertion wrongfully threw.");
} }
// A failed assertion should throw a subclass of std::runtime_error. // A failed assertion should throw a subclass of std::runtime_error.
try { try {
EXPECT_EQ(2, 3) << "Expected failure"; EXPECT_EQ(2, 3) << "Expected failure";
} catch(const std::runtime_error& e) { } catch (const std::runtime_error& e) {
if (strstr(e.what(), "Expected failure") != nullptr) return; if (strstr(e.what(), "Expected failure") != nullptr) return;
printf("%s", printf("%s",
"A failed assertion did throw an exception of the right type, " "A failed assertion did throw an exception of the right type, "
"but the message is incorrect. Instead of containing \"Expected " "but the message is incorrect. Instead of containing \"Expected "
"failure\", it is:\n"); "failure\", it is:\n");
Fail(e.what()); Fail(e.what());
} catch(...) { } catch (...) {
Fail("A failed assertion threw the wrong type of exception."); Fail("A failed assertion threw the wrong type of exception.");
} }
Fail("A failed assertion should've thrown but didn't."); Fail("A failed assertion should've thrown but didn't.");
} }
int main(int argc, char** argv) { int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv); testing::InitGoogleTest(&argc, argv);
// We want to ensure that people can use Google Test assertions in // We want to ensure that people can use Google Test assertions in
// other testing frameworks, as long as they initialize Google Test // other testing frameworks, as long as they initialize Google Test
 End of changes. 8 change blocks. 
7 lines changed or deleted 8 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)