From 6262887e0be413134376e493e0d31d43d09bdc44 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Tue, 21 Apr 2026 10:39:16 +0200 Subject: [PATCH 1/4] [tests] Enable nullability in Touch.Unit. --- .../Touch.Client/Runner/HttpTextWriter.cs | 16 +- .../Touch.Client/Runner/MacRunner.cs | 2 +- .../Runner/NUnitOutputTextWriter.cs | 15 +- .../Touch.Client/Runner/TcpTextWriter.cs | 10 +- .../Touch.Client/Runner/TestCaseElement.cs | 20 +- .../Touch.Client/Runner/TestElement.cs | 10 +- .../Touch.Client/Runner/TestSuiteElement.cs | 7 +- .../Touch.Client/Runner/TouchOptions.cs | 19 +- .../Touch.Client/Runner/TouchRunner.cs | 193 ++++++++++-------- .../Runner/TouchViewController.cs | 34 +-- .../Touch.Client/dotnet/shared.csproj | 3 + 11 files changed, 197 insertions(+), 132 deletions(-) diff --git a/tests/common/Touch.Unit/Touch.Client/Runner/HttpTextWriter.cs b/tests/common/Touch.Unit/Touch.Client/Runner/HttpTextWriter.cs index 2e97df0bbd96..6d4e40142955 100644 --- a/tests/common/Touch.Unit/Touch.Client/Runner/HttpTextWriter.cs +++ b/tests/common/Touch.Unit/Touch.Client/Runner/HttpTextWriter.cs @@ -16,7 +16,7 @@ namespace MonoTouch.NUnit { class HttpTextWriter : TextWriter { - public string HostName; + public string? HostName; public int Port; TaskCompletionSource finished = new TaskCompletionSource (); @@ -52,7 +52,7 @@ Task SendData (NSUrl url, string uploadData) var tcs = new TaskCompletionSource (); var request = new NSMutableUrlRequest (url); request.HttpMethod = "POST"; - var rv = NSUrlSession.SharedSession.CreateUploadTask (request, NSData.FromString (uploadData), (NSData data, NSUrlResponse response, NSError error) => { + var rv = NSUrlSession.SharedSession.CreateUploadTask (request, NSData.FromString (uploadData), (NSData? data, NSUrlResponse? response, NSError? error) => { if (error is not null) { Console.WriteLine ("Failed to send data to {0}: {1}", url.AbsoluteString, error); tcs.SetResult (false); @@ -67,7 +67,12 @@ Task SendData (NSUrl url, string uploadData) async Task SendData (string action, string uploadData) { + if (string.IsNullOrEmpty (HostName)) + throw new InvalidOperationException ("No host name specified."); + var url = NSUrl.FromString ("http://" + HostName + ":" + Port + "/" + action); + if (url is null) + throw new InvalidOperationException ("Failed to create the reporting url."); int attempts_left = 10; while (!await SendData (url, uploadData)) { @@ -105,13 +110,14 @@ public override void Write (char value) log.Append (value); } - public override void Write (char [] buffer) + public override void Write (char []? buffer) { Console.Out.Write (buffer); - log.Append (buffer); + if (buffer is not null) + log.Append (buffer); } - public override void WriteLine (string value) + public override void WriteLine (string? value) { Console.Out.WriteLine (value); log.AppendLine (value); diff --git a/tests/common/Touch.Unit/Touch.Client/Runner/MacRunner.cs b/tests/common/Touch.Unit/Touch.Client/Runner/MacRunner.cs index 4f1eaf0e0443..2cbaf024afe4 100644 --- a/tests/common/Touch.Unit/Touch.Client/Runner/MacRunner.cs +++ b/tests/common/Touch.Unit/Touch.Client/Runner/MacRunner.cs @@ -67,7 +67,7 @@ static async Task RunTestsAsync (TouchOptions options, Assembly [] assembl await runner.RunAsync (); - return !runner.Result.IsFailure (); + return runner.Result is not null && !runner.Result.IsFailure (); } protected override void WriteDeviceInformation (TextWriter writer) diff --git a/tests/common/Touch.Unit/Touch.Client/Runner/NUnitOutputTextWriter.cs b/tests/common/Touch.Unit/Touch.Client/Runner/NUnitOutputTextWriter.cs index 78da78b69896..cfb459fe7fbc 100644 --- a/tests/common/Touch.Unit/Touch.Client/Runner/NUnitOutputTextWriter.cs +++ b/tests/common/Touch.Unit/Touch.Client/Runner/NUnitOutputTextWriter.cs @@ -37,12 +37,12 @@ public class NUnitOutputTextWriter : TextWriter { StringBuilder extra_data = new StringBuilder (); XmlMode mode; - public NUnitOutputTextWriter (BaseTouchRunner runner, TextWriter baseWriter, OutputWriter xmlWriter) + public NUnitOutputTextWriter (BaseTouchRunner runner, TextWriter? baseWriter, OutputWriter? xmlWriter) : this (runner, baseWriter, xmlWriter, XmlMode.Default) { } - public NUnitOutputTextWriter (BaseTouchRunner runner, TextWriter baseWriter, OutputWriter xmlWriter, XmlMode xmlMode) + public NUnitOutputTextWriter (BaseTouchRunner runner, TextWriter? baseWriter, OutputWriter? xmlWriter, XmlMode xmlMode) { Runner = runner; BaseWriter = baseWriter ?? Console.Out; @@ -60,7 +60,7 @@ public override Encoding Encoding { public BaseTouchRunner Runner { get; private set; } - public OutputWriter XmlOutputWriter { get; private set; } + public OutputWriter? XmlOutputWriter { get; private set; } public override void Write (char value) { @@ -70,7 +70,7 @@ public override void Write (char value) extra_data.Append (value); } - public override void Write (string value) + public override void Write (string? value) { if (real_time_reporting) BaseWriter.Write (value); @@ -81,6 +81,7 @@ public override void Write (string value) public override void Close () { if (XmlOutputWriter is not null) { + var result = Runner.Result; // now we want the XML report to write real_time_reporting = true; // write to a temporary string, because NUnit2XmlOutputWriter.WriteResultFile closes the stream, @@ -88,7 +89,8 @@ public override void Close () var wrapped = mode == XmlMode.Wrapped; if (!wrapped) { - XmlOutputWriter.WriteResultFile (Runner.Result, BaseWriter); + if (result is not null) + XmlOutputWriter.WriteResultFile (result, BaseWriter); if (extra_data.Length > 0) { BaseWriter.Write (" $(NoWarn);CA1422 + + enable + Nullable From 06242312fe23005bdae687ddd59d1780d3644383 Mon Sep 17 00:00:00 2001 From: GitHub Actions Autoformatter Date: Tue, 21 Apr 2026 09:55:28 +0000 Subject: [PATCH 2/4] Auto-format source code --- tests/common/Touch.Unit/Touch.Client/Runner/TouchRunner.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/common/Touch.Unit/Touch.Client/Runner/TouchRunner.cs b/tests/common/Touch.Unit/Touch.Client/Runner/TouchRunner.cs index d1415c83fd7e..a2a873e133e8 100644 --- a/tests/common/Touch.Unit/Touch.Client/Runner/TouchRunner.cs +++ b/tests/common/Touch.Unit/Touch.Client/Runner/TouchRunner.cs @@ -594,7 +594,7 @@ SettingsDictionary CreateSettings (SettingsDictionary? settings) if (key is not null) { var name = key.ToString (); if (name is not null) - dict [name] = settings [key]; + dict [name] = settings [key]; } } } From 38da80fd3da39be5765ee5656ad757b0bcecd104 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Thu, 23 Apr 2026 10:38:46 +0200 Subject: [PATCH 3/4] Missing fix --- tests/introspection/ApiBaseTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/introspection/ApiBaseTest.cs b/tests/introspection/ApiBaseTest.cs index af67f58c996e..02cd37df96cd 100644 --- a/tests/introspection/ApiBaseTest.cs +++ b/tests/introspection/ApiBaseTest.cs @@ -101,7 +101,7 @@ protected TextWriter Writer { #if MONOMAC get { return Console.Out; } #else - get { return AppDelegate.Runner.Writer; } + get { return AppDelegate.Runner.Writer!; } #endif } From ea4ddff9fd288c896c3e7f1b34e1862785d42b9e Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Thu, 23 Apr 2026 18:00:43 +0200 Subject: [PATCH 4/4] Fix nullability errors in TouchViewController.GetAwesomeIcon - Add null check for CGContext from UIGraphics.GetCurrentContext() - Use var with null-coalescing for UIGraphics.GetImageFromCurrentImageContext() Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../Touch.Client/Runner/TouchViewController.cs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/tests/common/Touch.Unit/Touch.Client/Runner/TouchViewController.cs b/tests/common/Touch.Unit/Touch.Client/Runner/TouchViewController.cs index 7beeee4161e0..a9192e18a04b 100644 --- a/tests/common/Touch.Unit/Touch.Client/Runner/TouchViewController.cs +++ b/tests/common/Touch.Unit/Touch.Client/Runner/TouchViewController.cs @@ -256,15 +256,17 @@ static UIImage GetAwesomeIcon (Action render) float size = 20f; UIGraphics.BeginImageContextWithOptions (new CGSize (size, size), false, 0); using (var c = UIGraphics.GetCurrentContext ()) { - c.SetFillColor (1.0f, 1.0f, 1.0f, 1.0f); - c.SetStrokeColor (1.0f, 1.0f, 1.0f, 1.0f); - c.TranslateCTM (3f, size - 3f); - c.ScaleCTM (size / 1000, -size / 1000); - render (c); + if (c is not null) { + c.SetFillColor (1.0f, 1.0f, 1.0f, 1.0f); + c.SetStrokeColor (1.0f, 1.0f, 1.0f, 1.0f); + c.TranslateCTM (3f, size - 3f); + c.ScaleCTM (size / 1000, -size / 1000); + render (c); + } } - UIImage img = UIGraphics.GetImageFromCurrentImageContext (); + var img = UIGraphics.GetImageFromCurrentImageContext (); UIGraphics.EndImageContext (); - return img; + return img ?? new UIImage (); } #region generated code