Lucene.Net.TestFramework: Added exception logic for Nullable Enum convention


Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/32be74bf
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/32be74bf
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/32be74bf

Branch: refs/heads/api-work
Commit: 32be74bfe403766a55c0e7269a458c4b5ab3e998
Parents: da64d38
Author: Shad Storhaug <[email protected]>
Authored: Fri Mar 10 22:56:34 2017 +0700
Committer: Shad Storhaug <[email protected]>
Committed: Sat Mar 11 12:47:39 2017 +0700

----------------------------------------------------------------------
 src/Lucene.Net.Core/Lucene.Net.csproj                  |  1 +
 .../Support/ExceptionToNullableEnumConvention.cs       | 13 +++++++++++++
 src/Lucene.Net.TestFramework/Util/ApiScanTestBase.cs   | 11 +++++++++--
 .../Util/TestRuleSetupAndRestoreClassEnv.cs            |  9 ++++++++-
 4 files changed, 31 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/32be74bf/src/Lucene.Net.Core/Lucene.Net.csproj
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Lucene.Net.csproj 
b/src/Lucene.Net.Core/Lucene.Net.csproj
index d094f47..db7adab 100644
--- a/src/Lucene.Net.Core/Lucene.Net.csproj
+++ b/src/Lucene.Net.Core/Lucene.Net.csproj
@@ -637,6 +637,7 @@
     <Compile Include="Support\DataOutputStream.cs" />
     <Compile Include="Support\Codecs\DefaultCodecFactory.cs" />
     <Compile Include="Support\ExceptionToClassNameConventionAttribute.cs" />
+    <Compile Include="Support\ExceptionToNullableEnumConvention.cs" />
     <Compile Include="Support\FileStreamExtensions.cs" />
     <Compile Include="Support\HashHelpers.cs" />
     <Compile Include="Support\ICallable.cs" />

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/32be74bf/src/Lucene.Net.Core/Support/ExceptionToNullableEnumConvention.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Support/ExceptionToNullableEnumConvention.cs 
b/src/Lucene.Net.Core/Support/ExceptionToNullableEnumConvention.cs
new file mode 100644
index 0000000..db046ba
--- /dev/null
+++ b/src/Lucene.Net.Core/Support/ExceptionToNullableEnumConvention.cs
@@ -0,0 +1,13 @@
+using System;
+
+namespace Lucene.Net.Support
+{
+    /// <summary>
+    /// Use this attribute to make an exception to the nullable enum rule.
+    /// Some of these cannot be avoided.
+    /// </summary>
+    [AttributeUsage(AttributeTargets.Method | AttributeTargets.Property | 
AttributeTargets.Field | AttributeTargets.Constructor, AllowMultiple = false)]
+    public class ExceptionToNullableEnumConvention : Attribute
+    {
+    }
+}

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/32be74bf/src/Lucene.Net.TestFramework/Util/ApiScanTestBase.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.TestFramework/Util/ApiScanTestBase.cs 
b/src/Lucene.Net.TestFramework/Util/ApiScanTestBase.cs
index fc8b96b..42423c0 100644
--- a/src/Lucene.Net.TestFramework/Util/ApiScanTestBase.cs
+++ b/src/Lucene.Net.TestFramework/Util/ApiScanTestBase.cs
@@ -325,8 +325,9 @@ namespace Lucene.Net.Util
             //}
 
             Assert.IsFalse(names.Any(), names.Count() + " members that are 
type nullable enum detected. " +
-                "Nullable enum parameters, fields, methods, and properties 
should be eliminated, either by " +
-                "eliminating the logic that depends on 'null' or by adding a 
NOT_SET=0 state to the enum.");
+                "Nullable enum parameters, fields, methods, and properties 
should be eliminated (where possible), either by " +
+                "eliminating the logic that depends on 'null'. Sometimes, it 
makes sense to keep a nullable enum parameter. " +
+                "In those cases, mark the member with the 
[ExceptionToNullableEnumConvention] attribute.");
         }
 
         //[Test, LuceneNetSpecific]
@@ -869,6 +870,12 @@ namespace Lucene.Net.Util
                         continue;
                     }
 
+                    // Ignore properties, methods, and events with 
IgnoreNetNumericConventionAttribute
+                    if (System.Attribute.IsDefined(member, 
typeof(ExceptionToNullableEnumConvention)))
+                    {
+                        continue;
+                    }
+
                     if (member.DeclaringType.Equals(t.UnderlyingSystemType))
                     {
                         if (member.MemberType == MemberTypes.Method && 
!(member.Name.StartsWith("get_") || member.Name.StartsWith("set_")))

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/32be74bf/src/Lucene.Net.TestFramework/Util/TestRuleSetupAndRestoreClassEnv.cs
----------------------------------------------------------------------
diff --git 
a/src/Lucene.Net.TestFramework/Util/TestRuleSetupAndRestoreClassEnv.cs 
b/src/Lucene.Net.TestFramework/Util/TestRuleSetupAndRestoreClassEnv.cs
index 34ad216..4715e57 100644
--- a/src/Lucene.Net.TestFramework/Util/TestRuleSetupAndRestoreClassEnv.cs
+++ b/src/Lucene.Net.TestFramework/Util/TestRuleSetupAndRestoreClassEnv.cs
@@ -239,12 +239,19 @@ namespace Lucene.Net.Util
             {
                 Debug.Assert(false);
             }
+            //codec = Codec.ForName("Lucene42");
+            //LuceneTestCase.OLD_FORMAT_IMPERSONATION_IS_ACTIVE = true;
+
             Codec.Default = codec;
 
             // Initialize locale/ timezone.
             string testLocale = 
System.Environment.GetEnvironmentVariable("tests.locale") ?? "random";
             string testTimeZone = 
System.Environment.GetEnvironmentVariable("tests.timezone") ?? "random";
 
+            //testLocale = "sr-Latn-RS";
+            testLocale = "lt-LT";
+            //testLocale = "en-US";
+
             // Always pick a random one for consistency (whether tests.locale 
was specified or not).
             savedLocale = CultureInfo.CurrentCulture;
             CultureInfo randomLocale = LuceneTestCase.RandomLocale(random);
@@ -266,7 +273,7 @@ namespace Lucene.Net.Util
             //TimeZoneInfo.ConvertTime() // LUCENENET TODO: Everywhere 
TimeZoneInfo is supposed to be used, use this method to convert a dateTime 
object to the time zone
 
             similarity = random.NextBoolean() ? (Similarity)new 
DefaultSimilarity() : new RandomSimilarityProvider(random);
-            
+
             // Check codec restrictions once at class level.
             try
             {

Reply via email to