public StackTraceElement(string line, CoverageDS CoverageData) { // <pex> if (line == (string)null) throw new ArgumentNullException("line"); if (CoverageData == (CoverageDS)null) throw new ArgumentNullException("CoverageData"); // </pex> this.line = line; Regex r = new Regex("\\s+at\\s+(.+)\\.(.+\\))(\\s+in\\s+(.+):line\\s(\\d+))?"); Match m = r.Match(line); if(m.Success) { Class = m.Groups[1].Value; Method = m.Groups[2].Value; if(m.Groups[3].Success) { FileName = m.Groups[4].Value; LineNumber = uint.Parse(m.Groups[5].Value); Lines = (from file in CoverageData.SourceFileNames from ln in CoverageData.Lines where file.SourceFileName.Equals(FileName) && ln.LnStart <= LineNumber && ln.LnEnd >= LineNumber && ln.SourceFileID == file.SourceFileID select ln).ToList(); IsCovered = Lines.Any(); } } else { throw new ArgumentException("Not a valid stack trace line"); } }
private static void Main(string[] args) { Int64 lines_covered = 0; Int64 lines_partially_covered = 0; Int64 lines_not_covered = 0; string breakdown_percent_not_covered = ""; string breakdown_lines_not_covered = ""; string unit_names = ""; DirectoryInfo directory = new DirectoryInfo(args[0]); Console.WriteLine(directory.FullName); FileInfo[] files = directory.GetFiles("*.coverage"); foreach (FileInfo file in files) { Console.WriteLine("Analysing " + file.Name); Regex file_regex = new Regex(@"^(.+?)(_tests?)+.exe.coverage"); Match file_match = file_regex.Match(file.Name); string tested_unit = file_match.Groups[1].ToString(); Regex regex; if (tested_unit == "ksp_plugin") { Console.WriteLine("Covering principia::" + tested_unit + " as well as extern \"C\" interface functions" + " (of the form ::principia__Identifier)"); regex = new Regex("^principia(::" + tested_unit + "|__)"); } else { Console.WriteLine("Covering principia::" + tested_unit); regex = new Regex("^principia::" + tested_unit); } Regex ignored_files_regex = new Regex(@"((_test\.cpp|" + @"\.generated\.cc|" + @"\.generated\.h|" + @"\.pb\.h|" + @"\.pb\.cc)$|" + @"\\mock_)"); var covered = new Dictionary <CodeLine, UInt32>(); using (CoverageInfo info = CoverageInfo.CreateFromFile(file.FullName)) { CoverageDS dataset = info.BuildDataSet(); foreach (CoverageDSPriv.LinesRow lines in dataset.Lines) { if (regex.Match(lines.MethodRow.MethodName).Success&& !ignored_files_regex.Match( dataset.GetSourceFileName(lines)).Success) { var code_line = new CodeLine { file = dataset.GetSourceFileName(lines), line_number = lines.LnStart }; if (lines.LnStart != lines.LnEnd) { Console.WriteLine("lines.LnStart != lines.LnEnd"); return; } if (covered.ContainsKey(code_line)) { covered[code_line] = Math.Min(covered[code_line], lines.Coverage); } else { covered.Add(code_line, lines.Coverage); } } } } Int64 subtotal_lines = covered.Count; Int64 subtotal_not_covered = 0; foreach (var pair in covered) { if (pair.Value > 1) { ++subtotal_not_covered; ++lines_not_covered; Console.WriteLine(pair.Key.file + ":" + pair.Key.line_number); } else if (pair.Value == 1) { ++lines_partially_covered; } else { ++lines_covered; } } CommaSeparatedAppend(ref breakdown_lines_not_covered, subtotal_not_covered.ToString()); CommaSeparatedAppend( ref breakdown_percent_not_covered, (((double)subtotal_not_covered / (double)subtotal_lines) * 100.0).ToString()); CommaSeparatedAppend(ref unit_names, tested_unit); } Int64 total = lines_partially_covered + lines_covered + lines_not_covered; Console.WriteLine("Covered : " + ValueAndPercentage(lines_partially_covered + lines_covered, total)); Console.WriteLine(" Partially : " + ValueAndPercentage(lines_partially_covered, total)); Console.WriteLine(" Completely : " + ValueAndPercentage(lines_covered, total)); Console.WriteLine("Not Covered : " + ValueAndPercentage(lines_not_covered, total)); File.WriteAllText( Path.Combine(directory.FullName, "jenkins_percent_coverage.csv"), "not covered, partially covered, fully covered\n" + ((double)lines_not_covered / (double)total) * 100.0 + ", " + ((double)lines_partially_covered / (double)total) * 100.0 + ", " + ((double)lines_covered / (double)total) * 100.0); File.WriteAllText( Path.Combine(directory.FullName, "jenkins_lines_coverage.csv"), "not covered, partially covered, fully covered\n" + lines_not_covered + ", " + lines_partially_covered + ", " + lines_covered); File.WriteAllText( Path.Combine(directory.FullName, "jenkins_lines_coverage_breakdown.csv"), unit_names + "\n" + breakdown_lines_not_covered); File.WriteAllText( Path.Combine(directory.FullName, "jenkins_percent_coverage_breakdown.csv"), unit_names + "\n" + breakdown_percent_not_covered); }
public void FindCoverage(SourceClassDetail source, CoverageDS codeCoverage) { if (codeCoverage != null) { source.ExternalCoveredClasses.Clear(); source.ExternalCoveredClasses.AddRange(FindExternalCoveredClasses(source, codeCoverage)); var parentClassName = string.Join(".", source.Claz.Syntax.Ancestors <ClassDeclarationSyntax>().Select(x => x.ClassName())); var className = $"{parentClassName}.{source.Claz.Syntax.ClassName()}".TrimStart('.'); var coverages = codeCoverage .Class .Where(x => x.NamespaceTableRow.NamespaceName == source.Claz.Syntax.NameSpace() && (x.ClassName == className || x.ClassName.StartsWith($"{className}.{GenericMethodStart}") || x.ClassName.StartsWith($"{className}{GenericMethodStart}"))).ToList(); if (coverages.Any()) { source.Coverage = new Coverage { LinesCovered = (uint)coverages.Sum(x => x.LinesCovered), LinesNotCovered = (uint)coverages.Sum(x => x.LinesNotCovered), BlocksCovered = (uint)coverages.Sum(x => x.BlocksCovered), BlocksNotCovered = (uint)coverages.Sum(x => x.BlocksNotCovered) }; var methodsWithCoverage = new List <MethodDetail>(); PrintClassCoverage(source, className); foreach (var coverage in coverages) { var coverageClassName = coverage.ClassName; var methods = codeCoverage .Method.Where(x => x.ClassKeyName == coverage.ClassKeyName) .ToList(); foreach (CoverageDSPriv.MethodRow mCoverage in methods) { var methodFullName = mCoverage.MethodFullName; if (methodFullName.StartsWith(GenericMethodStart) && methodFullName.Contains(GenericMethodEnd)) { var startIndex = methodFullName.IndexOf(GenericMethodStart, StringComparison.InvariantCulture) + 1; var length = methodFullName.IndexOf(GenericMethodEnd, StringComparison.InvariantCulture) - 1; methodFullName = $"{methodFullName.Substring(startIndex, length)}("; } var numberOfOverloadedMethods = source.MethodDetails.Where(x => methodFullName.StartsWith($"{x.Method.MethodName()}(") || methodFullName.StartsWith($"set_{x.Method.MethodName()}(") || methodFullName.StartsWith($"get_{x.Method.MethodName()}(")).ToList(); MethodDetail methodDetail = null; if (numberOfOverloadedMethods.Count == 1) { methodDetail = numberOfOverloadedMethods.First(); } if (methodDetail == null) { methodDetail = source.MethodDetails .FirstOrDefault(x => x.Method.MethodWithParameterTypes() == methodFullName.Replace("System.", string.Empty)); } string methodName; if (methodDetail == null && coverageClassName.Contains(GenericMethodStart)) { var startIndex = coverageClassName.IndexOf(GenericMethodStart, StringComparison.InvariantCulture); var endIndex = coverageClassName.IndexOf(GenericMethodEnd, StringComparison.InvariantCulture); methodName = coverageClassName.Substring(startIndex + 1, endIndex - startIndex - 1); methodDetail = source.MethodDetails.FirstOrDefault(x => x.Method.MethodName().Equals(methodName)); } if (methodDetail != null) { if (methodDetail.Coverage == null) { methodDetail.Coverage = new Coverage(); } methodDetail.Coverage = new Coverage { LinesCovered = methodDetail.Coverage.LinesCovered + mCoverage.LinesCovered, LinesNotCovered = methodDetail.Coverage.LinesNotCovered + mCoverage.LinesNotCovered, BlocksCovered = methodDetail.Coverage.BlocksCovered + mCoverage.BlocksCovered, BlocksNotCovered = methodDetail.Coverage.BlocksNotCovered + mCoverage.BlocksNotCovered }; methodDetail.Lines.AddRange(mCoverage.GetLinesRows()); methodsWithCoverage.Add(methodDetail); } } } methodsWithCoverage = methodsWithCoverage.GroupBy(x => x.Method.MethodWithParameterTypes()).Select(x => { var methodDetail = new MethodDetail { Coverage = x.Last().Coverage, Method = x.First().Method, MethodName = x.First().MethodName }; methodDetail.Lines.AddRange(x.First().Lines); return(methodDetail); }).ToList(); foreach (var methodDetail in methodsWithCoverage) { var methodName = methodDetail.Method.MethodWithParameterTypes(); Output += $"{methodName} {methodDetail.Coverage.ToString().Print(color: Colors.BlueViolet)}".PrintWithPreTagWithMarginImportant(); } } PrintExternalCoveredClasses(source); } }
/// <summary> /// Main process /// </summary> /// <param name="args">Command Line Arguments</param> static void Main(string[] args) { bool result = false; try { // cosole write header. ConsoleWriteHeader(); if (IsConsoleWriteHelp(args)) { ConsoleWriteHelp(); return; } string inputPath = ConvertArg(args, ARGS_PREFIX_INPUT_PATH); string outputPath = ConvertArg(args, ARGS_PREFIX_OUTPUT_PATH); string symbolsDir = ConvertArg(args, ARGS_PREFIX_SYMBOLS_DIR); string exeDir = ConvertArg(args, ARGS_PREFIX_EXE_DIR); string xslPath = ConvertArg(args, ARGS_PREFIX_XSL_PATH); string tmpPath = Path.Combine(".\\", FILE_NAME_WORK); if (!CreateWorkFile(tmpPath, inputPath)) { return; } IList <string> symPaths = new List <string>(); IList <string> exePaths = new List <string>(); if (!string.IsNullOrWhiteSpace(symbolsDir)) { symPaths.Add(symbolsDir); } if (!string.IsNullOrWhiteSpace(exeDir)) { exePaths.Add(exeDir); } CoverageInfo ci = CoverageInfo.CreateFromFile(tmpPath, exePaths, symPaths); CoverageDS data = ci.BuildDataSet(null); string outputWk = outputPath; if (string.IsNullOrEmpty(outputWk)) { outputWk = Path.ChangeExtension(inputPath, "xml"); } Console.WriteLine("output file: {0}", outputWk); if (string.IsNullOrEmpty(xslPath)) { data.ExportXml(outputWk); } else { WriteTransformXml(data, outputWk, xslPath); } result = true; Console.WriteLine("convert success."); } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { Environment.Exit((result) ? (0) : (1)); } }
/// <summary> /// Main process /// </summary> /// <param name="args">Command Line Arguments</param> static void Main(string[] args) { bool result = false; try { // cosole write header. ConsoleWriteHeader(); if (IsConsoleWriteHelp(args)) { ConsoleWriteHelp(); return; } string inputPath = ConvertArg(args, ARGS_PREFIX_INPUT_PATH); string outputPath = ConvertArg(args, ARGS_PREFIX_OUTPUT_PATH); string symbolsDir = ConvertArg(args, ARGS_PREFIX_SYMBOLS_DIR); string exeDir = ConvertArg(args, ARGS_PREFIX_EXE_DIR); string xslPath = ConvertArg(args, ARGS_PREFIX_XSL_PATH); if (!File.Exists(inputPath)) { Console.WriteLine("input file not found. ({0})", inputPath); return; } Console.WriteLine("input file: {0}", inputPath); string inputDir = Path.GetDirectoryName(inputPath); CoverageInfoManager.SymPath = (string.IsNullOrEmpty(symbolsDir)) ? (inputDir) : (symbolsDir); CoverageInfoManager.ExePath = (string.IsNullOrEmpty(exeDir)) ? (inputDir) : (exeDir); CoverageInfo ci = CoverageInfoManager.CreateInfoFromFile(inputPath); CoverageDS data = ci.BuildDataSet(null); string outputWk = outputPath; if (string.IsNullOrEmpty(outputWk)) { outputWk = Path.ChangeExtension(inputPath, "xml"); } Console.WriteLine("output file: {0}", outputWk); if (string.IsNullOrEmpty(xslPath)) { data.WriteXml(outputWk); } else { WriteTransformXml(data, outputWk, xslPath); } result = true; Console.WriteLine("convert success."); } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { Environment.Exit((result) ? (0) : (1)); } }
public SourceClass(CoverageDS coverage, CoverageDSPriv.ClassRow classRow) { CoverageStats = new CoverageStats(classRow); Name = classRow.ClassName; _methodRows = classRow.GetMethodRows(); }
private static void WriteCoverageOutputAsXml(CoverageInfo coverageInfo, string coverageOutputXmlFilename) { CoverageDS data = coverageInfo.BuildDataSet(null); data.ExportXml(coverageOutputXmlFilename); }
private static void Main(string[] args) { string coverageFile = args[0]; // Create a coverage info object from the file CoverageInfo ci = CoverageInfo.CreateFromFile(coverageFile); CoverageDS summary = ci.BuildDataSet(null); BigInteger coveredBlocks = 0; BigInteger coveredLines = 0; BigInteger totalBlocks = 0; BigInteger totalLines = 0; DirectoryInfo htmlRoot = new DirectoryInfo(Path.Combine(Directory.GetCurrentDirectory(), "CoverageReport"));// Directory.CreateDirectory("html"); htmlRoot.Create(); CoverageDsParser parser = new CoverageDsParser(coverageFile); TeamCityHtmlReport report = new TeamCityHtmlReport(parser.Assemblies); report.WriteTo(htmlRoot); //foreach (CoverageDSPriv.SourceFileNamesRow fileRow in summary.SourceFileNames) //{ // int currentLineNumber = 1; // FileInfo info = new FileInfo(fileRow.SourceFileName); // StreamReader fileReader = new StreamReader(info.FullName); // StringBuilder builder = new StringBuilder(); // builder.Append("<html id=\"htmlId\">"); // builder.Append("<head>"); // builder.AppendFormat("<title>{0}</title>", "Coverage Report > " + fileRow.SourceFileName); // builder.AppendFormat("<style type=\"text/css\">{0}</style>", // "@import \"../../../.css/coverage.css\"; @import \"../../../.css/idea.css\";"); // builder.AppendFormat("<script type=\"text/javascript\" src=\"../../../.js/highlight.pack.js\"></script>"); // builder.Append("</head>"); // builder.Append("<body>"); // string sourceType = "cpp"; // if (info.Extension == ".cpp" || info.Extension == ".h") // { // } else if (info.Extension == ".cs") // { // sourceType = "cs"; // } // builder.AppendFormat("<pre><div class=\"sourceCode {0}\" id=\"sourceCode\"", sourceType); // CoverageDSPriv.SourceFileNamesRow row = fileRow; // foreach (CoverageDSPriv.LinesRow lineRow in summary.Lines.Where(line=>line.SourceFileID == row.SourceFileID).OrderBy(line=>line.LnStart)) // { // while (currentLineNumber < lineRow.LnStart) // { // builder.AppendFormat("<i class=\"no-highlight\">{0}</i> {1}" + Environment.NewLine, currentLineNumber++, fileReader.ReadLine()); // } // string cssClass = "nc"; // switch (lineRow.Coverage) // { // case 1: // cssClass = "pc"; // break; // case 2: // cssClass = "nc"; // break; // default: // cssClass = "fc"; // break; // } // builder.AppendFormat( // "<b class=\"{2}\"><i class=\"no-highlight\">{0}</i> {1}</b>" + Environment.NewLine, // currentLineNumber++, fileReader.ReadLine(), // cssClass); // } // while (fileReader.Peek() != -1) // { // builder.AppendFormat("<i class=\"no-highlight\">{0}</i> {1}" + Environment.NewLine, currentLineNumber++, fileReader.ReadLine()); // } // builder.Append("</pre></div>"); // builder.AppendFormat("<script type=\"text/javascript\">{0}</script>", "(function() {var codeBlock = document.getElementById('sourceCode');if (codeBlock) {hljs.highlightBlock(codeBlock);}})();"); // builder.Append("</body>"); // builder.Append("</html>"); // string html = builder.ToString(); // StreamWriter writer = new StreamWriter(Path.Combine(htmlRoot.FullName, new FileInfo(fileRow.SourceFileName).Name + ".html")); // writer.Write(html); // writer.Close(); //} foreach (CoverageDSPriv.ModuleRow moduleRow in summary.Module.Rows) { BigInteger blocksCovered = moduleRow.BlocksCovered; BigInteger blocksNotCovered = moduleRow.BlocksNotCovered; coveredBlocks += blocksCovered; totalBlocks += blocksCovered + blocksNotCovered; BigInteger linesCovered = moduleRow.LinesCovered; BigInteger linesPartiallyCovered = moduleRow.LinesPartiallyCovered; BigInteger linesNotCovered = moduleRow.LinesNotCovered; coveredLines += linesCovered + linesPartiallyCovered; totalLines += linesCovered + linesPartiallyCovered + linesNotCovered; } BigInteger coveredMethods = 0; BigInteger totalMethods = summary.Method.Rows.Count; foreach (CoverageDSPriv.MethodRow methodRow in summary.Method.Rows) { float coverage = (methodRow.LinesCovered + methodRow.LinesPartiallyCovered) / (methodRow.LinesCovered + methodRow.LinesPartiallyCovered + (float)methodRow.LinesNotCovered); coveredMethods += (coverage > MethodCoverageThreshold) ? 1 : 0; } float blockCoverage = totalBlocks == 0 ? 0 : ((uint)((coveredBlocks * TwoDecimalPlaces) / totalBlocks)) / 10000f; float lineCoverage = totalLines == 0 ? 0 : ((uint)((coveredLines * TwoDecimalPlaces) / totalLines)) / 10000f; float methodCoverage = totalMethods == 0 ? 0 : ((uint)((coveredMethods * TwoDecimalPlaces) / totalMethods)) / 10000f; XmlDocument doc = new XmlDocument(); XmlElement rootElement = doc.CreateElement("build"); XmlElement blockCoverageNode = CreateBlockCoverageElement(doc, blockCoverage); XmlElement lineCoverageNode = CreateLineCoverageElement(doc, lineCoverage); XmlElement methodCoverageNode = CreateMethodCoverageElement(doc, methodCoverage); XmlElement totalCoveredLinesNode = CreateCoveredLinesElement(doc, (uint)coveredLines); XmlElement totalLinesNode = CreateTotalLinesElement(doc, (uint)totalLines); XmlElement totalCoveredMethodsNode = CreateCoveredMethodsElement(doc, (uint)coveredMethods); XmlElement totalMethodsNode = CreateTotalMethodsElement(doc, (uint)totalMethods); rootElement.AppendChild(blockCoverageNode); rootElement.AppendChild(lineCoverageNode); rootElement.AppendChild(methodCoverageNode); rootElement.AppendChild(totalCoveredLinesNode); rootElement.AppendChild(totalLinesNode); rootElement.AppendChild(totalCoveredMethodsNode); rootElement.AppendChild(totalMethodsNode); doc.AppendChild(rootElement); using (var writer = new StreamWriter("teamcity-info.xml")) { writer.Write(doc.OuterXml); } }
public ProjectElement Parse(String[] inputfiles) { ProjectElement PROJECT = new ProjectElement("new_project", 123323230); // Open file using (CoverageInfo info = JoinCoverageFiles(inputfiles)) { CoverageDS dataSet = info.BuildDataSet(); Dictionary <String, PackageElement> packages = new Dictionary <String, PackageElement>(); Dictionary <uint, FileElement> files = new Dictionary <uint, FileElement>(); // Namespaces DataTable namespacesTable = dataSet.Tables["NameSpaceTable"]; DataTable classesTable = dataSet.Tables["Class"]; DataTable filesTable = dataSet.Tables["SourceFileNames"]; CreateIndexPackages(PROJECT, namespacesTable, packages); CreateIndexFiles(filesTable, files); foreach (DataRow iclass in classesTable.Rows) { DataRow[] childRows = iclass.GetChildRows("Class_Method"); // Since it's one class per file (at least) declare // file here and add it to the class. uint fileid = 0; // uint classlocs = 0; uint covered_methods = 0; FileElement fe = null; foreach (DataRow imethod in childRows) { // Method starting line uint linenum = 0; // Get First Line in class DataRow[] childRows2 = imethod.GetChildRows("Method_Lines"); //if(childRows2.Length > 0) foreach (DataRow iline in childRows2) { LineElement le = null; uint coverage = iline.Field <uint>("Coverage"); if (linenum == 0) { fileid = iline.Field <uint>("SourceFileID"); string methodname = System.Security.SecurityElement.Escape((string)imethod["MethodName"]); linenum = iline.Field <uint>("LnStart"); le = new LineElement(linenum, "method", methodname, coverage); } else { linenum = iline.Field <uint>("LnStart"); le = new LineElement(linenum, "stmt", "", coverage); } // If the file doesn't exists in our report, we'll // just ignore this information if (files.ContainsKey(fileid)) { fe = files[fileid]; fe.AddLine(le); } } // Count how many methods covered we have if ((uint)imethod["LinesCovered"] > 0) { covered_methods++; } } uint totallines = (uint)iclass["LinesCovered"] + (uint)iclass["LinesNotCovered"] + (uint)iclass["LinesPartiallyCovered"]; uint complexity = 1; uint methods = (uint)childRows.Length; uint statements = totallines - methods; uint covered_statements = (uint)iclass["LinesCovered"] - covered_methods; uint conditionals = 0; uint covered_conditionals = 0; ClassElement ce = new ClassElement(System.Security.SecurityElement.Escape((string)iclass["ClassName"])); ce.Metrics = new ClassMetrics(complexity, statements, covered_statements, conditionals, covered_conditionals, methods, covered_methods); if (fe != null) { if (!fe.GetClasses().Contains(ce)) { fe.AddClass(ce); } if (packages.ContainsKey((string)iclass["NamespaceKeyName"])) { PackageElement pe = packages[(string)iclass["NamespaceKeyName"]]; if (!pe.GetFiles().Contains(fe)) { pe.AddFile(fe); } } } } } return(PROJECT); }
static void Main(string[] args) { if ((args.Length > 4) || (args.Length < 3)) { Console.WriteLine("CoverageTool [action] file1 file2 [options]"); Console.WriteLine("actions:"); Console.WriteLine(" diff compare coverage files"); Console.WriteLine(" merge merge coverage files"); Console.WriteLine("options:"); Console.WriteLine("-ignoremodulenamecheck : by default module names should match to considered for diff checking."); return; } bool ignoremodulenamecheck = false; if ((args.Length == 4) && (args[3] == "-ignoremodulenamecheck")) { ignoremodulenamecheck = true; } if (args[0] == "merge") { CoverageDS dataSet_1 = new CoverageDS(); dataSet_1.ImportXml(args[1]); CoverageDS dataSet_2 = new CoverageDS(); dataSet_2.ImportXml(args[2]); CoverageDS dataSet_3 = CoverageDS.Join(dataSet_1, dataSet_2); string fname = "merge_" + Path.GetFileName(args[1]) + "_" + Path.GetFileName(args[2]) + ".xml"; dataSet_3.ExportXml(fname); Console.WriteLine($"Merge of two coverage files created as {fname}"); return; } CoverageDS dataSet1 = new CoverageDS(); dataSet1.ImportXml(args[1]); CoverageDS dataSet2 = new CoverageDS(); dataSet2.ImportXml(args[2]); List <string> validModules = new List <string>(); foreach (CoverageDSPriv.ModuleRow module in dataSet1.Module) { DataRow[] rows_module = dataSet2.Module.Select($"ModuleName = '{module.ModuleName.Replace("'", "''")}'"); if (rows_module.Length > 0) { validModules.Add(module.ModuleName); } } Console.WriteLine("Following modules are only checked : "); foreach (var module in validModules) { Console.WriteLine(module); } Console.WriteLine("\n\n"); bool printMissing = false; string printMissingMessage = $"Following Modules from {args[1]} are not compared :\n"; foreach (CoverageDSPriv.ModuleRow module in dataSet1.Module) { if (!validModules.Contains(module.ModuleName)) { printMissingMessage = printMissingMessage + module.ModuleName + "\n"; printMissing = true; } } if (printMissing) { Console.WriteLine(printMissingMessage + "\n\n"); } printMissingMessage = $"Following Modules from {args[2]} are not compared :\n"; foreach (CoverageDSPriv.ModuleRow module in dataSet2.Module) { if (!validModules.Contains(module.ModuleName)) { printMissingMessage = printMissingMessage + module.ModuleName + "\n"; printMissing = true; } } if (printMissing) { Console.WriteLine(printMissingMessage + "\n\n"); } foreach (CoverageDSPriv.MethodRow method in dataSet1.Method) { if (method.MethodName.StartsWith(".")) { continue; } String title = ":" + method.MethodName; DataRow[] rows = dataSet2.Method.Select($"MethodName = '{method.MethodName.Replace("'", "''")}'"); try { DataRow[] rows_class = dataSet1.Class.Select($"ClassKeyName = '{method.ClassKeyName.Replace("'", "''")}'"); DataRow[] rows_namespaces = dataSet1.NamespaceTable.Select($"NamespaceKeyName = '{((CoverageDSPriv.ClassRow)rows_class[0]).NamespaceKeyName.Replace("'", "''")}'"); if ((!ignoremodulenamecheck) && (!validModules.Contains(((CoverageDSPriv.NamespaceTableRow)rows_namespaces[0]).ModuleName))) { continue; } DataRow[] rows_lines = dataSet1.Lines.Select($"MethodKeyName = '{method.MethodKeyName.Replace("'", "''")}'"); DataRow[] rows_sources = dataSet1.SourceFileNames.Select($"SourceFileID = '{((CoverageDSPriv.LinesRow)rows_lines[0]).SourceFileID}'"); title = Path.GetFileName(((CoverageDSPriv.SourceFileNamesRow)rows_sources[0]).SourceFileName) + ":" + method.MethodName; } catch { } if (rows.Length > 1) { //Console.WriteLine(method.MethodName); } else if (rows.Length == 0) { Console.WriteLine($"=======1======== {title} =========2===="); Console.WriteLine($"Only here | Not used here"); } else //if = 1 { CoverageDSPriv.MethodRow row = (CoverageDSPriv.MethodRow)rows[0]; if ((row.LinesCovered != method.LinesCovered) || (row.LinesNotCovered != method.LinesNotCovered) || (row.LinesPartiallyCovered != method.LinesPartiallyCovered)) { Console.WriteLine($"=======1======== {title} =========2===="); Console.WriteLine($"Lines covered : {method.LinesCovered} | {row.LinesCovered}"); Console.WriteLine($"Lines not covered : {method.LinesNotCovered} | {row.LinesNotCovered}"); Console.WriteLine($"Lines partially covered : {method.LinesPartiallyCovered} | {row.LinesPartiallyCovered}"); Console.WriteLine($"Blocks covered : {method.BlocksCovered} | {row.BlocksCovered}"); Console.WriteLine($"Blocks not covered : {method.BlocksNotCovered} | {row.BlocksNotCovered}"); DataRow[] dataset1_lines = dataSet1.Lines.Select($"MethodKeyName = '{method.MethodKeyName.Replace("'", "''")}' and Coverage > 0", "LnStart ASC"); DataRow[] dataset2_lines = dataSet2.Lines.Select($"MethodKeyName = '{row.MethodKeyName.Replace("'", "''")}' and Coverage > 0", "LnStart ASC"); string dataset1_lines_string = "", dataset2_lines_string = ""; uint prevCounter1 = 0; uint prevCounter2 = 0; foreach (var roww in dataset1_lines) { CoverageDSPriv.LinesRow covRow = (CoverageDSPriv.LinesRow)roww; if (covRow.LnStart - 1 == prevCounter1) { prevCounter1 = covRow.LnEnd; if (!dataset1_lines_string.EndsWith("-")) { dataset1_lines_string = dataset1_lines_string + "-"; } continue; } else { prevCounter1 = covRow.LnEnd; if (!dataset1_lines_string.EndsWith("-") && dataset1_lines_string.Length > 0) { dataset1_lines_string = dataset1_lines_string + ","; } dataset1_lines_string = dataset1_lines_string + covRow.LnStart; } } foreach (var roww in dataset2_lines) { CoverageDSPriv.LinesRow covRow = (CoverageDSPriv.LinesRow)roww; if (covRow.LnStart - 1 == prevCounter2) { prevCounter2 = covRow.LnEnd; if (!dataset2_lines_string.EndsWith("-")) { dataset2_lines_string = dataset2_lines_string + "-"; } continue; } else { prevCounter2 = covRow.LnEnd; if (!dataset2_lines_string.EndsWith("-") && dataset2_lines_string.Length > 0) { dataset2_lines_string = dataset2_lines_string + ","; } dataset2_lines_string = dataset2_lines_string + covRow.LnStart; } } Console.WriteLine($"Lines difference : {dataset1_lines_string} vs {dataset2_lines_string}"); Console.WriteLine(); } } } //now only check for things not in 1 foreach (CoverageDSPriv.MethodRow method in dataSet2.Method) { if (method.MethodName.StartsWith(".")) { continue; } DataRow[] rows = dataSet2.Method.Select($"MethodName = '{method.MethodName.Replace("'", "''")}'"); String title = ":" + method.MethodName; try { DataRow[] rows_class = dataSet2.Class.Select($"ClassKeyName = '{method.ClassKeyName.Replace("'", "''")}'"); DataRow[] rows_namespaces = dataSet2.NamespaceTable.Select($"NamespaceKeyName = '{((CoverageDSPriv.ClassRow)rows_class[0]).NamespaceKeyName.Replace("'", "''")}'"); if ((!ignoremodulenamecheck) && (!validModules.Contains(((CoverageDSPriv.NamespaceTableRow)rows_namespaces[0]).ModuleName))) { continue; } DataRow[] rows_lines = dataSet2.Lines.Select($"MethodKeyName = '{method.MethodKeyName.Replace("'", "''")}'"); DataRow[] rows_sources = dataSet2.SourceFileNames.Select($"SourceFileID = '{((CoverageDSPriv.LinesRow)rows_lines[0]).SourceFileID}'"); title = Path.GetFileName(((CoverageDSPriv.SourceFileNamesRow)rows_sources[0]).SourceFileName) + ":" + method.MethodName; } catch { } if (rows.Length > 1) { //Console.WriteLine(method.MethodName); } else if (rows.Length == 0) { Console.WriteLine($"=======1======== {title} =========2===="); Console.WriteLine($"Not used here | Only here"); } } }
/// <summary> /// Write Transform Xml /// </summary> /// <param name="data">Coverage DataSet</param> /// <param name="outputPath">Output File Path</param> /// <param name="xslPath">Xsl File Path</param> private static void WriteTransformXml(CoverageDS data, string outputPath, string xslPath) { Console.WriteLine("xsl file: {0}", xslPath); using (XmlReader reader = new XmlTextReader(new StringReader(data.GetXml()))) { using (XmlWriter writer = new XmlTextWriter(outputPath, Encoding.UTF8)) { XslCompiledTransform transform = new XslCompiledTransform(); transform.Load(xslPath); transform.Transform(reader, writer); } } }
internal void ClearCoverageData() { _data.Dispose(); _data = null; }