|
| 1 | +#nullable enable |
| 2 | + |
| 3 | +using System; |
| 4 | +using System.IO; |
| 5 | +using System.Linq; |
| 6 | +using Microsoft.Build.Utilities; |
| 7 | +using NUnit.Framework; |
| 8 | + |
| 9 | +using Xamarin.Tests; |
| 10 | +using Xamarin.Utils; |
| 11 | + |
| 12 | +namespace Xamarin.MacDev.Tasks { |
| 13 | + [TestFixture] |
| 14 | + public class ValidateNoStaticLibrariesTests : TestBase { |
| 15 | + ValidateNoStaticLibraries CreateTask (string skipStaticLibraryValidation, params string [] paths) |
| 16 | + { |
| 17 | + var task = CreateTask<ValidateNoStaticLibraries> (); |
| 18 | + task.SkipStaticLibraryValidation = skipStaticLibraryValidation; |
| 19 | + task.ValidateItems = paths.Select (v => new TaskItem (v)).ToArray (); |
| 20 | + return task; |
| 21 | + } |
| 22 | + |
| 23 | + [Test] |
| 24 | + [TestCase ("error")] |
| 25 | + [TestCase ("false")] |
| 26 | + [TestCase ("")] |
| 27 | + public void StaticLibraries_Error (string skipStaticLibraryValidation) |
| 28 | + { |
| 29 | + var paths = new [] { |
| 30 | + Path.Combine (Configuration.RootPath, "tests", "test-libraries", ".libs", "iossimulator", "libtest.a"), |
| 31 | + Path.Combine (Configuration.RootPath, "README.md"), |
| 32 | + Path.Combine (Configuration.RootPath, "tests", "test-libraries", ".libs", "iossimulator", "libframework.dylib"), |
| 33 | + Path.Combine (Configuration.RootPath, "tests", "test-libraries", ".libs", "iossimulator", "SwiftTest.framework", "SwiftTest"), |
| 34 | + Path.Combine (Configuration.RootPath, "tests", "test-libraries", ".libs", "iossimulator", "SwiftTest.framework", "Info.plist"), |
| 35 | + Path.Combine (Configuration.RootPath, "tests", "test-libraries", ".libs", "iossimulator", "XStaticArTest.framework", "XStaticArTest"), |
| 36 | + Path.Combine (Configuration.RootPath, "tests", "test-libraries", ".libs", "iossimulator", "XStaticObjectTest.framework", "XStaticObjectTest"), |
| 37 | + Path.Combine (Configuration.RootPath, "tests", "test-libraries", ".libs", "iossimulator", "XTest.framework", "XTest"), |
| 38 | + }; |
| 39 | + var task = CreateTask (skipStaticLibraryValidation, paths); |
| 40 | + ExecuteTask (task, expectedErrorCount: 3); |
| 41 | + Assert.AreEqual (0, Engine.Logger.WarningsEvents.Count, "Warning Count"); |
| 42 | + Assert.AreEqual ($"The library {paths [0]} is a static library, and static libraries are not supported with Hot Restart. Set 'SkipStaticLibraryValidation=true' in the project file to ignore this error.", Engine.Logger.ErrorEvents [0].Message, "Error message 1"); |
| 43 | + Assert.AreEqual ($"The library {paths [5]} is a static library, and static libraries are not supported with Hot Restart. Set 'SkipStaticLibraryValidation=true' in the project file to ignore this error.", Engine.Logger.ErrorEvents [1].Message, "Error message 2"); |
| 44 | + Assert.AreEqual ($"The file {paths [6]} is an object file, and object files are not supported with Hot Restart. Set 'SkipStaticLibraryValidation=true' in the project file to ignore this error.", Engine.Logger.ErrorEvents [2].Message, "Error message 3"); |
| 45 | + } |
| 46 | + |
| 47 | + [Test] |
| 48 | + [TestCase ("warn")] |
| 49 | + public void StaticLibraries_Warn (string skipStaticLibraryValidation) |
| 50 | + { |
| 51 | + var paths = new [] { |
| 52 | + Path.Combine (Configuration.RootPath, "tests", "test-libraries", ".libs", "iossimulator", "libtest.a"), |
| 53 | + Path.Combine (Configuration.RootPath, "README.md"), |
| 54 | + Path.Combine (Configuration.RootPath, "tests", "test-libraries", ".libs", "iossimulator", "libframework.dylib"), |
| 55 | + Path.Combine (Configuration.RootPath, "tests", "test-libraries", ".libs", "iossimulator", "SwiftTest.framework/SwiftTest"), |
| 56 | + Path.Combine (Configuration.RootPath, "tests", "test-libraries", ".libs", "iossimulator", "SwiftTest.framework/Info.plist"), |
| 57 | + }; |
| 58 | + var task = CreateTask (skipStaticLibraryValidation, paths); |
| 59 | + ExecuteTask (task, expectedErrorCount: 0); |
| 60 | + Assert.AreEqual (1, Engine.Logger.WarningsEvents.Count, "Warning Count"); |
| 61 | + Assert.AreEqual ($"The library {paths [0]} is a static library, and static libraries are not supported with Hot Restart. Set 'SkipStaticLibraryValidation=true' in the project file to ignore this error.", Engine.Logger.WarningsEvents [0].Message, "Error message"); |
| 62 | + } |
| 63 | + |
| 64 | + [Test] |
| 65 | + [TestCase ("disable")] |
| 66 | + public void StaticLibraries_Disabled (string skipStaticLibraryValidation) |
| 67 | + { |
| 68 | + var paths = new [] { |
| 69 | + Path.Combine (Configuration.RootPath, "tests", "test-libraries", ".libs", "iossimulator", "libtest.a"), |
| 70 | + Path.Combine (Configuration.RootPath, "README.md"), |
| 71 | + Path.Combine (Configuration.RootPath, "tests", "test-libraries", ".libs", "iossimulator", "libframework.dylib"), |
| 72 | + Path.Combine (Configuration.RootPath, "tests", "test-libraries", ".libs", "iossimulator", "SwiftTest.framework/SwiftTest"), |
| 73 | + Path.Combine (Configuration.RootPath, "tests", "test-libraries", ".libs", "iossimulator", "SwiftTest.framework/Info.plist"), |
| 74 | + "/does/not/exist", |
| 75 | + }; |
| 76 | + var task = CreateTask (skipStaticLibraryValidation, paths); |
| 77 | + ExecuteTask (task, expectedErrorCount: 0); |
| 78 | + Assert.AreEqual (0, Engine.Logger.WarningsEvents.Count, "Warning Count"); |
| 79 | + } |
| 80 | + |
| 81 | + [Test] |
| 82 | + [TestCase ("invalid")] |
| 83 | + public void StaticLibraries_Invalid (string skipStaticLibraryValidation) |
| 84 | + { |
| 85 | + var paths = new [] { |
| 86 | + Path.Combine (Configuration.RootPath, "tests", "test-libraries", ".libs", "iossimulator", "libtest.a"), |
| 87 | + Path.Combine (Configuration.RootPath, "README.md"), |
| 88 | + Path.Combine (Configuration.RootPath, "tests", "test-libraries", ".libs", "iossimulator", "libframework.dylib"), |
| 89 | + Path.Combine (Configuration.RootPath, "tests", "test-libraries", ".libs", "iossimulator", "SwiftTest.framework/SwiftTest"), |
| 90 | + Path.Combine (Configuration.RootPath, "tests", "test-libraries", ".libs", "iossimulator", "SwiftTest.framework/Info.plist"), |
| 91 | + "/does/not/exist", |
| 92 | + }; |
| 93 | + var task = CreateTask (skipStaticLibraryValidation, paths); |
| 94 | + ExecuteTask (task, expectedErrorCount: 1); |
| 95 | + Assert.AreEqual (0, Engine.Logger.WarningsEvents.Count, "Warning Count"); |
| 96 | + Assert.AreEqual ($"Unknown value for 'SkipStaticLibraryValidation': {skipStaticLibraryValidation}. Valid values are: 'true', 'false', 'warn'.", Engine.Logger.ErrorEvents [0].Message, "Error Message"); |
| 97 | + } |
| 98 | + |
| 99 | + [Test] |
| 100 | + [TestCase ("")] |
| 101 | + [TestCase ("error")] |
| 102 | + public void StaticLibraries_Error_Inexistent (string skipStaticLibraryValidation) |
| 103 | + { |
| 104 | + var task = CreateTask (skipStaticLibraryValidation, "/does/not/exist"); |
| 105 | + ExecuteTask (task, expectedErrorCount: 1); |
| 106 | + Assert.AreEqual (0, Engine.Logger.WarningsEvents.Count, "Warning Count"); |
| 107 | + Assert.AreEqual ($"The file '/does/not/exist' does not exist.", Engine.Logger.ErrorEvents [0].Message.TrimEnd (), "Error Message"); |
| 108 | + } |
| 109 | + |
| 110 | + [Test] |
| 111 | + [TestCase ("warn")] |
| 112 | + public void StaticLibraries_Warn_Inexistent (string skipStaticLibraryValidation) |
| 113 | + { |
| 114 | + var task = CreateTask (skipStaticLibraryValidation, "/does/not/exist"); |
| 115 | + ExecuteTask (task, expectedErrorCount: 0); |
| 116 | + Assert.AreEqual (1, Engine.Logger.WarningsEvents.Count, "Warning Count"); |
| 117 | + Assert.AreEqual ($"The file '/does/not/exist' does not exist.", Engine.Logger.WarningsEvents [0].Message.TrimEnd (), "Error Message"); |
| 118 | + } |
| 119 | + } |
| 120 | +} |
0 commit comments