Skip to content

Instantly share code, notes, and snippets.

@jbrestan
Created January 10, 2018 12:47
Show Gist options
  • Save jbrestan/d124d7aa326b00d95ab8936b0287a28d to your computer and use it in GitHub Desktop.
Save jbrestan/d124d7aa326b00d95ab8936b0287a28d to your computer and use it in GitHub Desktop.
Finds all Paket DLL dependencies and builds a CLI exclusion filter for dotTrace
let filesToExcludeFromTestCoverage rootDir projectExcludes =
rootDir</>"paket.lock"
|> File.ReadLines
|> Seq.choose (fun line ->
// Expecting paket.lock line format for dependencies and transitive dependencies, e.g.:
// xunit (2.3)
// xunit.analyzers (>= 0.7)
// We'll use the version to recognize it from `remote: <url>` definitions, but take just the package name.
match Regex.Match(line,"^[ ]{4,6}([^ ]+) \((.+)\)") with
| m when m.Success && m.Groups.Count = 3 -> Some m.Groups.[1].Value
| _ -> None)
|> Seq.distinct
|> Seq.collect (fun packageName ->
!! (rootDir</>"packages"</>packageName</>"**/*.dll")
|> Seq.map FileHelper.fileNameWithoutExt)
|> Seq.distinct
|> Seq.append projectExcludes
|> Seq.append ["*Tests"]
|> Seq.map (sprintf "-:%s")
|> String.concat ";"
@jbrestan
Copy link
Author

Usage:

!! testAssemblies
|> DotCover.DotCoverXUnit2
    (fun p ->
        { p with
            Filters = filesToExcludeFromTestCoverage rootDir projectExcludes
            // Exclude F# compiler generated code (structural equality + comparison etc.)
            AttributeFilters = "System.Runtime.CompilerServices.CompilerGeneratedAttribute"
            ... })
    (fun p ->...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment