diff --git a/tests/common/ExecutionHelper.cs b/tests/common/ExecutionHelper.cs index 6d579826d2..4f21fff5ba 100644 --- a/tests/common/ExecutionHelper.cs +++ b/tests/common/ExecutionHelper.cs @@ -180,21 +180,25 @@ namespace Xamarin.Tests Assert.AreEqual (count, ErrorCount, message); } - public void AssertErrorPattern (int number, string messagePattern) + public void AssertErrorPattern (int number, string messagePattern, string filename = null, int? linenumber = null, bool custom_pattern_syntax = false) { - AssertErrorPattern (MessagePrefix, number, messagePattern); + AssertErrorPattern (MessagePrefix, number, messagePattern, filename, linenumber, custom_pattern_syntax); } - public void AssertErrorPattern (string prefix, int number, string messagePattern) + public void AssertErrorPattern (string prefix, int number, string messagePattern, string filename = null, int? linenumber = null, bool custom_pattern_syntax = false) { if (!messages.Any ((msg) => msg.Prefix == prefix && msg.Number == number)) Assert.Fail (string.Format ("The error '{0}{1:0000}' was not found in the output.", prefix, number)); - if (messages.Any ((msg) => Regex.IsMatch (msg.Message, messagePattern))) - return; - - var details = messages.Where ((msg) => msg.Prefix == prefix && msg.Number == number && !Regex.IsMatch (msg.Message, messagePattern)).Select ((msg) => string.Format ("\tThe message '{0}' did not match the pattern '{1}'.", msg.Message, messagePattern)); - Assert.Fail (string.Format ("The error '{0}{1:0000}: {2}' was not found in the output:\n{3}", prefix, number, messagePattern, string.Join ("\n", details.ToArray ()))); + // Custom pattern syntax: escape parenthesis and brackets so that they're treated like normal characters. + var processedPattern = custom_pattern_syntax ? messagePattern.Replace ("(", "[(]").Replace (")", "[)]").Replace ("[]", "[[][]]") + "$" : messagePattern; + var matches = messages.Where ((msg) => Regex.IsMatch (msg.Message, processedPattern)); + if (!matches.Any ()) { + var details = messages.Where ((msg) => msg.Prefix == prefix && msg.Number == number && !Regex.IsMatch (msg.Message, processedPattern)).Select ((msg) => string.Format ("\tThe message '{0}' did not match the pattern '{1}'.", msg.Message, messagePattern)); + Assert.Fail (string.Format ("The error '{0}{1:0000}: {2}' was not found in the output:\n{3}", prefix, number, messagePattern, string.Join ("\n", details.ToArray ()))); + } + + AssertFilename (prefix, number, messagePattern, matches, filename, linenumber); } public void AssertError (int number, string message, string filename = null, int? linenumber = null) @@ -215,6 +219,11 @@ namespace Xamarin.Tests Assert.Fail (string.Format ("The error '{0}{1:0000}: {2}' was not found in the output:\n{3}", prefix, number, message, string.Join ("\n", details.ToArray ()))); } + AssertFilename (prefix, number, message, matches, filename, linenumber); + } + + void AssertFilename (string prefix, int number, string message, IEnumerable matches, string filename, int? linenumber) + { if (filename != null) { var hasDirectory = filename.IndexOf (Path.DirectorySeparatorChar) > -1; if (!matches.Any ((v) => { diff --git a/tests/mtouch/MTouch.cs b/tests/mtouch/MTouch.cs index 768dc4f2f0..1785b9e9b6 100644 --- a/tests/mtouch/MTouch.cs +++ b/tests/mtouch/MTouch.cs @@ -3544,10 +3544,12 @@ public class Dummy { ExecutionHelper.Execute ("mono", $"{StringUtils.Quote (Path.Combine (Configuration.RootPath, "tests", "xharness", "xharness.exe"))} --run {StringUtils.Quote (csprojpath)} --target ios-simulator-64 --sdkroot {Configuration.xcode_root} --logdirectory {StringUtils.Quote (Path.Combine (tmpdir, "log.txt"))} --configuration {configuration}", environmentVariables: environment_variables); } - public static string CompileTestAppExecutable (string targetDirectory, string code = null, string extraArg = "", Profile profile = Profile.iOS, string appName = "testApp", string extraCode = null) + public static string CompileTestAppExecutable (string targetDirectory, string code = null, string extraArg = "", Profile profile = Profile.iOS, string appName = "testApp", string extraCode = null, string usings = null) { if (code == null) code = "public class TestApp { static void Main () { System.Console.WriteLine (typeof (ObjCRuntime.Runtime).ToString ()); } }"; + if (usings != null) + code = usings + "\n" + code; if (extraCode != null) code += extraCode; diff --git a/tests/mtouch/MTouchTool.cs b/tests/mtouch/MTouchTool.cs index 024cd9fea7..d5635a6dc7 100644 --- a/tests/mtouch/MTouchTool.cs +++ b/tests/mtouch/MTouchTool.cs @@ -645,7 +645,7 @@ namespace Xamarin return MTouch.CompileTestAppLibrary (asm_dir, "class X {}", appName: Path.GetFileNameWithoutExtension (asm_name)); } - public void CreateTemporaryApp (bool hasPlist = false, string appName = "testApp", string code = null, string extraArg = "", string extraCode = null) + public void CreateTemporaryApp (bool hasPlist = false, string appName = "testApp", string code = null, string extraArg = "", string extraCode = null, string usings = null) { string testDir; if (RootAssembly == null) { @@ -657,7 +657,7 @@ namespace Xamarin var app = AppPath ?? Path.Combine (testDir, appName + ".app"); Directory.CreateDirectory (app); AppPath = app; - RootAssembly = MTouch.CompileTestAppExecutable (testDir, code, extraArg, Profile, appName, extraCode); + RootAssembly = MTouch.CompileTestAppExecutable (testDir, code, extraArg, Profile, appName, extraCode, usings); if (hasPlist) File.WriteAllText (Path.Combine (app, "Info.plist"), CreatePlist (Profile, appName)); diff --git a/tests/mtouch/RegistrarTest.cs b/tests/mtouch/RegistrarTest.cs index 44f04f67e5..74322eddde 100644 --- a/tests/mtouch/RegistrarTest.cs +++ b/tests/mtouch/RegistrarTest.cs @@ -568,10 +568,11 @@ public struct FooF { public NSObject Obj; } [Test] - [TestCase (Profile.iOS, "iOS")] - [TestCase (Profile.tvOS, "tvOS")] + [TestCase (Profile.iOS, "iOS", MTouchLinker.DontLink)] + [TestCase (Profile.tvOS, "tvOS", MTouchLinker.DontLink)] + [TestCase (Profile.iOS, "iOS", MTouchLinker.LinkAll)] //[TestCase (Profile.WatchOS, "watchOS")] // MT0077 interferes - public void MT4162 (Profile profile, string name) + public void MT4162 (Profile profile, string name, MTouchLinker linker) { var code = @" [Introduced (PlatformName.iOS, 99, 0, 0, PlatformArchitecture.All, ""use Z instead"")] @@ -621,16 +622,21 @@ public struct FooF { public NSObject Obj; } } "; - Verify (R.Static, profile, code, false, - $"error MT4162: The type 'FutureType' (used as a base type of CurrentType) is not available in {name} .* (it was introduced in {name} 99.0.0): 'use Z instead'. Please build with a newer {name} SDK (usually done by using the most recent version of Xcode).", - $"error MT4162: The type 'FutureType' (used as a base type of CurrentType) is not available in {name} .* (it was introduced in {name} 89.0.0). Please build with a newer {name} SDK (usually done by using the most recent version of Xcode).", - $".*/Test.cs(.*): error MT4162: The type 'FutureType' (used as the property type of CurrentType.Zap) is not available in {name} .* (it was introduced in {name} 99.0.0): 'use Z instead'. Please build with a newer {name} SDK (usually done by using the most recent version of Xcode).", - $".*/Test.cs(.*): error MT4162: The type 'FutureType' (used as the property type of CurrentType.Zap) is not available in {name} .* (it was introduced in {name} 89.0.0). Please build with a newer {name} SDK (usually done by using the most recent version of Xcode).", - $".*/Test.cs(.*): error MT4162: The type 'FutureType' (used as a parameter in CurrentType.Foo) is not available in {name} .* (it was introduced in {name} 99.0.0): 'use Z instead'. Please build with a newer {name} SDK (usually done by using the most recent version of Xcode).", - $".*/Test.cs(.*): error MT4162: The type 'FutureType' (used as a parameter in CurrentType.Foo) is not available in {name} .* (it was introduced in {name} 89.0.0). Please build with a newer {name} SDK (usually done by using the most recent version of Xcode).", - $".*/Test.cs(.*): error MT4162: The type 'FutureType' (used as a return type in CurrentType.Bar) is not available in {name} .* (it was introduced in {name} 99.0.0): 'use Z instead'. Please build with a newer {name} SDK (usually done by using the most recent version of Xcode).", - $".*/Test.cs(.*): error MT4162: The type 'FutureType' (used as a return type in CurrentType.Bar) is not available in {name} .* (it was introduced in {name} 89.0.0). Please build with a newer {name} SDK (usually done by using the most recent version of Xcode)." - ); + using (var mtouch = new MTouchTool ()) { + mtouch.Profile = profile; + mtouch.Linker = linker; + mtouch.Registrar = MTouchRegistrar.Static; + mtouch.CreateTemporaryApp (extraCode: code, extraArg: "-debug", usings: "using System;\nusing Foundation;\nusing ObjCRuntime;\n"); + mtouch.AssertExecuteFailure (MTouchAction.BuildSim, "build"); + mtouch.AssertErrorPattern (4162, $"The type 'FutureType' (used as a base type of CurrentType) is not available in {name} .* (it was introduced in {name} 99.0.0): 'use Z instead'. Please build with a newer {name} SDK (usually done by using the most recent version of Xcode).", custom_pattern_syntax: true); + mtouch.AssertErrorPattern (4162, $"The type 'FutureType' (used as a base type of CurrentType) is not available in {name} .* (it was introduced in {name} 89.0.0). Please build with a newer {name} SDK (usually done by using the most recent version of Xcode).", custom_pattern_syntax: true); + mtouch.AssertErrorPattern (4162, $"The type 'FutureType' (used as the property type of CurrentType.Zap) is not available in {name} .* (it was introduced in {name} 99.0.0): 'use Z instead'. Please build with a newer {name} SDK (usually done by using the most recent version of Xcode).", "testApp.cs", custom_pattern_syntax: true); + mtouch.AssertErrorPattern (4162, $"The type 'FutureType' (used as the property type of CurrentType.Zap) is not available in {name} .* (it was introduced in {name} 89.0.0). Please build with a newer {name} SDK (usually done by using the most recent version of Xcode).", "testApp.cs", custom_pattern_syntax: true); + mtouch.AssertErrorPattern (4162, $"The type 'FutureType' (used as a parameter in CurrentType.Foo) is not available in {name} .* (it was introduced in {name} 99.0.0): 'use Z instead'. Please build with a newer {name} SDK (usually done by using the most recent version of Xcode).", "testApp.cs", custom_pattern_syntax: true); + mtouch.AssertErrorPattern (4162, $"The type 'FutureType' (used as a parameter in CurrentType.Foo) is not available in {name} .* (it was introduced in {name} 89.0.0). Please build with a newer {name} SDK (usually done by using the most recent version of Xcode).", "testApp.cs", custom_pattern_syntax: true); + mtouch.AssertErrorPattern (4162, $"The type 'FutureType' (used as a return type in CurrentType.Bar) is not available in {name} .* (it was introduced in {name} 99.0.0): 'use Z instead'. Please build with a newer {name} SDK (usually done by using the most recent version of Xcode).", "testApp.cs", custom_pattern_syntax: true); + mtouch.AssertErrorPattern (4162, $"The type 'FutureType' (used as a return type in CurrentType.Bar) is not available in {name} .* (it was introduced in {name} 89.0.0). Please build with a newer {name} SDK (usually done by using the most recent version of Xcode).", "testApp.cs", custom_pattern_syntax: true); + } } static string [] objective_c_keywords = new string [] {