Last active
August 12, 2016 22:02
-
-
Save comargo/9d8cf4dd4f5696568227797ef5e41a6f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <gtest/gtest.h> | |
#include <system_error> | |
#define ASSERT_SYSTEM_ERROR(statement, error_code) \ | |
ASSERT_THROW({\ | |
try { \ | |
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ | |
} \ | |
catch(const std::system_error &exception) {\ | |
ASSERT_EQ(error_code, exception.code());\ | |
throw;\ | |
}\ | |
}, std::system_error) | |
#define EXPECT_SYSTEM_ERROR(statement, error_code) \ | |
EXPECT_THROW({\ | |
try { \ | |
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ | |
} \ | |
catch(const std::system_error &exception) {\ | |
EXPECT_EQ(error_code, exception.code());\ | |
throw;\ | |
}\ | |
}, std::system_error) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <gtest/gtest.h> | |
#include "gtest-system-error.hpp" | |
#include <thread> | |
// Example of exception took from | |
// http://en.cppreference.com/w/cpp/error/system_error | |
TEST(Test,TestPassed) | |
{ | |
EXPECT_SYSTEM_ERROR(std::thread().detach(), std::make_error_code(std::errc::invalid_argument)); | |
} | |
TEST(Test,TestFailed) | |
{ | |
EXPECT_SYSTEM_ERROR(std::thread().detach(), std::make_error_code(std::errc::io_error)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
On my test environment the Test.TestFailed report error twice. Why?