thomhurst / TUnit

A modern, fast and flexible .NET testing framework
MIT License
2.28k stars 37 forks source link

Bug - Code Generator fails on string escape sequences and nullable annotated bytes. #575

Closed HarryCordewener closed 1 month ago

HarryCordewener commented 1 month ago

I have a branch for my project, trying to convert to TUnit - https://github.com/SharpMUSH/SharpMUSH/tree/TUnit

However, when I run a build, it fails on the CodeGeneration step of TUnit. I would inspect it, myself to see what lies at the source of this, but the files are not there when the generation fails.

Build failure: https://github.com/SharpMUSH/SharpMUSH/actions/runs/10967113289/job/30456269303

D:\SharpMUSH\SharpMUSH.Tests\obj\Debug\net8.0\TUnit.Engine.SourceGenerator\TUnit.Engine.SourceGenerator.CodeGenerators.TestsGenerator\ANSI_StringFunctionUnitTests_6d4f9a184b1643f1aa38939779ad444e.Generated.cs(21,38): error CS1525: Invalid expression term ';' [D:\SharpMUSH\SharpMUSH.Tests\SharpMUSH.Tests.csproj]
D:\SharpMUSH\SharpMUSH.Tests\obj\Debug\net8.0\TUnit.Engine.SourceGenerator\TUnit.Engine.SourceGenerator.CodeGenerators.TestsGenerator\ANSI_StringFunctionUnitTests_63f9bdb954cb4113951ebca02dec1a3f.Generated.cs(21,38): error CS1525: Invalid expression term ';' [D:\SharpMUSH\SharpMUSH.Tests\SharpMUSH.Tests.csproj]
D:\SharpMUSH\SharpMUSH.Tests\obj\Debug\net8.0\TUnit.Engine.SourceGenerator\TUnit.Engine.SourceGenerator.CodeGenerators.TestsGenerator\ANSIBackground_StringFunctionUnitTests_e019f1f3687a4844b495b947601aaf7f.Generated.cs(21,38): error CS1525: Invalid expression term ';' [D:\SharpMUSH\SharpMUSH.Tests\SharpMUSH.Tests.csproj]
D:\SharpMUSH\SharpMUSH.Tests\obj\Debug\net8.0\TUnit.Engine.SourceGenerator\TUnit.Engine.SourceGenerator.CodeGenerators.TestsGenerator\ANSIBackground_StringFunctionUnitTests_57c663cdb02d4e30bc56189193dec533.Generated.cs(21,38): error CS1525: Invalid expression term ';' [D:\SharpMUSH\SharpMUSH.Tests\SharpMUSH.Tests.csproj]
D:\SharpMUSH\SharpMUSH.Tests\obj\Debug\net8.0\TUnit.Engine.SourceGenerator\TUnit.Engine.SourceGenerator.CodeGenerators.TestsGenerator\Test_FunctionUnitTests_2fa6f6d356ab4af3b6a65198d6e38199.Generated.cs(18,50): error CS1009: Unrecognized escape sequence [D:\SharpMUSH\SharpMUSH.Tests\SharpMUSH.Tests.csproj]
D:\SharpMUSH\SharpMUSH.Tests\obj\Debug\net8.0\TUnit.Engine.SourceGenerator\TUnit.Engine.SourceGenerator.CodeGenerators.TestsGenerator\Test_FunctionUnitTests_2fa6f6d356ab4af3b6a65198d6e38199.Generated.cs(54,37): error CS1009: Unrecognized escape sequence [D:\SharpMUSH\SharpMUSH.Tests\SharpMUSH.Tests.csproj]
D:\SharpMUSH\SharpMUSH.Tests\obj\Debug\net8.0\TUnit.Engine.SourceGenerator\TUnit.Engine.SourceGenerator.CodeGenerators.TestsGenerator\Test_FunctionUnitTests_e11ab05ffb2c4b0496addd4cb43df1ed.Generated.cs(19,43): error CS1009: Unrecognized escape sequence [D:\SharpMUSH\SharpMUSH.Tests\SharpMUSH.Tests.csproj]
D:\SharpMUSH\SharpMUSH.Tests\obj\Debug\net8.0\TUnit.Engine.SourceGenerator\TUnit.Engine.SourceGenerator.CodeGenerators.TestsGenerator\Test_FunctionUnitTests_e11ab05ffb2c4b0496addd4cb43df1ed.Generated.cs(54,53): error CS1009: Unrecognized escape sequence [D:\SharpMUSH\SharpMUSH.Tests\SharpMUSH.Tests.csproj]
D:\SharpMUSH\SharpMUSH.Tests\obj\Debug\net8.0\TestPlatformEntryPoint.cs(10,66): error CS8892: Method 'TestingPlatformEntryPoint.Main(string[])' will not be used as an entry point because a synchronous entry point 'AutoGeneratedProgram.Main(string[])' was found. [D:\SharpMUSH\SharpMUSH.Tests\SharpMUSH.Tests.csproj]
thomhurst commented 1 month ago

