Skip to content

Commit

Permalink
Fixed some tests. (#2475)
Browse files Browse the repository at this point in the history
  • Loading branch information
timcassell committed Dec 4, 2023
1 parent 5557aee commit b987b99
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
Expand Up @@ -3,10 +3,14 @@
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Extensions;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Portability;
using Xunit;

namespace BenchmarkDotNet.IntegrationTests
{
// Note: To properly test this locally, modify
// BenchmarkDotNet.IntegrationTests.ManualRunning.MultipleFrameworks.csproj,
// following the comments in that file.
public class MultipleFrameworksTest : BenchmarkTestExecutor
{
private const string TfmEnvVarName = "TfmEnvVarName";
Expand All @@ -15,9 +19,23 @@ public class MultipleFrameworksTest : BenchmarkTestExecutor
[InlineData(RuntimeMoniker.Net461)]
[InlineData(RuntimeMoniker.Net48)]
[InlineData(RuntimeMoniker.NetCoreApp20)]
[InlineData(RuntimeMoniker.Net70)]
[InlineData(RuntimeMoniker.Net80)]
public void EachFrameworkIsRebuilt(RuntimeMoniker runtime)
{
#if NET461
// We cannot detect what target framework version the host was compiled for on full Framework,
// which causes the RoslynToolchain to be used instead of CsProjClassicNetToolchain when the host is full Framework
// (because full Framework always uses the version that's installed on the machine, unlike Core),
// which means if the machine has net48 installed (not net481), the net461 host with net48 runtime moniker
// will not be recompiled, causing the test to fail.

// If we ever change the default toolchain to CsProjClassicNetToolchain instead of RoslynToolchain, we can remove this check.
if (runtime == RuntimeMoniker.Net48)
{
// XUnit doesn't provide Assert.Skip API yet.
return;
}
#endif
var config = ManualConfig.CreateEmpty().AddJob(Job.Dry.WithRuntime(runtime.GetRuntime()).WithEnvironmentVariable(TfmEnvVarName, runtime.ToString()));
CanExecute<ValuePerTfm>(config);
}
Expand All @@ -31,8 +49,8 @@ public class ValuePerTfm
RuntimeMoniker.Net48;
#elif NETCOREAPP2_0
RuntimeMoniker.NetCoreApp20;
#elif NET7_0
RuntimeMoniker.Net70;
#elif NET8_0
RuntimeMoniker.Net80;
#else
RuntimeMoniker.NotRecognized;
#endif
Expand Down
2 changes: 1 addition & 1 deletion tests/BenchmarkDotNet.Tests/ConfigParserTests.cs
Expand Up @@ -162,7 +162,7 @@ public void SpecifyingCoreRunWithFullFrameworkTargetsMostRecentTfm()

CoreRunToolchain coreRunToolchain = (CoreRunToolchain)coreRunJob.GetToolchain();
DotNetCliGenerator generator = (DotNetCliGenerator)coreRunToolchain.Generator;
Assert.Equal("net8.0", generator.TargetFrameworkMoniker);
Assert.Equal("net9.0", generator.TargetFrameworkMoniker);
}

[FactEnvSpecific("It's impossible to determine TFM for CoreRunToolchain if host process is not .NET (Core) process", EnvRequirement.DotNetCoreOnly)]
Expand Down

0 comments on commit b987b99

Please sign in to comment.