diff --git a/src/ANcpLua.Roslyn.Utilities.Examples.XunitCancellationAnalyzer/MissingCancellationTokenAnalyzer.cs b/src/ANcpLua.Roslyn.Utilities.Examples.XunitCancellationAnalyzer/MissingCancellationTokenAnalyzer.cs index 44f9d85..4de9fff 100644 --- a/src/ANcpLua.Roslyn.Utilities.Examples.XunitCancellationAnalyzer/MissingCancellationTokenAnalyzer.cs +++ b/src/ANcpLua.Roslyn.Utilities.Examples.XunitCancellationAnalyzer/MissingCancellationTokenAnalyzer.cs @@ -88,7 +88,10 @@ private static bool IsDefaultLike(IOperation operation, ITypeSymbol cancellation || operation.Syntax.IsKind(SyntaxKind.DefaultLiteralExpression)) return true; - return operation is IPropertyReferenceOperation { Property.Name: "None", Property.ContainingType: { } containingType } + return operation is IPropertyReferenceOperation + { + Property: { Name: "None", ContainingType: { } containingType } + } && containingType.IsEqualTo(cancellationTokenType); } } diff --git a/src/ANcpLua.Roslyn.Utilities.Examples.XunitCancellationCodeFixes/MissingCancellationTokenFixer.cs b/src/ANcpLua.Roslyn.Utilities.Examples.XunitCancellationCodeFixes/MissingCancellationTokenFixer.cs index ca571dd..c27fa40 100644 --- a/src/ANcpLua.Roslyn.Utilities.Examples.XunitCancellationCodeFixes/MissingCancellationTokenFixer.cs +++ b/src/ANcpLua.Roslyn.Utilities.Examples.XunitCancellationCodeFixes/MissingCancellationTokenFixer.cs @@ -48,12 +48,9 @@ private static async Task ApplyAsync( Diagnostic diagnostic, CancellationToken cancellationToken) { - if (!diagnostic.Properties.TryGetValue(DiagnosticPropertyNames.ParameterName, out var parameterName)) - return document; - if (string.IsNullOrWhiteSpace(parameterName)) - return document; - - if (!diagnostic.Properties.TryGetValue(DiagnosticPropertyNames.ParameterIndex, out var parameterIndexText) + if (!diagnostic.Properties.TryGetValue(DiagnosticPropertyNames.ParameterName, out var parameterName) + || string.IsNullOrWhiteSpace(parameterName) + || !diagnostic.Properties.TryGetValue(DiagnosticPropertyNames.ParameterIndex, out var parameterIndexText) || !int.TryParse(parameterIndexText, out var parameterIndex)) return document; diff --git a/src/ANcpLua.Roslyn.Utilities.Testing/GeneratorTestEngine.cs b/src/ANcpLua.Roslyn.Utilities.Testing/GeneratorTestEngine.cs index 9f7d6e8..db41878 100644 --- a/src/ANcpLua.Roslyn.Utilities.Testing/GeneratorTestEngine.cs +++ b/src/ANcpLua.Roslyn.Utilities.Testing/GeneratorTestEngine.cs @@ -120,7 +120,7 @@ public GeneratorTestEngine WithStepTracking(bool trackSteps = true) /// A task that resolves to a . public async Task CreateCompilationAsync(CancellationToken cancellationToken = default) { - var resolvedReferences = await _referenceAssemblies.ResolveAsync(LanguageNames.CSharp, cancellationToken); + var resolvedReferences = await _referenceAssemblies.ResolveAsync(LanguageNames.CSharp, cancellationToken).ConfigureAwait(false); var allReferences = resolvedReferences .Concat(_references) @@ -163,7 +163,7 @@ public GeneratorDriver CreateDriver() internal async Task<(GeneratorDriverRunResult FirstRun, GeneratorDriverRunResult SecondRun)> RunTwiceAsync( CancellationToken cancellationToken = default) { - var compilation = await CreateCompilationAsync(cancellationToken); + var compilation = await CreateCompilationAsync(cancellationToken).ConfigureAwait(false); var driver = CreateDriver(); // First run diff --git a/src/ANcpLua.Roslyn.Utilities.Testing/LogAssert.cs b/src/ANcpLua.Roslyn.Utilities.Testing/LogAssert.cs index 8c09d0c..65f0d3c 100644 --- a/src/ANcpLua.Roslyn.Utilities.Testing/LogAssert.cs +++ b/src/ANcpLua.Roslyn.Utilities.Testing/LogAssert.cs @@ -331,7 +331,7 @@ public static async Task ShouldEventuallyContain( collector, logs => logs.Any(r => r.Message.Contains(text)), timeout, - ct); + ct).ConfigureAwait(false); Assert.True(found, $"Timed out waiting for log containing '{text}'.\nActual logs:\n{collector.FormatLogs()}"); @@ -355,7 +355,7 @@ public static async Task ShouldEventuallyHaveCount( collector, logs => logs.Count >= count, timeout, - ct); + ct).ConfigureAwait(false); Assert.True(found, $"Timed out waiting for {count} logs, got {collector.GetSnapshot().Count}.\nActual logs:\n{collector.FormatLogs()}"); @@ -379,7 +379,7 @@ public static async Task ShouldEventuallyHaveLevel( collector, logs => logs.Any(r => r.Level == level), timeout, - ct); + ct).ConfigureAwait(false); Assert.True(found, $"Timed out waiting for {level} log.\nActual logs:\n{collector.FormatLogs()}"); @@ -401,7 +401,7 @@ public static async Task ShouldEventuallySatisfy( TimeSpan? timeout = null, CancellationToken ct = default) { - var found = await WaitForCondition(collector, condition, timeout, ct); + var found = await WaitForCondition(collector, condition, timeout, ct).ConfigureAwait(false); Assert.True(found, because ?? $"Timed out waiting for condition.\nActual logs:\n{collector.FormatLogs()}"); diff --git a/src/ANcpLua.Roslyn.Utilities.Testing/MSBuild/DotNetSdkHelpers.cs b/src/ANcpLua.Roslyn.Utilities.Testing/MSBuild/DotNetSdkHelpers.cs index 6975998..1e55760 100644 --- a/src/ANcpLua.Roslyn.Utilities.Testing/MSBuild/DotNetSdkHelpers.cs +++ b/src/ANcpLua.Roslyn.Utilities.Testing/MSBuild/DotNetSdkHelpers.cs @@ -103,7 +103,7 @@ public static async Task Get(NetSdkVersion version) if (Values.TryGetValue(version, out var result)) return result; - using (await KeyedAsyncLock.LockAsync(version)) + using (await KeyedAsyncLock.LockAsync(version).ConfigureAwait(false)) { if (Values.TryGetValue(version, out result)) return result; @@ -114,9 +114,9 @@ public static async Task Get(NetSdkVersion version) _ => throw new NotSupportedException($"SDK version {version} is not supported") }; - var products = await ProductCollection.GetAsync(); + var products = await ProductCollection.GetAsync().ConfigureAwait(false); var product = products.Single(a => a.ProductName == ".NET" && a.ProductVersion == versionString); - var releases = await product.GetReleasesAsync(); + var releases = await product.GetReleasesAsync().ConfigureAwait(false); var latestRelease = releases.Single(r => r.Version == product.LatestReleaseVersion); var latestSdk = latestRelease.Sdks.MaxBy(static sdk => sdk.Version) ?? throw new InvalidOperationException($"No SDK found for .NET {versionString}"); @@ -135,19 +135,19 @@ public static async Task Get(NetSdkVersion version) var tempFolder = FullPath.GetTempPath() / "dotnet" / Guid.NewGuid().ToString("N"); - var bytes = await HttpClient.GetByteArrayAsync(file.Address); + var bytes = await HttpClient.GetByteArrayAsync(file.Address).ConfigureAwait(false); if (Path.GetExtension(file.Name) is ".zip") { using var ms = new MemoryStream(bytes); var zip = new ZipArchive(ms); - await zip.ExtractToDirectoryAsync(tempFolder, true); + await zip.ExtractToDirectoryAsync(tempFolder, true).ConfigureAwait(false); } else { using var ms = new MemoryStream(bytes); await using var gz = new GZipStream(ms, CompressionMode.Decompress); await using var tar = new TarReader(gz); - while (await tar.GetNextEntryAsync() is { } entry) + while ((await tar.GetNextEntryAsync().ConfigureAwait(false)) is { } entry) { var destinationPath = tempFolder / entry.Name; switch (entry.EntryType) @@ -161,7 +161,7 @@ public static async Task Get(NetSdkVersion version) Directory.CreateDirectory(parentDir); var entryStream = entry.DataStream; await using var outputStream = File.Create(destinationPath); - if (entryStream is not null) await entryStream.CopyToAsync(outputStream); + if (entryStream is not null) await entryStream.CopyToAsync(outputStream).ConfigureAwait(false); break; } } diff --git a/src/ANcpLua.Roslyn.Utilities.Testing/MSBuild/NuGetPackageFixture.cs b/src/ANcpLua.Roslyn.Utilities.Testing/MSBuild/NuGetPackageFixture.cs index aed44f6..df048f3 100644 --- a/src/ANcpLua.Roslyn.Utilities.Testing/MSBuild/NuGetPackageFixture.cs +++ b/src/ANcpLua.Roslyn.Utilities.Testing/MSBuild/NuGetPackageFixture.cs @@ -177,7 +177,7 @@ public async ValueTask InitializeAsync() } // Local development mode: pre-warm the cache - await PreWarmNuGetCacheAsync(); + await PreWarmNuGetCacheAsync().ConfigureAwait(false); } /// @@ -185,7 +185,7 @@ public async ValueTask InitializeAsync() /// public virtual async ValueTask DisposeAsync() { - await _packageDirectory.DisposeAsync(); + await _packageDirectory.DisposeAsync().ConfigureAwait(false); GC.SuppressFinalize(this); } @@ -218,7 +218,7 @@ private async Task PreWarmNuGetCacheAsync() """; - await File.WriteAllTextAsync(warmupDir / "NuGet.config", nugetConfig); + await File.WriteAllTextAsync(warmupDir / "NuGet.config", nugetConfig).ConfigureAwait(false); var packageRefs = string.Join("\n ", _preWarmPackages.Select(static p => @@ -234,7 +234,7 @@ private async Task PreWarmNuGetCacheAsync() """; - await File.WriteAllTextAsync(warmupDir / "warmup.csproj", csproj); + await File.WriteAllTextAsync(warmupDir / "warmup.csproj", csproj).ConfigureAwait(false); var psi = new ProcessStartInfo("dotnet") { @@ -246,7 +246,7 @@ private async Task PreWarmNuGetCacheAsync() }; psi.ArgumentList.AddRange("restore", "--no-cache"); - var result = await psi.RunAsTaskAsync(CancellationToken.None); + var result = await psi.RunAsTaskAsync(CancellationToken.None).ConfigureAwait(false); if (result.ExitCode is not 0) throw new InvalidOperationException( $"NuGet cache pre-warm failed with exit code {result.ExitCode}. Output: {result.Output}"); diff --git a/src/ANcpLua.Roslyn.Utilities.Testing/MSBuild/PackageProjectBuilder.cs b/src/ANcpLua.Roslyn.Utilities.Testing/MSBuild/PackageProjectBuilder.cs index 0c49cf0..1d50a49 100644 --- a/src/ANcpLua.Roslyn.Utilities.Testing/MSBuild/PackageProjectBuilder.cs +++ b/src/ANcpLua.Roslyn.Utilities.Testing/MSBuild/PackageProjectBuilder.cs @@ -250,7 +250,7 @@ public override async Task ExecuteDotnetCommandAsync( { BuildCount++; - var psi = new ProcessStartInfo(await DotNetSdkHelpers.Get(SdkVersion)) + var psi = new ProcessStartInfo(await DotNetSdkHelpers.Get(SdkVersion).ConfigureAwait(false)) { WorkingDirectory = Directory.FullPath, RedirectStandardOutput = true, @@ -310,7 +310,7 @@ public override async Task ExecuteDotnetCommandAsync( foreach (var env in environmentVariables) psi.Environment[env.Name] = env.Value; - var result = await psi.RunAsTaskAsync(); + var result = await psi.RunAsTaskAsync().ConfigureAwait(false); // Retry logic for SDK resolution failures const int maxRetries = 5; @@ -320,8 +320,8 @@ public override async Task ExecuteDotnetCommandAsync( line.Text.Contains("The project file may be invalid or missing targets required for restore", StringComparison.Ordinal))) { - await Task.Delay(100 * (1 << retry)); - result = await psi.RunAsTaskAsync(); + await Task.Delay(100 * (1 << retry)).ConfigureAwait(false); + result = await psi.RunAsTaskAsync().ConfigureAwait(false); } else { @@ -332,11 +332,11 @@ public override async Task ExecuteDotnetCommandAsync( SarifFile? sarif = null; if (File.Exists(sarifPath)) { - var bytes = await File.ReadAllBytesAsync(sarifPath); + var bytes = await File.ReadAllBytesAsync(sarifPath).ConfigureAwait(false); sarif = JsonSerializer.Deserialize(bytes); } - var binlogContent = await File.ReadAllBytesAsync(Directory.FullPath / "msbuild.binlog"); + var binlogContent = await File.ReadAllBytesAsync(Directory.FullPath / "msbuild.binlog").ConfigureAwait(false); return new BuildResult(result.ExitCode, result.Output, sarif, binlogContent); } @@ -564,10 +564,10 @@ public void AddDirectoryBuildPropsFile(string postSdkContent, string preSdkConte /// public async Task InitializeGitRepoAsync() { - await ExecuteGitCommand("init"); - await ExecuteGitCommand("add", "."); - await ExecuteGitCommand("commit", "-m", "Initial commit"); - await ExecuteGitCommand("remote", "add", "origin", "https://github.com/ancplua/sample.git"); + await ExecuteGitCommand("init").ConfigureAwait(false); + await ExecuteGitCommand("add", ".").ConfigureAwait(false); + await ExecuteGitCommand("commit", "-m", "Initial commit").ConfigureAwait(false); + await ExecuteGitCommand("remote", "add", "origin", "https://github.com/ancplua/sample.git").ConfigureAwait(false); } /// diff --git a/src/ANcpLua.Roslyn.Utilities.Testing/MSBuild/PackageTestBase.cs b/src/ANcpLua.Roslyn.Utilities.Testing/MSBuild/PackageTestBase.cs index 2849b42..24a7f16 100644 --- a/src/ANcpLua.Roslyn.Utilities.Testing/MSBuild/PackageTestBase.cs +++ b/src/ANcpLua.Roslyn.Utilities.Testing/MSBuild/PackageTestBase.cs @@ -301,7 +301,7 @@ protected override async Task QuickBuild( .WithOutputType(Val.Library) .WithProperties(extraProps) .AddSource("Code.cs", code) - .BuildAsync(); + .BuildAsync().ConfigureAwait(false); } /// @@ -352,6 +352,6 @@ protected override async Task BuildExe( .WithOutputType(Val.Exe) .WithProperties(extraProps) .AddSource("Program.cs", code) - .BuildAsync(); + .BuildAsync().ConfigureAwait(false); } } \ No newline at end of file diff --git a/src/ANcpLua.Roslyn.Utilities.Testing/MSBuild/ProjectBuilder.cs b/src/ANcpLua.Roslyn.Utilities.Testing/MSBuild/ProjectBuilder.cs index 4b4e33a..13277a1 100644 --- a/src/ANcpLua.Roslyn.Utilities.Testing/MSBuild/ProjectBuilder.cs +++ b/src/ANcpLua.Roslyn.Utilities.Testing/MSBuild/ProjectBuilder.cs @@ -240,7 +240,7 @@ public ProjectBuilder(ITestOutputHelper? testOutputHelper = null) /// public virtual async ValueTask DisposeAsync() { - await Directory.DisposeAsync(); + await Directory.DisposeAsync().ConfigureAwait(false); GC.SuppressFinalize(this); } @@ -1055,14 +1055,14 @@ public virtual async Task ExecuteDotnetCommandAsync(string command, foreach (var file in System.IO.Directory.GetFiles(Directory.FullPath, "*", SearchOption.AllDirectories)) { TestOutputHelper.WriteLine("File: " + file); - var content = await File.ReadAllTextAsync(file); + var content = await File.ReadAllTextAsync(file).ConfigureAwait(false); TestOutputHelper.WriteLine(content); } TestOutputHelper.WriteLine("-------- dotnet " + command); } - var psi = new ProcessStartInfo(await DotNetSdkHelpers.Get(SdkVersion)) + var psi = new ProcessStartInfo(await DotNetSdkHelpers.Get(SdkVersion).ConfigureAwait(false)) { WorkingDirectory = Directory.FullPath, RedirectStandardOutput = true, @@ -1096,13 +1096,13 @@ public virtual async Task ExecuteDotnetCommandAsync(string command, TestOutputHelper?.WriteLine("Executing: " + psi.FileName + " " + string.Join(' ', psi.ArgumentList)); - var result = await psi.RunAsTaskAsync(); + var result = await psi.RunAsTaskAsync().ConfigureAwait(false); TestOutputHelper?.WriteLine("Process exit code: " + result.ExitCode); TestOutputHelper?.WriteLine(result.Output.ToString()); - var sarif = await LoadSarifAsync(Directory.FullPath); - var binlogContent = await File.ReadAllBytesAsync(Directory.FullPath / "msbuild.binlog"); + var sarif = await LoadSarifAsync(Directory.FullPath).ConfigureAwait(false); + var binlogContent = await File.ReadAllBytesAsync(Directory.FullPath / "msbuild.binlog").ConfigureAwait(false); var recordedProperties = LoadRecordedProperties(Directory.FullPath); return new BuildResult(result.ExitCode, result.Output, sarif, binlogContent) @@ -1143,14 +1143,14 @@ public virtual async Task ExecuteDotnetCommandAsync(string command, if (sarifFiles.Count == 1) { - var bytes = await File.ReadAllBytesAsync(sarifFiles[0]); + var bytes = await File.ReadAllBytesAsync(sarifFiles[0]).ConfigureAwait(false); return JsonSerializer.Deserialize(bytes); } var allRuns = new List(); foreach (var path in sarifFiles) { - var bytes = await File.ReadAllBytesAsync(path); + var bytes = await File.ReadAllBytesAsync(path).ConfigureAwait(false); var sarif = JsonSerializer.Deserialize(bytes); if (sarif?.Runs is not null) allRuns.AddRange(sarif.Runs); diff --git a/src/ANcpLua.Roslyn.Utilities.Testing/SolutionRefactoringTest.cs b/src/ANcpLua.Roslyn.Utilities.Testing/SolutionRefactoringTest.cs index 771f02f..ee2b3da 100644 --- a/src/ANcpLua.Roslyn.Utilities.Testing/SolutionRefactoringTest.cs +++ b/src/ANcpLua.Roslyn.Utilities.Testing/SolutionRefactoringTest.cs @@ -101,21 +101,21 @@ protected async Task VerifyMultiDocumentAsync( { var solution = CreateSolution(documents); var triggerDoc = solution.Projects.First().Documents.First(d => d.Name == triggerFile); - var triggerDocText = await triggerDoc.GetTextAsync(cancellationToken); + var triggerDocText = await triggerDoc.GetTextAsync(cancellationToken).ConfigureAwait(false); var span = GetSpan(triggerDocText, triggerText); - var actions = await GetRefactoringsAsync(triggerDoc, span, cancellationToken); + var actions = await GetRefactoringsAsync(triggerDoc, span, cancellationToken).ConfigureAwait(false); var matchingAction = actions.FirstOrDefault(a => a.Title == refactoringTitle) ?? throw new InvalidOperationException( $"Expected refactoring '{refactoringTitle}' not found. Available: {string.Join(", ", actions.Select(a => $"'{a.Title}'"))}"); - var changedSolution = await ApplySolutionCodeActionAsync(matchingAction, cancellationToken); + var changedSolution = await ApplySolutionCodeActionAsync(matchingAction, cancellationToken).ConfigureAwait(false); foreach (var (fileName, expectedContent) in expected) { var changedDoc = changedSolution.Projects.First().Documents.First(d => d.Name == fileName); - var changedText = await changedDoc.GetTextAsync(cancellationToken); + var changedText = await changedDoc.GetTextAsync(cancellationToken).ConfigureAwait(false); var actual = changedText.ToString(); var normalizedExpected = expectedContent.ReplaceLineEndings(); @@ -161,16 +161,16 @@ protected async Task VerifyMultiProjectAsync( var solution = CreateMultiProjectSolution(projects); var triggerProj = solution.Projects.First(p => p.Name == triggerProject); var triggerDoc = triggerProj.Documents.First(d => d.Name == triggerFile); - var triggerDocText = await triggerDoc.GetTextAsync(cancellationToken); + var triggerDocText = await triggerDoc.GetTextAsync(cancellationToken).ConfigureAwait(false); var span = GetSpan(triggerDocText, triggerText); - var actions = await GetRefactoringsAsync(triggerDoc, span, cancellationToken); + var actions = await GetRefactoringsAsync(triggerDoc, span, cancellationToken).ConfigureAwait(false); var matchingAction = actions.FirstOrDefault(a => a.Title == refactoringTitle) ?? throw new InvalidOperationException( $"Expected refactoring '{refactoringTitle}' not found. Available: {string.Join(", ", actions.Select(a => $"'{a.Title}'"))}"); - var changedSolution = await ApplySolutionCodeActionAsync(matchingAction, cancellationToken); + var changedSolution = await ApplySolutionCodeActionAsync(matchingAction, cancellationToken).ConfigureAwait(false); foreach (var (projectName, expectedDocs) in expected) { @@ -178,7 +178,7 @@ protected async Task VerifyMultiProjectAsync( foreach (var (fileName, expectedContent) in expectedDocs) { var changedDoc = changedProj.Documents.First(d => d.Name == fileName); - var changedText = await changedDoc.GetTextAsync(cancellationToken); + var changedText = await changedDoc.GetTextAsync(cancellationToken).ConfigureAwait(false); var actual = changedText.ToString(); var normalizedExpected = expectedContent.ReplaceLineEndings(); @@ -200,10 +200,10 @@ protected async Task> GetRefactoringsForDocumentAsync { var solution = CreateSolution(documents); var triggerDoc = solution.Projects.First().Documents.First(d => d.Name == triggerFile); - var triggerDocText = await triggerDoc.GetTextAsync(cancellationToken); + var triggerDocText = await triggerDoc.GetTextAsync(cancellationToken).ConfigureAwait(false); var span = GetSpan(triggerDocText, triggerText); - return await GetRefactoringsAsync(triggerDoc, span, cancellationToken); + return await GetRefactoringsAsync(triggerDoc, span, cancellationToken).ConfigureAwait(false); } /// @@ -215,7 +215,7 @@ protected async Task VerifyNoRefactoringAsync( string triggerText, CancellationToken cancellationToken = default) { - var actions = await GetRefactoringsForDocumentAsync(documents, triggerFile, triggerText, cancellationToken); + var actions = await GetRefactoringsForDocumentAsync(documents, triggerFile, triggerText, cancellationToken).ConfigureAwait(false); if (actions.Length > 0) throw new InvalidOperationException( @@ -285,7 +285,7 @@ private static async Task> GetRefactoringsAsync( actions.Add, cancellationToken); - await provider.ComputeRefactoringsAsync(context); + await provider.ComputeRefactoringsAsync(context).ConfigureAwait(false); return [.. actions]; } @@ -294,7 +294,7 @@ private static async Task ApplySolutionCodeActionAsync( CodeAction action, CancellationToken cancellationToken) { - var operations = await action.GetOperationsAsync(cancellationToken); + var operations = await action.GetOperationsAsync(cancellationToken).ConfigureAwait(false); var applyChanges = operations.OfType().First(); return applyChanges.ChangedSolution; } diff --git a/src/ANcpLua.Roslyn.Utilities.Testing/Test.cs b/src/ANcpLua.Roslyn.Utilities.Testing/Test.cs index 6803b14..95c937e 100644 --- a/src/ANcpLua.Roslyn.Utilities.Testing/Test.cs +++ b/src/ANcpLua.Roslyn.Utilities.Testing/Test.cs @@ -21,7 +21,7 @@ internal static async Task Run( { var engine = new GeneratorTestEngine(); configure(engine); - var (firstRun, secondRun) = await engine.RunTwiceAsync(cancellationToken); + var (firstRun, secondRun) = await engine.RunTwiceAsync(cancellationToken).ConfigureAwait(false); return new GeneratorResult(firstRun, secondRun, null, primaryGeneratorType ?? typeof(GeneratorTestEngine)); } } @@ -35,7 +35,7 @@ internal static async Task Run( public static async Task Run(string source, CancellationToken cancellationToken = default) { var engine = new GeneratorTestEngine().WithSource(source); - var (firstRun, secondRun) = await engine.RunTwiceAsync(cancellationToken); + var (firstRun, secondRun) = await engine.RunTwiceAsync(cancellationToken).ConfigureAwait(false); return new GeneratorResult(firstRun, secondRun, source, typeof(TGenerator)); } @@ -45,7 +45,7 @@ internal static async Task Run( { var engine = new GeneratorTestEngine(); configure(engine); - var (firstRun, secondRun) = await engine.RunTwiceAsync(cancellationToken); + var (firstRun, secondRun) = await engine.RunTwiceAsync(cancellationToken).ConfigureAwait(false); return new GeneratorResult(firstRun, secondRun, null, typeof(TGenerator)); } } \ No newline at end of file diff --git a/src/ANcpLua.Roslyn.Utilities.Testing/WebTesting/KestrelTestBase.cs b/src/ANcpLua.Roslyn.Utilities.Testing/WebTesting/KestrelTestBase.cs index 44089da..e489866 100644 --- a/src/ANcpLua.Roslyn.Utilities.Testing/WebTesting/KestrelTestBase.cs +++ b/src/ANcpLua.Roslyn.Utilities.Testing/WebTesting/KestrelTestBase.cs @@ -55,7 +55,7 @@ public virtual ValueTask InitializeAsync() public virtual async ValueTask DisposeAsync() { _client?.Dispose(); - await _baseFactory.DisposeAsync(); + await _baseFactory.DisposeAsync().ConfigureAwait(false); GC.SuppressFinalize(this); } diff --git a/src/ANcpLua.Roslyn.Utilities.Testing/WebTesting/NUnit/IntegrationTestBase.cs b/src/ANcpLua.Roslyn.Utilities.Testing/WebTesting/NUnit/IntegrationTestBase.cs index ecabd11..873a279 100644 --- a/src/ANcpLua.Roslyn.Utilities.Testing/WebTesting/NUnit/IntegrationTestBase.cs +++ b/src/ANcpLua.Roslyn.Utilities.Testing/WebTesting/NUnit/IntegrationTestBase.cs @@ -53,7 +53,7 @@ public virtual void TearDown() [OneTimeTearDown] public virtual async Task OneTimeTearDownAsync() { - await Factory.DisposeAsync(); + await Factory.DisposeAsync().ConfigureAwait(false); } /// diff --git a/src/ANcpLua.Roslyn.Utilities.Testing/WebTesting/NUnit/KestrelTestBase.cs b/src/ANcpLua.Roslyn.Utilities.Testing/WebTesting/NUnit/KestrelTestBase.cs index 350cd13..5701625 100644 --- a/src/ANcpLua.Roslyn.Utilities.Testing/WebTesting/NUnit/KestrelTestBase.cs +++ b/src/ANcpLua.Roslyn.Utilities.Testing/WebTesting/NUnit/KestrelTestBase.cs @@ -50,7 +50,7 @@ public virtual void SetUp() public virtual async Task TearDownAsync() { _client?.Dispose(); - if (_factory != null) await _factory.DisposeAsync(); + if (_factory != null) await _factory.DisposeAsync().ConfigureAwait(false); } /// diff --git a/src/ANcpLua.Roslyn.Utilities.Testing/WebTesting/TUnit/IntegrationTestBase.cs b/src/ANcpLua.Roslyn.Utilities.Testing/WebTesting/TUnit/IntegrationTestBase.cs index 764ba18..452b97d 100644 --- a/src/ANcpLua.Roslyn.Utilities.Testing/WebTesting/TUnit/IntegrationTestBase.cs +++ b/src/ANcpLua.Roslyn.Utilities.Testing/WebTesting/TUnit/IntegrationTestBase.cs @@ -45,7 +45,7 @@ public virtual Task SetUp() public virtual async Task TearDown() { Client.Dispose(); - if (_factory != null) await _factory.DisposeAsync(); + if (_factory != null) await _factory.DisposeAsync().ConfigureAwait(false); } /// diff --git a/src/ANcpLua.Roslyn.Utilities.Testing/WebTesting/TUnit/KestrelTestBase.cs b/src/ANcpLua.Roslyn.Utilities.Testing/WebTesting/TUnit/KestrelTestBase.cs index 135957c..1208343 100644 --- a/src/ANcpLua.Roslyn.Utilities.Testing/WebTesting/TUnit/KestrelTestBase.cs +++ b/src/ANcpLua.Roslyn.Utilities.Testing/WebTesting/TUnit/KestrelTestBase.cs @@ -51,7 +51,7 @@ public virtual Task SetUp() public virtual async Task TearDown() { _client?.Dispose(); - if (_factory != null) await _factory.DisposeAsync(); + if (_factory != null) await _factory.DisposeAsync().ConfigureAwait(false); } /// diff --git a/src/ANcpLua.Roslyn.Utilities/Text/EnvConfig.cs b/src/ANcpLua.Roslyn.Utilities/Text/EnvConfig.cs index 7a43f62..4c32ad9 100644 --- a/src/ANcpLua.Roslyn.Utilities/Text/EnvConfig.cs +++ b/src/ANcpLua.Roslyn.Utilities/Text/EnvConfig.cs @@ -1,6 +1,7 @@ // Runtime-only. Excluded from the source-only Sources package (where ANCPLUA_ROSLYN_PUBLIC isn't defined) // because Roslyn analyzers are forbidden to read Environment by RS1035 ("Analyzers should not read their settings // directly from environment variables"). Generators that need config must go through analyzer config/MSBuildWorkspace. + #if ANCPLUA_ROSLYN_PUBLIC namespace ANcpLua.Roslyn.Utilities.Text; @@ -16,11 +17,11 @@ namespace ANcpLua.Roslyn.Utilities.Text; public static class EnvConfig { /// Trimmed string value of , or when unset/whitespace. - public static string? ReadString(string name, string? defaultValue = null) + private static string? ReadString(string name, string? defaultValue = null) { if (name is null) throw new ArgumentNullException(nameof(name)); var raw = Environment.GetEnvironmentVariable(name); - return string.IsNullOrWhiteSpace(raw) ? defaultValue : raw!.Trim(); + return string.IsNullOrWhiteSpace(raw) ? defaultValue : raw.Trim(); } /// @@ -30,10 +31,9 @@ public static class EnvConfig public static int ReadInt(string name, int defaultValue, int? min = null, int? max = null) { var raw = ReadString(name); - if (raw is null || !int.TryParse(raw, NumberStyles.Integer, CultureInfo.InvariantCulture, out var parsed)) + if (raw is null || !int.TryParse(raw, NumberStyles.Integer, CultureInfo.InvariantCulture, out var parsed) || + min is { } lo && parsed < lo || max is { } hi && parsed > hi) return defaultValue; - if (min is int lo && parsed < lo) return defaultValue; - if (max is int hi && parsed > hi) return defaultValue; return parsed; } @@ -79,4 +79,4 @@ public static TEnum ReadEnum(string name, TEnum defaultValue) where TEnum return raw is not null && Uri.TryCreate(raw, UriKind.Absolute, out var parsed) ? parsed : defaultValue; } } -#endif +#endif \ No newline at end of file