Ah thanks for the issue @HarryCordewener - if the source generation is failing then yeah there's an issue.

You can add to your project

<PropertyGroup>
    <EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
    <CompilerGeneratedFilesOutputPath>EmittedSourceGeneratedFiles</CompilerGeneratedFilesOutputPath>
  </PropertyGroup>

To show you the generated files.

If you could post that here I could work out what's the problem.

If not, if you could reproduce the issue in a minimal new project.

Thanks

HarryCordewener commented 1 month ago
// <auto-generated/>
using global::TUnit.Core;
using global::TUnit.Engine;

namespace TUnit.Engine;

[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
file partial class ANSIBackground_StringFunctionUnitTests
{
    [global::System.Runtime.CompilerServices.ModuleInitializer]
    public static void Initialise()
    {
        try
        {
            var methodInfo = typeof(global::SharpMUSH.Tests.Functions.StringFunctionUnitTests).GetMethod("ANSIBackground", 0, [typeof(global::System.String), typeof(global::System.String), typeof(global::System.Byte), typeof(global::System.Byte?)]);
            var resettableClassFactory = new ResettableLazy<global::SharpMUSH.Tests.Functions.StringFunctionUnitTests>(() => new global::SharpMUSH.Tests.Functions.StringFunctionUnitTests());

            global::System.String methodArg0 = "ansi(Y,yellow)";
            global::System.String methodArg1 = "yellow";
            global::System.Byte methodArg2 = 43;
            global::System.Byte? methodArg3 = ; // <------- this should not be empty

            TestRegistrar.RegisterTest<global::SharpMUSH.Tests.Functions.StringFunctionUnitTests>(new TestMetadata<global::SharpMUSH.Tests.Functions.StringFunctionUnitTests>
            {
                TestId = $"ArgumentsAttribute:TDAI3:SharpMUSH.Tests.Functions.StringFunctionUnitTests.ANSIBackground:(System.String,System.String,System.Byte,System.Byte?):0",
                TestClassArguments = [],
                TestMethodArguments = [methodArg0, methodArg1, methodArg2, methodArg3],
                InternalTestClassArguments = [],
                InternalTestMethodArguments = [new TestData(methodArg0, typeof(global::System.String), InjectedDataType.None)
                {
                    DisposeAfterTest = false,
                }, new TestData(methodArg1, typeof(global::System.String), InjectedDataType.None)
                {
                    DisposeAfterTest = false,
                }, new TestData(methodArg2, typeof(global::System.Byte), InjectedDataType.None)
                {
                    DisposeAfterTest = false,
                }, new TestData(methodArg3, typeof(global::System.Byte?), InjectedDataType.None)
                {
                    DisposeAfterTest = false,
                }],
                CurrentRepeatAttempt = 0,
                RepeatLimit = 0,
                MethodInfo = methodInfo,
                ResettableClassFactory = resettableClassFactory,
                TestMethodFactory = (classInstance, cancellationToken) => AsyncConvert.Convert(() => classInstance.ANSIBackground(methodArg0, methodArg1, methodArg2, methodArg3)),
                TestExecutor = DefaultExecutor.Instance,
                ClassConstructor = null,
                ParallelLimit = null,
                DisplayName = $"ANSIBackground({methodArg0}, {methodArg1}, {methodArg2}, {methodArg3})",
                TestFilePath = @"D:\SharpMUSH\SharpMUSH.Tests\Functions\StringFunctionUnitTests.cs",
                TestLineNumber = 37,
                AttributeTypes = [ typeof(global::TUnit.Core.TestAttribute), typeof(global::TUnit.Core.ArgumentsAttribute) ],
            });
        }
        catch (global::System.Exception exception)
        {
            TestRegistrar.Failed($"ArgumentsAttribute:TDAI3:SharpMUSH.Tests.Functions.StringFunctionUnitTests.ANSIBackground:(System.String,System.String,System.Byte,System.Byte?):0", new FailedInitializationTest
            {
                TestId = $"ArgumentsAttribute:TDAI3:SharpMUSH.Tests.Functions.StringFunctionUnitTests.ANSIBackground:(System.String,System.String,System.Byte,System.Byte?):0",
                TestName = "ANSIBackground",
                DisplayName = "ANSIBackground(\"ansi(Y,yellow)\", \"yellow\", 43, )",
                TestFilePath = @"D:\SharpMUSH\SharpMUSH.Tests\Functions\StringFunctionUnitTests.cs",
                TestLineNumber = 37,
                Exception = exception,
            });
        }
    }
}

This originates from the following null values. I had to do this hacky kind of way, because it doesn't allow a 'params' argument for the last Method argument.

    [Test]
    [Arguments("ansi(R,red)", "red", (byte)41, null)]
    [Arguments("ansi(hR,red)", "red", (byte)1, (byte)41)]
    [Arguments("ansi(Y,yellow)", "yellow", (byte)43, null)]
    [Arguments("ansi(hY,yellow)", "yellow", (byte)1, (byte)43)]
    public async Task ANSIBackground(string str, string expectedText, byte expectedByte1, byte? expectedByte2)
    {
        Console.WriteLine("Testing: {0}", str);

        var expectedBytes = expectedByte2 == null 
            ? new byte[] { expectedByte1 }
            : new byte[] { expectedByte1, expectedByte2.Value };

        var parser = TestParser();
        var result = (await parser.FunctionParse(MModule.single(str)))?.Message!;

        var color = StringExtensions.ansiBytes(expectedBytes);
        var markup = MarkupString.MarkupImplementation.AnsiMarkup.Create(background: color);
        var markedUpString = A.markupSingle2(markup, A.single(expectedText));

        Log.Logger.Information("Result: {Result}{NewLine}Expected: {Expected}", result, Environment.NewLine, markedUpString);

        await Assert
            .That(Encoding.Unicode.GetBytes(result.ToString()))
            .IsEqualTo(Encoding.Unicode.GetBytes(markedUpString.ToString()));
    }
HarryCordewener commented 1 month ago
// <auto-generated/>
using global::TUnit.Core;
using global::TUnit.Engine;

namespace TUnit.Engine;

[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
file partial class Test_FunctionUnitTests
{
    [global::System.Runtime.CompilerServices.ModuleInitializer]
    public static void Initialise()
    {
        try
        {
            var methodInfo = typeof(global::SharpMUSH.Tests.Parser.FunctionUnitTests).GetMethod("Test", 0, [typeof(global::System.String), typeof(global::System.String)]);
            var resettableClassFactory = new ResettableLazy<global::SharpMUSH.Tests.Parser.FunctionUnitTests>(() => new global::SharpMUSH.Tests.Parser.FunctionUnitTests());

            global::System.String methodArg0 = "strcat(foo\,dog)"; // <--- This fails, due to an invalid escape sequence.
            global::System.String methodArg1 = "foo,dog";

            TestRegistrar.RegisterTest<global::SharpMUSH.Tests.Parser.FunctionUnitTests>(new TestMetadata<global::SharpMUSH.Tests.Parser.FunctionUnitTests>
            {
                TestId = $"ArgumentsAttribute:TDAI2:SharpMUSH.Tests.Parser.FunctionUnitTests.Test:(System.String,System.String):0",
                TestClassArguments = [],
                TestMethodArguments = [methodArg0, methodArg1],
                InternalTestClassArguments = [],
                InternalTestMethodArguments = [new TestData(methodArg0, typeof(global::System.String), InjectedDataType.None)
                {
                    DisposeAfterTest = false,
                }, new TestData(methodArg1, typeof(global::System.String), InjectedDataType.None)
                {
                    DisposeAfterTest = false,
                }],
                CurrentRepeatAttempt = 0,
                RepeatLimit = 0,
                MethodInfo = methodInfo,
                ResettableClassFactory = resettableClassFactory,
                TestMethodFactory = (classInstance, cancellationToken) => AsyncConvert.Convert(() => classInstance.Test(methodArg0, methodArg1)),
                TestExecutor = DefaultExecutor.Instance,
                ClassConstructor = null,
                ParallelLimit = null,
                DisplayName = $"Test({methodArg0}, {methodArg1})",
                TestFilePath = @"D:\SharpMUSH\SharpMUSH.Tests\Parser\FunctionUnitTests.cs",
                TestLineNumber = 5,
                AttributeTypes = [ typeof(global::TUnit.Core.TestAttribute), typeof(global::TUnit.Core.ArgumentsAttribute) ],
            });
        }
        catch (global::System.Exception exception)
        {
            TestRegistrar.Failed($"ArgumentsAttribute:TDAI2:SharpMUSH.Tests.Parser.FunctionUnitTests.Test:(System.String,System.String):0", new FailedInitializationTest
            {
                TestId = $"ArgumentsAttribute:TDAI2:SharpMUSH.Tests.Parser.FunctionUnitTests.Test:(System.String,System.String):0",
                TestName = "Test",
                DisplayName = "Test(\"strcat(foo\,dog)\", \"foo,dog\")",
                TestFilePath = @"D:\SharpMUSH\SharpMUSH.Tests\Parser\FunctionUnitTests.cs",
                TestLineNumber = 5,
                Exception = exception,
            });
        }
    }
}

This originates from here. You may be able to source-generate using @"string" string formats instead of a plain "string".

public class FunctionUnitTests : BaseUnitTest
{
    [Test]
    [Arguments("strcat(strcat(),wi`th a[strcat(strcat(strcat(depth of 5)))])","wi`th adepth of 5")]
    // [Arguments("strcat(strcat(dog)", "strcat(dog")] // Currently Illegal according to the Parser. Fix maybe needed.
    [Arguments("strcat(foo\\,dog)", "foo,dog")]
    [Arguments("strcat(foo\\\\,dog)", "foo\\dog")]
    [Arguments("strcat(foo,-dog))", "foo-dog)")]
    [Arguments("\\t", "t")]
    [Arguments("add(1,5)","6")]
    [Arguments("add(1,add(2,3),add(2,2))", "10")]
    [Arguments("add(1,2)[add(5,5)]", "310")]
    [Arguments("add(1,2)[add(5,5)]word()", "310word()")]
    public async Task Test(string str, string? expected = null)
    {
        Console.WriteLine("Testing: {0}", str);
        var parser = TestParser();
        var result = (await parser.FunctionParse(MModule.single(str)))?.Message?.ToString();

        Console.WriteLine(string.Join("", result));

        if (expected != null)
        {
            await Assert.That(result).IsEqualTo(expected);
        }
    }
}
thomhurst commented 1 month ago

// <------- this should not be empty

What's your test class/method look like?

HarryCordewener commented 1 month ago

// <------- this should not be empty

What's your test class/method look like?

Just added the origins of these.

thomhurst commented 1 month ago

// <------- this should not be empty

What's your test class/method look like?

Just added the origins of these.

Thanks! I'm a bit busy the next few days so might have to leave it with me but I'll try and reproduce and get a fix out. Thanks for the report

HarryCordewener commented 1 month ago

I'll see if I can figure out TUnit's source generation on my side while you are busy, and try to generate a Pull Review. But no guarantees.

https://github.com/HarryCordewener/TUnit/tree/ISSUE%23575-Failing-CodeGeneration

Edit: I am likely missing something obvious. Because changes to TypedConstantParser.cs and Arguments.cs's MapValue are not adjusting the code generation when I emit them into TUnit.TestProject.

thomhurst commented 1 month ago

@HarryCordewener can you try the latest version? I think I've fixed escaping strings. But I couldn't recreate the null byte issue?

HarryCordewener commented 1 month ago

Will do in a few hours, and I'll report back to you!

HarryCordewener commented 1 month ago

Failing to compile because of something unrelated to this:

6>TestPlatformEntryPoint.cs(10,66): Error CS8892 : Method 'TestingPlatformEntryPoint.Main(string[])' will not be used as an entry point because a synchronous entry point 'AutoGeneratedProgram.Main(string[])' was found.

Edit: That's because I have Warnings as Errors turned on. I'll have to exclude that Warning. Edit: Dotnet Rider is not finding the tests. And 'dotnet test' says tests ran successfully, but not how many ran etc.

thomhurst commented 1 month ago

Can you show your csproj? Something sounds misconfigured

HarryCordewener commented 1 month ago

Can you show your csproj? Something sounds misconfigured

I agree I likely have something misconfigured.

https://github.com/SharpMUSH/SharpMUSH/pull/52/files#diff-a433f2b8980b5b79569945af52210729fd08236ee9c0c83b189439589234cffd

thomhurst commented 1 month ago

Can you show your csproj? Something sounds misconfigured

I agree I likely have something misconfigured.

https://github.com/SharpMUSH/SharpMUSH/pull/52/files#diff-a433f2b8980b5b79569945af52210729fd08236ee9c0c83b189439589234cffd

Remove this:

    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />

That's attempting to use the older VSTest protocol I think

HarryCordewener commented 1 month ago

That did the trick. And the tests are running. Some fixing left to do on my end, and I'll get back to you again.

HarryCordewener commented 1 month ago

TUnit doesn't have a Collection Assert, and some other funkiness, so I had to translate:

await Assert
  .That(Encoding.Unicode.GetBytes(result.ToString()))
  .IsEqualTo(Encoding.Unicode.GetBytes(expected.ToString())); 

To:

foreach(var bt in Encoding.Unicode.GetBytes(result.ToString()).Zip(Encoding.Unicode.GetBytes(expected.ToString())))
{       
  await Assert
    .That(bt.First)
    .IsEqualTo(bt.Second); 
}
HarryCordewener commented 1 month ago

This looks like a bug, I can submit a new ticket for this.

https://github.com/SharpMUSH/SharpMUSH/pull/52/files#diff-24f2e7f893b0eb9eb90401e75855e7c1c8fdbaf249fbd0db12511e5a34de62e7

Debugger:

  roomZero.GetType()
  {SharpMUSH.Library.Models.SharpRoom}
    Assembly: {SharpMUSH.Library, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null}
    AssemblyQualifiedName: "SharpMUSH.Library.Models.SharpRoom, SharpMUSH.Library, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
    Attributes: Public | BeforeFieldInit
    BaseType: {System.Object}
    Cache: {System.RuntimeType.RuntimeTypeCache}
    CacheIfExists: {System.RuntimeType.RuntimeTypeCache}
    ContainsGenericParameters: false
    CustomAttributes: {Count = 3}
    DeclaredConstructors: {System.Reflection.ConstructorInfo[1]}
    DeclaredEvents: {System.Reflection.EventInfo[0]}
    DeclaredFields: {System.Reflection.FieldInfo[2]}
    DeclaredMembers: {System.Reflection.MemberInfo[9]}
    DeclaredMethods: {System.Reflection.MethodInfo[4]}
    DeclaredNestedTypes: {System.Reflection.TypeInfo.<get_DeclaredNestedTypes>d__22}
    DeclaredProperties: {System.Reflection.PropertyInfo[2]}
    DeclaringMethod: Exception of type 'System.InvalidOperationException' was thrown
    DeclaringType (System.Reflection.MemberInfo): null
    DeclaringType: null
    DomainInitialized: false
    FullName: "SharpMUSH.Library.Models.SharpRoom"
    GUID: {01ef0a02-e420-3fd8-8f7f-b0f64153fa1d}
    GenericCache: null
    GenericParameterAttributes: Exception of type 'System.InvalidOperationException' was thrown
    GenericParameterPosition: Exception of type 'System.InvalidOperationException' was thrown
    GenericTypeArguments: {System.Type[0]}
    GenericTypeParameters: {System.Type[0]}
    HasElementType: false
    ImplementedInterfaces: {System.Type[0]}
    IsAbstract: false
    IsActualEnum: false
    IsAnsiClass: true
    IsArray: false
    IsAutoClass: false
    IsAutoLayout: true
    IsByRef: false
    IsByRefLike: false
    IsCOMObject: false
    IsClass: true
    IsCollectible: false
    IsConstructedGenericType: false
    IsContextful: false
    IsEnum: false
    IsExplicitLayout: false
    IsFunctionPointer: false
    IsGenericMethodParameter: false
    IsGenericParameter: false
    IsGenericType: false
    IsGenericTypeDefinition: false
    IsGenericTypeParameter: false
    IsImport: false
    IsInterface: false
    IsLayoutSequential: false
    IsMarshalByRef: false
    IsNested: false
    IsNestedAssembly: false
    IsNestedFamANDAssem: false
    IsNestedFamORAssem: false
    IsNestedFamily: false
    IsNestedPrivate: false
    IsNestedPublic: false
    IsNotPublic: false
    IsNullableOfT: false
    IsPointer: false
    IsPrimitive: false
    IsPublic: true
    IsSZArray: false
    IsSealed: false
    IsSecurityCritical: true
    IsSecuritySafeCritical: false
    IsSecurityTransparent: false
    IsSerializable: false
    IsSignatureType: false
    IsSpecialName: false
    IsTypeDefinition: true
    IsUnicodeClass: false
    IsUnmanagedFunctionPointer: false
    IsValueType: false
    IsVariableBoundArray: false
    IsVisible: true
    MemberType (System.Reflection.MemberInfo): TypeInfo
    MemberType: TypeInfo
    MetadataToken: 33554483
    Module (System.Reflection.MemberInfo): {SharpMUSH.Library.dll}
    Module: {SharpMUSH.Library.dll}
    Name: "SharpRoom"
    Namespace: "SharpMUSH.Library.Models"
    ReflectedType (System.Reflection.MemberInfo): null
    ReflectedType: null
    StructLayoutAttribute: {System.Runtime.InteropServices.StructLayoutAttribute}
    TypeHandle: {System.RuntimeTypeHandle}
    TypeInitializer: null
    UnderlyingSystemType: {SharpMUSH.Library.Models.SharpRoom}
    m_cache: 0x20b5f8424c8
    m_handle: 0x7ffc6a2d5118
    m_keepalive: null

Test failure:

Assert.That(roomZero.GetType()).IsTypeOf(SharpRoom)
SharpMUSH.Library.Models.SharpRoom is RuntimeType instead of SharpRoom
   at TUnit.Assertions.AssertionBuilders.InvokableAssertionBuilder`3.ProcessAssertionsAsync()
   at SharpMUSH.Tests.Database.ArangoDBTests.TestRoomZero() in D:\SharpMUSH\SharpMUSH.Tests\Database\ArangoDBTests.cs:line 22
   at TUnit.Engine.AsyncConvert.Convert(Func`1 action)
   at TUnit.Core.DiscoveredTest`1.ExecuteTest(CancellationToken cancellationToken)
   at TUnit.Engine.Helpers.Timings.Record(String name, TestContext context, Func`1 action)
   at TUnit.Engine.Services.TestInvoker.Invoke(DiscoveredTest discoveredTest, CancellationToken cancellationToken)
   at TUnit.Engine.Services.SingleTestExecutor.ExecuteTestMethodWithTimeout(DiscoveredTest discoveredTest)
   at TUnit.Engine.Services.SingleTestExecutor.ExecuteCore(DiscoveredTest discoveredTest)
   at TUnit.Engine.Services.SingleTestExecutor.ExecuteWithRetries(DiscoveredTest discoveredTest)
   at TUnit.Engine.Services.SingleTestExecutor.ExecuteWithRetries(DiscoveredTest discoveredTest)
   at TUnit.Engine.Services.SingleTestExecutor.ExecuteTestInternalAsync(DiscoveredTest test, ITestExecutionFilter filter, ExecuteRequestContext context, Boolean isStartedAsDependencyForAnotherTest)
   at TUnit.Engine.Services.SingleTestExecutor.ExecuteTestInternalAsync(DiscoveredTest test, ITestExecutionFilter filter, ExecuteRequestContext context, Boolean isStartedAsDependencyForAnotherTest)
