From 21a9b8398a04aa13098e2c7424cfaf88c1714079 Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Thu, 15 Aug 2024 10:52:19 +0300 Subject: [PATCH 1/4] test: Adjust Given_DependencyObjectGenerator --- .../Given_DependencyObjectGenerator.cs | 70 ++++++++++++++++--- 1 file changed, 61 insertions(+), 9 deletions(-) diff --git a/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/DependencyObjectGeneratorTests/Given_DependencyObjectGenerator.cs b/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/DependencyObjectGeneratorTests/Given_DependencyObjectGenerator.cs index 3fa7d8a122fe..61dd269cac5d 100644 --- a/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/DependencyObjectGeneratorTests/Given_DependencyObjectGenerator.cs +++ b/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/DependencyObjectGeneratorTests/Given_DependencyObjectGenerator.cs @@ -1,5 +1,7 @@ using System.Collections.Immutable; using System.Text; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.CSharp.Testing; using Microsoft.CodeAnalysis.Testing; using Microsoft.CodeAnalysis.Testing.Verifiers; @@ -14,9 +16,54 @@ namespace Uno.UI.SourceGenerators.Tests.DependencyObjectGeneratorTests; [TestClass] public class Given_DependencyObjectGenerator { - private static readonly ImmutableArray _unoPackage = ImmutableArray.Create(new PackageIdentity("Uno.WinUI", "5.0.118")); - private static readonly ReferenceAssemblies _Net70AndroidWithUno = ReferenceAssemblies.Net.Net80Android.AddPackages(_unoPackage); - private static readonly ReferenceAssemblies _Net70WithUno = ReferenceAssemblies.Net.Net80.AddPackages(_unoPackage); + private static readonly ReferenceAssemblies _net80Android = ReferenceAssemblies.Net.Net80Android; + private static readonly ReferenceAssemblies _net80 = ReferenceAssemblies.Net.Net80; + + private static MetadataReference[] BuildUnoReferences(bool isAndroid) + { + const string configuration = +#if DEBUG + "Debug"; +#else + "Release"; +#endif + string[] availableTargets; + if (isAndroid) + { + availableTargets = [Path.Combine("Uno.UI.netcoremobile", configuration, "net8.0")]; + } + else + { + availableTargets = [ + Path.Combine("Uno.UI.Skia", configuration, "net8.0"), + Path.Combine("Uno.UI.Reference", configuration, "net8.0"), + Path.Combine("Uno.UI.Tests", configuration, "net8.0"), + ]; + } + + var unoUIBase = Path.Combine( + Path.GetDirectoryName(typeof(Given_DependencyObjectGenerator).Assembly.Location)!, + "..", + "..", + "..", + "..", + "..", + "Uno.UI", + "bin" + ); + var unoTarget = availableTargets + .Select(t => Path.Combine(unoUIBase, t, "Uno.UI.dll")) + .FirstOrDefault(File.Exists); + if (unoTarget is null) + { + throw new InvalidOperationException($"Unable to find Uno.UI.dll in {string.Join(",", availableTargets)}"); + } + + return Directory.GetFiles(Path.GetDirectoryName(unoTarget)!, "*.dll") + .Select(f => MetadataReference.CreateFromFile(Path.GetFullPath(f))) + .ToArray(); + } + private async Task TestAndroid(string testCode, params DiagnosticResult[] expectedDiagnostics) { @@ -26,8 +73,10 @@ private async Task TestAndroid(string testCode, params DiagnosticResult[] expect { Sources = { testCode }, }, - ReferenceAssemblies = _Net70AndroidWithUno, + ReferenceAssemblies = _net80, }; + + test.TestState.AdditionalReferences.AddRange(BuildUnoReferences(isAndroid: true)); test.ExpectedDiagnostics.AddRange(expectedDiagnostics); await test.RunAsync(); } @@ -65,7 +114,7 @@ public void UnregisterPropertyChangedCallback(DependencyProperty dp, long token) [TestMethod] public async Task TestNested() { - var test = """ + var testCode = """ using Windows.UI.Core; using Microsoft.UI.Xaml; @@ -77,11 +126,11 @@ internal partial class Inner : DependencyObject } """; - await new Verify.Test + var test = new Verify.Test { TestState = { - Sources = { test }, + Sources = { testCode }, GeneratedSources = { { (@"Uno.UI.SourceGenerators\Uno.UI.SourceGenerators.DependencyObject.DependencyObjectGenerator\OuterClass.Inner.cs", SourceText.From(""" @@ -292,7 +341,10 @@ public void SuspendBindings() => """, Encoding.UTF8)) } } }, - ReferenceAssemblies = _Net70WithUno, - }.RunAsync(); + ReferenceAssemblies = _net80, + }; + + test.TestState.AdditionalReferences.AddRange(BuildUnoReferences(isAndroid: false)); + await test.RunAsync(); } } From 78386bb73eabcb3256c59564869f099640a5a0c1 Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Thu, 15 Aug 2024 19:12:42 +0300 Subject: [PATCH 2/4] chore: Adjust --- build/ci/.azure-devops-unit-tests.yml | 7 +++++++ .../Given_DependencyObjectGenerator.cs | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/build/ci/.azure-devops-unit-tests.yml b/build/ci/.azure-devops-unit-tests.yml index d5a870d3669c..d25f806ac0d7 100644 --- a/build/ci/.azure-devops-unit-tests.yml +++ b/build/ci/.azure-devops-unit-tests.yml @@ -61,6 +61,13 @@ jobs: artifactName: 'NugetPackages-Artifacts-reference-$(XAML_FLAVOR_BUILD)' downloadPath: '$(Agent.WorkFolder)' + # Unfortunate, but this is needed specifically for a single test: TestAndroidViewImplementingDependencyObject + - task: DownloadBuildArtifacts@0 + displayName: Download build artifact + inputs: + artifactName: 'NugetPackages-Artifacts-netcoremobile-$(XAML_FLAVOR_BUILD)' + downloadPath: '$(Agent.WorkFolder)' + - task: ExtractFiles@1 displayName: Restore binaries structure inputs: diff --git a/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/DependencyObjectGeneratorTests/Given_DependencyObjectGenerator.cs b/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/DependencyObjectGeneratorTests/Given_DependencyObjectGenerator.cs index 61dd269cac5d..6784fdef57c0 100644 --- a/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/DependencyObjectGeneratorTests/Given_DependencyObjectGenerator.cs +++ b/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/DependencyObjectGeneratorTests/Given_DependencyObjectGenerator.cs @@ -16,8 +16,8 @@ namespace Uno.UI.SourceGenerators.Tests.DependencyObjectGeneratorTests; [TestClass] public class Given_DependencyObjectGenerator { - private static readonly ReferenceAssemblies _net80Android = ReferenceAssemblies.Net.Net80Android; - private static readonly ReferenceAssemblies _net80 = ReferenceAssemblies.Net.Net80; + private static readonly ReferenceAssemblies _net80Android = ReferenceAssemblies.Net.Net80Android.AddPackages([new PackageIdentity("Uno.Diagnostics.Eventing", "2.1.0")]); + private static readonly ReferenceAssemblies _net80 = ReferenceAssemblies.Net.Net80.AddPackages([new PackageIdentity("Uno.Diagnostics.Eventing", "2.1.0")]); private static MetadataReference[] BuildUnoReferences(bool isAndroid) { From af114c07d8b20596c2ccb79e5aeefee2584cfc2e Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Fri, 16 Aug 2024 11:18:50 +0300 Subject: [PATCH 3/4] chore: Adjust --- .../Given_DependencyObjectGenerator.cs | 31 +++++++++---------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/DependencyObjectGeneratorTests/Given_DependencyObjectGenerator.cs b/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/DependencyObjectGeneratorTests/Given_DependencyObjectGenerator.cs index 6784fdef57c0..94c8eeb77fab 100644 --- a/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/DependencyObjectGeneratorTests/Given_DependencyObjectGenerator.cs +++ b/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/DependencyObjectGeneratorTests/Given_DependencyObjectGenerator.cs @@ -19,27 +19,24 @@ public class Given_DependencyObjectGenerator private static readonly ReferenceAssemblies _net80Android = ReferenceAssemblies.Net.Net80Android.AddPackages([new PackageIdentity("Uno.Diagnostics.Eventing", "2.1.0")]); private static readonly ReferenceAssemblies _net80 = ReferenceAssemblies.Net.Net80.AddPackages([new PackageIdentity("Uno.Diagnostics.Eventing", "2.1.0")]); - private static MetadataReference[] BuildUnoReferences(bool isAndroid) - { - const string configuration = + private const string Configuration = #if DEBUG - "Debug"; + "Debug"; #else - "Release"; + "Release"; #endif - string[] availableTargets; - if (isAndroid) - { - availableTargets = [Path.Combine("Uno.UI.netcoremobile", configuration, "net8.0")]; - } - else - { - availableTargets = [ - Path.Combine("Uno.UI.Skia", configuration, "net8.0"), - Path.Combine("Uno.UI.Reference", configuration, "net8.0"), - Path.Combine("Uno.UI.Tests", configuration, "net8.0"), + + private const string TFM = "net8.0"; + + private static MetadataReference[] BuildUnoReferences(bool isAndroid) + { + string[] availableTargets = isAndroid + ? [Path.Combine("Uno.UI.netcoremobile", Configuration, $"{TFM}-android")] + : [ + Path.Combine("Uno.UI.Skia", Configuration, TFM), + Path.Combine("Uno.UI.Reference", Configuration, TFM), + Path.Combine("Uno.UI.Tests", Configuration, TFM), ]; - } var unoUIBase = Path.Combine( Path.GetDirectoryName(typeof(Given_DependencyObjectGenerator).Assembly.Location)!, From 5db867697826ea97f17050c2520bfff99ca35d61 Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Fri, 16 Aug 2024 12:35:23 +0300 Subject: [PATCH 4/4] chore: Small fix --- .../Given_DependencyObjectGenerator.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/DependencyObjectGeneratorTests/Given_DependencyObjectGenerator.cs b/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/DependencyObjectGeneratorTests/Given_DependencyObjectGenerator.cs index 94c8eeb77fab..50d5372af071 100644 --- a/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/DependencyObjectGeneratorTests/Given_DependencyObjectGenerator.cs +++ b/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/DependencyObjectGeneratorTests/Given_DependencyObjectGenerator.cs @@ -70,7 +70,7 @@ private async Task TestAndroid(string testCode, params DiagnosticResult[] expect { Sources = { testCode }, }, - ReferenceAssemblies = _net80, + ReferenceAssemblies = _net80Android, }; test.TestState.AdditionalReferences.AddRange(BuildUnoReferences(isAndroid: true));