Skip to content

Commit e269e7d

Browse files
Merge pull request #487 from BHoM/Test_Toolkit-#486-RuleOutTestAssembliesFromVersioningTestSets
Rule out test assemblies from versioning test sets
2 parents e06c818 + df77646 commit e269e7d

File tree

5 files changed

+130
-8
lines changed

5 files changed

+130
-8
lines changed

Test_Engine/Query/IsTestToolkit.cs

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* This file is part of the Buildings and Habitats object Model (BHoM)
3+
* Copyright (c) 2015 - 2024, the respective contributors. All rights reserved.
4+
*
5+
* Each contributor holds copyright over their respective contributions.
6+
* The project versioning (Git) records all such contribution source information.
7+
*
8+
*
9+
* The BHoM is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Lesser General Public License as published by
11+
* the Free Software Foundation, either version 3.0 of the License, or
12+
* (at your option) any later version.
13+
*
14+
* The BHoM is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public License
20+
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
21+
*/
22+
23+
using BH.oM.Base;
24+
using BH.oM.Base.Attributes;
25+
using System;
26+
using System.Collections.Generic;
27+
using System.ComponentModel;
28+
using System.Linq;
29+
using System.Reflection;
30+
31+
namespace BH.Engine.Test
32+
{
33+
public static partial class Query
34+
{
35+
/***************************************************/
36+
/**** Public Methods ****/
37+
/***************************************************/
38+
39+
[Description("Checks if a type is defined in an assembly that is part of Test_Toolkit.")]
40+
[Input("type", "Type to check.")]
41+
[Output("isTestToolkit", "Returns true if the type is defined inside Test_Toolkit.")]
42+
public static bool IsTestToolkit(this Type type)
43+
{
44+
if (type == null)
45+
return false;
46+
47+
string assemblyName = type.Assembly?.GetName()?.Name;
48+
49+
return m_testToolkitAssemblyNames.Contains(assemblyName);
50+
}
51+
52+
/***************************************************/
53+
54+
[Description("Checks if a method is defined in an assembly that is part of Test_Toolkit.")]
55+
[Input("method", "Method to check.")]
56+
[Output("isTestToolkit", "Returns true if the method is defined inside Test_Toolkit.")]
57+
public static bool IsTestToolkit(this MethodBase method)
58+
{
59+
if (method == null)
60+
return false;
61+
62+
return method.DeclaringType.IsTestToolkit();
63+
}
64+
65+
/***************************************************/
66+
/**** Private Fields ****/
67+
/***************************************************/
68+
69+
private static HashSet<string> m_testToolkitAssemblyNames = new HashSet<string>
70+
{
71+
"CodeComplianceTest_Engine",
72+
"CodeComplianceTest_oM",
73+
"InteroperabilityTest_Engine",
74+
"InteroperabilityTest_oM",
75+
"NUnit_Engine",
76+
"NUnit_oM",
77+
"Test_Engine",
78+
"TestRunner",
79+
"UnitTest_Engine",
80+
"UnitTest_oM"
81+
};
82+
83+
/***************************************************/
84+
}
85+
}

Test_Engine/Query/VersioningAdapterConstructorList.cs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@
2626
using System;
2727
using System.Collections.Generic;
2828
using System.ComponentModel;
29+
using System.IO;
2930
using System.Linq;
3031
using System.Reflection;
3132

33+
3234
namespace BH.Engine.Test
3335
{
3436
public static partial class Query
@@ -41,7 +43,7 @@ public static partial class Query
4143
[Input("includeRevit", "Toggle to control wheter assemblies depending on revit API dlls should be loaded or not.")]
4244
[MultiOutput(0, "included", "AdapterConstructors to be considered for adding to the Versioning TestSet.")]
4345
[MultiOutput(1, "ignored", "AdapterConstructors to _not_ be added to the Versioning TestSet.")]
44-
public static Output<List<ConstructorInfo>, List<ConstructorInfo>> VersioningAdapterConstructorList(bool includeRevit = true)
46+
public static Output<List<ConstructorInfo>, List<ConstructorInfo>> VersioningAdapterConstructorList(bool includeRevit = true, List<Type> ignoredTypes = null)
4547
{
4648
BH.Engine.Base.Compute.LoadAllAssemblies();
4749

@@ -52,16 +54,30 @@ public static Output<List<ConstructorInfo>, List<ConstructorInfo>> VersioningAda
5254
BH.Engine.Base.Compute.RecordError($"Exiting {nameof(VersioningAdapterConstructorList)} with empty lists returned as failed to execute {nameof(Compute.LoadRevitAssemblies)}.");
5355
return new Output<List<ConstructorInfo>, List<ConstructorInfo>>() { Item1 = new List<ConstructorInfo>(), Item2 = new List<ConstructorInfo>() };
5456
}
55-
}
5657

