Ejemplo n.º 1
0
        public IList <TestCase> CreateTestCases()
        {
            var           launcher = new ProcessLauncher(_testEnvironment, _testEnvironment.Options.GetPathExtension(_executable));
            int           processReturnCode;
            List <string> consoleOutput = launcher.GetOutputOfCommand("", _executable, GoogleTestConstants.ListTestsOption.Trim(), false, false, out processReturnCode);

            if (processReturnCode != 0)
            {
                string messsage =
                    $"Could not list test cases of executable '{_executable}': executing process failed with return code {processReturnCode}";
                messsage += $"\nCommand executed: '{_executable} {GoogleTestConstants.ListTestsOption.Trim()}', working directory: '{Path.GetDirectoryName(_executable)}'";
                if (consoleOutput.Count(s => !string.IsNullOrEmpty(s)) > 0)
                {
                    messsage += $"\nOutput of command:\n{string.Join("\n", consoleOutput)}";
                }
                else
                {
                    messsage += "\nCommand produced no output";
                }

                _testEnvironment.LogWarning(messsage);

                return(new List <TestCase>());
            }

            IList <TestCaseDescriptor> testCaseDescriptors = new ListTestsParser(_testEnvironment).ParseListTestsOutput(consoleOutput);

            if (_testEnvironment.Options.ParseSymbolInformation)
            {
                List <TestCaseLocation> testCaseLocations = GetTestCaseLocations(testCaseDescriptors, _testEnvironment.Options.GetPathExtension(_executable));
                return(testCaseDescriptors.Select(descriptor => CreateTestCase(descriptor, testCaseLocations)).ToList());
            }

            return(testCaseDescriptors.Select(CreateTestCase).ToList());
        }
Ejemplo n.º 2
0
        private IEnumerable <string> GetTypedTestMethodSignatures(TestCaseDescriptor descriptor)
        {
            var result = new List <string>();

            // remove instance number
            string suite = descriptor.Suite.Substring(0, descriptor.Suite.LastIndexOf("/", StringComparison.Ordinal));

            // remove prefix
            if (suite.Contains("/"))
            {
                int index = suite.IndexOf("/", StringComparison.Ordinal);
                suite = suite.Substring(index + 1, suite.Length - index - 1);
            }

            string typeParam = ListTestsParser.GetEnclosedTypeParam(descriptor.TypeParam);

            // <testcase name>_<test name>_Test<type param value>::TestBody
            result.Add(GetTestMethodSignature(suite, descriptor.Name, typeParam));

            // gtest_case_<testcase name>_::<test name><type param value>::TestBody
            string signature =
                $"gtest_case_{suite}_::{descriptor.Name}{typeParam}{GoogleTestConstants.TestBodySignature}";

            result.Add(signature);

            return(result);
        }
        public IList<TestCase> CreateTestCases()
        {
            var launcher = new ProcessLauncher(_testEnvironment, _testEnvironment.Options.GetPathExtension(_executable));
            int processReturnCode;
            List<string> consoleOutput = launcher.GetOutputOfCommand("", _executable, GoogleTestConstants.ListTestsOption.Trim(), false, false, out processReturnCode);
            if (processReturnCode != 0)
            {
                string messsage =
                    $"Could not list test cases of executable '{_executable}': executing process failed with return code {processReturnCode}";
                messsage += $"\nCommand executed: '{_executable} {GoogleTestConstants.ListTestsOption.Trim()}', working directory: '{Path.GetDirectoryName(_executable)}'";
                if (consoleOutput.Count(s => !string.IsNullOrEmpty(s)) > 0)
                    messsage += $"\nOutput of command:\n{string.Join("\n", consoleOutput)}";
                else
                    messsage += "\nCommand produced no output";

                _testEnvironment.LogWarning(messsage);

                return new List<TestCase>();
            }

            IList<TestCaseDescriptor> testCaseDescriptors = new ListTestsParser(_testEnvironment).ParseListTestsOutput(consoleOutput);
            if (_testEnvironment.Options.ParseSymbolInformation)
            {
                List<TestCaseLocation> testCaseLocations = GetTestCaseLocations(testCaseDescriptors, _testEnvironment.Options.GetPathExtension(_executable));
                return testCaseDescriptors.Select(descriptor => CreateTestCase(descriptor, testCaseLocations)).ToList();
            }

            return testCaseDescriptors.Select(CreateTestCase).ToList();
        }
