Skip to content

Commit

Permalink
Merge pull request #4256 from devlead/feature/gh-4255
Browse files Browse the repository at this point in the history
GH4255: Introduce Verify for CodeGen Expectations
  • Loading branch information
devlead authored Nov 16, 2023
2 parents f1d3ebe + 16a25bd commit dc378ed
Show file tree
Hide file tree
Showing 58 changed files with 124 additions and 143 deletions.
12 changes: 11 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,14 @@ indent_size = 4

[*.js]
indent_style = tab
indent_size = 2
indent_size = 2

# Verify settings
[*.{received,verified}.{txt,xml,json,cake}]
charset = "utf-8-bom"
end_of_line = lf
indent_size = unset
indent_style = unset
insert_final_newline = false
tab_width = unset
trim_trailing_whitespace = false
17 changes: 13 additions & 4 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#
# Merging from the command prompt will add diff markers to the files if there
# are conflicts (Merging from VS is not affected by the settings below, in VS
# the diff markers are never inserted). Diff markers may cause the following
# the diff markers are never inserted). Diff markers may cause the following
# file extensions to fail to load in VS. An alternative would be to treat
# these files as binary and thus will always conflict and require user
# intervention with every merge. To do so, just uncomment the entries below
Expand Down Expand Up @@ -47,9 +47,9 @@

###############################################################################
# diff behavior for common document formats
#
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
#*.doc diff=astextplain
Expand All @@ -61,4 +61,13 @@
#*.pdf diff=astextplain
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain
#*.RTF diff=astextplain

###############################################################################
# Verify files
###############################################################################

*.verified.txt text eol=lf working-tree-encoding=UTF-8
*.verified.xml text eol=lf working-tree-encoding=UTF-8
*.verified.json text eol=lf working-tree-encoding=UTF-8
*.verified.cake text eol=lf working-tree-encoding=UTF-8
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,7 @@ Thumbs.db
.DS_Store

# Generated Assembly info
AssemblyInfo.Generated.cs
AssemblyInfo.Generated.cs

# Verify
*.received
3 changes: 2 additions & 1 deletion src/Cake.Core.Tests/Cake.Core.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<!-- Global packages -->
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="Spectre.Verify.Extensions" Version="22.3.0" />
<PackageReference Include="Verify.Xunit" Version="22.4.1" />
<PackageReference Include="xunit" Version="2.6.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3">
<PrivateAssets>all</PrivateAssets>
Expand All @@ -24,7 +26,6 @@
<PackageReference Include="Castle.Core" Version="5.1.1" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Unit\Scripting\CodeGen\Expected\Methods\*;Unit\Scripting\CodeGen\Expected\Properties\*" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
</Project>
26 changes: 0 additions & 26 deletions src/Cake.Core.Tests/Exceptions/CustomeExitCodeTests.cs

This file was deleted.

19 changes: 0 additions & 19 deletions src/Cake.Core.Tests/Fixtures/MethodAliasGeneratorFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,13 @@ namespace Cake.Core.Tests.Fixtures
{
public sealed class MethodAliasGeneratorFixture
{
private readonly Assembly _assembly;
private readonly MethodInfo[] _methods;

public MethodAliasGeneratorFixture()
{
_assembly = typeof(MethodAliasGeneratorFixture).GetTypeInfo().Assembly;
_methods = typeof(MethodAliasGeneratorData).GetMethods();
}

[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2202:Do not dispose objects multiple times")]
public string GetExpectedCode(string name)
{
var resource = string.Concat("Cake.Core.Tests.Unit.Scripting.CodeGen.Expected.Methods.", name);
using (var stream = _assembly.GetManifestResourceStream(resource))
{
if (stream == null)
{
throw new InvalidOperationException("Could not load manifest resource stream.");
}
using (var reader = new StreamReader(stream))
{
return reader.ReadToEnd().NormalizeGeneratedCode();
}
}
}

public string Generate(string name)
{
var method = _methods.SingleOrDefault(x => x.Name == name);
Expand Down
17 changes: 0 additions & 17 deletions src/Cake.Core.Tests/Fixtures/PropertyAliasGeneratorFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,6 @@ public PropertyAliasGeneratorFixture()
_methods = typeof(PropertyAliasGeneratorData).GetMethods();
}

[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2202:Do not dispose objects multiple times")]
public string GetExpectedData(string name)
{
var resource = string.Concat("Cake.Core.Tests.Unit.Scripting.CodeGen.Expected.Properties.", name);
using (var stream = _assembly.GetManifestResourceStream(resource))
{
if (stream == null)
{
throw new InvalidOperationException("Could not load manifest resource stream.");
}
using (var reader = new StreamReader(stream))
{
return reader.ReadToEnd().NormalizeGeneratedCode();
}
}
}

public string Generate(string name)
{
var method = _methods.SingleOrDefault(x => x.Name == name);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Threading.Tasks;
using Cake.Core.Scripting.CodeGen;
using Cake.Core.Tests.Fixtures;
using VerifyXunit;
using Xunit;
using static Cake.Core.Tests.VerifyConfig;

namespace Cake.Core.Tests.Unit.Scripting.CodeGen
{
[UsesVerify]
public sealed class MethodAliasGeneratorTests
{
[UsesVerify]
public sealed class TheGeneratorMethod : IClassFixture<MethodAliasGeneratorFixture>
{
private readonly MethodAliasGeneratorFixture _fixture;
Expand All @@ -30,76 +35,70 @@ public void Should_Throw_If_Method_Is_Null()
}

[Theory]
[InlineData("NonGeneric_ExtensionMethodWithNoParameters")]
[InlineData("NonGeneric_ExtensionMethodWithParameter")]
[InlineData("NonGeneric_ExtensionMethodWithGenericParameter")]
[InlineData("NonGeneric_ExtensionMethodWithGenericExpressionParameter")]
[InlineData("NonGeneric_ExtensionMethodWithGenericExpressionArrayParameter")]
[InlineData("NonGeneric_ExtensionMethodWithGenericExpressionParamsArrayParameter")]
[InlineData("NonGeneric_ExtensionMethodWithReturnValue")]
[InlineData("NonGeneric_ExtensionMethodWithParameterArray")]
[InlineData("NonGeneric_ExtensionMethodWithOptionalObjectParameter")]
[InlineData("NonGeneric_ExtensionMethodWithOptionalBooleanParameter")]
[InlineData("NonGeneric_ExtensionMethodWithOptionalStringParameter")]
[InlineData("NonGeneric_ExtensionMethodWithOptionalEnumParameter")]
[InlineData("NonGeneric_ExtensionMethodWithOptionalCharParameter")]
[InlineData("NonGeneric_ExtensionMethodWithOptionalDecimalParameter")]
[InlineData("NonGeneric_ExtensionMethodWithOptionalNullableTParameter")]
[InlineData("NonGeneric_ExtensionMethodWithOptionalNullableBooleanParameter")]
[InlineData("NonGeneric_ExtensionMethodWithOptionalNullableCharParameter")]
[InlineData("NonGeneric_ExtensionMethodWithOptionalNullableEnumParameter")]
[InlineData("NonGeneric_ExtensionMethodWithOptionalNullableDecimalParameter")]
[InlineData("NonGeneric_ExtensionMethodWithOptionalNullableLongParameter")]
[InlineData("NonGeneric_ExtensionMethodWithOptionalNullableDoubleParameter")]
[InlineData("NonGeneric_ExtensionMethodWithReservedKeywordParameter")]
[InlineData("NonGeneric_ExtensionMethodWithOutputParameter")]
[InlineData("NonGeneric_ExtensionMethodWithGenericCollectionOfNestedType")]
[InlineData("NonGeneric_ExtensionMethodWithParameterAttributes")]
[InlineData("NonGeneric_ExtensionMethodWithDynamicReturnValue")]
public void Should_Return_Correct_Generated_Code_For_Non_Generic_Methods(string name)
[InlineData("ExtensionMethodWithNoParameters")]
[InlineData("ExtensionMethodWithParameter")]
[InlineData("ExtensionMethodWithGenericParameter")]
[InlineData("ExtensionMethodWithGenericExpressionParameter")]
[InlineData("ExtensionMethodWithGenericExpressionArrayParameter")]
[InlineData("ExtensionMethodWithGenericExpressionParamsArrayParameter")]
[InlineData("ExtensionMethodWithReturnValue")]
[InlineData("ExtensionMethodWithParameterArray")]
[InlineData("ExtensionMethodWithOptionalObjectParameter")]
[InlineData("ExtensionMethodWithOptionalBooleanParameter")]
[InlineData("ExtensionMethodWithOptionalStringParameter")]
[InlineData("ExtensionMethodWithOptionalEnumParameter")]
[InlineData("ExtensionMethodWithOptionalCharParameter")]
[InlineData("ExtensionMethodWithOptionalDecimalParameter")]
[InlineData("ExtensionMethodWithOptionalNullableTParameter")]
[InlineData("ExtensionMethodWithOptionalNullableBooleanParameter")]
[InlineData("ExtensionMethodWithOptionalNullableCharParameter")]
[InlineData("ExtensionMethodWithOptionalNullableEnumParameter")]
[InlineData("ExtensionMethodWithOptionalNullableDecimalParameter")]
[InlineData("ExtensionMethodWithOptionalNullableLongParameter")]
[InlineData("ExtensionMethodWithOptionalNullableDoubleParameter")]
[InlineData("ExtensionMethodWithReservedKeywordParameter")]
[InlineData("ExtensionMethodWithOutputParameter")]
[InlineData("ExtensionMethodWithGenericCollectionOfNestedType")]
[InlineData("ExtensionMethodWithParameterAttributes")]
[InlineData("ExtensionMethodWithDynamicReturnValue")]
public Task Should_Return_Correct_Generated_Code_For_Non_Generic_Methods(string name)
{
// Given
var expected = _fixture.GetExpectedCode(name);

// When
var result = _fixture.Generate(name);
// Given / When
var result = _fixture.Generate("NonGeneric_" + name);

// Then
Assert.Equal(expected, result);
return VerifyCake(result)
.UseParameters(name);
}

[Theory]
[InlineData("Generic_ExtensionMethod")]
[InlineData("Generic_ExtensionMethodWithParameter")]
[InlineData("Generic_ExtensionMethodWithGenericReturnValue")]
[InlineData("Generic_ExtensionMethodWithGenericReturnValueAndTypeParamConstraints")]
public void Should_Return_Correct_Generated_Code_For_Generic_Methods(string name)
public Task Should_Return_Correct_Generated_Code_For_Generic_Methods(string name)
{
// Given
var expected = _fixture.GetExpectedCode(name);

// When
// Given / When
var result = _fixture.Generate(name);

// Then
Assert.Equal(expected, result);
return VerifyCake(result)
.UseParameters(name);
}

[Theory]
[InlineData("Obsolete_ImplicitWarning_NoMessage")]
[InlineData("Obsolete_ImplicitWarning_WithMessage")]
[InlineData("Obsolete_ExplicitWarning_WithMessage")]
[InlineData("Obsolete_ExplicitError_WithMessage")]
public void Should_Return_Correct_Generated_Code_For_Obsolete_Methods(string name)
public Task Should_Return_Correct_Generated_Code_For_Obsolete_Methods(string name)
{
// Given
var expected = _fixture.GetExpectedCode(name);

// When
// Given / When
var result = _fixture.Generate(name);

// Then
Assert.Equal(expected, result);
return VerifyCake(result)
.UseParameters(name);
}
}
}
Expand Down
Loading

0 comments on commit dc378ed

Please sign in to comment.