Repository navigation
Expand file tree
/
Copy pathTestFrameworkDisplay.cs
More file actions
56 lines (46 loc) · 2.23 KB
/
Copy pathTestFrameworkDisplay.cs
File metadata and controls
56 lines (46 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Adapted from https://github.com/microsoft/testfx/blob/main/src/Platform/Microsoft.Testing.Platform/OutputDevice/Terminal/TestFrameworkDisplay.cs
using System.Globalization;
namespace Microsoft.DotNet.Cli.Commands.Test.Terminal;
internal static class TestFrameworkDisplay
{
public static string GetDisplayName(string? targetFramework, string? architecture, string? runtimeFramework = null)
{
string primary = string.IsNullOrWhiteSpace(targetFramework)
? string.IsNullOrWhiteSpace(architecture) ? string.Empty : architecture
: string.IsNullOrWhiteSpace(architecture)
? targetFramework
: $"{targetFramework}|{architecture}";
if (string.IsNullOrWhiteSpace(runtimeFramework))
{
return primary;
}
if (!string.IsNullOrWhiteSpace(targetFramework) && IsKnownRuntimeFramework(runtimeFramework))
{
int platformSeparator = targetFramework.IndexOf('-');
string baseTargetFramework = platformSeparator < 0 ? targetFramework : targetFramework[..platformSeparator];
if (string.Equals(baseTargetFramework, runtimeFramework, StringComparison.OrdinalIgnoreCase))
{
return primary;
}
}
string runtime = string.Format(CultureInfo.CurrentCulture, CliCommandStrings.RuntimeFramework, runtimeFramework);
return primary.Length == 0 ? runtime : $"{primary}, {runtime}";
}
private static bool IsKnownRuntimeFramework(string framework)
{
if (framework.StartsWith("netcoreapp", StringComparison.OrdinalIgnoreCase))
{
return Version.TryParse(framework[10..], out _);
}
if (!framework.StartsWith("net", StringComparison.OrdinalIgnoreCase))
{
return false;
}
string version = framework[3..];
return Version.TryParse(version, out _)
|| (version.Length is 2 or 3 && version[0] == '4' && int.TryParse(version, NumberStyles.None, CultureInfo.InvariantCulture, out _));
}
}