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
domsinclair13mo ago
It turned out to be a small almost imperceptible formatting issue, each line was out by 1 character position.
Gael Fraiteur
Gael Fraiteur13mo ago
Ok
domsinclair
domsinclair13mo 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 Fraiteur13mo ago
Do dotnet build '-p:MetalamaDebugTransformedCode=True from the command line for instance.
domsinclair
domsinclair13mo 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 Fraiteur13mo 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
domsinclair13mo ago
That makes perfect sense, Thanks.
Want results from more Discord servers?
Add your server
More Posts
Has anyone tried the Ctrl + . refactor menu recently?According to the documentation Invoking Ctrl + . to pull up the refactor menu should (if they are avIs it possible to mix aspects that call different parts of a class (ie Methods and Properties)?Pretty much as per the subject line. Consider the following scenario where one has aspects to log mIs this section of the documentation wrong?I'm looking at the following topic (https://doc.metalama.net/conceptual/using/fabrics/adding-aspectsWhy is it indicating I have compile-time code despite not?See the screenshot - Is there some way to decorate this to make clear that nothing in the class contHow do I invoke (and cast) an introduced generically typed field?Bear with me - there's a lot going on here. Also Discord is funky about styling my code, so I'm handIntegration with VS to display introduced elements in partial classesI can use compile-time generated elements from my run-time code by marking a class as partial, but IInterpolatedStringHandlerI'm experimenting with the InterpolatedStringHandler. The idea, in simple terms is to do away with How might I list the properties of a generic type within an aspect?I want to translate the properties of a generic type constraint of the base type implemented by my tIs there a new Vsix?As it's not possible to add a comment in the releases section I've had to add this here. AccordinLive re-application and diff view updates of aspects on saveIt's awfully convenient to enable Continuous Testing in Visual Studio. I turn it on and every time I