Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
  • 9 commits
  • 8 files changed
  • 0 commit comments
  • 1 contributor
View
45 igloo/core/outputters/defaulttestresultsoutput.h
@@ -0,0 +1,45 @@
+
+// Copyright Joakim Karlsson & Kim Gräsman 2010.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef IGLOO_DEFAULTTESTRESULTSOUTPUT_H
+#define IGLOO_DEFAULTTESTRESULTSOUTPUT_H
+
+namespace igloo {
+
+ class DefaultTestResultsOutput : public TestResultsOutput
+ {
+ public:
+ DefaultTestResultsOutput(std::ostream& outputStream) : outputStream_(outputStream)
+ {
+ }
+
+ void PrintResult(const TestResults& results)
+ {
+ for (TestResults::FailedTestsType::const_iterator it = results.FailedTests().begin(); it != results.FailedTests().end(); it++)
+ {
+ const FailedTestResult& result = *it;
+ outputStream_ << result.GetContextName() << "::" << result.GetSpecName() << " failed:" << std::endl;
+
+ if(result.HasLineNumber() && result.HasFilename())
+ {
+ outputStream_ << result.Filename() << "(" << result.LineNumber() << "): Assertion failed." << std::endl << result.GetErrorMessage() << std::endl;
+ }
+ else
+ {
+ outputStream_ << result.GetErrorMessage() << std::endl;
+ }
+ }
+
+ outputStream_ << "Test run complete. " << results.NumberOfTestsRun() << " tests run, " << results.NumberOfSucceededTests() << " succeeded, " << results.NumberOfFailedTests() << " failed." << std::endl;
+ }
+
+ private:
+ std::ostream& outputStream_;
+ };
+}
+
+#endif
+
View
14 igloo/core/outputters/outputters.h
@@ -0,0 +1,14 @@
+
+// Copyright Joakim Karlsson & Kim Gräsman 2010.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef IGLOO_OUTPUTTERS_H
+#define IGLOO_OUTPUTTERS_H
+
+#include <igloo/core/outputters/testresultsoutput.h>
+#include <igloo/core/outputters/defaulttestresultsoutput.h>
+#include <igloo/core/outputters/visualstudiooutput.h>
+
+#endif
View
19 igloo/core/outputters/testresultsoutput.h
@@ -0,0 +1,19 @@
+
+// Copyright Joakim Karlsson & Kim Gräsman 2010.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef IGLOO_TESTRESULTSOUTPUT_H
+#define IGLOO_TESTRESULTSOUTPUT_H
+
+namespace igloo {
+
+ class TestResultsOutput
+ {
+ public:
+ virtual void PrintResult(const TestResults& results) = 0;
+ };
+}
+
+#endif
View
49 igloo/core/outputters/visualstudiooutput.h
@@ -0,0 +1,49 @@
+
+// Copyright Joakim Karlsson & Kim Gräsman 2010.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef IGLOO_VISUALSTUDIOOUTPUT_H
+#define IGLOO_VISUALSTUDIOOUTPUT_H
+
+namespace igloo {
+
+ class VisualStudioResultsOutput : public TestResultsOutput
+ {
+ public:
+ VisualStudioResultsOutput(std::ostream& output)
+ : output_(output)
+ {}
+
+ void PrintResult(const TestResults& results)
+ {
+ TestResults::FailedTestsType::const_iterator it;
+
+ for(it = results.FailedTests().begin(); it != results.FailedTests().end(); it++)
+ {
+ output_ << FormatOriginString(*it) << " : assertion failed error I001: " << (*it).GetContextName() << "::" << (*it).GetSpecName() << ":" << std::endl << (*it).GetErrorMessage() << std::endl;
+ }
+
+ output_ << "Test run complete. " << results.NumberOfTestsRun() << " tests run, " << results.NumberOfSucceededTests() << " succeeded, " << results.NumberOfFailedTests() << " failed." << std::endl;
+ }
+
+ private:
+
+ std::string FormatOriginString(const FailedTestResult& result)
+ {
+ if(result.HasLineNumber() && result.HasFilename())
+ {
+ std::ostringstream builder;
+ builder << result.Filename() << "(" << result.LineNumber() << ")";
+ return builder.str();
+ }
+
+ // Default to toolname if no location information is available
+ return "Igloo";
+ }
+
+ std::ostream& output_;
+ };
+}
+#endif
View
47 igloo/core/testrunner.h
@@ -12,37 +12,6 @@
namespace igloo {
- class DefaultTestResultsOutput
- {
- public:
- DefaultTestResultsOutput(std::ostream& outputStream) : outputStream_(outputStream)
- {
- }
-
- void PrintResult(const TestResults& results)
- {
- for (TestResults::FailedTestsType::const_iterator it = results.FailedTests().begin(); it != results.FailedTests().end(); it++)
- {
- const FailedTestResult& result = *it;
- outputStream_ << result.GetContextName() << "::" << result.GetSpecName() << " failed:" << std::endl;
-
- if(result.HasLineNumber() && result.HasFilename())
- {
- outputStream_ << result.Filename() << "(" << result.LineNumber() << "): Assertion failed." << std::endl << result.GetErrorMessage() << std::endl;
- }
- else
- {
- outputStream_ << result.GetErrorMessage() << std::endl;
- }
- }
-
- outputStream_ << "Test run complete. " << results.NumberOfTestsRun() << " tests run, " << results.NumberOfSucceededTests() << " succeeded, " << results.NumberOfFailedTests() << " failed." << std::endl;
- }
-
- private:
- std::ostream& outputStream_;
- };
-
class TestRunner
{
public:
@@ -51,6 +20,17 @@ namespace igloo {
static int RunAllTests()
{
+ DefaultTestResultsOutput output(std::cout);
+ TestRunner runner(&output);
+ return runner.Run();
+ }
+
+ TestRunner(TestResultsOutput* output)
+ : output_(output)
+ {}
+
+ int Run()
+ {
TestResults results;
for (ContextRunners::iterator it = RegisteredRunners().begin(); it != RegisteredRunners().end(); it++)
@@ -63,7 +43,7 @@ namespace igloo {
std::cout << std::endl;
- DefaultTestResultsOutput(std::cout).PrintResult(results);
+ output_->PrintResult(results);
return results.NumberOfFailedTests();
}
@@ -110,6 +90,9 @@ namespace igloo {
static TestRunner::ContextRunners contextRunners;
return contextRunners;
}
+
+ private:
+ TestResultsOutput* output_;
};
}
View
1  igloo/igloo_framework.h
@@ -23,6 +23,7 @@
#include <igloo/core/testresult.h>
#include <igloo/core/testresultfactory.h>
#include <igloo/core/testresults.h>
+#include <igloo/core/outputters/outputters.h>
#include <igloo/core/assertionexception.h>
#include <igloo/core/context.h>
#include <igloo/core/contextrunner.h>
View
86 tests/visualstudiotestresultsoutput_tests.cpp
@@ -0,0 +1,86 @@
+
+// Copyright Joakim Karlsson & Kim Gräsman 2010.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include <tests/igloo_self_test.h>
+#include <memory>
+
+using namespace igloo;
+
+Context(VisualStudioResultsOutput_EmptyTestRun)
+{
+ std::auto_ptr<VisualStudioResultsOutput> output;
+ std::stringstream resulting_stream;
+ TestResults results;
+
+ void SetUp()
+ {
+ output = std::auto_ptr<VisualStudioResultsOutput>(new VisualStudioResultsOutput(resulting_stream));
+ output->PrintResult(results);
+ }
+
+ Spec(it_should_display_a_summary_line_with_no_tests_run)
+ {
+ Assert::That(resulting_stream.str(), Is().StartingWith("Test run complete. 0 tests run, 0 succeeded, 0 failed."));
+ }
+
+ Context(VisualStudioResultsOutput_one_failed_test_with_no_location_information)
+ {
+ void SetUp()
+ {
+ testResults().AddResult(FailedTestResult("A context name", "A failing spec", "The error message"));
+ Parent().output->PrintResult(Parent().results);
+ }
+
+ Spec(it_displays_one_failing_test_in_summary)
+ {
+ AssertThat(resulting_output(), Has().Exactly(1).StartingWith("Test run complete. 1 tests run, 0 succeeded, 1 failed"));
+ }
+
+ Spec(it_displays_error_text_for_failed_spec_with_no_location_information)
+ {
+ AssertThat(resulting_output(), Is().Containing("Igloo : assertion failed error I001: A context name::A failing spec:\nThe error message"));
+ }
+
+ TestResults& testResults()
+ {
+ return Parent().results;
+ }
+
+ std::string resulting_output()
+ {
+ return Parent().resulting_stream.str();
+ }
+ };
+
+ Context(VisualStudioResultOutput_one_failed_test_with_information_about_location_of_assertion)
+ {
+ void SetUp()
+ {
+ testResults().AddResult(FailedTestResult("A context name", "A failing spec", "The error message", "filename.cpp", 23));
+ Parent().output->PrintResult(Parent().results);
+ }
+
+ Spec(it_displays_one_failing_test_in_summary)
+ {
+ AssertThat(resulting_output(), Has().Exactly(1).StartingWith("Test run complete. 1 tests run, 0 succeeded, 1 failed"));
+ }
+
+ Spec(it_displays_error_text_for_failed_spec_with_location_information)
+ {
+ AssertThat(resulting_output(), Is().Containing("filename.cpp(23) : assertion failed error I001: A context name::A failing spec:\nThe error message\n"));
+ }
+
+ TestResults& testResults()
+ {
+ return Parent().results;
+ }
+
+ std::string resulting_output()
+ {
+ return Parent().resulting_stream.str();
+ }
+ };
+};
View
31 todo.txt
@@ -0,0 +1,31 @@
+
+Visual Studio Formatted output:
+*Done: Moved current formatting to DefaultTestResultOutputter
+*Done: Move DefaultTestResultOutputter to its own file.
+*Done: Create VisualStudioResultOutputter
+*Done: Create interface common for all ResultOutputters
+Documentation
+
+Cleanup needed to be done:
+Move ContextRegistry from context.h to its own file.
+Change year in license header notice.
+
+Outer context is not recreated properly between runs:
+
+Create test listeners:
+Possibility to register listener.
+Listener gets callback when test run starts.
+Listener gets callback when test run ends.
+Listener gets callback when context run starts
+Listener gets callback when context run ends
+Listener gets callback when spec run starts
+Listener gets callback when spec run succeeds
+Listener gets callback when spec run fails
+
+Create Context Level SetUp/TearDown:
+TBD
+
+Create Global Environment hooks:
+TBD
+
+vim: ft=todolist

No commit comments for this range

Something went wrong with that request. Please try again.