Commits

Matt Oswald committed d48ca5a

separated theory params from the theory's full name

Comments (0)

Files changed (12)

       <WarningLevel>Level4</WarningLevel>
       <MultiProcessorCompilation>true</MultiProcessorCompilation>
       <MinimalRebuild>false</MinimalRebuild>
-      <PreprocessorDefinitions>WIN32;_VARIADIC_MAX=9</PreprocessorDefinitions>
+      <PreprocessorDefinitions>WIN32;_VARIADIC_MAX=10</PreprocessorDefinitions>
     </ClCompile>
     <Link>
       <GenerateDebugInformation>true</GenerateDebugInformation>

Tests/UnitTests/TestRunner.cpp

 
     operator std::shared_ptr<xUnitTest>()
     {
-        return std::make_shared<xUnitTest>(std::move(testFn), std::move(name), std::move(name), suite, std::move(attributes), timeLimit, std::move(file), line, testEventRecorders);
+        return std::make_shared<xUnitTest>(std::move(testFn), std::string(name), 0, "", suite, std::move(attributes), timeLimit, std::move(file), line, testEventRecorders);
     }
 
 private:

Tests/UnitTests/Theory.cpp

     {
         auto test = std::get<0>(t);
 
-        Assert.Equal("TheoryName", test.ShortName);
+        Assert.Equal("TheoryName", test.Name);
     }
 }
 
 {
     for (const auto &test : xUnitpp::TestCollection::Instance().Tests())
     {
-        if (test->TestDetails().ShortName == "TheoriesCanHaveAttributes")
+        if (test->TestDetails().Name == "TheoriesCanHaveAttributes")
         {
             auto it = std::find_if(test->TestDetails().Attributes.begin(), test->TestDetails().Attributes.end(), [](const std::pair<std::string, std::string> &item) { return item.first == "Cats"; });
             Assert.True(it != test->TestDetails().Attributes.end());

xUnit++.VsRunner/xUnit++.VsRunner.cpp

 
         void ReportStart(const xUnitpp::TestDetails &td)
         {
-            auto key = marshal_as<String ^>(td.Name);
-            auto name = marshal_as<String ^>(td.ShortName);
+            auto key = marshal_as<String ^>(td.FullName());
+            auto name = marshal_as<String ^>(td.Name);
             recorder->RecordStart(testCases[name]);
 
             auto result = gcnew TestResult(testCases[name]);
 
         void ReportSkip(const xUnitpp::TestDetails &td, const std::string &)
         {
-            auto testCase = testCases[marshal_as<String ^>(td.ShortName)];
+            auto testCase = testCases[marshal_as<String ^>(td.FullName())];
             auto result = gcnew TestResult(testCase);
             result->ComputerName = Environment::MachineName;
-            result->DisplayName = marshal_as<String ^>(td.ShortName);
+            result->DisplayName = marshal_as<String ^>(td.Name);
             result->Duration = TimeSpan::FromSeconds(0);
             result->Outcome = TestOutcome::Skipped;
             recorder->RecordEnd(testCase, result->Outcome);
                 result->Outcome = TestOutcome::Passed;
             }
 
-            recorder->RecordEnd(testCases[marshal_as<String ^>(td.ShortName)], result->Outcome);
+            recorder->RecordEnd(testCases[marshal_as<String ^>(td.FullName())], result->Outcome);
             recorder->RecordResult(result);
         }
 
                     return !cancelled && std::find_if(tests.begin(), tests.end(),
                         [&](gcroot<TestCase ^> test)
                         {
-                            return marshal_as<std::string>(test->DisplayName) == testDetails.ShortName;
+                            return marshal_as<std::string>(test->DisplayName) == testDetails.Name;
                         }) != tests.end();
                 });
         }
             auto dict = gcroot<Dictionary<String ^, TestCase ^> ^>(result);
             assembly.EnumerateTestDetails([&](const xUnitpp::TestDetails &td)
                 {
-                    if (!dict->ContainsKey(marshal_as<String ^>(td.ShortName)))
+                    if (!dict->ContainsKey(marshal_as<String ^>(td.Name)))
                     {
-                        TestCase ^testCase = gcnew TestCase(marshal_as<String ^>(td.ShortName), uri, marshal_as<String ^>(source));
-                        testCase->DisplayName = marshal_as<String ^>(td.ShortName);
+                        TestCase ^testCase = gcnew TestCase(marshal_as<String ^>(td.Name), uri, marshal_as<String ^>(source));
+                        testCase->DisplayName = marshal_as<String ^>(td.Name);
                         testCase->CodeFilePath = marshal_as<String ^>(td.LineInfo.file);
                         testCase->LineNumber = td.LineInfo.line;
 
-                        dict->Add(marshal_as<String ^>(td.ShortName), testCase);
+                        dict->Add(marshal_as<String ^>(td.FullName()), testCase);
                     }
                 });
         }

