Commits

Matt Oswald committed 2b424de

fixed VS IDE test runner to run theories

Comments (0)

Files changed (6)

 {
     for (const auto &test : xUnitpp::TestCollection::Instance().Tests())
     {
-        if (test.TestDetails().Name == "TheoriesCanHaveAttributes")
+        if (test.TestDetails().ShortName == "TheoriesCanHaveAttributes")
         {
             auto it = test.TestDetails().Attributes.find("Cats");
             Assert.True(it != test.TestDetails().Attributes.end());
 ------------------------
 create vsix for test runners
 need msbuild test runner
-EnumerateAllTests needs to include individual theory instances
-    - maybe refactor TestCollection to contain just "facts" consisting of Facts and each Theory instance?
+
 
 General
 -------

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

         {
             for (auto &test : testCases)
             {
-                this->testCases.Add(test->FullyQualifiedName, test);
+                if (!this->testCases.ContainsKey(test->DisplayName))
+                this->testCases.Add(test->DisplayName, test);
             }
         }
 
         void ReportStart(const xUnitpp::TestDetails &td)
         {
-            auto name = marshal_as<String ^>(td.Name);
+            auto key = marshal_as<String ^>(td.Name);
+            auto name = marshal_as<String ^>(td.ShortName);
             recorder->RecordStart(testCases[name]);
 
             auto result = gcnew TestResult(testCases[name]);
             result->DisplayName = name;
             result->Outcome = TestOutcome::None;
 
-            testResults.Add(name, result);
+            testResults.Add(key, result);
         }
 
         void ReportFailure(const xUnitpp::TestDetails &td, const std::string &msg, const xUnitpp::LineInfo &)
 
         void ReportSkip(const xUnitpp::TestDetails &td, const std::string &)
         {
-            auto testCase = testCases[marshal_as<String ^>(td.Name)];
+            auto testCase = testCases[marshal_as<String ^>(td.ShortName)];
             auto result = gcnew TestResult(testCase);
             result->ComputerName = Environment::MachineName;
-            result->DisplayName = marshal_as<String ^>(td.Name);
+            result->DisplayName = marshal_as<String ^>(td.ShortName);
             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.Name)], result->Outcome);
+            recorder->RecordEnd(testCases[marshal_as<String ^>(td.ShortName)], 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.Name;
+                            return marshal_as<std::string>(test->DisplayName) == testDetails.ShortName;
                         }) != tests.end();
                 });
         }
         std::vector<gcroot<TestCase ^>> tests;
     };
 
-    IEnumerable<TestCase ^> ^SingleSourceTestCases(String ^source, Uri ^_uri)
+    IEnumerable<TestCase ^> ^SingleSourceTestCases(String ^_source, Uri ^_uri)
     {
-        auto result = gcnew List<TestCase ^>();
+        auto result = gcnew Dictionary<String ^, TestCase ^>();
 
-        auto name = marshal_as<std::string>(source);
-        if (auto assembly = TestAssembly(name))
+        auto source = marshal_as<std::string>(_source);
+        if (auto assembly = TestAssembly(source))
         {
             auto uri = gcroot<Uri ^>(_uri);
-            auto list = gcroot<List<TestCase ^> ^>(result);
+            auto dict = gcroot<Dictionary<String ^, TestCase ^> ^>(result);
             assembly.EnumerateTestDetails([&](const xUnitpp::TestDetails &td)
                 {
-                    TestCase ^testCase = gcnew TestCase(marshal_as<String ^>(td.Name.c_str()), uri, marshal_as<String ^>(name));
-                    testCase->CodeFilePath = marshal_as<String ^>(td.Filename);
-                    testCase->DisplayName = marshal_as<String ^>(td.Name);
-                    testCase->LineNumber = td.Line;
+                    if (!dict->ContainsKey(marshal_as<String ^>(td.ShortName)))
+                    {
+                        TestCase ^testCase = gcnew TestCase(marshal_as<String ^>(td.ShortName), uri, marshal_as<String ^>(source));
+                        testCase->DisplayName = marshal_as<String ^>(td.ShortName);
+                        testCase->CodeFilePath = marshal_as<String ^>(td.Filename);
+                        testCase->LineNumber = td.Line;
 
-                    list->Add(testCase);
+                        dict->Add(marshal_as<String ^>(td.ShortName), testCase);
+                    }
                 });
         }
 
-        return result;
+        return result->Values;
     }
 }
 

xUnit++.console/main.cpp

         }
     }
 
-    int failures = 0;
+    int totalFailures = 0;
 
     for (const auto &lib : options.libraries)
     {
                 onList(td);
             });
 
-        if (!options.list)
+        if (!activeTestIds.empty())
         {
             std::sort(activeTestIds.begin(), activeTestIds.end());
 
             std::unique_ptr<xUnitpp::IOutput> reporter(options.xmlOutput.empty() ?
                 (xUnitpp::IOutput *)new xUnitpp::StdOutReporter(options.verbose, options.veryVerbose) :
                 (xUnitpp::IOutput *)new xUnitpp::XmlReporter(options.xmlOutput));
-            failures += filteredTestRunner(options.timeLimit, *reporter,
+            totalFailures += filteredTestRunner(options.timeLimit, *reporter,
                 [&](const xUnitpp::TestDetails &testDetails)
                 {
                     return std::binary_search(activeTestIds.begin(), activeTestIds.end(), testDetails.Id);
         }
     }
 
-    return failures;
+    return totalFailures;
 }

xUnit++/TestDetails.cpp

         static int id = 0;
         return id++;
     }
+
+    std::string shorten(const std::string &name)
+    {
+        auto idx = name.rfind('(');
+        if (idx == std::string::npos)
+        {
+            return name;
+        }
+
+        return name.substr(0, idx);
+    }
 }
 
 namespace xUnitpp
                          Time::Duration timeLimit, const std::string &filename, int line)
     : Id(NextId())
     , Name(name)
+    , ShortName(shorten(name))
     , Suite(suite)
     , Attributes(attributes)
     , TimeLimit(timeLimit)
 TestDetails::TestDetails(const TestDetails &other)
     : Id(other.Id)
     , Name(other.Name)
+    , ShortName(other.ShortName)
     , Suite(other.Suite)
     , Attributes(other.Attributes)
     , TimeLimit(other.TimeLimit)
 
     swap(td0.Id, td1.Id);
     swap(td0.Name, td1.Name);
+    swap(td0.ShortName, td1.ShortName);
     swap(td0.Suite, td1.Suite);
     swap(td0.Attributes, td1.Attributes);
     swap(td0.TimeLimit, td1.TimeLimit);

xUnit++/TestDetails.h

 
     int Id;
     std::string Name;
+    std::string ShortName;
     std::string Suite;
     AttributeCollection Attributes;
     Time::Duration TimeLimit;