Ejemplo n.º 4
0
        public IList <TestCase> CreateTestCases(Action <TestCase> reportTestCase = null)
        {
            List <string> standardOutput = new List <string>();

            if (_settings.UseNewTestExecutionFramework)
            {
                return(NewCreateTestcases(reportTestCase, standardOutput));
            }

            try
            {
                var    launcher = new ProcessLauncher(_logger, _settings.GetPathExtension(_executable), null);
                int    processExitCode;
                string workingDir = new FileInfo(_executable).DirectoryName;
                standardOutput = launcher.GetOutputOfCommand(workingDir, null, _executable, GoogleTestConstants.ListTestsOption,
                                                             false, false, out processExitCode);

                if (!CheckProcessExitCode(processExitCode, standardOutput))
                {
                    return(new List <TestCase>());
                }
            }
            catch (Exception e)
            {
                SequentialTestRunner.LogExecutionError(_logger, _executable, Path.GetFullPath(""),
                                                       GoogleTestConstants.ListTestsOption, e);
                return(new List <TestCase>());
            }

            IList <TestCaseDescriptor> testCaseDescriptors = new ListTestsParser(_settings.TestNameSeparator).ParseListTestsOutput(standardOutput);
            var testCaseLocations = GetTestCaseLocations(testCaseDescriptors, _settings.GetPathExtension(_executable));

            IList <TestCase> testCases = new List <TestCase>();
            IDictionary <string, ISet <TestCase> > suite2TestCases = new Dictionary <string, ISet <TestCase> >();

            foreach (var descriptor in testCaseDescriptors)
            {
                var testCase = _settings.ParseSymbolInformation
                    ? CreateTestCase(descriptor, testCaseLocations)
                    : CreateTestCase(descriptor);
                ISet <TestCase> testCasesInSuite;
                if (!suite2TestCases.TryGetValue(descriptor.Suite, out testCasesInSuite))
                {
                    suite2TestCases.Add(descriptor.Suite, testCasesInSuite = new HashSet <TestCase>());
                }
                testCasesInSuite.Add(testCase);
                testCases.Add(testCase);
            }

            foreach (var suiteTestCasesPair in suite2TestCases)
            {
                foreach (var testCase in suiteTestCasesPair.Value)
                {
                    testCase.Properties.Add(new TestCaseMetaDataProperty(suiteTestCasesPair.Value.Count, testCases.Count));
                }
            }

            return(testCases);
        }
Ejemplo n.º 5
0
        public IList <TestCase> CreateTestCases()
        {
            var           launcher      = new ProcessLauncher(TestEnvironment, TestEnvironment.Options.PathExtension);
            List <string> consoleOutput = launcher.GetOutputOfCommand("", Executable, GoogleTestConstants.ListTestsOption.Trim(), false, false);
            IList <TestCaseDescriptor> testCaseDescriptors = new ListTestsParser(TestEnvironment).ParseListTestsOutput(consoleOutput);
            List <TestCaseLocation>    testCaseLocations   = GetTestCaseLocations(testCaseDescriptors, TestEnvironment.Options.PathExtension);

            return(testCaseDescriptors.Select(descriptor => CreateTestCase(descriptor, testCaseLocations)).ToList());
        }
        public void ParseListTestsOutput_TestWithTypeParam_CorrectParsing()
        {
            var consoleOutput = new List<string>
            {
                "TypedTests/0.  # TypeParam = class std::vector<int,class std::allocator<int> >",
                "  CanIterate",
            };

            IList<TestCaseDescriptor> descriptors = new ListTestsParser(TestEnvironment)
                .ParseListTestsOutput(consoleOutput);

            descriptors.Count.Should().Be(1);
            descriptors[0].Suite.Should().Be("TypedTests/0");
            descriptors[0].Name.Should().Be("CanIterate");
            descriptors[0].FullyQualifiedName.Should().Be("TypedTests/0.CanIterate");
            descriptors[0].DisplayName.Should().Be("TypedTests/0.CanIterate<std::vector<int,std::allocator<int> > >");
            descriptors[0].TestType.Should().Be(TestCaseDescriptor.TestTypes.TypeParameterized);
        }
        public void ParseListTestsOutput_TestWithParam_CorrectParsing()
        {
            var consoleOutput = new List<string>
            {
                "InstantiationName/ParameterizedTests.",
                "  Simple/0  # GetParam() = (1,)",
            };

            IList<TestCaseDescriptor> descriptors = new ListTestsParser(TestEnvironment)
                .ParseListTestsOutput(consoleOutput);

            descriptors.Count.Should().Be(1);
            descriptors[0].Suite.Should().Be("InstantiationName/ParameterizedTests");
            descriptors[0].Name.Should().Be("Simple/0");
            descriptors[0].FullyQualifiedName.Should().Be("InstantiationName/ParameterizedTests.Simple/0");
            descriptors[0].DisplayName.Should().Be("InstantiationName/ParameterizedTests.Simple/0 [(1,)]");
            descriptors[0].TestType.Should().Be(TestCaseDescriptor.TestTypes.Parameterized);
        }
