Skip to content

Commit

Permalink
chore: uncomment test attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
TimothyMakkison committed Oct 9, 2024
1 parent 0b52490 commit 84881b7
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 22 deletions.
62 changes: 54 additions & 8 deletions Refit.GeneratorTests/Incremental/FunctionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public class FunctionTest
{
private const string DefaultInterface =
"""
#nullable enabled
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -24,7 +25,28 @@ public interface IGitHubApi
}
""";

// [Fact]
private const string ReturnValueInterface =
"""
#nullable enabled
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Refit;
namespace RefitGeneratorTest;
public interface IGitHubApi
{
[Get("/users/{user}")]
Task<int> GetUser(string user);
}
""";

[Fact]
public void ModifyParameterNameDoesRegenerate()
{
var syntaxTree = CSharpSyntaxTree.ParseText(DefaultInterface, CSharpParseOptions.Default);
Expand All @@ -48,7 +70,7 @@ public interface IGitHubApi
TestHelper.AssertRunReasons(driver2, IncrementalGeneratorRunReasons.ModifiedSource);
}

// [Fact]
[Fact]
public void ModifyParameterTypeDoesRegenerate()
{
var syntaxTree = CSharpSyntaxTree.ParseText(DefaultInterface, CSharpParseOptions.Default);
Expand All @@ -72,7 +94,7 @@ public interface IGitHubApi
TestHelper.AssertRunReasons(driver2, IncrementalGeneratorRunReasons.ModifiedSource);
}

// [Fact]
[Fact]
public void ModifyParameterNullabilityDoesRegenerate()
{
var syntaxTree = CSharpSyntaxTree.ParseText(DefaultInterface, CSharpParseOptions.Default);
Expand All @@ -96,7 +118,7 @@ public interface IGitHubApi
TestHelper.AssertRunReasons(driver2, IncrementalGeneratorRunReasons.ModifiedSource);
}

// [Fact]
[Fact]
public void AddParameterDoesRegenerate()
{
var syntaxTree = CSharpSyntaxTree.ParseText(DefaultInterface, CSharpParseOptions.Default);
Expand All @@ -120,7 +142,7 @@ public interface IGitHubApi
TestHelper.AssertRunReasons(driver2, IncrementalGeneratorRunReasons.ModifiedSource);
}

// [Fact]
[Fact]
public void ModifyReturnTypeDoesRegenerate()
{
var syntaxTree = CSharpSyntaxTree.ParseText(DefaultInterface, CSharpParseOptions.Default);
Expand All @@ -144,8 +166,8 @@ public interface IGitHubApi
TestHelper.AssertRunReasons(driver2, IncrementalGeneratorRunReasons.ModifiedSource);
}

// [Fact]
public void ModifyReturnNullabilityDoesRegenerate()
[Fact]
public void ModifyReturnObjectNullabilityDoesNotRegenerate()
{
var syntaxTree = CSharpSyntaxTree.ParseText(DefaultInterface, CSharpParseOptions.Default);
var compilation1 = Fixture.CreateLibrary(syntaxTree);
Expand All @@ -164,11 +186,35 @@ public interface IGitHubApi
""";
var compilation2 = TestHelper.ReplaceMemberDeclaration(compilation1, "IGitHubApi", newInterface);

var driver2 = driver1.RunGenerators(compilation2);
TestHelper.AssertRunReasons(driver2, IncrementalGeneratorRunReasons.Cached);
}

[Fact]
public void ModifyReturnValueNullabilityDoesRegenerate()
{
var syntaxTree = CSharpSyntaxTree.ParseText(DefaultInterface, CSharpParseOptions.Default);
var compilation1 = Fixture.CreateLibrary(syntaxTree);

var driver1 = TestHelper.GenerateTracked(compilation1);
TestHelper.AssertRunReasons(driver1, IncrementalGeneratorRunReasons.New);

// change return nullability
var newInterface =
"""
public interface IGitHubApi
{
[Get("/users/{user}")]
Task<int?> GetUser(string user);
}
""";
var compilation2 = TestHelper.ReplaceMemberDeclaration(compilation1, "IGitHubApi", newInterface);

var driver2 = driver1.RunGenerators(compilation2);
TestHelper.AssertRunReasons(driver2, IncrementalGeneratorRunReasons.ModifiedSource);
}

// [Fact]
[Fact]
public void AddNonRefitMethodDoesRegenerate()
{
var syntaxTree = CSharpSyntaxTree.ParseText(DefaultInterface, CSharpParseOptions.Default);
Expand Down
8 changes: 4 additions & 4 deletions Refit.GeneratorTests/Incremental/GenericTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public interface IGeneratedInterface<T1>
}
""";

// [Fact]
[Fact]
public void RenameGenericTypeDoesRegenerate()
{
var syntaxTree = CSharpSyntaxTree.ParseText(GenericInterface, CSharpParseOptions.Default);
Expand All @@ -49,7 +49,7 @@ public interface IGeneratedInterface<T>
TestHelper.AssertRunReasons(driver2, IncrementalGeneratorRunReasons.ModifiedSource);
}

// [Fact]
[Fact]
public void AddGenericConstraintDoesRegenerate()
{
var syntaxTree = CSharpSyntaxTree.ParseText(GenericInterface, CSharpParseOptions.Default);
Expand Down Expand Up @@ -91,7 +91,7 @@ public interface IGeneratedInterface<T1>
TestHelper.AssertRunReasons(driver3, IncrementalGeneratorRunReasons.ModifiedSource);
}

// [Fact]
[Fact]
public void AddObjectGenericConstraintDoesRegenerate()
{
var syntaxTree = CSharpSyntaxTree.ParseText(GenericInterface, CSharpParseOptions.Default);
Expand All @@ -117,7 +117,7 @@ public interface IGeneratedInterface<T1>
TestHelper.AssertRunReasons(driver2, IncrementalGeneratorRunReasons.ModifiedSource);
}

// [Fact]
[Fact]
public void AddGenericTypeDoesRegenerate()
{
var syntaxTree = CSharpSyntaxTree.ParseText(GenericInterface, CSharpParseOptions.Default);
Expand Down
10 changes: 4 additions & 6 deletions Refit.GeneratorTests/Incremental/IncrementalTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace Refit.GeneratorTests.Incremental;

public class IncrementalTest
{
private const string Default =
private const string DefaultInterface =
"""
#nullable enabled
using System;
Expand All @@ -25,7 +25,7 @@ public interface IGitHubApi
}
""";

// [Fact]
[Fact]
public void AddUnrelatedTypeDoesntRegenerate()
{
var syntaxTree = CSharpSyntaxTree.ParseText(DefaultInterface, CSharpParseOptions.Default);
Expand All @@ -39,7 +39,7 @@ public void AddUnrelatedTypeDoesntRegenerate()
TestHelper.AssertRunReasons(driver2, IncrementalGeneratorRunReasons.Cached);
}

// [Fact]
[Fact]
public void SmallChangeDoesntRegenerate()
{
var syntaxTree = CSharpSyntaxTree.ParseText(DefaultInterface, CSharpParseOptions.Default);
Expand All @@ -57,16 +57,14 @@ public interface IGitHubApi
{
[Get("/users/{user}")]
Task<string> GetUser(string user);
private record Temp();
}
"""
);
var driver2 = driver1.RunGenerators(compilation2);
TestHelper.AssertRunReasons(driver2, IncrementalGeneratorRunReasons.Cached);
}

// [Fact]
[Fact]
public void AddNewMemberDoesRegenerate()
{
var syntaxTree = CSharpSyntaxTree.ParseText(DefaultInterface, CSharpParseOptions.Default);
Expand Down
7 changes: 4 additions & 3 deletions Refit.GeneratorTests/Incremental/InheritanceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public interface IGitHubApi
public interface IBaseInterface { void NonRefitMethod(); }
""";

// [Fact]
[Fact]
public void InheritFromIDisposableDoesRegenerate()
{
var syntaxTree = CSharpSyntaxTree.ParseText(DefaultInterface, CSharpParseOptions.Default);
Expand All @@ -71,9 +71,10 @@ public interface IGitHubApi : IDisposable
TestHelper.AssertRunReasons(driver2, IncrementalGeneratorRunReasons.ModifiedSource);
}

// [Fact]
[Fact]
public void InheritFromInterfaceDoesRegenerate()
{
// TODO: this currently generates invalid code see issue #1801 for more information
var syntaxTree = CSharpSyntaxTree.ParseText(TwoInterface, CSharpParseOptions.Default);
var compilation1 = Fixture.CreateLibrary(syntaxTree);

Expand All @@ -93,6 +94,6 @@ public interface IGitHubApi : IBaseInterface
"""
);
var driver2 = driver1.RunGenerators(compilation2);
TestHelper.AssertRunReasons(driver2, IncrementalGeneratorRunReasons.Modified);
TestHelper.AssertRunReasons(driver2, IncrementalGeneratorRunReasons.Cached);
}
}
2 changes: 1 addition & 1 deletion Refit.GeneratorTests/InterfaceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public interface IBaseInterface
[Fact]
public Task RefitInterfaceDerivedFromBaseTest()
{
// this currently generates invalid code see issue #1801 for more information
// TODO: this currently generates invalid code see issue #1801 for more information
return Fixture.VerifyForType(
"""
public interface IGeneratedInterface : IBaseInterface
Expand Down

0 comments on commit 84881b7

Please sign in to comment.