private static void GenerateCoverageColourisedSources( string srcDir, string outputDir, ILookup <string, CodeRecord> codeRecordLookup, ISet <string> dirNames, ICollection <string> fileNodes) { var filemask = "*.cs"; if (gcovMode) { filemask = "*.*"; } var srcFiles = Directory.GetFiles(srcDir + Path.DirectorySeparatorChar, filemask, SearchOption.AllDirectories); foreach (var srcFile in srcFiles) { var srcFileInfo = new FileInfo(srcFile); var srcFileName = srcFileInfo.FullName; var dirName = srcFileInfo.Directory.FullName; var basename = Path.GetFileName(srcFileName); var relpath = GCovReader.GetRelativePath(srcDir, srcFileInfo.FullName); var reldir = Path.GetDirectoryName(relpath); if (!srcFileName.StartsWith(srcDir) || relpath.EndsWith("/Properties/AssemblyInfo.cs") || relpath.Contains("/obj/")) { continue; } var covFile = Path.Combine(outputDir, relpath + ".html"); var fileRecords = codeRecordLookup[srcFileName].ToList(); if (fileRecords.Count > 0 || !gcovMode) { GenerateCoverageColourisedFile(srcFileName, relpath, covFile, fileRecords); var totalLines = fileRecords.SelectMany(x => x.GetLines()).Distinct().Count(); var coveredLines = fileRecords.SelectMany(x => x.GetHitCounts().Keys).Distinct().Count(); var covPct = totalLines == 0 ? 0 : 100 * coveredLines / totalLines; reldir = "/" + reldir; relpath = "/" + relpath; dirNames.Add(reldir); fileNodes.Add(String.Format( "{{'id':'{0}','parent':'{1}','text':'{2} ({3}%)'}}", relpath, reldir, basename, covPct) .Replace('\'', '"')); } } }
protected void openGcovSelector(object sender, EventArgs e) { var fb = new FileChooserDialog("Select a folder containg a gcov build", this, FileChooserAction.SelectFolder, "Cancel", ResponseType.Cancel, "Select", ResponseType.Accept); fb.Response += (o, args) => fb.Hide(); fb.Run(); var topdir = fb.Filename; if (!string.IsNullOrEmpty(topdir) && Directory.Exists(topdir)) { var scanner = new GCovReader(); scanner.Scan(topdir); scanner.ProcessGCovData(); Load(scanner.Records); } }
/// <summary> /// usage: cov-srchtml.exe COVERAGEDB SRCDIR OUTPUTDIR /// </summary> /// <param name="args"></param> public static void Main(string[] args) { if (args.Contains("-h") || args.Contains("--help") || args.Length < 2) { Usage(); Environment.Exit(1); } if (args [0].Equals("--gcov")) { gcovMode = true; } else { if (!File.Exists(args [0])) { Console.Error.WriteLine("No coverage file: {0}", args [0]); Environment.Exit(1); } } if (!Directory.Exists(args[1])) { Console.Error.WriteLine("No source folder: {0}", args [1]); Environment.Exit(1); } var outputDir = args[2]; if (!Directory.Exists(outputDir)) { Directory.CreateDirectory(outputDir); } List <CodeRecord> codeRecords; CodeRecordData coverageData = null; if (gcovMode) { var scanner = new GCovReader(); scanner.Scan(Path.GetFullPath(args [1])); scanner.ProcessGCovData(); codeRecords = scanner.Records; } else { coverageData = new CodeRecordData(); coverageData.Open(args [0]); codeRecords = coverageData.Load(); } var dirNames = new HashSet <string>(); var fileNodes = new List <string>(); GenerateCoverageColourisedSources( new DirectoryInfo(args[1]).FullName, outputDir, codeRecords.ToLookup(x => x.SourceFile), dirNames, fileNodes); GenerateSourceTree(outputDir, CreateDirNodeJson(dirNames), fileNodes); GenerateIndex(outputDir); if (coverageData != null) { coverageData.Close(); } }