Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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