Skip to content

Commit

Permalink
Remove warnings from terminal when compiling the test runner.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nicrowe00 committed Jan 14, 2025
1 parent 116605a commit 7095b97
Show file tree
Hide file tree
Showing 15 changed files with 129 additions and 77 deletions.
2 changes: 1 addition & 1 deletion Turkey/BashTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected override async Task<TestResult> InternalRunAsync(Action<string> logger
startInfo.EnvironmentVariables.Add(key, value);
}

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

return exitCode == 0 ? TestResult.Passed : TestResult.Failed;
}
Expand Down
15 changes: 11 additions & 4 deletions Turkey/Cleaner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ public static IEnumerable<string> LocalProjectCruft()
yield return "project.lock.json";
}

public async Task CleanProjectLocalDotNetCruftAsync()
#pragma warning disable CA1822 // Mark members as static
public Task CleanProjectLocalDotNetCruftAsync()
#pragma warning restore CA1822 // Mark members as static
{

foreach(var name in LocalProjectCruft())
Expand All @@ -51,9 +53,12 @@ public async Task CleanProjectLocalDotNetCruftAsync()
File.Delete(name);
}
}
return Task.CompletedTask;
}

public async Task CleanLocalDotNetCacheAsync()
#pragma warning disable CA1822 // Mark members as static
public Task CleanLocalDotNetCacheAsync()
#pragma warning restore CA1822 // Mark members as static
{
foreach (var path in CruftDirectoryGlobs())
{
Expand All @@ -77,12 +82,14 @@ public async Task CleanLocalDotNetCacheAsync()
Console.WriteLine($"WARNING: unable to expand {path}");
}
}
return;
return Task.CompletedTask;
}

#pragma warning disable CA1822 // Mark members as static
public IEnumerable<string> ExpandPath(string pathWithGlob)
#pragma warning restore CA1822 // Mark members as static
{
if (pathWithGlob.StartsWith("~"))
if (pathWithGlob.StartsWith("~", StringComparison.Ordinal))
{
pathWithGlob = Environment.GetEnvironmentVariable("HOME") + pathWithGlob.Substring(1);
}
Expand Down
6 changes: 4 additions & 2 deletions Turkey/DotNet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public List<Version> RuntimeVersions
string output = p.StandardOutput.ReadToEnd();
var list = output
.Split("\n", StringSplitOptions.RemoveEmptyEntries)
.Where(line => line.StartsWith("Microsoft.NETCore.App"))
.Where(line => line.StartsWith("Microsoft.NETCore.App", StringComparison.Ordinal))
.Select(line => line.Split(" ")[1])
.Select(versionString => Version.Parse(versionString))
.OrderBy(x => x)
Expand Down Expand Up @@ -137,7 +137,7 @@ private async Task<int> RunDotNetCommandAsync(DirectoryInfo workingDirectory, st
startInfo.EnvironmentVariables.Add(key, value);
}

return await ProcessRunner.RunAsync(startInfo, logger, token);
return await ProcessRunner.RunAsync(startInfo, logger, token).ConfigureAwait(false);
}

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

