Skip to content

Commit d6e008f

Browse files
committed
Singular argument name, code cleanup, cwd change
1 parent a7a27e7 commit d6e008f

File tree

7 files changed

+37
-36
lines changed

7 files changed

+37
-36
lines changed

README.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,19 @@ Arguments:
5656
<ASSEMBLY> Path to the test assembly.
5757

5858
Options:
59-
-h|--help Show help information
60-
-v|--version Show version information
61-
-t|--target Path to the test runner application.
62-
-a|--targetargs Arguments to be passed to the test runner.
63-
-o|--output Output of the generated coverage report
64-
-f|--format Format of the generated coverage report.
65-
--threshold Exits with error if the coverage % is below value.
66-
--threshold-type Coverage type to apply the threshold to.
67-
--exclude Filter expressions to exclude specific modules and types.
68-
--include Filter expressions to include specific modules and types.
69-
--include-directories Include directories containing additional assemblies to be instrumented.
70-
--exclude-by-file Glob patterns specifying source files to exclude.
71-
--merge-with Path to existing coverage result to merge.
59+
-h|--help Show help information
60+
-v|--version Show version information
61+
-t|--target Path to the test runner application.
62+
-a|--targetargs Arguments to be passed to the test runner.
63+
-o|--output Output of the generated coverage report
64+
-f|--format Format of the generated coverage report.
65+
--threshold Exits with error if the coverage % is below value.
66+
--threshold-type Coverage type to apply the threshold to.
67+
--exclude Filter expressions to exclude specific modules and types.
68+
--include Filter expressions to include specific modules and types.
69+
--include-directory Include directories containing additional assemblies to be instrumented.
70+
--exclude-by-file Glob patterns specifying source files to exclude.
71+
--merge-with Path to existing coverage result to merge.
7272
```
7373
7474
#### Code Coverage

src/coverlet.console/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ static int Main(string[] args)
3232
CommandOption thresholdTypes = app.Option("--threshold-type", "Coverage type to apply the threshold to.", CommandOptionType.MultipleValue);
3333
CommandOption excludeFilters = app.Option("--exclude", "Filter expressions to exclude specific modules and types.", CommandOptionType.MultipleValue);
3434
CommandOption includeFilters = app.Option("--include", "Filter expressions to include only specific modules and types.", CommandOptionType.MultipleValue);
35-
CommandOption includeDirectories = app.Option("--include-directories", "Include directories containing additional assemblies to be instrumented.", CommandOptionType.MultipleValue);
35+
CommandOption includeDirectories = app.Option("--include-directory", "Include directories containing additional assemblies to be instrumented.", CommandOptionType.MultipleValue);
3636
CommandOption excludedSourceFiles = app.Option("--exclude-by-file", "Glob patterns specifying source files to exclude.", CommandOptionType.MultipleValue);
3737
CommandOption mergeWith = app.Option("--merge-with", "Path to existing coverage result to merge.", CommandOptionType.SingleValue);
3838

src/coverlet.core/Coverage.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ public void PrepareModules()
6666
}
6767
catch (Exception)
6868
{
69+
// TODO: With verbose logging we should note that instrumentation failed.
6970
InstrumentationHelper.RestoreOriginalModule(module, _identifier);
70-
throw;
7171
}
7272
}
7373
}

src/coverlet.core/Helpers/InstrumentationHelper.cs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,39 +14,41 @@ namespace Coverlet.Core.Helpers
1414
{
1515
internal static class InstrumentationHelper
1616
{
17-
public static string[] GetCoverableModules(string module, string[] includeDirectories)
17+
public static string[] GetCoverableModules(string module, string[] directories)
1818
{
19-
Debug.Assert(includeDirectories != null, "Parameter " + nameof(includeDirectories) + " in method " +
20-
nameof(InstrumentationHelper) + "." + nameof(GetCoverableModules) + " must not be null");
19+
Debug.Assert(directories != null);
2120

2221
string moduleDirectory = Path.GetDirectoryName(module);
2322
if (moduleDirectory == string.Empty)
2423
{
2524
moduleDirectory = Directory.GetCurrentDirectory();
2625
}
2726

28-
var dirs = new List<string>(1 + includeDirectories.Length)
27+
var dirs = new List<string>()
2928
{
3029
// Add the test assembly's directory.
3130
moduleDirectory
3231
};
3332

34-
// Prepare all the directories in which we probe for modules.
35-
foreach (var includeDirectory in includeDirectories.Where(d => d != null))
33+
// Prepare all the directories we probe for modules.
34+
foreach (string directory in directories)
3635
{
37-
var fullPath = (!Path.IsPathRooted(includeDirectory)
38-
? Path.GetFullPath(Path.Combine(moduleDirectory, includeDirectory))
39-
: includeDirectory).TrimEnd('*');
36+
if (string.IsNullOrWhiteSpace(directory)) continue;
37+
38+
string fullPath = (!Path.IsPathRooted(directory)
39+
? Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), directory))
40+
: directory).TrimEnd('*');
4041

4142
if (!Directory.Exists(fullPath)) continue;
4243

43-
if (includeDirectory.EndsWith("*", StringComparison.Ordinal))
44+
if (directory.EndsWith("*", StringComparison.Ordinal))
4445
dirs.AddRange(Directory.GetDirectories(fullPath));
4546
else
4647
dirs.Add(fullPath);
4748
}
4849

49-
// The test module's name must be unique.
50+
// The module's name must be unique.
51+
// Add the test module itself to exclude it from the files enumeration.
5052
var uniqueModules = new HashSet<string>
5153
{
5254
Path.GetFileName(module)
@@ -309,8 +311,7 @@ private static string WildcardToRegex(string pattern)
309311

310312
private static bool IsAssembly(string filePath)
311313
{
312-
Debug.Assert(filePath != null, "Parameter " + nameof(filePath) + " in " + nameof(InstrumentationHelper) +
313-
"." + nameof(IsAssembly) + " must not be null.");
314+
Debug.Assert(filePath != null);
314315

315316
if (!(filePath.EndsWith(".exe") || filePath.EndsWith(".dll")))
316317
return false;

src/coverlet.msbuild.tasks/InstrumentationTask.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class InstrumentationTask : Task
1111
private string _path;
1212
private string _exclude;
1313
private string _include;
14-
private string _includeDirectories;
14+
private string _includeDirectory;
1515
private string _excludeByFile;
1616
private string _mergeWith;
1717

@@ -39,10 +39,10 @@ public string Include
3939
set { _include = value; }
4040
}
4141

42-
public string IncludeDirectories
42+
public string IncludeDirectory
4343
{
44-
get { return _includeDirectories; }
45-
set { _includeDirectories = value; }
44+
get { return _includeDirectory; }
45+
set { _includeDirectory = value; }
4646
}
4747

4848
public string ExcludeByFile
@@ -64,7 +64,7 @@ public override bool Execute()
6464
var excludedSourceFiles = _excludeByFile?.Split(',');
6565
var excludeFilters = _exclude?.Split(',');
6666
var includeFilters = _include?.Split(',');
67-
var includeDirectories = _includeDirectories?.Split(',');
67+
var includeDirectories = _includeDirectory?.Split(',');
6868

6969
_coverage = new Coverage(_path, excludeFilters, includeFilters, includeDirectories, excludedSourceFiles, _mergeWith);
7070
_coverage.PrepareModules();

src/coverlet.msbuild/coverlet.msbuild.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
<MergeWith Condition="$(MergeWith) == ''"></MergeWith>
1010
<Threshold Condition="$(Threshold) == ''">0</Threshold>
1111
<ThresholdType Condition="$(ThresholdType) == ''">line,branch,method</ThresholdType>
12-
<IncludeDirectories Condition="$(IncludeDirectories) == ''"></IncludeDirectories>
12+
<IncludeDirectory Condition="$(IncludeDirectory) == ''"></IncludeDirectory>
1313
</PropertyGroup>
1414
</Project>

src/coverlet.msbuild/coverlet.msbuild.targets

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<Coverlet.MSbuild.Tasks.InstrumentationTask
88
Condition="'$(VSTestNoBuild)' == 'true' and $(CollectCoverage) == 'true'"
99
Include="$(Include)"
10-
IncludeDirectories="$(IncludeDirectories)"
10+
IncludeDirectory="$(IncludeDirectory)"
1111
Exclude="$(Exclude)"
1212
ExcludeByFile="$(ExcludeByFile)"
1313
MergeWith="$(MergeWith)"
@@ -18,7 +18,7 @@
1818
<Coverlet.MSbuild.Tasks.InstrumentationTask
1919
Condition="'$(VSTestNoBuild)' != 'true' and $(CollectCoverage) == 'true'"
2020
Include="$(Include)"
21-
IncludeDirectories="$(IncludeDirectories)"
21+
IncludeDirectory="$(IncludeDirectory)"
2222
Exclude="$(Exclude)"
2323
ExcludeByFile="$(ExcludeByFile)"
2424
MergeWith="$(MergeWith)"

0 commit comments

Comments
 (0)