-
-
Notifications
You must be signed in to change notification settings - Fork 986
/
Copy pathEnvironmentVariablesTests.cs
72 lines (61 loc) · 2.32 KB
/
EnvironmentVariablesTests.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using System;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Jobs;
using Xunit;
using Xunit.Abstractions;
namespace BenchmarkDotNet.IntegrationTests
{
public class EnvironmentVariablesTests : BenchmarkTestExecutor
{
internal const string Key = "VeryNiceKey";
internal const string Value = "VeryNiceValue";
public EnvironmentVariablesTests(ITestOutputHelper output) : base(output)
{
}
[Fact]
public void UserCanSpecifyEnvironmentVariables()
{
var variables = new[] { new EnvironmentVariable(Key, Value) };
var jobWithCustomConfiguration = Job.Dry.WithEnvironmentVariables(variables);
var config = CreateSimpleConfig(job: jobWithCustomConfiguration);
CanExecute<WithEnvironmentVariables>(config);
}
public class WithEnvironmentVariables
{
[Benchmark]
public void Benchmark()
{
if (Environment.GetEnvironmentVariable(Key) != Value)
throw new InvalidOperationException("The env var was not set");
}
}
[Fact]
public void ResharperDynamicProgramAnalysisIsDisabledByDefault()
=> CanExecute<TestingDpaDisabled>(CreateSimpleConfig(job: Job.Dry));
public class TestingDpaDisabled
{
[Benchmark]
public void Benchmark()
{
if (Environment.GetEnvironmentVariable("JETBRAINS_DPA_AGENT_ENABLE") != "0")
throw new InvalidOperationException("The JETBRAINS_DPA_AGENT_ENABLE env var was not set to zero");
}
}
[Fact]
public void ResharperDynamicProgramAnalysisCanBeEnabled()
{
var jobWithSettingEnabled = Job.Dry.WithEnvironmentVariable("JETBRAINS_DPA_AGENT_ENABLE", "1");
var config = CreateSimpleConfig(job: jobWithSettingEnabled);
CanExecute<TestingDpaEnabled>(config);
}
public class TestingDpaEnabled
{
[Benchmark]
public void Benchmark()
{
if (Environment.GetEnvironmentVariable("JETBRAINS_DPA_AGENT_ENABLE") != "1")
throw new InvalidOperationException("The JETBRAINS_DPA_AGENT_ENABLE env var was not set to one");
}
}
}
}