Skip to content

Commit 8a1c6c2

Browse files
committed
Disable CecilSourceInformationProvider when instructed by TESTINGPLATFORM_EXPERIMENTAL_VSTEST_RUNSETTINGS
1 parent c7ecf37 commit 8a1c6c2

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

src/xunit.v3.runner.common/Frameworks/CecilSourceInformationProvider.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ public sealed class CecilSourceInformationProvider : ISourceInformationProvider
3939
/// <param name="assemblyFileName">The test assembly filename</param>
4040
public static ISourceInformationProvider Create(string? assemblyFileName)
4141
{
42+
if (!RunSettingsUtility.CollectSourceInformation)
43+
return NullSourceInformationProvider.Instance;
44+
4245
var folder = Path.GetDirectoryName(assemblyFileName);
4346
if (folder is null)
4447
return NullSourceInformationProvider.Instance;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System;
2+
using System.Collections;
3+
using System.Linq;
4+
using System.Xml.Linq;
5+
using System.Xml.XPath;
6+
7+
namespace Xunit.Runner.Common;
8+
9+
internal static class RunSettingsUtility
10+
{
11+
static bool? collectSourceInformation;
12+
13+
public static bool CollectSourceInformation
14+
{
15+
get
16+
{
17+
if (!collectSourceInformation.HasValue)
18+
{
19+
try
20+
{
21+
var runSettings = Environment.GetEnvironmentVariable("TESTINGPLATFORM_EXPERIMENTAL_VSTEST_RUNSETTINGS");
22+
if (runSettings is not null)
23+
{
24+
var doc = XDocument.Parse(runSettings);
25+
if (doc.Root?.XPathEvaluate("/RunSettings/RunConfiguration/CollectSourceInformation") is IEnumerable enumerable)
26+
if (enumerable.OfType<XElement>().FirstOrDefault() is XElement element)
27+
collectSourceInformation = bool.Parse(element.Value);
28+
}
29+
}
30+
catch { }
31+
32+
collectSourceInformation ??= true;
33+
}
34+
35+
return collectSourceInformation.Value;
36+
}
37+
}
38+
}

0 commit comments

Comments
 (0)