-
-
Notifications
You must be signed in to change notification settings - Fork 990
/
Copy pathMultipleFrameworksTest.cs
51 lines (47 loc) · 1.6 KB
/
MultipleFrameworksTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Extensions;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Portability;
using Xunit;
namespace BenchmarkDotNet.IntegrationTests.ManualRunning
{
public class MultipleFrameworksTest : BenchmarkTestExecutor
{
private const string TfmEnvVarName = "TfmEnvVarName";
[Theory]
[InlineData(RuntimeMoniker.Net462)]
[InlineData(RuntimeMoniker.Net48)]
[InlineData(RuntimeMoniker.NetCoreApp31)]
[InlineData(RuntimeMoniker.Net80)]
public void EachFrameworkIsRebuilt(RuntimeMoniker runtime)
{
var config = ManualConfig.CreateEmpty().AddJob(Job.Dry.WithRuntime(runtime.GetRuntime()).WithEnvironmentVariable(TfmEnvVarName, runtime.ToString()));
CanExecute<ValuePerTfm>(config);
}
public class ValuePerTfm
{
private const RuntimeMoniker moniker =
#if NET462
RuntimeMoniker.Net462;
#elif NET48
RuntimeMoniker.Net48;
#elif NETCOREAPP3_1
RuntimeMoniker.NetCoreApp31;
#elif NET8_0
RuntimeMoniker.Net80;
#else
RuntimeMoniker.NotRecognized;
#endif
[Benchmark]
public void ThrowWhenWrong()
{
if (Environment.GetEnvironmentVariable(TfmEnvVarName) != moniker.ToString())
{
throw new InvalidOperationException($"Has not been recompiled, the value was {Environment.GetEnvironmentVariable(TfmEnvVarName)}");
}
}
}
}
}