diff options
author | Mateo Torres-Ruiz <mateoatr@users.noreply.github.com> | 2020-03-31 12:59:26 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-31 12:59:26 +0300 |
commit | 7b141d7a316b39d17c9a7778f680a42617c1d4a5 (patch) | |
tree | 2d6e6262cf89237959c51d8baae9679e376917b8 /test/Mono.Linker.Tests | |
parent | 65cea0854f3ab546312cad81ba270bdfd9899c30 (diff) |
Output Mono.Linker warnings through MSBuild (#968)
* Add Message class to output errors and warnings to the stdout.
* Add simple test case.
* Log messages through LinkerTestLogger
* Address feedback
* Add parameter to LogContainsAttribute that checks for regex match.
Remove Position and move line and column to MessageOrigin.
Remove MessageCode and use integer instead, check that code value falls into one of the known ranges and that it matches with the received category.
* Order msbuildMC params based on their importance
Remove toolname from MessageOrigin
* Remove unnecessary constructor and comparisons
* Clean up msbuild container to be universaly usable
* Update tests
* Tweak one more category
* Add more tests
* Use factory methods for MessageContainer
Update tests
* Update MessageContainerTests.cs
* Use Append instead of string concatenation
Co-Authored-By: Marek Safar <marek.safar@gmail.com>
Co-authored-by: Marek Safar <marek.safar@gmail.com>
Diffstat (limited to 'test/Mono.Linker.Tests')
5 files changed, 50 insertions, 9 deletions
diff --git a/test/Mono.Linker.Tests/TestCases/TestDatabase.cs b/test/Mono.Linker.Tests/TestCases/TestDatabase.cs index 5e603ba19..42b2685d6 100644 --- a/test/Mono.Linker.Tests/TestCases/TestDatabase.cs +++ b/test/Mono.Linker.Tests/TestCases/TestDatabase.cs @@ -162,6 +162,11 @@ namespace Mono.Linker.Tests.TestCases return NUnitCasesBySuiteName ("Tracing"); } + public static IEnumerable<TestCaseData> LoggingTests () + { + return NUnitCasesBySuiteName ("Logging"); + } + public static TestCaseCollector CreateCollector () { GetDirectoryPaths (out string rootSourceDirectory, out string testCaseAssemblyPath); diff --git a/test/Mono.Linker.Tests/TestCases/TestSuites.cs b/test/Mono.Linker.Tests/TestCases/TestSuites.cs index 60f2ff9ed..5a39b1213 100644 --- a/test/Mono.Linker.Tests/TestCases/TestSuites.cs +++ b/test/Mono.Linker.Tests/TestCases/TestSuites.cs @@ -79,6 +79,12 @@ namespace Mono.Linker.Tests.TestCases Run (testCase); } + [TestCaseSource (typeof (TestDatabase), nameof (TestDatabase.LoggingTests))] + public void LoggingTests (TestCase testCase) + { + Run (testCase); + } + [TestCaseSource(typeof (TestDatabase), nameof (TestDatabase.TestFrameworkTests))] public void TestFrameworkTests (TestCase testCase) { diff --git a/test/Mono.Linker.Tests/TestCasesRunner/LinkerTestLogger.cs b/test/Mono.Linker.Tests/TestCasesRunner/LinkerTestLogger.cs index ffd9cfe67..2a0af7d53 100644 --- a/test/Mono.Linker.Tests/TestCasesRunner/LinkerTestLogger.cs +++ b/test/Mono.Linker.Tests/TestCasesRunner/LinkerTestLogger.cs @@ -10,14 +10,20 @@ namespace Mono.Linker.Tests.TestCasesRunner public string Message; } - public List<MessageRecord> Messages { get; private set; } = new List<MessageRecord>(); + public List<MessageRecord> Messages { get; private set; } = new List<MessageRecord> (); - public void LogMessage(MessageImportance importance, string message, params object[] values) + public void LogMessage (MessageImportance importance, string message, params object [] values) { - Messages.Add(new MessageRecord - { + Messages.Add (new MessageRecord { Importance = importance, - Message = string.Format(message, values) + Message = string.Format (message, values) + }); + } + + public void LogMessage (MessageContainer msBuildMessage) + { + Messages.Add (new MessageRecord { + Message = msBuildMessage.ToString () }); } } diff --git a/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs b/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs index 7abff46b1..3752c8b94 100644 --- a/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs +++ b/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs @@ -597,10 +597,13 @@ namespace Mono.Linker.Tests.TestCasesRunner { foreach (var typeWithRemoveInAssembly in original.AllDefinedTypes ()) { foreach (var attr in typeWithRemoveInAssembly.CustomAttributes) { if (attr.AttributeType.Resolve ().Name == nameof (LogContainsAttribute)) { - var expectedMessagePattern = (string)attr.ConstructorArguments [0].Value; - Assert.That ( - logger.Messages.Any (mc => Regex.IsMatch (mc.Message, expectedMessagePattern)), - $"Expected to find logged message matching `{expectedMessagePattern}`, but no such message was found.{Environment.NewLine}Logged messages:{Environment.NewLine}{allMessages}"); + var expectedMessage = (string)attr.ConstructorArguments [0].Value; + + Assert.That (new Func<bool> (() => { + if ((bool)attr.ConstructorArguments [1].Value) + return logger.Messages.Any (mc => Regex.IsMatch (mc.Message, expectedMessage)); + return logger.Messages.Any (mc => mc.Message.Contains (expectedMessage)); + }), $"Expected to find logged message matching `{expectedMessage}`, but no such message was found.{Environment.NewLine}Logged messages:{Environment.NewLine}{allMessages}"); } if (attr.AttributeType.Resolve ().Name == nameof (LogDoesNotContainAttribute)) { diff --git a/test/Mono.Linker.Tests/Tests/MessageContainerTests.cs b/test/Mono.Linker.Tests/Tests/MessageContainerTests.cs new file mode 100644 index 000000000..d2b134efb --- /dev/null +++ b/test/Mono.Linker.Tests/Tests/MessageContainerTests.cs @@ -0,0 +1,21 @@ +using NUnit.Framework; + +namespace Mono.Linker.Tests +{ + [TestFixture] + public class MessageContainerTests + { + [Test] + public void MSBuildFormat () + { + var msg = MessageContainer.CreateErrorMessage ("text", 0); + Assert.AreEqual ("illinker: error IL0000: text", msg.ToMSBuildString ()); + + msg = MessageContainer.CreateWarningMessage ("message", 2001, origin: new MessageOrigin("logtest", 1, 1)); + Assert.AreEqual ("logtest(1,1): warning IL2001: message", msg.ToMSBuildString ()); + + msg = MessageContainer.CreateInfoMessage ("log test"); + Assert.AreEqual ("illinker: log test", msg.ToMSBuildString ()); + } + } +} |