Skip to content

Commit fe2701b

Browse files
committed
Remove warnings from terminal when compiling the test runner.
A fix for the test runner that patches most of the warnings that are reported in the terminal when compiling the test runner. Some warnings were suppressed as it was too time-consuming or there were impacts to other parts of the test runner when they were fixed.
1 parent 116605a commit fe2701b

15 files changed

+132
-74
lines changed

Turkey/BashTest.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ protected override async Task<TestResult> InternalRunAsync(Action<string> logger
3838
startInfo.EnvironmentVariables.Add(key, value);
3939
}
4040

41-
int exitCode = await ProcessRunner.RunAsync(startInfo, logger, cancellationToken);
41+
int exitCode = await ProcessRunner.RunAsync(startInfo, logger, cancellationToken).ConfigureAwait(false);
4242

4343
return exitCode == 0 ? TestResult.Passed : TestResult.Failed;
4444
}

Turkey/Cleaner.cs

+11-4
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ public static IEnumerable<string> LocalProjectCruft()
3636
yield return "project.lock.json";
3737
}
3838

39-
public async Task CleanProjectLocalDotNetCruftAsync()
39+
#pragma warning disable CA1822 // Mark members as static
40+
public Task CleanProjectLocalDotNetCruftAsync()
41+
#pragma warning restore CA1822 // Mark members as static
4042
{
4143

4244
foreach(var name in LocalProjectCruft())
@@ -51,9 +53,12 @@ public async Task CleanProjectLocalDotNetCruftAsync()
5153
File.Delete(name);
5254
}
5355
}
56+
return Task.CompletedTask;
5457
}
5558

56-
public async Task CleanLocalDotNetCacheAsync()
59+
#pragma warning disable CA1822 // Mark members as static
60+
public Task CleanLocalDotNetCacheAsync()
61+
#pragma warning restore CA1822 // Mark members as static
5762
{
5863
foreach (var path in CruftDirectoryGlobs())
5964
{
@@ -77,12 +82,14 @@ public async Task CleanLocalDotNetCacheAsync()
7782
Console.WriteLine($"WARNING: unable to expand {path}");
7883
}
7984
}
80-
return;
85+
return Task.CompletedTask;
8186
}
8287

88+
#pragma warning disable CA1822 // Mark members as static
8389
public IEnumerable<string> ExpandPath(string pathWithGlob)
90+
#pragma warning restore CA1822 // Mark members as static
8491
{
85-
if (pathWithGlob.StartsWith("~"))
92+
if (pathWithGlob.StartsWith("~", StringComparison.Ordinal))
8693
{
8794
pathWithGlob = Environment.GetEnvironmentVariable("HOME") + pathWithGlob.Substring(1);
8895
}

Turkey/DotNet.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public List<Version> RuntimeVersions
4343
string output = p.StandardOutput.ReadToEnd();
4444
var list = output
4545
.Split("\n", StringSplitOptions.RemoveEmptyEntries)
46-
.Where(line => line.StartsWith("Microsoft.NETCore.App"))
46+
.Where(line => line.StartsWith("Microsoft.NETCore.App", StringComparison.Ordinal))
4747
.Select(line => line.Split(" ")[1])
4848
.Select(versionString => Version.Parse(versionString))
4949
.OrderBy(x => x)
@@ -137,7 +137,7 @@ private async Task<int> RunDotNetCommandAsync(DirectoryInfo workingDirectory, st
137137
startInfo.EnvironmentVariables.Add(key, value);
138138
}
139139

140-
return await ProcessRunner.RunAsync(startInfo, logger, token);
140+
return await ProcessRunner.RunAsync(startInfo, logger, token).ConfigureAwait(false);
141141
}
142142

143143
private static bool IsCoreClrRuntime(string dotnetRoot, Version version)
@@ -159,7 +159,9 @@ private static bool IsCoreClrRuntime(string dotnetRoot, Version version)
159159
return File.Exists(Path.Combine(runtimeDir, "libcoreclrtraceptprovider.so"));
160160
}
161161

