From e99c71ad36ef471c461b659da0aeef28319e0fd1 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Wed, 21 Dec 2022 10:19:13 +0100 Subject: [PATCH] [tests] Fix a few nullability issues in cecil-tests and the .NET tests. (#17095) Also make any nullability warnings show up as errors. --- tests/cecil-tests/cecil-tests.csproj | 1 + tests/dotnet/UnitTests/DotNetUnitTests.csproj | 2 ++ tests/dotnet/UnitTests/PartialAppManifestTest.cs | 2 +- tests/dotnet/UnitTests/ProjectTest.cs | 14 +++++++------- tests/dotnet/UnitTests/TestBaseClass.cs | 2 +- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/tests/cecil-tests/cecil-tests.csproj b/tests/cecil-tests/cecil-tests.csproj index f9d6a85f505..50fc8c52d76 100644 --- a/tests/cecil-tests/cecil-tests.csproj +++ b/tests/cecil-tests/cecil-tests.csproj @@ -6,6 +6,7 @@ cecil-tests latest enable + Nullable diff --git a/tests/dotnet/UnitTests/DotNetUnitTests.csproj b/tests/dotnet/UnitTests/DotNetUnitTests.csproj index bec12dee723..c5fda93bbd9 100644 --- a/tests/dotnet/UnitTests/DotNetUnitTests.csproj +++ b/tests/dotnet/UnitTests/DotNetUnitTests.csproj @@ -3,6 +3,8 @@ net$(BundledNETCoreAppTargetFrameworkVersion) false $(DefineConstants);NET;TESTS + enable + Nullable diff --git a/tests/dotnet/UnitTests/PartialAppManifestTest.cs b/tests/dotnet/UnitTests/PartialAppManifestTest.cs index 1d1c843ccc2..02639d3beaf 100644 --- a/tests/dotnet/UnitTests/PartialAppManifestTest.cs +++ b/tests/dotnet/UnitTests/PartialAppManifestTest.cs @@ -17,7 +17,7 @@ public void Build (ApplePlatform platform, string runtimeIdentifiers) DotNet.AssertBuild (project_path, properties); var infoPlistPath = GetInfoPListPath (platform, appPath); - var infoPlist = PDictionary.FromFile (infoPlistPath); + var infoPlist = PDictionary.FromFile (infoPlistPath)!; Assert.AreEqual ("com.xamarin.mypartialappmanifestapp", infoPlist.GetString ("CFBundleIdentifier").Value, "CFBundleIdentifier"); Assert.AreEqual ("MyPartialAppManifestApp", infoPlist.GetString ("CFBundleDisplayName").Value, "CFBundleDisplayName"); Assert.AreEqual ("3.14", infoPlist.GetString ("CFBundleVersion").Value, "CFBundleVersion"); diff --git a/tests/dotnet/UnitTests/ProjectTest.cs b/tests/dotnet/UnitTests/ProjectTest.cs index c23f4ce20a8..8c2028a00fb 100644 --- a/tests/dotnet/UnitTests/ProjectTest.cs +++ b/tests/dotnet/UnitTests/ProjectTest.cs @@ -28,7 +28,7 @@ public void BuildMySingleView (string runtimeIdentifier) AssertThatLinkerExecuted (result); AssertAppContents (platform, appPath); var infoPlistPath = Path.Combine (appPath, "Info.plist"); - var infoPlist = PDictionary.FromFile (infoPlistPath); + var infoPlist = PDictionary.FromFile (infoPlistPath)!; Assert.AreEqual ("com.xamarin.mysingletitle", infoPlist.GetString ("CFBundleIdentifier").Value, "CFBundleIdentifier"); Assert.AreEqual ("MySingleTitle", infoPlist.GetString ("CFBundleDisplayName").Value, "CFBundleDisplayName"); Assert.AreEqual ("3.14", infoPlist.GetString ("CFBundleVersion").Value, "CFBundleVersion"); @@ -83,7 +83,7 @@ public void BuildMyCatalystApp (string runtimeIdentifier) AssertThatLinkerExecuted (result); AssertAppContents (platform, appPath); var infoPlistPath = Path.Combine (appPath, "Contents", "Info.plist"); - var infoPlist = PDictionary.FromFile (infoPlistPath); + var infoPlist = PDictionary.FromFile (infoPlistPath)!; Assert.AreEqual ("com.xamarin.mycatalystapp", infoPlist.GetString ("CFBundleIdentifier").Value, "CFBundleIdentifier"); Assert.AreEqual ("MyCatalystApp", infoPlist.GetString ("CFBundleDisplayName").Value, "CFBundleDisplayName"); Assert.AreEqual ("3.14", infoPlist.GetString ("CFBundleVersion").Value, "CFBundleVersion"); @@ -326,7 +326,7 @@ public void BuildFatApp (ApplePlatform platform, string runtimeIdentifiers) AssertThatLinkerExecuted (result); var infoPlistPath = GetInfoPListPath (platform, appPath); Assert.That (infoPlistPath, Does.Exist, "Info.plist"); - var infoPlist = PDictionary.FromFile (infoPlistPath); + var infoPlist = PDictionary.FromFile (infoPlistPath)!; Assert.AreEqual ("com.xamarin.mysimpleapp", infoPlist.GetString ("CFBundleIdentifier").Value, "CFBundleIdentifier"); Assert.AreEqual ("MySimpleApp", infoPlist.GetString ("CFBundleDisplayName").Value, "CFBundleDisplayName"); Assert.AreEqual ("3.14", infoPlist.GetString ("CFBundleVersion").Value, "CFBundleVersion"); @@ -357,7 +357,7 @@ public void BuildFatMonoTouchTest (ApplePlatform platform, string runtimeIdentif var appPath = Path.Combine (Path.GetDirectoryName (project_path)!, "bin", "Debug", platform.ToFramework (), "monotouchtest.app"); var infoPlistPath = GetInfoPListPath (platform, appPath); Assert.That (infoPlistPath, Does.Exist, "Info.plist"); - var infoPlist = PDictionary.FromFile (infoPlistPath); + var infoPlist = PDictionary.FromFile (infoPlistPath)!; Assert.AreEqual ("com.xamarin.monotouch-test", infoPlist.GetString ("CFBundleIdentifier").Value, "CFBundleIdentifier"); Assert.AreEqual ("MonoTouchTest", infoPlist.GetString ("CFBundleDisplayName").Value, "CFBundleDisplayName"); } @@ -577,7 +577,7 @@ public void BuildCoreCLR (ApplePlatform platform, string runtimeIdentifiers) AssertThatLinkerExecuted (rv); var infoPlistPath = GetInfoPListPath (platform, appPath); Assert.That (infoPlistPath, Does.Exist, "Info.plist"); - var infoPlist = PDictionary.FromFile (infoPlistPath); + var infoPlist = PDictionary.FromFile (infoPlistPath)!; Assert.AreEqual ("com.xamarin.mysimpleapp", infoPlist.GetString ("CFBundleIdentifier").Value, "CFBundleIdentifier"); Assert.AreEqual ("MySimpleApp", infoPlist.GetString ("CFBundleDisplayName").Value, "CFBundleDisplayName"); Assert.AreEqual ("3.14", infoPlist.GetString ("CFBundleVersion").Value, "CFBundleVersion"); @@ -689,7 +689,7 @@ public void AppWithResources (ApplePlatform platform, string runtimeIdentifiers) Assert.That (fontBFile, Does.Exist, "B.otf existence"); Assert.That (fontCFile, Does.Exist, "C.ttf existence"); - var plist = PDictionary.FromFile (GetInfoPListPath (platform, appPath)); + var plist = PDictionary.FromFile (GetInfoPListPath (platform, appPath))!; switch (platform) { case ApplePlatform.iOS: case ApplePlatform.TVOS: @@ -974,7 +974,7 @@ public void BuildNet6_0App (ApplePlatform platform, string runtimeIdentifiers) AssertThatLinkerExecuted (result); var infoPlistPath = GetInfoPListPath (platform, appPath); Assert.That (infoPlistPath, Does.Exist, "Info.plist"); - var infoPlist = PDictionary.FromFile (infoPlistPath); + var infoPlist = PDictionary.FromFile (infoPlistPath)!; Assert.AreEqual ("com.xamarin.mysimpleapp", infoPlist.GetString ("CFBundleIdentifier").Value, "CFBundleIdentifier"); Assert.AreEqual ("MySimpleApp", infoPlist.GetString ("CFBundleDisplayName").Value, "CFBundleDisplayName"); Assert.AreEqual ("6.0", infoPlist.GetString ("CFBundleVersion").Value, "CFBundleVersion"); diff --git a/tests/dotnet/UnitTests/TestBaseClass.cs b/tests/dotnet/UnitTests/TestBaseClass.cs index cf4fc02ad41..53770f38782 100644 --- a/tests/dotnet/UnitTests/TestBaseClass.cs +++ b/tests/dotnet/UnitTests/TestBaseClass.cs @@ -389,7 +389,7 @@ protected bool TryGetEntitlements (string nativeExecutable, [NotNullWhen (true)] Assert.AreEqual (0, rv, $"'codesign {string.Join (" ", args)}' failed:\n{codesignOutput}"); if (File.Exists (entitlementsPath)) { entitlements = PDictionary.FromFile (entitlementsPath); - return true; + return entitlements is not null; } entitlements = null; return false;