Skip to content

Commit 847c5fe

Browse files
authored
[tests] Enable more tests to run on all 3 runtimes, part 13 (#10635)
This primarily refactors and improves test utility methods and logging for better maintainability and clarity. The most important changes include refactoring how MSBuild warnings are asserted in tests, improving debug logging in marshal method generation, and making test timeouts more maintainable by using a constant. **Test utilities and assertion improvements:** * Refactored `AssertHasNoWarnings` and `AssertHasSomeWarnings` methods in `AssertionExtensions.cs` to reduce duplication and centralize the logic for asserting the number of MSBuild warnings. Now, both methods delegate to a shared implementation, improving maintainability. * Added a missing `using System.Collections.Generic;` directive in `AssertionExtensions.cs` to support the refactored methods. **Logging improvements:** * Enhanced debug logging in `MarshalMethodsNativeAssemblyGenerator.cs` to include the native symbol name when generating marshal methods, providing more context for debugging. **Test timeout maintainability:** * Updated hardcoded activity start timeouts in `MonoAndroidExportTest.cs` to use the shared constant `InstallAndRunTests.ActivityStartTimeoutInSeconds`, improving consistency and ease of configuration.
1 parent 0a5601a commit 847c5fe

File tree

4 files changed

+452
-119
lines changed

4 files changed

+452
-119
lines changed

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/AssertionExtensions.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Collections.Generic;
12
using System.Diagnostics;
23
using System.IO;
34
using System.Linq;
@@ -130,19 +131,30 @@ public static void AssertEntryContents (this ZipArchive zip, string zipPath, str
130131
[DebuggerHidden]
131132
public static void AssertHasNoWarnings (this ProjectBuilder builder)
132133
{
133-
Assert.IsTrue (StringAssertEx.ContainsText (builder.LastBuildOutput, " 0 Warning(s)"), $"{builder.BuildLogFile} should have no MSBuild warnings.");
134+
AssertHasSomeWarnings (builder.LastBuildOutput, 0, builder.BuildLogFile);
135+
}
136+
137+
[DebuggerHidden]
138+
public static void AssertHasSomeWarnings (this ProjectBuilder builder, uint numOfExpectedWarnings)
139+
{
140+
AssertHasSomeWarnings (builder.LastBuildOutput, numOfExpectedWarnings, builder.BuildLogFile);
134141
}
135142

136143
[DebuggerHidden]
137144
public static void AssertHasNoWarnings (this DotNetCLI dotnet)
138145
{
139-
Assert.IsTrue (StringAssertEx.ContainsText (dotnet.LastBuildOutput, " 0 Warning(s)"), $"{dotnet.BuildLogFile} should have no MSBuild warnings.");
146+
AssertHasSomeWarnings (dotnet.LastBuildOutput, 0, dotnet.BuildLogFile);
140147
}
141148

142149
[DebuggerHidden]
143150
public static void AssertHasSomeWarnings (this DotNetCLI dotnet, uint numOfExpectedWarnings)
144151
{
145-
Assert.IsTrue (StringAssertEx.ContainsText (dotnet.LastBuildOutput, $" {numOfExpectedWarnings} Warning(s)"), $"{dotnet.BuildLogFile} should have {numOfExpectedWarnings} MSBuild warnings.");
152+
AssertHasSomeWarnings (dotnet.LastBuildOutput, numOfExpectedWarnings, dotnet.BuildLogFile);
153+
}
154+
155+
static void AssertHasSomeWarnings (IEnumerable<string> lastBuildOutput, uint numOfExpectedWarnings, string logFile)
156+
{
157+
Assert.IsTrue (StringAssertEx.ContainsText (lastBuildOutput, $" {numOfExpectedWarnings} Warning(s)"), $"{logFile} should have {numOfExpectedWarnings} MSBuild warnings.");
146158
}
147159
}
148160
}

src/Xamarin.Android.Build.Tasks/Utilities/MarshalMethodsNativeAssemblyGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ void AddMarshalMethods (LlvmIrModule module, AssemblyCacheState acs, LlvmIrVaria
643643

644644
void AddMarshalMethod (LlvmIrModule module, MarshalMethodInfo method, ulong asmId, MarshalMethodsWriteState writeState)
645645
{
646-
Log.LogDebugMessage ($"MM: generating code for {method.Method.DeclaringType.FullName} {method.Method.NativeCallback.FullName}");
646+
Log.LogDebugMessage ($"MM: generating code for {method.Method.DeclaringType.FullName} (native cb: '{method.Method.NativeCallback.FullName}'; native symbol name: '{method.NativeSymbolName}')");
647647
MarshalMethodEntryMethodObject nativeCallback = method.Method.NativeCallback;
648648
string backingFieldName = $"native_cb_{method.Method.JniMethodName}_{asmId}_{method.ClassCacheIndex}_{nativeCallback.MetadataToken:x}";
649649

0 commit comments

Comments
 (0)