protected override Task <int> Execute() { var result = _coverageLoadedFileOption.Result; Uninstrumenter.Execute(result); return(Task.FromResult(0)); }
private static int Main(string[] args) { Console.OutputEncoding = Encoding.UTF8; var commandLineApplication = new CommandLineApplication(); commandLineApplication.Name = "MiniCover"; commandLineApplication.Description = "MiniCover - Code coverage for .NET Core via assembly instrumentation"; commandLineApplication.Command("instrument", command => { command.Description = "Instrument assemblies"; var workDirOption = CreateWorkdirOption(command); var parentDirOption = CreateParentdirOption(command); var includeAssembliesOption = command.Option("--assemblies", "Pattern to include assemblies [default: **/*.dll]", CommandOptionType.MultipleValue); var excludeAssembliesOption = command.Option("--exclude-assemblies", "Pattern to exclude assemblies", CommandOptionType.MultipleValue); var includeSourceOption = command.Option("--sources", "Pattern to include source files [default: **/*]", CommandOptionType.MultipleValue); var excludeSourceOption = command.Option("--exclude-sources", "Pattern to exclude source files", CommandOptionType.MultipleValue); var hitsFileOption = command.Option("--hits-file", "Hits file name [default: coverage-hits.txt]", CommandOptionType.SingleValue); var coverageFileOption = CreateCoverageFileOption(command); command.HelpOption("-h | --help"); command.OnExecute(() => { var workdir = UpdateWorkingDirectory(workDirOption); var assemblies = GetFiles(includeAssembliesOption, excludeAssembliesOption, "**/*.dll", parentDirOption); if (assemblies.Length == 0) { throw new Exception("No assemblies found"); } var sourceFiles = GetFiles(includeSourceOption, excludeSourceOption, "**/*.cs", parentDirOption); if (sourceFiles.Length == 0) { throw new Exception("No source files found"); } var hitsFile = GetHitsFile(hitsFileOption); var coverageFile = GetCoverageFile(coverageFileOption); var instrumenter = new Instrumenter(assemblies, hitsFile, sourceFiles, workdir); var result = instrumenter.Execute(); SaveCoverageFile(coverageFile, result); return(0); }); }); commandLineApplication.Command("uninstrument", command => { command.Description = "Uninstrument assemblies"; var workDirOption = CreateWorkdirOption(command); var coverageFileOption = CreateCoverageFileOption(command); command.HelpOption("-h | --help"); command.OnExecute(() => { UpdateWorkingDirectory(workDirOption); var coverageFile = GetCoverageFile(coverageFileOption); var result = LoadCoverageFile(coverageFile); Uninstrumenter.Execute(result); return(0); }); }); new ResetCommand().AddTo(commandLineApplication); new ConsoleReportCommand().AddTo(commandLineApplication); new HtmlReportCommand().AddTo(commandLineApplication); new NCoverReportCommand().AddTo(commandLineApplication); new OpenCoverReportCommand().AddTo(commandLineApplication); new CloverReportCommand().AddTo(commandLineApplication); commandLineApplication.Command("coverallsreport", command => { command.Description = "Write a coveralls-formatted JSON report to folder"; var rootPathOption = command.Option("--root-path", "Set the git root path", CommandOptionType.SingleValue); var outputOption = command.Option("--output", "Output file for coveralls report", CommandOptionType.SingleValue); var serviceJobIdOption = command.Option("--service-job-id", "Define service_job_id in coveralls json", CommandOptionType.SingleValue); var serviceNameOption = command.Option("--service-name", "Define service_name in coveralls json", CommandOptionType.SingleValue); var repoTokenOption = command.Option("--repo-token", "set the repo token", CommandOptionType.SingleValue); var commitOption = command.Option("--commit", "set the git commit id", CommandOptionType.SingleValue); var commitMessageOption = command.Option("--commit-message", "set the commit message", CommandOptionType.SingleValue); var commitAuthorNameOption = command.Option("--commit-author-name", "set the commit author name", CommandOptionType.SingleValue); var commitAuthorEmailOption = command.Option("--commit-author-email", "set the commit author email", CommandOptionType.SingleValue); var commitCommitterNameOption = command.Option("--commit-committer-name", "set the commit committer name", CommandOptionType.SingleValue); var commitCommitterEmailOption = command.Option("--commit-committer-email", "set the commit committer email", CommandOptionType.SingleValue); var branchOption = command.Option("--branch", "set the git branch", CommandOptionType.SingleValue); var remoteOption = command.Option("--remote", "set the git remote name", CommandOptionType.SingleValue); var remoteUrlOption = command.Option("--remote-url", "set the git remote url", CommandOptionType.SingleValue); var workDirOption = CreateWorkdirOption(command); var coverageFileOption = CreateCoverageFileOption(command); command.HelpOption("-h | --help"); command.OnExecute(() => { UpdateWorkingDirectory(workDirOption); var coverageFile = GetCoverageFile(coverageFileOption); var result = LoadCoverageFile(coverageFile); var output = outputOption.Value(); var rootPath = rootPathOption.HasValue() ? Path.GetFullPath(rootPathOption.Value()) : Directory.GetCurrentDirectory(); var report = new CoverallsReport( output, repoTokenOption.Value(), serviceJobIdOption.Value(), serviceNameOption.Value(), commitMessageOption.Value(), rootPath, commitOption.Value(), commitAuthorNameOption.Value(), commitAuthorEmailOption.Value(), commitCommitterNameOption.Value(), commitCommitterEmailOption.Value(), branchOption.Value(), remoteOption.Value(), remoteUrlOption.Value() ); return(report.Execute(result).Result); }); }); commandLineApplication.HelpOption("-h | --help"); commandLineApplication.OnExecute(() => { commandLineApplication.ShowHelp(); return(0); }); return(commandLineApplication.Execute(args)); }
static int Main(string[] args) { Console.OutputEncoding = Encoding.UTF8; var commandLineApplication = new CommandLineApplication(); commandLineApplication.Name = "MiniCover"; commandLineApplication.Description = "MiniCover - Code coverage for .NET Core via assembly instrumentation"; commandLineApplication.Command("instrument", command => { command.Description = "Instrument assemblies"; var workDirOption = CreateWorkdirOption(command); var includeAssembliesOption = command.Option("--assemblies", "Pattern to include assemblies [default: **/*.dll]", CommandOptionType.MultipleValue); var excludeAssembliesOption = command.Option("--exclude-assemblies", "Pattern to exclude assemblies", CommandOptionType.MultipleValue); var includeSourceOption = command.Option("--sources", "Pattern to include source files [default: **/*]", CommandOptionType.MultipleValue); var excludeSourceOption = command.Option("--exclude-sources", "Pattern to exclude source files", CommandOptionType.MultipleValue); var hitsFileOption = command.Option("--hits-file", "Hits file name [default: coverage-hits.txt]", CommandOptionType.SingleValue); var coverageFileOption = CreateCoverageFileOption(command); command.HelpOption("-h | --help"); command.OnExecute(() => { var workdir = UpdateWorkingDirectory(workDirOption); var assemblies = GetFiles(includeAssembliesOption, excludeAssembliesOption, "**/*.dll"); if (assemblies.Length == 0) { throw new Exception("No assemblies found"); } var sourceFiles = GetFiles(includeSourceOption, excludeSourceOption, "**/*.cs"); if (sourceFiles.Length == 0) { throw new Exception("No source files found"); } var hitsFile = GetHitsFile(hitsFileOption); var coverageFile = GetCoverageFile(coverageFileOption); var instrumenter = new Instrumenter(assemblies, hitsFile, sourceFiles, workdir); var result = instrumenter.Execute(); SaveCoverageFile(coverageFile, result); return(0); }); }); commandLineApplication.Command("uninstrument", command => { command.Description = "Uninstrument assemblies"; var workDirOption = CreateWorkdirOption(command); var coverageFileOption = CreateCoverageFileOption(command); command.HelpOption("-h | --help"); command.OnExecute(() => { UpdateWorkingDirectory(workDirOption); var coverageFile = GetCoverageFile(coverageFileOption); var result = LoadCoverageFile(coverageFile); Uninstrumenter.Execute(result); return(0); }); }); commandLineApplication.Command("report", command => { command.Description = "Outputs coverage report"; var workDirOption = CreateWorkdirOption(command); var coverageFileOption = CreateCoverageFileOption(command); var thresholdOption = CreateThresholdOption(command); command.HelpOption("-h | --help"); command.OnExecute(() => { UpdateWorkingDirectory(workDirOption); var coverageFile = GetCoverageFile(coverageFileOption); var threshold = GetThreshold(thresholdOption); var result = LoadCoverageFile(coverageFile); var consoleReport = new ConsoleReport(); return(consoleReport.Execute(result, threshold)); }); }); commandLineApplication.Command("htmlreport", command => { command.Description = "Write html report to folder"; var workDirOption = CreateWorkdirOption(command); var coverageFileOption = CreateCoverageFileOption(command); var thresholdOption = CreateThresholdOption(command); var outputOption = command.Option("--output", "Output folder for html report [default: coverage-html]", CommandOptionType.SingleValue); command.HelpOption("-h | --help"); command.OnExecute(() => { UpdateWorkingDirectory(workDirOption); var coverageFile = GetCoverageFile(coverageFileOption); var threshold = GetThreshold(thresholdOption); var result = LoadCoverageFile(coverageFile); var output = GetHtmlReportOutput(outputOption); var htmlReport = new HtmlReport(output); return(htmlReport.Execute(result, threshold)); }); }); commandLineApplication.Command("xmlreport", command => { command.Description = "Write an NCover-formatted XML report to folder"; var workDirOption = CreateWorkdirOption(command); var coverageFileOption = CreateCoverageFileOption(command); var thresholdOption = CreateThresholdOption(command); var outputOption = command.Option("--output", "Output file for NCover report [default: coverage.xml]", CommandOptionType.SingleValue); command.HelpOption("-h | --help"); command.OnExecute(() => { UpdateWorkingDirectory(workDirOption); var coverageFile = GetCoverageFile(coverageFileOption); var threshold = GetThreshold(thresholdOption); var result = LoadCoverageFile(coverageFile); var output = GetXmlReportOutput(outputOption); XmlReport.Execute(result, output, threshold); return(0); }); }); commandLineApplication.Command("opencoverreport", command => { command.Description = "Write an OpenCover-formatted XML report to folder"; var workDirOption = CreateWorkdirOption(command); var coverageFileOption = CreateCoverageFileOption(command); var thresholdOption = CreateThresholdOption(command); var outputOption = command.Option("--output", "Output file for OpenCover report [default: opencovercoverage.xml]", CommandOptionType.SingleValue); command.HelpOption("-h | --help"); command.OnExecute(() => { UpdateWorkingDirectory(workDirOption); var coverageFile = GetCoverageFile(coverageFileOption); var threshold = GetThreshold(thresholdOption); var result = LoadCoverageFile(coverageFile); var output = GetOpenCoverXmlReportOutput(outputOption); OpenCoverReport.Execute(result, output, threshold); return(0); }); }); commandLineApplication.Command("reset", command => { command.Description = "Reset hits count"; var workDirOption = CreateWorkdirOption(command); var coverageFileOption = CreateCoverageFileOption(command); command.HelpOption("-h | --help"); command.OnExecute(() => { UpdateWorkingDirectory(workDirOption); var coverageFile = GetCoverageFile(coverageFileOption); if (File.Exists(coverageFile)) { var result = LoadCoverageFile(coverageFile); if (File.Exists(result.HitsFile)) { File.Delete(result.HitsFile); } } return(0); }); }); commandLineApplication.HelpOption("-h | --help"); commandLineApplication.OnExecute(() => { commandLineApplication.ShowHelp(); return(0); }); return(commandLineApplication.Execute(args)); }
private static int Main(string[] args) { Console.OutputEncoding = Encoding.UTF8; var commandLineApplication = new CommandLineApplication(); commandLineApplication.Name = "MiniCover"; commandLineApplication.Description = "MiniCover - Code coverage for .NET Core via assembly instrumentation"; commandLineApplication.Command("instrument", command => { command.Description = "Instrument assemblies"; var workDirOption = CreateWorkdirOption(command); var parentDirOption = CreateParentdirOption(command); var includeAssembliesOption = command.Option("--assemblies", "Pattern to include assemblies [default: **/*.dll]", CommandOptionType.MultipleValue); var excludeAssembliesOption = command.Option("--exclude-assemblies", "Pattern to exclude assemblies", CommandOptionType.MultipleValue); var includeSourceOption = command.Option("--sources", "Pattern to include source files [default: **/*]", CommandOptionType.MultipleValue); var excludeSourceOption = command.Option("--exclude-sources", "Pattern to exclude source files", CommandOptionType.MultipleValue); var hitsFileOption = command.Option("--hits-file", "Hits file name [default: coverage-hits.txt]", CommandOptionType.SingleValue); var coverageFileOption = CreateCoverageFileOption(command); command.HelpOption("-h | --help"); command.OnExecute(() => { var workdir = UpdateWorkingDirectory(workDirOption); var assemblies = GetFiles(includeAssembliesOption, excludeAssembliesOption, "**/*.dll", parentDirOption); if (assemblies.Length == 0) { throw new Exception("No assemblies found"); } var sourceFiles = GetFiles(includeSourceOption, excludeSourceOption, "**/*.cs", parentDirOption); if (sourceFiles.Length == 0) { throw new Exception("No source files found"); } var hitsFile = GetHitsFile(hitsFileOption); var coverageFile = GetCoverageFile(coverageFileOption); var instrumenter = new Instrumenter(assemblies, hitsFile, sourceFiles, workdir); var result = instrumenter.Execute(); SaveCoverageFile(coverageFile, result); return(0); }); }); commandLineApplication.Command("uninstrument", command => { command.Description = "Uninstrument assemblies"; var workDirOption = CreateWorkdirOption(command); var coverageFileOption = CreateCoverageFileOption(command); command.HelpOption("-h | --help"); command.OnExecute(() => { UpdateWorkingDirectory(workDirOption); var coverageFile = GetCoverageFile(coverageFileOption); var result = LoadCoverageFile(coverageFile); Uninstrumenter.Execute(result); return(0); }); }); new ResetCommand().AddTo(commandLineApplication); new ConsoleReportCommand().AddTo(commandLineApplication); new HtmlReportCommand().AddTo(commandLineApplication); new NCoverReportCommand().AddTo(commandLineApplication); new OpenCoverReportCommand().AddTo(commandLineApplication); new CloverReportCommand().AddTo(commandLineApplication); commandLineApplication.HelpOption("-h | --help"); commandLineApplication.OnExecute(() => { commandLineApplication.ShowHelp(); return(0); }); return(commandLineApplication.Execute(args)); }