Ejemplo n.º 8
0
        public void ParseListTestsOutput_TestWithTypeParamAndPrefixOldFormat_CorrectParsing()
        {
            var consoleOutput = new List <string>
            {
                "Arr/TypeParameterizedTests/1",
                "  CanIterate",
            };

            IList <TestCaseDescriptor> descriptors = new ListTestsParser(TestEnvironment.Options.TestNameSeparator)
                                                     .ParseListTestsOutput(consoleOutput);

            descriptors.Count.Should().Be(1);
            descriptors[0].Suite.Should().Be("Arr/TypeParameterizedTests/1");
            descriptors[0].Name.Should().Be("CanIterate");
            descriptors[0].FullyQualifiedName.Should().Be("Arr/TypeParameterizedTests/1.CanIterate");
            descriptors[0].DisplayName.Should().Be("Arr/TypeParameterizedTests/1.CanIterate");
            descriptors[0].TestType.Should().Be(TestCaseDescriptor.TestTypes.TypeParameterized);
        }
Ejemplo n.º 9
0
        public void ParseListTestsOutput_TestWithTypeParam_CorrectParsing()
        {
            var consoleOutput = new List <string>
            {
                "TypedTests/0.  # TypeParam = class std::vector<int,class std::allocator<int> >",
                "  CanIterate",
            };

            IList <TestCaseDescriptor> descriptors = new ListTestsParser(TestEnvironment.Options.TestNameSeparator)
                                                     .ParseListTestsOutput(consoleOutput);

            descriptors.Count.Should().Be(1);
            descriptors[0].Suite.Should().Be("TypedTests/0");
            descriptors[0].Name.Should().Be("CanIterate");
            descriptors[0].FullyQualifiedName.Should().Be("TypedTests/0.CanIterate");
            descriptors[0].DisplayName.Should().Be("TypedTests/0.CanIterate<std::vector<int,std::allocator<int> > >");
            descriptors[0].TestType.Should().Be(TestCaseDescriptor.TestTypes.TypeParameterized);
        }
Ejemplo n.º 10
0
        public void ParseListTestsOutput_TestWithParam_CorrectParsing()
        {
            var consoleOutput = new List <string>
            {
                "InstantiationName/ParameterizedTests.",
                "  Simple/0  # GetParam() = (1,)",
            };

            IList <TestCaseDescriptor> descriptors = new ListTestsParser(TestEnvironment.Options.TestNameSeparator)
                                                     .ParseListTestsOutput(consoleOutput);

            descriptors.Count.Should().Be(1);
            descriptors[0].Suite.Should().Be("InstantiationName/ParameterizedTests");
            descriptors[0].Name.Should().Be("Simple/0");
            descriptors[0].FullyQualifiedName.Should().Be("InstantiationName/ParameterizedTests.Simple/0");
            descriptors[0].DisplayName.Should().Be("InstantiationName/ParameterizedTests.Simple/0 [(1,)]");
            descriptors[0].TestType.Should().Be(TestCaseDescriptor.TestTypes.Parameterized);
        }
Ejemplo n.º 11
0
        public void ParseListTestsOutput_TestWithTypeParamAndPrefix_CorrectParsing()
        {
            var consoleOutput = new List <string>
            {
                "Arr/TypeParameterizedTests/1.  # TypeParam = struct MyStrangeArray",
                "  CanIterate",
            };

            IList <TestCase> descriptors = new ListTestsParser(TestEnvironment.Options.TestNameSeparator)
                                           .ParseListTestsOutput(consoleOutput);

            descriptors.Should().ContainSingle();
            descriptors[0].Suite.Should().Be("Arr/TypeParameterizedTests/1");
            descriptors[0].Name.Should().Be("CanIterate");
            descriptors[0].FullyQualifiedName.Should().Be("Arr/TypeParameterizedTests/1.CanIterate");
            descriptors[0].DisplayName.Should().Be("Arr/TypeParameterizedTests/1.CanIterate<MyStrangeArray>");
            descriptors[0].TestType.Should().Be(TestCase.TestTypes.TypeParameterized);
        }
Ejemplo n.º 12
0
        public void ParseListTestsOutput_TestWithParamGeneratedNames_CorrectParsing()
        {
            var consoleOutput = new List <string>
            {
                "InstantiationName/ParameterisedTests.",
                "  Name/NamedTest  # GetParam() = 0000023AD11C0C20"
            };

            IList <TestCaseDescriptor> descriptors = new ListTestsParser(TestEnvironment.Options.TestNameSeparator)
                                                     .ParseListTestsOutput(consoleOutput);

            descriptors.Count.Should().Be(1);
            descriptors[0].Suite.Should().Be("InstantiationName/ParameterisedTests");
            descriptors[0].Name.Should().Be("Name/NamedTest");
            descriptors[0].FullyQualifiedName.Should().Be("InstantiationName/ParameterisedTests.Name/NamedTest");
            descriptors[0].DisplayName.Should().Be("InstantiationName/ParameterisedTests.Name/NamedTest [0000023AD11C0C20]");
            descriptors[0].TestType.Should().Be(TestCaseDescriptor.TestTypes.Parameterized);
        }
Ejemplo n.º 13
0
        public void ParseListTestsOutput_SimpleTest_CorrectSuiteAndName()
        {
            var consoleOutput = new List <string>
            {
                "MySuite.",
                "  MyTestCase"
            };

            IList <TestCaseDescriptor> descriptors = new ListTestsParser(TestEnvironment)
                                                     .ParseListTestsOutput(consoleOutput);

            Assert.AreEqual(1, descriptors.Count);
            Assert.AreEqual("MySuite", descriptors[0].Suite);
            Assert.AreEqual("MyTestCase", descriptors[0].Name);
            Assert.IsNull(descriptors[0].Param);
            Assert.IsNull(descriptors[0].TypeParam);
            Assert.AreEqual("MySuite.MyTestCase", descriptors[0].DisplayName);
            Assert.AreEqual("MySuite.MyTestCase", descriptors[0].FullyQualifiedName);
        }
Ejemplo n.º 14
0
        public void ParseListTestsOutput_TestWithTypeParamAndPrefix_CorrectParsing()
        {
            var consoleOutput = new List <string>
            {
                "Arr/TypeParameterizedTests/1.  # TypeParam = struct MyStrangeArray",
                "  CanIterate",
            };

            IList <TestCaseDescriptor> descriptors = new ListTestsParser(TestEnvironment)
                                                     .ParseListTestsOutput(consoleOutput);

            Assert.AreEqual(1, descriptors.Count);
            Assert.AreEqual("Arr/TypeParameterizedTests/1", descriptors[0].Suite);
            Assert.AreEqual("CanIterate", descriptors[0].Name);
            Assert.IsNull(descriptors[0].Param);
            Assert.AreEqual("MyStrangeArray", descriptors[0].TypeParam);
            Assert.AreEqual("Arr/TypeParameterizedTests/1.CanIterate", descriptors[0].FullyQualifiedName);
            Assert.AreEqual("Arr/TypeParameterizedTests/1.CanIterate<MyStrangeArray>", descriptors[0].DisplayName);
        }
        public void ParseListTestsOutput_SimpleTest_CorrectSuiteAndName()
        {
            var consoleOutput = new List<string>
            {
                "MySuite.",
                "  MyTestCase"
            };

            IList<TestCaseDescriptor> descriptors = new ListTestsParser(TestEnvironment)
                .ParseListTestsOutput(consoleOutput);

            descriptors.Count.Should().Be(1);
            descriptors[0].Suite.Should().Be("MySuite");
            descriptors[0].Name.Should().Be("MyTestCase");

            descriptors[0].DisplayName.Should().Be("MySuite.MyTestCase");
            descriptors[0].FullyQualifiedName.Should().Be("MySuite.MyTestCase");
            descriptors[0].TestType.Should().Be(TestCaseDescriptor.TestTypes.Simple);
        }
Ejemplo n.º 16
0
        public void ParseListTestsOutput_TestWithParam_CorrectParsing()
        {
            var consoleOutput = new List <string>
            {
                "InstantiationName/ParameterizedTests.",
                "  Simple/0  # GetParam() = (1,)",
            };

            IList <TestCaseDescriptor> descriptors = new ListTestsParser(TestEnvironment)
                                                     .ParseListTestsOutput(consoleOutput);

            Assert.AreEqual(1, descriptors.Count);
            Assert.AreEqual("InstantiationName/ParameterizedTests", descriptors[0].Suite);
            Assert.AreEqual("Simple/0", descriptors[0].Name);
            Assert.AreEqual("(1,)", descriptors[0].Param);
            Assert.IsNull(descriptors[0].TypeParam);
            Assert.AreEqual("InstantiationName/ParameterizedTests.Simple/0", descriptors[0].FullyQualifiedName);
            Assert.AreEqual("InstantiationName/ParameterizedTests.Simple/0 [(1,)]", descriptors[0].DisplayName);
        }
Ejemplo n.º 17
0
        public void ParseListTestsOutput_TestWithTypeParam_DoesNotModifyName()
        {
            // We test that the keywords "class" and "struct" are correctly removed, without touching type names that would contain these words.
            var consoleOutput = new List <string>
            {
                "TypedTests/0.  # TypeParam = class std::tuple<struct my_struct const ,class gsl::span<class my_class const ,-1> >",
                "  CanIterate",
            };

            IList <TestCaseDescriptor> descriptors = new ListTestsParser(TestEnvironment.Options.TestNameSeparator)
                                                     .ParseListTestsOutput(consoleOutput);

            descriptors.Count.Should().Be(1);
            descriptors[0].Suite.Should().Be("TypedTests/0");
            descriptors[0].Name.Should().Be("CanIterate");
            descriptors[0].FullyQualifiedName.Should().Be("TypedTests/0.CanIterate");
            descriptors[0].DisplayName.Should().Be("TypedTests/0.CanIterate<std::tuple<my_struct const ,gsl::span<my_class const ,-1> > >");
            descriptors[0].TestType.Should().Be(TestCaseDescriptor.TestTypes.TypeParameterized);
        }
Ejemplo n.º 18
0
        public void ParseListTestsOutput_TestWithTypeParam_CorrectParsing()
        {
            var consoleOutput = new List <string>
            {
                "TypedTests/0.  # TypeParam = class std::vector<int,class std::allocator<int> >",
                "  CanIterate",
            };

            IList <TestCaseDescriptor> descriptors = new ListTestsParser(TestEnvironment)
                                                     .ParseListTestsOutput(consoleOutput);

            Assert.AreEqual(1, descriptors.Count);
            Assert.AreEqual("TypedTests/0", descriptors[0].Suite);
            Assert.AreEqual("CanIterate", descriptors[0].Name);
            Assert.IsNull(descriptors[0].Param);
            Assert.AreEqual("std::vector<int,std::allocator<int> >", descriptors[0].TypeParam);
            Assert.AreEqual("TypedTests/0.CanIterate", descriptors[0].FullyQualifiedName);
            Assert.AreEqual("TypedTests/0.CanIterate<std::vector<int,std::allocator<int> > >", descriptors[0].DisplayName);
        }
Ejemplo n.º 19
0
        public void ParseListTestsOutput_TestWithParamAndTestNameSeparatorOldFormat_CorrectParsing()
        {
            MockOptions.Setup(o => o.TestNameSeparator).Returns("::");
            var consoleOutput = new List <string>
            {
                "InstantiationName/ParameterizedTests.",
                "  Simple/0",
            };

            IList <TestCaseDescriptor> descriptors = new ListTestsParser(TestEnvironment.Options.TestNameSeparator)
                                                     .ParseListTestsOutput(consoleOutput);

            descriptors.Count.Should().Be(1);
            descriptors[0].Suite.Should().Be("InstantiationName/ParameterizedTests");
            descriptors[0].Name.Should().Be("Simple/0");
            descriptors[0].FullyQualifiedName.Should().Be("InstantiationName/ParameterizedTests.Simple/0");
            descriptors[0].DisplayName.Should().Be("InstantiationName::ParameterizedTests.Simple::0");
            descriptors[0].TestType.Should().Be(TestCaseDescriptor.TestTypes.Parameterized);
        }
Ejemplo n.º 20
0
        public void ParseListTestsOutput_SimpleTest_CorrectSuiteAndName()
        {
            var consoleOutput = new List <string>
            {
                "MySuite.",
                "  MyTestCase"
            };

            IList <TestCaseDescriptor> descriptors = new ListTestsParser(TestEnvironment.Options.TestNameSeparator)
                                                     .ParseListTestsOutput(consoleOutput);

            descriptors.Count.Should().Be(1);
            descriptors[0].Suite.Should().Be("MySuite");
            descriptors[0].Name.Should().Be("MyTestCase");

            descriptors[0].DisplayName.Should().Be("MySuite.MyTestCase");
            descriptors[0].FullyQualifiedName.Should().Be("MySuite.MyTestCase");
            descriptors[0].TestType.Should().Be(TestCaseDescriptor.TestTypes.Simple);
        }
Ejemplo n.º 21
0
        public IList <TestCase> CreateTestCases(Action <TestCase> reportTestCase = null)
        {
            List <string> standardOutput = new List <string>();

            if (_settings.UseNewTestExecutionFramework)
            {
                return(NewCreateTestcases(reportTestCase, standardOutput));
            }

            try
            {
                var launcher = new ProcessLauncher(_logger, _settings.GetPathExtension(_executable));
                int processExitCode;
                standardOutput = launcher.GetOutputOfCommand("", _executable, GoogleTestConstants.ListTestsOption.Trim(),
                                                             false, false, out processExitCode);

                if (!CheckProcessExitCode(processExitCode, standardOutput))
                {
                    return(new List <TestCase>());
                }
            }
            catch (Exception e)
            {
                SequentialTestRunner.LogExecutionError(_logger, _executable, Path.GetFullPath(""),
                                                       GoogleTestConstants.ListTestsOption.Trim(), e);
                return(new List <TestCase>());
            }

            IList <TestCaseDescriptor> testCaseDescriptors = new ListTestsParser(_settings.TestNameSeparator).ParseListTestsOutput(standardOutput);

            if (_settings.ParseSymbolInformation)
            {
                List <TestCaseLocation> testCaseLocations = GetTestCaseLocations(testCaseDescriptors, _settings.GetPathExtension(_executable));
                return(testCaseDescriptors.Select(descriptor => CreateTestCase(descriptor, testCaseLocations)).ToList());
            }

            return(testCaseDescriptors.Select(CreateTestCase).ToList());
        }
