public void RunStarted(ITestAdaptor testsToRun) { if (!Coverage.enabled) { return; } m_IsConnectedToPlayer = CoverageUtils.IsConnectedToPlayer; if (m_IsConnectedToPlayer) { ResultsLogger.Log(ResultID.Warning_StandaloneUnsupported); return; } if (CoverageRunData.instance.isRunning || EditorApplication.isCompiling) { return; } CoverageRunData.instance.Start(); m_CoverageReporterManager.CreateCoverageReporter(); ICoverageReporter coverageReporter = m_CoverageReporterManager.CoverageReporter; if (coverageReporter != null) { coverageReporter.OnRunStarted(testsToRun); } }
private static void DivisionTests() { ResultsLogger.Log("Division"); TimeLogger.LogExecutionTime("Int", () => { var __ = 300 / 291; }); TimeLogger.LogExecutionTime("Long", () => { var __ = 34534500 / 29534534531; }); TimeLogger.LogExecutionTime("Float", () => { var __ = 2.342342340f / 29.132423f; }); TimeLogger.LogExecutionTime("Double", () => { var __ = 30.00010d / 20000.91d; }); TimeLogger.LogExecutionTime("Decimal", () => { var __ = 30.000030m / 291.9m; }); }
private static void SubstractionTests() { ResultsLogger.Log("Square root"); TimeLogger.LogExecutionTime("Int", () => { var __ = 300 - 291; }); TimeLogger.LogExecutionTime("Long", () => { var __ = 34534500 - 29534534531; }); TimeLogger.LogExecutionTime("Float", () => { var __ = 2.342342340f - 29.132423f; }); TimeLogger.LogExecutionTime("Double", () => { var __ = 30.00010d - 20000.91d; }); TimeLogger.LogExecutionTime("Decimal", () => { var __ = 30.000030m - 291.9m; }); }
public virtual void WriteCoverageSession() { #if UNITY_2020_1_OR_NEWER if (Compilation.CompilationPipeline.codeOptimization == Compilation.CodeOptimization.Release) { ResultsLogger.Log(ResultID.Warning_DebugCodeOptimization); if (!CommandLineManager.instance.batchmode) { if (EditorUtility.DisplayDialog( L10n.Tr("Code Coverage"), L10n.Tr($"Code Coverage requires Code Optimization to be set to debug mode in order to obtain accurate coverage information. Do you want to switch to debug mode?\n\nNote that you would need to rerun {(CoverageRunData.instance.isRecording ? "the Coverage Recording session." : "the tests.")}"), L10n.Tr("Switch to debug mode"), L10n.Tr("Cancel"))) { Compilation.CompilationPipeline.codeOptimization = Compilation.CodeOptimization.Debug; EditorPrefs.SetBool("ScriptDebugInfoEnabled", true); } } } #endif #if BURST_INSTALLED if (EditorPrefs.GetBool("BurstCompilation", true) && !CommandLineManager.instance.burstDisabled) { ResultsLogger.Log(ResultID.Warning_BurstCompilationEnabled); } #endif }
private void SetCoverageHistoryPath(string filePathArg) { if (coverageHistoryPath != string.Empty) { ResultsLogger.Log(ResultID.Warning_MultipleHistoryPaths, coverageHistoryPath); } else { if (filePathArg != null) { coverageHistoryPath = CoverageUtils.NormaliseFolderSeparators(filePathArg); } } }
private static void IncrementTest() { ResultsLogger.Log("Increment test"); int intResult = 0; StopwatchMeasures.MeasureTime( "Int", () => { intResult++; }); long longResult = 0; StopwatchMeasures.MeasureTime( "Long", () => { longResult++; }); float floatResult = 1.1f; StopwatchMeasures.MeasureTime( "Float", () => { floatResult++; }); double doubleResult = 1.1d; StopwatchMeasures.MeasureTime( "Double", () => { doubleResult++; }); decimal decimalResult = 1.1m; StopwatchMeasures.MeasureTime( "Decimal", () => { decimalResult++; }); }
public override void WriteCoverageSession() { XmlSerializer serializer = new XmlSerializer(typeof(CoverageSession)); string fileFullPath = GetNextFullFilePath(); using (TextWriter writer = new StreamWriter(fileFullPath)) { serializer.Serialize(writer, CoverageSession); } ResultsLogger.Log(ResultID.Log_ResultsSaved, fileFullPath); CoverageEventData.instance.AddSessionResultPath(fileFullPath); base.WriteCoverageSession(); }
private static void SinusTests() { ResultsLogger.Log("Sinus"); TimeLogger.LogExecutionTime("Int", () => { float a = (float)Math.Sin(2.03); }); TimeLogger.LogExecutionTime("Double", () => { double a = Math.Sin(2.03); }); TimeLogger.LogExecutionTime("Decimal", () => { decimal a = (decimal)Math.Sin(2.03); }); }
private static void NaturalLogarithmTests() { ResultsLogger.Log("Natural logarithm"); TimeLogger.LogExecutionTime("Int", () => { float a = (float)Math.Log(3.04003); }); TimeLogger.LogExecutionTime("Double", () => { double a = Math.Log(3.04003); }); TimeLogger.LogExecutionTime("Decimal", () => { decimal a = (decimal)Math.Log(3.04003); }); }
private static void SquareRootTests() { ResultsLogger.Log("Square root"); TimeLogger.LogExecutionTime("Int", () => { float a = (float)Math.Sqrt(3.04003); }); TimeLogger.LogExecutionTime("Double", () => { double a = Math.Sqrt(3.04003); }); TimeLogger.LogExecutionTime("Decimal", () => { decimal a = (decimal)Math.Sqrt(3.04003); }); }
private static void SubtractTest() { ResultsLogger.Log("Subtract test"); StopwatchMeasures.MeasureTime( "Int", () => { int result = 44243 - 14242; }); StopwatchMeasures.MeasureTime( "Long", () => { long result = 32233720368547758 - 56757514242; }); StopwatchMeasures.MeasureTime( "Float", () => { float result = 311.125345f - 14242.643256f; }); StopwatchMeasures.MeasureTime( "Double", () => { double result = 324.23425235d - 234.324254534d; }); StopwatchMeasures.MeasureTime( "Decimal", () => { decimal result = 324.2433425235m - 234.35354254534m; }); }
private static void MultiplyTest() { ResultsLogger.Log("Multiply test"); StopwatchMeasures.MeasureTime( "Int", () => { int result = 442 * 142; }); StopwatchMeasures.MeasureTime( "Long", () => { long result = 68548 * 6442; }); StopwatchMeasures.MeasureTime( "Float", () => { float result = 311.1253f * 14242.6456f; }); StopwatchMeasures.MeasureTime( "Double", () => { double result = 324.23235d * 234.3254534d; }); StopwatchMeasures.MeasureTime( "Decimal", () => { decimal result = 324.243342235m * 234.353254534m; }); }
private static void IncrementationTests() { ResultsLogger.Log("Incrementation"); int iNum = 0; TimeLogger.LogExecutionTime("Int", () => { iNum += 1; }); long lNum = 0; TimeLogger.LogExecutionTime("Long", () => { lNum += 1; }); float fNum = 0; TimeLogger.LogExecutionTime("Float", () => { fNum += 1; }); double dNum = 0; TimeLogger.LogExecutionTime("Double", () => { dNum += 1; }); decimal decNum = 0; TimeLogger.LogExecutionTime("Decimal", () => { decNum += 1; }); }
private static void DivideTest() { ResultsLogger.Log("Divide test"); StopwatchMeasures.MeasureTime( "Int", () => { int result = 442 / 142; }); StopwatchMeasures.MeasureTime( "Long", () => { long result = 68548 / 6442; }); StopwatchMeasures.MeasureTime( "Float", () => { float result = 311.1253f / 14242.6456f; }); StopwatchMeasures.MeasureTime( "Double", () => { double result = 324.23235d / 234.3254534d; }); StopwatchMeasures.MeasureTime( "Decimal", () => { decimal result = 324.243342235m / 234.353254534m; }); }
public void OutputCoverageReport(ITestResultAdaptor testResults = null, bool clearProgressBar = true) { if (!CommandLineManager.instance.batchmode) { EditorUtility.DisplayProgressBar(Styles.ProgressTitle.text, Styles.ProgressWritingFile.text, 0.95f); } CoverageSession coverageSession = GenerateOpenCoverSession(); if (coverageSession != null && m_Writer != null) { m_Writer.CoverageSession = coverageSession; m_Writer.WriteCoverageSession(); } else { ResultsLogger.Log(ResultID.Warning_NoCoverageResultsSaved); } if (clearProgressBar) { EditorUtility.ClearProgressBar(); } }
private void ParseCoverageOptions() { m_CoverageOptions = m_CoverageOptionsArg.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries); foreach (string optionArgsStr in m_CoverageOptions) { if (optionArgsStr.Length == 0) { continue; } string optionName = optionArgsStr; string optionArgs = string.Empty; int indexOfColon = optionArgsStr.IndexOf(':'); if (indexOfColon > 0) { optionName = optionArgsStr.Substring(0, indexOfColon); optionArgs = optionArgsStr.Substring(indexOfColon + 1); } switch (optionName.ToUpperInvariant()) { case "GENERATEADDITIONALMETRICS": generateAdditionalMetrics = true; break; case "GENERATEHTMLREPORTHISTORY": generateHTMLReportHistory = true; break; case "GENERATEHTMLREPORT": generateHTMLReport = true; break; case "GENERATEBADGEREPORT": generateBadgeReport = true; break; case "USEPROJECTSETTINGS": if (batchmode) { useProjectSettings = true; } else { ResultsLogger.Log(ResultID.Warning_UseProjectSettingsNonBatchmode); } break; case "VERBOSITY": if (optionArgs.Length > 0) { switch (optionArgs.ToUpperInvariant()) { case "VERBOSE": ResultsLogger.VerbosityLevel = LogVerbosityLevel.Verbose; break; case "INFO": ResultsLogger.VerbosityLevel = LogVerbosityLevel.Info; break; case "WARNING": ResultsLogger.VerbosityLevel = LogVerbosityLevel.Warning; break; case "ERROR": ResultsLogger.VerbosityLevel = LogVerbosityLevel.Error; break; case "OFF": ResultsLogger.VerbosityLevel = LogVerbosityLevel.Off; break; } } break; case "ASSEMBLYFILTERS": if (optionArgs.Length > 0) { assemblyFiltersSpecified = true; string[] assemblyFilters = optionArgs.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < assemblyFilters.Length; ++i) { string filter = assemblyFilters[i]; string filterBody = filter.Length > 1 ? filter.Substring(1) : string.Empty; if (filter.StartsWith("+", StringComparison.OrdinalIgnoreCase)) { if (m_IncludeAssemblies.Length > 0) { m_IncludeAssemblies += ","; } if (filterBody.StartsWith("<", StringComparison.OrdinalIgnoreCase)) { if (string.Equals(filterBody, AssemblyFiltering.kUserAlias, StringComparison.OrdinalIgnoreCase)) { m_IncludeAssemblies += AssemblyFiltering.GetUserOnlyAssembliesString(); } else if (string.Equals(filterBody, AssemblyFiltering.kProjectAlias, StringComparison.OrdinalIgnoreCase)) { m_IncludeAssemblies += AssemblyFiltering.GetAllProjectAssembliesString(); } else if (string.Equals(filterBody, AssemblyFiltering.kPackagesAlias, StringComparison.OrdinalIgnoreCase)) { m_IncludeAssemblies += AssemblyFiltering.GetPackagesOnlyAssembliesString(); } else if (string.Equals(filterBody, AssemblyFiltering.kAllAlias, StringComparison.OrdinalIgnoreCase)) { m_IncludeAssemblies += "*"; } } else { m_IncludeAssemblies += filterBody; } } else if (filter.StartsWith("-", StringComparison.OrdinalIgnoreCase)) { if (m_ExcludeAssemblies.Length > 0) { m_ExcludeAssemblies += ","; } if (filterBody.StartsWith("<", StringComparison.OrdinalIgnoreCase)) { if (string.Equals(filterBody, AssemblyFiltering.kUserAlias, StringComparison.OrdinalIgnoreCase)) { m_ExcludeAssemblies += AssemblyFiltering.GetUserOnlyAssembliesString(); } else if (string.Equals(filterBody, AssemblyFiltering.kProjectAlias, StringComparison.OrdinalIgnoreCase)) { m_ExcludeAssemblies += AssemblyFiltering.GetAllProjectAssembliesString(); } else if (string.Equals(filterBody, AssemblyFiltering.kPackagesAlias, StringComparison.OrdinalIgnoreCase)) { m_ExcludeAssemblies += AssemblyFiltering.GetPackagesOnlyAssembliesString(); } else if (string.Equals(filterBody, AssemblyFiltering.kAllAlias, StringComparison.OrdinalIgnoreCase)) { m_ExcludeAssemblies += "*"; } } else { m_ExcludeAssemblies += filterBody; } } else { ResultsLogger.Log(ResultID.Warning_AssemblyFiltersNotPrefixed, filter); } } } break; case "PATHFILTERS": if (optionArgs.Length > 0) { pathFiltersSpecified = true; string[] pathFilters = optionArgs.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < pathFilters.Length; ++i) { string filter = pathFilters[i]; string filterBody = filter.Length > 1 ? filter.Substring(1) : string.Empty; if (filter.StartsWith("+", StringComparison.OrdinalIgnoreCase)) { if (m_IncludePaths.Length > 0) { m_IncludePaths += ","; } m_IncludePaths += filterBody; } else if (filter.StartsWith("-", StringComparison.OrdinalIgnoreCase)) { if (m_ExcludePaths.Length > 0) { m_ExcludePaths += ","; } m_ExcludePaths += filterBody; } else { ResultsLogger.Log(ResultID.Warning_PathFiltersNotPrefixed, filter); } } } break; case "PATHSTRIPPINGPATTERNS": if (optionArgs.Length > 0) { pathStrippingSpecified = true; m_PathStrippingPatterns = optionArgs; } break; case "SOURCEPATHS": if (optionArgs.Length > 0) { sourcePathsSpecified = true; string[] rawSourcePaths = optionArgs.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < rawSourcePaths.Length; ++i) { if (sourcePaths.Length > 0) { sourcePaths += ","; } sourcePaths += CoverageUtils.NormaliseFolderSeparators(rawSourcePaths[i]); } } break; } } if (m_IncludeAssemblies.Length == 0) { // If there are no inlcudedAssemblies specified but there are includedPaths specified // then include all project assemblies so path filtering can take precedence over assembly filtering, // othewise if there are no includedPaths specified neither then inlcude just the user assemblies (found under the Assets folder) if (m_IncludePaths.Length > 0) { m_IncludeAssemblies = AssemblyFiltering.GetAllProjectAssembliesString(); } else { m_IncludeAssemblies = AssemblyFiltering.GetUserOnlyAssembliesString(); } } if (m_ExcludeAssemblies.Length > 0) { m_ExcludeAssemblies += ","; } m_ExcludeAssemblies += AssemblyFiltering.kDefaultExcludedAssemblies; assemblyFiltering.Parse(m_IncludeAssemblies, m_ExcludeAssemblies); pathFiltering.Parse(m_IncludePaths, m_ExcludePaths); pathStripping.Parse(m_PathStrippingPatterns); }
internal CoverageSession GenerateOpenCoverSession() { ResultsLogger.LogSessionItem("Started OpenCover Session", LogVerbosityLevel.Info); CoverageSession coverageSession = null; UInt32 fileUID = 0; List <Module> moduleList = new List <Module>(); Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); float progressInterval = 0.9f / assemblies.Length; float currentProgress = 0.0f; bool shouldGenerateAdditionalMetrics = m_ReporterFilter.ShouldGenerateAdditionalMetrics(); foreach (Assembly assembly in assemblies) { string assemblyName = assembly.GetName().Name.ToLower(); ResultsLogger.LogSessionItem($"Processing assembly: {assemblyName}", LogVerbosityLevel.Verbose); try { if (assembly.GetCustomAttribute <ExcludeFromCoverageAttribute>() != null || assembly.GetCustomAttribute <ExcludeFromCodeCoverageAttribute>() != null) { ResultsLogger.LogSessionItem($"Excluded assembly (ExcludeFromCoverage): {assemblyName}", LogVerbosityLevel.Verbose); continue; } } catch { ResultsLogger.Log(ResultID.Warning_ExcludeAttributeAssembly, assemblyName); } if (!CommandLineManager.instance.batchmode) { EditorUtility.DisplayProgressBar(Styles.ProgressTitle.text, Styles.ProgressGatheringResults.text, currentProgress); } currentProgress += progressInterval; if (!m_ReporterFilter.ShouldProcessAssembly(assemblyName)) { ResultsLogger.LogSessionItem($"Excluded assembly (Assembly Filtering): {assemblyName}", LogVerbosityLevel.Verbose); continue; } List <Class> coveredClasses = new List <Class>(); List <string> filesNotFound = new List <string>(); Dictionary <string, UInt32> fileList = new Dictionary <string, UInt32>(); Type[] assemblyTypes = null; m_ExcludedMethods = null; m_ExcludedTypes = null; try { assemblyTypes = assembly.GetTypes(); } catch (ReflectionTypeLoadException ex) { // This exception can be thrown if some of the types from this assembly can't be loaded. If this // happens, the Types property array contains a Type for all loaded types and null for each // type that couldn't be loaded. assemblyTypes = ex.Types; m_ReporterFilter.ShouldProcessAssembly(assemblyName); } // Debug.Assert(assemblyTypes != null) ResultsLogger.Log(ResultID.Assert_NullAssemblyTypes, assemblyTypes == null ? "0" : "1"); ResultsLogger.LogSessionItem($"Processing included assembly: {assemblyName}", LogVerbosityLevel.Info); foreach (Type type in assemblyTypes) { // The type can be null if the ReflectionTypeLoadException has been thrown previously. if (type == null) { continue; } string className = type.FullName; ResultsLogger.LogSessionItem($"Processing class: {className}", LogVerbosityLevel.Verbose); try { if (type.GetCustomAttribute <ExcludeFromCoverageAttribute>() != null || type.GetCustomAttribute <ExcludeFromCodeCoverageAttribute>() != null || CheckIfParentMemberIsExcluded(type)) { ResultsLogger.LogSessionItem($"Excluded class (ExcludeFromCoverage): {className}", LogVerbosityLevel.Verbose); if (m_ExcludedTypes == null) { m_ExcludedTypes = new List <string>(); } m_ExcludedTypes.Add(type.FullName); continue; } } catch { ResultsLogger.Log(ResultID.Warning_ExcludeAttributeClass, className, assemblyName); } ResultsLogger.LogSessionItem($"Processing included class: {className}", LogVerbosityLevel.Info); CoveredMethodStats[] classMethodStatsArray = Coverage.GetStatsFor(type); if (classMethodStatsArray.Length > 0) { List <Method> coveredMethods = new List <Method>(); foreach (CoveredMethodStats classMethodStats in classMethodStatsArray) { MethodBase method = classMethodStats.method; if (method == null) { continue; } string methodName = method.Name; ResultsLogger.LogSessionItem($"Processing method: {methodName}", LogVerbosityLevel.Verbose); try { if (method.GetCustomAttribute <ExcludeFromCoverageAttribute>() != null || method.GetCustomAttribute <ExcludeFromCodeCoverageAttribute>() != null || CheckIfParentMemberIsExcluded(method)) { ResultsLogger.LogSessionItem($"Excluded method (ExcludeFromCoverage): {methodName}", LogVerbosityLevel.Verbose); if (m_ExcludedMethods == null) { m_ExcludedMethods = new List <MethodBase>(); } m_ExcludedMethods.Add(method); continue; } } catch { ResultsLogger.Log(ResultID.Warning_ExcludeAttributeMethod, methodName, className, assemblyName); } if (IsGetterSetterPropertyExcluded(method, type)) { ResultsLogger.LogSessionItem($"Excluded method (ExcludeFromCoverage): {methodName}", LogVerbosityLevel.Verbose); continue; } if (classMethodStats.totalSequencePoints > 0) { List <SequencePoint> coveredSequencePoints = new List <SequencePoint>(); uint fileId = 0; CoveredSequencePoint[] classMethodSequencePointsArray = Coverage.GetSequencePointsFor(method); foreach (CoveredSequencePoint classMethodSequencePoint in classMethodSequencePointsArray) { string filename = classMethodSequencePoint.filename; if (filesNotFound.Contains(filename) || !m_ReporterFilter.ShouldProcessFile(filename)) { ResultsLogger.LogSessionItem($"Excluded method (Path Filtering): {methodName}", LogVerbosityLevel.Verbose); continue; } if (!fileList.TryGetValue(filename, out fileId)) { if (!File.Exists(filename)) { filesNotFound.Add(filename); continue; } else { fileId = ++fileUID; fileList.Add(filename, fileId); } } SequencePoint coveredSequencePoint = new SequencePoint(); coveredSequencePoint.FileId = fileId; coveredSequencePoint.StartLine = (int)classMethodSequencePoint.line; coveredSequencePoint.StartColumn = (int)classMethodSequencePoint.column; coveredSequencePoint.EndLine = (int)classMethodSequencePoint.line; coveredSequencePoint.EndColumn = (int)classMethodSequencePoint.column; coveredSequencePoint.VisitCount = (int)classMethodSequencePoint.hitCount; coveredSequencePoint.Offset = (int)classMethodSequencePoint.ilOffset; coveredSequencePoints.Add(coveredSequencePoint); } if (coveredSequencePoints.Count > 0) { Method coveredMethod = new Method(); coveredMethod.MetadataToken = method.MetadataToken; coveredMethod.FullName = GenerateMethodName(method); coveredMethod.FileRef = new FileRef() { UniqueId = fileId }; coveredMethod.IsConstructor = IsConstructor(method) || IsStaticConstructor(method); coveredMethod.IsStatic = method.IsStatic; coveredMethod.IsSetter = IsPropertySetter(method); coveredMethod.IsGetter = IsPropertyGetter(method); coveredMethod.SequencePoints = coveredSequencePoints.ToArray(); if (shouldGenerateAdditionalMetrics) { coveredMethod.CyclomaticComplexity = method.CalculateCyclomaticComplexity(); } ResultsLogger.LogSessionItem($"Processing included method: {coveredMethod.FullName}", LogVerbosityLevel.Verbose); coveredMethods.Add(coveredMethod); } } } if (coveredMethods.Count > 0) { Class coveredClass = new Class(); coveredClass.FullName = GenerateTypeName(type); coveredClass.Methods = coveredMethods.ToArray(); coveredClasses.Add(coveredClass); } } } if (coveredClasses.Count != 0) { Module module = new Module(); module.ModuleName = assembly.GetName().Name; List <ModelFile> coveredFileList = new List <ModelFile>(); foreach (KeyValuePair <string, UInt32> fileEntry in fileList) { ModelFile coveredFile = new ModelFile(); coveredFile.FullPath = CoverageUtils.NormaliseFolderSeparators(fileEntry.Key); if (CommandLineManager.instance.pathStrippingSpecified) { coveredFile.FullPath = CommandLineManager.instance.pathStripping.StripPath(coveredFile.FullPath); } coveredFile.UniqueId = fileEntry.Value; coveredFileList.Add(coveredFile); } module.Files = coveredFileList.ToArray(); module.Classes = coveredClasses.ToArray(); moduleList.Add(module); } } if (moduleList.Count > 0) { coverageSession = new CoverageSession(); coverageSession.Modules = moduleList.ToArray(); ProcessGenericMethods(coverageSession); foreach (Module coveredModule in moduleList) { foreach (Class coveredClass in coveredModule.Classes) { foreach (Method coveredMethod in coveredClass.Methods) { UpdateMethodSummary(coveredMethod); } UpdateClassSummary(coveredClass); } UpdateModuleSummary(coveredModule); } UpdateSessionSummary(coverageSession); } ResultsLogger.LogSessionItem("Finished OpenCover Session", LogVerbosityLevel.Info); return(coverageSession); }
public void Generate(CoverageSettings coverageSettings) { CoverageRunData.instance.ReportGenerationStart(); if (coverageSettings == null) { EditorUtility.ClearProgressBar(); ResultsLogger.Log(ResultID.Warning_FailedReportNullCoverageSettings); CoverageRunData.instance.ReportGenerationEnd(false); return; } string includeAssemblies = string.Empty; if (CommandLineManager.instance.batchmode && !CommandLineManager.instance.useProjectSettings) { includeAssemblies = CommandLineManager.instance.assemblyFiltering.includedAssemblies; } else { includeAssemblies = CommandLineManager.instance.assemblyFiltersSpecified ? CommandLineManager.instance.assemblyFiltering.includedAssemblies : CoveragePreferences.instance.GetString("IncludeAssemblies", AssemblyFiltering.GetUserOnlyAssembliesString()); } // If override for include assemblies is set in coverageSettings, use overrideIncludeAssemblies instead if (!String.IsNullOrEmpty(coverageSettings.overrideIncludeAssemblies)) { includeAssemblies = coverageSettings.overrideIncludeAssemblies; } string[] includeAssembliesArray = includeAssemblies.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < includeAssembliesArray.Length; i++) { includeAssembliesArray[i] = "+" + includeAssembliesArray[i]; } string assemblies = string.Join(",", includeAssembliesArray); string[] assemblyFilters = assemblies.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); if (assemblyFilters.Length == 0) { EditorUtility.ClearProgressBar(); ResultsLogger.Log(ResultID.Error_FailedReportNoAssemblies); CoverageRunData.instance.ReportGenerationEnd(false); return; } string rootFolderPath = coverageSettings.rootFolderPath; if (!CoverageUtils.DoesFolderExistAndNotEmpty(rootFolderPath) || CoverageUtils.GetNumberOfFilesInFolder(rootFolderPath, "*.xml", SearchOption.AllDirectories) == 0) { EditorUtility.ClearProgressBar(); ResultsLogger.Log(ResultID.Error_FailedReportNoTests); CoverageRunData.instance.ReportGenerationEnd(false); return; } // Only include xml files with the correct filename format string sourceXmlPath = CoverageUtils.JoinPaths(rootFolderPath, "**"); string testResultsXmlPath = CoverageUtils.JoinPaths(sourceXmlPath, "TestCoverageResults_????.xml"); string recordingResultsXmlPath = CoverageUtils.JoinPaths(sourceXmlPath, "RecordingCoverageResults_????.xml"); string[] reportFilePatterns = new string[] { testResultsXmlPath, recordingResultsXmlPath }; bool includeHistoryInReport = CommandLineManager.instance.batchmode && !CommandLineManager.instance.useProjectSettings ? CommandLineManager.instance.generateHTMLReportHistory : CommandLineManager.instance.generateHTMLReportHistory || CoveragePreferences.instance.GetBool("IncludeHistoryInReport", true); string historyDirectory = includeHistoryInReport ? coverageSettings.historyFolderPath : null; string targetDirectory = CoverageUtils.JoinPaths(rootFolderPath, CoverageSettings.ReportFolderName); string[] sourceDirectories = CommandLineManager.instance.sourcePathsSpecified ? CommandLineManager.instance.sourcePaths.Split(',') : new string[] { }; bool generateHTMLReport = CommandLineManager.instance.batchmode && !CommandLineManager.instance.useProjectSettings ? CommandLineManager.instance.generateHTMLReport : CommandLineManager.instance.generateHTMLReport || CoveragePreferences.instance.GetBool("GenerateHTMLReport", true); if (coverageSettings.overrideGenerateReport) { generateHTMLReport = true; } bool generateBadge = CommandLineManager.instance.batchmode && !CommandLineManager.instance.useProjectSettings ? CommandLineManager.instance.generateBadgeReport : CommandLineManager.instance.generateBadgeReport || CoveragePreferences.instance.GetBool("GenerateBadge", true); string reportTypesString = "xmlSummary,"; if (generateHTMLReport) { reportTypesString += "Html,"; } if (generateBadge) { reportTypesString += "Badges,"; } string[] reportTypes = reportTypesString.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); string[] plugins = new string[] { }; bool includeAdditionalMetrics = CommandLineManager.instance.batchmode && !CommandLineManager.instance.useProjectSettings ? CommandLineManager.instance.generateAdditionalMetrics : CommandLineManager.instance.generateAdditionalMetrics || CoveragePreferences.instance.GetBool("GenerateAdditionalMetrics", false); string[] classFilters = new string[] { }; string[] fileFilters = new string[] { }; string verbosityLevel = null; string tag = null; ReportConfiguration config = new ReportConfiguration( reportFilePatterns, targetDirectory, sourceDirectories, historyDirectory, reportTypes, plugins, assemblyFilters, classFilters, fileFilters, verbosityLevel, tag); DebugFactory loggerFactory = new DebugFactory(); LoggerFactory.Configure(loggerFactory); try { if (!CommandLineManager.instance.batchmode) { EditorUtility.DisplayProgressBar(ReportGeneratorStyles.ProgressTitle.text, ReportGeneratorStyles.ProgressInfo.text, 0.4f); } if (Directory.Exists(targetDirectory)) { Directory.Delete(targetDirectory, true); } Generator generator = new Generator(); if (generator.GenerateReport(config, new Settings() { DisableRiskHotspots = !includeAdditionalMetrics }, new RiskHotspotsAnalysisThresholds())) { ResultsLogger.Log(ResultID.Log_ReportSaved, targetDirectory); CoverageRunData.instance.ReportGenerationEnd(true); // Send Analytics event (Report Only / Data & Report) CoverageAnalytics.instance.SendCoverageEvent(true); if (!CommandLineManager.instance.batchmode && coverageSettings.revealReportInFinder) { string indexHtm = CoverageUtils.JoinPaths(targetDirectory, "index.htm"); if (File.Exists(indexHtm)) { EditorUtility.RevealInFinder(indexHtm); } else { EditorUtility.RevealInFinder(targetDirectory); } } } else { ResultsLogger.Log(ResultID.Error_FailedReport); CoverageRunData.instance.ReportGenerationEnd(false); } } finally { EditorUtility.ClearProgressBar(); } }