/// <summary> /// Executes the task. /// </summary> /// <returns> /// true if the task successfully executed; otherwise, false. /// </returns> public override bool Execute() { List <ITaskItem> results = new List <ITaskItem>(); foreach (ITaskItem file in CoverageFiles) { try { string sourceFile = file.ItemSpec; if (File.Exists(sourceFile)) { Log.LogMessageFromResources(MessageImportance.Normal, "ConvertingVSCoverageFile", sourceFile); string symbolsDir = Path.GetDirectoryName(sourceFile); if (SymbolsDirectory != null) { symbolsDir = SymbolsDirectory.ItemSpec; } using (CoverageInfo info = CoverageInfo.CreateFromFile( sourceFile, executablePaths: new [] { symbolsDir }, symbolPaths: new [] { symbolsDir })) { CoverageDS dataSet = info.BuildDataSet(null); string outputFile = Path.ChangeExtension(sourceFile, "xml"); // Unless an output dir is specified // the converted files will be stored in the same dir // as the source files, with the .XML extension if (OutputDirectory != null) { outputFile = Path.Combine(OutputDirectory.ItemSpec, Path.GetFileName(outputFile)); } dataSet.WriteXml(outputFile); Log.LogMessageFromResources(MessageImportance.Normal, "WrittenXmlCoverageFile", outputFile); } ITaskItem item = new TaskItem(file); results.Add(item); } else { Log.LogMessageFromResources(MessageImportance.Normal, "SkippingNonExistentFile", sourceFile); } } catch (Exception e) { Log.LogErrorFromException(e, true); } } ConvertedFiles = results.ToArray(); return(!Log.HasLoggedErrors); }
static void Main(string[] args) { if (args.Length == 0) { // comment once testing is done //args = new string[3] { @"\\hqomsws04t1a.dstest.drugstore.com\webroot\DsPayPalService\Release_DsPayPalService_16.02.24.01\bin\PP_CC.coverage", "PayPal", @"C:\QAAutomation\CoverageFiles\PayPal" }; //args = new string[3] { @"\\hqomsws04t1a.dstest.drugstore.com\webroot\ContentCatalogService\Dev2_ContentCatalogService_16.04.19.00\bin\CC.coverage", "ConentCatalog", @"C:\QAAutomation\CoverageFiles\ContentCatalog" }; //args = new string[3] { @"\\hqomsws04t1a.dstest.drugstore.com\webroot\ContentCatalogService\Dev2_ContentCatalogService_16.03.16.03\bin\CCProductBlurb.coverage", "ConentCatalogProductBlurb", @"C:\QAAutomation\CoverageFiles\ContentCatalog" }; //Uncomment once testing is done Console.WriteLine("Invalid Arguments......"); Console.WriteLine("Argumenst should be Coverage File Path (same as instrumented bin path), Application Name, Xml File Location"); return; } bool isXmlGenerated = false; string inputfile = args[0]; CoveragePath = Path.GetDirectoryName(inputfile); coverageFile = Path.GetFileNameWithoutExtension(inputfile); strAppList = args[1]; if (File.Exists(inputfile)) { Console.WriteLine("Coverage File Exist"); Console.WriteLine("Params:{0},{1}", inputfile, strAppList); try { binPaths = new List <string>(); binPaths.Add(CoveragePath); CoverageInfo ci = CoverageInfo.CreateFromFile(inputfile, binPaths, binPaths); CoverageDS data = ci.BuildDataSet(null); masterXmlPath = GetMasterXmlFilePath(args[2]); data.WriteXml(masterXmlPath); } catch (ImageNotFoundException infEx) { Console.WriteLine("Image not found exception is caught.." + infEx.StackTrace); //throw; } if (File.Exists(masterXmlPath)) { isXmlGenerated = true; } } else { Console.WriteLine("Coverage File does not Exist"); } if (isXmlGenerated) { Console.WriteLine("Successfully coverted to Xml File :" + isXmlGenerated); } Console.ReadLine(); }
public void ConvertToXml(string outputFile) { var master = CoverageFiles.First(); var others = CoverageFiles.Skip(1); CoverageInfo ci = CoverageInfo.CreateFromFile(master, BinaryPaths, BinaryPaths); CoverageDS data = ci.BuildDataSet(null); data.WriteXml(outputFile); }
static void Main(string[] args) { using (CoverageInfo info = CoverageInfo.CreateFromFile( "PATH_OF_YOUR_*.coverage_FILE", new string[] { @"DIRECTORY_OF_YOUR_DLL_OR_EXE" }, new string[] { })) { CoverageDS data = info.BuildDataSet(); data.WriteXml("converted.coveragexml"); } }
static int Main(string[] args) { if (args == null || args.Length < 3) { PrintUsage(); return(2); } string coverageFilePath = args[0]; string assemblyFolderPath = args[1]; string outputFilePath = args[2]; if (string.IsNullOrEmpty(coverageFilePath)) { throw new ArgumentNullException(nameof(coverageFilePath)); } if (string.IsNullOrEmpty(assemblyFolderPath)) { throw new ArgumentNullException(nameof(assemblyFolderPath)); } if (string.IsNullOrEmpty(outputFilePath)) { throw new ArgumentNullException(nameof(outputFilePath)); } if (!File.Exists(coverageFilePath)) { System.Console.WriteLine(string.Format("Coverage file not found", coverageFilePath)); PrintUsage(); return(3); } if (!Directory.Exists(assemblyFolderPath)) { System.Console.WriteLine(string.Format("Build ouput folder not found at [{0}]", assemblyFolderPath)); PrintUsage(); return(4); } if (File.Exists(outputFilePath)) { File.Delete(outputFilePath); } using (CoverageInfo info = CoverageInfo.CreateFromFile(coverageFilePath, new string[] { assemblyFolderPath }, new string[] { })) { CoverageDS data = info.BuildDataSet(); data.WriteXml(outputFilePath); } return(0); }
static int Main(string[] args) { try { if (args.Length != 5) { Console.Error.WriteLine("Usage: CoverageReader <input coverage> <bin folder> <filter> <stylesheet> <output xml>"); return(-1); } string inputFile = args[0]; string binFolder = args[1]; string mask = args[2]; string xsl = args[3]; string outputFile = args[4]; Console.WriteLine($"Converting from '{inputFile}' to '{outputFile}'"); Console.WriteLine($" using bin folder: '{binFolder}'"); Console.WriteLine($" stylesheet: '{xsl}'"); Console.WriteLine($" filter: '{mask}'"); Console.WriteLine(); using (CoverageInfo info = CoverageInfo.CreateFromFile(inputFile, new[] { binFolder }, new[] { binFolder })) { CoverageDS data = info.BuildDataSet(); using (var w = new XmlTextWriter(outputFile, Encoding.UTF8)) { w.WriteProcessingInstruction("xml-stylesheet", "type=\"text/xsl\" href=\"" + xsl + "\""); data.WriteXml(w); } Console.WriteLine("File written."); Console.WriteLine($"Analysing {inputFile}..."); var classesDataTable = data.Tables.Cast <DataTable>().First(dt => dt.TableName == "Class"); var classes = DataTableToDict(classesDataTable); var coverage = CalculateCoverage(classes, mask); Console.WriteLine("Unit test coverage:"); Console.WriteLine(" {0:0.00}% blocks", coverage.Item1); Console.WriteLine(" {0:0.00}% lines", coverage.Item2); if (System.Diagnostics.Debugger.IsAttached) { Console.WriteLine("Press any key to exit."); Console.ReadLine(); } return(0); } } catch (Exception e) { Console.Error.WriteLine(e); return(1); } }
private static void convert(string filePath) { using (CoverageInfo info = CoverageInfo.CreateFromFile( filePath, new string[] { @"C:\repos\ConsoleApp2\UnitTestProject1\bin\Debug" }, new string[] { })) { CoverageDS data = info.BuildDataSet(); data.WriteXml("TestResults.coveragexml"); } }
static int Main(string[] args) { if (args.Length < 2) { Console.WriteLine("Coverage Convert - reads VStest binary code coverage data, and outputs it in XML format."); Console.WriteLine("Usage: ConverageConvert <destinationfile> <sourcefile1> <sourcefile2> ... <sourcefileN>"); return(1); } string destinationFile = args[0]; //destinationFile = @"C:\TestResults\MySuperMergedCoverage.coverage.converted.to.xml"; List <string> sourceFiles = new List <string>(); //files.Add(@"C:\MyCoverage1.coverage"); //files.Add(@"C:\MyCoverage2.coverage"); //files.Add(@"C:\MyCoverage3.coverage"); /* get all the file names EXCEPT the first one */ for (int i = 1; i < args.Length; i++) { sourceFiles.Add(args[i]); } CoverageInfo mergedCoverage; try { mergedCoverage = JoinCoverageFiles(sourceFiles); } catch (Exception e) { Console.WriteLine("Error opening coverage data: {0}", e.Message); return(1); } CoverageDS data = mergedCoverage.BuildDataSet(); try { data.WriteXml(destinationFile); } catch (Exception e) { Console.WriteLine("Error writing to output file: {0}", e.Message); return(1); } return(0); }
static void Main(string[] args) { var pathToCoverageFile = args[0]; var pathToCoverageXmlFile = Path.Combine( Path.GetDirectoryName(pathToCoverageFile), Path.GetFileNameWithoutExtension(pathToCoverageFile) + ".coveragexml"); using (CoverageInfo info = CoverageInfo.CreateFromFile(pathToCoverageFile)) { CoverageDS data = info.BuildDataSet(); data.WriteXml(pathToCoverageXmlFile); } }
public void convertCoverageFileToXmlFile(string fileName) { string coverage_file_path = @"D:\afl\mupdf\platform\win32\Release\coverage_ift\"; string mupdf_x86_path = @"D:\afl\mupdf\platform\win32\Release\mupdf.exe"; string mupdf_x64_path = @"D:\afl\mupdf\platform\win32\x64\Release\mupdf.exe"; string coverage_xml_path = @"D:\afl\mupdf\platform\win32\Release\coverage_ift\temp1.coverage.coveragexml"; using (CoverageInfo info = CoverageInfo.CreateFromFile(coverage_file_path + fileName, new string[] { mupdf_x64_path }, new string[] { })) { CoverageDS data = info.BuildDataSet(); data.WriteXml(coverage_xml_path); } Console.WriteLine("Start2"); readCodeCoverage(fileName); }
static void Main(string[] args) { /* * pathCoverageFile: Coverage file need to convert to xml * pathOutputXMLFile: Coveragexml file coverted from .coverage file */ string pathCoverageFile = args[0]; string pathOutputXMLFile = args[1]; using (CoverageInfo info = CoverageInfo.CreateFromFile( pathCoverageFile, new string[] { @"DIRECTORY_OF_YOUR_DLL_OR_EXE" }, new string[] { })) { CoverageDS data = info.BuildDataSet(); data.WriteXml(pathOutputXMLFile); } }
static void Main(string[] args) { //Console.WriteLine("Hello World!"); if (args.Length != 2) { Console.WriteLine("Coverage Convert - reads VStest binary code coverage data, and outputs it in XML format."); Console.WriteLine("Usage: ConverageConvert <sourcefile> <destinationfile>"); return(1); } CoverageInfo info; string path; try { path = System.IO.Path.GetDirectoryName(args[0]); info = CoverageInfo.CreateFromFile(args[0], new string[] { path }, new string[] { }); } catch (Exception e) { Console.WriteLine("Error opening coverage data: {0}", e.Message); return(1); } CoverageDS data = info.BuildDataSet(); try { data.WriteXml(args[1]); } catch (Exception e) { Console.WriteLine("Error writing to output file: {0}", e.Message); return(1); } return(0); }
protected override void ExecuteTask() { try { if (File.Exists(CoverageFile)) { Log(Level.Info, "Converting Visual Studio coverage file {0}", CoverageFile); string symbolsDir = SymbolsDirectory ?? Path.GetDirectoryName(CoverageFile); using (CoverageInfo info = CoverageInfo.CreateFromFile( CoverageFile, executablePaths: new [] { symbolsDir }, symbolPaths: new [] {symbolsDir})) { CoverageDS dataSet = info.BuildDataSet(null); string outputFile = Path.ChangeExtension(CoverageFile, "xml"); // Unless an output dir is specified // the converted files will be stored in the same dir // as the source files, with the .XML extension if (OutputDirectory != null) { outputFile = Path.Combine(OutputDirectory, Path.GetFileName(outputFile)); } dataSet.WriteXml(outputFile); Log(Level.Info, "Written XML coverage file {0}", outputFile); } } else { Log(Level.Error, "{0} does not exist, cannot generate code coverage file", CoverageFile); } } catch (Exception e) { Log(Level.Error, "Exception generating code coverage XML: {0}", e.Message); } }
/// <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)); } }
/// <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(Path.GetTempPath(), 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.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)); } }