xUnit++.console/ConsoleReporter.cpp

                     }
                 }
 
-                std::cout << Fragment(Color::TestName, testDetails.Name + "\n");
+                std::cout << Fragment(Color::TestName, testDetails.FullName() + "\n");
             }
 
             if (!fragments.empty())
                 Instant(Color::Separator, TestSeparator);
             }
 
-            Instant(Color::TestName, testDetails.ShortName + "\n");
+            Instant(Color::TestName, testDetails.Name + "\n");
             Instant(Color::FileAndLine, to_string(testDetails.LineInfo) + ": ");
             Instant(Color::Skip, reason);
             Instant(Color::Default, "\n");

xUnit++.console/main.cpp

                     {
                         std::regex regex(name, std::regex_constants::icase);
 
-                        if (std::regex_search(td.ShortName, regex))
+                        if (std::regex_search(td.Name, regex))
                         {
                             included = true;
                             break;

xUnit++/src/TestCollection.cpp

 TestCollection::Register::Register(TestCollection &collection, std::function<void()> &&fn, std::string &&name, const std::string &suite,
             AttributeCollection &&attributes, int milliseconds, std::string &&filename, int line, std::vector<std::shared_ptr<TestEventRecorder>> &&testEventRecorders)
 {
-    auto shortName = name;
-    collection.mTests.push_back(std::make_shared<xUnitTest>(std::move(fn), std::move(shortName), std::move(name), suite, std::move(attributes), Time::ToDuration(Time::ToMilliseconds(milliseconds)), std::move(filename), line, std::move(testEventRecorders)));
+    collection.mTests.push_back(std::make_shared<xUnitTest>(std::move(fn), std::move(name), 0, "", suite, std::move(attributes), Time::ToDuration(Time::ToMilliseconds(milliseconds)), std::move(filename), line, std::move(testEventRecorders)));
 }
 
 const std::vector<std::shared_ptr<xUnitTest>> &TestCollection::Tests()

xUnit++/src/TestDetails.cpp

 {
 }
 
-TestDetails::TestDetails(std::string &&name, std::string &&shortName, const std::string &suite, AttributeCollection &&attributes,
+TestDetails::TestDetails(std::string &&name, int testInstance, std::string &&params, const std::string &suite, AttributeCollection &&attributes,
                          Time::Duration timeLimit, std::string &&filename, int line)
     : Id(NextId())
+    , TestInstance(testInstance)
     , Name(std::move(name))
-    , ShortName(std::move(shortName))
+    , Params(std::move(params))
     , Suite(suite)
     , Attributes(std::move(attributes))
     , TimeLimit(timeLimit)
 
 TestDetails::TestDetails(const TestDetails &other)
     : Id(other.Id)
+    , TestInstance(other.TestInstance)
     , Name(other.Name)
-    , ShortName(other.ShortName)
+    , Params(other.Params)
     , Suite(other.Suite)
     , Attributes(other.Attributes)
     , TimeLimit(other.TimeLimit)
     using std::swap;
 
     swap(td0.Id, td1.Id);
+    swap(td0.TestInstance, td1.TestInstance);
     swap(td0.Name, td1.Name);
-    swap(td0.ShortName, td1.ShortName);
+    swap(td0.Params, td1.Params);
     swap(td0.Suite, td1.Suite);
     swap(td0.Attributes, td1.Attributes);
     swap(td0.TimeLimit, td1.TimeLimit);
     swap(td0.LineInfo, td1.LineInfo);
 }
 
+std::string TestDetails::FullName() const
+{
+    if (Params.empty())
+    {
+        return Name;
+    }
+
+    return Name + "[" + std::to_string(TestInstance) + "]" + Params;
 }
+
+}

xUnit++/src/xUnitTest.cpp

 namespace xUnitpp
 {
 
-xUnitTest::xUnitTest(std::function<void()> &&test, std::string &&name, std::string &&shortName, const std::string &suite,
-                     AttributeCollection &&attributes, Time::Duration timeLimit,
+xUnitTest::xUnitTest(std::function<void()> &&test, std::string &&name, int testInstance, std::string &&params,
+                     const std::string &suite, AttributeCollection &&attributes, Time::Duration timeLimit,
                      std::string &&filename, int line, const std::vector<std::shared_ptr<TestEventRecorder>> &testEventRecorders)
     : test(std::move(test))
-    , testDetails(std::move(name), std::move(shortName), suite, std::move(attributes), timeLimit, std::move(filename), line)
+    , testDetails(std::move(name), testInstance, std::move(params), suite, std::move(attributes), timeLimit, std::move(filename), line)
     , testEventRecorders(testEventRecorders)
     , failureEventLogged(false)
 {

xUnit++/xUnit++/TestCollection.h

 
         // !!!VS something else that can be simplified once VS understands variadic macros...
         template<typename TArg0>
-        std::string GetLongTheoryName(std::string name, const std::deque<std::string> &params, std::tuple<TArg0> &&t) const
+        std::string GetTheoryParams(const std::deque<std::string> &params, std::tuple<TArg0> &&t) const
         {
-            name += params[0] + ": " + ToString(std::get<0>(std::forward<std::tuple<TArg0>>(t))) + ")";
-
-            return name;
+            return "(" + params[0] + ": " + ToString(std::get<0>(std::forward<std::tuple<TArg0>>(t))) + ")";
         }
 
         template<typename TArg0, typename TArg1>
-        std::string GetLongTheoryName(std::string name, const std::deque<std::string> &params, std::tuple<TArg0, TArg1> &&t) const
+        std::string GetTheoryParams(const std::deque<std::string> &params, std::tuple<TArg0, TArg1> &&t) const
         {
-            name += params[0] + ": " + ToString(std::get<0>(std::forward<std::tuple<TArg0, TArg1>>(t))) + ", ";
-            name += params[1] + ": " + ToString(std::get<1>(std::forward<std::tuple<TArg0, TArg1>>(t))) + ")";
-
-            return name;
+            return "(" + params[0] + ": " + ToString(std::get<0>(std::forward<std::tuple<TArg0, TArg1>>(t))) + ", " +
+                params[1] + ": " + ToString(std::get<1>(std::forward<std::tuple<TArg0, TArg1>>(t))) + ")";
         }
 
         template<typename TArg0, typename TArg1, typename TArg2>
-        std::string GetLongTheoryName(std::string name, const std::deque<std::string> &params, std::tuple<TArg0, TArg1, TArg2> &&t) const
+        std::string GetTheoryParams(const std::deque<std::string> &params, std::tuple<TArg0, TArg1, TArg2> &&t) const
         {
-            name += params[0] + ": " + ToString(std::get<0>(std::forward<std::tuple<TArg0, TArg1, TArg2>>(t))) + ", ";
-            name += params[1] + ": " + ToString(std::get<1>(std::forward<std::tuple<TArg0, TArg1, TArg2>>(t))) + ", ";
-            name += params[2] + ": " + ToString(std::get<2>(std::forward<std::tuple<TArg0, TArg1, TArg2>>(t))) + ")";
-
-            return name;
+            return "(" + params[0] + ": " + ToString(std::get<0>(std::forward<std::tuple<TArg0, TArg1, TArg2>>(t))) + ", " +
+                params[1] + ": " + ToString(std::get<1>(std::forward<std::tuple<TArg0, TArg1, TArg2>>(t))) + ", " +
+                params[2] + ": " + ToString(std::get<2>(std::forward<std::tuple<TArg0, TArg1, TArg2>>(t))) + ")";
         }
 
         template<typename TArg0, typename TArg1, typename TArg2, typename TArg3>
-        std::string GetLongTheoryName(std::string name, const std::deque<std::string> &params, std::tuple<TArg0, TArg1, TArg2, TArg3> &&t) const
+        std::string GetTheoryParams(const std::deque<std::string> &params, std::tuple<TArg0, TArg1, TArg2, TArg3> &&t) const
         {
-            name += params[0] + ": " + ToString(std::get<0>(std::forward<std::tuple<TArg0, TArg1, TArg2, TArg3>>(t))) + ", ";
-            name += params[1] + ": " + ToString(std::get<1>(std::forward<std::tuple<TArg0, TArg1, TArg2, TArg3>>(t))) + ", ";
-            name += params[2] + ": " + ToString(std::get<2>(std::forward<std::tuple<TArg0, TArg1, TArg2, TArg3>>(t))) + ", ";
-            name += params[3] + ": " + ToString(std::get<3>(std::forward<std::tuple<TArg0, TArg1, TArg2, TArg3>>(t))) + ")";
-
-            return name;
+            return "(" + params[0] + ": " + ToString(std::get<0>(std::forward<std::tuple<TArg0, TArg1, TArg2, TArg3>>(t))) + ", " +
+                params[1] + ": " + ToString(std::get<1>(std::forward<std::tuple<TArg0, TArg1, TArg2, TArg3>>(t))) + ", " +
+                params[2] + ": " + ToString(std::get<2>(std::forward<std::tuple<TArg0, TArg1, TArg2, TArg3>>(t))) + ", " +
+                params[3] + ": " + ToString(std::get<3>(std::forward<std::tuple<TArg0, TArg1, TArg2, TArg3>>(t))) + ")";
         }
 
         template<typename TArg0, typename TArg1, typename TArg2, typename TArg3, typename TArg4>
-        std::string GetLongTheoryName(std::string name, const std::deque<std::string> &params, std::tuple<TArg0, TArg1, TArg2, TArg3, TArg4> &&t) const
+        std::string GetTheoryParams(const std::deque<std::string> &params, std::tuple<TArg0, TArg1, TArg2, TArg3, TArg4> &&t) const
         {
-            name += params[0] + ": " + ToString(std::get<0>(std::forward<std::tuple<TArg0, TArg1, TArg2, TArg3, TArg4>>(t))) + ", ";
-            name += params[1] + ": " + ToString(std::get<1>(std::forward<std::tuple<TArg0, TArg1, TArg2, TArg3, TArg4>>(t))) + ", ";
-            name += params[2] + ": " + ToString(std::get<2>(std::forward<std::tuple<TArg0, TArg1, TArg2, TArg3, TArg4>>(t))) + ", ";
-            name += params[3] + ": " + ToString(std::get<3>(std::forward<std::tuple<TArg0, TArg1, TArg2, TArg3, TArg4>>(t))) + ", ";
-            name += params[4] + ": " + ToString(std::get<4>(std::forward<std::tuple<TArg0, TArg1, TArg2, TArg3, TArg4>>(t))) + ")";
-
-            return name;
+            return "(" + params[0] + ": " + ToString(std::get<0>(std::forward<std::tuple<TArg0, TArg1, TArg2, TArg3, TArg4>>(t))) + ", " +
+                params[1] + ": " + ToString(std::get<1>(std::forward<std::tuple<TArg0, TArg1, TArg2, TArg3, TArg4>>(t))) + ", " +
+                params[2] + ": " + ToString(std::get<2>(std::forward<std::tuple<TArg0, TArg1, TArg2, TArg3, TArg4>>(t))) + ", " +
+                params[3] + ": " + ToString(std::get<3>(std::forward<std::tuple<TArg0, TArg1, TArg2, TArg3, TArg4>>(t))) + ", " +
+                params[4] + ": " + ToString(std::get<4>(std::forward<std::tuple<TArg0, TArg1, TArg2, TArg3, TArg4>>(t))) + ")";
         }
 
     public:
             int id = 0;
             for (auto t : theoryData())
             {
-                auto theoryName = GetLongTheoryName(name + " [" + ToString(id++) + "] (", SplitParams(std::move(params)), std::forward<decltype(t)>(t));
+                auto fullParams = GetTheoryParams(SplitParams(std::move(params)), std::forward<decltype(t)>(t));
 
-                collection.mTests.push_back(std::make_shared<xUnitTest>(TheoryHelper(std::forward<TTheory>(theory), std::move(t)), std::string(theoryName), std::string(name), suite,
-                    AttributeCollection(attributes), Time::ToDuration(Time::ToMilliseconds(milliseconds)), std::string(filename), line, testEventRecorders));
+                collection.mTests.push_back(
+                    std::make_shared<xUnitTest>(
+                        TheoryHelper(std::forward<TTheory>(theory), std::move(t)),
+                        std::string(name),
+                        id++,
+                        std::move(fullParams),
+                        suite,
+                        AttributeCollection(attributes),
+                        Time::ToDuration(Time::ToMilliseconds(milliseconds)),
+                        std::string(filename),
+                        line,
+                        testEventRecorders)
+                    );
             }
         }
     };

xUnit++/xUnit++/TestDetails.h

 struct TestDetails
 {
     TestDetails();
-    TestDetails(std::string &&name, std::string &&shortName, const std::string &suite,
+    TestDetails(std::string &&name, int testInstance, std::string &&params, const std::string &suite,
         AttributeCollection &&attributes, Time::Duration timeLimit,
         std::string &&filename, int line);
     TestDetails(const TestDetails &other);
     TestDetails &operator =(TestDetails other);
     friend void swap(TestDetails &td0, TestDetails &td1);
 
+    std::string FullName() const;
+
     int Id;
+    int TestInstance;
     std::string Name;
-    std::string ShortName;
+    std::string Params;
     std::string Suite;
     AttributeCollection Attributes;
     Time::Duration TimeLimit;

xUnit++/xUnit++/xUnitTest.h

 class xUnitTest
 {
 public:
-    xUnitTest(std::function<void()> &&test, std::string &&name, std::string &&shortName,
+    xUnitTest(std::function<void()> &&test, std::string &&name, int testInstance, std::string &&params,
         const std::string &suite, AttributeCollection &&attributes, Time::Duration timeLimit,
         std::string &&filename, int line, const std::vector<std::shared_ptr<TestEventRecorder>> &testEventRecorders);