Testing Issue

I've followed the basic instructions in the Documentation for testing Aspects (https://doc.metalama.net/conceptual/aspects/testing/aspect-testing) Starting off with something simple to hopefully make it easier. However I'm getting an Asert.Equal() failure. Could the fact that CodeRush can automatically add regions to code when it is saved be the cause of this?
7 Replies
domsinclair
domsinclairOP2y ago
It turned out to be a small almost imperceptible formatting issue, each line was out by 1 character position.
Gael Fraiteur
Gael Fraiteur2y ago
Ok
domsinclair
domsinclairOP2y ago
Ah different issue now which to be frank I don't understand. I created a new test .In the Transformed code that appears in the Transformed section of the obj folder I see the following;
c#
// Error CS1620 on `"Entering MethodTest.MyTestMethod"`: `Argument 2 must be passed with the 'ref' keyword`
// Error CS1620 on `"Leaving MethodTest.MyTestMethod."`: `Argument 2 must be passed with the 'ref' keyword`
namespace VtlSoftware.Logging.Tests
{
internal class MethodTest
{
[LogMethod]
public void MyTestMethod()
{
c#
// Error CS1620 on `"Entering MethodTest.MyTestMethod"`: `Argument 2 must be passed with the 'ref' keyword`
// Error CS1620 on `"Leaving MethodTest.MyTestMethod."`: `Argument 2 must be passed with the 'ref' keyword`
namespace VtlSoftware.Logging.Tests
{
internal class MethodTest
{
[LogMethod]
public void MyTestMethod()
{
What is it trying to tell me? I don't see that if I do a standard Show metalama diffs on the method itself. Ok forgive my ignorance here. I'm getting this error message; Error LAMA0612 The most likely cause of the compilation failure is a bug in an aspect. To diagnose the issue, build the project with the option '-p:MetalamaDebugTransformedCode=True' and inspect the transformed files in 'obj/Debug/.../metalama'. VtlSoftware.LoggingConsoleApp D:\source\repos\VtlSoftware.LoggingWithStringHandler\VtlSoftware.LoggingConsoleApp\CSC 1 The message I understand, what I don't is how to actually build said project with the relevant option.
Gael Fraiteur
Gael Fraiteur2y ago
Do dotnet build '-p:MetalamaDebugTransformedCode=True from the command line for instance.
domsinclair
domsinclairOP2y ago
Well I'm well and truly at a loss with this. I'm building out a series of tests to test various possibilities that my logging aspect might encounter.
If I create methods with params and return values to log the test passes, but if it's just a void method it fails. The issue I'm facing is that I would expect the reason being given for failure to be equally applicable to a method with params and yet its not. I suspect that this is my own fault but at the same time I can't account for the discrepancy.
Gael Fraiteur
Gael Fraiteur2y ago
You should do dotnet build -p:MetalamaDebugTransformedCode=True, then the error messages will point to transformed files. You see how these files were transformed by your aspect or by Metalama, and look for the cause of the error from there. Ok I got it. You need to add this method:
public static void Log(
this ILogger logger,
LogLevel logLevel,
string message)
{
if (logger.IsEnabled(logLevel))
{
logger.Log(logLevel, message);
}
}
public static void Log(
this ILogger logger,
LogLevel logLevel,
string message)
{
if (logger.IsEnabled(logLevel))
{
logger.Log(logLevel, message);
}
}
it's because you're sending a string literal and not an interpolated string.
domsinclair
domsinclairOP2y ago
That makes perfect sense, Thanks.
Want results from more Discord servers?
Add your server