Skip to content

Fix automatic test skipping #157

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

Merged
merged 1 commit into from
Oct 16, 2023
Merged
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
20 changes: 20 additions & 0 deletions src/EFCore.Jet/Utilities/ExceptionExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Collections.Generic;

// ReSharper disable once CheckNamespace
namespace System;

public static class ExceptionExtensions
{
public static IEnumerable<Exception> FlattenHierarchy(this Exception ex)
{
ArgumentNullException.ThrowIfNull(ex);

var innerException = ex;
do
{
yield return innerException;
innerException = innerException.InnerException;
}
while (innerException != null);
}
}
65 changes: 38 additions & 27 deletions test/Shared/TestUtilities/Xunit/JetXunitTestRunner.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
Expand Down Expand Up @@ -128,44 +129,54 @@ public JetXunitTestRunner(
/// </summary>
protected virtual bool SkipFailedTest(Exception exception)
{
var skip = true;
var skip = false;
var unexpectedUnsupportedTranslation = false;

var aggregateException = exception as AggregateException ??
new AggregateException(exception);

foreach (var innerException in aggregateException.InnerExceptions)
foreach (var innerException in aggregateException.Flatten().InnerExceptions.SelectMany(e => e.FlattenHierarchy()))
{
if (!skip ||
innerException is not InvalidOperationException)
if (innerException is InvalidOperationException)
{
return false;
}

if (innerException.Message.StartsWith("Jet does not support "))
{
var expectedUnsupportedTranslation = innerException.Message.Contains("APPLY statements") ||
innerException.Message.Contains("skipping rows");
var message = innerException.Message;

skip &= expectedUnsupportedTranslation;
unexpectedUnsupportedTranslation = !expectedUnsupportedTranslation;
}
else if (innerException.Message.StartsWith("The LINQ expression '") &&
innerException.Message.Contains("' could not be translated."))
{
var expectedUnsupportedTranslation = innerException.Message.Contains("RowNumberExpression");
if (message.StartsWith("Jet does not support "))
{
var expectedUnsupportedTranslation = message.Contains("APPLY statements") ||
message.Contains("skipping rows");

skip &= expectedUnsupportedTranslation;
unexpectedUnsupportedTranslation = !expectedUnsupportedTranslation;
}
skip = expectedUnsupportedTranslation;
unexpectedUnsupportedTranslation = !expectedUnsupportedTranslation;
}
else if (message.StartsWith("The LINQ expression '") &&
message.Contains("' could not be translated."))
{
var expectedUnsupportedTranslation = message.Contains("RowNumberExpression");

if (unexpectedUnsupportedTranslation)
{
var sb = new StringBuilder();
sb.AppendLine(innerException.Message.ReplaceLineEndings(" "));
sb.AppendLine("-----");
skip = expectedUnsupportedTranslation;
unexpectedUnsupportedTranslation = !expectedUnsupportedTranslation;
}

if (skip)
{
// var sb = new StringBuilder();
// sb.AppendLine(message.ReplaceLineEndings(" "));
// sb.AppendLine("-----");
//
// File.AppendAllText("ExpectedUnsupportedTranslations.txt", sb.ToString());

File.AppendAllText("UnsupportedTranslations.txt", sb.ToString());
break;
}

if (unexpectedUnsupportedTranslation)
{
// var sb = new StringBuilder();
// sb.AppendLine(message.ReplaceLineEndings(" "));
// sb.AppendLine("-----");
//
// File.AppendAllText("UnsupportedTranslations.txt", sb.ToString());
}
}
}

Expand Down