Skip to content

Commit

Permalink
[tests] Fix a few nullability issues in cecil-tests and the .NET test…
Browse files Browse the repository at this point in the history
…s. (xamarin#17095)

Also make any nullability warnings show up as errors.
  • Loading branch information
rolfbjarne authored Dec 21, 2022
1 parent a7502b2 commit e99c71a
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
1 change: 1 addition & 0 deletions tests/cecil-tests/cecil-tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<AssemblyName>cecil-tests</AssemblyName>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<WarningsAsErrors>Nullable</WarningsAsErrors>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
Expand Down
2 changes: 2 additions & 0 deletions tests/dotnet/UnitTests/DotNetUnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<TargetFramework>net$(BundledNETCoreAppTargetFrameworkVersion)</TargetFramework>
<IsPackable>false</IsPackable>
<DefineConstants>$(DefineConstants);NET;TESTS</DefineConstants>
<Nullable>enable</Nullable>
<WarningsAsErrors>Nullable</WarningsAsErrors>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion tests/dotnet/UnitTests/PartialAppManifestTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
14 changes: 7 additions & 7 deletions tests/dotnet/UnitTests/ProjectTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion tests/dotnet/UnitTests/TestBaseClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e99c71a

Please sign in to comment.