Skip to content

Commit

Permalink
Fixed code coverage compatibility issue (#2514)
Browse files Browse the repository at this point in the history
* Fixed code coverage compatibility issue

* Added comment

* Updated commit
  • Loading branch information
cvpoienaru committed Aug 19, 2020
1 parent c1b6b2c commit 8ac7e27
Showing 1 changed file with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,14 @@ public virtual void Initialize(

try
{
var processor = new CodeCoverageRunSettingsProcessor(defaultConfigurationElement);
configurationElement = (XmlElement)processor.Process(configurationElement);
// WARNING: Do NOT remove this function call !!!
//
// Due to a dependency we took on Microsoft.TestPlatform.Utilities.dll, an
// exception may be thrown if we cannot resolve CodeCoverageRunSettingsProcessor.
// If such an exception is thrown we cannot catch it in this try-catch block
// because all method dependencies must be resolved before the method call, thus
// we introduced an additional layer of indirection.
configurationElement = this.AddDefaultExclusions(configurationElement, defaultConfigurationElement);
}
catch (Exception ex)
{
Expand Down Expand Up @@ -326,5 +332,17 @@ private void CreateDirectory(DataCollectionContext context, string path)
throw;
}
}

/// <summary>
/// Adding default exclusions to the configuration element.
/// </summary>
/// <param name="configurationElement">The configuration element.</param>
/// <param name="defaultConfigurationElement">The default configuration element.</param>
/// <returns>The original configuration element with additional default exclusions.</returns>
private XmlElement AddDefaultExclusions(XmlElement configurationElement, XmlElement defaultConfigurationElement)
{
var processor = new CodeCoverageRunSettingsProcessor(defaultConfigurationElement);
return (XmlElement)processor.Process(configurationElement);
}
}
}

0 comments on commit 8ac7e27

Please sign in to comment.