HarryCordewener commented 1 month ago

https://github.com/SharpMUSH/SharpMUSH/pull/52/files#diff-a8b4df71bd0856a13e2d9c9e8ff80f391a9c2e3b5070425e2f3cbf564ee46d12

The byte? compile failure is still here - see the commented out lines.

5>ANSI_StringFunctionUnitTests_65520b6a986c48d3a55f7703a95d17b9.Generated.cs(21,38): Error CS1525 : Invalid expression term ';'
5>ANSI_StringFunctionUnitTests_de9ab96c2fae44559ce3278fe19f7441.Generated.cs(21,38): Error CS1525 : Invalid expression term ';'
5>ANSI_StringFunctionUnitTests_7fdf0dfac0b9465e8a4cfeac5cf559f6.Generated.cs(21,38): Error CS1525 : Invalid expression term ';'
5>ANSI_StringFunctionUnitTests_e09918ab63a1490ab372e1f12709857a.Generated.cs(21,38): Error CS1525 : Invalid expression term ';'
thomhurst commented 1 month ago

Cheers for the repro. Can you raise a separate issue for the byte issue and I'll take a look tomorrow if I can!

thomhurst commented 1 month ago

This looks like a bug, I can submit a new ticket for this.

https://github.com/SharpMUSH/SharpMUSH/pull/52/files#diff-24f2e7f893b0eb9eb90401e75855e7c1c8fdbaf249fbd0db12511e5a34de62e7

