Commits

Matt Oswald committed f95fd1e

half-assing the implementation of the Assert members (half-assing because I'm not testing the results yet)

Comments (0)

Files changed (1)

         }
     }
 
-    // DoesNotThrow
-    // Throws
-    // Fail
-    // False
-    // True
-    // Empty
-    // NotEmpty
-    // Contains
-    // DoesNotContain
+    template<typename TFunc>
+    void DoesNotThrow(TFunc &&fn)
+    {
+        try
+        {
+            fn();
+        }
+        catch (std::exception &e)
+        {
+            throw xUnitAssert(std::string("Caught std::exception with message: ") + e.what());
+        }
+        catch (...)
+        {
+            throw xUnitAssert(std::string("Caught unknown exception (crash) with message: ") + e.what());
+        }
+    }
 
+    template<typename TException, typename TFunc>
+    TException Throws(TFunc &&fn)
+    {
+        try
+        {
+            fn();
+        }
+        catch (TException e)
+        {
+            return e;
+        }
+        catch (std::exception &e)
+        {
+            throw xUnitAssert(std::string("Caught std::exception with message: ") + e.what());
+        }
+        catch (...)
+        {
+            throw xUnitAssert(std::string("Caught unknown exception (crash) with message: ") + e.what());
+        }
 
+        throw xUnitAssert(std::string("Did not catch any exceptions."));
+    }
+
+    void Fail()
+    {
+        throw xUnitAssert("Fail.");
+    }
+
+    void False(bool b)
+    {
+        if (b)
+        {
+            throw xUnitAssert("Expected false.");
+        }
+    }
+
+    void True(bool b)
+    {
+        if (!b)
+        {
+            throw xUnitAssert("Expected true.");
+        }
+    }
+
+    template<typename TContainer>
+    void Empty(TContainer container)
+    {
+        if (!container.empty())
+        {
+            throw xUnitAssert("Container is not empty.");
+        }
+    }
+
+    template<typename TContainer>
+    void NotEmpty(TContainer container)
+    {
+        if (container.empty())
+        {
+            throw xUnitAssert("Container is empty.");
+        }
+    }
+
+    template<typename TContainer, typename TItem>
+    void DoesNotContain(TContainer container, TItem item)
+    {
+        if (std::find(container.begin(), container.end(), item))
+        {
+            throw xUnitAssert("Container contains item.");
+        }
+    }
+
+    template<typename TContainer, typename TItem>
+    void Contains(TContainer container, TItem item)
+    {
+        if (!std::find(container.begin(), container.end(), item))
+        {
+            throw xUnitAssert("Container does not contain item.");
+        }
+    }
 } Assert;
 
 FACT(SuccessfulFact)
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.