filter tests

This commit is contained in:
MilenaHristova 2023-03-03 10:59:00 +01:00
parent e944fdc2de
commit 55430a2b54
3 changed files with 11 additions and 32 deletions

View file

@ -3,8 +3,6 @@
// See the LICENSE file in the project root for more information.
using System;
using System.Linq;
using System.Runtime.CompilerServices;
using Xunit;
namespace Microsoft.DotNet.SourceBuild.SmokeTests;
@ -14,29 +12,14 @@ namespace Microsoft.DotNet.SourceBuild.SmokeTests;
/// </summary>
internal class SkippableFactAttribute : FactAttribute
{
public SkippableFactAttribute([CallerMemberName] string name = "") =>
CheckIncluded(name, (skip) => Skip = skip);
public SkippableFactAttribute(string envName, bool skipOnNullOrWhiteSpace = false, bool skipOnTrue = false) =>
CheckEnvs(skipOnNullOrWhiteSpace, skipOnTrue, (skip) => Skip = skip, envName);
public SkippableFactAttribute(string envName, bool skipOnNullOrWhiteSpace = false, bool skipOnTrue = false, [CallerMemberName] string testName = "") =>
CheckEnvs(skipOnNullOrWhiteSpace, skipOnTrue, (skip) => Skip = skip, testName, envName);
public SkippableFactAttribute(string[] envNames, bool skipOnNullOrWhiteSpace = false, bool skipOnTrue = false) =>
CheckEnvs(skipOnNullOrWhiteSpace, skipOnTrue, (skip) => Skip = skip, envNames);
public SkippableFactAttribute(string[] envNames, bool skipOnNullOrWhiteSpace = false, bool skipOnTrue = false, [CallerMemberName] string testName = "") =>
CheckEnvs(skipOnNullOrWhiteSpace, skipOnTrue, (skip) => Skip = skip, testName, envNames);
public static void CheckIncluded(string methodName, Action<string> setSkip)
public static void CheckEnvs(bool skipOnNullOrWhiteSpace, bool skipOnTrue, Action<string> setSkip, params string[] envNames)
{
var included = Config.IncludedTests;
if (included.Length != 0 && !included.Contains(methodName))
{
setSkip($"Skipping because `{methodName}` is not included");
return;
}
}
public static void CheckEnvs(bool skipOnNullOrWhiteSpace, bool skipOnTrue, Action<string> setSkip, string testName, params string[] envNames)
{
CheckIncluded(testName, setSkip);
foreach (string envName in envNames)
{
string? envValue = Environment.GetEnvironmentVariable(envName);

View file

@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Runtime.CompilerServices;
using Xunit;
namespace Microsoft.DotNet.SourceBuild.SmokeTests;
@ -12,12 +11,9 @@ namespace Microsoft.DotNet.SourceBuild.SmokeTests;
/// </summary>
internal class SkippableTheoryAttribute : TheoryAttribute
{
public SkippableTheoryAttribute([CallerMemberName] string testName = "") =>
SkippableFactAttribute.CheckIncluded(testName, (skip) => Skip = skip);
public SkippableTheoryAttribute(string envName, bool skipOnNullOrWhiteSpace = false, bool skipOnTrue = false) =>
SkippableFactAttribute.CheckEnvs(skipOnNullOrWhiteSpace, skipOnTrue, (skip) => Skip = skip, envName);
public SkippableTheoryAttribute(string envName, bool skipOnNullOrWhiteSpace = false, bool skipOnTrue = false, [CallerMemberName] string testName = "") =>
SkippableFactAttribute.CheckEnvs(skipOnNullOrWhiteSpace, skipOnTrue, (skip) => Skip = skip, testName, envName);
public SkippableTheoryAttribute(string[] envNames, bool skipOnNullOrWhiteSpace = false, bool skipOnTrue = false, [CallerMemberName] string testName = "") =>
SkippableFactAttribute.CheckEnvs(skipOnNullOrWhiteSpace, skipOnTrue, (skip) => Skip = skip, testName, envNames);
public SkippableTheoryAttribute(string[] envNames, bool skipOnNullOrWhiteSpace = false, bool skipOnTrue = false) =>
SkippableFactAttribute.CheckEnvs(skipOnNullOrWhiteSpace, skipOnTrue, (skip) => Skip = skip, envNames);
}