Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add exe modules to coverage #128

Merged
merged 2 commits into from Jun 27, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/coverlet.core/Helpers/InstrumentationHelper.cs
Expand Up @@ -15,7 +15,7 @@ internal static class InstrumentationHelper
{
public static string[] GetCoverableModules(string module)
{
IEnumerable<string> modules = Directory.GetFiles(Path.GetDirectoryName(module), "*.dll");
IEnumerable<string> modules = Directory.EnumerateFiles(Path.GetDirectoryName(module)).Where(fileName => Path.HasExtension(fileName) && (Path.GetExtension(fileName) == ".exe" || Path.GetExtension(fileName) == ".dll"));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try this:

Directory.EnumerateFiles(Path.GetDirectoryName(module)).Where(f => f.EndsWith(".exe") || f.EndsWith(".dll"))

It feels more cleaner

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

modules = modules.Where(m => IsAssembly(m) && Path.GetFileName(m) != Path.GetFileName(module));
return modules.ToArray();
}
Expand Down
16 changes: 15 additions & 1 deletion test/coverlet.core.tests/Helpers/InstrumentationHelperTests.cs
@@ -1,6 +1,5 @@
using System;
using System.IO;

using Xunit;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -17,6 +16,21 @@ public void TestGetDependencies()
Assert.False(Array.Exists(modules, m => m == module));
}

[Fact]
public void TestExeModulesCoverage()
{
string module = typeof(InstrumentationHelperTests).Assembly.Location;
string exeModule = Path.ChangeExtension(module, ".exe");
string noExtModule = Path.ChangeExtension(module, "").TrimEnd('.');
File.Delete(exeModule);
File.Copy(module, exeModule);
File.Delete(noExtModule);
File.Copy(module, noExtModule);
var modules = InstrumentationHelper.GetCoverableModules(module);
Assert.True(Array.Exists(modules, m => m == exeModule));
Assert.False(Array.Exists(modules, m => m == noExtModule));
}

[Fact]
public void TestHasPdb()
{
Expand Down