#nullable enable
private static string? FindProgramInPath(string program)
#nullable disable
{
string[] paths = Environment.GetEnvironmentVariable("PATH")?.Split(':', StringSplitOptions.RemoveEmptyEntries) ?? Array.Empty<string>();
foreach (string p in paths)
Expand Down
2 changes: 1 addition & 1 deletion Turkey/IEnumerableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static async Task ForEachAsync<T>(this IEnumerable<T> items, Func<T, Task
{
foreach (T item in items)
{
await task(item);
await task(item).ConfigureAwait(false);
}
}
}
Expand Down
30 changes: 19 additions & 11 deletions Turkey/NuGet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,31 @@ public NuGet(HttpClient client)
public async Task<bool> IsPackageLiveAsync(string name, Version version)
{
var url = $"https://api-v2v3search-0.nuget.org/autocomplete?id={name}&prerelease=true";
var result = await _client.GetStringAsync(url);
return await IsPackageLiveAsync(name, version, result);
Uri uri = new(url);
var result = await _client.GetStringAsync(uri).ConfigureAwait(false);
return await IsPackageLiveAsync(name, version, result).ConfigureAwait(false);
}

public async Task<bool> IsPackageLiveAsync(string name, Version version, string json)
#pragma warning disable CA1801 // Remove unused parameter
#pragma warning disable CA1822 // Mark members as static
public Task<bool> IsPackageLiveAsync(string name, Version version, string json)
#pragma warning restore CA1822 // Mark members as static
#pragma warning restore CA1801 // Remove unused parameter
{
JObject deserialized = (JObject) JsonConvert.DeserializeObject(json);
JArray versions = (JArray) deserialized.GetValue("data");
JArray versions = (JArray) deserialized.GetValue("data", StringComparison.Ordinal);
var found = versions.Children<JToken>()
.Where(v => v.Value<string>().Equals(version.ToString()))
.Where(v => v.Value<string>().Equals(version.ToString(), StringComparison.Ordinal))
.Any();
return found;
return Task.FromResult(found);
}

public async Task<string> GenerateNuGetConfig(List<string> urls, string nugetConfig = null)
#pragma warning disable CA1822 // Mark members as static
public Task<string> GenerateNuGetConfig(List<string> urls, string nugetConfig = null)
#pragma warning restore CA1822 // Mark members as static
{
if( !urls.Any() && nugetConfig == null )
throw new ArgumentNullException();
if(!urls.Any())
ArgumentNullException.ThrowIfNull(nugetConfig);

string sources = null;
if( urls.Any() )
Expand All @@ -54,6 +61,7 @@ public async Task<string> GenerateNuGetConfig(List<string> urls, string nugetCon
{
sources = $" {sources}\n";
}

}

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

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

return nugetConfig;
return Task.FromResult(nugetConfig);
}

}
Expand Down
12 changes: 8 additions & 4 deletions Turkey/PlatformId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ public List<string> CurrentIds

public List<string> ComputePlatformIds(string[] osReleaseLines, string lddVersionOutput)
{
string arch = Enum.GetName(typeof(Architecture), RuntimeInformation.OSArchitecture).ToLowerInvariant();
#pragma warning disable CA1308 // Normalize strings to uppercase
string arch = RuntimeInformation.OSArchitecture.ToString().ToLowerInvariant();
#pragma warning restore CA1308 // Normalize strings to uppercase
return ComputePlatformIds(osReleaseLines, arch, lddVersionOutput);
}

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

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

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

return text;
}

