mirror of
https://github.com/irongut/CodeCoverageSummary.git
synced 2026-05-14 22:20:13 +02:00
formatting + cleanup
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
// This file is used by Code Analysis to maintain SuppressMessage
|
||||
// attributes that are applied to this project.
|
||||
// Project-level suppressions either have no target or are given
|
||||
// a specific target and scoped to a namespace, type, member, etc.
|
||||
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
[assembly: SuppressMessage("Performance", "RCS1197:Optimize StringBuilder.Append/AppendLine call.", Scope = "type", Target = "~T:CodeCoverageSummary.Program")]
|
||||
@@ -9,83 +9,81 @@ namespace CodeCoverageSummary
|
||||
{
|
||||
internal static class Program
|
||||
{
|
||||
// test file: /Dev/Csharp/CodeCoverageSummary/coverage.cobertura.xml
|
||||
|
||||
private static int Main(string[] args)
|
||||
{
|
||||
return Parser.Default.ParseArguments<CommandLineOptions>(args)
|
||||
.MapResult(o =>
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!File.Exists(o.Filename))
|
||||
{
|
||||
Console.WriteLine("Error: Code coverage file not found.");
|
||||
return -2; // error
|
||||
}
|
||||
.MapResult(o =>
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!File.Exists(o.Filename))
|
||||
{
|
||||
Console.WriteLine("Error: Code coverage file not found.");
|
||||
return -2; // error
|
||||
}
|
||||
|
||||
// parse code coverage file
|
||||
Console.WriteLine($"Code Coverage File: {o.Filename}");
|
||||
CodeSummary summary = ParseTestResults(o.Filename);
|
||||
if (summary == null)
|
||||
{
|
||||
Console.WriteLine("Error: Parsing code coverage file.");
|
||||
return -2; // error
|
||||
}
|
||||
else
|
||||
{
|
||||
// generate badge
|
||||
string badgeUrl = o.Badge ? GenerateBadge(summary) : null;
|
||||
// parse code coverage file
|
||||
Console.WriteLine($"Code Coverage File: {o.Filename}");
|
||||
CodeSummary summary = ParseTestResults(o.Filename);
|
||||
if (summary == null)
|
||||
{
|
||||
Console.WriteLine("Error: Parsing code coverage file.");
|
||||
return -2; // error
|
||||
}
|
||||
else
|
||||
{
|
||||
// generate badge
|
||||
string badgeUrl = o.Badge ? GenerateBadge(summary) : null;
|
||||
|
||||
// generate output
|
||||
string output;
|
||||
string fileExt;
|
||||
if (o.Format.Equals("text", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
fileExt = "txt";
|
||||
output = GenerateTextOutput(summary, badgeUrl);
|
||||
}
|
||||
else if (o.Format.Equals("md", StringComparison.OrdinalIgnoreCase) || o.Format.Equals("markdown", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
fileExt = "md";
|
||||
output = GenerateMarkdownOutput(summary, badgeUrl);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Error: Unknown output format.");
|
||||
return -2; // error
|
||||
}
|
||||
// generate output
|
||||
string output;
|
||||
string fileExt;
|
||||
if (o.Format.Equals("text", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
fileExt = "txt";
|
||||
output = GenerateTextOutput(summary, badgeUrl);
|
||||
}
|
||||
else if (o.Format.Equals("md", StringComparison.OrdinalIgnoreCase) || o.Format.Equals("markdown", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
fileExt = "md";
|
||||
output = GenerateMarkdownOutput(summary, badgeUrl);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Error: Unknown output format.");
|
||||
return -2; // error
|
||||
}
|
||||
|
||||
// output
|
||||
if (o.Output.Equals("console", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
Console.WriteLine(output);
|
||||
}
|
||||
else if (o.Output.Equals("file", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
File.WriteAllText($"code-coverage-results.{fileExt}", output);
|
||||
}
|
||||
else if (o.Output.Equals("both", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
Console.WriteLine(output);
|
||||
File.WriteAllText($"code-coverage-results.{fileExt}", output);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Error: Unknown output type.");
|
||||
return -2; // error
|
||||
}
|
||||
// output
|
||||
if (o.Output.Equals("console", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
Console.WriteLine(output);
|
||||
}
|
||||
else if (o.Output.Equals("file", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
File.WriteAllText($"code-coverage-results.{fileExt}", output);
|
||||
}
|
||||
else if (o.Output.Equals("both", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
Console.WriteLine(output);
|
||||
File.WriteAllText($"code-coverage-results.{fileExt}", output);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Error: Unknown output type.");
|
||||
return -2; // error
|
||||
}
|
||||
|
||||
return 0; // success
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Error: {ex.GetType()} - {ex.Message}");
|
||||
return -3; // unhandled error
|
||||
}
|
||||
},
|
||||
errs => -1); // invalid arguments
|
||||
return 0; // success
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Error: {ex.GetType()} - {ex.Message}");
|
||||
return -3; // unhandled error
|
||||
}
|
||||
},
|
||||
_ => -1); // invalid arguments
|
||||
}
|
||||
|
||||
private static CodeSummary ParseTestResults(string filename)
|
||||
|
||||
Reference in New Issue
Block a user