internal static async Task ProcessSarifLogAsync(SarifLog sarifLog, string logFilePath, bool cleanErrors, bool openInEditor)
        {
            // The creation of the data models must be done on the UI thread (for now).
            // VS's table data source constructs are indeed thread safe.
            // The object model (which is eventually handed to WPF\XAML) could also
            // be constructed on any thread as well.
            // However the current implementation of the data model and
            // the "run data cache" have not been augmented to support this
            // and are not thread safe.
            // This work could be done in the future to do even less work on the UI
            // thread if needed.
            if (!SarifViewerPackage.IsUnitTesting)
            {
                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
            }

            // Clear previous data
            if (cleanErrors)
            {
                CleanAllErrors();
            }

            bool hasResults = false;

            foreach (Run run in sarifLog.Runs)
            {
                // run.tool is required, add one if it's missing
                if (run.Tool == null)
                {
                    run.Tool = new Tool
                    {
                        Driver = new ToolComponent
                        {
                            Name = Resources.UnknownToolName,
                        },
                    };
                }

                if (Instance.WriteRunToErrorList(run, logFilePath, sarifLog) > 0)
                {
                    hasResults = true;
                }
            }

            if (openInEditor && !SarifViewerPackage.IsUnitTesting)
            {
                SdkUIUtilities.OpenDocument(ServiceProvider.GlobalProvider, logFilePath, usePreviewPane: false);
            }

            if (hasResults)
            {
                if (!SarifViewerPackage.IsUnitTesting)
                {
                    // We cannot show UI during unit-tests.
                    SdkUIUtilities.ShowToolWindowAsync(new Guid(ToolWindowGuids80.ErrorList), activate: false).FileAndForget(Constants.FileAndForgetFaultEventNames.ShowErrorList);
                }
            }

            RaiseLogProcessed(ExceptionalConditionsCalculator.Calculate(sarifLog));
        }
示例#2
0
        public void ExceptionalConditionsCalculator_OnMultipleLogs_MergesConditions()
        {
            var logs = new List <SarifLog>
            {
                new SarifLog // Run with no results.
                {
                    Runs = new List <Run>
                    {
                        new Run
                        {
                            Results = new List <Result>(),
                        },
                    },
                },
                new SarifLog // Run with both configuration and execution errors.
                {
                    Runs = new List <Run>
                    {
                        new Run
                        {
                            Results = new List <Result>
                            {
                                new Result(),
                            },
                            Invocations = new List <Invocation>
                            {
                                new Invocation
                                {
                                    ToolConfigurationNotifications = new List <Notification>
                                    {
                                        new Notification
                                        {
                                            Level = FailureLevel.Error,
                                        },
                                    },
                                    ToolExecutionNotifications = new List <Notification>
                                    {
                                        new Notification
                                        {
                                            Level = FailureLevel.Error,
                                        },
                                    },
                                },
                            },
                        },
                    },
                },
            };

            ExceptionalConditionsCalculator.Calculate(logs).
            Should().Be(ExceptionalConditions.NoResults | ExceptionalConditions.ConfigurationError | ExceptionalConditions.ExecutionError);
        }
示例#3
0
        public void ExceptionalConditionsCalculator_ProducesExpectedResults()
        {
            var sb = new StringBuilder();

            foreach (TestCase testCase in s_testCases)
            {
                ExceptionalConditions actualResult = ExceptionalConditionsCalculator.Calculate(testCase.Log);
                if (actualResult != testCase.ExpectedResult)
                {
                    sb.Append("    ").Append(testCase.Name).Append(": expected ").Append(testCase.ExpectedResult)
                    .Append(" but got ").Append(actualResult).AppendLine();
                }
            }

            sb.Length.Should().Be(0, "failed test cases:\n" + sb.ToString());
        }