From 1290ad0d56792e05477db27b326174ba63bd663d Mon Sep 17 00:00:00 2001 From: smdn Date: Fri, 15 Dec 2023 22:01:47 +0900 Subject: [PATCH] avoid test failures due to build warnings from external tools --- .../Smdn/Runtime.cs | 36 +++++++++++-------- .../print-runtime-information.csproj | 2 ++ 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/tests/Smdn.Fundamental.RuntimeInformation/Smdn/Runtime.cs b/tests/Smdn.Fundamental.RuntimeInformation/Smdn/Runtime.cs index 6f0a2be6..6b3763dd 100644 --- a/tests/Smdn.Fundamental.RuntimeInformation/Smdn/Runtime.cs +++ b/tests/Smdn.Fundamental.RuntimeInformation/Smdn/Runtime.cs @@ -230,10 +230,11 @@ private void SupportsIanaTimeZoneName_Windows() private void SupportsIanaTimeZoneName_NonWindowsOS() => Assert.That(Runtime.SupportsIanaTimeZoneName, Is.True, "Mono or .NET on non-windows OS supports IANA time zone name"); - private static string ExecutePrintRuntimeInformation( + private static TResult ExecutePrintRuntimeInformation( string[] args, - string[] buildAdditionalProperties = null, - IReadOnlyDictionary environmentVariables = null + string[] buildAdditionalProperties, + IReadOnlyDictionary environmentVariables, + Func getResult ) { int exitCode; @@ -288,9 +289,14 @@ out stderr ); if (exitCode != 0) - throw new InvalidOperationException($"run failed: (stdout: {stdout}, stderr: {stderr})"); + throw new InvalidOperationException($"run failed: (stdout: '{stdout}', stderr: '{stderr}')"); - return stdout; + try { + return getResult(stdout); + } + catch (Exception ex) { + throw new InvalidOperationException($"could not get result: (stdout: '{stdout}', stderr: '{stderr}')", ex); + } } [Test] @@ -301,11 +307,11 @@ public void SupportsIanaTimeZoneName_UseNls_RuntimeConfiguration() return; } - var processSupportsIanaTimeZoneName = bool.Parse( - ExecutePrintRuntimeInformation( - args: new[] { nameof(Runtime.SupportsIanaTimeZoneName) }, - buildAdditionalProperties: new[] { "RuntimeConfigurationSystemGlobalizationUseNls=true" } - ).TrimEnd() + var processSupportsIanaTimeZoneName = ExecutePrintRuntimeInformation( + args: new[] { nameof(Runtime.SupportsIanaTimeZoneName) }, + buildAdditionalProperties: new[] { "RuntimeConfigurationSystemGlobalizationUseNls=true" }, + environmentVariables: null, + getResult: result => bool.Parse(result.TrimEnd()) ); Assert.That(processSupportsIanaTimeZoneName, Is.False); @@ -320,11 +326,11 @@ public void SupportsIanaTimeZoneName_UseNls_EnvironmentVariable(string value) return; } - var processSupportsIanaTimeZoneName = bool.Parse( - ExecutePrintRuntimeInformation( - args: new[] { nameof(Runtime.SupportsIanaTimeZoneName) }, - environmentVariables: new Dictionary() { ["DOTNET_SYSTEM_GLOBALIZATION_USENLS"] = value } - ).TrimEnd() + var processSupportsIanaTimeZoneName = ExecutePrintRuntimeInformation( + args: new[] { nameof(Runtime.SupportsIanaTimeZoneName) }, + buildAdditionalProperties: null, + environmentVariables: new Dictionary() { ["DOTNET_SYSTEM_GLOBALIZATION_USENLS"] = value }, + getResult: result => bool.Parse(result.TrimEnd()) ); Assert.That(processSupportsIanaTimeZoneName, Is.False); diff --git a/tests/Smdn.Fundamental.RuntimeInformation/print-runtime-information/print-runtime-information.csproj b/tests/Smdn.Fundamental.RuntimeInformation/print-runtime-information/print-runtime-information.csproj index 70e896ae..8d724de0 100644 --- a/tests/Smdn.Fundamental.RuntimeInformation/print-runtime-information/print-runtime-information.csproj +++ b/tests/Smdn.Fundamental.RuntimeInformation/print-runtime-information/print-runtime-information.csproj @@ -8,6 +8,8 @@ SPDX-License-Identifier: MIT net6.0;net48;net47;net462 disable disable + + false