コード例 #1
0
        private IList <TestCase> NewCreateTestcases(Action <TestCase> reportTestCase, List <string> standardOutput)
        {
            var testCases = new List <TestCase>();

            var resolver = new NewTestCaseResolver(
                _executable,
                _settings.GetPathExtension(_executable),
                _diaResolverFactory,
                _settings.ParseSymbolInformation,
                _logger);

            var parser = new StreamingListTestsParser(_settings.TestNameSeparator);

            parser.TestCaseDescriptorCreated += (sender, args) =>
            {
                TestCase testCase;
                if (_settings.ParseSymbolInformation)
                {
                    TestCaseLocation testCaseLocation =
                        resolver.FindTestCaseLocation(
                            _signatureCreator.GetTestMethodSignatures(args.TestCaseDescriptor).ToList());
                    testCase = CreateTestCase(args.TestCaseDescriptor, testCaseLocation.Yield().ToList());
                }
                else
                {
                    testCase = CreateTestCase(args.TestCaseDescriptor);
                }
                reportTestCase?.Invoke(testCase);
                testCases.Add(testCase);
            };

            Action <string> lineAction = s =>
            {
                standardOutput.Add(s);
                parser.ReportLine(s);
            };

            try
            {
                var executor        = new ProcessExecutor(null, _logger);
                int processExitCode = executor.ExecuteCommandBlocking(
                    _executable,
                    GoogleTestConstants.ListTestsOption.Trim(),
                    "",
                    _settings.GetPathExtension(_executable),
                    lineAction);

                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>());
            }
            return(testCases);
        }
コード例 #2
0
        private IList <TestCase> NewCreateTestcases(Action <TestCase> reportTestCase, List <string> standardOutput)
        {
            var testCases = new List <TestCase>();

            var resolver = new NewTestCaseResolver(
                _executable,
                _settings.GetPathExtension(_executable),
                _diaResolverFactory,
                _settings.ParseSymbolInformation,
                _logger);

            var suite2TestCases = new Dictionary <string, ISet <TestCase> >();
            var parser          = new StreamingListTestsParser(_settings.TestNameSeparator);

            parser.TestCaseDescriptorCreated += (sender, args) =>
            {
                TestCase testCase;
                if (_settings.ParseSymbolInformation)
                {
                    TestCaseLocation testCaseLocation =
                        resolver.FindTestCaseLocation(
                            _signatureCreator.GetTestMethodSignatures(args.TestCaseDescriptor).ToList());
                    testCase = CreateTestCase(args.TestCaseDescriptor, testCaseLocation.Yield().ToList());
                }
                else
                {
                    testCase = CreateTestCase(args.TestCaseDescriptor);
                }
                testCases.Add(testCase);

                ISet <TestCase> testCasesOfSuite;
                if (!suite2TestCases.TryGetValue(args.TestCaseDescriptor.Suite, out testCasesOfSuite))
                {
                    suite2TestCases.Add(args.TestCaseDescriptor.Suite, testCasesOfSuite = new HashSet <TestCase>());
                }
                testCasesOfSuite.Add(testCase);
            };

            Action <string> lineAction = s =>
            {
                standardOutput.Add(s);
                parser.ReportLine(s);
            };

            try
            {
                int             processExitCode       = ProcessExecutor.ExecutionFailed;
                ProcessExecutor executor              = null;
                var             listAndParseTestsTask = new Task(() =>
                {
                    executor        = new ProcessExecutor(null, _logger);
                    processExitCode = executor.ExecuteCommandBlocking(
                        _executable,
                        GoogleTestConstants.ListTestsOption.Trim(),
                        "",
                        _settings.GetPathExtension(_executable),
                        lineAction);
                }, TaskCreationOptions.AttachedToParent);
                listAndParseTestsTask.Start();

                if (!listAndParseTestsTask.Wait(TimeSpan.FromSeconds(_settings.TestDiscoveryTimeoutInSeconds)))
                {
                    executor?.Cancel();

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

                    _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>());
                }

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

                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>());
            }
            return(testCases);
        }