use glob pattern matching #31

This commit is contained in:
irongut
2022-02-19 01:35:28 +00:00
parent 0d078db7cc
commit 009a5455b8
2 changed files with 12 additions and 5 deletions
+11 -4
View File
@@ -1,5 +1,7 @@
using CommandLine; using CommandLine;
using Microsoft.Extensions.FileSystemGlobbing;
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@@ -19,8 +21,13 @@ namespace CodeCoverageSummary
{ {
try try
{ {
// use glob patterns to match files
Matcher matcher = new();
matcher.AddIncludePatterns(o.Files.ToArray());
IEnumerable<string> matchingFiles = matcher.GetResultsInFullPath(".");
// check files exist // check files exist
foreach (var file in o.Files) foreach (var file in matchingFiles)
{ {
if (!File.Exists(file)) if (!File.Exists(file))
{ {
@@ -31,13 +38,13 @@ namespace CodeCoverageSummary
// parse code coverage file // parse code coverage file
CodeSummary summary = new(); CodeSummary summary = new();
foreach (var file in o.Files) foreach (var file in matchingFiles)
{ {
Console.WriteLine($"Code Coverage File: {file}"); Console.WriteLine($"Code Coverage File: {file}");
summary = ParseTestResults(file, summary); summary = ParseTestResults(file, summary);
} }
summary.LineRate /= o.Files.Count(); summary.LineRate /= matchingFiles.Count();
summary.BranchRate /= o.Files.Count(); summary.BranchRate /= matchingFiles.Count();
if (summary.Packages.Count == 0) if (summary.Packages.Count == 0)
{ {
@@ -2,7 +2,7 @@
"profiles": { "profiles": {
"CodeCoverageSummary": { "CodeCoverageSummary": {
"commandName": "Project", "commandName": "Project",
"commandLineArgs": "--files ../../../../coverage.cobertura.xml,../../../../coverage.cobertura.xml --format=text --badge true --thresholds=\"85 90\" --fail true" "commandLineArgs": "--files **/coverage.*.xml --format=text --badge true --thresholds=\"85 90\" --fail true"
}, },
"Docker": { "Docker": {
"commandName": "Docker", "commandName": "Docker",