[tests] Add a test to make sure the protocol attributes are properly removed.
This commit is contained in:
Родитель
8485e7f4bb
Коммит
ea3316465b
|
@ -21,6 +21,41 @@ namespace Xamarin
|
|||
[TestFixture]
|
||||
public class BundlerTests
|
||||
{
|
||||
[Test]
|
||||
#if __MACOS__
|
||||
[TestCase (Profile.macOSMobile)]
|
||||
#else
|
||||
[TestCase (Profile.iOS)]
|
||||
#endif
|
||||
public void RegisterProtocolOptimization (Profile profile)
|
||||
{
|
||||
using (var bundler = new BundlerTool ()) {
|
||||
bundler.Profile = profile;
|
||||
bundler.CreateTemporaryCacheDirectory ();
|
||||
bundler.CreateTemporaryApp (profile);
|
||||
bundler.Linker = LinkerOption.LinkAll;
|
||||
bundler.Registrar = RegistrarOption.Static;
|
||||
bundler.Optimize = new string [] { "register-protocols" };
|
||||
bundler.AssertExecute ();
|
||||
bundler.AssertWarningCount (0);
|
||||
|
||||
AssemblyDefinition ad = AssemblyDefinition.ReadAssembly (bundler.GetPlatformAssemblyInApp ());
|
||||
var failures = new List<string> ();
|
||||
foreach (var attrib in ad.MainModule.GetCustomAttributes ()) {
|
||||
switch (attrib.AttributeType.Name) {
|
||||
case "ProtocolAttribute":
|
||||
case "ProtocolMemberAttribute":
|
||||
case "AdoptsAttribute":
|
||||
// Unfortunately the CustomAttribute doesn't know its owner, so we can't show that in the test failure message :(
|
||||
failures.Add ($"Found an unexpected attribute: {attrib.AttributeType.FullName}");
|
||||
break;
|
||||
}
|
||||
}
|
||||
Assert.That (failures, Is.Empty, "all these attributes should have been linked away");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
#if __MACOS__
|
||||
[TestCase (Profile.macOSMobile)]
|
||||
|
|
|
@ -364,5 +364,15 @@ namespace Xamarin.Tests
|
|||
|
||||
return assembly;
|
||||
}
|
||||
|
||||
// The directory where the assemblies are located in the built app
|
||||
public abstract string GetAppAssembliesDirectory ();
|
||||
|
||||
// The path to the platform assembly in the built app.
|
||||
public string GetPlatformAssemblyInApp ()
|
||||
{
|
||||
var asm = Path.GetFileName (Configuration.GetBaseLibrary (Profile));
|
||||
return Path.Combine (GetAppAssembliesDirectory (), asm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,5 +63,10 @@ namespace Xamarin
|
|||
Directory.CreateDirectory (app);
|
||||
RootAssembly = CompileTestAppExecutable (OutputPath, code, extraArg, profile, appName, extraCode, usings, use_csc);
|
||||
}
|
||||
|
||||
public override string GetAppAssembliesDirectory()
|
||||
{
|
||||
return Path.Combine (OutputPath, ApplicationName + ".app", "Contents", "MonoBundle");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -714,5 +714,10 @@ public partial class NotificationController : WKUserNotificationInterfaceControl
|
|||
protected override string MessagePrefix {
|
||||
get { return "MT"; }
|
||||
}
|
||||
|
||||
public override string GetAppAssembliesDirectory ()
|
||||
{
|
||||
return AppPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче