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());
        }
示例#2
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);
        }
示例#3
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 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());
        }
        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);
        }
示例#6
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);
        }