Commits

Matt Oswald  committed a517b02

Visual Studio version will now handle errors like divide-by-zero without crashing the test runner

  • Participants
  • Parent commits 62104af

Comments (0)

Files changed (4)

File Tests/UnitTests/ErrorHandling.cpp

+#include "xUnit++/xUnit++.h"
+#include "xUnit++/xUnitTestRunner.h"
+#include "Helpers/OutputRecord.h"
+
+SUITE("Error Handling")
+{
+
+#if defined(_MSC_VER)
+FACT("A test that divides by zero should not halt the test runner")
+{
+    auto test = []()
+    {
+        volatile auto z = 0;
+        volatile auto y = 1;
+
+        volatile auto x = y / z;
+        (void)x;
+    };
+
+    xUnitpp::TestCollection collection;
+    std::vector<std::shared_ptr<xUnitpp::TestEventRecorder>> localEventRecorders;
+    localEventRecorders.push_back(std::make_shared<xUnitpp::TestEventRecorder>());
+    localEventRecorders.push_back(std::make_shared<xUnitpp::TestEventRecorder>());
+    localEventRecorders.push_back(std::make_shared<xUnitpp::TestEventRecorder>());
+    xUnitpp::Tests::OutputRecord outputRecord;
+    
+    xUnitpp::TestCollection::Register reg(collection, test, "Name", "Suite", xUnitpp::AttributeCollection(), -1, "file", 0, std::forward<decltype(localEventRecorders)>(localEventRecorders));
+    (void)reg;
+
+    xUnitpp::RunTests(outputRecord, [](const xUnitpp::ITestDetails &) { return true; }, collection.Tests(), xUnitpp::Time::Duration::zero(), 0);
+}
+#endif
+
+}

File Tests/UnitTests/UnitTests.vcxproj

     <ClCompile Include="Assert.Throws.cpp" />
     <ClCompile Include="Assert.True.cpp" />
     <ClCompile Include="Attributes.cpp" />
+    <ClCompile Include="ErrorHandling.cpp" />
     <ClCompile Include="Helpers\OutputRecord.cpp" />
     <ClCompile Include="LineInfo.cpp" />
     <ClCompile Include="TestEvents.cpp" />

File Tests/UnitTests/UnitTests.vcxproj.filters

     <ClCompile Include="TestsCanOutputAnythingWithToString.cpp" />
     <ClCompile Include="TestEvents.cpp" />
     <ClCompile Include="ToString.cpp" />
+    <ClCompile Include="ErrorHandling.cpp" />
   </ItemGroup>
   <ItemGroup>
     <Filter Include="Test Helpers">

File xUnit++/xUnit++.vcxproj

     <ClCompile Include="src\TestCollection.cpp" />
     <ClCompile Include="src\TestDetails.cpp" />
     <ClCompile Include="src\xUnitAssert.cpp" />
-    <ClCompile Include="src\xUnitTest.cpp" />
+    <ClCompile Include="src\xUnitTest.cpp">
+      <ExceptionHandling Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Async</ExceptionHandling>
+      <ExceptionHandling Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Async</ExceptionHandling>
+    </ClCompile>
     <ClCompile Include="src\xUnitTestRunner.cpp" />
     <ClCompile Include="src\TestEventRecorder.cpp" />
     <ClCompile Include="src\xUnitCheck.cpp" />