Debugger:

  roomZero.GetType()
  {SharpMUSH.Library.Models.SharpRoom}
    Assembly: {SharpMUSH.Library, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null}
    AssemblyQualifiedName: "SharpMUSH.Library.Models.SharpRoom, SharpMUSH.Library, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
    Attributes: Public | BeforeFieldInit
    BaseType: {System.Object}
    Cache: {System.RuntimeType.RuntimeTypeCache}
    CacheIfExists: {System.RuntimeType.RuntimeTypeCache}
    ContainsGenericParameters: false
    CustomAttributes: {Count = 3}
    DeclaredConstructors: {System.Reflection.ConstructorInfo[1]}
    DeclaredEvents: {System.Reflection.EventInfo[0]}
    DeclaredFields: {System.Reflection.FieldInfo[2]}
    DeclaredMembers: {System.Reflection.MemberInfo[9]}
    DeclaredMethods: {System.Reflection.MethodInfo[4]}
    DeclaredNestedTypes: {System.Reflection.TypeInfo.<get_DeclaredNestedTypes>d__22}
    DeclaredProperties: {System.Reflection.PropertyInfo[2]}
    DeclaringMethod: Exception of type 'System.InvalidOperationException' was thrown
    DeclaringType (System.Reflection.MemberInfo): null
    DeclaringType: null
    DomainInitialized: false
    FullName: "SharpMUSH.Library.Models.SharpRoom"
    GUID: {01ef0a02-e420-3fd8-8f7f-b0f64153fa1d}
    GenericCache: null
    GenericParameterAttributes: Exception of type 'System.InvalidOperationException' was thrown
    GenericParameterPosition: Exception of type 'System.InvalidOperationException' was thrown
    GenericTypeArguments: {System.Type[0]}
    GenericTypeParameters: {System.Type[0]}
    HasElementType: false
    ImplementedInterfaces: {System.Type[0]}
    IsAbstract: false
    IsActualEnum: false
    IsAnsiClass: true
    IsArray: false
    IsAutoClass: false
    IsAutoLayout: true
    IsByRef: false
    IsByRefLike: false
    IsCOMObject: false
    IsClass: true
    IsCollectible: false
    IsConstructedGenericType: false
    IsContextful: false
    IsEnum: false
    IsExplicitLayout: false
    IsFunctionPointer: false
    IsGenericMethodParameter: false
    IsGenericParameter: false
    IsGenericType: false
    IsGenericTypeDefinition: false
    IsGenericTypeParameter: false
    IsImport: false
    IsInterface: false
    IsLayoutSequential: false
    IsMarshalByRef: false
    IsNested: false
    IsNestedAssembly: false
    IsNestedFamANDAssem: false
    IsNestedFamORAssem: false
    IsNestedFamily: false
    IsNestedPrivate: false
    IsNestedPublic: false
    IsNotPublic: false
    IsNullableOfT: false
    IsPointer: false
    IsPrimitive: false
    IsPublic: true
    IsSZArray: false
    IsSealed: false
    IsSecurityCritical: true
    IsSecuritySafeCritical: false
    IsSecurityTransparent: false
    IsSerializable: false
    IsSignatureType: false
    IsSpecialName: false
    IsTypeDefinition: true
    IsUnicodeClass: false
    IsUnmanagedFunctionPointer: false
    IsValueType: false
    IsVariableBoundArray: false
    IsVisible: true
    MemberType (System.Reflection.MemberInfo): TypeInfo
    MemberType: TypeInfo
    MetadataToken: 33554483
    Module (System.Reflection.MemberInfo): {SharpMUSH.Library.dll}
    Module: {SharpMUSH.Library.dll}
    Name: "SharpRoom"
    Namespace: "SharpMUSH.Library.Models"
    ReflectedType (System.Reflection.MemberInfo): null
    ReflectedType: null
    StructLayoutAttribute: {System.Runtime.InteropServices.StructLayoutAttribute}
    TypeHandle: {System.RuntimeTypeHandle}
    TypeInitializer: null
    UnderlyingSystemType: {SharpMUSH.Library.Models.SharpRoom}
    m_cache: 0x20b5f8424c8
    m_handle: 0x7ffc6a2d5118
    m_keepalive: null

Test failure:

Assert.That(roomZero.GetType()).IsTypeOf(SharpRoom)
SharpMUSH.Library.Models.SharpRoom is RuntimeType instead of SharpRoom
   at TUnit.Assertions.AssertionBuilders.InvokableAssertionBuilder`3.ProcessAssertionsAsync()
   at SharpMUSH.Tests.Database.ArangoDBTests.TestRoomZero() in D:\SharpMUSH\SharpMUSH.Tests\Database\ArangoDBTests.cs:line 22
   at TUnit.Engine.AsyncConvert.Convert(Func`1 action)
   at TUnit.Core.DiscoveredTest`1.ExecuteTest(CancellationToken cancellationToken)
   at TUnit.Engine.Helpers.Timings.Record(String name, TestContext context, Func`1 action)
   at TUnit.Engine.Services.TestInvoker.Invoke(DiscoveredTest discoveredTest, CancellationToken cancellationToken)
   at TUnit.Engine.Services.SingleTestExecutor.ExecuteTestMethodWithTimeout(DiscoveredTest discoveredTest)
   at TUnit.Engine.Services.SingleTestExecutor.ExecuteCore(DiscoveredTest discoveredTest)
   at TUnit.Engine.Services.SingleTestExecutor.ExecuteWithRetries(DiscoveredTest discoveredTest)
   at TUnit.Engine.Services.SingleTestExecutor.ExecuteWithRetries(DiscoveredTest discoveredTest)
   at TUnit.Engine.Services.SingleTestExecutor.ExecuteTestInternalAsync(DiscoveredTest test, ITestExecutionFilter filter, ExecuteRequestContext context, Boolean isStartedAsDependencyForAnotherTest)
   at TUnit.Engine.Services.SingleTestExecutor.ExecuteTestInternalAsync(DiscoveredTest test, ITestExecutionFilter filter, ExecuteRequestContext context, Boolean isStartedAsDependencyForAnotherTest)

Remove the .GetType() call. You just wanna call IsTypeOf on the object itself.

HarryCordewener commented 1 month ago

Something something - RTFM, me. That fixed that one!

HarryCordewener commented 1 month ago

Issue #615 created.