DryChem 1.0.0
A generic, compile-time C++ toolbox with no dependencies for the modern computational chemistry project.
Loading...
Searching...
No Matches
testErrorHandling.hpp
Go to the documentation of this file.
1// Copyright (c) 2020-2025 Cody R. Drisko. All rights reserved.
2// Licensed under the MIT License. See the LICENSE file in the project root for more information.
3//
4// Name: testErrorHandling.hpp
5// Author: crdrisko
6// Date: 08/26/2020-14:35:44
7// Description: Provides ~100% unit test coverage over all error handing functions
8
9#ifndef DRYCHEM_COMMON_UTILITIES_LIBS_ERRORS_TESTS_TESTUTILITIES_TESTERRORHANDLING_HPP
10#define DRYCHEM_COMMON_UTILITIES_LIBS_ERRORS_TESTS_TESTUTILITIES_TESTERRORHANDLING_HPP
11
12#include <string>
13
15#include <gtest/gtest.h>
16
17GTEST_TEST(testErrorHandling, errorPrintsMessageToStandardError)
18{
19 testing::internal::CaptureStderr();
20
21 DryChem::printErrorMessage<DryChem::ErrorSeverity::Warning>(
22 DryChem::ErrorMessage {"Common-Utilities", "Testing the output of the non-fatal error message command."});
23
24 std::string output = testing::internal::GetCapturedStderr();
25 ASSERT_EQ(output, "Common-Utilities Warning:\n Testing the output of the non-fatal error message command.\n");
26}
27
28GTEST_TEST(testErrorHandling, fatalErrorCausesProgramTermination)
29{
30 ASSERT_DEATH(
31 {
32 DryChem::printErrorMessage<DryChem::ErrorSeverity::Fatal>(
33 DryChem::ErrorMessage {"Common-Utilities", "Fatal Error, Program Terminated."});
34 },
35 "Common-Utilities Fatal Error:\n Fatal Error, Program Terminated.\n");
36}
37
38GTEST_TEST(testErrorHandling, defaultTemplateParameterIsAWarning)
39{
40 testing::internal::CaptureStderr();
41
42 DryChem::printErrorMessage(
43 DryChem::ErrorMessage {"Common-Utilities", "Testing the output of the non-fatal error message command."});
44
45 std::string output = testing::internal::GetCapturedStderr();
46 ASSERT_EQ(output, "Common-Utilities Warning:\n Testing the output of the non-fatal error message command.\n");
47}
48
49GTEST_TEST(testErrorHandling, aliasLambdaFunctionWorksForAFatalError)
50{
51 ASSERT_DEATH(
52 { DryChem::printFatalErrorMessage(DryChem::ErrorMessage {"Common-Utilities", "Fatal Error, Program Terminated."}); },
53 "Common-Utilities Fatal Error:\n Fatal Error, Program Terminated.\n");
54}
55
56#endif
GTEST_TEST(testErrorHandling, errorPrintsMessageToStandardError)
Definition testErrorHandling.hpp:17