-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fill in IRunnerUtilityContext, and add support for v3 runner utility
- Loading branch information
1 parent
2b4f69b
commit 7e82f3f
Showing
5 changed files
with
90 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System; | ||
|
||
namespace Xunit.Analyzers; | ||
|
||
public class EmptyRunnerUtilityContext : IRunnerUtilityContext | ||
{ | ||
EmptyRunnerUtilityContext() | ||
{ } | ||
|
||
public static EmptyRunnerUtilityContext Instance { get; } = new(); | ||
|
||
public string Platform => "N/A"; | ||
|
||
public Version Version { get; } = new(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,17 @@ | ||
using System; | ||
|
||
namespace Xunit.Analyzers; | ||
|
||
public interface IRunnerUtilityContext | ||
{ | ||
/// <summary> | ||
/// Gets a description of the target platform for the runner utility (i.e., "net452"). This is | ||
/// typically extracted from the assembly name (i.e., "xunit.runner.utility.net452"). | ||
/// </summary> | ||
string Platform { get; } | ||
|
||
/// <summary> | ||
/// Gets the version number of the runner utility assembly. | ||
/// </summary> | ||
Version Version { get; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System; | ||
using System.Linq; | ||
using Microsoft.CodeAnalysis; | ||
|
||
namespace Xunit.Analyzers; | ||
|
||
public class V3RunnerUtilityContext : IRunnerUtilityContext | ||
{ | ||
const string assemblyPrefix = "xunit.v3.runner.utility."; | ||
|
||
V3RunnerUtilityContext( | ||
string platform, | ||
Version version) | ||
{ | ||
Platform = platform; | ||
Version = version; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public string Platform { get; } | ||
|
||
/// <inheritdoc/> | ||
public Version Version { get; } | ||
|
||
public static V3RunnerUtilityContext? Get( | ||
Compilation compilation, | ||
Version? versionOverride = null) | ||
{ | ||
var assembly = | ||
compilation | ||
.ReferencedAssemblyNames | ||
.FirstOrDefault(a => a.Name.StartsWith(assemblyPrefix, StringComparison.OrdinalIgnoreCase)); | ||
|
||
if (assembly is null) | ||
return null; | ||
|
||
var version = versionOverride ?? assembly.Version; | ||
var platform = assembly.Name.Substring(assemblyPrefix.Length); | ||
|
||
return version is null ? null : new(platform, version); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters