mirror of
https://github.com/irongut/CodeCoverageSummary.git
synced 2026-05-20 08:50:14 +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
|
internal static class Program
|
||||||
{
|
{
|
||||||
// test file: /Dev/Csharp/CodeCoverageSummary/coverage.cobertura.xml
|
|
||||||
|
|
||||||
private static int Main(string[] args)
|
private static int Main(string[] args)
|
||||||
{
|
{
|
||||||
return Parser.Default.ParseArguments<CommandLineOptions>(args)
|
return Parser.Default.ParseArguments<CommandLineOptions>(args)
|
||||||
.MapResult(o =>
|
.MapResult(o =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!File.Exists(o.Filename))
|
if (!File.Exists(o.Filename))
|
||||||
{
|
{
|
||||||
Console.WriteLine("Error: Code coverage file not found.");
|
Console.WriteLine("Error: Code coverage file not found.");
|
||||||
return -2; // error
|
return -2; // error
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse code coverage file
|
// parse code coverage file
|
||||||
Console.WriteLine($"Code Coverage File: {o.Filename}");
|
Console.WriteLine($"Code Coverage File: {o.Filename}");
|
||||||
CodeSummary summary = ParseTestResults(o.Filename);
|
CodeSummary summary = ParseTestResults(o.Filename);
|
||||||
if (summary == null)
|
if (summary == null)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Error: Parsing code coverage file.");
|
Console.WriteLine("Error: Parsing code coverage file.");
|
||||||
return -2; // error
|
return -2; // error
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// generate badge
|
// generate badge
|
||||||
string badgeUrl = o.Badge ? GenerateBadge(summary) : null;
|
string badgeUrl = o.Badge ? GenerateBadge(summary) : null;
|
||||||
|
|
||||||
// generate output
|
// generate output
|
||||||
string output;
|
string output;
|
||||||
string fileExt;
|
string fileExt;
|
||||||
if (o.Format.Equals("text", StringComparison.OrdinalIgnoreCase))
|
if (o.Format.Equals("text", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
fileExt = "txt";
|
fileExt = "txt";
|
||||||
output = GenerateTextOutput(summary, badgeUrl);
|
output = GenerateTextOutput(summary, badgeUrl);
|
||||||
}
|
}
|
||||||
else if (o.Format.Equals("md", StringComparison.OrdinalIgnoreCase) || o.Format.Equals("markdown", StringComparison.OrdinalIgnoreCase))
|
else if (o.Format.Equals("md", StringComparison.OrdinalIgnoreCase) || o.Format.Equals("markdown", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
fileExt = "md";
|
fileExt = "md";
|
||||||
output = GenerateMarkdownOutput(summary, badgeUrl);
|
output = GenerateMarkdownOutput(summary, badgeUrl);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Console.WriteLine("Error: Unknown output format.");
|
Console.WriteLine("Error: Unknown output format.");
|
||||||
return -2; // error
|
return -2; // error
|
||||||
}
|
}
|
||||||
|
|
||||||
// output
|
// output
|
||||||
if (o.Output.Equals("console", StringComparison.OrdinalIgnoreCase))
|
if (o.Output.Equals("console", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
Console.WriteLine(output);
|
Console.WriteLine(output);
|
||||||
}
|
}
|
||||||
else if (o.Output.Equals("file", StringComparison.OrdinalIgnoreCase))
|
else if (o.Output.Equals("file", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
File.WriteAllText($"code-coverage-results.{fileExt}", output);
|
File.WriteAllText($"code-coverage-results.{fileExt}", output);
|
||||||
}
|
}
|
||||||
else if (o.Output.Equals("both", StringComparison.OrdinalIgnoreCase))
|
else if (o.Output.Equals("both", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
Console.WriteLine(output);
|
Console.WriteLine(output);
|
||||||
File.WriteAllText($"code-coverage-results.{fileExt}", output);
|
File.WriteAllText($"code-coverage-results.{fileExt}", output);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Console.WriteLine("Error: Unknown output type.");
|
Console.WriteLine("Error: Unknown output type.");
|
||||||
return -2; // error
|
return -2; // error
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0; // success
|
return 0; // success
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Error: {ex.GetType()} - {ex.Message}");
|
Console.WriteLine($"Error: {ex.GetType()} - {ex.Message}");
|
||||||
return -3; // unhandled error
|
return -3; // unhandled error
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
errs => -1); // invalid arguments
|
_ => -1); // invalid arguments
|
||||||
}
|
}
|
||||||
|
|
||||||
private static CodeSummary ParseTestResults(string filename)
|
private static CodeSummary ParseTestResults(string filename)
|
||||||
|
|||||||
Reference in New Issue
Block a user