Skip to content

Commit

Permalink
Added filter for internal attributes #474
Browse files Browse the repository at this point in the history
  • Loading branch information
OsirisTerje committed Jan 17, 2019
1 parent 1feeed6 commit ace70c7
Show file tree
Hide file tree
Showing 4 changed files with 537 additions and 511 deletions.
2 changes: 1 addition & 1 deletion build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var configuration = Argument("configuration", "Release");
// SET PACKAGE VERSION
//////////////////////////////////////////////////////////////////////

var version = "3.12.0";
var version = "3.13.0";
var modifier = "";

var dbgSuffix = configuration == "Debug" ? "-dbg" : "";
Expand Down
6 changes: 5 additions & 1 deletion src/NUnitTestAdapter/AdapterSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ public interface IAdapterSettings
/// </summary>
bool DisableParallelization { get; }

bool ShowInternalProperties { get; }

void Load(IDiscoveryContext context);
void Load(string settingsXml);
void SaveRandomSeed(string dirname);
Expand Down Expand Up @@ -180,6 +182,8 @@ public AdapterSettings(TestLogger logger)

public string DomainUsage { get; private set; }

public bool ShowInternalProperties { get; private set; }


public VsTestCategoryType VsTestCategoryType { get; private set; } = VsTestCategoryType.NUnit;

Expand Down Expand Up @@ -258,7 +262,7 @@ public void Load(string settingsXml)
if (!RandomSeedSpecified)
RandomSeed = new Random().Next();
DefaultTestNamePattern = GetInnerTextWithLog(nunitNode, nameof(DefaultTestNamePattern));

ShowInternalProperties = GetInnerTextAsBool(nunitNode, nameof(ShowInternalProperties), false);
DumpXmlTestDiscovery = GetInnerTextAsBool(nunitNode, nameof(DumpXmlTestDiscovery), false);
DumpXmlTestResults = GetInnerTextAsBool(nunitNode, nameof(DumpXmlTestResults), false);
var vsTestCategoryType = GetInnerText(nunitNode, nameof(VsTestCategoryType), Verbosity > 0);
Expand Down
38 changes: 30 additions & 8 deletions src/NUnitTestAdapter/CategoryList.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
Expand All @@ -11,19 +12,27 @@ public class CategoryList
private const string NunitTestCategoryLabel = "Category";
private const string VsTestCategoryLabel = "TestCategory";
private const string MSTestCategoryName = "MSTestDiscoverer.TestCategory";
internal static readonly TestProperty NUnitTestCategoryProperty = TestProperty.Register(NUnitCategoryName, VsTestCategoryLabel, typeof(string[]), TestPropertyAttributes.Hidden | TestPropertyAttributes.Trait, typeof(TestCase));
internal TestProperty MsTestCategoryProperty; // = TestProperty.Register(MSTestCategoryName, VsTestCategoryLabel, typeof(string[]), TestPropertyAttributes.Hidden | TestPropertyAttributes.Trait, typeof(TestCase));
internal static readonly TestProperty NUnitExplicitProperty = TestProperty.Register("NUnit.Explicit", "Explicit", typeof(bool), TestPropertyAttributes.Hidden, typeof(TestCase));

internal static readonly TestProperty NUnitTestCategoryProperty = TestProperty.Register(NUnitCategoryName,
VsTestCategoryLabel, typeof(string[]), TestPropertyAttributes.Hidden | TestPropertyAttributes.Trait,
typeof(TestCase));

internal TestProperty
MsTestCategoryProperty; // = TestProperty.Register(MSTestCategoryName, VsTestCategoryLabel, typeof(string[]), TestPropertyAttributes.Hidden | TestPropertyAttributes.Trait, typeof(TestCase));

internal static readonly TestProperty NUnitExplicitProperty = TestProperty.Register("NUnit.Explicit",
"Explicit", typeof(bool), TestPropertyAttributes.Hidden, typeof(TestCase));

private const string ExplicitTraitName = "Explicit";

// The empty string causes the UI we want.
// If it's null, the explicit trait doesn't show up in Test Explorer.
// If it's not empty, it shows up as “Explicit [value]” in Test Explorer.
private const string ExplicitTraitValue = "";

private readonly List<string> categorylist = new List<string>();
private readonly TestCase testCase;
private IAdapterSettings settings;
private readonly IAdapterSettings settings;

public CategoryList(TestCase testCase, IAdapterSettings adapterSettings)
{
Expand All @@ -39,7 +48,9 @@ public void AddRange(IEnumerable<string> categories)
}

public int LastNodeListCount { get; private set; }
public IEnumerable<string> ProcessTestCaseProperties(XmlNode testNode, bool addToCache, string key = null, IDictionary<string, TraitsFeature.CachedTestCaseInfo> traitsCache = null)

public IEnumerable<string> ProcessTestCaseProperties(XmlNode testNode, bool addToCache, string key = null,
IDictionary<string, TraitsFeature.CachedTestCaseInfo> traitsCache = null)
{
var nodelist = testNode.SelectNodes("properties/property");
LastNodeListCount = nodelist.Count;
Expand Down Expand Up @@ -82,7 +93,15 @@ public IEnumerable<string> ProcessTestCaseProperties(XmlNode testNode, bool addT
return categorylist;
}

private static bool IsInternalProperty(string propertyName, string propertyValue)
/// <summary>
/// List based on https://github.com/nunit/docs/wiki/Attributes
/// </summary>
private readonly List<string> internalProperties = new List<string>
{ "Timeout", "Repeat", "Apartment", "Author", "Combinatorial", "Culture", "Datapoint",
"DatapointSource", "DefaultFloatingPointTolerance", "Description", "LevelOfParallelism",
"MaxTime", "NonParallelizable", "Order", "Pairwise", "Platform", "Random", "Range",
"RequiresThread", "Retry", "Sequential", "SetCulture", "SetUICulture", "SingleThreaded", "Values", "ValueSource" };
private bool IsInternalProperty(string propertyName, string propertyValue)
{
if (propertyName == ExplicitTraitName)
{
Expand All @@ -92,10 +111,13 @@ private static bool IsInternalProperty(string propertyName, string propertyValue
}

// Property names starting with '_' are for internal use only
if (!settings.ShowInternalProperties &&
internalProperties.Contains(propertyName, StringComparer.OrdinalIgnoreCase))
return true;
return string.IsNullOrEmpty(propertyName) || propertyName[0] == '_' || string.IsNullOrEmpty(propertyValue);
}

private static void AddTraitsToCache(IDictionary<string, TraitsFeature.CachedTestCaseInfo> traitsCache, string key, string propertyName, string propertyValue)
private void AddTraitsToCache(IDictionary<string, TraitsFeature.CachedTestCaseInfo> traitsCache, string key, string propertyName, string propertyValue)
{
if (IsInternalProperty(propertyName, propertyValue)) return;

Expand Down
Loading

0 comments on commit ace70c7

Please sign in to comment.