Skip to content

Commit

Permalink
Adding a test to validate that AutoInit can throw exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
codemercenary committed Aug 25, 2014
1 parent ba2d805 commit eb870cd
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/autowiring/test/AutoConstructTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,18 @@ TEST_F(AutoConstructTest, PostConstructGetsCalled) {
AutoRequired<ClassWithAutoInit> cwai;
ASSERT_TRUE(cwai->m_constructed) << "Trivial constructor call was not made as expected";
ASSERT_TRUE(cwai->m_postConstructed) << "Auto-initialization routine was not called on an initializable type";
}

class PostConstructThrowsException {
public:
void AutoInit(void) const {
throw std::runtime_error("Autoinit crashing for no reason");
}
};

TEST_F(AutoConstructTest, PostConstructCanSafelyThrow) {
ASSERT_ANY_THROW(AutoRequired<PostConstructThrowsException>()) << "AutoInit call threw an exception, but it was incorrectly eaten by Autowiring";

Autowired<PostConstructThrowsException> pcte;
ASSERT_FALSE(pcte.IsAutowired()) << "A context member which threw an exception post-construction was incorrectly introduced into a context";
}

0 comments on commit eb870cd

Please sign in to comment.