[dotnet] Add unit tests for archiving, package creation and ipa creation.
This commit is contained in:
Родитель
46128ac62e
Коммит
d22cf7da8c
|
@ -0,0 +1,96 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
|
||||
using NUnit.Framework;
|
||||
|
||||
using Xamarin.Utils;
|
||||
|
||||
using Microsoft.Build.Framework;
|
||||
using Microsoft.Build.Logging.StructuredLogger;
|
||||
|
||||
namespace Xamarin.Tests {
|
||||
[TestFixture]
|
||||
public class PostBuildTest : TestBaseClass {
|
||||
[Test]
|
||||
[TestCase (ApplePlatform.iOS, "ios-arm64")]
|
||||
[TestCase (ApplePlatform.iOS, "ios-arm64;ios-arm")]
|
||||
[TestCase (ApplePlatform.TVOS, "tvos-arm64")]
|
||||
[TestCase (ApplePlatform.MacCatalyst, "maccatalyst-arm64")]
|
||||
[TestCase (ApplePlatform.MacCatalyst, "maccatalyst-arm64;maccatalyst-x64")]
|
||||
[TestCase (ApplePlatform.MacOSX, "osx-x64")]
|
||||
[TestCase (ApplePlatform.MacOSX, "osx-arm64;osx-x64")]
|
||||
public void ArchiveTest (ApplePlatform platform, string runtimeIdentifiers)
|
||||
{
|
||||
var project = "MySimpleApp";
|
||||
Configuration.IgnoreIfIgnoredPlatform (platform);
|
||||
|
||||
var project_path = GetProjectPath (project, platform: platform);
|
||||
Clean (project_path);
|
||||
var properties = new Dictionary<string, string> (verbosity);
|
||||
var multiRid = runtimeIdentifiers.IndexOf (';') >= 0 ? "RuntimeIdentifiers" : "RuntimeIdentifier";
|
||||
if (!string.IsNullOrEmpty (runtimeIdentifiers))
|
||||
properties [multiRid] = runtimeIdentifiers;
|
||||
properties ["ArchiveOnBuild"] = "true";
|
||||
|
||||
var result = DotNet.AssertBuild (project_path, properties);
|
||||
var reader = new BinLogReader ();
|
||||
var records = reader.ReadRecords (result.BinLogPath).ToList ();
|
||||
var findString = "Output Property: ArchiveDir";
|
||||
var archiveDirRecord = records.Where (v => v?.Args?.Message?.Contains (findString) == true).ToList ();
|
||||
Assert.That (archiveDirRecord.Count, Is.GreaterThan (0), "ArchiveDir");
|
||||
var archiveDir = archiveDirRecord [0].Args.Message.Substring (findString.Length + 1).Trim ();
|
||||
Assert.That (archiveDir, Does.Exist, "Archive directory existence");
|
||||
}
|
||||
|
||||
[Test]
|
||||
[TestCase (ApplePlatform.iOS, "ios-arm64")]
|
||||
[TestCase (ApplePlatform.iOS, "ios-arm64;ios-arm")]
|
||||
[TestCase (ApplePlatform.TVOS, "tvos-arm64")]
|
||||
public void BuildIpaTest (ApplePlatform platform, string runtimeIdentifiers)
|
||||
{
|
||||
var project = "MySimpleApp";
|
||||
Configuration.IgnoreIfIgnoredPlatform (platform);
|
||||
|
||||
var project_path = GetProjectPath (project, platform: platform);
|
||||
Clean (project_path);
|
||||
var properties = new Dictionary<string, string> (verbosity);
|
||||
var multiRid = runtimeIdentifiers.IndexOf (';') >= 0 ? "RuntimeIdentifiers" : "RuntimeIdentifier";
|
||||
if (!string.IsNullOrEmpty (runtimeIdentifiers))
|
||||
properties [multiRid] = runtimeIdentifiers;
|
||||
properties ["BuildIpa"] = "true";
|
||||
|
||||
DotNet.AssertBuild (project_path, properties);
|
||||
|
||||
var appPath = Path.Combine (Path.GetDirectoryName (project_path), "bin", "Debug", platform.ToFramework (), runtimeIdentifiers.IndexOf (';') >= 0 ? string.Empty : runtimeIdentifiers, $"{project}.app");
|
||||
var pkgPath = Path.Combine (appPath, "..", $"{project}.ipa");
|
||||
Assert.That (pkgPath, Does.Exist, "pkg creation");
|
||||
}
|
||||
|
||||
[Test]
|
||||
[TestCase (ApplePlatform.MacCatalyst, "maccatalyst-arm64")]
|
||||
[TestCase (ApplePlatform.MacCatalyst, "maccatalyst-arm64;maccatalyst-x64")]
|
||||
[TestCase (ApplePlatform.MacOSX, "osx-x64")]
|
||||
[TestCase (ApplePlatform.MacOSX, "osx-arm64;osx-x64")]
|
||||
public void BuildPackageTest (ApplePlatform platform, string runtimeIdentifiers)
|
||||
{
|
||||
var project = "MySimpleApp";
|
||||
Configuration.IgnoreIfIgnoredPlatform (platform);
|
||||
|
||||
var project_path = GetProjectPath (project, platform: platform);
|
||||
Clean (project_path);
|
||||
var properties = new Dictionary<string, string> (verbosity);
|
||||
var multiRid = runtimeIdentifiers.IndexOf (';') >= 0 ? "RuntimeIdentifiers" : "RuntimeIdentifier";
|
||||
if (!string.IsNullOrEmpty (runtimeIdentifiers))
|
||||
properties [multiRid] = runtimeIdentifiers;
|
||||
properties ["CreatePackage"] = "true";
|
||||
|
||||
DotNet.AssertBuild (project_path, properties);
|
||||
|
||||
var appPath = Path.Combine (Path.GetDirectoryName (project_path), "bin", "Debug", platform.ToFramework (), runtimeIdentifiers.IndexOf (';') >= 0 ? string.Empty : runtimeIdentifiers, $"{project}.app");
|
||||
var pkgPath = Path.Combine (appPath, "..", $"{project}.pkg");
|
||||
Assert.That (pkgPath, Does.Exist, "pkg creation");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -14,43 +14,7 @@ using Xamarin.MacDev;
|
|||
|
||||
namespace Xamarin.Tests {
|
||||
[TestFixture]
|
||||
public class DotNetProjectTest {
|
||||
Dictionary<string, string> verbosity = new Dictionary<string, string> {
|
||||
{ "MtouchExtraArgs", "-v" },
|
||||
{ "MonoBundlingExtraArgs", "-v" },
|
||||
};
|
||||
|
||||
string GetProjectPath (string project, string subdir = null, ApplePlatform? platform = null)
|
||||
{
|
||||
var project_dir = Path.Combine (Configuration.SourceRoot, "tests", "dotnet", project);
|
||||
if (!string.IsNullOrEmpty (subdir))
|
||||
project_dir = Path.Combine (project_dir, subdir);
|
||||
|
||||
if (platform.HasValue)
|
||||
project_dir = Path.Combine (project_dir, platform.Value.AsString ());
|
||||
|
||||
var project_path = Path.Combine (project_dir, project + ".csproj");
|
||||
if (!File.Exists (project_path))
|
||||
project_path = Path.ChangeExtension (project_path, "sln");
|
||||
|
||||
if (!File.Exists (project_path))
|
||||
throw new FileNotFoundException ($"Could not find the project or solution {project} - {project_path} does not exist.");
|
||||
|
||||
return project_path;
|
||||
}
|
||||
|
||||
void Clean (string project_path)
|
||||
{
|
||||
var dirs = Directory.GetDirectories (Path.GetDirectoryName (project_path), "*", SearchOption.AllDirectories);
|
||||
dirs = dirs.OrderBy (v => v.Length).Reverse ().ToArray (); // If we have nested directories, make sure to delete the nested one first
|
||||
foreach (var dir in dirs) {
|
||||
var name = Path.GetFileName (dir);
|
||||
if (name != "bin" && name != "obj")
|
||||
continue;
|
||||
Directory.Delete (dir, true);
|
||||
}
|
||||
}
|
||||
|
||||
public class DotNetProjectTest : TestBaseClass {
|
||||
[Test]
|
||||
[TestCase (null)]
|
||||
[TestCase ("iossimulator-x86")]
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using Mono.Cecil;
|
||||
|
||||
using NUnit.Framework;
|
||||
|
||||
using Xamarin.Utils;
|
||||
using Xamarin.Tests;
|
||||
using Xamarin.MacDev;
|
||||
|
||||
namespace Xamarin.Tests {
|
||||
[TestFixture]
|
||||
public abstract class TestBaseClass {
|
||||
protected Dictionary<string, string> verbosity = new Dictionary<string, string> {
|
||||
{ "MtouchExtraArgs", "-v" },
|
||||
{ "MonoBundlingExtraArgs", "-v" },
|
||||
};
|
||||
|
||||
protected string GetProjectPath (string project, string subdir = null, ApplePlatform? platform = null)
|
||||
{
|
||||
var project_dir = Path.Combine (Configuration.SourceRoot, "tests", "dotnet", project);
|
||||
if (!string.IsNullOrEmpty (subdir))
|
||||
project_dir = Path.Combine (project_dir, subdir);
|
||||
|
||||
if (platform.HasValue)
|
||||
project_dir = Path.Combine (project_dir, platform.Value.AsString ());
|
||||
|
||||
var project_path = Path.Combine (project_dir, project + ".csproj");
|
||||
if (!File.Exists (project_path))
|
||||
project_path = Path.ChangeExtension (project_path, "sln");
|
||||
|
||||
if (!File.Exists (project_path))
|
||||
throw new FileNotFoundException ($"Could not find the project or solution {project} - {project_path} does not exist.");
|
||||
|
||||
return project_path;
|
||||
}
|
||||
|
||||
protected void Clean (string project_path)
|
||||
{
|
||||
var dirs = Directory.GetDirectories (Path.GetDirectoryName (project_path), "*", SearchOption.AllDirectories);
|
||||
dirs = dirs.OrderBy (v => v.Length).Reverse ().ToArray (); // If we have nested directories, make sure to delete the nested one first
|
||||
foreach (var dir in dirs) {
|
||||
var name = Path.GetFileName (dir);
|
||||
if (name != "bin" && name != "obj")
|
||||
continue;
|
||||
Directory.Delete (dir, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче