diff options
Diffstat (limited to 'mcs/class/Microsoft.Build.Utilities/Test')
-rw-r--r-- | mcs/class/Microsoft.Build.Utilities/Test/Microsoft.Build.Utilities/TaskItemTest.cs | 59 | ||||
-rw-r--r-- | mcs/class/Microsoft.Build.Utilities/Test/Microsoft.Build.Utilities/ToolTaskTest.cs | 141 |
2 files changed, 200 insertions, 0 deletions
diff --git a/mcs/class/Microsoft.Build.Utilities/Test/Microsoft.Build.Utilities/TaskItemTest.cs b/mcs/class/Microsoft.Build.Utilities/Test/Microsoft.Build.Utilities/TaskItemTest.cs index 2032f7c357..79e2eff5f6 100644 --- a/mcs/class/Microsoft.Build.Utilities/Test/Microsoft.Build.Utilities/TaskItemTest.cs +++ b/mcs/class/Microsoft.Build.Utilities/Test/Microsoft.Build.Utilities/TaskItemTest.cs @@ -28,6 +28,7 @@ using System; using System.Collections; using System.Collections.Specialized; +using System.IO; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; using NUnit.Framework; @@ -116,6 +117,50 @@ namespace MonoTests.Microsoft.Build.Utilities { } [Test] + public void TestCtor_EscapedSpecialChar () + { + // If we instantiate with the *escaped* metadata, it's unescaped automatically + var metadata = "foo@2x.png"; + var escapedMetadata = global::Microsoft.Build.BuildEngine.Utilities.Escape ("foo@2x.png"); + var item = new TaskItem (escapedMetadata); + item.SetMetadata ("mine", escapedMetadata); + + Assert.AreEqual (metadata, item.ItemSpec, "#1"); + Assert.AreEqual (metadata, item.GetMetadata ("Identity"), "#2"); + Assert.AreEqual (Path.GetFileNameWithoutExtension (metadata), item.GetMetadata ("FileName"), "#3"); + Assert.IsTrue (item.GetMetadata ("FullPath").EndsWith (metadata), "#4"); + Assert.AreEqual (metadata, item.GetMetadata ("mine"), "#5"); + } + + [Test] + public void TestCtor_EscapedSpecialChar_BrokenEscaping () + { + // This is badly escaped, but MSBuild does not care. + var metadata = "foo%4@2x.png"; + var item = new TaskItem (metadata); + + Assert.AreEqual (metadata, item.ItemSpec, "#1"); + Assert.AreEqual (metadata, item.GetMetadata ("Identity"), "#2"); + Assert.AreEqual (Path.GetFileNameWithoutExtension (metadata), item.GetMetadata ("FileName"), "#3"); + Assert.IsTrue (item.GetMetadata ("FullPath").EndsWith (metadata), "#4"); + } + + [Test] + public void TestCtor_UnescapedSpecialChar () + { + // If we instantiate with unescaped metadata, we get the same value back + var metadata = "foo@2x.png"; + var item = new TaskItem (metadata); + item.SetMetadata ("mine", metadata); + + Assert.AreEqual (metadata, item.ItemSpec, "#1"); + Assert.AreEqual (metadata, item.GetMetadata ("Identity"), "#2"); + Assert.AreEqual (Path.GetFileNameWithoutExtension (metadata), item.GetMetadata ("FileName"), "#3"); + Assert.IsTrue (item.GetMetadata ("FullPath").EndsWith (metadata), "#4"); + Assert.AreEqual (metadata, item.GetMetadata ("mine"), "#5"); + } + + [Test] public void TestCopyConstructor () { item1 = new TaskItem ("itemSpec"); @@ -240,5 +285,19 @@ namespace MonoTests.Microsoft.Build.Utilities { item = new TaskItem ("lalala"); item.SetMetadata ("Identity", "some value"); } + + [Test] + public void TestSetItemSpec () + { + var itemSpec = "foo@2x.png"; + var escapedItemSpec = global::Microsoft.Build.BuildEngine.Utilities.Escape (itemSpec); + + var item = new TaskItem ("foo"); + item.ItemSpec = itemSpec; + Assert.AreEqual (itemSpec, item.ItemSpec, "#1"); + + item.ItemSpec = escapedItemSpec; + Assert.AreEqual (itemSpec, item.ItemSpec, "#2"); + } } } diff --git a/mcs/class/Microsoft.Build.Utilities/Test/Microsoft.Build.Utilities/ToolTaskTest.cs b/mcs/class/Microsoft.Build.Utilities/Test/Microsoft.Build.Utilities/ToolTaskTest.cs new file mode 100644 index 0000000000..8b3ae6e69c --- /dev/null +++ b/mcs/class/Microsoft.Build.Utilities/Test/Microsoft.Build.Utilities/ToolTaskTest.cs @@ -0,0 +1,141 @@ +// +// ToolTaskTest.cs: +// +// Author: +// Jonathan Pryor (jonp@xamarin.com) +// +// (C) 2013 Xamarin Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; + +using Microsoft.Build.Framework; +using Microsoft.Build.Utilities; + +using NUnit.Framework; + +namespace MonoTests.Microsoft.Build.Utilities { + + [TestFixture] + public class ToolTaskTest { + + [Test] + public void LogEventsFromTextOutput () + { + var messages = new[] { + new {Code = "CS0152", Line = "class1.cs(16,4): error CS0152: The label `case 1:' already occurs in this switch statement" }, + }; + + var task = new LogEventsFromTextOutputToolTask (); + foreach (var m in messages) { + task.LogEventsFromTextOutput (m.Line); + Assert.IsTrue (task.Codes.Count > 0, "No error logged for line: {0}", m.Line); + Assert.AreEqual (m.Code, task.Codes [0]); + task.Codes.Clear (); + } + } + } + + class LogEventsFromTextOutputToolTask : ToolTask { + + public List<string> Codes { + get {return engine.Codes;} + } + + CodeLoggingBuildEngine engine = new CodeLoggingBuildEngine (); + + public LogEventsFromTextOutputToolTask () + { + BuildEngine = engine; + } + + protected override string GenerateFullPathToTool () + { + throw new NotImplementedException (); + } + + protected override string ToolName { + get {throw new NotImplementedException ();} + } + + public void LogEventsFromTextOutput (string line) + { + base.LogEventsFromTextOutput (line, MessageImportance.Normal); + } + } + + class CodeLoggingBuildEngine : IBuildEngine { + + public List<string> Codes = new List<string> (); + + public int ColumnNumberOfTaskNode { + get { + throw new NotImplementedException (); + } + } + + public bool ContinueOnError { + get { + throw new NotImplementedException (); + } + } + + public int LineNumberOfTaskNode { + get { + throw new NotImplementedException (); + } + } + + public string ProjectFileOfTaskNode { + get { + throw new NotImplementedException (); + } + } + + public bool BuildProjectFile (string projectFileName, string[] targetNames, System.Collections.IDictionary globalProperties, System.Collections.IDictionary targetOutputs) + { + throw new NotImplementedException (); + } + + public void LogCustomEvent (CustomBuildEventArgs e) + { + } + + public void LogErrorEvent (BuildErrorEventArgs e) + { + Codes.Add (e.Code); + } + + public void LogMessageEvent (BuildMessageEventArgs e) + { + } + + public void LogWarningEvent (BuildWarningEventArgs e) + { + Codes.Add (e.Code); + } + } +} + |