58+
}
59+
ignoredTypes = ignoredTypes ?? new List<Type>();
5760
List<ConstructorInfo> bhomAdapterConstructors = BH.Engine.Base.Query.AdapterTypeList().SelectMany(x => x.GetConstructors()).ToList();
5861

5962
List<ConstructorInfo> included = new List<ConstructorInfo>();
6063
List<ConstructorInfo> ignored = new List<ConstructorInfo>();
6164

62-
foreach (var ctor in bhomAdapterConstructors)
63-
{
64-
if(ctor.IsNotImplemented() || ctor.IsDeprecated())
65+
foreach (var ctor in bhomAdapterConstructors)
66+
{
67+
bool shouldBeIgnored = ignoredTypes.Any(x => x.IsAssignableFrom(ctor.DeclaringType));
68+
69+
70+
bool isDepractedOrNotImplemented = false;
71+
try
72+
{
73+
isDepractedOrNotImplemented = ctor.IsDeprecated() || ctor.IsNotImplemented();
74+
}
75+
catch (Exception e)
76+
{
77+
isDepractedOrNotImplemented = true;
78+
BH.Engine.Base.Compute.RecordError(e, $"Could not check if {ctor.DeclaringType.Name} was deprecated");
79+
}
80+
if (shouldBeIgnored || isDepractedOrNotImplemented || ctor.IsTestToolkit())
6581
ignored.Add(ctor);
6682
else
6783
included.Add(ctor);
@@ -71,6 +87,8 @@ public static Output<List<ConstructorInfo>, List<ConstructorInfo>> VersioningAda
7187
}
7288

7389
/***************************************************/
90+
91+
7492
}
7593
}
7694

Test_Engine/Query/VersioningMethodList.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,18 @@ public static Output<List<MethodInfo>, List<MethodInfo>> VersioningMethodList(bo
5656

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

59-
List<MethodInfo> included = bhomMethodList;
59+
List<MethodInfo> included = new List<MethodInfo>();
6060
List<MethodInfo> ignored = new List<MethodInfo>();
6161

62-
//Note, keeping both collections here for now to allow for future filtering without requirement of changing scripts.
62+
foreach (MethodInfo method in bhomMethodList)
63+
{
64+
bool isPropMethod = method.DeclaringType.GetProperties().Any(x => x.GetSetMethod() == method || x.GetGetMethod() == method);
65+
if (!method.IsTestToolkit() && !isPropMethod)
66+
included.Add(method);
67+
else
68+
ignored.Add(method);
69+
}
70+
6371
return new Output<List<MethodInfo>, List<MethodInfo>> { Item1 = included, Item2 = ignored };
6472
}
6573

Test_Engine/Query/VersioningTypeList.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,17 @@ public static Output<List<Type>, List<Type>> VersioningTypeList(bool includeRevi
6060

6161
foreach (Type type in bhomTypeList)
6262
{
63-
if (typeof(IObject).IsAssignableFrom(type) && !type.IsAbstract && !type.IsDeprecated())
63+
bool isDepracted = false;
64+
try
65+
{
66+
isDepracted = type.IsDeprecated();
67+
}
68+
catch (Exception e)
69+
{
70+
isDepracted = true;
71+
BH.Engine.Base.Compute.RecordError(e, $"Could not check if {type.FullName} was deprecated");
72+
}
73+
if (!type.IsTestToolkit() && typeof(IObject).IsAssignableFrom(type) && !type.IsAbstract && !isDepracted)
6474
{
6575
includeTypeList.Add(type);
6676
}

Test_Engine/Test_Engine.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
<Compile Include="Properties\AssemblyInfo.cs" />
9292
<Compile Include="Query\FullMessage.cs" />
9393
<Compile Include="Query\IsEqualOrMoreSevere.cs" />
94+
<Compile Include="Query\IsTestToolkit.cs" />
9495
<Compile Include="Query\MostSevereStatus.cs" />
9596
<Compile Include="Query\TestInformationOfType.cs" />
9697
<Compile Include="Query\VersioningAdapterConstructorList.cs" />

0 commit comments

Comments
 (0)