Commits

Matt Oswald committed 798700b

xUnitpp::ToString was incorrectly moving some types

Comments (0)

Files changed (4)

Tests/UnitTests/ToString.cpp

+#include "xUnit++/xUnit++.h"
+
+SUITE("ToString")
+{
+
+DATA_THEORY("ToString should not move parameters", (const std::string &s),
+    []() -> std::vector<std::tuple<std::string>>
+    {
+        std::vector<std::tuple<std::string>> data;
+        data.emplace_back("ABCD");
+        return data;
+    })
+{
+    Assert.Equal("ABCD", s);
+}
+
+}

Tests/UnitTests/UnitTests.vcxproj

     <ClCompile Include="TestRunner.cpp" />
     <ClCompile Include="TestsCanOutputAnythingWithToString.cpp" />
     <ClCompile Include="Theory.cpp" />
+    <ClCompile Include="ToString.cpp" />
   </ItemGroup>
   <ItemGroup>
     <ProjectReference Include="..\..\xUnit++\xUnit++.vcxproj">

Tests/UnitTests/UnitTests.vcxproj.filters

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

xUnit++/xUnit++/xUnitToString.h

     struct to_string_impl<true>
     {
         template<typename T>
-        static std::string to_string(T &&t)
+        static std::string to_string(const T &t)
         {
             using fallback::to_string;
             using std::to_string;
 
-            return to_string(std::forward<T>(t));
+            return to_string(t);
         }
     };
 
     using ToStringImpl::fallback::to_string;
     using std::to_string;
 
-    return ToStringImpl::to_string_impl<(sizeof (ToStringImpl::fallback::flag(), to_string(t), ToStringImpl::fallback::flag()) != sizeof(char))>::to_string(std::forward<T>(t));
+    return ToStringImpl::to_string_impl<(sizeof (ToStringImpl::fallback::flag(), to_string(t), ToStringImpl::fallback::flag()) != sizeof(char))>::to_string(t);
 }
 
 template<typename T>
-bool has_to_string(T &&t)
+bool has_to_string(T &&)
 {
-    (void)t;
     return has_to_string<typename std::remove_reference<T>::type>();
 }