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

Bump xunit and related fixes #350

Merged
merged 10 commits into from
Oct 12, 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
3 changes: 1 addition & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
branches:
- master
- develop
- v8
- v8
paths:
- src/**
- .github/workflows/**
Expand Down Expand Up @@ -39,7 +39,6 @@ jobs:
with:
dotnet-version: |
3.1.x
5.0.x
6.0.x
7.0.x
source-url: https://nuget.pkg.github.com/graphql-dotnet/index.json
Expand Down
4 changes: 2 additions & 2 deletions src/GraphQLParser.ApiTests/GraphQLParser.ApiTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="Shouldly" Version="4.2.1" />
<PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5" />
<PackageReference Include="xunit" Version="2.5.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.1" />
<PackageReference Include="PublicApiGenerator" Version="11.0.0" />
</ItemGroup>

Expand Down
5 changes: 3 additions & 2 deletions src/GraphQLParser.Tests/GraphQLParser.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
</PropertyGroup>

<PropertyGroup Condition="'$(SingleTestPlatform)' != 'true'">
<TargetFrameworks>netcoreapp3.1;net5;net6;net7</TargetFrameworks>
<TargetFrameworks>netcoreapp3.1;net6;net7</TargetFrameworks>
<TargetFrameworks Condition="'$(OS)' == 'Windows_NT'">$(TargetFrameworks);net462</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand All @@ -27,7 +28,7 @@
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="Shouldly" Version="4.2.1" />
<PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="xunit" Version="2.5.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5" />
</ItemGroup>

Expand Down
8 changes: 4 additions & 4 deletions src/GraphQLParser.Tests/Visitors/ASTVisitorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,25 @@ public void ASTVisitor_Should_Handle_Null()
}

[Fact]
public void ASTVisitor_Should_Throw_On_Unknown_Node()
public async Task ASTVisitor_Should_Throw_On_Unknown_Node()
{
var visitor = new ASTVisitor<Context>();
var context = new Context();

var ex = Should.Throw<NotSupportedException>(() => visitor.VisitAsync(new MySuperNode(), context).GetAwaiter().GetResult());
var ex = await Should.ThrowAsync<NotSupportedException>(async () => await visitor.VisitAsync(new MySuperNode(), context));
sungam3r marked this conversation as resolved.
Show resolved Hide resolved
ex.Message.ShouldBe("Unknown node 'MySuperNode'.");
}

[Fact]
public void ASTVisitor_Should_Pass_CancellationToken()
public async Task ASTVisitor_Should_Pass_CancellationToken()
{
var document = "scalar JSON".Parse();
var visitor = new MyVisitor();
using var cts = new CancellationTokenSource(500);
var context = new Context { CancellationToken = cts.Token };
context.CancellationToken.ThrowIfCancellationRequested();

Should.Throw<OperationCanceledException>(() => visitor.VisitAsync(document, context).GetAwaiter().GetResult());
await Should.ThrowAsync<OperationCanceledException>(async () => await visitor.VisitAsync(document, context));
}

private sealed class MyVisitor : ASTVisitor<Context>
Expand Down
4 changes: 2 additions & 2 deletions src/GraphQLParser.Tests/Visitors/CountVisitorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public async Task CountVisitor_Should_Count_Nodes(string text, int expectedCount

var document = text.Parse();

await visitor.VisitAsync(document, context).ConfigureAwait(false);
await visitor.VisitAsync(document, context);
sungam3r marked this conversation as resolved.
Show resolved Hide resolved
context.Count.ShouldBe(expectedCount);
document.AllNestedCount().ShouldBe(expectedCount);
}
Expand All @@ -55,7 +55,7 @@ public async Task CountVisitor_Should_Count_Zero_Nodes(string text)

var document = text.Parse();

await visitor.VisitAsync(document, context).ConfigureAwait(false);
await visitor.VisitAsync(document, context);
context.Count.ShouldBe(0);
}
}
2 changes: 1 addition & 1 deletion src/GraphQLParser.Tests/Visitors/MaxDepthVisitorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public async Task MaxDepthVisitor_Should_Work(string text, int expectedMaxDepth)

var document = text.Parse();

await visitor.VisitAsync(document, context).ConfigureAwait(false);
await visitor.VisitAsync(document, context);
context.MaxDepth.ShouldBe(expectedMaxDepth);
document.MaxNestedDepth().ShouldBe(expectedMaxDepth);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ public async Task SDLPrinter_Should_Print_Document(
var writer = new StringWriter();
var document = text.Parse();

await printer.PrintAsync(document, writer).ConfigureAwait(false);
await printer.PrintAsync(document, writer);
var actual = writer.ToString();
actual.ShouldBe(expected, $"Test {number} failed");

Expand Down Expand Up @@ -924,11 +924,11 @@ public async Task SDLPrinter_Should_Print_BlockStrings(int number, string input,
var document = (input + " scalar a").Parse();

var printer = new SDLPrinter();
await printer.PrintAsync(document, writer).ConfigureAwait(false);
await printer.PrintAsync(document, writer);
var renderedOriginal = writer.ToString();

var lines = renderedOriginal.Split(Environment.NewLine);
var renderedDescription = string.Join(Environment.NewLine, lines.SkipLast(1));
var lines = renderedOriginal.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
sungam3r marked this conversation as resolved.
Show resolved Hide resolved
var renderedDescription = string.Join(Environment.NewLine, lines.Take(lines.Length - 1));
renderedDescription = renderedDescription.Replace("\r\n", "\n");
renderedDescription.ShouldBe(expected);

Expand All @@ -955,7 +955,7 @@ public async Task SDLPrinter_Should_Print_EscapedStrings(string stringValue)
var document = query.Parse();

var printer = new SDLPrinter();
await printer.PrintAsync(document, writer).ConfigureAwait(false);
await printer.PrintAsync(document, writer);
var rendered = writer.ToString();
rendered.ShouldBe(expected);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public async Task Printer_Should_Print_Pretty_If_Directives_Skipped(
var writer = new StringWriter();
var document = text.Parse();

await printer.PrintAsync(document, writer).ConfigureAwait(false);
await printer.PrintAsync(document, writer);
var actual = writer.ToString();
actual.ShouldBe(expected, $"Test {number} failed");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public async Task Printer_Should_Print_Pretty_If_Definitions_Skipped(
var writer = new StringWriter();
var document = text.Parse();

await printer.PrintAsync(document, writer).ConfigureAwait(false);
await printer.PrintAsync(document, writer);
var actual = writer.ToString();
actual.ShouldBe(expected, $"Test {number} failed");

Expand Down
8 changes: 4 additions & 4 deletions src/GraphQLParser.Tests/Visitors/StructurePrinterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public async Task StructurePrinter_Should_Print_Tree(string text, string expecte
{
var writer = new StringWriter();
var document = text.Parse();
await _structPrinter1.PrintAsync(document, writer).ConfigureAwait(false);
await _structPrinter1.PrintAsync(document, writer);
var actual = writer.ToString();
actual.ShouldBe(expected);
}
Expand All @@ -304,7 +304,7 @@ public async Task StructurePrinter_Should_Print_Tree_Without_Names(string text,
{
var writer = new StringWriter();
var document = text.Parse();
await _structPrinter2.PrintAsync(document, writer).ConfigureAwait(false);
await _structPrinter2.PrintAsync(document, writer);
var actual = writer.ToString();
actual.ShouldBe(expected);
}
Expand Down Expand Up @@ -550,7 +550,7 @@ public async Task StructurePrinter_Should_Print_Tree_With_Locations(string text,
var writer = new StringWriter();

var document = text.Parse(new ParserOptions { Ignore = option });
await _structPrinter3.PrintAsync(document, writer).ConfigureAwait(false);
await _structPrinter3.PrintAsync(document, writer);
var actual = writer.ToString();
actual.ShouldBe(expected);
}
Expand Down Expand Up @@ -587,7 +587,7 @@ public async Task StructurePrinter_Should_Print_Tree_With_Custom_Indentation(str

var document = text.Parse(new ParserOptions { Ignore = option });
var printer = new StructurePrinter(new StructurePrinterOptions { PrintNames = false, IndentSize = indentSize });
await printer.PrintAsync(document, writer).ConfigureAwait(false);
await printer.PrintAsync(document, writer);
var actual = writer.ToString();
actual.ShouldBe(expected);
}
Expand Down
2 changes: 1 addition & 1 deletion src/GraphQLParser/Visitors/PrintContextExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static ValueTask WriteAsync<TContext>(this TContext context, ROM value)
context.IndentPrinted = false;

var task =
#if NETSTANDARD2_0
#if NETSTANDARD2_0 || NET462
// no cancellationToken support on netstandard2.0
context.Writer.WriteAsync(value.ToString()); //ISSUE: allocation - either WriteAsync(value.ToString()) or Write(char value) in a loop
#elif NETSTANDARD2_1_OR_GREATER || NET6_0_OR_GREATER
Expand Down
12 changes: 11 additions & 1 deletion src/GraphQLParser/Visitors/SDLPrinterExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,23 @@ public static string Print(this SDLPrinter printer, ASTNode node)
public static void Print(this SDLPrinter printer, ASTNode node, StringBuilder stringBuilder)
=> printer.PrintAsync(node, new StringWriter(stringBuilder), default).AsTask().GetAwaiter().GetResult();

#if !NET6_0_OR_GREATER
private static readonly Encoding _uTF8NoBOM = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false, throwOnInvalidBytes: true);
#endif

/// <summary>
/// Prints the specified AST into the specified <see cref="MemoryStream"/> as a SDL document.
/// If no encoding is specified, the document is written in UTF-8 format without a byte order mark.
/// </summary>
public static void Print(this SDLPrinter printer, ASTNode node, MemoryStream memoryStream, Encoding? encoding = null)
{
using var streamWriter = new StreamWriter(memoryStream, encoding, -1 /* default */, true);
int bufferSize = -1;
#if !NET6_0_OR_GREATER
encoding ??= _uTF8NoBOM;
if (bufferSize == -1)
bufferSize = 1024;
#endif
using var streamWriter = new StreamWriter(memoryStream, encoding, bufferSize, true);
printer.PrintAsync(node, streamWriter, default).AsTask().GetAwaiter().GetResult();
// flush encoder state to stream
streamWriter.Flush();
Expand Down