Skip to content

Commit

Permalink
Merge pull request #10 from tonerdo/master
Browse files Browse the repository at this point in the history
Update fork
  • Loading branch information
daveMueller authored Jan 18, 2020
2 parents fce0e2d + ddd734e commit 8b8505b
Show file tree
Hide file tree
Showing 45 changed files with 1,054 additions and 140 deletions.
5 changes: 5 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

Contributions are highly welcome, however, except for very small changes, kindly file an issue and let's have a discussion before you open a pull request.

## Requirements

.NET SDK 2.2 https://dotnet.microsoft.com/download/dotnet-core/2.2
.NET SDK 3.1 https://dotnet.microsoft.com/download/dotnet-core/3.1

## Building the Project

Clone this repo:
Expand Down
3 changes: 2 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
<RepoRoot>$(MSBuildThisFileDirectory)</RepoRoot>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<PackageOutputPath>$(MSBuildThisFileDirectory)bin\$(Configuration)\Packages\</PackageOutputPath>

<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<MSBuildTreatWarningsAsErrors>true</MSBuildTreatWarningsAsErrors>
<LangVersion>preview</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
18 changes: 17 additions & 1 deletion Documentation/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

-Fixed ExcludeFromCodeCoverage attribute bugs [#129](https://github.com/tonerdo/coverlet/issues/129) and [#670](https://github.com/tonerdo/coverlet/issues/670) with [#671](https://github.com/tonerdo/coverlet/pull/671) by https://github.com/matteoerigozzi

### Improvements

-Trim whitespace between values when reading from configuration from runsettings [#679](https://github.com/tonerdo/coverlet/pull/679) by https://github.com/EricStG

## Release date 2020-01-03
### Packages
coverlet.msbuild 2.8.0
coverlet.console 1.7.0
coverlet.collector 1.2.0

### Added
-Add log to tracker [#553](https://github.com/tonerdo/coverlet/pull/553)
-Exclude by assembly level System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage [#589](https://github.com/tonerdo/coverlet/pull/589)
Expand All @@ -24,7 +38,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Improvements

-Improve exception message for unsupported runtime [#569](https://github.com/tonerdo/coverlet/pull/569) by https://github.com/daveMueller
-Improve exception message for unsupported runtime [#569](https://github.com/tonerdo/
coverlet/pull/569) by https://github.com/daveMueller
-Improve cobertura absolute/relative path report generation [#661](https://github.com/tonerdo/coverlet/pull/661) by https://github.com/daveMueller

## Release date 2019-09-23
### Packages
Expand Down
9 changes: 8 additions & 1 deletion Documentation/Examples/MSBuild/MergeWith/HowTo.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,11 @@ Last command will join and create final needed format file.
dotnet test XUnitTestProject1\XUnitTestProject1.csproj /p:CollectCoverage=true /p:CoverletOutput=../CoverageResults/
dotnet test XUnitTestProject2\XUnitTestProject2.csproj /p:CollectCoverage=true /p:CoverletOutput=../CoverageResults/ /p:MergeWith="../CoverageResults/coverage.json"
dotnet test XUnitTestProject3\XUnitTestProject3.csproj /p:CollectCoverage=true /p:CoverletOutput=../CoverageResults/ /p:MergeWith="../CoverageResults/coverage.json" /p:CoverletOutputFormat="opencover"
```
```

You can merge also running `dotnet test` and merge with single command from a solution file, but you need to ensure that tests will run sequentially(`-m:1`). This slow down testing but avoid invalid coverage result.

```
dotnet test /p:CollectCoverage=true /p:CoverletOutput=../CoverageResults/ /p:MergeWith="../CoverageResults/coverage.json" /p:CoverletOutputFormat=\"opencover,json\" -m:1
```
N.B. You need to specify `json` format plus another format(the final one), because Coverlet can only merge proprietary format. At the end you can delete temporary `coverage.json` file.
60 changes: 54 additions & 6 deletions Documentation/ReleasePlan.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ We plan 1 release [once per quarter](https://en.wikipedia.org/wiki/Calendar_year

| Package | **coverlet.msbuild** |
| :-------------: |:-------------:|
|**coverlet.msbuild** | 2.7.0 |
|**coverlet.console** | 1.6.0 |
|**coverlet.collector** | 1.1.0 |
|**coverlet.msbuild** | 2.8.0 |
|**coverlet.console** | 1.7.0 |
|**coverlet.collector** | 1.2.0 |

### Proposed next versions

Expand All @@ -41,11 +41,59 @@ We MANUALLY bump versions on production release, so we have different release pl

| Release Date | **coverlet.msbuild** | **coverlet.console** | **coverlet.collector** | **commit hash**| **notes** |
| :-------------: |:-------------:|:-------------:|:-------------:|:-------------:|:-------------:|
| <01 April 2020> | 2.8.1 | 1.7.1 | 1.2.1 |
| 03 January 2019 | 2.8.0 | 1.7.0 | 1.2.0 | 72a688f1c47fa92059540d5fbb1c4b0b4bf0dc8c | |
| 23 September 2019 | 2.7.0 | 1.6.0 | 1.1.0 | 4ca01eb239038808739699470a61fad675af6c79 | |
| 1 July 2019 | 2.6.3 | 1.5.3 | 1.0.1 | e1593359497fdfe6befbb86304b8f4e09a656d14 | |
| 6 June 2019 | 2.6.2 | 1.5.2 | 1.0.0 | 3e7eac9df094c22335711a298d359890aed582e8 | first collector release |
| 01 July 2019 | 2.6.3 | 1.5.3 | 1.0.1 | e1593359497fdfe6befbb86304b8f4e09a656d14 | |
| 06 June 2019 | 2.6.2 | 1.5.2 | 1.0.0 | 3e7eac9df094c22335711a298d359890aed582e8 | first collector release |

*< date > Expected next release date

To get the list of commits between two version use git command
```bash
git log --oneline hashbefore currenthash
```
```

# How to manually release packages to Nuget.org

This is the steps to do to release new packages to Nuget.org

1) Clone repo, **remember to build packages from master and not from your fork or metadata links will point to your forked repo.**
Run `git log -5` from repo root to verify last commit.

2) Update project versions in file:

Collector
https://github.com/tonerdo/coverlet/blob/master/src/coverlet.collector/version.json
.NET tool
https://github.com/tonerdo/coverlet/blob/master/src/coverlet.console/version.json
Msbuild tasks
https://github.com/tonerdo/coverlet/blob/master/src/coverlet.msbuild.tasks/version.json

Core lib project file https://github.com/tonerdo/coverlet/blob/master/src/coverlet.core/coverlet.core.csproj.
The version of core lib project file is the version we'll report on github repo releases https://github.com/tonerdo/coverlet/releases


Sample of updated version PR https://github.com/tonerdo/coverlet/pull/675/files

3) From new cloned, aligned and versions updated repo root run pack command
```
dotnet pack -c release /p:PublicRelease=true
...
coverlet.console -> D:\git\coverlet\src\coverlet.console\bin\Release\netcoreapp2.2\coverlet.console.dll
coverlet.console -> D:\git\coverlet\src\coverlet.console\bin\Release\netcoreapp2.2\publish\
Successfully created package 'D:\git\coverlet\bin\Release\Packages\coverlet.msbuild.2.8.1.nupkg'.
Successfully created package 'D:\git\coverlet\bin\Release\Packages\coverlet.msbuild.2.8.1.snupkg'.
Successfully created package 'D:\git\coverlet\bin\Release\Packages\coverlet.console.1.7.1.nupkg'.
Successfully created package 'D:\git\coverlet\bin\Release\Packages\coverlet.console.1.7.1.snupkg'.
Successfully created package 'D:\git\coverlet\bin\Release\Packages\coverlet.collector.1.2.1.nupkg'.
Successfully created package 'D:\git\coverlet\bin\Release\Packages\coverlet.collector.1.2.1.snupkg'.
```

4) Upload *.nupkg files to Nuget.org site. **Check all metadata(url links etc...) before "Submit"**

5) **On your fork**:
* Align to master
* Update versions in files accordingly to new release and commit/merge to master
* Create release on repo https://github.com/tonerdo/coverlet/releases using https://github.com/tonerdo/coverlet/blob/master/src/coverlet.core/coverlet.core.csproj assembly version
* Update the [Release Plan](https://github.com/tonerdo/coverlet/blob/master/Documentation/ReleasePlan.md)(this document) and [ChangeLog](https://github.com/tonerdo/coverlet/blob/master/Documentation/Changelog.md)
10 changes: 9 additions & 1 deletion Documentation/Troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,4 +235,12 @@ You'll get this message during test run
dotnet test -p:Include="[test_coverage.]" -p:Exclude="[*.Test.*]*" -p:CollectCoverage=true -p:CoverletOutputFormat=cobertura -p:CoverletOutput=coverage.cobertura.xml
Coverlet msbuild instrumentation task debugging is enabled. Please attach debugger to process to continue
Process Id: 29228 Name: dotnet
```
```

## Enable collector instrumentation debugging

You can live attach and debug collectors with `COVERLET_DATACOLLECTOR_OUTOFPROC_DEBUG` env variable
```
set COVERLET_DATACOLLECTOR_OUTOFPROC_DEBUG=1
```
You will be asket to attach a debugger through UI popup.
8 changes: 5 additions & 3 deletions Documentation/VSTestIntegration.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ These are a list of options that are supported by coverlet. These can be specifi
| Option | Summary |
|------------- |------------------------------------------------------------------------------------------|
|Format | Coverage output format. These are either cobertura, json, lcov, opencover or teamcity as well as combinations of these formats. |
|MergeWith | Combine the output of multiple coverage runs into a single result([check the sample](Examples.md)). |
|Exclude | Exclude from code coverage analysing using filter expressions. |
|ExcludeByFile | Ignore specific source files from code coverage. |
|Include | Explicitly set what to include in code coverage analysis using filter expressions. |
|IncludeDirectory| Explicitly set which directories to include in code coverage analysis. |
|SingleHit | Specifies whether to limit code coverage hit reporting to a single hit for each location.|
|UseSourceLink | Specifies whether to use SourceLink URIs in place of file system paths. |
|IncludeTestAssembly | Include coverage of the test assembly. |

How to specify these options via runsettings?
```
Expand All @@ -46,15 +46,15 @@ How to specify these options via runsettings?
<DataCollectors>
<DataCollector friendlyName="XPlat code coverage">
<Configuration>
<Format>json,cobertura</Format>
<MergeWith>/custom/path/result.json</MergeWith>
<Format>json,cobertura</Format>
<Exclude>[coverlet.*.tests?]*,[*]Coverlet.Core*</Exclude> <!-- [Assembly-Filter]Type-Filter -->
<Include>[coverlet.*]*,[*]Coverlet.Core*</Include> <!-- [Assembly-Filter]Type-Filter -->
<ExcludeByAttribute>Obsolete,GeneratedCodeAttribute,CompilerGeneratedAttribute</ExcludeByAttribute>
<ExcludeByFile>../dir1/class1.cs,../dir2/*.cs,../dir3/**/*.cs,</ExcludeByFile> <!-- Absolute or relative file paths -->
<IncludeDirectory>../dir1/,../dir2/,</IncludeDirectory>
<SingleHit>false</SingleHit>
<UseSourceLink>true</UseSourceLink>
<IncludeTestAssembly>true<IncludeTestAssembly>
</Configuration>
</DataCollector>
</DataCollectors>
Expand All @@ -67,6 +67,8 @@ This runsettings file can easily be provided using command line option as given

2. `dotnet vstest --settings coverletArgs.runsettings`

Take a look at our [`HelloWorld`](Examples/VSTest/HelloWorld/HowTo.md) sample.

## Implementation Details

The proposed solution is implemented with the help of [datacollectors](https://github.com/Microsoft/vstest-docs/blob/master/docs/extensions/datacollector.md).
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Coverlet can be used through three different *drivers*

### VSTest Integration (preferred due to [know issue](https://github.com/tonerdo/coverlet/blob/master/Documentation/KnowIssues.md#1-vstest-stops-process-execution-earlydotnet-test))

### Insallation
### Installation
```bash
dotnet add package coverlet.collector
```
Expand All @@ -51,7 +51,7 @@ See [documentation](Documentation/VSTestIntegration.md) for advanced usage.
* Important [know issue](Documentation/KnowIssues.md#2-upgrade-coverletcollector-to-version--100)
### MSBuild Integration

### Insallation
### Installation
```bash
dotnet add package coverlet.msbuild
```
Expand Down
Binary file added _assets/coverlet-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 8 additions & 3 deletions eng/build.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
steps:
- task: UseDotNet@2
inputs:
version: 2.2.402
version: 2.2.207
displayName: Install .NET Core SDK

- task: UseDotNet@2
inputs:
version: 3.1.100
displayName: Install .NET Core SDK

- script: dotnet restore
Expand All @@ -10,12 +15,12 @@ steps:
- script: dotnet build -c $(BuildConfiguration) --no-restore
displayName: Build

- script: dotnet pack -c $(BuildConfiguration) --no-build
- script: dotnet pack -c $(BuildConfiguration)
displayName: Pack

- task: DotNetCoreCLI@2
displayName: Test
inputs:
command: test
arguments: -c $(BuildConfiguration) --no-build /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Include=[coverlet.*]* /p:Exclude=[coverlet.tests.remoteexecutor]*
testRunTitle: $(Agent.JobName)
testRunTitle: $(Agent.JobName)
8 changes: 4 additions & 4 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"sdk": {
"version": "2.2.402"
}
}
"sdk": {
"version": "3.1.100"
}
}
12 changes: 12 additions & 0 deletions src/coverlet.collector/DataCollection/CoverletCoverageCollector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ internal CoverletCoverageCollector(TestPlatformEqtTrace eqtTrace, ICoverageWrapp
_countDownEventFactory = countDownEventFactory;
}

private void AttachDebugger()
{
if (int.TryParse(Environment.GetEnvironmentVariable("COVERLET_DATACOLLECTOR_OUTOFPROC_DEBUG"), out int result) && result == 1)
{
Debugger.Launch();
Debugger.Break();
}
}

/// <summary>
/// Initializes data collector
/// </summary>
Expand All @@ -52,6 +61,9 @@ public override void Initialize(
DataCollectionLogger logger,
DataCollectionEnvironmentContext environmentContext)
{

AttachDebugger();

if (_eqtTrace.IsInfoEnabled)
{
_eqtTrace.Info("Initializing {0} with configuration: '{1}'", CoverletConstants.DataCollectorName, configurationElement?.OuterXml);
Expand Down
23 changes: 16 additions & 7 deletions src/coverlet.collector/DataCollection/CoverletSettingsParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ private string[] ParseReportFormats(XmlElement configurationElement)
if (configurationElement != null)
{
XmlElement reportFormatElement = configurationElement[CoverletConstants.ReportFormatElementName];
formats = reportFormatElement?.InnerText?.Split(',').Select(format => format.Trim())
.Where(format => !string.IsNullOrEmpty(format)).ToArray();
formats = this.SplitElement(reportFormatElement);
}

return formats is null || formats.Length == 0 ? new[] { CoverletConstants.DefaultReportFormat } : formats;
Expand All @@ -101,7 +100,7 @@ private string[] ParseReportFormats(XmlElement configurationElement)
private string[] ParseIncludeFilters(XmlElement configurationElement)
{
XmlElement includeFiltersElement = configurationElement[CoverletConstants.IncludeFiltersElementName];
return includeFiltersElement?.InnerText?.Split(',');
return this.SplitElement(includeFiltersElement);
}

/// <summary>
Expand All @@ -112,7 +111,7 @@ private string[] ParseIncludeFilters(XmlElement configurationElement)
private string[] ParseIncludeDirectories(XmlElement configurationElement)
{
XmlElement includeDirectoriesElement = configurationElement[CoverletConstants.IncludeDirectoriesElementName];
return includeDirectoriesElement?.InnerText?.Split(',');
return this.SplitElement(includeDirectoriesElement);
}

/// <summary>
Expand All @@ -127,7 +126,7 @@ private string[] ParseExcludeFilters(XmlElement configurationElement)
if (configurationElement != null)
{
XmlElement excludeFiltersElement = configurationElement[CoverletConstants.ExcludeFiltersElementName];
string[] filters = excludeFiltersElement?.InnerText?.Split(',');
string[] filters = this.SplitElement(excludeFiltersElement);
if (filters != null)
{
excludeFilters.AddRange(filters);
Expand All @@ -145,7 +144,7 @@ private string[] ParseExcludeFilters(XmlElement configurationElement)
private string[] ParseExcludeSourceFiles(XmlElement configurationElement)
{
XmlElement excludeSourceFilesElement = configurationElement[CoverletConstants.ExcludeSourceFilesElementName];
return excludeSourceFilesElement?.InnerText?.Split(',');
return this.SplitElement(excludeSourceFilesElement);
}

/// <summary>
Expand All @@ -156,7 +155,7 @@ private string[] ParseExcludeSourceFiles(XmlElement configurationElement)
private string[] ParseExcludeAttributes(XmlElement configurationElement)
{
XmlElement excludeAttributesElement = configurationElement[CoverletConstants.ExcludeAttributesElementName];
return excludeAttributesElement?.InnerText?.Split(',');
return this.SplitElement(excludeAttributesElement);
}

/// <summary>
Expand Down Expand Up @@ -205,5 +204,15 @@ private bool ParseIncludeTestAssembly(XmlElement configurationElement)
bool.TryParse(includeTestAssemblyElement?.InnerText, out bool includeTestAssembly);
return includeTestAssembly;
}

/// <summary>
/// Splits a comma separated elements into an array
/// </summary>
/// <param name="element">The element to split</param>
/// <returns>An array of the values in the element</returns>
private string[] SplitElement(XmlElement element)
{
return element?.InnerText?.Split(',', StringSplitOptions.RemoveEmptyEntries).Where(value => !string.IsNullOrWhiteSpace(value)).Select(value => value.Trim()).ToArray();
}
}
}
Loading

0 comments on commit 8b8505b

Please sign in to comment.