-
Notifications
You must be signed in to change notification settings - Fork 773
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f5e6069
commit 2026e86
Showing
4 changed files
with
39 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
test/OpenTelemetry.Tests/Shared/SkipUnlessTrueTheoryAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
using System.Reflection; | ||
using OpenTelemetry.Internal; | ||
using Xunit; | ||
|
||
namespace OpenTelemetry.Tests; | ||
|
||
internal sealed class SkipUnlessTrueTheoryAttribute : TheoryAttribute | ||
{ | ||
public SkipUnlessTrueTheoryAttribute(Type typeContainingTest, string testFieldName, string skipMessage) | ||
{ | ||
Guard.ThrowIfNull(typeContainingTest); | ||
Guard.ThrowIfNullOrEmpty(testFieldName); | ||
Guard.ThrowIfNullOrEmpty(skipMessage); | ||
|
||
var field = typeContainingTest.GetField(testFieldName, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic) | ||
?? throw new InvalidOperationException($"Static field '{testFieldName}' could not be found on '{typeContainingTest}' type."); | ||
|
||
if (field.FieldType != typeof(Func<bool>)) | ||
{ | ||
throw new InvalidOperationException($"Field '{testFieldName}' on '{typeContainingTest}' type should be defined as '{typeof(Func<bool>)}'."); | ||
} | ||
|
||
var testFunc = (Func<bool>)field.GetValue(null); | ||
|
||
if (!testFunc()) | ||
{ | ||
this.Skip = skipMessage; | ||
} | ||
} | ||
} |