Permalink
Browse files

TestResult can determine if it has a line number

  • Loading branch information...
1 parent c4c0250 commit 7d777eef3f4a32107867f2c8e9a18fb2b7713daa @joakimkarlsson committed Jul 13, 2011
Showing with 58 additions and 17 deletions.
  1. +29 −14 igloo/core/assertionexception.h
  2. +8 −2 igloo/core/testresult.h
  3. +1 −1 igloo/core/testresultfactory.h
  4. +20 −0 tests/testresultfactory_tests.cpp
View
43 igloo/core/assertionexception.h
@@ -10,23 +10,38 @@
namespace igloo {
class AssertionException : public std::exception
{
- public:
- AssertionException(const std::string& message)
- : m_message(message)
- {
- }
+ public:
+ AssertionException(const std::string& message)
+ : m_message(message), m_fileName(""), m_line(0)
+ {}
- virtual ~AssertionException() throw()
- {
- }
+ AssertionException(const std::string& message, const std::string& fileName, unsigned int line)
+ : m_message(message), m_fileName(fileName), m_line(line)
+ {}
- std::string GetMessage() const
- {
- return m_message;
- }
+ virtual ~AssertionException() throw()
+ {
+ }
+
+ std::string GetMessage() const
+ {
+ return m_message;
+ }
+
+ std::string GetFilename() const
+ {
+ return m_fileName;
+ }
+
+ unsigned int GetLineNumber() const
+ {
+ return m_line;
+ }
- private:
- std::string m_message;
+ private:
+ std::string m_message;
+ std::string m_fileName;
+ unsigned int m_line;
};
}
View
10 igloo/core/testresult.h
@@ -11,8 +11,13 @@ namespace igloo {
class TestResult
{
public:
+ TestResult(const std::string& contextName, const std::string& specName, bool success, const std::string& errorMessage, const std::string& filename, unsigned int line)
+ : m_contextName(contextName), m_specName(specName), m_success(success), m_errorMessage(errorMessage), m_filename(filename), m_line(line)
+ {
+ }
+
TestResult(const std::string& contextName, const std::string& specName, bool success, const std::string& errorMessage)
- : m_contextName(contextName), m_specName(specName), m_success(success), m_errorMessage(errorMessage)
+ : m_contextName(contextName), m_specName(specName), m_success(success), m_errorMessage(errorMessage), m_filename(""), m_line(0)
{
}
@@ -38,7 +43,7 @@ namespace igloo {
bool HasLineNumber() const
{
- return false;
+ return m_line != 0;
}
unsigned int LineNumber() const
@@ -72,6 +77,7 @@ namespace igloo {
bool m_success;
std::string m_errorMessage;
std::string m_filename;
+ unsigned int m_line;
};
inline std::ostream& operator<<(std::ostream& stream, const TestResult& res)
View
2 igloo/core/testresultfactory.h
@@ -18,7 +18,7 @@ namespace igloo {
TestResult CreateFromException(const AssertionException& exception)
{
- return TestResult(m_contextName, m_specName, false, exception.GetMessage());
+ return TestResult(m_contextName, m_specName, false, exception.GetMessage(), exception.GetFilename(), exception.GetLineNumber());
}
private:
View
20 tests/testresultfactory_tests.cpp
@@ -35,3 +35,23 @@ Context(An_assertion_without_file_and_linenumber_information)
}
};
+
+Context(An_assertion_with_file_and_linenumber_information)
+{
+ AssertionException exception;
+ TestResultFactory factory;
+
+ An_assertion_with_file_and_linenumber_information()
+ : exception("An error message", "myfile.cpp", 432)
+ ,factory("A context name", "A spec")
+ {}
+
+ Spec(Created_TestResult_should_have_a_linenumber)
+ {
+ TestResult result = factory.CreateFromException(exception);
+
+ Assert::That(result.HasLineNumber());
+
+ }
+
+};

0 comments on commit 7d777ee

Please sign in to comment.