From 53e41eac60dc57c5b130ad3731d663ad434628c5 Mon Sep 17 00:00:00 2001 From: James Crosswell Date: Wed, 25 Sep 2024 14:47:54 +1200 Subject: [PATCH 1/7] Builds --- .generated.NoMobile.sln | 28 +- Sentry-CI-Build-macOS.slnf | 1 + Sentry.sln | 28 +- SentryMobile.slnf | 3 - nuget.config | 6 + scripts/generate-solution-filters-config.yaml | 2 - .../AnalyzerReleases.Shipped.md | 0 .../AnalyzerReleases.Unshipped.md | 5 - .../CodeBehindGenerator.cs | 27 -- .../GeneratorDiagnostics.cs | 19 - .../RunnerGenerator.cs | 223 ---------- ...Utils.DeviceTests.Runners.SourceGen.csproj | 21 - .../AppHostBuilderExtensions.cs | 41 -- .../DeviceTests.Runners/Assets/credits.html | 16 - .../Android/HeadlessTestRunner.cs | 93 ---- .../Android/MauiTestActivity.cs | 37 -- .../Android/MauiTestInstrumentation.cs | 148 ------- .../HeadlessRunner/TestDevice.cs | 25 -- .../HeadlessRunner/iOS/HeadlessTestRunner.cs | 68 --- .../iOS/MauiTestApplicationDelegate.cs | 123 ------ .../iOS/MauiTestViewController.cs | 32 -- .../HeadlessRunnerOptions.cs | 9 - .../DeviceTests.Runners/TestDispatcher.cs | 40 -- .../DeviceTests.Runners/TestOptions.cs | 19 - .../DeviceTests.Runners/TestServices.cs | 32 -- .../TestUtils.DeviceTests.Runners.csproj | 39 -- .../DeviceTests.Runners/TestWindow.cs | 49 -- .../VisualRunner/AssemblyRunInfo.cs | 22 - .../Converters/RunStatusToColorConverter.cs | 29 -- .../VisualRunner/DeviceRunner.cs | 345 --------------- .../VisualRunner/ITestListener.cs | 7 - .../VisualRunner/ITestRunner.cs | 19 - .../VisualRunner/MauiVisualRunnerApp.xaml | 18 - .../VisualRunner/MauiVisualRunnerApp.xaml.cs | 37 -- .../VisualRunner/Navigation/INavigation.cs | 9 - .../VisualRunner/Navigation/Navigator.cs | 33 -- .../VisualRunner/Navigation/PageType.cs | 11 - .../VisualRunner/Pages/CreditsPage.xaml | 9 - .../VisualRunner/Pages/CreditsPage.xaml.cs | 20 - .../VisualRunner/Pages/HomePage.xaml | 66 --- .../VisualRunner/Pages/HomePage.xaml.cs | 22 - .../VisualRunner/Pages/TestAssemblyPage.xaml | 64 --- .../Pages/TestAssemblyPage.xaml.cs | 22 - .../VisualRunner/Pages/TestResultPage.xaml | 25 -- .../VisualRunner/Pages/TestResultPage.xaml.cs | 12 - .../VisualRunner/Sinks/DeviceExecutionSink.cs | 81 ---- .../Sinks/DiagnosticMessageSink.cs | 30 -- .../VisualRunner/Utils/AsyncLock.cs | 52 --- .../Utils/FilteredCollectionView.cs | 295 ------------- .../VisualRunner/Utils/SortedList.cs | 101 ----- .../VisualRunner/Utils/TestRunLogger.cs | 97 ---- .../VisualRunner/ViewModels/HomeViewModel.cs | 114 ----- .../VisualRunner/ViewModels/RunStatus.cs | 10 - .../ViewModels/TestAssemblyViewModel.cs | 333 -------------- .../ViewModels/TestCaseViewModel.cs | 104 ----- .../ViewModels/TestResultViewModel.cs | 47 -- .../VisualRunner/ViewModels/TestState.cs | 10 - .../VisualRunner/ViewModels/ViewModelBase.cs | 34 -- .../XamlExtensions/EmbeddedHtmlExtension.cs | 20 - .../EmbeddedResourceExtension.cs | 29 -- .../AssertionExtensions.Android.cs | 319 -------------- .../AssertionExtensions.Windows.cs | 290 ------------ .../DeviceTests/AssertionExtensions.cs | 45 -- .../DeviceTests/AssertionExtensions.iOS.cs | 417 ------------------ .../DeviceTests/ColorComparison.Android.cs | 18 - .../DeviceTests/ColorComparison.Windows.cs | 18 - .../DeviceTests/ColorComparison.iOS.cs | 35 -- .../DeviceTests/RepeatAttribute.cs | 30 -- .../DeviceTests/TestUtils.DeviceTests.csproj | 25 -- .../DeviceTests/UINSWindow.iOS.cs | 107 ----- .../DeviceTests/xUnitCustomizations.cs | 191 -------- .../Directory.Build.props | 2 - .../Platforms/Android/MainActivity.cs | 11 + .../Platforms/Android/MainApplication.cs | 15 + .../Platforms/iOS/AppDelegate.cs | 9 + .../Platforms/iOS/Program.cs | 15 + .../Properties/launchSettings.json | 5 +- .../Sentry.Maui.Device.TestApp.csproj | 18 +- test/Sentry.Maui.Device.TestApp/Startup.cs | 21 +- 79 files changed, 80 insertions(+), 4772 deletions(-) delete mode 100644 test/MauiTestUtils/DeviceTests.Runners.SourceGen/AnalyzerReleases.Shipped.md delete mode 100644 test/MauiTestUtils/DeviceTests.Runners.SourceGen/AnalyzerReleases.Unshipped.md delete mode 100644 test/MauiTestUtils/DeviceTests.Runners.SourceGen/CodeBehindGenerator.cs delete mode 100644 test/MauiTestUtils/DeviceTests.Runners.SourceGen/GeneratorDiagnostics.cs delete mode 100644 test/MauiTestUtils/DeviceTests.Runners.SourceGen/RunnerGenerator.cs delete mode 100644 test/MauiTestUtils/DeviceTests.Runners.SourceGen/TestUtils.DeviceTests.Runners.SourceGen.csproj delete mode 100644 test/MauiTestUtils/DeviceTests.Runners/AppHostBuilderExtensions.cs delete mode 100644 test/MauiTestUtils/DeviceTests.Runners/Assets/credits.html delete mode 100644 test/MauiTestUtils/DeviceTests.Runners/HeadlessRunner/Android/HeadlessTestRunner.cs delete mode 100644 test/MauiTestUtils/DeviceTests.Runners/HeadlessRunner/Android/MauiTestActivity.cs delete mode 100644 test/MauiTestUtils/DeviceTests.Runners/HeadlessRunner/Android/MauiTestInstrumentation.cs delete mode 100644 test/MauiTestUtils/DeviceTests.Runners/HeadlessRunner/TestDevice.cs delete mode 100644 test/MauiTestUtils/DeviceTests.Runners/HeadlessRunner/iOS/HeadlessTestRunner.cs delete mode 100644 test/MauiTestUtils/DeviceTests.Runners/HeadlessRunner/iOS/MauiTestApplicationDelegate.cs delete mode 100644 test/MauiTestUtils/DeviceTests.Runners/HeadlessRunner/iOS/MauiTestViewController.cs delete mode 100644 test/MauiTestUtils/DeviceTests.Runners/HeadlessRunnerOptions.cs delete mode 100644 test/MauiTestUtils/DeviceTests.Runners/TestDispatcher.cs delete mode 100644 test/MauiTestUtils/DeviceTests.Runners/TestOptions.cs delete mode 100644 test/MauiTestUtils/DeviceTests.Runners/TestServices.cs delete mode 100644 test/MauiTestUtils/DeviceTests.Runners/TestUtils.DeviceTests.Runners.csproj delete mode 100644 test/MauiTestUtils/DeviceTests.Runners/TestWindow.cs delete mode 100644 test/MauiTestUtils/DeviceTests.Runners/VisualRunner/AssemblyRunInfo.cs delete mode 100644 test/MauiTestUtils/DeviceTests.Runners/VisualRunner/Converters/RunStatusToColorConverter.cs delete mode 100644 test/MauiTestUtils/DeviceTests.Runners/VisualRunner/DeviceRunner.cs delete mode 100644 test/MauiTestUtils/DeviceTests.Runners/VisualRunner/ITestListener.cs delete mode 100644 test/MauiTestUtils/DeviceTests.Runners/VisualRunner/ITestRunner.cs delete mode 100644 test/MauiTestUtils/DeviceTests.Runners/VisualRunner/MauiVisualRunnerApp.xaml delete mode 100644 test/MauiTestUtils/DeviceTests.Runners/VisualRunner/MauiVisualRunnerApp.xaml.cs delete mode 100644 test/MauiTestUtils/DeviceTests.Runners/VisualRunner/Navigation/INavigation.cs delete mode 100644 test/MauiTestUtils/DeviceTests.Runners/VisualRunner/Navigation/Navigator.cs delete mode 100644 test/MauiTestUtils/DeviceTests.Runners/VisualRunner/Navigation/PageType.cs delete mode 100644 test/MauiTestUtils/DeviceTests.Runners/VisualRunner/Pages/CreditsPage.xaml delete mode 100644 test/MauiTestUtils/DeviceTests.Runners/VisualRunner/Pages/CreditsPage.xaml.cs delete mode 100644 test/MauiTestUtils/DeviceTests.Runners/VisualRunner/Pages/HomePage.xaml delete mode 100644 test/MauiTestUtils/DeviceTests.Runners/VisualRunner/Pages/HomePage.xaml.cs delete mode 100644 test/MauiTestUtils/DeviceTests.Runners/VisualRunner/Pages/TestAssemblyPage.xaml delete mode 100644 test/MauiTestUtils/DeviceTests.Runners/VisualRunner/Pages/TestAssemblyPage.xaml.cs delete mode 100644 test/MauiTestUtils/DeviceTests.Runners/VisualRunner/Pages/TestResultPage.xaml delete mode 100644 test/MauiTestUtils/DeviceTests.Runners/VisualRunner/Pages/TestResultPage.xaml.cs delete mode 100644 test/MauiTestUtils/DeviceTests.Runners/VisualRunner/Sinks/DeviceExecutionSink.cs delete mode 100644 test/MauiTestUtils/DeviceTests.Runners/VisualRunner/Sinks/DiagnosticMessageSink.cs delete mode 100644 test/MauiTestUtils/DeviceTests.Runners/VisualRunner/Utils/AsyncLock.cs delete mode 100644 test/MauiTestUtils/DeviceTests.Runners/VisualRunner/Utils/FilteredCollectionView.cs delete mode 100644 test/MauiTestUtils/DeviceTests.Runners/VisualRunner/Utils/SortedList.cs delete mode 100644 test/MauiTestUtils/DeviceTests.Runners/VisualRunner/Utils/TestRunLogger.cs delete mode 100644 test/MauiTestUtils/DeviceTests.Runners/VisualRunner/ViewModels/HomeViewModel.cs delete mode 100644 test/MauiTestUtils/DeviceTests.Runners/VisualRunner/ViewModels/RunStatus.cs delete mode 100644 test/MauiTestUtils/DeviceTests.Runners/VisualRunner/ViewModels/TestAssemblyViewModel.cs delete mode 100644 test/MauiTestUtils/DeviceTests.Runners/VisualRunner/ViewModels/TestCaseViewModel.cs delete mode 100644 test/MauiTestUtils/DeviceTests.Runners/VisualRunner/ViewModels/TestResultViewModel.cs delete mode 100644 test/MauiTestUtils/DeviceTests.Runners/VisualRunner/ViewModels/TestState.cs delete mode 100644 test/MauiTestUtils/DeviceTests.Runners/VisualRunner/ViewModels/ViewModelBase.cs delete mode 100644 test/MauiTestUtils/DeviceTests.Runners/VisualRunner/XamlExtensions/EmbeddedHtmlExtension.cs delete mode 100644 test/MauiTestUtils/DeviceTests.Runners/VisualRunner/XamlExtensions/EmbeddedResourceExtension.cs delete mode 100644 test/MauiTestUtils/DeviceTests/AssertionExtensions.Android.cs delete mode 100644 test/MauiTestUtils/DeviceTests/AssertionExtensions.Windows.cs delete mode 100644 test/MauiTestUtils/DeviceTests/AssertionExtensions.cs delete mode 100644 test/MauiTestUtils/DeviceTests/AssertionExtensions.iOS.cs delete mode 100644 test/MauiTestUtils/DeviceTests/ColorComparison.Android.cs delete mode 100644 test/MauiTestUtils/DeviceTests/ColorComparison.Windows.cs delete mode 100644 test/MauiTestUtils/DeviceTests/ColorComparison.iOS.cs delete mode 100644 test/MauiTestUtils/DeviceTests/RepeatAttribute.cs delete mode 100644 test/MauiTestUtils/DeviceTests/TestUtils.DeviceTests.csproj delete mode 100644 test/MauiTestUtils/DeviceTests/UINSWindow.iOS.cs delete mode 100644 test/MauiTestUtils/DeviceTests/xUnitCustomizations.cs create mode 100644 test/Sentry.Maui.Device.TestApp/Platforms/Android/MainActivity.cs create mode 100644 test/Sentry.Maui.Device.TestApp/Platforms/Android/MainApplication.cs create mode 100644 test/Sentry.Maui.Device.TestApp/Platforms/iOS/AppDelegate.cs create mode 100644 test/Sentry.Maui.Device.TestApp/Platforms/iOS/Program.cs diff --git a/.generated.NoMobile.sln b/.generated.NoMobile.sln index e212ca2dd2..45e1b1caa9 100644 --- a/.generated.NoMobile.sln +++ b/.generated.NoMobile.sln @@ -103,14 +103,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{6987A1CC-6 EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AndroidTestApp", "test\AndroidTestApp\AndroidTestApp.csproj", "{99E2D1A4-1853-49F9-96B6-59C70FA3DE3A}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "MauiTestUtils", "MauiTestUtils", "{A11512A4-26BD-4936-B7A6-6FCE2E78FA80}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestUtils.DeviceTests.Runners.SourceGen", "test\MauiTestUtils\DeviceTests.Runners.SourceGen\TestUtils.DeviceTests.Runners.SourceGen.csproj", "{7C1A1318-137E-4E1E-ADB3-C0CE2B10F779}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestUtils.DeviceTests.Runners", "test\MauiTestUtils\DeviceTests.Runners\TestUtils.DeviceTests.Runners.csproj", "{1C6F1CB1-2339-4E8B-9941-80998B940DCC}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestUtils.DeviceTests", "test\MauiTestUtils\DeviceTests\TestUtils.DeviceTests.csproj", "{E92F0A4E-2653-4341-8732-2AC9CF766739}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.Android.AssemblyReader.Tests", "test\Sentry.Android.AssemblyReader.Tests\Sentry.Android.AssemblyReader.Tests.csproj", "{3C543CED-F801-4843-BA48-76142843E1B9}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.AspNet.Tests", "test\Sentry.AspNet.Tests\Sentry.AspNet.Tests.csproj", "{7ABAA536-7BEC-46D7-9C61-82440DDC9AA8}" @@ -178,6 +170,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "root", "root", "{233D34AB-9 README.md = README.md CHANGELOG.md = CHANGELOG.md CONTRIBUTING.md = CONTRIBUTING.md + Directory.Build.props = Directory.Build.props + Directory.Build.targets = Directory.Build.targets + global.json = global.json + nuget.config = nuget.config EndProjectSection EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.AspNetCore.Blazor.WebAssembly", "src\Sentry.AspNetCore.Blazor.WebAssembly\Sentry.AspNetCore.Blazor.WebAssembly.csproj", "{8298202C-9983-4D0A-851D-805539EE481A}" @@ -372,18 +368,6 @@ Global {99E2D1A4-1853-49F9-96B6-59C70FA3DE3A}.Debug|Any CPU.Build.0 = Debug|Any CPU {99E2D1A4-1853-49F9-96B6-59C70FA3DE3A}.Release|Any CPU.ActiveCfg = Release|Any CPU {99E2D1A4-1853-49F9-96B6-59C70FA3DE3A}.Release|Any CPU.Build.0 = Release|Any CPU - {7C1A1318-137E-4E1E-ADB3-C0CE2B10F779}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {7C1A1318-137E-4E1E-ADB3-C0CE2B10F779}.Debug|Any CPU.Build.0 = Debug|Any CPU - {7C1A1318-137E-4E1E-ADB3-C0CE2B10F779}.Release|Any CPU.ActiveCfg = Release|Any CPU - {7C1A1318-137E-4E1E-ADB3-C0CE2B10F779}.Release|Any CPU.Build.0 = Release|Any CPU - {1C6F1CB1-2339-4E8B-9941-80998B940DCC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {1C6F1CB1-2339-4E8B-9941-80998B940DCC}.Debug|Any CPU.Build.0 = Debug|Any CPU - {1C6F1CB1-2339-4E8B-9941-80998B940DCC}.Release|Any CPU.ActiveCfg = Release|Any CPU - {1C6F1CB1-2339-4E8B-9941-80998B940DCC}.Release|Any CPU.Build.0 = Release|Any CPU - {E92F0A4E-2653-4341-8732-2AC9CF766739}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {E92F0A4E-2653-4341-8732-2AC9CF766739}.Debug|Any CPU.Build.0 = Debug|Any CPU - {E92F0A4E-2653-4341-8732-2AC9CF766739}.Release|Any CPU.ActiveCfg = Release|Any CPU - {E92F0A4E-2653-4341-8732-2AC9CF766739}.Release|Any CPU.Build.0 = Release|Any CPU {3C543CED-F801-4843-BA48-76142843E1B9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {3C543CED-F801-4843-BA48-76142843E1B9}.Debug|Any CPU.Build.0 = Debug|Any CPU {3C543CED-F801-4843-BA48-76142843E1B9}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -559,10 +543,6 @@ Global {854EBD1B-73EE-4B93-89DF-E70436FF14CB} = {230B9384-90FD-4551-A5DE-1A5C197F25B6} {5F253D7F-BF27-46F5-9382-73A66EC247BF} = {230B9384-90FD-4551-A5DE-1A5C197F25B6} {99E2D1A4-1853-49F9-96B6-59C70FA3DE3A} = {6987A1CC-608E-4868-A02C-09D30C8B7B2D} - {A11512A4-26BD-4936-B7A6-6FCE2E78FA80} = {6987A1CC-608E-4868-A02C-09D30C8B7B2D} - {7C1A1318-137E-4E1E-ADB3-C0CE2B10F779} = {A11512A4-26BD-4936-B7A6-6FCE2E78FA80} - {1C6F1CB1-2339-4E8B-9941-80998B940DCC} = {A11512A4-26BD-4936-B7A6-6FCE2E78FA80} - {E92F0A4E-2653-4341-8732-2AC9CF766739} = {A11512A4-26BD-4936-B7A6-6FCE2E78FA80} {3C543CED-F801-4843-BA48-76142843E1B9} = {6987A1CC-608E-4868-A02C-09D30C8B7B2D} {7ABAA536-7BEC-46D7-9C61-82440DDC9AA8} = {6987A1CC-608E-4868-A02C-09D30C8B7B2D} {D7D1EA68-ACE3-4DF3-A33C-EBB5B74701F5} = {6987A1CC-608E-4868-A02C-09D30C8B7B2D} diff --git a/Sentry-CI-Build-macOS.slnf b/Sentry-CI-Build-macOS.slnf index 876cfd1d69..cc40fdf79f 100644 --- a/Sentry-CI-Build-macOS.slnf +++ b/Sentry-CI-Build-macOS.slnf @@ -67,6 +67,7 @@ "test\\Sentry.Google.Cloud.Functions.Tests\\Sentry.Google.Cloud.Functions.Tests.csproj", "test\\Sentry.Hangfire.Tests\\Sentry.Hangfire.Tests.csproj", "test\\Sentry.Log4Net.Tests\\Sentry.Log4Net.Tests.csproj", + "test\\Sentry.Maui.Device.TestApp\\Sentry.Maui.Device.TestApp.csproj", "test\\Sentry.Maui.Tests\\Sentry.Maui.Tests.csproj", "test\\Sentry.NLog.Tests\\Sentry.NLog.Tests.csproj", "test\\Sentry.OpenTelemetry.Tests\\Sentry.OpenTelemetry.Tests.csproj", diff --git a/Sentry.sln b/Sentry.sln index e212ca2dd2..45e1b1caa9 100644 --- a/Sentry.sln +++ b/Sentry.sln @@ -103,14 +103,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{6987A1CC-6 EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AndroidTestApp", "test\AndroidTestApp\AndroidTestApp.csproj", "{99E2D1A4-1853-49F9-96B6-59C70FA3DE3A}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "MauiTestUtils", "MauiTestUtils", "{A11512A4-26BD-4936-B7A6-6FCE2E78FA80}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestUtils.DeviceTests.Runners.SourceGen", "test\MauiTestUtils\DeviceTests.Runners.SourceGen\TestUtils.DeviceTests.Runners.SourceGen.csproj", "{7C1A1318-137E-4E1E-ADB3-C0CE2B10F779}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestUtils.DeviceTests.Runners", "test\MauiTestUtils\DeviceTests.Runners\TestUtils.DeviceTests.Runners.csproj", "{1C6F1CB1-2339-4E8B-9941-80998B940DCC}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestUtils.DeviceTests", "test\MauiTestUtils\DeviceTests\TestUtils.DeviceTests.csproj", "{E92F0A4E-2653-4341-8732-2AC9CF766739}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.Android.AssemblyReader.Tests", "test\Sentry.Android.AssemblyReader.Tests\Sentry.Android.AssemblyReader.Tests.csproj", "{3C543CED-F801-4843-BA48-76142843E1B9}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.AspNet.Tests", "test\Sentry.AspNet.Tests\Sentry.AspNet.Tests.csproj", "{7ABAA536-7BEC-46D7-9C61-82440DDC9AA8}" @@ -178,6 +170,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "root", "root", "{233D34AB-9 README.md = README.md CHANGELOG.md = CHANGELOG.md CONTRIBUTING.md = CONTRIBUTING.md + Directory.Build.props = Directory.Build.props + Directory.Build.targets = Directory.Build.targets + global.json = global.json + nuget.config = nuget.config EndProjectSection EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.AspNetCore.Blazor.WebAssembly", "src\Sentry.AspNetCore.Blazor.WebAssembly\Sentry.AspNetCore.Blazor.WebAssembly.csproj", "{8298202C-9983-4D0A-851D-805539EE481A}" @@ -372,18 +368,6 @@ Global {99E2D1A4-1853-49F9-96B6-59C70FA3DE3A}.Debug|Any CPU.Build.0 = Debug|Any CPU {99E2D1A4-1853-49F9-96B6-59C70FA3DE3A}.Release|Any CPU.ActiveCfg = Release|Any CPU {99E2D1A4-1853-49F9-96B6-59C70FA3DE3A}.Release|Any CPU.Build.0 = Release|Any CPU - {7C1A1318-137E-4E1E-ADB3-C0CE2B10F779}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {7C1A1318-137E-4E1E-ADB3-C0CE2B10F779}.Debug|Any CPU.Build.0 = Debug|Any CPU - {7C1A1318-137E-4E1E-ADB3-C0CE2B10F779}.Release|Any CPU.ActiveCfg = Release|Any CPU - {7C1A1318-137E-4E1E-ADB3-C0CE2B10F779}.Release|Any CPU.Build.0 = Release|Any CPU - {1C6F1CB1-2339-4E8B-9941-80998B940DCC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {1C6F1CB1-2339-4E8B-9941-80998B940DCC}.Debug|Any CPU.Build.0 = Debug|Any CPU - {1C6F1CB1-2339-4E8B-9941-80998B940DCC}.Release|Any CPU.ActiveCfg = Release|Any CPU - {1C6F1CB1-2339-4E8B-9941-80998B940DCC}.Release|Any CPU.Build.0 = Release|Any CPU - {E92F0A4E-2653-4341-8732-2AC9CF766739}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {E92F0A4E-2653-4341-8732-2AC9CF766739}.Debug|Any CPU.Build.0 = Debug|Any CPU - {E92F0A4E-2653-4341-8732-2AC9CF766739}.Release|Any CPU.ActiveCfg = Release|Any CPU - {E92F0A4E-2653-4341-8732-2AC9CF766739}.Release|Any CPU.Build.0 = Release|Any CPU {3C543CED-F801-4843-BA48-76142843E1B9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {3C543CED-F801-4843-BA48-76142843E1B9}.Debug|Any CPU.Build.0 = Debug|Any CPU {3C543CED-F801-4843-BA48-76142843E1B9}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -559,10 +543,6 @@ Global {854EBD1B-73EE-4B93-89DF-E70436FF14CB} = {230B9384-90FD-4551-A5DE-1A5C197F25B6} {5F253D7F-BF27-46F5-9382-73A66EC247BF} = {230B9384-90FD-4551-A5DE-1A5C197F25B6} {99E2D1A4-1853-49F9-96B6-59C70FA3DE3A} = {6987A1CC-608E-4868-A02C-09D30C8B7B2D} - {A11512A4-26BD-4936-B7A6-6FCE2E78FA80} = {6987A1CC-608E-4868-A02C-09D30C8B7B2D} - {7C1A1318-137E-4E1E-ADB3-C0CE2B10F779} = {A11512A4-26BD-4936-B7A6-6FCE2E78FA80} - {1C6F1CB1-2339-4E8B-9941-80998B940DCC} = {A11512A4-26BD-4936-B7A6-6FCE2E78FA80} - {E92F0A4E-2653-4341-8732-2AC9CF766739} = {A11512A4-26BD-4936-B7A6-6FCE2E78FA80} {3C543CED-F801-4843-BA48-76142843E1B9} = {6987A1CC-608E-4868-A02C-09D30C8B7B2D} {7ABAA536-7BEC-46D7-9C61-82440DDC9AA8} = {6987A1CC-608E-4868-A02C-09D30C8B7B2D} {D7D1EA68-ACE3-4DF3-A33C-EBB5B74701F5} = {6987A1CC-608E-4868-A02C-09D30C8B7B2D} diff --git a/SentryMobile.slnf b/SentryMobile.slnf index e20fae4d84..b5d76fafbd 100644 --- a/SentryMobile.slnf +++ b/SentryMobile.slnf @@ -12,9 +12,6 @@ "src\\Sentry.Extensions.Logging\\Sentry.Extensions.Logging.csproj", "src\\Sentry.Maui\\Sentry.Maui.csproj", "src\\Sentry\\Sentry.csproj", - "test\\MauiTestUtils\\DeviceTests.Runners.SourceGen\\TestUtils.DeviceTests.Runners.SourceGen.csproj", - "test\\MauiTestUtils\\DeviceTests.Runners\\TestUtils.DeviceTests.Runners.csproj", - "test\\MauiTestUtils\\DeviceTests\\TestUtils.DeviceTests.csproj", "test\\Sentry.Android.AssemblyReader.Tests\\Sentry.Android.AssemblyReader.Tests.csproj", "test\\Sentry.Extensions.Logging.Tests\\Sentry.Extensions.Logging.Tests.csproj", "test\\Sentry.Maui.Device.TestApp\\Sentry.Maui.Device.TestApp.csproj", diff --git a/nuget.config b/nuget.config index 48792e6dcb..aec3c1420a 100644 --- a/nuget.config +++ b/nuget.config @@ -8,6 +8,9 @@ + + + @@ -26,5 +29,8 @@ + + + diff --git a/scripts/generate-solution-filters-config.yaml b/scripts/generate-solution-filters-config.yaml index 5af0c03ff0..adc0d61fd6 100644 --- a/scripts/generate-solution-filters-config.yaml +++ b/scripts/generate-solution-filters-config.yaml @@ -53,7 +53,6 @@ filterConfigs: patterns: - "**/*AndroidTestApp.csproj" - "**/*DeviceTests*.csproj" - - "**/*Maui.Device.TestApp.csproj" - "**/*SourceGen.csproj" - "**/Sentry.Samples.Android.csproj" @@ -159,7 +158,6 @@ filterConfigs: - "test/**/Sentry.Maui.Tests.csproj" - "test/**/Sentry.Testing.csproj" - "test/**/Sentry.Tests.csproj" - - "test/MauiTestUtils/**/*.csproj" - outputPath: SentryNoMobile.slnf solution: .generated.NoMobile.sln diff --git a/test/MauiTestUtils/DeviceTests.Runners.SourceGen/AnalyzerReleases.Shipped.md b/test/MauiTestUtils/DeviceTests.Runners.SourceGen/AnalyzerReleases.Shipped.md deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/test/MauiTestUtils/DeviceTests.Runners.SourceGen/AnalyzerReleases.Unshipped.md b/test/MauiTestUtils/DeviceTests.Runners.SourceGen/AnalyzerReleases.Unshipped.md deleted file mode 100644 index 4a4a177305..0000000000 --- a/test/MauiTestUtils/DeviceTests.Runners.SourceGen/AnalyzerReleases.Unshipped.md +++ /dev/null @@ -1,5 +0,0 @@ -### New Rules - -Rule ID | Category | Severity | Notes ---------|----------|----------|-------------------- -TST1001 | Logging | Info | Logging messages diff --git a/test/MauiTestUtils/DeviceTests.Runners.SourceGen/CodeBehindGenerator.cs b/test/MauiTestUtils/DeviceTests.Runners.SourceGen/CodeBehindGenerator.cs deleted file mode 100644 index 6272f898ca..0000000000 --- a/test/MauiTestUtils/DeviceTests.Runners.SourceGen/CodeBehindGenerator.cs +++ /dev/null @@ -1,27 +0,0 @@ -using Microsoft.CodeAnalysis; - -namespace Microsoft.Maui.TestUtils.DeviceTests.Runners.SourceGen; - -[Generator] -public class CodeBehindGenerator : ISourceGenerator -{ - public void Initialize(GeneratorInitializationContext context) - { - //#if DEBUG - //if (!System.Diagnostics.Debugger.IsAttached) - // System.Diagnostics.Debugger.Launch(); - //#endif - } - - public void Execute(GeneratorExecutionContext context) - { - if (!context.AnalyzerConfigOptions.GlobalOptions.TryGetValue("build_property.TargetFramework", out var targetFramework)) - return; - - context.Log($"TargetFramework: {targetFramework}"); - - var generator = new RunnerGenerator(context, targetFramework); - - generator?.Generate(); - } -} diff --git a/test/MauiTestUtils/DeviceTests.Runners.SourceGen/GeneratorDiagnostics.cs b/test/MauiTestUtils/DeviceTests.Runners.SourceGen/GeneratorDiagnostics.cs deleted file mode 100644 index a017ed449b..0000000000 --- a/test/MauiTestUtils/DeviceTests.Runners.SourceGen/GeneratorDiagnostics.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System.Diagnostics; -using Microsoft.CodeAnalysis; - -namespace Microsoft.Maui.TestUtils.DeviceTests.Runners.SourceGen; - -internal static class GeneratorDiagnostics -{ - public static readonly DiagnosticDescriptor LoggingMessage = new DiagnosticDescriptor( - id: "TST1001", - title: "Logging Message", - messageFormat: "{0}", - category: "Logging", - DiagnosticSeverity.Info, - isEnabledByDefault: true); - - [Conditional("DEBUG")] - public static void Log(this GeneratorExecutionContext context, string message) => - context.ReportDiagnostic(Diagnostic.Create(LoggingMessage, Location.None, message)); -} diff --git a/test/MauiTestUtils/DeviceTests.Runners.SourceGen/RunnerGenerator.cs b/test/MauiTestUtils/DeviceTests.Runners.SourceGen/RunnerGenerator.cs deleted file mode 100644 index 651f21a25a..0000000000 --- a/test/MauiTestUtils/DeviceTests.Runners.SourceGen/RunnerGenerator.cs +++ /dev/null @@ -1,223 +0,0 @@ -using System; -using System.Text; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.Text; - -namespace Microsoft.Maui.TestUtils.DeviceTests.Runners.SourceGen; - -public class RunnerGenerator -{ - public RunnerGenerator(GeneratorExecutionContext context, string targetFramework) - { - Context = context; - - TargetFramework = targetFramework; - - context.AnalyzerConfigOptions.GlobalOptions.TryGetValue("build_property.ApplicationId", out var applicationId); - context.Log($"ApplicationId: {applicationId}"); - ApplicationId = applicationId ?? throw new Exception("ApplicationId needs to be set."); - - context.AnalyzerConfigOptions.GlobalOptions.TryGetValue("build_property.ApplicationTitle", out var applicationTitle); - context.Log($"ApplicationTitle: {applicationTitle}"); - ApplicationTitle = applicationTitle ?? "Tests"; - - context.AnalyzerConfigOptions.GlobalOptions.TryGetValue("build_property.RootNamespace", out var rootNamespace); - context.Log($"RootNamespace: {rootNamespace}"); - RootNamespace = rootNamespace ?? "TestRunnerNamespace"; - - ContainsSplashScreen = false; - foreach (var file in context.AdditionalFiles) - { - var options = context.AnalyzerConfigOptions.GetOptions(file); - if (options.TryGetValue("build_metadata.AdditionalFiles.IsMauiSplashScreen", out var isMauiSplashScreen) && bool.TryParse(isMauiSplashScreen, out var isSplash) && isSplash) - { - ContainsSplashScreen = true; - break; - } - } - context.Log($"ContainsSplashScreen: {ContainsSplashScreen}"); - } - - public GeneratorExecutionContext Context { get; } - - public string TargetFramework { get; } - - public string RootNamespace { get; } - - public string ApplicationId { get; } - - public string ApplicationTitle { get; } - - public bool ContainsSplashScreen { get; } - - public void Generate() - { - Context.Log($"Generating runners..."); - - if (TargetFramework.IndexOf("-android", StringComparison.OrdinalIgnoreCase) != -1) - { - var code = GenerateAndroidSource(); - var name = "TestRunner.Android.sg.cs"; - - AddSource(name, code); - } - else if (TargetFramework.IndexOf("-ios", StringComparison.OrdinalIgnoreCase) != -1) - { - var code = GenerateIosSource(); - var name = "TestRunner.iOS.sg.cs"; - - AddSource(name, code); - } - else if (TargetFramework.IndexOf("-maccatalyst", StringComparison.OrdinalIgnoreCase) != -1) - { - var code = GenerateIosSource(); - var name = "TestRunner.MacCatalyst.sg.cs"; - - AddSource(name, code); - } - } - - protected void AddSource(string filename, string contents) - { - Context.Log($"AddSource: {filename}"); - Context.AddSource(filename, SourceText.From(contents, Encoding.UTF8)); - } - - private string GenerateAndroidSource() - { - var mauiProgramName = "MauiProgram"; - var mauiProgramFullName = @"global::" + RootNamespace + "." + mauiProgramName; - var splash = ContainsSplashScreen ? @"Theme = ""@style/Maui.SplashTheme""," : ""; - - var appName = "MainApplication"; - var visualActivityName = "MainActivity"; - - var instrumentationName = "TestInstrumentation"; - var headlessActivityName = "TestActivity"; - - return @" -#if !SKIP_RUNNER_ENTRYPOINT_GENERATION && !SKIP_VISUAL_RUNNER_ENTRYPOINT_GENERATION && !SKIP_VISUAL_RUNNER_APPLICATION_GENERATION -namespace " + RootNamespace + @" -{ - [global::Android.App.Application] - partial class " + appName + @" : global::Microsoft.Maui.MauiApplication - { - public " + appName + @"(global::System.IntPtr handle, global::Android.Runtime.JniHandleOwnership ownership) - : base(handle, ownership) - { - } - - protected override global::Microsoft.Maui.Hosting.MauiApp CreateMauiApp() => " + mauiProgramFullName + @".CreateMauiApp(); - } -} -#endif - -#if !SKIP_RUNNER_ENTRYPOINT_GENERATION && !SKIP_VISUAL_RUNNER_ENTRYPOINT_GENERATION && !SKIP_VISUAL_RUNNER_ACTIVITY_GENERATION -namespace " + RootNamespace + @" -{ - [global::Android.App.Activity( - " + splash + @" - MainLauncher = true, - ConfigurationChanges = - global::Android.Content.PM.ConfigChanges.ScreenSize | - global::Android.Content.PM.ConfigChanges.Orientation | - global::Android.Content.PM.ConfigChanges.UiMode | - global::Android.Content.PM.ConfigChanges.ScreenLayout | - global::Android.Content.PM.ConfigChanges.SmallestScreenSize)] - partial class " + visualActivityName + @" : global::Microsoft.Maui.MauiAppCompatActivity - { - } -} -#endif - -#if !SKIP_RUNNER_ENTRYPOINT_GENERATION && !SKIP_HEADLESS_RUNNER_ENTRYPOINT_GENERATION && !SKIP_HEADLESS_RUNNER_INSTRUMENTATION_GENERATION -namespace " + RootNamespace + @" -{ - [global::Android.App.Instrumentation(Name = """ + ApplicationId + "." + instrumentationName + @""")] - public partial class " + instrumentationName + @" : global::Microsoft.Maui.TestUtils.DeviceTests.Runners.HeadlessRunner.MauiTestInstrumentation - { - protected " + instrumentationName + @"(global::System.IntPtr handle, global::Android.Runtime.JniHandleOwnership transfer) - : base(handle, transfer) - { - } - } -} -#endif - -#if !SKIP_RUNNER_ENTRYPOINT_GENERATION && !SKIP_HEADLESS_RUNNER_ENTRYPOINT_GENERATION && !SKIP_HEADLESS_RUNNER_ACTIVITY_GENERATION -namespace " + RootNamespace + @" -{ - [global::Android.App.Activity( - Name = """ + ApplicationId + "." + headlessActivityName + @""", - Theme = ""@style/Maui.MainTheme.NoActionBar"", - ConfigurationChanges = - global::Android.Content.PM.ConfigChanges.ScreenSize | - global::Android.Content.PM.ConfigChanges.Orientation | - global::Android.Content.PM.ConfigChanges.UiMode | - global::Android.Content.PM.ConfigChanges.ScreenLayout | - global::Android.Content.PM.ConfigChanges.SmallestScreenSize)] - public partial class " + headlessActivityName + @" : global::Microsoft.Maui.TestUtils.DeviceTests.Runners.HeadlessRunner.MauiTestActivity - { - } -} -#endif -"; - } - - private string GenerateIosSource() - { - var mauiProgramName = "MauiProgram"; - var mauiProgramFullName = @"global::" + RootNamespace + "." + mauiProgramName; - var visualDelegateName = "VisualRunnerAppDelegate"; - var headlessDelegateName = "HeadlessRunnerAppDelegate"; - - return @" -#if !SKIP_RUNNER_ENTRYPOINT_GENERATION && !SKIP_VISUAL_RUNNER_ENTRYPOINT_GENERATION && !SKIP_RUNNER_PROGRAM_GENERATION -namespace " + RootNamespace + @" -{ - partial class Program - { - static void Main(global::System.String[] args) - { -#if !SKIP_HEADLESS_RUNNER_APP_DELEGATE_GENERATION - if (global::Microsoft.Maui.TestUtils.DeviceTests.Runners.HeadlessRunner.MauiTestApplicationDelegate.IsHeadlessRunner(args)) - { - global::UIKit.UIApplication.Main(args, null, typeof(global::" + RootNamespace + @"." + headlessDelegateName + @")); - } - else -#endif - { -#if !SKIP_VISUAL_RUNNER_APP_DELEGATE_GENERATION - global::UIKit.UIApplication.Main(args, null, typeof(global::" + RootNamespace + @"." + visualDelegateName + @")); -#endif - } - } - } -} -#endif - -#if !SKIP_RUNNER_ENTRYPOINT_GENERATION && !SKIP_VISUAL_RUNNER_ENTRYPOINT_GENERATION && !SKIP_VISUAL_RUNNER_APP_DELEGATE_GENERATION -namespace " + RootNamespace + @" -{ - [global::Foundation.Register(""" + visualDelegateName + @""")] - partial class " + visualDelegateName + @" : global::Microsoft.Maui.MauiUIApplicationDelegate - { - protected override global::Microsoft.Maui.Hosting.MauiApp CreateMauiApp() => " + mauiProgramFullName + @".CreateMauiApp(); - } -} -#endif - -#if !SKIP_RUNNER_ENTRYPOINT_GENERATION && !SKIP_HEADLESS_RUNNER_ENTRYPOINT_GENERATION && !SKIP_HEADLESS_RUNNER_APP_DELEGATE_GENERATION -namespace " + RootNamespace + @" -{ - [global::Foundation.Register(""" + headlessDelegateName + @""")] - partial class " + headlessDelegateName + @" : global::Microsoft.Maui.TestUtils.DeviceTests.Runners.HeadlessRunner.MauiTestApplicationDelegate - { - - protected override global::Microsoft.Maui.Hosting.MauiApp CreateMauiApp() => " + mauiProgramFullName + @".CreateMauiApp(); - } -} -#endif -"; - } -} diff --git a/test/MauiTestUtils/DeviceTests.Runners.SourceGen/TestUtils.DeviceTests.Runners.SourceGen.csproj b/test/MauiTestUtils/DeviceTests.Runners.SourceGen/TestUtils.DeviceTests.Runners.SourceGen.csproj deleted file mode 100644 index 928c94c1b9..0000000000 --- a/test/MauiTestUtils/DeviceTests.Runners.SourceGen/TestUtils.DeviceTests.Runners.SourceGen.csproj +++ /dev/null @@ -1,21 +0,0 @@ - - - - netstandard2.0 - enable - Microsoft.Maui.TestUtils - Microsoft.Maui.TestUtils.DeviceTests.Runners.SourceGen - false - true - - - - - - - - - - - - diff --git a/test/MauiTestUtils/DeviceTests.Runners/AppHostBuilderExtensions.cs b/test/MauiTestUtils/DeviceTests.Runners/AppHostBuilderExtensions.cs deleted file mode 100644 index a6916c1caa..0000000000 --- a/test/MauiTestUtils/DeviceTests.Runners/AppHostBuilderExtensions.cs +++ /dev/null @@ -1,41 +0,0 @@ -#nullable enable -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; -using Microsoft.Maui.Controls.Hosting; -using Microsoft.Maui.Hosting; -using Microsoft.Maui.TestUtils.DeviceTests.Runners.HeadlessRunner; -using Microsoft.Maui.TestUtils.DeviceTests.Runners.VisualRunner; - -namespace Microsoft.Maui.TestUtils.DeviceTests.Runners; - -public static class AppHostBuilderExtensions -{ - public static MauiAppBuilder ConfigureTests(this MauiAppBuilder appHostBuilder, TestOptions options) - { - appHostBuilder.Services.AddSingleton(options); - - return appHostBuilder; - } - - public static MauiAppBuilder UseVisualRunner(this MauiAppBuilder appHostBuilder) - { - appHostBuilder.UseMauiApp(svc => new MauiVisualRunnerApp( - svc.GetRequiredService(), - svc.GetRequiredService().CreateLogger("TestRun"))); - - return appHostBuilder; - } - - public static MauiAppBuilder UseHeadlessRunner(this MauiAppBuilder appHostBuilder, HeadlessRunnerOptions options) - { - appHostBuilder.Services.AddSingleton(options); - -#if __ANDROID__ || __IOS__ || MACCATALYST - appHostBuilder.Services.AddTransient(svc => new HeadlessTestRunner( - svc.GetRequiredService(), - svc.GetRequiredService())); -#endif - - return appHostBuilder; - } -} diff --git a/test/MauiTestUtils/DeviceTests.Runners/Assets/credits.html b/test/MauiTestUtils/DeviceTests.Runners/Assets/credits.html deleted file mode 100644 index 65a209fcf7..0000000000 --- a/test/MauiTestUtils/DeviceTests.Runners/Assets/credits.html +++ /dev/null @@ -1,16 +0,0 @@ - - - - xUnit Device Runner
- Copyright © 2015
- Outercurve Foundation
- All rights reserved.
-
- - Author: Claire Novotny
-
- - About xUnit
- - - \ No newline at end of file diff --git a/test/MauiTestUtils/DeviceTests.Runners/HeadlessRunner/Android/HeadlessTestRunner.cs b/test/MauiTestUtils/DeviceTests.Runners/HeadlessRunner/Android/HeadlessTestRunner.cs deleted file mode 100644 index cd489fa90d..0000000000 --- a/test/MauiTestUtils/DeviceTests.Runners/HeadlessRunner/Android/HeadlessTestRunner.cs +++ /dev/null @@ -1,93 +0,0 @@ -#nullable enable -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Threading.Tasks; -using Android.App; -using Android.OS; -using Microsoft.DotNet.XHarness.TestRunners.Common; -using Microsoft.DotNet.XHarness.TestRunners.Xunit; - -namespace Microsoft.Maui.TestUtils.DeviceTests.Runners.HeadlessRunner; - -internal class HeadlessTestRunner : AndroidApplicationEntryPoint -{ - private readonly HeadlessRunnerOptions _runnerOptions; - private readonly TestOptions _options; - private readonly string _resultsPath; - - public HeadlessTestRunner(HeadlessRunnerOptions runnerOptions, TestOptions options) - { - _runnerOptions = runnerOptions; - _options = options; - - var cache = Application.Context.CacheDir!.AbsolutePath; - _resultsPath = Path.Combine(cache, _runnerOptions.TestResultsFilename); - } - - protected override bool LogExcludedTests => true; - - public override TextWriter? Logger => null; - - public override string TestsResultsFinalPath => _resultsPath; - - protected override int? MaxParallelThreads => System.Environment.ProcessorCount; - - protected override IDevice Device { get; } = new TestDevice(); - - protected override IEnumerable GetTestAssemblies() => - _options.Assemblies - .Distinct() - .Select(assembly => - { - // Android needs this file to "exist" but it uses the assembly actually. - var path = Path.Combine(Application.Context.CacheDir!.AbsolutePath, assembly.GetName().Name + ".dll"); - if (!File.Exists(path)) - File.Create(path).Close(); - - return new TestAssemblyInfo(assembly, path); - }); - - protected override void TerminateWithSuccess() { } - - protected override TestRunner GetTestRunner(LogWriter logWriter) - { - var testRunner = base.GetTestRunner(logWriter); - if (_options.SkipCategories?.Count > 0) - testRunner.SkipCategories(_options.SkipCategories); - return testRunner; - } - - public async Task RunTestsAsync() - { - var bundle = new Bundle(); - - TestsCompleted += OnTestsCompleted; - - await RunAsync(); - - TestsCompleted -= OnTestsCompleted; - - if (File.Exists(TestsResultsFinalPath)) - bundle.PutString("test-results-path", TestsResultsFinalPath); - - if (bundle.GetLong("return-code", -1) == -1) - bundle.PutLong("return-code", 1); - - return bundle; - - void OnTestsCompleted(object? sender, TestRunResult results) - { - var message = - $"Tests run: {results.ExecutedTests} " + - $"Passed: {results.PassedTests} " + - $"Inconclusive: {results.InconclusiveTests} " + - $"Failed: {results.FailedTests} " + - $"Ignored: {results.SkippedTests}"; - - bundle.PutString("test-execution-summary", message); - - bundle.PutLong("return-code", results.FailedTests == 0 ? 0 : 1); - } - } -} diff --git a/test/MauiTestUtils/DeviceTests.Runners/HeadlessRunner/Android/MauiTestActivity.cs b/test/MauiTestUtils/DeviceTests.Runners/HeadlessRunner/Android/MauiTestActivity.cs deleted file mode 100644 index bc59b3b583..0000000000 --- a/test/MauiTestUtils/DeviceTests.Runners/HeadlessRunner/Android/MauiTestActivity.cs +++ /dev/null @@ -1,37 +0,0 @@ -#nullable enable -using System; -using System.Threading.Tasks; -using Android.OS; -using AndroidX.AppCompat.App; -using Microsoft.Extensions.DependencyInjection; - -namespace Microsoft.Maui.TestUtils.DeviceTests.Runners.HeadlessRunner; - -public abstract class MauiTestActivity : AppCompatActivity -{ - public TaskCompletionSource TaskCompletionSource { get; } = new TaskCompletionSource(); - - protected override void OnCreate(Bundle? savedInstanceState) - { - base.OnCreate(savedInstanceState); - - // Do the work on the background thread to avoid a keyDispatchingTimedOut ANR - Task.Run(async () => - { - try - { - var runner = MauiTestInstrumentation.Current.Services.GetRequiredService(); - - var bundle = await runner.RunTestsAsync(); - - TaskCompletionSource.TrySetResult(bundle); - } - catch (Exception ex) - { - TaskCompletionSource.TrySetException(ex); - } - - Finish(); - }); - } -} diff --git a/test/MauiTestUtils/DeviceTests.Runners/HeadlessRunner/Android/MauiTestInstrumentation.cs b/test/MauiTestUtils/DeviceTests.Runners/HeadlessRunner/Android/MauiTestInstrumentation.cs deleted file mode 100644 index e3ae2b8d8d..0000000000 --- a/test/MauiTestUtils/DeviceTests.Runners/HeadlessRunner/Android/MauiTestInstrumentation.cs +++ /dev/null @@ -1,148 +0,0 @@ -#nullable enable -using System; -using System.IO; -using System.Threading.Tasks; -using Android.App; -using Android.Content; -using Android.OS; -using Android.Provider; -using Android.Runtime; -using Microsoft.Extensions.DependencyInjection; - -namespace Microsoft.Maui.TestUtils.DeviceTests.Runners.HeadlessRunner; - -public abstract class MauiTestInstrumentation : Instrumentation -{ - private readonly TaskCompletionSource _waitForApplication = new(); - private Java.Lang.Class _activityClass = null!; - - protected MauiTestInstrumentation(IntPtr handle, JniHandleOwnership ownership) - : base(handle, ownership) - { - Current = this; - } - - public static MauiTestInstrumentation Current { get; private set; } = null!; - - public Bundle? Arguments { get; private set; } - - public IServiceProvider Services { get; private set; } = null!; - - public TestOptions Options { get; private set; } = null!; - - public HeadlessRunnerOptions RunnerOptions { get; private set; } = null!; - - public Context? CurrentExecutionContext { get; private set; } - - public override void OnCreate(Bundle? arguments) - { - _activityClass = Java.Lang.Class.ForName(Context!.PackageName + ".TestActivity"); - Arguments = arguments; - - base.OnCreate(arguments); - - Start(); - } - - public override void CallApplicationOnCreate(Application? app) - { - base.CallApplicationOnCreate(app); - - if (app == null) - _waitForApplication.SetException(new ArgumentNullException(nameof(app))); - else - _waitForApplication.SetResult(app); - } - - public override async void OnStart() - { - base.OnStart(); - - await _waitForApplication.Task; - - Services = MauiApplication.Current.Services; - Options = Services.GetRequiredService(); - RunnerOptions = Services.GetRequiredService(); - - var resultsFilename = Arguments?.GetString("results-file-name"); - if (!string.IsNullOrWhiteSpace(resultsFilename)) - RunnerOptions.TestResultsFilename = resultsFilename; - - var bundle = await RunTestsAsync(); - - CopyFile(bundle); - - Finish(Result.Ok, bundle); - } - - private void CopyFile(Bundle bundle) - { - var resultsFile = bundle.GetString("test-results-path"); - if (resultsFile == null) - return; - - var guid = Guid.NewGuid().ToString("N"); - var name = Path.GetFileName(resultsFile); - - string finalPath; - if (!OperatingSystem.IsAndroidVersionAtLeast(30)) - { - var root = Application.Context.GetExternalFilesDir(null)!.AbsolutePath!; - var dir = Path.Combine(root, guid); - - if (!Directory.Exists(dir)) - Directory.CreateDirectory(dir); - - finalPath = Path.Combine(dir, name); - File.Copy(resultsFile, finalPath, true); - } - else - { - var downloads = Android.OS.Environment.DirectoryDownloads!; - var relative = Path.Combine(downloads, Context!.PackageName!, guid); - - var values = new ContentValues(); - values.Put(MediaStore.IMediaColumns.DisplayName, name); - values.Put(MediaStore.IMediaColumns.MimeType, "text/xml"); - values.Put(MediaStore.IMediaColumns.RelativePath, relative); - - var resolver = Context!.ContentResolver!; - var uri = resolver.Insert(MediaStore.Downloads.ExternalContentUri, values)!; - using (var dest = resolver.OpenOutputStream(uri)!) - using (var source = File.OpenRead(resultsFile)) - source.CopyTo(dest); - -#pragma warning disable CS0618 // Type or member is obsolete - var root = Android.OS.Environment.ExternalStorageDirectory!.AbsolutePath; -#pragma warning restore CS0618 // Type or member is obsolete - finalPath = Path.Combine(root, relative, name); - } - - bundle.PutString("test-results-path", finalPath); - } - - private Task RunTestsAsync() - { - if (RunnerOptions.RequiresUIContext) - { - var intent = new Intent(TargetContext, _activityClass); - intent.AddFlags(ActivityFlags.NewTask); - - var activity = StartActivitySync(intent); - if (activity is not MauiTestActivity testActivity) - throw new InvalidOperationException($"Unexpected activity type '{activity?.GetType().FullName ?? ""}'."); - - CurrentExecutionContext = activity; - - return testActivity.TaskCompletionSource.Task; - } - else - { - CurrentExecutionContext = TargetContext; - - var runner = Services.GetRequiredService(); - - return runner.RunTestsAsync(); - } - } -} diff --git a/test/MauiTestUtils/DeviceTests.Runners/HeadlessRunner/TestDevice.cs b/test/MauiTestUtils/DeviceTests.Runners/HeadlessRunner/TestDevice.cs deleted file mode 100644 index 6407569987..0000000000 --- a/test/MauiTestUtils/DeviceTests.Runners/HeadlessRunner/TestDevice.cs +++ /dev/null @@ -1,25 +0,0 @@ -#nullable enable -using System; -using System.Globalization; -using Microsoft.DotNet.XHarness.TestRunners.Common; -using Microsoft.Maui.ApplicationModel; -using Microsoft.Maui.Devices; - -namespace Microsoft.Maui.TestUtils.DeviceTests.Runners.HeadlessRunner; - -internal class TestDevice : IDevice -{ - public string BundleIdentifier => AppInfo.PackageName; - - public string UniqueIdentifier => Guid.NewGuid().ToString("N"); - - public string Name => DeviceInfo.Name; - - public string Model => DeviceInfo.Model; - - public string SystemName => DeviceInfo.Platform.ToString(); - - public string SystemVersion => DeviceInfo.VersionString; - - public string Locale => CultureInfo.CurrentCulture.Name; -} diff --git a/test/MauiTestUtils/DeviceTests.Runners/HeadlessRunner/iOS/HeadlessTestRunner.cs b/test/MauiTestUtils/DeviceTests.Runners/HeadlessRunner/iOS/HeadlessTestRunner.cs deleted file mode 100644 index 130be2f4e4..0000000000 --- a/test/MauiTestUtils/DeviceTests.Runners/HeadlessRunner/iOS/HeadlessTestRunner.cs +++ /dev/null @@ -1,68 +0,0 @@ -#nullable enable -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.DotNet.XHarness.TestRunners.Common; -using Microsoft.DotNet.XHarness.TestRunners.Xunit; -using UIKit; - -namespace Microsoft.Maui.TestUtils.DeviceTests.Runners.HeadlessRunner; - -internal class HeadlessTestRunner : iOSApplicationEntryPoint -{ - private readonly HeadlessRunnerOptions _runnerOptions; - private readonly TestOptions _options; - - public HeadlessTestRunner(HeadlessRunnerOptions runnerOptions, TestOptions options) - { - _runnerOptions = runnerOptions; - _options = options; - } - - protected override bool LogExcludedTests => true; - - protected override int? MaxParallelThreads => Environment.ProcessorCount; - - protected override IDevice Device { get; } = new TestDevice(); - - protected override IEnumerable GetTestAssemblies() => - _options.Assemblies - .Distinct() - .Select(assembly => new TestAssemblyInfo(assembly, assembly.Location)); - - protected override void TerminateWithSuccess() - { - var s = new ObjCRuntime.Selector("terminateWithSuccess"); - UIApplication.SharedApplication.PerformSelector(s, UIApplication.SharedApplication, 0); - } - - protected override TestRunner GetTestRunner(LogWriter logWriter) - { - var testRunner = base.GetTestRunner(logWriter); - if (_options.SkipCategories?.Count > 0) - testRunner.SkipCategories(_options.SkipCategories); - return testRunner; - } - - public async Task RunTestsAsync() - { - TestsCompleted += OnTestsCompleted; - - await RunAsync(); - - TestsCompleted -= OnTestsCompleted; - - void OnTestsCompleted(object? sender, TestRunResult results) - { - var message = - $"Tests run: {results.ExecutedTests} " + - $"Passed: {results.PassedTests} " + - $"Inconclusive: {results.InconclusiveTests} " + - $"Failed: {results.FailedTests} " + - $"Ignored: {results.SkippedTests}"; - - Console.WriteLine(message); - } - } -} diff --git a/test/MauiTestUtils/DeviceTests.Runners/HeadlessRunner/iOS/MauiTestApplicationDelegate.cs b/test/MauiTestUtils/DeviceTests.Runners/HeadlessRunner/iOS/MauiTestApplicationDelegate.cs deleted file mode 100644 index 93700cb64c..0000000000 --- a/test/MauiTestUtils/DeviceTests.Runners/HeadlessRunner/iOS/MauiTestApplicationDelegate.cs +++ /dev/null @@ -1,123 +0,0 @@ -#nullable enable -using System; -using System.Collections.Generic; -using System.Threading.Tasks; -using Foundation; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Maui.Hosting; -using ObjCRuntime; -using UIKit; - -namespace Microsoft.Maui.TestUtils.DeviceTests.Runners.HeadlessRunner; - -public abstract class MauiTestApplicationDelegate : UIApplicationDelegate -{ - // TODO: https://github.com/xamarin/xamarin-macios/issues/12555 - private static readonly string[] EnvVarNames = { - "NUNIT_AUTOSTART", - "NUNIT_AUTOEXIT", - "NUNIT_ENABLE_NETWORK", - "DISABLE_SYSTEM_PERMISSION_TESTS", - "NUNIT_HOSTNAME", - "NUNIT_TRANSPORT", - "NUNIT_LOG_FILE", - "NUNIT_HOSTPORT", - "USE_TCP_TUNNEL", - "RUN_END_TAG", - "NUNIT_ENABLE_XML_OUTPUT", - "NUNIT_ENABLE_XML_MODE", - "NUNIT_XML_VERSION", - "NUNIT_SORTNAMES", - "NUNIT_RUN_ALL", - "NUNIT_SKIPPED_METHODS", - "NUNIT_SKIPPED_CLASSES", - }; - private static readonly Dictionary EnvVars = new(); - - static MauiTestApplicationDelegate() - { - // copy into dictionary for later - foreach (var envvar in EnvVarNames) - { - EnvVars[envvar] = Environment.GetEnvironmentVariable(envvar); - } - } - - private static void SetEnvironmentVariables() - { - // read from dictionary - foreach (var envvar in EnvVars) - { - Console.WriteLine($" {envvar.Key} = '{envvar.Value}'"); - Environment.SetEnvironmentVariable(envvar.Key, envvar.Value); - } - } - - public static bool IsHeadlessRunner(string[] args) - { - // usually means this is from xharness - return args?.Length > 0 || Environment.GetEnvironmentVariable("NUNIT_AUTOEXIT")?.Length > 0; - } - - protected MauiTestApplicationDelegate() - { - Current = this; - } - - public static MauiTestApplicationDelegate Current { get; private set; } = null!; - - public IServiceProvider Services { get; private set; } = null!; - - public TestOptions Options { get; private set; } = null!; - - public HeadlessRunnerOptions RunnerOptions { get; private set; } = null!; - - public override UIWindow? Window { get; set; } - - protected abstract MauiApp CreateMauiApp(); - - public override bool WillFinishLaunching(UIApplication application, NSDictionary launchOptions) - { - Runtime.MarshalManagedException += (object sender, MarshalManagedExceptionEventArgs args) => - { - Console.WriteLine("Marshaling managed exception"); - Console.WriteLine(" Exception: {0}", args.Exception); - Console.WriteLine(" Mode: {0}", args.ExceptionMode); - - }; - - Runtime.MarshalObjectiveCException += (object sender, MarshalObjectiveCExceptionEventArgs args) => - { - Console.WriteLine("Marshaling Objective-C exception"); - Console.WriteLine(" Exception: {0}", args.Exception); - Console.WriteLine(" Mode: {0}", args.ExceptionMode); - }; - - var mauiApp = CreateMauiApp(); - Services = mauiApp.Services; - - SetEnvironmentVariables(); - - Options = Services.GetRequiredService(); - RunnerOptions = Services.GetRequiredService(); - - return true; - } - - public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions) - { - var tcs = new TaskCompletionSource(); - - Window = new UIWindow(UIScreen.MainScreen.Bounds) - { - RootViewController = new MauiTestViewController(tcs.Task) - }; - - Window.MakeKeyAndVisible(); - - tcs.TrySetResult(); - - return true; - } - -} diff --git a/test/MauiTestUtils/DeviceTests.Runners/HeadlessRunner/iOS/MauiTestViewController.cs b/test/MauiTestUtils/DeviceTests.Runners/HeadlessRunner/iOS/MauiTestViewController.cs deleted file mode 100644 index 7e520cc6c9..0000000000 --- a/test/MauiTestUtils/DeviceTests.Runners/HeadlessRunner/iOS/MauiTestViewController.cs +++ /dev/null @@ -1,32 +0,0 @@ -#nullable enable -using System.Threading.Tasks; -using Microsoft.Extensions.DependencyInjection; -using UIKit; - -namespace Microsoft.Maui.TestUtils.DeviceTests.Runners.HeadlessRunner; - -public class MauiTestViewController : UIViewController -{ - private Task? _task; - - public MauiTestViewController() - { - } - - public MauiTestViewController(Task task) - { - _task = task; - } - - public override async void ViewDidLoad() - { - base.ViewDidLoad(); - - if (_task is not null) - await _task; - - var runner = MauiTestApplicationDelegate.Current.Services.GetRequiredService(); - - await runner.RunTestsAsync(); - } -} diff --git a/test/MauiTestUtils/DeviceTests.Runners/HeadlessRunnerOptions.cs b/test/MauiTestUtils/DeviceTests.Runners/HeadlessRunnerOptions.cs deleted file mode 100644 index 3c332a02ea..0000000000 --- a/test/MauiTestUtils/DeviceTests.Runners/HeadlessRunnerOptions.cs +++ /dev/null @@ -1,9 +0,0 @@ -#nullable enable -namespace Microsoft.Maui.TestUtils.DeviceTests.Runners; - -public class HeadlessRunnerOptions -{ - public string TestResultsFilename { get; set; } = "TestResults.xml"; - - public bool RequiresUIContext { get; set; } = true; -} diff --git a/test/MauiTestUtils/DeviceTests.Runners/TestDispatcher.cs b/test/MauiTestUtils/DeviceTests.Runners/TestDispatcher.cs deleted file mode 100644 index bcefa60f0e..0000000000 --- a/test/MauiTestUtils/DeviceTests.Runners/TestDispatcher.cs +++ /dev/null @@ -1,40 +0,0 @@ -#nullable enable -using System; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Maui.Dispatching; - -namespace Microsoft.Maui.TestUtils.DeviceTests.Runners; - -public static class TestDispatcher -{ - private static IDispatcher? s_dispatcher; - private static IDispatcherProvider? s_provider; - - public static IDispatcherProvider Provider - { - get - { - if (s_provider is null) - s_provider = TestServices.Services.GetService(); - - if (s_provider is null) - throw new InvalidOperationException($"Test app did not provide a dispatcher."); - - return s_provider; - } - } - - public static IDispatcher Current - { - get - { - if (s_dispatcher is null) - s_dispatcher = TestServices.Services.GetService(); - - if (s_dispatcher is null) - throw new InvalidOperationException($"Test app did not provide a dispatcher."); - - return s_dispatcher; - } - } -} diff --git a/test/MauiTestUtils/DeviceTests.Runners/TestOptions.cs b/test/MauiTestUtils/DeviceTests.Runners/TestOptions.cs deleted file mode 100644 index 9c519c5478..0000000000 --- a/test/MauiTestUtils/DeviceTests.Runners/TestOptions.cs +++ /dev/null @@ -1,19 +0,0 @@ -#nullable enable -using System.Collections.Generic; -using System.Reflection; - -namespace Microsoft.Maui.TestUtils.DeviceTests.Runners; - -public class TestOptions -{ - /// - /// The list of assemblies that contain tests. - /// - public List Assemblies { get; set; } = new List(); - - /// - /// The list of categories to skip in the form: - /// [category-name]=[skip-when-value] - /// - public List SkipCategories { get; set; } = new List(); -} diff --git a/test/MauiTestUtils/DeviceTests.Runners/TestServices.cs b/test/MauiTestUtils/DeviceTests.Runners/TestServices.cs deleted file mode 100644 index 4a29be0f60..0000000000 --- a/test/MauiTestUtils/DeviceTests.Runners/TestServices.cs +++ /dev/null @@ -1,32 +0,0 @@ -#nullable enable -using System; -using Microsoft.Maui.TestUtils.DeviceTests.Runners.HeadlessRunner; - -namespace Microsoft.Maui.TestUtils.DeviceTests.Runners; - -public static class TestServices -{ - private static IServiceProvider? s_services = null; - - public static IServiceProvider Services - { - get - { - if (s_services is null) - { -#if __ANDROID__ - s_services = MauiTestInstrumentation.Current?.Services ?? MauiApplication.Current.Services; -#elif __IOS__ - s_services = MauiTestApplicationDelegate.Current?.Services ?? MauiUIApplicationDelegate.Current.Services; -#elif WINDOWS - s_services = MauiWinUIApplication.Current.Services; -#endif - } - - if (s_services is null) - throw new InvalidOperationException($"Test app could not find services."); - - return s_services; - } - } -} diff --git a/test/MauiTestUtils/DeviceTests.Runners/TestUtils.DeviceTests.Runners.csproj b/test/MauiTestUtils/DeviceTests.Runners/TestUtils.DeviceTests.Runners.csproj deleted file mode 100644 index 7a02b2f989..0000000000 --- a/test/MauiTestUtils/DeviceTests.Runners/TestUtils.DeviceTests.Runners.csproj +++ /dev/null @@ -1,39 +0,0 @@ - - - - - $(TargetFrameworks);net7.0-android - $(TargetFrameworks);net7.0-windows10.0.19041.0 - $(TargetFrameworks);net7.0-ios - $(TargetFrameworks);net7.0-maccatalyst - - true - Microsoft.Maui.TestUtils.DeviceTests.Runners - Microsoft.Maui.TestUtils.DeviceTests.Runners - - true - false - - - - - - - - - - - - - - - - - - - - TestAssemblyPage.xaml - - - - diff --git a/test/MauiTestUtils/DeviceTests.Runners/TestWindow.cs b/test/MauiTestUtils/DeviceTests.Runners/TestWindow.cs deleted file mode 100644 index 38d167180b..0000000000 --- a/test/MauiTestUtils/DeviceTests.Runners/TestWindow.cs +++ /dev/null @@ -1,49 +0,0 @@ -#nullable enable -using System; -using System.Linq; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Maui.TestUtils.DeviceTests.Runners.HeadlessRunner; - -#if __IOS__ || MACCATALYST -using PlatformView = UIKit.UIWindow; -#elif MONOANDROID -using PlatformView = Android.App.Activity; -#elif WINDOWS -using PlatformView = Microsoft.UI.Xaml.Window; -#elif (NETSTANDARD || !PLATFORM) || (NET6_0_OR_GREATER && !IOS && !ANDROID) -using PlatformView = System.Object; -#endif - -namespace Microsoft.Maui.TestUtils.DeviceTests.Runners; - -public static class TestWindow -{ - private static PlatformView? s_platformWindow; - - public static PlatformView PlatformWindow - { - get - { - if (s_platformWindow is null) - { -#if __ANDROID__ - s_platformWindow = MauiTestInstrumentation.Current?.CurrentExecutionContext as PlatformView; -#elif __IOS__ - s_platformWindow = MauiTestApplicationDelegate.Current?.Window; -#endif - } - - if (s_platformWindow is null) - { - var application = TestServices.Services.GetService(); - s_platformWindow = application?.Windows.FirstOrDefault()?.Handler?.PlatformView as PlatformView; - } - - if (s_platformWindow is null) - throw new InvalidOperationException($"Test app did not provide a window."); - - return s_platformWindow; - } - } -} - diff --git a/test/MauiTestUtils/DeviceTests.Runners/VisualRunner/AssemblyRunInfo.cs b/test/MauiTestUtils/DeviceTests.Runners/VisualRunner/AssemblyRunInfo.cs deleted file mode 100644 index 363e0bdf14..0000000000 --- a/test/MauiTestUtils/DeviceTests.Runners/VisualRunner/AssemblyRunInfo.cs +++ /dev/null @@ -1,22 +0,0 @@ -#nullable enable -using System; -using System.Collections.Generic; -using Xunit; - -namespace Microsoft.Maui.TestUtils.DeviceTests.Runners.VisualRunner; - -public class AssemblyRunInfo -{ - public AssemblyRunInfo(string assemblyFileName, TestAssemblyConfiguration configuration, IList testCases) - { - AssemblyFileName = assemblyFileName ?? throw new ArgumentNullException(nameof(assemblyFileName)); - Configuration = configuration ?? throw new ArgumentNullException(nameof(configuration)); - TestCases = testCases ?? throw new ArgumentNullException(nameof(testCases)); - } - - public string AssemblyFileName { get; } - - public TestAssemblyConfiguration Configuration { get; } - - public IList TestCases { get; } -} diff --git a/test/MauiTestUtils/DeviceTests.Runners/VisualRunner/Converters/RunStatusToColorConverter.cs b/test/MauiTestUtils/DeviceTests.Runners/VisualRunner/Converters/RunStatusToColorConverter.cs deleted file mode 100644 index fd540f8bf3..0000000000 --- a/test/MauiTestUtils/DeviceTests.Runners/VisualRunner/Converters/RunStatusToColorConverter.cs +++ /dev/null @@ -1,29 +0,0 @@ -#nullable enable -using System; -using System.Globalization; -using Microsoft.Maui.Controls; -using Microsoft.Maui.Graphics; - -namespace Microsoft.Maui.TestUtils.DeviceTests.Runners.VisualRunner; - -internal class RunStatusToColorConverter : IValueConverter -{ - public object Convert(object value, Type targetType, object parameter, CultureInfo culture) - { - if (value is not RunStatus status || Application.Current == null) - return Colors.Red; - - return status switch - { - RunStatus.Ok => Application.Current.Resources["VisualRunnerSuccessfulTestsColor"], - RunStatus.Failed => Application.Current.Resources["VisualRunnerFailedTestsColor"], - RunStatus.NoTests => Application.Current.Resources["VisualRunnerNoTestsColor"], - RunStatus.NotRun => Application.Current.Resources["VisualRunnerNotRunTestsColor"], - RunStatus.Skipped => Application.Current.Resources["VisualRunnerSkippedTestsColor"], - _ => throw new ArgumentOutOfRangeException(nameof(value)), - }; - } - - public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => - throw new NotImplementedException(); -} diff --git a/test/MauiTestUtils/DeviceTests.Runners/VisualRunner/DeviceRunner.cs b/test/MauiTestUtils/DeviceTests.Runners/VisualRunner/DeviceRunner.cs deleted file mode 100644 index 92f5c8dde9..0000000000 --- a/test/MauiTestUtils/DeviceTests.Runners/VisualRunner/DeviceRunner.cs +++ /dev/null @@ -1,345 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Reflection; -using System.Threading; -using System.Threading.Tasks; -using Microsoft.Extensions.Logging; -using Microsoft.Maui.Controls.Xaml; -using Xunit; - -[assembly: XamlCompilation(XamlCompilationOptions.Compile)] - -namespace Microsoft.Maui.TestUtils.DeviceTests.Runners.VisualRunner; - -public class DeviceRunner : ITestListener, ITestRunner -{ - private readonly SynchronizationContext context = SynchronizationContext.Current; - private readonly AsyncLock executionLock = new AsyncLock(); - private readonly ITestNavigation _navigation; - private readonly TestRunLogger _logger; - private volatile bool cancelled; - - public DeviceRunner(IReadOnlyCollection testAssemblies, ITestNavigation navigation, ILogger logger) - { - TestAssemblies = testAssemblies; - _navigation = navigation; - _logger = new TestRunLogger(logger); - } - - public IReadOnlyCollection TestAssemblies { get; } - - public void RecordResult(TestResultViewModel result) - { - _logger.LogTestResult(result); - } - - public Task RunAsync(TestCaseViewModel test) - { - return RunAsync(new[] { test }); - } - - public Task RunAsync(IEnumerable tests, string message = null) - { - var groups = tests - .GroupBy(t => t.AssemblyFileName) - .Select(g => new AssemblyRunInfo( - g.Key, - GetConfiguration(Path.GetFileNameWithoutExtension(g.Key)), - g.ToList())) - .ToList(); - - return RunAsync(groups, message); - } - - public async Task RunAsync(IReadOnlyList runInfos, string message = null) - { - using (await executionLock.LockAsync()) - { - if (message == null) - { - message = runInfos.Count > 1 || runInfos.FirstOrDefault()?.TestCases.Count > 1 - ? "Run Multiple Tests" - : runInfos.FirstOrDefault()?.TestCases.FirstOrDefault()?.DisplayName; - } - - _logger.LogTestStart(message); - - try - { - await RunTests(() => runInfos); - } - finally - { - _logger.LogTestComplete(); - } - } - } - - public event Action OnDiagnosticMessage; - - public Task> DiscoverAsync() - { - var tcs = new TaskCompletionSource>(); - - RunAsync(() => - { - try - { - var runInfos = DiscoverTestsInAssemblies(); - var list = runInfos.Select(ri => new TestAssemblyViewModel(ri, _navigation, this)).ToList(); - - tcs.SetResult(list); - } - catch (Exception e) - { - tcs.SetException(e); - } - }); - - return tcs.Task; - } - - private IEnumerable DiscoverTestsInAssemblies() - { - var result = new List(); - - try - { - foreach (var assm in TestAssemblies) - { -#if WINDOWS - var nameWithoutExt = assm.GetName().Name; - var assemblyFileName = Storage.FileSystemUtils.PlatformGetFullAppPackageFilePath($"{nameWithoutExt}.dll"); -#elif ANDROID - // this is required to exist, but is not used - var assemblyFileName = assm.GetName().Name + ".dll"; - assemblyFileName = Path.Combine(Android.App.Application.Context.CacheDir.AbsolutePath, assemblyFileName); - if (!File.Exists(assemblyFileName)) - File.Create(assemblyFileName).Close(); -#else - var assemblyFileName = assm.Location; -#endif - - var configuration = GetConfiguration(assemblyFileName); - var discoveryOptions = TestFrameworkOptions.ForDiscovery(configuration); - - try - { - if (cancelled) - break; - - using (var framework = new XunitFrontController(AppDomainSupport.Denied, assemblyFileName, null, false)) - using (var sink = new TestDiscoverySink(() => cancelled)) - { - framework.Find(false, sink, discoveryOptions); - sink.Finished.WaitOne(); - - result.Add(new AssemblyRunInfo( - assemblyFileName, - configuration, - sink.TestCases.Select(tc => new TestCaseViewModel(assemblyFileName, tc)).ToList())); - } - } - catch (Exception e) - { - Debug.WriteLine(e); - } - } - } - catch (Exception e) - { - Debug.WriteLine(e); - } - - return result; - } - - private static TestAssemblyConfiguration GetConfiguration(string assemblyName) - { - var stream = GetConfigurationStreamForAssembly(assemblyName); - if (stream != null) - { - using (stream) - { - return ConfigReader.Load(stream); - } - } - - return new TestAssemblyConfiguration(); - } - - private static Stream GetConfigurationStreamForAssembly(string assemblyName) - { -#if __ANDROID__ - var assets = Android.App.Application.Context.Assets; - var allAssets = assets.List(string.Empty); - - if (allAssets.Contains($"{assemblyName}.xunit.runner.json")) - return assets.Open($"{assemblyName}.xunit.runner.json"); - - if (allAssets.Contains("xunit.runner.json")) - return assets.Open("xunit.runner.json"); -#else - - // See if there's a directory with the assm name. this might be the case for appx - if (Directory.Exists(assemblyName)) - { - if (File.Exists(Path.Combine(assemblyName, $"{assemblyName}.xunit.runner.json"))) - { - return File.OpenRead(Path.Combine(assemblyName, $"{assemblyName}.xunit.runner.json")); - } - - if (File.Exists(Path.Combine(assemblyName, "xunit.runner.json"))) - { - return File.OpenRead(Path.Combine(assemblyName, "xunit.runner.json")); - } - } - - // Fallback to working dir - - // look for a file called assemblyName.xunit.runner.json first - if (File.Exists($"{assemblyName}.xunit.runner.json")) - { - return File.OpenRead($"{assemblyName}.xunit.runner.json"); - } - - if (File.Exists("xunit.runner.json")) - { - return File.OpenRead("xunit.runner.json"); - } -#endif - - return null; - } - - private Task RunTests(Func> testCaseAccessor) - { - var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - - void Handler() - { - var toDispose = new List(); - - try - { - cancelled = false; - var assemblies = testCaseAccessor(); - var parallelizeAssemblies = assemblies.All(runInfo => runInfo.Configuration.ParallelizeAssemblyOrDefault); - - if (parallelizeAssemblies) - { - assemblies - .Select(runInfo => RunTestsInAssemblyAsync(toDispose, runInfo)) - .ToList() - .ForEach(@event => @event.WaitOne()); - } - else - { - foreach (var runInfo in assemblies) - { - RunTestsInAssembly(toDispose, runInfo); - } - } - } - catch (Exception e) - { - tcs.SetException(e); - } - finally - { - toDispose.ForEach(disposable => disposable.Dispose()); - tcs.TrySetResult(null); - } - } - - RunAsync(Handler); - - return tcs.Task; - } - - private void RunTestsInAssembly(List toDispose, AssemblyRunInfo runInfo) - { - if (cancelled) - return; - - var assemblyFileName = runInfo.AssemblyFileName; - - var longRunningSeconds = runInfo.Configuration.LongRunningTestSecondsOrDefault; - - var controller = new XunitFrontController(AppDomainSupport.Denied, assemblyFileName); - - lock (toDispose) - toDispose.Add(controller); - - var xunitTestCases = runInfo.TestCases - .Select(tc => new { vm = tc, tc = tc.TestCase }) - .Where(tc => tc.tc.UniqueID != null) - .ToDictionary(tc => tc.tc, tc => tc.vm); - - var executionOptions = TestFrameworkOptions.ForExecution(runInfo.Configuration); - - var diagSink = new DiagnosticMessageSink(d => context.Post(_ => OnDiagnosticMessage?.Invoke(d), null), runInfo.AssemblyFileName, executionOptions.GetDiagnosticMessagesOrDefault()); - - var deviceExecSink = new DeviceExecutionSink(xunitTestCases, this, context); - - var resultsSink = new ExecutionSink(deviceExecSink, new ExecutionSinkOptions { CancelThunk = () => cancelled }); - if (longRunningSeconds > 0) - { - resultsSink = new ExecutionSink(resultsSink, new ExecutionSinkOptions - { - LongRunningTestTime = TimeSpan.FromSeconds(longRunningSeconds), - DiagnosticMessageSink = diagSink - }); - } - - var assm = new XunitProjectAssembly() { AssemblyFilename = runInfo.AssemblyFileName }; - deviceExecSink.OnMessage(new TestAssemblyExecutionStarting(assm, executionOptions)); - - controller.RunTests(xunitTestCases.Select(tc => tc.Value.TestCase).ToList(), resultsSink, executionOptions); - resultsSink.Finished.WaitOne(); - - deviceExecSink.OnMessage(new TestAssemblyExecutionFinished(assm, executionOptions, resultsSink.ExecutionSummary)); - } - - private ManualResetEvent RunTestsInAssemblyAsync(List toDispose, AssemblyRunInfo runInfo) - { - var @event = new ManualResetEvent(false); - - void Handler() - { - try - { - RunTestsInAssembly(toDispose, runInfo); - } - finally - { - @event.Set(); - } - } - - RunAsync(Handler); - - return @event; - } - - private static async void RunAsync(Action action) - { - var task = Task.Factory.StartNew(action, CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Default); - - try - { - await task; - } - catch (Exception e) - { - if (Debugger.IsAttached) - { - Debugger.Break(); - Debug.WriteLine(e); - } - } - } -} diff --git a/test/MauiTestUtils/DeviceTests.Runners/VisualRunner/ITestListener.cs b/test/MauiTestUtils/DeviceTests.Runners/VisualRunner/ITestListener.cs deleted file mode 100644 index dd6681ca21..0000000000 --- a/test/MauiTestUtils/DeviceTests.Runners/VisualRunner/ITestListener.cs +++ /dev/null @@ -1,7 +0,0 @@ -#nullable enable -namespace Microsoft.Maui.TestUtils.DeviceTests.Runners.VisualRunner; - -public interface ITestListener -{ - void RecordResult(TestResultViewModel result); -} diff --git a/test/MauiTestUtils/DeviceTests.Runners/VisualRunner/ITestRunner.cs b/test/MauiTestUtils/DeviceTests.Runners/VisualRunner/ITestRunner.cs deleted file mode 100644 index c8c4630270..0000000000 --- a/test/MauiTestUtils/DeviceTests.Runners/VisualRunner/ITestRunner.cs +++ /dev/null @@ -1,19 +0,0 @@ -#nullable enable -using System; -using System.Collections.Generic; -using System.Threading.Tasks; - -namespace Microsoft.Maui.TestUtils.DeviceTests.Runners.VisualRunner; - -internal interface ITestRunner -{ - Task> DiscoverAsync(); - - Task RunAsync(TestCaseViewModel test); - - Task RunAsync(IEnumerable tests, string? message = null); - - Task RunAsync(IReadOnlyList runInfos, string? message = null); - - event Action OnDiagnosticMessage; -} diff --git a/test/MauiTestUtils/DeviceTests.Runners/VisualRunner/MauiVisualRunnerApp.xaml b/test/MauiTestUtils/DeviceTests.Runners/VisualRunner/MauiVisualRunnerApp.xaml deleted file mode 100644 index af7b2cbc7b..0000000000 --- a/test/MauiTestUtils/DeviceTests.Runners/VisualRunner/MauiVisualRunnerApp.xaml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - #ff7f00 - DarkGray - #ff7700 - Red - Green - - - - - - \ No newline at end of file diff --git a/test/MauiTestUtils/DeviceTests.Runners/VisualRunner/MauiVisualRunnerApp.xaml.cs b/test/MauiTestUtils/DeviceTests.Runners/VisualRunner/MauiVisualRunnerApp.xaml.cs deleted file mode 100644 index c364f70e98..0000000000 --- a/test/MauiTestUtils/DeviceTests.Runners/VisualRunner/MauiVisualRunnerApp.xaml.cs +++ /dev/null @@ -1,37 +0,0 @@ -#nullable enable -using Microsoft.Extensions.Logging; -using Microsoft.Maui.Controls; -using Microsoft.Maui.TestUtils.DeviceTests.Runners.VisualRunner.Pages; - -namespace Microsoft.Maui.TestUtils.DeviceTests.Runners.VisualRunner; - -public partial class MauiVisualRunnerApp : Application -{ - private readonly TestOptions _options; - private readonly ILogger _logger; - - public MauiVisualRunnerApp(TestOptions options, ILogger logger) - { - _options = options; - _logger = logger; - - InitializeComponent(); - } - - protected override Window CreateWindow(IActivationState? activationState) - { - var hp = new HomePage(); - - var nav = new TestNavigator(hp.Navigation); - - var runner = new DeviceRunner(_options.Assemblies, nav, _logger); - - var vm = new HomeViewModel(nav, runner); - - hp.BindingContext = vm; - - var navPage = new NavigationPage(hp); - - return new Window(navPage); - } -} diff --git a/test/MauiTestUtils/DeviceTests.Runners/VisualRunner/Navigation/INavigation.cs b/test/MauiTestUtils/DeviceTests.Runners/VisualRunner/Navigation/INavigation.cs deleted file mode 100644 index bfc487437f..0000000000 --- a/test/MauiTestUtils/DeviceTests.Runners/VisualRunner/Navigation/INavigation.cs +++ /dev/null @@ -1,9 +0,0 @@ -#nullable enable -using System.Threading.Tasks; - -namespace Microsoft.Maui.TestUtils.DeviceTests.Runners.VisualRunner; - -public interface ITestNavigation -{ - Task NavigateTo(PageType page, object? dataContext = null); -} diff --git a/test/MauiTestUtils/DeviceTests.Runners/VisualRunner/Navigation/Navigator.cs b/test/MauiTestUtils/DeviceTests.Runners/VisualRunner/Navigation/Navigator.cs deleted file mode 100644 index 5209bd182d..0000000000 --- a/test/MauiTestUtils/DeviceTests.Runners/VisualRunner/Navigation/Navigator.cs +++ /dev/null @@ -1,33 +0,0 @@ -#nullable enable -using System; -using System.Threading.Tasks; -using Microsoft.Maui.Controls; -using Microsoft.Maui.TestUtils.DeviceTests.Runners.VisualRunner.Pages; - -namespace Microsoft.Maui.TestUtils.DeviceTests.Runners.VisualRunner; - -internal class TestNavigator : ITestNavigation -{ - private readonly INavigation _navigation; - - public TestNavigator(INavigation navigation) - { - _navigation = navigation; - } - - public Task NavigateTo(PageType page, object? dataContext = null) - { - ContentPage p = page switch - { - PageType.Home => new HomePage(), - PageType.AssemblyTestList => new TestAssemblyPage(), - PageType.TestResult => new TestResultPage(), - PageType.Credits => new CreditsPage(), - _ => throw new ArgumentOutOfRangeException(nameof(page)), - }; - - p.BindingContext = dataContext; - - return _navigation.PushAsync(p); - } -} diff --git a/test/MauiTestUtils/DeviceTests.Runners/VisualRunner/Navigation/PageType.cs b/test/MauiTestUtils/DeviceTests.Runners/VisualRunner/Navigation/PageType.cs deleted file mode 100644 index ed539bc751..0000000000 --- a/test/MauiTestUtils/DeviceTests.Runners/VisualRunner/Navigation/PageType.cs +++ /dev/null @@ -1,11 +0,0 @@ -#nullable enable - -namespace Microsoft.Maui.TestUtils.DeviceTests.Runners.VisualRunner; - -public enum PageType -{ - Home, - AssemblyTestList, - TestResult, - Credits -} diff --git a/test/MauiTestUtils/DeviceTests.Runners/VisualRunner/Pages/CreditsPage.xaml b/test/MauiTestUtils/DeviceTests.Runners/VisualRunner/Pages/CreditsPage.xaml deleted file mode 100644 index 54339403a7..0000000000 --- a/test/MauiTestUtils/DeviceTests.Runners/VisualRunner/Pages/CreditsPage.xaml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - \ No newline at end of file diff --git a/test/MauiTestUtils/DeviceTests.Runners/VisualRunner/Pages/CreditsPage.xaml.cs b/test/MauiTestUtils/DeviceTests.Runners/VisualRunner/Pages/CreditsPage.xaml.cs deleted file mode 100644 index 7f627713b2..0000000000 --- a/test/MauiTestUtils/DeviceTests.Runners/VisualRunner/Pages/CreditsPage.xaml.cs +++ /dev/null @@ -1,20 +0,0 @@ -#nullable enable -using Microsoft.Maui.ApplicationModel; -using Microsoft.Maui.Controls; - -namespace Microsoft.Maui.TestUtils.DeviceTests.Runners.VisualRunner.Pages; - -public partial class CreditsPage : ContentPage -{ - public CreditsPage() - { - InitializeComponent(); - } - - private void OnNavigating(object? sender, WebNavigatingEventArgs e) - { - Browser.OpenAsync(e.Url); - - e.Cancel = true; - } -} diff --git a/test/MauiTestUtils/DeviceTests.Runners/VisualRunner/Pages/HomePage.xaml b/test/MauiTestUtils/DeviceTests.Runners/VisualRunner/Pages/HomePage.xaml deleted file mode 100644 index fcc922ea0a..0000000000 --- a/test/MauiTestUtils/DeviceTests.Runners/VisualRunner/Pages/HomePage.xaml +++ /dev/null @@ -1,66 +0,0 @@ - - - - -