Commits

Matt Oswald committed 2d1c41c

IOutput didn't have to be a shared_ptr, just passing a reference around is good enough

Comments (0)

Files changed (8)

Tests/Attributes.cpp

         }
     };
 
-    struct EmptyReporter : xUnitpp::IOutput
+    struct : xUnitpp::IOutput
     {
         virtual void ReportStart(const xUnitpp::TestDetails &, int) override
         {
         virtual void ReportAllTestsComplete(size_t, size_t, size_t, xUnitpp::Duration) override 
         {
         }
-    };
+    } emptyReporter;
 
     xUnitpp::AttributeCollection attributes;
     attributes.insert(std::make_pair("Skip", "Testing skip."));
     xUnitpp::TestCollection collection;
     xUnitpp::TestCollection::Register reg(collection, []() { SkippedTest().RunTest(); }, "SkippedTest", "Attributes", attributes, -1, __FILE__, __LINE__);
 
-    xUnitpp::TestRunner local(std::make_shared<EmptyReporter>());
+    xUnitpp::TestRunner local(emptyReporter);
     local.RunTests([](const xUnitpp::TestDetails &) { return true; },
         collection.Facts(), collection.Theories(), xUnitpp::Duration::zero(), 0);
 }
 struct TheoryFixture
 {
 private:
-    struct EmptyReporter : xUnitpp::IOutput
+    struct : xUnitpp::IOutput
     {
         virtual void ReportStart(const xUnitpp::TestDetails &, int) override
         {
         virtual void ReportAllTestsComplete(size_t, size_t, size_t, xUnitpp::Duration) override 
         {
         }
-    };
+    } emptyReporter;
 
 public:
     TheoryFixture()
-        : localRunner(std::make_shared<EmptyReporter>())
+        : localRunner(emptyReporter)
     {
     }
 

xUnit++.console/main.cpp

                 continue;
             }
 
-            std::shared_ptr<xUnitpp::IOutput> reporter;
-            
-            if (options.xmlOutput.empty())
-            {
-                reporter = std::make_shared<xUnitpp::StdOutReporter>(options.verbose, options.veryVerbose);
-            }
-            else
-            {
-                reporter = std::make_shared<xUnitpp::XmlReporter>(options.xmlOutput);
-            }
-
-            failures += filteredTestRunner(options.timeLimit, reporter,
+            std::unique_ptr<xUnitpp::IOutput> reporter(options.xmlOutput.empty() ?
+                (xUnitpp::IOutput *)new xUnitpp::StdOutReporter(options.verbose, options.veryVerbose) :
+                (xUnitpp::IOutput *)new xUnitpp::XmlReporter(options.xmlOutput));
+            failures += filteredTestRunner(options.timeLimit, *reporter,
                 [&](const xUnitpp::TestDetails &testDetails)
                 {
                     return std::binary_search(activeTestIds.begin(), activeTestIds.end(), testDetails.Id);

xUnit++/ExportApi.h

     typedef void(*EnumerateTestDetails)(EnumerateTestDetailsCallback callback);
 
     typedef std::function<bool(const TestDetails &)> TestFilterCallback;
-    typedef int(*FilteredTestsRunner)(int, std::shared_ptr<IOutput>, TestFilterCallback );
+    typedef int(*FilteredTestsRunner)(int, IOutput &, TestFilterCallback );
 }
 
 #endif

xUnit++/TestCollection.h

 public:
     class Register
     {
-        // !!! someday, Visual Studio will understand variadic macros
+        // !!!VS someday, Visual Studio will understand variadic macros
         // when it does, fix this collection
 
         // !!! should use a macro system to automate this

xUnit++/xUnit++.vcxproj

   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <Lib />
   </ItemDefinitionGroup>
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
   </ItemDefinitionGroup>

xUnit++/xUnitTestRunner.cpp

 namespace
 {
 
-extern "C" __declspec(dllexport) int FilteredTestsRunner(int timeLimit, std::shared_ptr<xUnitpp::IOutput> testReporter, std::function<bool(const xUnitpp::TestDetails &)> filter)
+extern "C" __declspec(dllexport) int FilteredTestsRunner(int timeLimit, xUnitpp::IOutput &testReporter, std::function<bool(const xUnitpp::TestDetails &)> filter)
 {
     return xUnitpp::TestRunner(testReporter)
         .RunTests(filter, xUnitpp::TestCollection::Instance().Facts(), xUnitpp::TestCollection::Instance().Theories(),
 class TestRunner::Impl
 {
 public:
-    Impl(std::shared_ptr<IOutput> testReporter)
+    Impl(IOutput &testReporter)
         : mTestReporter(testReporter)
     {
     }
     void OnTestStart(const TestDetails &details, int dataIndex)
     {
         std::lock_guard<std::mutex> guard(mStartMtx);
-        mTestReporter->ReportStart(details, dataIndex);
+        mTestReporter.ReportStart(details, dataIndex);
     }
 
     void OnTestFailure(const TestDetails &details, int dataIndex, const std::string &message)
     {
         std::lock_guard<std::mutex> guard(mFailureMtx);
-        mTestReporter->ReportFailure(details, dataIndex, message);
+        mTestReporter.ReportFailure(details, dataIndex, message);
     }
 
     void OnTestSkip(const TestDetails &details, const std::string &reason)
     {
-        mTestReporter->ReportSkip(details, reason);
+        mTestReporter.ReportSkip(details, reason);
     }
 
     void OnTestFinish(const TestDetails &details, int dataIndex, xUnitpp::Duration time)
     {
         std::lock_guard<std::mutex> guard(mFinishMtx);
-        mTestReporter->ReportFinish(details, dataIndex, time);
+        mTestReporter.ReportFinish(details, dataIndex, time);
     }
 
 
     void OnAllTestsComplete(int total, int skipped, int failed, xUnitpp::Duration totalTime)
     {
-        mTestReporter->ReportAllTestsComplete(total, skipped, failed, totalTime);
+        mTestReporter.ReportAllTestsComplete(total, skipped, failed, totalTime);
     }
 
 private:
-    std::shared_ptr<IOutput> mTestReporter;
+    Impl(const Impl &);
+    Impl &operator=(Impl);
+
+private:
+    IOutput &mTestReporter;
 
     std::mutex mStartMtx;
     std::mutex mFailureMtx;
     std::mutex mFinishMtx;
 };
 
-TestRunner::TestRunner(std::shared_ptr<IOutput> testReporter)
+TestRunner::TestRunner(IOutput &testReporter)
     : mImpl(new Impl(testReporter))
 {
 }

xUnit++/xUnitTestRunner.h

 class TestRunner
 {
 public:
-    TestRunner(std::shared_ptr<IOutput> testReporter);
+    TestRunner(IOutput &testReporter);
     int RunTests(std::function<bool(const TestDetails &)> filter, const std::vector<Fact> &facts, const std::vector<Theory> &theories,
                  xUnitpp::Duration maxTestRunTime, size_t maxConcurrent);
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.