-
Notifications
You must be signed in to change notification settings - Fork 643
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Lucene.Net.TestFramework: Improved error handling and test reporting (#…
…1092) * Lucene.Net.Util.LuceneTestCase.SetUpFixture::OneTimeSetUpWrapper(): Removed debug code. * Lucene.Net.Util.LuceneTestCase (OneTimeSetUp() + OneTimeTearDown()): Fixed error reporting, since NUnit swallows exceptions in these events. This will write them to stderr by default and allows enabling failing the tests if an exception occurs in LuceneTestCase.OneTimeSetUp() which will make them appear in the Test Output window in Visual Studio. The failures can be enabled by setting the tests:failontestfixtureonetimesetuperror system property to true. * azure-pipelines.yml: Added FailOnTestFixtureOneTimeSetUpError environment variable (defaulting to 'true') to set the system property of the same name. * Lucene.Net.Search.RandomSimilarityProvider: Use J2N.Collections.Generic.Dictionary<TKey, TValue>, which will format itself. Marked fields private instead of internal. * PERFORMANCE: Moved logging random test settings and system properties from SetUp() to TearDown() and only include them in the test message upon failure. * Lucene.Net.Support.ExceptionHandling.TestExceptionExtensions: Removed messages from calls to Assert.Pass(), since this writes to the output and bloats the size of the test logs with no benefit. * publish-test-results.yml + run-tests-on-os.yml: Changed build to fail when maximumAllowedFailures is 0 and there are errors in the stderr file. * publish-test-results.yml + run-tests-on-os.yml: Changed build to fail when maximumAllowedFailures is 0 and there are errors in the stdout in the TestResults.trx file. * publish-test-results.yml: Check for [ERROR] in RunInfo rather than StdOut
- Loading branch information
1 parent
c2583f0
commit a9f7d30
Showing
8 changed files
with
211 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
src/Lucene.Net.TestFramework/Support/Util/TestExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
using NUnit.Framework.Internal; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
#nullable enable | ||
|
||
namespace Lucene.Net.Util | ||
{ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/// <summary> | ||
/// Extensions to <see cref="Test"/>. | ||
/// </summary> | ||
internal static class TestExtensions | ||
{ | ||
/// <summary> | ||
/// Mark the test and all descendents as Invalid (not runnable) specifying a reason and an exception. | ||
/// </summary> | ||
/// <param name="test">This <see cref="Test"/>.</param> | ||
/// <param name="reason">The reason the test is not runnable</param> | ||
/// <exception cref="ArgumentNullException"><paramref name="test"/> or <paramref name="reason"/> is <c>null</c>.</exception> | ||
public static void MakeAllInvalid(this Test test, string reason) | ||
=> MakeAllInvalidInternal(test, null, reason); | ||
|
||
/// <summary> | ||
/// Mark the test and all descendents as Invalid (not runnable) specifying a reason and an exception. | ||
/// </summary> | ||
/// <param name="test">This <see cref="Test"/>.</param> | ||
/// <param name="exception">The exception that was the cause.</param> | ||
/// <param name="reason">The reason the test is not runnable</param> | ||
/// <exception cref="ArgumentNullException"><paramref name="test"/>, <paramref name="exception"/> or <paramref name="reason"/> is <c>null</c>.</exception> | ||
public static void MakeAllInvalid(this Test test, Exception exception, string reason) | ||
{ | ||
if (exception is null) | ||
throw new ArgumentNullException(nameof(exception)); | ||
MakeAllInvalidInternal(test, exception, reason); | ||
} | ||
|
||
private static void MakeAllInvalidInternal(this Test test, Exception? exception, string reason) | ||
{ | ||
if (test is null) | ||
throw new ArgumentNullException(nameof(test)); | ||
if (reason is null) | ||
throw new ArgumentNullException(nameof(reason)); | ||
|
||
if (exception is null) | ||
test.MakeInvalid(reason); | ||
else | ||
test.MakeInvalid(exception, reason); | ||
|
||
if (test.HasChildren) | ||
{ | ||
var stack = new Stack<Test>(test.Tests.OfType<Test>()); | ||
|
||
while (stack.Count > 0) | ||
{ | ||
var currentTest = stack.Pop(); | ||
if (exception is null) | ||
currentTest.MakeInvalid(reason); | ||
else | ||
currentTest.MakeInvalid(exception, reason); | ||
|
||
// Add children to the stack if they exist | ||
if (currentTest.HasChildren) | ||
{ | ||
foreach (var child in currentTest.Tests.OfType<Test>()) | ||
{ | ||
stack.Push(child); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.