From d6e008fba9afc2bde3d45d64bf6d66eac912e48d Mon Sep 17 00:00:00 2001 From: Viktor Hofer Date: Wed, 28 Nov 2018 16:36:52 +0100 Subject: [PATCH] Singular argument name, code cleanup, cwd change --- README.md | 26 +++++++++--------- src/coverlet.console/Program.cs | 2 +- src/coverlet.core/Coverage.cs | 2 +- .../Helpers/InstrumentationHelper.cs | 27 ++++++++++--------- .../InstrumentationTask.cs | 10 +++---- src/coverlet.msbuild/coverlet.msbuild.props | 2 +- src/coverlet.msbuild/coverlet.msbuild.targets | 4 +-- 7 files changed, 37 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index c25c0e6..00aa7e0 100644 --- a/README.md +++ b/README.md @@ -56,19 +56,19 @@ Arguments: Path to the test assembly. Options: - -h|--help Show help information - -v|--version Show version information - -t|--target Path to the test runner application. - -a|--targetargs Arguments to be passed to the test runner. - -o|--output Output of the generated coverage report - -f|--format Format of the generated coverage report. - --threshold Exits with error if the coverage % is below value. - --threshold-type Coverage type to apply the threshold to. - --exclude Filter expressions to exclude specific modules and types. - --include Filter expressions to include specific modules and types. - --include-directories Include directories containing additional assemblies to be instrumented. - --exclude-by-file Glob patterns specifying source files to exclude. - --merge-with Path to existing coverage result to merge. + -h|--help Show help information + -v|--version Show version information + -t|--target Path to the test runner application. + -a|--targetargs Arguments to be passed to the test runner. + -o|--output Output of the generated coverage report + -f|--format Format of the generated coverage report. + --threshold Exits with error if the coverage % is below value. + --threshold-type Coverage type to apply the threshold to. + --exclude Filter expressions to exclude specific modules and types. + --include Filter expressions to include specific modules and types. + --include-directory Include directories containing additional assemblies to be instrumented. + --exclude-by-file Glob patterns specifying source files to exclude. + --merge-with Path to existing coverage result to merge. ``` #### Code Coverage diff --git a/src/coverlet.console/Program.cs b/src/coverlet.console/Program.cs index 5d7e837..f515633 100644 --- a/src/coverlet.console/Program.cs +++ b/src/coverlet.console/Program.cs @@ -32,7 +32,7 @@ namespace Coverlet.Console CommandOption thresholdTypes = app.Option("--threshold-type", "Coverage type to apply the threshold to.", CommandOptionType.MultipleValue); CommandOption excludeFilters = app.Option("--exclude", "Filter expressions to exclude specific modules and types.", CommandOptionType.MultipleValue); CommandOption includeFilters = app.Option("--include", "Filter expressions to include only specific modules and types.", CommandOptionType.MultipleValue); - CommandOption includeDirectories = app.Option("--include-directories", "Include directories containing additional assemblies to be instrumented.", CommandOptionType.MultipleValue); + CommandOption includeDirectories = app.Option("--include-directory", "Include directories containing additional assemblies to be instrumented.", CommandOptionType.MultipleValue); CommandOption excludedSourceFiles = app.Option("--exclude-by-file", "Glob patterns specifying source files to exclude.", CommandOptionType.MultipleValue); CommandOption mergeWith = app.Option("--merge-with", "Path to existing coverage result to merge.", CommandOptionType.SingleValue); diff --git a/src/coverlet.core/Coverage.cs b/src/coverlet.core/Coverage.cs index c9a4a90..c666925 100644 --- a/src/coverlet.core/Coverage.cs +++ b/src/coverlet.core/Coverage.cs @@ -66,8 +66,8 @@ namespace Coverlet.Core } catch (Exception) { + // TODO: With verbose logging we should note that instrumentation failed. InstrumentationHelper.RestoreOriginalModule(module, _identifier); - throw; } } } diff --git a/src/coverlet.core/Helpers/InstrumentationHelper.cs b/src/coverlet.core/Helpers/InstrumentationHelper.cs index 5b3d7c0..6982ea1 100644 --- a/src/coverlet.core/Helpers/InstrumentationHelper.cs +++ b/src/coverlet.core/Helpers/InstrumentationHelper.cs @@ -14,10 +14,9 @@ namespace Coverlet.Core.Helpers { internal static class InstrumentationHelper { - public static string[] GetCoverableModules(string module, string[] includeDirectories) + public static string[] GetCoverableModules(string module, string[] directories) { - Debug.Assert(includeDirectories != null, "Parameter " + nameof(includeDirectories) + " in method " + - nameof(InstrumentationHelper) + "." + nameof(GetCoverableModules) + " must not be null"); + Debug.Assert(directories != null); string moduleDirectory = Path.GetDirectoryName(module); if (moduleDirectory == string.Empty) @@ -25,28 +24,31 @@ namespace Coverlet.Core.Helpers moduleDirectory = Directory.GetCurrentDirectory(); } - var dirs = new List(1 + includeDirectories.Length) + var dirs = new List() { // Add the test assembly's directory. moduleDirectory }; - // Prepare all the directories in which we probe for modules. - foreach (var includeDirectory in includeDirectories.Where(d => d != null)) + // Prepare all the directories we probe for modules. + foreach (string directory in directories) { - var fullPath = (!Path.IsPathRooted(includeDirectory) - ? Path.GetFullPath(Path.Combine(moduleDirectory, includeDirectory)) - : includeDirectory).TrimEnd('*'); + if (string.IsNullOrWhiteSpace(directory)) continue; + + string fullPath = (!Path.IsPathRooted(directory) + ? Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), directory)) + : directory).TrimEnd('*'); if (!Directory.Exists(fullPath)) continue; - if (includeDirectory.EndsWith("*", StringComparison.Ordinal)) + if (directory.EndsWith("*", StringComparison.Ordinal)) dirs.AddRange(Directory.GetDirectories(fullPath)); else dirs.Add(fullPath); } - // The test module's name must be unique. + // The module's name must be unique. + // Add the test module itself to exclude it from the files enumeration. var uniqueModules = new HashSet { Path.GetFileName(module) @@ -309,8 +311,7 @@ namespace Coverlet.Core.Helpers private static bool IsAssembly(string filePath) { - Debug.Assert(filePath != null, "Parameter " + nameof(filePath) + " in " + nameof(InstrumentationHelper) + - "." + nameof(IsAssembly) + " must not be null."); + Debug.Assert(filePath != null); if (!(filePath.EndsWith(".exe") || filePath.EndsWith(".dll"))) return false; diff --git a/src/coverlet.msbuild.tasks/InstrumentationTask.cs b/src/coverlet.msbuild.tasks/InstrumentationTask.cs index 400f7f1..40410e0 100644 --- a/src/coverlet.msbuild.tasks/InstrumentationTask.cs +++ b/src/coverlet.msbuild.tasks/InstrumentationTask.cs @@ -11,7 +11,7 @@ namespace Coverlet.MSbuild.Tasks private string _path; private string _exclude; private string _include; - private string _includeDirectories; + private string _includeDirectory; private string _excludeByFile; private string _mergeWith; @@ -39,10 +39,10 @@ namespace Coverlet.MSbuild.Tasks set { _include = value; } } - public string IncludeDirectories + public string IncludeDirectory { - get { return _includeDirectories; } - set { _includeDirectories = value; } + get { return _includeDirectory; } + set { _includeDirectory = value; } } public string ExcludeByFile @@ -64,7 +64,7 @@ namespace Coverlet.MSbuild.Tasks var excludedSourceFiles = _excludeByFile?.Split(','); var excludeFilters = _exclude?.Split(','); var includeFilters = _include?.Split(','); - var includeDirectories = _includeDirectories?.Split(','); + var includeDirectories = _includeDirectory?.Split(','); _coverage = new Coverage(_path, excludeFilters, includeFilters, includeDirectories, excludedSourceFiles, _mergeWith); _coverage.PrepareModules(); diff --git a/src/coverlet.msbuild/coverlet.msbuild.props b/src/coverlet.msbuild/coverlet.msbuild.props index d4beab8..729a6e2 100644 --- a/src/coverlet.msbuild/coverlet.msbuild.props +++ b/src/coverlet.msbuild/coverlet.msbuild.props @@ -9,6 +9,6 @@ 0 line,branch,method - + diff --git a/src/coverlet.msbuild/coverlet.msbuild.targets b/src/coverlet.msbuild/coverlet.msbuild.targets index ec8807f..acbb880 100644 --- a/src/coverlet.msbuild/coverlet.msbuild.targets +++ b/src/coverlet.msbuild/coverlet.msbuild.targets @@ -7,7 +7,7 @@