Ejemplo n.º 22
0
        public IList <TestCase> CreateTestCases(Action <TestCase> reportTestCase = null)
        {
            List <string> standardOutput = new List <string>();

            if (_settings.UseNewTestExecutionFramework)
            {
                return(NewCreateTestcases(reportTestCase, standardOutput));
            }

            try
            {
                int             processExitCode = 0;
                ProcessLauncher launcher        = null;
                var             listTestsTask   = new Task(() =>
                {
                    launcher       = new ProcessLauncher(_logger, _settings.GetPathExtension(_executable), null);
                    standardOutput = launcher.GetOutputOfCommand("", _executable, GoogleTestConstants.ListTestsOption,
                                                                 false, false, out processExitCode);
                }, TaskCreationOptions.AttachedToParent);
                listTestsTask.Start();

                if (!listTestsTask.Wait(TimeSpan.FromSeconds(_settings.TestDiscoveryTimeoutInSeconds)))
                {
                    launcher?.Cancel();

                    string dir              = Path.GetDirectoryName(_executable);
                    string file             = Path.GetFileName(_executable);
                    string cdToWorkingDir   = $@"cd ""{dir}""";
                    string listTestsCommand = $"{file} {GoogleTestConstants.ListTestsOption}";

                    _logger.LogError($"Test discovery was cancelled after {_settings.TestDiscoveryTimeoutInSeconds}s for executable {_executable}");
                    _logger.DebugError($"Test whether the following commands can be executed sucessfully on the command line (make sure all required binaries are on the PATH):{Environment.NewLine}{cdToWorkingDir}{Environment.NewLine}{listTestsCommand}");

                    return(new List <TestCase>());
                }

                if (!CheckProcessExitCode(processExitCode, standardOutput))
                {
                    return(new List <TestCase>());
                }
            }
            catch (Exception e)
            {
                SequentialTestRunner.LogExecutionError(_logger, _executable, Path.GetFullPath(""),
                                                       GoogleTestConstants.ListTestsOption, e);
                return(new List <TestCase>());
            }

            IList <TestCaseDescriptor> testCaseDescriptors = new ListTestsParser(_settings.TestNameSeparator).ParseListTestsOutput(standardOutput);
            var resolver = new TestCaseResolver(_executable, _settings.GetPathExtension(_executable), _diaResolverFactory, _settings.ParseSymbolInformation, _logger);

            IList <TestCase> testCases = new List <TestCase>();
            IDictionary <string, ISet <TestCase> > suite2TestCases = new Dictionary <string, ISet <TestCase> >();

            foreach (var descriptor in testCaseDescriptors)
            {
                var testCase = _settings.ParseSymbolInformation
                    ? CreateTestCase(descriptor, resolver)
                    : CreateTestCase(descriptor);
                ISet <TestCase> testCasesInSuite;
                if (!suite2TestCases.TryGetValue(descriptor.Suite, out testCasesInSuite))
                {
                    suite2TestCases.Add(descriptor.Suite, testCasesInSuite = new HashSet <TestCase>());
                }
                testCasesInSuite.Add(testCase);
                testCases.Add(testCase);
            }

            foreach (var suiteTestCasesPair in suite2TestCases)
            {
                foreach (var testCase in suiteTestCasesPair.Value)
                {
                    testCase.Properties.Add(new TestCaseMetaDataProperty(suiteTestCasesPair.Value.Count, testCases.Count));
                }
            }

            if (reportTestCase != null)
            {
                foreach (var testCase in testCases)
                {
                    reportTestCase(testCase);
                }
            }

            return(testCases);
        }
        public void ParseListTestsOutput_TestWithTypeParamAndPrefixOldFormat_CorrectParsing()
        {
            var consoleOutput = new List<string>
            {
                "Arr/TypeParameterizedTests/1",
                "  CanIterate",
            };

            IList<TestCaseDescriptor> descriptors = new ListTestsParser(TestEnvironment)
                .ParseListTestsOutput(consoleOutput);

            descriptors.Count.Should().Be(1);
            descriptors[0].Suite.Should().Be("Arr/TypeParameterizedTests/1");
            descriptors[0].Name.Should().Be("CanIterate");
            descriptors[0].FullyQualifiedName.Should().Be("Arr/TypeParameterizedTests/1.CanIterate");
            descriptors[0].DisplayName.Should().Be("Arr/TypeParameterizedTests/1.CanIterate");
            descriptors[0].TestType.Should().Be(TestCaseDescriptor.TestTypes.TypeParameterized);
        }
        public void ParseListTestsOutput_TestWithParamAndTestNameSeparatorOldFormat_CorrectParsing()
        {
            MockOptions.Setup(o => o.TestNameSeparator).Returns("::");
            var consoleOutput = new List<string>
            {
                "InstantiationName/ParameterizedTests.",
                "  Simple/0",
            };

            IList<TestCaseDescriptor> descriptors = new ListTestsParser(TestEnvironment)
                .ParseListTestsOutput(consoleOutput);

            descriptors.Count.Should().Be(1);
            descriptors[0].Suite.Should().Be("InstantiationName/ParameterizedTests");
            descriptors[0].Name.Should().Be("Simple/0");
            descriptors[0].FullyQualifiedName.Should().Be("InstantiationName/ParameterizedTests.Simple/0");
            descriptors[0].DisplayName.Should().Be("InstantiationName::ParameterizedTests.Simple::0");
            descriptors[0].TestType.Should().Be(TestCaseDescriptor.TestTypes.Parameterized);
        }
        public IList <TestCase> CreateTestCases(Action <TestCase> reportTestCase = null)
        {
            if (_settings.UseNewTestExecutionFramework)
            {
                return(NewCreateTestcases(reportTestCase));
            }

            string        workingDir     = _settings.GetWorkingDirForDiscovery(_executable);
            string        finalParams    = GetDiscoveryParams();
            List <string> standardOutput = new List <string>();

            try
            {
                int             processExitCode = 0;
                ProcessLauncher launcher        = null;
                var             listTestsTask   = new Task(() =>
                {
                    launcher       = new ProcessLauncher(_logger, _settings.GetPathExtension(_executable), null);
                    standardOutput = launcher.GetOutputOfCommand(workingDir, _executable, finalParams,
                                                                 false, false, out processExitCode);
                }, TaskCreationOptions.AttachedToParent);
                listTestsTask.Start();

                if (!listTestsTask.Wait(TimeSpan.FromSeconds(_settings.TestDiscoveryTimeoutInSeconds)))
                {
                    launcher?.Cancel();
                    LogTimeoutError(workingDir, finalParams);
                    return(new List <TestCase>());
                }

                if (!CheckProcessExitCode(processExitCode, standardOutput, workingDir, finalParams))
                {
                    return(new List <TestCase>());
                }
            }
            catch (Exception e)
            {
                SequentialTestRunner.LogExecutionError(_logger, _executable, workingDir, finalParams, e);
                return(new List <TestCase>());
            }

            IList <TestCaseDescriptor> testCaseDescriptors = new ListTestsParser(_settings.TestNameSeparator).ParseListTestsOutput(standardOutput);
            var resolver = new TestCaseResolver(_executable, _settings.GetPathExtension(_executable), _settings.GetAdditionalPdbs(_executable), _diaResolverFactory, _settings.ParseSymbolInformation, _logger);

            IList <TestCase> testCases = new List <TestCase>();
            IDictionary <string, ISet <TestCase> > suite2TestCases = new Dictionary <string, ISet <TestCase> >();

            foreach (var descriptor in testCaseDescriptors)
            {
                var testCase = _settings.ParseSymbolInformation
                    ? CreateTestCase(descriptor, resolver)
                    : CreateTestCase(descriptor);
                ISet <TestCase> testCasesInSuite;
                if (!suite2TestCases.TryGetValue(descriptor.Suite, out testCasesInSuite))
                {
                    suite2TestCases.Add(descriptor.Suite, testCasesInSuite = new HashSet <TestCase>());
                }
                testCasesInSuite.Add(testCase);
                testCases.Add(testCase);
            }

            foreach (var suiteTestCasesPair in suite2TestCases)
            {
                foreach (var testCase in suiteTestCasesPair.Value)
                {
                    testCase.Properties.Add(new TestCaseMetaDataProperty(suiteTestCasesPair.Value.Count, testCases.Count));
                }
            }

            if (reportTestCase != null)
            {
                foreach (var testCase in testCases)
                {
                    reportTestCase(testCase);
                }
            }

            return(testCases);
        }