#pragma warning disable CA1822 // Mark members as static
internal string GetLddVersion()
#pragma warning restore CA1822 // Mark members as static
{
using (Process p = new Process())
{
Expand Down
6 changes: 3 additions & 3 deletions Turkey/ProcessExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static async Task<int> RunAsync(ProcessStartInfo psi, Action<string> logg
{
logger($"Executing {psi.FileName} with arguments {psi.Arguments} in working directory {psi.WorkingDirectory}");
using var process = Process.Start(psi);
await process.WaitForExitAsync(logger, token);
await process.WaitForExitAsync(logger, token).ConfigureAwait(false);
return process.ExitCode;
}
}
Expand Down Expand Up @@ -43,11 +43,11 @@ public static async Task WaitForExitAsync(this Process process, Action<string> l

try
{
await process.WaitForExitAsync(token);
await process.WaitForExitAsync(token).ConfigureAwait(false);

logger($"Process Exit Code: {process.ExitCode}");
}
catch (OperationCanceledException ex)
catch (OperationCanceledException)
{
lock (logger)
{
Expand Down
20 changes: 12 additions & 8 deletions Turkey/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
using System.Runtime.InteropServices;

namespace Turkey
{
public class Program
{ public static class Program

{
public static readonly Option<bool> verboseOption = new Option<bool>(
new string[] { "--verbose", "-v" },
Expand Down Expand Up @@ -118,7 +118,7 @@ public static async Task<int> Run(string testRoot,

Version packageVersion = runtimeVersion;
string nuGetConfig = await GenerateNuGetConfigIfNeededAsync(additionalFeed, packageVersion,
useSourceBuildNuGetConfig: false);
useSourceBuildNuGetConfig: false).ConfigureAwait(false);
if (verbose && nuGetConfig != null)
{
Console.WriteLine("Using nuget.config: ");
Expand All @@ -132,7 +132,7 @@ public static async Task<int> Run(string testRoot,
verboseOutput: verbose,
nuGetConfig: nuGetConfig);

var results = await runner.ScanAndRunAsync(testOutputs, logDir.FullName, defaultTimeout);
var results = await runner.ScanAndRunAsync(testOutputs, logDir.FullName, defaultTimeout).ConfigureAwait(false);

int exitCode = (results.Failed == 0) ? 0 : 1;
return exitCode;
Expand All @@ -157,7 +157,7 @@ public static async Task<string> GenerateNuGetConfigIfNeededAsync(string additio
{
try
{
nugetConfig = await sourceBuild.GetNuGetConfigAsync(netCoreAppVersion);
nugetConfig = await sourceBuild.GetNuGetConfigAsync(netCoreAppVersion).ConfigureAwait(false);
}
catch( HttpRequestException exception )
{
Expand All @@ -173,14 +173,16 @@ public static async Task<string> GenerateNuGetConfigIfNeededAsync(string additio
// if the nugetConfig has a <clear/> element that removes
// it.
urls.Add("https://api.nuget.org/v3/index.json");
return await nuget.GenerateNuGetConfig(urls, nugetConfig);
return await nuget.GenerateNuGetConfig(urls, nugetConfig).ConfigureAwait(false);
}
}

return null;
}

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

Expand All @@ -199,7 +201,9 @@ public static IReadOnlySet<string> CreateTraits(Version runtimeVersion, Version
}

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

// Add 'runtime=' trait.
Expand Down Expand Up @@ -231,7 +235,7 @@ static async Task<int> Main(string[] args)
rootCommand.AddOption(traitOption);
rootCommand.AddOption(timeoutOption);

return await rootCommand.InvokeAsync(args);
return await rootCommand.InvokeAsync(args).ConfigureAwait(false);
}
}
}
}
15 changes: 9 additions & 6 deletions Turkey/SourceBuild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ public SourceBuild(HttpClient client)
this._client = client;
}

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

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

var url = GetBranchContentUrl(version) + "ProdConFeed.txt";
var feedUrl = await _client.GetStringAsync(url);

using(var response = await _client.GetAsync(feedUrl))
Uri uri = new(url);
var feedUrl = await _client.GetStringAsync(uri).ConfigureAwait(false);
Uri feedUri = new(feedUrl);
using(var response = await _client.GetAsync(feedUri).ConfigureAwait(false))
{
if (!response.IsSuccessStatusCode)
{
Expand All @@ -46,11 +48,12 @@ public async Task<string> GetProdConFeedAsync(Version version)
public async Task<string> GetNuGetConfigAsync(Version version)
{
string url = GetBranchContentUrl(version) + "NuGet.config";
Uri uri = new(url);

string nugetConfig = null;
try
{
nugetConfig = await _client.GetStringAsync(url);
nugetConfig = await _client.GetStringAsync(uri).ConfigureAwait(false);
}
catch( HttpRequestException e )
{
Expand Down
8 changes: 4 additions & 4 deletions Turkey/Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public class TestDescriptor
public string Type { get; set; }
public bool Cleanup { get; set; }
public double TimeoutMultiplier { get; set; } = 1.0;
public List<string> IgnoredRIDs { get; set; } = new();
public List<string> SkipWhen { get; set; } = new();
internal List<string> IgnoredRIDs = new();
internal List<string> SkipWhen = new();
}

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

var testResult = await InternalRunAsync(logger, cancelltionToken);
var testResult = await InternalRunAsync(logger, cancelltionToken).ConfigureAwait(false);

if (!string.IsNullOrEmpty(NuGetConfig))
{
Expand Down
Loading

0 comments on commit 7095b97

Please sign in to comment.