Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rule out test assemblies from versioning test sets #487

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions Test_Engine/Query/IsTestToolkit.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2024, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
*
*
* The BHoM is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3.0 of the License, or
* (at your option) any later version.
*
* The BHoM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
*/

using BH.oM.Base;
using BH.oM.Base.Attributes;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;

namespace BH.Engine.Test
{
public static partial class Query
{
/***************************************************/
/**** Public Methods ****/
/***************************************************/

[Description("Checks if a type is defined in an assembly that is part of Test_Toolkit.")]
[Input("type", "Type to check.")]
[Output("isTestToolkit", "Returns true if the type is defined inside Test_Toolkit.")]
public static bool IsTestToolkit(this Type type)
{
if (type == null)
return false;

string assemblyName = type.Assembly?.GetName()?.Name;

return m_testToolkitAssemblyNames.Contains(assemblyName);
}

/***************************************************/

[Description("Checks if a method is defined in an assembly that is part of Test_Toolkit.")]
[Input("method", "Method to check.")]
[Output("isTestToolkit", "Returns true if the method is defined inside Test_Toolkit.")]
public static bool IsTestToolkit(this MethodBase method)
{
if (method == null)
return false;

return method.DeclaringType.IsTestToolkit();
}

/***************************************************/
/**** Private Fields ****/
/***************************************************/

private static HashSet<string> m_testToolkitAssemblyNames = new HashSet<string> { "CodeComplianceTest_Engine", "CodeComplianceTest_oM", "InteroperabilityTest_Engine", "InteroperabilityTest_oM", "NUnit_Engine", "NUnit_oM", "Test_Engine", "TestRunner", "UnitTest_Engine", "UnitTest_oM" };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would consider splitting the collection with line breaks for readability


/***************************************************/
}
}
2 changes: 1 addition & 1 deletion Test_Engine/Query/VersioningAdapterConstructorList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static Output<List<ConstructorInfo>, List<ConstructorInfo>> VersioningAda

foreach (var ctor in bhomAdapterConstructors)
{
if(ctor.IsNotImplemented() || ctor.IsDeprecated())
if(ctor.IsNotImplemented() || ctor.IsDeprecated() || ctor.IsTestToolkit())
ignored.Add(ctor);
else
included.Add(ctor);
Expand Down
11 changes: 9 additions & 2 deletions Test_Engine/Query/VersioningMethodList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,17 @@ public static Output<List<MethodInfo>, List<MethodInfo>> VersioningMethodList(bo

List<MethodInfo> bhomMethodList = BH.Engine.Base.Query.BHoMMethodList();

List<MethodInfo> included = bhomMethodList;
List<MethodInfo> included = new List<MethodInfo>();
List<MethodInfo> ignored = new List<MethodInfo>();

//Note, keeping both collections here for now to allow for future filtering without requirement of changing scripts.
foreach (MethodInfo method in bhomMethodList)
{
if(!method.IsTestToolkit())
included.Add(method);
else
ignored.Add(method);
}

return new Output<List<MethodInfo>, List<MethodInfo>> { Item1 = included, Item2 = ignored };
}

Expand Down
2 changes: 1 addition & 1 deletion Test_Engine/Query/VersioningTypeList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static Output<List<Type>, List<Type>> VersioningTypeList(bool includeRevi

foreach (Type type in bhomTypeList)
{
if (typeof(IObject).IsAssignableFrom(type) && !type.IsAbstract && !type.IsDeprecated())
if (!type.IsTestToolkit() && typeof(IObject).IsAssignableFrom(type) && !type.IsAbstract && !type.IsDeprecated())
{
includeTypeList.Add(type);
}
Expand Down
1 change: 1 addition & 0 deletions Test_Engine/Test_Engine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Query\FullMessage.cs" />
<Compile Include="Query\IsEqualOrMoreSevere.cs" />
<Compile Include="Query\IsTestToolkit.cs" />
<Compile Include="Query\MostSevereStatus.cs" />
<Compile Include="Query\TestInformationOfType.cs" />
<Compile Include="Query\VersioningAdapterConstructorList.cs" />
Expand Down