Skip to content

Commit 9a20662

Browse files
committed
improve excludeAssembliesWithoutSources parameter validation
1 parent 484d643 commit 9a20662

File tree

3 files changed

+86
-2
lines changed

3 files changed

+86
-2
lines changed

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"sdk": {
3-
"version": "8.0.408"
3+
"version": "8.0.409"
44
}
55
}

src/coverlet.console/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ static int Main(string[] args)
4848
var mergeWith = new Option<string>("--merge-with", "Path to existing coverage result to merge.") { Arity = ArgumentArity.ZeroOrOne };
4949
var useSourceLink = new Option<bool>("--use-source-link", "Specifies whether to use SourceLink URIs in place of file system paths.") { Arity = ArgumentArity.Zero };
5050
var doesNotReturnAttributes = new Option<string[]>("--does-not-return-attribute", "Attributes that mark methods that do not return") { Arity = ArgumentArity.ZeroOrMore, AllowMultipleArgumentsPerToken = true };
51-
var excludeAssembliesWithoutSources = new Option<string>("--exclude-assemblies-without-sources", "Specifies behavior of heuristic to ignore assemblies with missing source documents.") { Arity = ArgumentArity.ZeroOrOne };
51+
Option<string> excludeAssembliesWithoutSources = new Option<string>("--exclude-assemblies-without-sources", "Specifies behavior of heuristic to ignore assemblies with missing source documents.").FromAmong("MissingAll", "MissingAny", "None");
5252
var sourceMappingFile = new Option<string>("--source-mapping-file", "Specifies the path to a SourceRootsMappings file.") { Arity = ArgumentArity.ZeroOrOne };
5353

5454
RootCommand rootCommand = new()

test/coverlet.integration.tests/DotnetTool.cs

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,5 +141,89 @@ public void StandAloneThresholdLineAndMethod()
141141
Assert.Contains("The minimum line coverage is below the specified 80", standardOutput);
142142
Assert.Contains("The minimum method coverage is below the specified 80", standardOutput);
143143
}
144+
145+
[Fact]
146+
public void ExcludeAssembliesWithoutSources_WrongValue()
147+
{
148+
using ClonedTemplateProject clonedTemplateProject = CloneTemplateProject();
149+
UpdateNugetConfigWithLocalPackageFolder(clonedTemplateProject.ProjectRootPath!);
150+
string coverletToolCommandPath = InstallTool(clonedTemplateProject.ProjectRootPath!);
151+
string outputPath = $"{clonedTemplateProject.ProjectRootPath}{Path.DirectorySeparatorChar}coverage.json";
152+
153+
// Build the test project
154+
DotnetCli($"build -f {_buildTargetFramework} {clonedTemplateProject.ProjectRootPath}",
155+
out string buildOutput,
156+
out string buildError);
157+
158+
string publishedTestFile = clonedTemplateProject.GetFiles("*" + ClonedTemplateProject.AssemblyName + ".dll")
159+
.Single(f => !f.Contains("obj") && !f.Contains("ref"));
160+
161+
// Run coverage with exclude-assemblies-without-sources parameter
162+
int cmdExitCode = RunCommand(
163+
coverletToolCommandPath,
164+
$"\"{publishedTestFile}\" --target \"dotnet\" " +
165+
$"--targetargs \"test {Path.Combine(clonedTemplateProject.ProjectRootPath, ClonedTemplateProject.ProjectFileName)} --no-build\" " +
166+
$"--exclude-assemblies-without-sources nonsense " +
167+
$"--output \"{outputPath}\"",
168+
out string standardOutput,
169+
out string standardError);
170+
171+
if (!string.IsNullOrEmpty(standardError))
172+
{
173+
_output.WriteLine(standardError);
174+
}
175+
else
176+
{
177+
_output.WriteLine(standardOutput);
178+
}
179+
180+
// Verify results
181+
Assert.Contains("Argument 'nonsense' not recognized. Must be one of:\t'MissingAll'\t'MissingAny'\t'None'", standardError);
182+
}
183+
184+
[Theory]
185+
[InlineData("MissingAll")]
186+
[InlineData("MissingAny")]
187+
[InlineData("None")]
188+
public void ExcludeAssembliesWithoutSources_DifferentModes(string mode)
189+
{
190+
using ClonedTemplateProject clonedTemplateProject = CloneTemplateProject();
191+
UpdateNugetConfigWithLocalPackageFolder(clonedTemplateProject.ProjectRootPath!);
192+
string coverletToolCommandPath = InstallTool(clonedTemplateProject.ProjectRootPath!);
193+
string outputPath = $"{clonedTemplateProject.ProjectRootPath}{Path.DirectorySeparatorChar}coverage.json";
194+
195+
// Build the test project
196+
DotnetCli($"build -f {_buildTargetFramework} {clonedTemplateProject.ProjectRootPath}",
197+
out string buildOutput,
198+
out string buildError);
199+
200+
string publishedTestFile = clonedTemplateProject.GetFiles("*" + ClonedTemplateProject.AssemblyName + ".dll")
201+
.Single(f => !f.Contains("obj") && !f.Contains("ref"));
202+
203+
// Run coverage with different exclude-assemblies-without-sources modes
204+
int cmdExitCode = RunCommand(
205+
coverletToolCommandPath,
206+
$"\"{publishedTestFile}\" --target \"dotnet\" " +
207+
$"--targetargs \"test {Path.Combine(clonedTemplateProject.ProjectRootPath, ClonedTemplateProject.ProjectFileName)} --no-build\" " +
208+
$"--exclude-assemblies-without-sources {mode} " +
209+
$"--output \"{outputPath}\"",
210+
out string standardOutput,
211+
out string standardError);
212+
213+
if (!string.IsNullOrEmpty(standardError))
214+
{
215+
_output.WriteLine(standardError);
216+
}
217+
else
218+
{
219+
_output.WriteLine(standardOutput);
220+
}
221+
222+
// Verify basic execution
223+
Assert.Empty(standardError);
224+
Assert.True(File.Exists(outputPath), "Coverage output file should exist");
225+
Assert.Equal((int)CommandExitCodes.Success, cmdExitCode);
226+
Assert.Contains("Passed!", standardOutput);
227+
}
144228
}
145229
}

0 commit comments

Comments
 (0)