diff options
author | Mike Voorhees <mrvoorhe@users.noreply.github.com> | 2022-08-04 18:03:23 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-04 18:03:23 +0300 |
commit | 1120fae3c496cd96caed98b2b8fc2d1dde2ba8d3 (patch) | |
tree | faf0a3f1012fb658c09307bbdb60afbaa12ff6d2 | |
parent | 99f923341813d4f28eeb09191622cd2cc0b8a32d (diff) |
Improve tests and docs (#2941)
* Add a test for the `<namespace>` element. There were no tests.
* Expand `CanPreserveTypesUsingRegex` to help highlight how it behaves differently from `<namespace>`
* Add more examples to the docs
4 files changed, 98 insertions, 0 deletions
diff --git a/docs/data-formats.md b/docs/data-formats.md index ef782495b..e360a914b 100644 --- a/docs/data-formats.md +++ b/docs/data-formats.md @@ -100,6 +100,21 @@ The `required` attribute specifies that if the type is not marked, during the ma </linker> ``` +### Preserve more than one type within an assembly + +```xml +<linker> + <assembly fullname="Assembly"> + + <!-- Preserves all types who's fully qualified type name matches the regular expression --> + <type fullname="Assembly.Namespace*" /> + + <!-- Preserve all types within the specified namespace --> + <namespace fullname="Assembly.Namespace" /> + </assembly> +</linker> +``` + ### Preserve only selected fields on a type ```xml diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/CanPreserveNamespace.cs b/test/Mono.Linker.Tests.Cases/LinkXml/CanPreserveNamespace.cs new file mode 100644 index 000000000..4cca62a47 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/CanPreserveNamespace.cs @@ -0,0 +1,51 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.LinkXml +{ + [SetupLinkerDescriptorFile ("CanPreserveNamespace.xml")] + public class CanPreserveNamespace + { + public static void Main () + { + } + } +} + +namespace Mono.Linker.Tests.Cases.LinkXml.PreserveNamespace2 +{ + [Kept] + [KeptMember (".ctor()")] + class Type1 + { + [Kept] + public int UnusedField; + } + + [Kept] + [KeptMember (".ctor()")] + class Type2 + { + [Kept] + public void Method () + { + } + } +} + +namespace Mono.Linker.Tests.Cases.LinkXml.PreserveNamespace2.SubNamespace +{ + class Type1 + { + } + + class Type2 + { + public void Method () + { + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/CanPreserveNamespace.xml b/test/Mono.Linker.Tests.Cases/LinkXml/CanPreserveNamespace.xml new file mode 100644 index 000000000..07d798652 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/CanPreserveNamespace.xml @@ -0,0 +1,5 @@ +<linker> + <assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <namespace fullname="Mono.Linker.Tests.Cases.LinkXml.PreserveNamespace2" /> + </assembly> +</linker>
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/CanPreserveTypesUsingRegex.cs b/test/Mono.Linker.Tests.Cases/LinkXml/CanPreserveTypesUsingRegex.cs index 54bd66a96..a6e51be4a 100644 --- a/test/Mono.Linker.Tests.Cases/LinkXml/CanPreserveTypesUsingRegex.cs +++ b/test/Mono.Linker.Tests.Cases/LinkXml/CanPreserveTypesUsingRegex.cs @@ -31,11 +31,38 @@ namespace Mono.Linker.Tests.Cases.LinkXml.PreserveNamespace [KeptMember (".ctor()")] class Type1 { + [Kept] + public int UnusedField; + } + + [Kept] + [KeptMember (".ctor()")] + class Type2 + { + [Kept] + public void Method () + { + } + } +} + +namespace Mono.Linker.Tests.Cases.LinkXml.PreserveNamespace.SubNamespace +{ + [Kept] + [KeptMember (".ctor()")] + class Type1 + { + [Kept] + public int UnusedField; } [Kept] [KeptMember (".ctor()")] class Type2 { + [Kept] + public void Method () + { + } } } |