Commits

Matt Oswald committed 3b95753

Assert.DoesNotContain tests added

  • Participants
  • Parent commits 50267e8

Comments (0)

Files changed (7)

+Bugs
+----
+Setting max concurrency smaller than the number of tests results in an infinite loop
+
 Visual Studio 2012 notes
 ------------------------
 will need to export a function that reports a list of tests
 unit test the lib - started
 custom xUnitAsserts per assert (revisit unit tests at that point)
 xml output
+support versions of DoesNotContain/Contains that call find_if

File xUnit++/Tests/Assert.DoesNotContain.cpp

+#include <string>
+#include <vector>
+#include "../xUnit++.h"
+
+using xUnitpp::xUnitAssert;
+using xUnitpp::Assert;
+
+SUITE(AssertDoesNotContain)
+{
+
+FACT(DoesNotContainForSequenceSuccess)
+{
+    std::vector<int> v;
+
+    Assert.DoesNotContain(v, 0);
+}
+
+FACT(DoesNotContainForSequenceAssertsOnFailure)
+{
+    std::vector<int> v(1, 0);
+
+    Assert.Throws<xUnitAssert>([&]() { Assert.DoesNotContain(v, 0); });
+}
+
+FACT(DoesNotContainForSequenceAppendsUserMessage)
+{
+    static const std::string msg = "xUnit++";
+    std::vector<int> v(1, 0);
+
+    auto assert = Assert.Throws<xUnitAssert>([&]() { Assert.DoesNotContain(v, 0, msg); });
+
+    Assert.Contains(assert.what(), msg.c_str());
+}
+
+FACT(DoesNotContainForStringSuccess)
+{
+    std::string expected = "abcd";
+
+    Assert.DoesNotContain(expected, "xyz");
+}
+
+FACT(DoesNotContainForStringAssertsOnFailure)
+{
+    std::string expected = "abcd";
+
+    Assert.Throws<xUnitAssert>([&]() { Assert.DoesNotContain(expected, "bc"); });
+}
+
+FACT(DoesNotContainForStringAppendsUserMessage)
+{
+    static const std::string msg = "xUnit++";
+    std::string expected = "abcd";
+
+    auto assert = Assert.Throws<xUnitAssert>([&]() { Assert.DoesNotContain(expected, "ab", msg); });
+
+    Assert.Contains(assert.what(), msg.c_str());
+}
+
+}

File xUnit++/Tests/Assert.Empty.cpp

     }
 }
 
-SUITE(AssertEqual)
+SUITE(AssertEmpty)
 {
 
 FACT(EmptyCallsEmptyForContainerWithConstEmptyMember)

File xUnit++/xUnit++.vcxproj

     <ClCompile Include="main.cpp" />
     <ClCompile Include="TestCollection.cpp" />
     <ClCompile Include="TestDetails.cpp" />
+    <ClCompile Include="Tests\Assert.DoesNotContain.cpp" />
     <ClCompile Include="Tests\Assert.DoesNotThrow.cpp" />
     <ClCompile Include="Tests\Assert.Empty.cpp" />
     <ClCompile Include="Tests\Assert.Equal.cpp" />

File xUnit++/xUnit++.vcxproj.filters

     <ClCompile Include="Tests\Assert.Empty.cpp">
       <Filter>Tests</Filter>
     </ClCompile>
+    <ClCompile Include="Tests\Assert.DoesNotContain.cpp">
+      <Filter>Tests</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="Fact.h" />

File xUnit++/xUnitAssert.cpp

     DoesNotContain(std::string(actualString), std::string(value), msg);
 }
 
+void Assert::DoesNotContain(const std::string &actualString, const char *value, const std::string &msg) const
+{
+    DoesNotContain(actualString, std::string(value), msg);
+}
+
 void Assert::DoesNotContain(const std::string &actualString, const std::string &value, const std::string &msg) const
 {
     auto found = actualString.find(value);

File xUnit++/xUnitAssert.h

 
     void DoesNotContain(const char *actualString, const char *value, const std::string &msg = "") const;
 
+    void DoesNotContain(const std::string &actualString, const char *value, const std::string &msg = "") const;
+
     void DoesNotContain(const std::string &actualString, const std::string &value, const std::string &msg = "") const;
 
     template<typename TSequence, typename T>