Skip to content

Commit

Permalink
avoid test failures due to build warnings from external tools
Browse files Browse the repository at this point in the history
  • Loading branch information
smdn committed Dec 15, 2023
1 parent bc099b1 commit 1290ad0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
36 changes: 21 additions & 15 deletions tests/Smdn.Fundamental.RuntimeInformation/Smdn/Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TResult>(
string[] args,
string[] buildAdditionalProperties = null,
IReadOnlyDictionary<string, string> environmentVariables = null
string[] buildAdditionalProperties,
IReadOnlyDictionary<string, string> environmentVariables,
Func<string, TResult> getResult
)
{
int exitCode;
Expand Down Expand Up @@ -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]
Expand All @@ -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);
Expand All @@ -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<string, string>() { ["DOTNET_SYSTEM_GLOBALIZATION_USENLS"] = value }
).TrimEnd()
var processSupportsIanaTimeZoneName = ExecutePrintRuntimeInformation(
args: new[] { nameof(Runtime.SupportsIanaTimeZoneName) },
buildAdditionalProperties: null,
environmentVariables: new Dictionary<string, string>() { ["DOTNET_SYSTEM_GLOBALIZATION_USENLS"] = value },
getResult: result => bool.Parse(result.TrimEnd())
);

Assert.That(processSupportsIanaTimeZoneName, Is.False);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ SPDX-License-Identifier: MIT
<TargetFrameworks>net6.0;net48;net47;net462</TargetFrameworks>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>disable</Nullable>
<!-- suppress warning: Set MSBuild property 'GenerateDocumentationFile' to 'true' in project file to enable IDE0005 (Remove unnecessary usings/imports) on build (https://github.com/dotnet/roslyn/issues/41640) -->
<EnforceCodeStyleInBuild>false</EnforceCodeStyleInBuild>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="$(MSBuildThisFileDirectory)..\..\..\src\Smdn.Fundamental.RuntimeInformation\Smdn.Fundamental.RuntimeInformation.csproj" />
Expand Down

0 comments on commit 1290ad0

Please sign in to comment.