162+
#nullable enable
162163
private static string? FindProgramInPath(string program)
164+
#nullable disable
163165
{
164166
string[] paths = Environment.GetEnvironmentVariable("PATH")?.Split(':', StringSplitOptions.RemoveEmptyEntries) ?? Array.Empty<string>();
165167
foreach (string p in paths)

Turkey/IEnumerableExtensions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public static async Task ForEachAsync<T>(this IEnumerable<T> items, Func<T, Task
1010
{
1111
foreach (T item in items)
1212
{
13-
await task(item);
13+
await task(item).ConfigureAwait(false);
1414
}
1515
}
1616
}

Turkey/NuGet.cs

+20-12
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,34 @@ public NuGet(HttpClient client)
2121
public async Task<bool> IsPackageLiveAsync(string name, Version version)
2222
{
2323
var url = $"https://api-v2v3search-0.nuget.org/autocomplete?id={name}&prerelease=true";
24-
var result = await _client.GetStringAsync(url);
25-
return await IsPackageLiveAsync(name, version, result);
24+
Uri uri = new(url);
25+
var result = await _client.GetStringAsync(uri).ConfigureAwait(false);
26+
return await IsPackageLiveAsync(name, version, result).ConfigureAwait(false);
2627
}
2728

28-
public async Task<bool> IsPackageLiveAsync(string name, Version version, string json)
29+
#pragma warning disable CA1801 // Remove unused parameter
30+
#pragma warning disable CA1822 // Mark members as static
31+
public Task<bool> IsPackageLiveAsync(string name, Version version, string json)
32+
#pragma warning restore CA1822 // Mark members as static
33+
#pragma warning restore CA1801 // Remove unused parameter
2934
{
3035
JObject deserialized = (JObject) JsonConvert.DeserializeObject(json);
31-
JArray versions = (JArray) deserialized.GetValue("data");
36+
JArray versions = (JArray) deserialized.GetValue("data", StringComparison.Ordinal);
3237
var found = versions.Children<JToken>()
33-
.Where(v => v.Value<string>().Equals(version.ToString()))
38+
.Where(v => v.Value<string>().Equals(version.ToString(), StringComparison.Ordinal))
3439
.Any();
35-
return found;
40+
return Task.FromResult(found);
3641
}
3742

38-
public async Task<string> GenerateNuGetConfig(List<string> urls, string nugetConfig = null)
43+
#pragma warning disable CA1822 // Mark members as static
44+
public Task<string> GenerateNuGetConfig(List<string> urls, string nugetConfig = null)
45+
#pragma warning restore CA1822 // Mark members as static
3946
{
40-
if( !urls.Any() && nugetConfig == null )
41-
throw new ArgumentNullException();
47+
if (!urls.Any())
48+
ArgumentNullException.ThrowIfNull(nugetConfig);
4249

4350
string sources = null;
44-
if( urls.Any() )
51+
if (urls.Any())
4552
{
4653
var sourceParts = new List<string>(urls.Count);
4754
for( int i = 0; i < urls.Count; i++ )
@@ -54,6 +61,7 @@ public async Task<string> GenerateNuGetConfig(List<string> urls, string nugetCon
5461
{
5562
sources = $" {sources}\n";
5663
}
64+
5765
}
5866

5967
if( string.IsNullOrWhiteSpace(nugetConfig) )
@@ -66,9 +74,9 @@ public async Task<string> GenerateNuGetConfig(List<string> urls, string nugetCon
6674
}
6775

6876
if( !string.IsNullOrWhiteSpace(sources) )
69-
nugetConfig = nugetConfig.Replace("</packageSources>", sources + "</packageSources>");
77+
nugetConfig = nugetConfig.Replace("</packageSources>", sources + "</packageSources>", StringComparison.Ordinal);
7078

71-
return nugetConfig;
79+
return Task.FromResult(nugetConfig);
7280
}
7381

7482
}

Turkey/PlatformId.cs

+8-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ public List<string> CurrentIds
1818

1919
public List<string> ComputePlatformIds(string[] osReleaseLines, string lddVersionOutput)
2020
{
21-
string arch = Enum.GetName(typeof(Architecture), RuntimeInformation.OSArchitecture).ToLowerInvariant();
21+
#pragma warning disable CA1308 // Normalize strings to uppercase
22+
string arch = RuntimeInformation.OSArchitecture.ToString().ToLowerInvariant();
23+
#pragma warning restore CA1308 // Normalize strings to uppercase
2224
return ComputePlatformIds(osReleaseLines, arch, lddVersionOutput);
2325
}
2426

@@ -63,25 +65,27 @@ public List<string> ComputePlatformIds(string[] osReleaseLines, string architect
6365
return platforms.ToList();
6466
}
6567

66-
private string GetValue(string key, string[] lines)
68+
private static string GetValue(string key, string[] lines)
6769
{
6870
return lines.Where(line => line.StartsWith(key + "=", StringComparison.Ordinal)).Last().Substring((key + "=").Length);
6971
}
7072

71-
private string Unquote(string text)
73+
private static string Unquote(string text)
7274
{
7375
// TODO implement proper un-escaping
7476
// This is a limited shell-style syntax described at
7577
// https://www.freedesktop.org/software/systemd/man/os-release.html
76-
if (text.StartsWith("\"") && text.EndsWith("\""))
78+
if (text.StartsWith("\"", StringComparison.Ordinal) && text.EndsWith("\"", StringComparison.Ordinal))
7779
{
7880
return text.Substring(1, text.Length - 2);
7981
}
8082

8183
return text;
8284
}
8385

86+
#pragma warning disable CA1822 // Mark members as static
8487
internal string GetLddVersion()
88+
#pragma warning restore CA1822 // Mark members as static
8589
{
8690
using (Process p = new Process())
8791
{

Turkey/ProcessExtensions.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public static async Task<int> RunAsync(ProcessStartInfo psi, Action<string> logg
1212
{
1313
logger($"Executing {psi.FileName} with arguments {psi.Arguments} in working directory {psi.WorkingDirectory}");
1414
using var process = Process.Start(psi);
15-
await process.WaitForExitAsync(logger, token);
15+
await process.WaitForExitAsync(logger, token).ConfigureAwait(false);
1616
return process.ExitCode;
1717
}
1818
}
@@ -43,11 +43,11 @@ public static async Task WaitForExitAsync(this Process process, Action<string> l
4343

4444
try
4545
{
46-
await process.WaitForExitAsync(token);
46+
await process.WaitForExitAsync(token).ConfigureAwait(false);
4747

4848
logger($"Process Exit Code: {process.ExitCode}");
4949
}
50-
catch (OperationCanceledException ex)
50+
catch (OperationCanceledException)
5151
{
5252
lock (logger)
5353
{

Turkey/Program.cs

+12-6
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212

1313
namespace Turkey
1414
{
15+
#pragma warning disable CA1052 // Static holder types should be Static or NotInheritable
1516
public class Program
17+
#pragma warning restore CA1052 // Static holder types should be Static or NotInheritable
1618
{
1719
public static readonly Option<bool> verboseOption = new Option<bool>(
1820
new string[] { "--verbose", "-v" },
@@ -118,7 +120,7 @@ public static async Task<int> Run(string testRoot,
118120

119121
Version packageVersion = runtimeVersion;
120122
string nuGetConfig = await GenerateNuGetConfigIfNeededAsync(additionalFeed, packageVersion,
121-
useSourceBuildNuGetConfig: false);
123+
useSourceBuildNuGetConfig: false).ConfigureAwait(false);
122124
if (verbose && nuGetConfig != null)
123125
{
124126
Console.WriteLine("Using nuget.config: ");
@@ -132,7 +134,7 @@ public static async Task<int> Run(string testRoot,
132134
verboseOutput: verbose,
133135
nuGetConfig: nuGetConfig);
134136

135-
var results = await runner.ScanAndRunAsync(testOutputs, logDir.FullName, defaultTimeout);
137+
var results = await runner.ScanAndRunAsync(testOutputs, logDir.FullName, defaultTimeout).ConfigureAwait(false);
136138

137139
int exitCode = (results.Failed == 0) ? 0 : 1;
138140
return exitCode;
@@ -157,7 +159,7 @@ public static async Task<string> GenerateNuGetConfigIfNeededAsync(string additio
157159
{
158160
try
159161
{
160-
nugetConfig = await sourceBuild.GetNuGetConfigAsync(netCoreAppVersion);
162+
nugetConfig = await sourceBuild.GetNuGetConfigAsync(netCoreAppVersion).ConfigureAwait(false);
161163
}
162164
catch( HttpRequestException exception )
163165
{
@@ -173,14 +175,16 @@ public static async Task<string> GenerateNuGetConfigIfNeededAsync(string additio
173175
// if the nugetConfig has a <clear/> element that removes
174176
// it.
175177
urls.Add("https://api.nuget.org/v3/index.json");
176-
return await nuget.GenerateNuGetConfig(urls, nugetConfig);
178+
return await nuget.GenerateNuGetConfig(urls, nugetConfig).ConfigureAwait(false);
177179
}
178180
}
179181

180182
return null;
181183
}
182184

185+
#pragma warning disable CA1801 // Remove unused parameter
183186
public static IReadOnlySet<string> CreateTraits(Version runtimeVersion, Version sdkVersion, List<string> rids, bool isMonoRuntime, IEnumerable<string> additionalTraits)
187+
#pragma warning restore CA1801 // Remove unused parameter
184188
{
185189
var traits = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
186190

@@ -199,7 +203,9 @@ public static IReadOnlySet<string> CreateTraits(Version runtimeVersion, Version
199203
}
200204

201205
// Add 'arch=' trait.
206+
#pragma warning disable CA1308 // Normalize strings to uppercase
202207
string arch = RuntimeInformation.OSArchitecture.ToString().ToLowerInvariant();
208+
#pragma warning restore CA1308 // Normalize strings to uppercase
203209
traits.Add($"arch={arch}");
204210

205211
// Add 'runtime=' trait.
@@ -231,7 +237,7 @@ static async Task<int> Main(string[] args)
231237
rootCommand.AddOption(traitOption);
232238
rootCommand.AddOption(timeoutOption);
233239

234-
return await rootCommand.InvokeAsync(args);
240+
return await rootCommand.InvokeAsync(args).ConfigureAwait(false);
235241
}
236242
}
237-
}
243+
}

Turkey/SourceBuild.cs

+9-6
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ public SourceBuild(HttpClient client)
1616
this._client = client;
1717
}
1818

19-
public string GetBranchContentUrl(Version version)
19+
public static System.Uri GetBranchContentUrl(Version version)
2020
{
2121
var branchName = "release/" + version.MajorMinor + ".1xx";
2222
var url = $"https://raw.githubusercontent.com/dotnet/installer/{branchName}/";
23-
return url;
23+
Uri uri = new(url);
24+
return uri;
2425
}
2526

2627
public async Task<string> GetProdConFeedAsync(Version version)
@@ -31,9 +32,10 @@ public async Task<string> GetProdConFeedAsync(Version version)
3132
}
3233

3334
var url = GetBranchContentUrl(version) + "ProdConFeed.txt";
34-
var feedUrl = await _client.GetStringAsync(url);
35-
36-
using(var response = await _client.GetAsync(feedUrl))
35+
Uri uri = new(url);
36+
var feedUrl = await _client.GetStringAsync(uri).ConfigureAwait(false);
37+
Uri feedUri = new(feedUrl);
38+
using(var response = await _client.GetAsync(feedUri).ConfigureAwait(false))
3739
{
3840
if (!response.IsSuccessStatusCode)
3941
{
@@ -46,11 +48,12 @@ public async Task<string> GetProdConFeedAsync(Version version)
4648
public async Task<string> GetNuGetConfigAsync(Version version)
4749
{
4850
string url = GetBranchContentUrl(version) + "NuGet.config";
51+
Uri uri = new(url);
4952

5053
string nugetConfig = null;
5154
try
5255
{
53-
nugetConfig = await _client.GetStringAsync(url);
56+
nugetConfig = await _client.GetStringAsync(uri).ConfigureAwait(false);
5457
}
5558
catch( HttpRequestException e )
5659
{

Turkey/Test.cs

+6-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@ public class TestDescriptor
1818
public string Type { get; set; }
1919
public bool Cleanup { get; set; }
2020
public double TimeoutMultiplier { get; set; } = 1.0;
21+
22+
#pragma warning disable CA2227 // Change to be read-only by removing the property setter.
2123
public List<string> IgnoredRIDs { get; set; } = new();
2224
public List<string> SkipWhen { get; set; } = new();
25+
26+
#pragma warning restore CA2227
2327
}
2428

2529
// TODO is this a strongly-typed enum in C#?
@@ -58,10 +62,10 @@ public async Task<TestResult> RunAsync(Action<string> logger, CancellationToken
5862
{
5963
Console.WriteLine($"WARNING: overwriting {path}");
6064
}
61-
await File.WriteAllTextAsync(path, NuGetConfig);
65+
await File.WriteAllTextAsync(path, NuGetConfig).ConfigureAwait(false);
6266
}
6367

64-
var testResult = await InternalRunAsync(logger, cancelltionToken);
68+
var testResult = await InternalRunAsync(logger, cancelltionToken).ConfigureAwait(false);
6569

6670
if (!string.IsNullOrEmpty(NuGetConfig))
6771
{

0 commit comments

Comments
 (0)