Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
YegorStepanov committed Sep 24, 2022
1 parent 145d11b commit ce1b1cd
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions tests/BenchmarkDotNet.Tests/Validators/ExecutionValidatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -298,12 +298,8 @@ public void NonThrowing() { }
[Fact]
public void NonPublicFieldsWithParamsAreDiscovered()
{
var validationErrors = ExecutionValidator.FailOnError
.Validate(BenchmarkConverter.TypeToBenchmarks(typeof(NonPublicFieldWithParams)))
.ToList();

Assert.NotEmpty(validationErrors);
Assert.StartsWith($"Member \"{nameof(NonPublicFieldWithParams.Field)}\" must be public if it has the [Params]", validationErrors.Single().Message);
Assert.Throws<InvalidOperationException>(
() => ExecutionValidator.FailOnError.Validate(BenchmarkConverter.TypeToBenchmarks(typeof(NonPublicFieldWithParams))));
}

public class NonPublicFieldWithParams
Expand All @@ -318,6 +314,29 @@ public class NonPublicFieldWithParams
public void NonThrowing() { }
}

[Fact]
public void NonPublicFieldsWithParamsSourceAreDiscovered()
{
Assert.Throws<InvalidOperationException>(
() => ExecutionValidator.FailOnError.Validate(BenchmarkConverter.TypeToBenchmarks(typeof(NonPublicFieldWithParamsSource))));
}

public class NonPublicFieldWithParamsSource
{
#pragma warning disable CS0649
[ParamsSource(nameof(Get))]
internal int Field;
#pragma warning restore CS0649

[Benchmark]
public void NonThrowing() { }

public IEnumerable<object> Get()
{
yield return 0;
}
}

[Fact]
public void NonPublicPropertiesWithParamsAreDiscovered()
{
Expand Down

0 comments on commit ce1b1cd

Please sign in to comment.