Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,190 @@
//
// AssignCultureTest.cs
//
// Author:
// Ankit Jain (jankit@novell.com)
//
// Copyright 2008 Novell, Inc (http://www.novell.com)
//
// 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.IO;
using System.Text;
using NUnit.Framework;
using Microsoft.Build.BuildEngine;
namespace MonoTests.Microsoft.Build.Tasks
{
[TestFixture]
public class AssignCultureTest
{
static OsType OS;
static char DSC = Path.DirectorySeparatorChar;
string [] files;
Project project;
Engine engine;
[SetUp]
public void SetUp ()
{
if ('/' == DSC) {
OS = OsType.Unix;
} else if ('\\' == DSC) {
OS = OsType.Windows;
} else {
OS = OsType.Mac;
//FIXME: For Mac. figure this out when we need it
}
files = new string [] {
//resx files
".\\foo.resx", @"bar\foo.resx",
"foo.fr.resx", @"dir\abc.en.resx", "foo.bar.resx",
//non-resx
"sample.txt", @"bar\sample.txt",
"sample.it.png", @"dir\sample.en.png", "sample.inv.txt"};
engine = new Engine (Consts.BinPath);
project = engine.CreateNewProject ();
}
[Test]
public void TestAssignedFiles ()
{
LoadAndBuildProject (files);
//AssignedFiles
if (OS == OsType.Unix) {
CheckItems (new string [] {"./foo.resx", "bar/foo.resx", "foo.fr.resx", "dir/abc.en.resx", "foo.bar.resx",
"sample.txt", "bar/sample.txt", "sample.it.png", "dir/sample.en.png", "sample.inv.txt"},
new string [] {null, null, "fr", "en", null, null, null, "it", "en", null},
"AssignedFiles", "A2");
} else if (OS == OsType.Windows) {
CheckItems (new string [] {".\\foo.resx", @"bar\foo.resx", "foo.fr.resx", @"dir\abc.en.resx", "foo.bar.resx",
"sample.txt", @"bar\sample.txt", "sample.it.png", @"dir\sample.en.png", "sample.inv.txt"},
new string [] { null, null, "fr", "en", null, null, null, "it", "en", null },
"AssignedFiles", "A2");
}
}
[Test]
public void TestAssignedFilesWithCulture ()
{
LoadAndBuildProject (files);
//AssignedFilesWithCulture
if (OS == OsType.Unix) {
CheckItems (new string [] { "foo.fr.resx", "dir/abc.en.resx", "sample.it.png", "dir/sample.en.png" },
new string [] {"fr", "en", "it", "en"},
"AssignedFilesWithCulture", "A2");
} else if (OS == OsType.Windows) {
CheckItems (new string [] { "foo.fr.resx", @"dir\abc.en.resx", "sample.it.png", @"dir\sample.en.png" },
new string [] { "fr", "en", "it", "en" },
"AssignedFilesWithCulture", "A2");
}
}
[Test]
public void TestAssignedFilesWithNoCulture ()
{
LoadAndBuildProject (files);
//AssignedFilesWithNoCulture
if (OS == OsType.Unix) {
CheckItems (new string [] { "./foo.resx", "bar/foo.resx", "foo.bar.resx", "sample.txt", "bar/sample.txt", "sample.inv.txt"},
null, "AssignedFilesWithNoCulture", "A2");
} else if (OS == OsType.Windows) {
CheckItems (new string [] { ".\\foo.resx", @"bar\foo.resx", "foo.bar.resx", "sample.txt", @"bar\sample.txt", "sample.inv.txt"},
null, "AssignedFilesWithNoCulture", "A2");
}
}
[Test]
public void TestCultureNeutralAssignedFiles ()
{
LoadAndBuildProject (files);
//CultureNeutralAssignedFiles
if (OS == OsType.Unix) {
CheckItems (new string [] { "./foo.resx", "bar/foo.resx", "foo.resx", "dir/abc.resx", "foo.bar.resx",
"sample.txt", "bar/sample.txt", "sample.png", "dir/sample.png", "sample.inv.txt"},
new string [] { null, null, "fr", "en", null, null, null, "it", "en", null },
"CultureNeutralAssignedFiles", "A2");
} else if (OS == OsType.Windows) {
CheckItems (new string [] { ".\\foo.resx", @"bar\foo.resx", "foo.resx", @"dir\abc.resx", "foo.bar.resx",
"sample.txt", @"bar\sample.txt", "sample.png", @"dir\sample.png", "sample.inv.txt"},
new string [] { null, null, "fr", "en", null, null, null, "it", "en", null },
"CultureNeutralAssignedFiles", "A2");
}
}
void LoadAndBuildProject (string [] files_list)
{
string projectText = CreateProjectString (files_list);
project.LoadXml (projectText);
TestMessageLogger testLogger = new TestMessageLogger ();
engine.RegisterLogger (testLogger);
if (!project.Build ("1")) {
testLogger.DumpMessages ();
Assert.Fail ("A1 : Error in building");
}
}
void CheckItems (string [] values, string [] cultures, string itemlist_name, string prefix)
{
BuildItemGroup group = project.GetEvaluatedItemsByName (itemlist_name);
Assert.AreEqual (values.Length, group.Count, prefix + "#1");
for (int i = 0; i < values.Length; i++) {
Assert.AreEqual (values [i], group [i].FinalItemSpec, prefix + "#2");
Assert.IsTrue (group [i].HasMetadata ("Child"), prefix + "#3");
Assert.AreEqual ("ChildValue", group [i].GetMetadata ("Child"), prefix + "#4");
Assert.AreEqual (cultures != null && cultures [i] != null, group [i].HasMetadata ("Culture"), prefix + "#5");
if (cultures != null && cultures [i] != null)
Assert.AreEqual (cultures [i], group [i].GetMetadata ("Culture"), prefix + "#6");
}
}
string CreateProjectString (string [] files)
{
StringBuilder sb = new StringBuilder ();
sb.Append (@"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""><ItemGroup>");
foreach (string file in files)
sb.AppendFormat ("<Files Include=\"{0}\"><Child>ChildValue</Child></Files>\n", file);
sb.Append (@"</ItemGroup>
<Target Name=""1"">
<AssignCulture Files=""@(Files)"" >
<Output TaskParameter=""AssignedFiles"" ItemName=""AssignedFiles"" />
<Output TaskParameter=""AssignedFilesWithCulture"" ItemName=""AssignedFilesWithCulture"" />
<Output TaskParameter=""AssignedFilesWithNoCulture"" ItemName=""AssignedFilesWithNoCulture"" />
<Output TaskParameter=""CultureNeutralAssignedFiles"" ItemName=""CultureNeutralAssignedFiles"" />
</AssignCulture>
</Target>
</Project>");
return sb.ToString ();
}
}
}

View File

@@ -0,0 +1,188 @@
//
// AssignProjectConfigurationTest.cs
//
// Author:
// Ankit Jain (jankit@novell.com)
//
// Copyright 2009 Novell, Inc (http://www.novell.com)
//
// 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;
using Microsoft.Build.BuildEngine;
using Microsoft.Build.Framework;
using Microsoft.Build.Tasks;
using Microsoft.Build.Utilities;
using NUnit.Framework;
using System.Text;
namespace MonoTests.Microsoft.Build.Tasks
{
[TestFixture]
public class AssignProjectConfigurationTest
{
[Test]
public void TestValidCase () {
string[] guids = new string[] {
"{88932AF5-A0AF-44F3-A202-5C88152F25CA}",
"{88932AF5-A0AF-44F3-A202-5C88152FABC1}",
"{3653C4D3-60C0-4657-8289-3922D0DFB933}",
"{DAE34193-B5C7-4488-A911-29EE15C84CB8}",
"{23F291D9-78DF-4133-8CF2-78CE104DDE63}",
"asd"
};
string[] project_ref_guids = new string[] {
"{88932AF5-A0AF-44F3-A202-5C88152F25CA}",
"{88932AF5-A0AF-44F3-A202-5C88152faBC1}",
"{3653C4D3-60C0-4657-8289-3922D0DFB933}",
"{DAE34193-B5C7-4488-A911-29EE15C84CB8}",
"{DAE34193-B5C7-4488-A911-29EE15C84CBE}"
};
CreateAndCheckProject (guids, project_ref_guids, new string[] {
"AssignedProjects : foo0.csproj;foo1.csproj;foo2.csproj;foo3.csproj: SetConfig: Configuration=Release",
"AssignedProjects : foo0.csproj: SetPlatform: Platform=AnyCPU0",
"AssignedProjects : foo1.csproj: SetPlatform: Platform=AnyCPU1",
"AssignedProjects : foo2.csproj: SetPlatform: Platform=AnyCPU2",
"AssignedProjects : foo3.csproj: SetPlatform: Platform=AnyCPU3",
"UnassignedProjects : foo4.csproj"},
true,
"A1#");
}
[Test]
public void TestInvalidProjectGuid ()
{
string[] guids = new string[] {
"{23F291D9-78DF-4133-8CF2-78CE104DDE63}",
};
string[] project_ref_guids = new string[] {
"{DAE34193-B5C7-4488-A911-29EE15C84CB8}",
"{23F291D9-78DF-4133-8CF2-78CE104DDE63}",
"invalid guid"
};
CreateAndCheckProject (guids, project_ref_guids, null, false, "A1#");
}
[Test]
public void TestInvalidProjectGuidInSolutionConfigContents () {
string[] guids = new string[] {
"{23F291D9-78DF-4133-8CF2-78CE104DDE63}",
"invalid guid"
};
string[] project_ref_guids = new string[] {
"{DAE34193-B5C7-4488-A911-29EE15C84CB8}",
"{23F291D9-78DF-4133-8CF2-78CE104DDE63}"
};
CreateAndCheckProject (guids, project_ref_guids,
new string [] {
"AssignedProjects : foo1.csproj: SetConfig: Configuration=Release",
"AssignedProjects : foo1.csproj: SetPlatform: Platform=AnyCPU0",
"UnassignedProjects : foo0.csproj"
}, true, "A1#");
}
void CreateAndCheckProject (string[] guids, string[] project_ref_guids, string[] messages, bool build_result, string prefix)
{
Engine engine = new Engine (Consts.BinPath);
Project project = engine.CreateNewProject ();
TestMessageLogger testLogger = new TestMessageLogger ();
engine.RegisterLogger (testLogger);
string projectString = CreateProject (guids, project_ref_guids);
project.LoadXml (projectString);
try {
Assert.AreEqual (build_result, project.Build (), "Build " + (build_result ? "failed" : "should've failed"));
if (!build_result || messages == null)
// build failed as expected, don't check outputs
return;
for (int i = 0; i < messages.Length; i++)
testLogger.CheckLoggedMessageHead (messages [i], prefix + i.ToString ());
Assert.AreEqual (0, testLogger.NormalMessageCount);
} catch (AssertionException) {
Console.WriteLine (projectString);
testLogger.DumpMessages ();
throw;
}
}
string CreateProject (string[] guids, string[] project_ref_guids)
{
StringBuilder sb = new StringBuilder ();
sb.Append (@"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">");
sb.Append ("\n" + GetUsingTask ("AssignProjectConfiguration"));
sb.AppendFormat (@"<PropertyGroup>{0}</PropertyGroup>", CreateSolutionConfigurationProperty (guids, "Release|AnyCPU"));
sb.Append (CreateProjectReferencesItemGroup (project_ref_guids));
sb.Append ("\n\t<Target Name=\"1\">\n");
sb.Append ("\t\t<AssignProjectConfiguration ProjectReferences=\"@(ProjectReference)\" " +
" SolutionConfigurationContents=\"$(CurrentSolutionConfigurationContents)\">\n");
sb.Append ("\t\t\t<Output TaskParameter=\"AssignedProjects\" ItemName = \"AssignedProjects\" />\n");
sb.Append ("\t\t\t<Output TaskParameter=\"UnassignedProjects\" ItemName = \"UnassignedProjects\" />\n");
sb.Append ("\t\t</AssignProjectConfiguration>\n");
sb.Append ("<Message Text=\"AssignedProjects : @(AssignedProjects): SetConfig: %(AssignedProjects.SetConfiguration)\"/>\n");
sb.Append ("<Message Text=\"AssignedProjects : @(AssignedProjects): SetPlatform: %(AssignedProjects.SetPlatform)\"/>\n");
sb.Append ("<Message Text=\"UnassignedProjects : @(UnassignedProjects)\"/>\n");
sb.Append ("</Target>\n");
sb.Append ("</Project>");
return sb.ToString ();
}
string CreateSolutionConfigurationProperty (string[] guids, string config_str)
{
StringBuilder sb = new StringBuilder ();
sb.Append ("\n<CurrentSolutionConfigurationContents>\n");
sb.Append ("\t<foo xmlns=\"\">\n");
for (int i = 0; i < guids.Length; i++) {
sb.AppendFormat ("\t\t<bar Project=\"{0}\">{1}{2}</bar>\n",
guids[i], config_str, i);
}
sb.Append ("\t</foo>\n");
sb.Append ("</CurrentSolutionConfigurationContents>\n");
return sb.ToString ();
}
string CreateProjectReferencesItemGroup (string[] guids)
{
StringBuilder sb = new StringBuilder ();
sb.Append ("\n<ItemGroup>\n");
for (int i = 0; i < guids.Length; i ++)
sb.AppendFormat ("\t<ProjectReference Include=\"foo{1}.csproj\"><Project>{0}</Project></ProjectReference>\n", guids [i], i);
sb.Append ("</ItemGroup>\n");
return sb.ToString ();
}
string GetUsingTask (string taskName)
{
return "<UsingTask TaskName='Microsoft.Build.Tasks." + taskName + "' AssemblyFile='" + Consts.GetTasksAsmPath () + "' />";
}
}
}

View File

@@ -0,0 +1,221 @@
//
// AssignTargetPathTest.cs
//
// Author:
// Ankit Jain (jankit@novell.com)
//
// Copyright 2008 Novell, Inc (http://www.novell.com)
//
// 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.Text;
using NUnit.Framework;
using Microsoft.Build.BuildEngine;
using System.IO;
namespace MonoTests.Microsoft.Build.Tasks
{
enum OsType {
Windows,
Unix,
Mac
}
[TestFixture]
public class AssignTargetPathTest
{
//inspired from PathTest.cs
static OsType OS;
static char DSC = Path.DirectorySeparatorChar;
[SetUp]
public void SetUp ()
{
if ('/' == DSC) {
OS = OsType.Unix;
} else if ('\\' == DSC) {
OS = OsType.Windows;
} else {
OS = OsType.Mac;
//FIXME: For Mac. figure this out when we need it
}
}
[Test]
public void TestExecute1()
{
if (OS == OsType.Unix) {
CheckTargetPath(
new string[] { "/a/b/./abc.cs", "/a/c/def.cs", "a/xyz.cs", "/different/xyz/foo.cs", "rel/bar.resx"},
new string[] { "b/abc.cs", "c/def.cs", "xyz.cs", "foo.cs", "bar.resx" },
"/a/./", "A");
} else if (OS == OsType.Windows) {
CheckTargetPath(
new string[] { @"C:\a\b\.\abc.cs", @"C:\a\c\def.cs", "xyz.cs", @"C:\different\xyz\foo.cs", @"rel\bar.resx"},
new string[] { @"b\abc.cs", @"c\def.cs", "xyz.cs", "foo.cs", "bar.resx" },
@"C:\a\.\", "A");
}
}
[Test]
public void TestExecute2()
{
string root = Path.GetPathRoot (Environment.CurrentDirectory);
string cur_dir_minus_root = Environment.CurrentDirectory.Substring (root.Length);
if (OS == OsType.Unix) {
CheckTargetPath(
new string[] { "//a/b/abc.cs", "k/../k/def.cs", "/xyz.cs", "/different/xyz/foo.cs"},
new string[] { "a/b/abc.cs", Path.Combine (cur_dir_minus_root, "k/def.cs"), "xyz.cs", "different/xyz/foo.cs"},
"/", "A");
} else if (OS == OsType.Windows) {
CheckTargetPath(
new string[] { root + @"a\b\abc.cs", @"k\..\k\def.cs", root + @"xyz.cs", root + @"different\xyz\foo.cs"},
new string[] { "a\\b\\abc.cs", cur_dir_minus_root + "\\k\\def.cs", "xyz.cs", "different\\xyz\\foo.cs"},
root, "A");
}
}
[Test]
public void TestExecute3()
{
string root = Path.GetPathRoot (Environment.CurrentDirectory);
string cur_dir_minus_root = Environment.CurrentDirectory.Substring (root.Length);
if (OS == OsType.Unix) {
CheckTargetPath(
new string[] { "xyz.cs", "rel/bar.resx" },
new string[] { Path.Combine (cur_dir_minus_root, "xyz.cs"),
Path.Combine (cur_dir_minus_root, "rel/bar.resx") },
"/", "A");
} else if (OS == OsType.Windows) {
CheckTargetPath(
new string[] { "xyz.cs", "rel\\bar.resx" },
new string[] { Path.Combine (cur_dir_minus_root, "xyz.cs"),
Path.Combine (cur_dir_minus_root, "rel\\bar.resx") },
root, "A");
}
}
[Test]
public void TestLink ()
{
string projectText = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
<ItemGroup>
<FooFiles Include=""xyz.cs"">
<Child>Cxyz.cs</Child>
<Link>Test\Link\xyz.cs</Link>
</FooFiles>
<FooFiles Include=""rel\bar.resx"">
<Child>Crel\bar.resx</Child>
<Link>Test\Link\bar.resx</Link>
</FooFiles>
<FooFiles Include=""rel\qwe.txt"">
<Child>Crel\qwe.txt</Child>
<Link>..\Test\Link\qwe.txt</Link>
</FooFiles>
</ItemGroup>
<Target Name=""1"">
<AssignTargetPath Files=""@(FooFiles)"" RootFolder=""/"">
<Output TaskParameter=""AssignedFiles"" ItemName=""FooPath"" />
</AssignTargetPath>
</Target>
</Project>";
Engine engine = new Engine(Consts.BinPath);
Project project = engine.CreateNewProject();
project.LoadXml(projectText);
string id = "A";
Assert.IsTrue(project.Build("1"), id + "1 : Error in building");
string [] files = new string [] { "xyz.cs", "rel/bar.resx", "rel/qwe.txt"};
string [] assignedFiles = new string [] {
PathCombine ("Test", "Link", "xyz.cs"),
PathCombine ("Test", "Link", "bar.resx"),
PathCombine ("..", "Test", "Link", "qwe.txt")
};
BuildItemGroup include = project.GetEvaluatedItemsByName("FooPath");
Assert.AreEqual(files.Length, include.Count, id + "2");
for (int i = 0; i < files.Length; i++) {
Assert.AreEqual (files [i], include [i].FinalItemSpec, id + "3, file #" + i);
Assert.IsTrue (include[i].HasMetadata ("TargetPath"), id + "4, file #" + i + ", TargetPath metadata missing");
Assert.AreEqual (assignedFiles [i], include[i].GetMetadata("TargetPath"), id + "5, file #" + i);
Assert.IsTrue (include [i].HasMetadata ("Child"), id + "6, file #" + i + ", Child metadata missing");
Assert.AreEqual ("C" + files [i], include [i].GetMetadata ("Child"), id + "7, file #" + i + ", Child metadata value incorrect");
}
}
string PathCombine (string path1, params string[] parts)
{
if (parts == null || parts.Length == 0)
return path1;
string final_path = path1;
foreach (string part in parts)
final_path = Path.Combine (final_path, part);
return final_path;
}
void CheckTargetPath(string[] files, string[] assignedFiles, string rootFolder, string id)
{
Engine engine = new Engine(Consts.BinPath);
Project project = engine.CreateNewProject();
string projectText = CreateProjectString(files, rootFolder);
project.LoadXml(projectText);
Assert.IsTrue(project.Build("1"), id + "1 : Error in building");
BuildItemGroup include = project.GetEvaluatedItemsByName("FooPath");
Assert.AreEqual(files.Length, include.Count, id + "2");
for (int i = 0; i < files.Length; i++) {
Assert.AreEqual (files [i], include [i].FinalItemSpec, id + "3, file #" + i);
Assert.IsTrue (include[i].HasMetadata ("TargetPath"), id + "4, file #" + i + ", TargetPath metadata missing");
Assert.AreEqual (assignedFiles [i], include[i].GetMetadata("TargetPath"), id + "5, file #" + i);
Assert.IsTrue (include [i].HasMetadata ("Child"), id + "6, file #" + i + ", Child metadata missing");
Assert.AreEqual ("C" + files [i], include [i].GetMetadata ("Child"), id + "7, file #" + i + ", Child metadata value incorrect");
}
}
string CreateProjectString(string[] files, string rootFolder)
{
StringBuilder sb = new StringBuilder();
sb.Append(@"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""><ItemGroup>");
foreach (string file in files)
sb.AppendFormat("<FooFiles Include=\"{0}\"><Child>C{0}</Child></FooFiles>\n", file);
sb.AppendFormat(@"</ItemGroup>
<Target Name=""1"">
<AssignTargetPath Files=""@(FooFiles)"" RootFolder=""{0}"">
<Output TaskParameter=""AssignedFiles"" ItemName=""FooPath"" />
</AssignTargetPath>
</Target>
</Project>", rootFolder);
return sb.ToString();
}
}
}

View File

@@ -0,0 +1,267 @@
2010-07-09 Ankit Jain <jankit@novell.com>
* MessageTest (TestExecution): Additional messages with 'low'
importance get emitted, so don't expect sequential messages.
2010-04-06 Ankit Jain <jankit@novell.com>
* Consts.cs: Remove.
* AssignProjectConfigurationTest.cs:
* CreateCSharpManifestResourceNameTest.cs:
* CreateVisualBasicManifestResourceNameTest.cs:
* CreateItemTest.cs:
* FindAppConfigFileTest.cs:
* RemoveDuplicatesTest.cs:
* TaskBatchingTest.cs:
* WriteLinesToFileTest.cs:
Set the ToolsVersion to match the profile. Use the
full path to the tasks assembly for UsingTasks.
2010-03-04 Ankit Jain <jankit@novell.com>
* AssignTargetPathTest.cs (CreateProjectString): Remove the
unnecessary import of ms.common.targets .
2010-02-06 Ankit Jain <jankit@novell.com>
* LCTest.cs: New.
2010-02-05 Ankit Jain <jankit@novell.com>
* CreateCSharpManifestResourceNameTest.cs:
* CreateVisualBasicManifestResourceNameTest.cs:
Add new tests for TargetPath metadata.
2010-02-04 Ankit Jain <jankit@novell.com>
* WriteLinesToFileTest.cs: New.
2009-12-22 Ankit Jain <jankit@novell.com>
* CreateItemTest.cs (TestItemsWithWildcards): New.
2009-11-28 Ankit Jain <jankit@novell.com>
* TaskBatchingTest.cs: Add new tests for batching.
2009-11-28 Ankit Jain <jankit@novell.com>
* TaskBatchingTest.cs: Add new tests for batching, use on unbatched
items in a batching scenario.
2009-10-08 Ankit Jain <jankit@novell.com>
* TestMessageLogger.cs (CheckLoggedAny): New.
2009-10-08 Ankit Jain <jankit@novell.com>
* RemoveDuplicatesTest.cs: New.
2009-09-25 Ankit Jain <jankit@novell.com>
* FindAppConfigFileTest.cs: New.
2009-09-01 Ankit Jain <jankit@novell.com>
* TaskBatchingTest.cs: Add new tests for metadata refs found
in places other than task attributes.
2009-08-28 Ankit Jain <jankit@novell.com>
* CopyTest.cs (TestCopy_EmptySources): New.
(TestCopy_EmptyDestFolder): New.
2009-08-26 Ankit Jain <jankit@novell.com>
* CreateItemTest.cs (TestVariableExpansion): Update test to
use a transform with a item reference in a property.
2009-08-26 Ankit Jain <jankit@novell.com>
* CreateItemTest.cs (TestVariableExpansion): New.
* CreatePropertyTest.cs (TestExecution2): New.
2009-08-24 Ankit Jain <jankit@novell.com>
* CreateCSharpManifestResourceNameTest.cs:
* CreateVisualBasicManifestResourceNameTest.cs: Add tests for
folder name with spaces in it.
2009-07-23 Ankit Jain <jankit@novell.com>
* AssignProjectConfigurationTest.cs: New.
2009-06-08 Ankit Jain <jankit@novell.com>
* CreateCSharpManifestResourceNameTest.cs (TestInvalidCulture): New.
2009-06-07 Ankit Jain <jankit@novell.com>
* CscTest.cs (TestDefineConstants): Update DefineConstants to include
spaces also.
2009-06-07 Ankit Jain <jankit@novell.com>
* AssignTargetPathTest.cs: Update tests to not depend on a fixed
root (C:\) or cur dir.
2009-05-29 Ankit Jain <jankit@novell.com>
* TestMessageLogger.cs: Add counts for project/build start/finish
events.
2009-04-27 Ankit Jain <jankit@novell.com>
* CreateVisualBasicManifestResourceNameTest.cs: New.
2009-03-03 Ankit Jain <jankit@novell.com>
* CscTest.cs (DefineConstants): Add some extra semi-colons,
that should get removed on output.
(DefineConstants2): New. Test effectively empty define constants.
2009-02-25 Ankit Jain <jankit@novell.com>
* CreateCSharpManifestResourceNameTest.cs (CheckResourceNames):
Refactor a bit to improve error reporting.
Update to use Path.Combine instead of hardcoding "\".
2009-02-24 Ankit Jain <jankit@novell.com>
* TestMessageLogger.cs (CheckLoggedMessageHead): Move here from
* TaskBatchingTest.cs: .. here. Track api change.
2009-02-21 Ankit Jain <jankit@novell.com>
* CopyTest.cs: New.
2009-01-31 Ankit Jain <jankit@novell.com>
* TaskBatchingTest.cs (*): Add tests for target/task events.
(TestTargetBatching*): New tests for target batching.
* TestMessageLogger.cs: Add counts for target/task started/finished
events.
(NormalMessageCount): New.
2008-12-22 Ankit Jain <jankit@novell.com>
* TestMessageLogger.cs: Emit debug messages to stderr.
* CreateCSharpManifestResourceNameTest.cs: Likewise.
Revert last patch, don't emit to stderr, monobuild emits
the log contents now.
2008-12-22 Ankit Jain <jankit@novell.com>
* TestMessageLogger.cs: Emit debug messages to stderr.
* CreateCSharpManifestResourceNameTest.cs: Likewise.
2008-12-22 Ankit Jain <jankit@novell.com>
* TestMessageLogger.cs: Listen for errors and warnings also.
* CreateCSharpManifestResourceNameTest.cs: Emit helpful info when tests
fail.
2008-12-12 Ankit Jain <jankit@novell.com>
* CreateCSharpManifestResourceNameTest.cs: New.
2008-11-27 Ankit Jain <jankit@novell.com>
* AssignCultureTest.cs: Add tests for "Culture" metadata.
2008-11-23 Ankit Jain <jankit@novell.com>
* AssignCultureTest.cs: New.
2008-11-22 Ankit Jain <jankit@novell.com>
* AssignTargetPathTest.cs: New.
2008-11-21 Ankit Jain <jankit@novell.com>
* CreateItemTest.cs (CheckBuildItem): Make public.
* TestMessageLogger.cs:
* TaskBatchingTests.cs: Fix file mode.
2008-11-21 Ankit Jain <jankit@novell.com>
* CreateItemTest.cs (TestNullFields): New.
(CheckBuildItem): Make public, used by batching tests.
* MessageTest.cs (TestDefaultValues): New.
(TestMessageLogger): Move to ..
* TestMessageLogger.cs: .. here.
* TaskBatchingTests.cs: New. Tests for batching implementation.
2008-11-11 Jonathan Chambers <joncham@gmail.com>
* DeleteTest.cs: Added tests for Delete task.
2008-10-09 Ankit Jain <jankit@novell.com>
* CreateItemTest.cs (TestExcludeAndCondition): New. NotWorking.
2008-08-06 Ankit Jain <jankit@novell.com>
* CscTest.cs: Alter tests to checking for quoting in various switches.
2008-06-02 Atsushi Enomoto <atsushi@ximian.com>
* ResolveAssemblyReferenceTest.cs: marked some failing tests as
[Ignore]. They will never be successful when mono is not
"installed".
2007-03-19 Marek Sieradzki <marek.sieradzki@gmail.com>
* CombinePathTest.cs: Added.
2007-03-17 Marek Sieradzki <marek.sieradzki@gmail.com>
* Consts.cs: Check for runtime not platform.
* ResolveAssemblyReferenceTest.cs: Pass valid SearchPaths.
2007-02-18 Marek Sieradzki <marek.sieradzki@gmail.com>
* ResolveAssemblyReferenceTest.cs: Added.
2006-12-11 Marek Sieradzki <marek.sieradzki@gmail.com>
* GetFrameworkSdkPath.cs, GetFrameworkPath.cs, CreateItemTest.cs,
CreatePropertyTest.cs, RemoveDirTest.cs: Added.
* MakeDirTest.cs: Added check for task's output.
2006-12-08 Marek Sieradzki <marek.sieradzki@gmail.com>
* MakeDirTest.cs, CscTest.cs: Added.
* ManagedCompilerTest.cs: Enabled some NotWorking tests related to
Csc.
2006-12-05 Marek Sieradzki <marek.sieradzki@gmail.com>
* ManagedCompilerTest (TestSources ()): Enabled.
2006-12-04 Marek Sieradzki <marek.sieradzki@gmail.com>
* ALTest.cs, ManagedCompilerTest.cs: New tests.
* Consts.cs: Added a platform check.
* TestEngine.cs: Class that acts like IBuildEngine implementation from
Microsoft.Build.BuildEngine.
2006-06-17 Marek Sieradzki <marek.sieradzki@gmail.com>
* ErrorTest.cs: Added check for Execute () return value.
2006-05-26 Marek Sieradzki <marek.sieradzki@gmail.com>
* MessageTest.cs: Corrected.
* WarningTest.cs: Added.
* ErrorTest.cs: Added new test.
2006-05-22 Marek Sieradzki <marek.sieradzki@gmail.com>
* Consts.cs: Moved BinPath here.
* MessageTest.cs: Added new test.
2006-05-03 Marek Sieradzki <marek.sieradzki@gmail.com>
* ErrorTest.cs: Added.

View File

@@ -0,0 +1,155 @@
//
// CodeTaskFactoryTest.cs
//
// Author:
// Atsushi Enomoto <atsushi@xamarin.com>
//
// Copyright (C) 2014 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.
//
#if NET_4_0
using System;
using System.IO;
using System.Linq;
using System.Xml;
using Microsoft.Build.Framework;
using Microsoft.Build.Tasks;
using NUnit.Framework;
using Microsoft.Build.Construction;
using Microsoft.Build.Evaluation;
using Microsoft.Build.Logging;
namespace MonoTests.Microsoft.Build.Tasks
{
[TestFixture]
public class CodeTaskFactoryTest
{
[Test]
public void EmptyFactory ()
{
var f = new CodeTaskFactory ();
Assert.AreEqual ("Code Task Factory", f.FactoryName, "Name");
Assert.IsNull (f.TaskType, "TaskType");
Assert.IsNull (f.CreateTask (null), "CreateTask");
}
[Test]
public void Hello ()
{
string project_xml = @"<Project ToolsVersion='4.0' xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
<UsingTask
TaskName='DoNothing'
TaskFactory='CodeTaskFactory'
AssemblyFile='$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll' >
<ParameterGroup />
<Task>
<Code Type='Fragment' Language='cs'>
<![CDATA[
// Display ""Hello, world!""
Log.LogWarning(""Hello, world!"");
]]> </Code>
</Task>
</UsingTask>
<Target Name='default'>
<DoNothing />
</Target>
</Project>";
var root = ProjectRootElement.Create (XmlReader.Create (new StringReader (project_xml)));
root.FullPath = "CodeTaskFactoryTest.Hello.proj";
var project = new Project (root);
Assert.IsTrue (project.Build (new ConsoleLogger (LoggerVerbosity.Diagnostic)), "Build");
}
[Test]
public void MultipleCodeElements ()
{
string project_xml = @"<Project ToolsVersion='4.0' xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
<UsingTask
TaskName='DoNothing'
TaskFactory='CodeTaskFactory'
AssemblyFile='$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll' >
<ParameterGroup />
<Task>
<Code Type='Fragment' Language='cs'></Code>
<Code Type='Fragment' Language='cs'></Code>
</Task>
</UsingTask>
<Target Name='default'>
<DoNothing />
</Target>
</Project>";
var root = ProjectRootElement.Create (XmlReader.Create (new StringReader (project_xml)));
root.FullPath = "CodeTaskFactoryTest.MultipleCodeElements.proj";
var project = new Project (root);
Assert.IsFalse (project.Build (), "Build");
}
[Test]
public void InvalidLanguage ()
{
string project_xml = @"<Project ToolsVersion='4.0' xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
<UsingTask
TaskName='DoNothing'
TaskFactory='CodeTaskFactory'
AssemblyFile='$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll' >
<ParameterGroup />
<Task>
<Code Type='Fragment' Language='ts'></Code>
</Task>
</UsingTask>
<Target Name='default'>
<DoNothing />
</Target>
</Project>";
var root = ProjectRootElement.Create (XmlReader.Create (new StringReader (project_xml)));
root.FullPath = "CodeTaskFactoryTest.InvalidLanguage.proj";
var project = new Project (root);
Assert.IsFalse (project.Build (), "Build");
}
[Test]
public void InvalidCSharp ()
{
string project_xml = @"<Project ToolsVersion='4.0' xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
<UsingTask
TaskName='DoNothing'
TaskFactory='CodeTaskFactory'
AssemblyFile='$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll' >
<ParameterGroup />
<Task>
<Code Type='Fragment' Language='cs'>
""Hello, world!""
</Code>
</Task>
</UsingTask>
<Target Name='default'>
<DoNothing />
</Target>
</Project>";
var root = ProjectRootElement.Create (XmlReader.Create (new StringReader (project_xml)));
root.FullPath = "CodeTaskFactoryTest.InvalidCSharp.proj";
var project = new Project (root);
Assert.IsFalse (project.Build (), "Build");
}
}
}
#endif

View File

@@ -0,0 +1,124 @@
//
// CombinePath.cs
//
// Author:
// Marek Sieradzki (marek.sieradzki@gmail.com)
//
// (C) 2006 Marek Sieradzki
//
// 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;
using System.IO;
using Microsoft.Build.BuildEngine;
using Microsoft.Build.Framework;
using Microsoft.Build.Tasks;
using Microsoft.Build.Utilities;
using NUnit.Framework;
namespace MonoTests.Microsoft.Build.Tasks {
[TestFixture]
public class CombinePathTest {
[Test]
public void TestAssignment ()
{
CombinePath cp = new CombinePath ();
cp.BasePath = "a";
cp.Paths = new ITaskItem [] { new TaskItem ("b")};
Assert.AreEqual ("a", cp.BasePath, "A1");
Assert.AreEqual ("b", cp.Paths [0].ItemSpec, "A2");
}
[Test]
public void TestExecution1 ()
{
Engine engine;
Project project;
string documentString = @"
<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
<ItemGroup>
<Dir Include='b' />
<Dir Include='c' />
<Dir Include='d\e' />
</ItemGroup>
<Target Name='1'>
<CombinePath BasePath='a' Paths='@(Dir)'>
<Output
TaskParameter='CombinedPaths'
ItemName='Out'
/>
</CombinePath>
</Target>
</Project>
";
engine = new Engine (Consts.BinPath);
project = engine.CreateNewProject ();
project.LoadXml (documentString);
Assert.IsTrue (project.Build ("1"), "A1");
BuildItemGroup output = project.GetEvaluatedItemsByName ("Out");
Assert.AreEqual (3, output.Count, "A2");
Assert.AreEqual (Path.Combine ("a", "b"), output [0].FinalItemSpec, "A3");
Assert.AreEqual (Path.Combine ("a", "c"), output [1].FinalItemSpec, "A4");
Assert.AreEqual (Path.Combine ("a", Path.Combine ("d", "e")), output [2].FinalItemSpec, "A5");
}
[Test]
public void TestExecution2 ()
{
Engine engine;
Project project;
string documentString = @"
<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
<ItemGroup>
<Dir Include='a\b' />
</ItemGroup>
<Target Name='1'>
<CombinePath Paths='@(Dir)'>
<Output
TaskParameter='CombinedPaths'
ItemName='Out'
/>
</CombinePath>
</Target>
</Project>
";
engine = new Engine (Consts.BinPath);
project = engine.CreateNewProject ();
project.LoadXml (documentString);
Assert.IsTrue (project.Build ("1"), "A1");
BuildItemGroup output = project.GetEvaluatedItemsByName ("Out");
Assert.AreEqual (1, output.Count, "A2");
Assert.AreEqual (Path.Combine ("a", "b"), output [0].FinalItemSpec, "A3");
}
}
}

View File

@@ -0,0 +1,430 @@
//
// CopyTest.cs
//
// Author:
// Ankit Jain (jankit@novell.com)
//
// Copyright 2009 Novell, Inc (http://www.novell.com)
//
// 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.IO;
using Microsoft.Build.BuildEngine;
using NUnit.Framework;
using System.Text;
using Microsoft.Build.Tasks;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
namespace MonoTests.Microsoft.Build.Tasks {
[TestFixture]
public class CopyTest {
string source_path, target_path;
[SetUp]
public void CreateDir ()
{
source_path = Path.Combine (Path.Combine ("Test", "resources"), "Copy");
Directory.CreateDirectory (source_path);
target_path = Path.Combine (Path.Combine ("Test", "resources"), "Target");
Directory.CreateDirectory (target_path);
}
[TearDown]
public void RemoveDirectories ()
{
Directory.Delete (source_path, true);
Directory.Delete (target_path, true);
}
[Test]
public void TestCopy_MissingSourceFile ()
{
Copy copy = new Copy ();
copy.BuildEngine = new TestEngine ();
copy.SourceFiles = new ITaskItem [1];
copy.SourceFiles [0] = new TaskItem ("SourceDoesNotExist");
copy.DestinationFiles = new ITaskItem [1];
copy.DestinationFiles [0] = new TaskItem ("DestDoesNotExist");
Assert.IsFalse (copy.Execute ());
}
[Test]
public void TestCopy1 ()
{
Engine engine;
Project project;
string file_path = Path.Combine (source_path, "copy.txt");
string target_file = Path.Combine (target_path, "copy.txt");
using (File.CreateText (file_path)) { }
string documentString = @"
<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
<PropertyGroup><DestFile>" + target_file + @"</DestFile></PropertyGroup>
<ItemGroup>
<SFiles Include='" + file_path + @"'><Md>1</Md></SFiles>
<DFiles Include='$(DestFile)'><Mde>2</Mde></DFiles>
</ItemGroup>
<Target Name='1'>
<Copy SourceFiles='@(SFiles)' DestinationFiles='@(DFiles)' SkipUnchangedFiles='true' >
<Output TaskParameter='CopiedFiles' ItemName='I0'/>
<Output TaskParameter='DestinationFiles' ItemName='I1'/>
</Copy>
<Message Text=""I0 : @(I0), I1: @(I1)""/>
</Target>
</Project>
";
engine = new Engine (Consts.BinPath);
project = engine.CreateNewProject ();
TestMessageLogger testLogger = new TestMessageLogger ();
engine.RegisterLogger (testLogger);
project.LoadXml (documentString);
if (!project.Build ("1")) {
var sb = new StringBuilder ();
testLogger.DumpMessages (sb);
Assert.Fail ("Build failed " + sb.ToString ());
}
Assert.IsTrue (File.Exists (target_file), "A2");
BuildItemGroup big = project.GetEvaluatedItemsByName ("I0");
Assert.AreEqual (1, big.Count, "A3");
BuildItem bi = big [0];
Assert.AreEqual (target_file, bi.FinalItemSpec, "A4");
Assert.AreEqual ("1", bi.GetMetadata ("Md"), "A4");
Assert.AreEqual ("2", bi.GetMetadata ("Mde"), "A5");
big = project.GetEvaluatedItemsByName ("I1");
Assert.AreEqual (1, big.Count, "A10");
bi = big [0];
Assert.AreEqual (target_file, bi.FinalItemSpec, "A11");
Assert.AreEqual ("1", bi.GetMetadata ("Md"), "A12");
Assert.AreEqual ("2", bi.GetMetadata ("Mde"), "A13");
// build again, this time files won't get copied because
// of SkipUnchangedFiles=true
if (!project.Build ("1")) {
testLogger.DumpMessages ();
Assert.Fail ("Build failed #2");
}
Assert.IsTrue (File.Exists (target_file), "A20");
big = project.GetEvaluatedItemsByName ("I0");
Assert.AreEqual (1, big.Count, "A21");
bi = big [0];
Assert.AreEqual (target_file, bi.FinalItemSpec, "A22");
Assert.AreEqual ("1", bi.GetMetadata ("Md"), "A23");
Assert.AreEqual ("2", bi.GetMetadata ("Mde"), "A24");
big = project.GetEvaluatedItemsByName ("I1");
Assert.AreEqual (1, big.Count, "A25");
bi = big [0];
Assert.AreEqual (target_file, bi.FinalItemSpec, "A26");
Assert.AreEqual ("1", bi.GetMetadata ("Md"), "A27");
Assert.AreEqual ("2", bi.GetMetadata ("Mde"), "A28");
}
[Test]
public void TestCopy2 ()
{
Engine engine;
Project project;
string [] file_paths = new string [] {
Path.Combine (source_path, "copy1.txt"),
Path.Combine (source_path, "copy2.txt")
};
using (File.CreateText (file_paths[0])) { }
using (File.CreateText (file_paths[1])) { }
string documentString = @"
<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
<PropertyGroup><TargetPath>" + target_path + @"</TargetPath></PropertyGroup>
<ItemGroup>
<SFiles Include='" + file_paths [0] + @"'><Md>1</Md></SFiles>
<SFiles Include='" + file_paths [1] + @"'><Md>2</Md></SFiles>
</ItemGroup>
<Target Name='1'>
<Copy SourceFiles='@(SFiles)' DestinationFolder='$(TargetPath)' SkipUnchangedFiles='true' >
<Output TaskParameter='CopiedFiles' ItemName='I0'/>
<Output TaskParameter='DestinationFiles' ItemName='I1'/>
</Copy>
</Target>
</Project>
";
engine = new Engine (Consts.BinPath);
project = engine.CreateNewProject ();
TestMessageLogger testLogger = new TestMessageLogger ();
engine.RegisterLogger (testLogger);
project.LoadXml (documentString);
if (!project.Build ("1")) {
testLogger.DumpMessages ();
Assert.Fail ("Build failed");
}
CheckCopyBuildItems (project, file_paths, target_path, "A1");
// build again, this time files won't get copied because
// of SkipUnchangedFiles=true
if (!project.Build ("1")) {
testLogger.DumpMessages ();
Assert.Fail ("Build failed #2");
}
CheckCopyBuildItems (project, file_paths, target_path, "A2");
}
[Test]
public void TestCopy_EmptySources () {
Engine engine;
Project project;
string documentString = @"
<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
<Target Name='1'>
<Copy SourceFiles='@(NonExistantSourceFiles)' DestinationFolder='$(TargetPath)' SkipUnchangedFiles='true' >
<Output TaskParameter='CopiedFiles' ItemName='I0'/>
<Output TaskParameter='DestinationFiles' ItemName='I1'/>
</Copy>
</Target>
</Project>
";
engine = new Engine (Consts.BinPath);
project = engine.CreateNewProject ();
TestMessageLogger testLogger = new TestMessageLogger ();
engine.RegisterLogger (testLogger);
project.LoadXml (documentString);
if (!project.Build ("1")) {
testLogger.DumpMessages ();
Assert.Fail ("Build failed");
}
}
[Test]
public void TestCopy_EmptyDestFolder () {
Engine engine;
Project project;
string documentString = @"
<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
<ItemGroup>
<SFiles Include='foo.txt'><Md>1</Md></SFiles>
</ItemGroup>
<Target Name='1'>
<Copy SourceFiles='@(SFiles)' DestinationFolder='@(NonExistant)' DestinationFiles='@(NonExistant)' SkipUnchangedFiles='true' >
<Output TaskParameter='CopiedFiles' ItemName='I0'/>
<Output TaskParameter='DestinationFiles' ItemName='I1'/>
</Copy>
</Target>
</Project>
";
engine = new Engine (Consts.BinPath);
project = engine.CreateNewProject ();
TestMessageLogger testLogger = new TestMessageLogger ();
engine.RegisterLogger (testLogger);
project.LoadXml (documentString);
if (project.Build ("1")) {
testLogger.DumpMessages ();
Assert.Fail ("Build should have failed");
}
}
[Test]
public void TestCopy_ReadOnlyUpdate ()
{
Engine engine;
Project project;
string file_path = Path.Combine (source_path, "copyro.txt");
string target_file = Path.Combine (target_path, "copyro.txt");
using (File.CreateText (file_path)) { }
string documentString = @"
<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
<PropertyGroup><DestFile>" + target_file + @"</DestFile></PropertyGroup>
<ItemGroup>
<SFiles Include='" + file_path + @"'><Md>1</Md></SFiles>
<DFiles Include='$(DestFile)'><Mde>2</Mde></DFiles>
</ItemGroup>
<Target Name='1'>
<Copy SourceFiles='@(SFiles)' DestinationFiles='@(DFiles)' >
<Output TaskParameter='CopiedFiles' ItemName='I0'/>
<Output TaskParameter='DestinationFiles' ItemName='I1'/>
</Copy>
<Message Text=""I0 : @(I0), I1: @(I1)""/>
</Target>
</Project>
";
engine = new Engine (Consts.BinPath);
project = engine.CreateNewProject ();
TestMessageLogger testLogger = new TestMessageLogger ();
engine.RegisterLogger (testLogger);
project.LoadXml (documentString);
if (!project.Build ("1")) {
testLogger.DumpMessages ();
Assert.Fail ("Build failed");
}
Assert.IsTrue (File.Exists (target_file), "A2");
Assert.AreEqual (FileAttributes.Normal, File.GetAttributes (target_file), "A3");
}
#if NET_3_5
[Test]
public void TestCopy_OverwriteReadOnlyTrue ()
{
Engine engine;
Project project;
string file_path = Path.Combine (source_path, "copyro1.txt");
string target_file = Path.Combine (target_path, "copyro1.txt");
using (File.CreateText (file_path)) { }
using (File.CreateText (target_file)) { }
File.SetAttributes (target_file, FileAttributes.ReadOnly);
Assert.AreEqual (FileAttributes.ReadOnly, File.GetAttributes (target_file), "A1");
string documentString = @"
<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"" ToolsVersion=""3.5"">
<PropertyGroup><DestFile>" + target_file + @"</DestFile></PropertyGroup>
<ItemGroup>
<SFiles Include='" + file_path + @"'><Md>1</Md></SFiles>
<DFiles Include='$(DestFile)'><Mde>2</Mde></DFiles>
</ItemGroup>
<Target Name='1'>
<Copy SourceFiles='@(SFiles)' DestinationFiles='@(DFiles)' OverwriteReadOnlyFiles='true'>
<Output TaskParameter='CopiedFiles' ItemName='I0'/>
<Output TaskParameter='DestinationFiles' ItemName='I1'/>
</Copy>
<Message Text=""I0 : @(I0), I1: @(I1)""/>
</Target>
</Project>
";
engine = new Engine (Consts.BinPath);
project = engine.CreateNewProject ();
TestMessageLogger testLogger = new TestMessageLogger ();
engine.RegisterLogger (testLogger);
project.LoadXml (documentString);
if (!project.Build ("1")) {
var sb = new StringBuilder ();
testLogger.DumpMessages (sb);
Assert.Fail ("Build failed " + sb.ToString ());
}
Assert.IsTrue (File.Exists (target_file), "A2");
Assert.AreEqual (FileAttributes.Normal, File.GetAttributes (target_file), "A3");
}
[Test]
public void TestCopy_OverwriteReadOnlyFalse ()
{
Engine engine;
Project project;
string file_path = Path.Combine (source_path, "copyro2.txt");
string target_file = Path.Combine (target_path, "copyro2.txt");
using (File.CreateText (file_path)) { }
using (File.CreateText (target_file)) { }
File.SetAttributes (target_file, FileAttributes.ReadOnly);
Assert.AreEqual (FileAttributes.ReadOnly, File.GetAttributes (target_file), "A1");
string documentString = @"
<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
<PropertyGroup><DestFile>" + target_file + @"</DestFile></PropertyGroup>
<ItemGroup>
<SFiles Include='" + file_path + @"'><Md>1</Md></SFiles>
<DFiles Include='$(DestFile)'><Mde>2</Mde></DFiles>
</ItemGroup>
<Target Name='1'>
<Copy SourceFiles='@(SFiles)' DestinationFiles='@(DFiles)'>
<Output TaskParameter='CopiedFiles' ItemName='I0'/>
<Output TaskParameter='DestinationFiles' ItemName='I1'/>
</Copy>
<Message Text=""I0 : @(I0), I1: @(I1)""/>
</Target>
</Project>
";
engine = new Engine (Consts.BinPath);
project = engine.CreateNewProject ();
TestMessageLogger testLogger = new TestMessageLogger ();
engine.RegisterLogger (testLogger);
project.LoadXml (documentString);
// build should fail because of the readonly target file
Assert.IsFalse (project.Build ("1"));
File.SetAttributes (target_file, FileAttributes.Normal);
}
#endif
void CheckCopyBuildItems (Project project, string [] source_files, string destination_folder, string prefix)
{
int num = source_files.Length;
for (int i = 0; i < num; i ++)
Assert.IsTrue (File.Exists (source_files [i]), prefix + " C1");
BuildItemGroup big = project.GetEvaluatedItemsByName ("I0");
Assert.AreEqual (num, big.Count, prefix + " C2");
for (int i = 0; i < num; i++) {
string suffix = (i + 1).ToString ();
BuildItem bi = big [i];
Assert.AreEqual (Path.Combine (destination_folder, Path.GetFileName (source_files [i])),
bi.FinalItemSpec, prefix + " C3 #" + suffix);
Assert.AreEqual (suffix, bi.GetMetadata ("Md"), prefix + " C4 #" + suffix);
}
big = project.GetEvaluatedItemsByName ("I1");
Assert.AreEqual (num, big.Count, prefix + " C6");
for (int i = 0; i < num; i++) {
string suffix = (i + 1).ToString ();
BuildItem bi = big [i];
Assert.AreEqual (Path.Combine (destination_folder, Path.GetFileName (source_files [i])),
bi.FinalItemSpec, prefix + " C7 #" + suffix);
Assert.AreEqual (suffix, bi.GetMetadata ("Md"), prefix + " C8 #" + suffix);
}
}
}
}

View File

@@ -0,0 +1,298 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using NUnit.Framework;
using Microsoft.Build.BuildEngine;
namespace MonoTests.Microsoft.Build.Tasks
{
[TestFixture]
public class CreateCSharpManifestResourceNameTest
{
string [,] resx_no_culture_files, resx_with_culture_files;
string [,] non_resx_no_culture_files, non_resx_with_culture_files;
public CreateCSharpManifestResourceNameTest ()
{
string sample_cs_path = Path.Combine ("Test", Path.Combine ("resources", "Sample.cs"));
string junk_file = Path.Combine ("Test", Path.Combine ("resources", "junk.txt"));
string curdir = Path.GetDirectoryName (Environment.CurrentDirectory);
/* {Include, LogicalName, DependentUpon, TargetPath} */
resx_no_culture_files = new string [,] {
// With dependent file
{ "foo with space.resx", null, sample_cs_path, null },
{ "foo with space.resx", "RandomName", sample_cs_path, null },
{ "foo with space.resx", "RandomName", sample_cs_path, "bar with space.resx" },
// can't find a C# class in the .vb file
{ "foo with space.resx", "RandomName", junk_file, "bar with space.resx" },
{ "Test/resources/foo with space.resx", null, "Sample.cs", null },
{ "Test/resources/foo with space.resx", "RandomName", "Sample.cs", null },
{ "Test/resources/foo with space.resx", "RandomName", "Sample.cs", "bar with space.resx"},
// W/o dependent file
{ "foo with space.resx", null, null, null },
{ "foo with space.resx", "RandomName", null, null },
{ "Test/resources folder/foo with space.resx", null, null, null },
{ "Test/resources folder/foo with space.resx", "RandomName", null, null },
};
resx_with_culture_files = new string [,] {
// With dependent file
{ "foo with space.de.resx", null, sample_cs_path, null },
{ "foo with space.de.resx", "RandomName", sample_cs_path, null },
{ "foo with space.de.resx", "RandomName", sample_cs_path, "bar with space.fr.resx" },
// can't find a C# class in the .vb file
{ "foo with space.de.resx", "RandomName", junk_file, "bar with space.fr.resx" },
{ "Test/resources/foo with space.de.resx", null, "Sample.cs", null },
{ "Test/resources/foo with space.de.resx", "RandomName", "Sample.cs", null},
// W/o dependent file
{ "foo with space.de.resx", null, null, null },
{ "foo with space.de.resx", "RandomName", null, null },
{ "Test/resources folder/foo with space.de.resx", null, null, null },
{ "Test/resources folder/foo with space.de.resx", "RandomName", null, null }
};
non_resx_no_culture_files = new string [,] {
{ "foo with space.txt", null, null },
{ "foo with space.txt", "RandomName", null },
{ "Test/resources folder/foo with space.txt", null, null },
{ "Test/resources folder/foo with space.txt", "RandomName", null }
};
non_resx_with_culture_files = new string [,] {
{ "foo with space.de.txt", null, null },
{ "foo with space.de.txt", "RandomName", null },
{ "Test/resources folder/foo with space.de.txt", null, null },
{ "Test/resources folder/foo with space.de.txt", "RandomName", null }
};
}
[Test]
public void TestNoRootNamespaceNoCulture ()
{
CheckResourceNames (resx_no_culture_files, new string [] {
// w/ dependent file
"Mono.Tests.Sample", "Mono.Tests.Sample",
"Mono.Tests.Sample", "bar with space",
"Mono.Tests.Sample", "Mono.Tests.Sample",
// W/o dependent file
"Mono.Tests.Sample", "foo with space" ,
"foo with space", "Test.resources_folder.foo with space",
"Test.resources_folder.foo with space",
}, null);
}
[Test]
public void TestWithRootNamespaceNoCulture ()
{
//FIXME: How does LogicalName affect things??
CheckResourceNames (resx_no_culture_files, new string [] {
// With dependent file
"Mono.Tests.Sample", "Mono.Tests.Sample",
"Mono.Tests.Sample", "RN1.RN2.bar with space",
"Mono.Tests.Sample", "Mono.Tests.Sample",
// W/o dependent file
"Mono.Tests.Sample", "RN1.RN2.foo with space",
"RN1.RN2.foo with space", "RN1.RN2.Test.resources_folder.foo with space",
"RN1.RN2.Test.resources_folder.foo with space"},
"RN1.RN2");
}
[Test]
public void TestNoRootNamespaceWithCulture ()
{
CheckResourceNames (resx_with_culture_files, new string [] {
// With dependent file
"Mono.Tests.Sample.de", "Mono.Tests.Sample.de",
"Mono.Tests.Sample.fr", "bar with space.fr",
"Mono.Tests.Sample.de", "Mono.Tests.Sample.de",
// W/o dependent file
"foo with space.de", "foo with space.de",
"Test.resources_folder.foo with space.de", "Test.resources_folder.foo with space.de" }, null);
}
[Test]
public void TestWithRootNamespaceWithCulture ()
{
CheckResourceNames (resx_with_culture_files, new string [] {
// With dependent file
"Mono.Tests.Sample.de", "Mono.Tests.Sample.de",
"Mono.Tests.Sample.fr", "RN1.RN2.bar with space.fr",
"Mono.Tests.Sample.de", "Mono.Tests.Sample.de",
// W/o dependent file
"RN1.RN2.foo with space.de", "RN1.RN2.foo with space.de",
"RN1.RN2.Test.resources_folder.foo with space.de", "RN1.RN2.Test.resources_folder.foo with space.de"},
"RN1.RN2");
}
[Test]
public void TestNonResxNoRootNamespaceWithCulture ()
{
CheckResourceNames (non_resx_with_culture_files, new string [] {
Path.Combine ("de", "foo with space.txt"), Path.Combine ("de", "foo with space.txt"),
Path.Combine ("de", "Test.resources_folder.foo with space.txt"), Path.Combine ("de", "Test.resources_folder.foo with space.txt")}, null);
}
[Test]
public void TestNonResxWithRootNamespaceWithCulture ()
{
CheckResourceNames (non_resx_with_culture_files, new string [] {
Path.Combine ("de", "RN1.RN2.foo with space.txt"), Path.Combine ("de", "RN1.RN2.foo with space.txt"),
Path.Combine ("de", "RN1.RN2.Test.resources_folder.foo with space.txt"), Path.Combine ("de", "RN1.RN2.Test.resources_folder.foo with space.txt")},
"RN1.RN2");
}
[Test]
public void TestNonResxNoRootNamespaceNoCulture ()
{
CheckResourceNames (non_resx_no_culture_files, new string [] {
"foo with space.txt", "foo with space.txt",
"Test.resources_folder.foo with space.txt", "Test.resources_folder.foo with space.txt"}, null);
}
[Test]
public void TestNonResxWithRootNamespaceNoCulture ()
{
CheckResourceNames (non_resx_no_culture_files, new string [] {
// With dependent file
"RN1.RN2.foo with space.txt", "RN1.RN2.foo with space.txt",
"RN1.RN2.Test.resources_folder.foo with space.txt", "RN1.RN2.Test.resources_folder.foo with space.txt"},
"RN1.RN2");
}
[Test]
public void TestExternalResourcesNoRootNamespaceWithTargetPath ()
{
CheckResourceNames (new string[,] {
{"../folder/foo.txt", null, null, "abc.txt"},
{"../folder/foo.de.txt", null, null, "xyz.txt"}},
new string[] { "abc.txt", "xyz.txt" }, null);
}
[Test]
public void TestExternalResourcesWithRootNamespaceWithTargetPath ()
{
CheckResourceNames (new string[,] {
{"../folder/foo.txt", null, null, "abc.txt"},
{"../folder/foo.de.txt", null, null, "xyz.txt"}},
new string[] { "RN.abc.txt", "RN.xyz.txt" }, "RN");
}
[Test]
public void TestExternalResourcesNoRootNamespaceNoTargetPath ()
{
CheckResourceNames (new string[,] {
{"../folder/foo.txt", null, null},
{"../folder/foo.de.txt", null, null}},
new string[] { "...folder.foo.txt", Path.Combine ("de", "...folder.foo.txt") }, null);
}
[Test]
public void TestExternalResourcesWithRootNamespaceNoTargetPath ()
{
CheckResourceNames (new string[,] {
{"../folder/foo.txt", null, null},
{"../folder/foo.de.txt", null, null}},
new string[] { "RN....folder.foo.txt", Path.Combine ("de", "RN....folder.foo.txt") }, "RN");
}
[Test]
public void TestInvalidCulture ()
{
string [,] files = new string [,] {
{ "Foo.invalid.txt", null, null },
{ "Foo.invalid.resx", null, null }
};
CheckResourceNames (files, new string [] {"RN1.RN2.Foo.invalid.txt", "RN1.RN2.Foo.invalid"},
"RN1.RN2");
}
void CheckResourceNames (string [,] files, string [] names, string rootNamespace)
{
Assert.AreEqual (files.GetUpperBound (0) + 1, names.Length, "Number of files and names must match");
string projectText = CreateProject (files, rootNamespace);
Engine engine = new Engine (Consts.BinPath);
Project project = engine.CreateNewProject ();
TestMessageLogger logger = new TestMessageLogger ();
engine.RegisterLogger (logger);
project.LoadXml (projectText);
if (!project.Build ("1")) {
Console.WriteLine (projectText);
logger.DumpMessages ();
Assert.Fail ("Build failed");
}
bool has_targetpaths = files.GetUpperBound (1) == 3;
BuildItemGroup group = project.GetEvaluatedItemsByName ("ResourceNames");
Assert.AreEqual (names.Length, group.Count, "A2");
for (int i = 0; i <= files.GetUpperBound (0); i++) {
Assert.AreEqual (names [i], group [i].FinalItemSpec, "A3 #" + (i + 1));
Assert.AreEqual (files [i, 1] != null, group [i].HasMetadata ("LogicalName"), "A4 #" + (i + 1));
if (files [i, 1] != null)
Assert.AreEqual (files [i, 1], group [i].GetMetadata ("LogicalName"), "A5 #" + (i + 1));
Assert.AreEqual (files [i, 2] != null, group [i].HasMetadata ("DependentUpon"), "A6 #" + (i + 1));
if (files [i, 2] != null)
Assert.AreEqual (files [i, 2], group [i].GetMetadata ("DependentUpon"), "A7 #" + (i + 1));
if (has_targetpaths && files [i, 3] != null)
Assert.AreEqual (files [i, 3], group [i].GetMetadata ("TargetPath"), "A8 #" + (i + 1));
}
}
string CreateProject (string [,] files, string rootNamespace)
{
StringBuilder sb = new StringBuilder ();
sb.Append ("<Project xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n");
bool has_targetpaths = files.GetUpperBound (1) == 3;
sb.Append ("\t<ItemGroup>\n");
for (int i = 0; i <= files.GetUpperBound (0); i ++) {
sb.AppendFormat ("\t\t<ResourceFiles Include = \"{0}\">\n", files [i, 0]);
if (has_targetpaths && files [i, 3] != null)
sb.AppendFormat ("\t\t\t<TargetPath>{0}</TargetPath>\n", files [i, 3]);
if (files [i, 1] != null)
sb.AppendFormat ("\t\t\t<LogicalName>{0}</LogicalName>\n", files [i, 1]);
if (files [i, 2] != null)
sb.AppendFormat ("\t\t\t<DependentUpon>{0}</DependentUpon>\n", files [i, 2]);
sb.AppendFormat ("\t\t</ResourceFiles>\n");
}
sb.Append ("\t</ItemGroup>\n");
sb.Append ("\t<Target Name=\"1\">\n");
sb.Append ("\t\t<CreateCSharpManifestResourceName ResourceFiles=\"@(ResourceFiles)\" ");
if (rootNamespace != null)
sb.AppendFormat (" RootNamespace = \"{0}\"", rootNamespace);
sb.Append (">\n \t\t\t<Output TaskParameter=\"ManifestResourceNames\" ItemName=\"ResourceNames\" />\n");
sb.Append ("\t\t</CreateCSharpManifestResourceName>\n\t</Target>\n");
sb.Append ("\t" + GetUsingTask ("CreateCSharpManifestResourceName"));
sb.Append ("</Project>");
return sb.ToString ();
}
string GetUsingTask (string taskName)
{
return "<UsingTask TaskName='Microsoft.Build.Tasks." + taskName + "' AssemblyFile='" + Consts.GetTasksAsmPath () + "' />";
}
}
}

View File

@@ -0,0 +1,406 @@
//
// CreateItemTest.cs
//
// Author:
// Marek Sieradzki (marek.sieradzki@gmail.com)
//
// (C) 2006 Marek Sieradzki
//
// 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;
using System.IO;
using Microsoft.Build.BuildEngine;
using Microsoft.Build.Framework;
using Microsoft.Build.Tasks;
using Microsoft.Build.Utilities;
using NUnit.Framework;
namespace MonoTests.Microsoft.Build.Tasks {
[TestFixture]
public class CreateItemTest {
[Test]
public void TestAssignment ()
{
CreateItem ci = new CreateItem ();
ci.AdditionalMetadata = new string [1] { "a=1" };
ci.Include = new ITaskItem [1] { new TaskItem ("1") };
ci.Exclude = new ITaskItem [1] { new TaskItem ("2") };
Assert.AreEqual ("a=1", ci.AdditionalMetadata [0], "A1");
Assert.AreEqual ("1", ci.Include [0].ItemSpec, "A2");
Assert.AreEqual ("2", ci.Exclude [0].ItemSpec, "A3");
}
[Test]
public void TestExecution1 ()
{
Engine engine;
Project project;
string documentString = @"
<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
<ItemGroup>
<A Include='1;2'>
<Sub>fooA</Sub>
</A>
<A Include='3;4'>
<Sub>fooC</Sub>
</A>
<B Include='1;3'>
<Sub>fooB</Sub>
</B>
</ItemGroup>
<Target Name='1'>
<CreateItem
AdditionalMetadata='a=1; b = 2 '
Include='@(A)'
Exclude='@(B)'
>
<Output
TaskParameter='Include'
ItemName='NewItem'
/>
</CreateItem>
</Target>
</Project>
";
engine = new Engine (Consts.BinPath);
project = engine.CreateNewProject ();
project.LoadXml (documentString);
Assert.IsTrue (project.Build ("1"), "A1");
BuildItemGroup include = project.GetEvaluatedItemsByName ("NewItem");
Assert.AreEqual (2, include.Count, "A2");
string [,] additional_metadata = new string [,] { { "a", "1" }, { "b", "2" }, { "Sub", "fooA" } };
CheckBuildItem (include [0], "NewItem", additional_metadata, "2", "A");
additional_metadata = new string [,] { { "a", "1" }, { "b", "2" }, { "Sub", "fooC" } };
CheckBuildItem (include [1], "NewItem", additional_metadata, "4", "B");
}
[Test]
public void TestExcludeAndCondition ()
{
Engine engine;
Project project;
string documentString = @"
<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
<ItemGroup>
<A Include='1;2;5'>
<Sub>fooA</Sub>
</A>
<A Include='3;4'>
<Sub>fooC</Sub>
</A>
<B Include='1;3'>
<Sub>fooB</Sub>
</B>
</ItemGroup>
<Target Name='1'>
<CreateItem
AdditionalMetadata='a=1;b=2'
Include='@(A)'
Exclude='@(B)'
Condition=""'%(Sub)' == 'fooA'""
>
<Output
TaskParameter='Include'
ItemName='NewItem'
/>
</CreateItem>
</Target>
</Project>
";
engine = new Engine (Consts.BinPath);
project = engine.CreateNewProject ();
project.LoadXml (documentString);
Assert.IsTrue (project.Build ("1"), "A1");
BuildItemGroup include = project.GetEvaluatedItemsByName ("NewItem");
Assert.AreEqual (3, include.Count, "A2");
string [,] additional_metadata = new string [,] { { "a", "1" }, {"b", "2"}, {"Sub", "fooA" } };
CheckBuildItem (include [0], "NewItem", additional_metadata, "1", "A");
CheckBuildItem (include [1], "NewItem", additional_metadata, "2", "B");
CheckBuildItem (include [2], "NewItem", additional_metadata, "5", "C");
}
[Test]
public void TestNullFields ()
{
Engine engine;
Project project;
string documentString = @"
<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
<ItemGroup>
<A Include='1;2;5'>
<Sub>fooA</Sub>
</A>
</ItemGroup>
<Target Name='1'>
<CreateItem Include='@(A)' >
<Output
TaskParameter='Include'
ItemName='NewItem'
/>
</CreateItem>
</Target>
</Project>";
engine = new Engine (Consts.BinPath);
project = engine.CreateNewProject ();
project.LoadXml (documentString);
Assert.IsTrue (project.Build ("1"), "A1, Build failed");
BuildItemGroup include = project.GetEvaluatedItemsByName ("NewItem");
Assert.AreEqual (3, include.Count, "A2");
string [,] additional_metadata = new string [0, 0];
CheckBuildItem (include [0], "NewItem", additional_metadata, "1", "A");
CheckBuildItem (include [1], "NewItem", additional_metadata, "2", "B");
CheckBuildItem (include [2], "NewItem", additional_metadata, "5", "C");
}
[Test]
public void TestVariableExpansion ()
{
Engine engine;
Project project;
string documentString = @"
<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
<PropertyGroup>
<P1>FooP1</P1>
<P2>FooP2</P2>
<C>@(IG)</C>
<P3>@(Nine->'%(Identity)')</P3>
</PropertyGroup>
<ItemGroup>
<Nine Include=""Nine""/>
<Eight Include=""Eight""/>
<Seven Include=""@(Eight)""/>
<Six Include=""@(Seven);$(P3)""/>
<Third Include=""Abc""/>
<Fourth Include=""$(P2)""/>
<Second Include=""@(Third);$(P1);@(Fourth);@(Six)""/>
<IG Include=""@(Second)""/>
</ItemGroup>
<Target Name='1'>
<CreateItem Include='$(C)' >
<Output
TaskParameter='Include'
ItemName='Items'
/>
</CreateItem>
<Message Text=""C: $(C)""/>
<Message Text=""items: @(items)""/>
</Target>
</Project>
";
engine = new Engine (Consts.BinPath);
TestMessageLogger testLogger = new TestMessageLogger ();
engine.RegisterLogger (testLogger);
project = engine.CreateNewProject ();
project.LoadXml (documentString);
if (!project.Build ("1")) {
testLogger.DumpMessages ();
Assert.Fail ("Build failed");
}
BuildItemGroup include = project.GetEvaluatedItemsByName ("Items");
Assert.AreEqual (5, include.Count, "A2");
Assert.AreEqual ("Abc", include [0].FinalItemSpec, "A#3");
Assert.AreEqual ("FooP1", include[1].FinalItemSpec, "A#4");
Assert.AreEqual ("FooP2", include[2].FinalItemSpec, "A#5");
Assert.AreEqual ("Eight", include[3].FinalItemSpec, "A#6");
Assert.AreEqual ("Nine", include[4].FinalItemSpec, "A#7");
testLogger.CheckLoggedMessageHead ("C: Abc;FooP1;FooP2;Eight;Nine", "A#9");
testLogger.CheckLoggedMessageHead ("items: Abc;FooP1;FooP2;Eight;Nine", "A#10");
}
#if NET_3_5 || NET_4_0
[Test]
public void TestItemsWithWildcards () {
Engine engine = new Engine (Consts.BinPath);
Project proj = engine.CreateNewProject ();
TestMessageLogger logger = new TestMessageLogger ();
engine.RegisterLogger (logger);
// Setup
string projectdir = Path.Combine ("Test", "resources");
string basedir = "dir";
string aaa = PathCombine (basedir, "a", "aa", "aaa");
string bb = PathCombine (basedir, "b", "bb");
string c = PathCombine (basedir, "c");
string[] dirs = { aaa, bb, c };
string[] files = {
PathCombine (aaa, "foo.dll"),
PathCombine (bb, "bar.dll"),
PathCombine (bb, "sample.txt"),
Path.Combine (basedir, "xyz.dll")
};
string documentString = @"
<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"" " + Consts.ToolsVersionString + @">
<Target Name='Main'>
<CreateItem Include='dir\**'>
<Output TaskParameter='Include' ItemName='CI1' />
</CreateItem>
<Message Text=""CI1: @(CI1)""/>
</Target>
</Project>";
try {
CreateDirectoriesAndFiles (projectdir, dirs, files);
File.WriteAllText (Path.Combine (projectdir, "wild1.proj"), documentString);
proj.Load (Path.Combine (projectdir, "wild1.proj"));
if (!proj.Build ("Main"))
Assert.Fail ("Build failed");
string full_base_dir = Path.GetFullPath (basedir);
logger.CheckLoggedAny ("CI1: " + String.Join (";", files), MessageImportance.Normal, "A1");
} catch (AssertionException) {
logger.DumpMessages ();
throw;
} finally {
Directory.Delete (Path.Combine (projectdir, basedir), true);
}
}
[Test]
public void TestItemsWithWildcards2 () {
Engine engine = new Engine (Consts.BinPath);
Project proj = engine.CreateNewProject ();
TestMessageLogger logger = new TestMessageLogger ();
engine.RegisterLogger (logger);
// Setup
string basedir = PathCombine ("Test", "resources", "dir");
string aaa = PathCombine ("a", "aa", "aaa");
string bb = Path.Combine ("b", "bb");
string[] dirs = { aaa, bb, "c" };
string[] files = {
PathCombine (aaa, "foo.dll"),
PathCombine (bb, "bar.dll"),
PathCombine (bb, "sample.txt"),
PathCombine ("xyz.dll")
};
string documentString = @"
<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"" " + Consts.ToolsVersionString + @">
<PropertyGroup>
<WC>dir\**\*.dll</WC>
<ExWC>*\x*.dll</ExWC>
</PropertyGroup>
<Target Name='Main'>
<Copy SourceFiles='dir\xyz.dll' DestinationFiles='dir\abc.dll'/>
<CreateItem Include='dir\**\*.dll' Exclude='*\x*.dll'>
<Output TaskParameter='Include' ItemName='CI1' />
</CreateItem>
<Message Text=""CI1: %(CI1.FullPath)""/>
<CreateItem Include='$(WC)' Exclude='$(ExWC)'>
<Output TaskParameter='Include' ItemName='CI2' />
</CreateItem>
<Message Text=""CI2: %(CI2.FullPath)""/>
</Target>
</Project>";
try {
CreateDirectoriesAndFiles (basedir, dirs, files);
string projectdir = Path.Combine ("Test", "resources");
File.WriteAllText (Path.Combine (projectdir, "wild1.proj"), documentString);
proj.Load (Path.Combine (projectdir, "wild1.proj"));
if (!proj.Build ("Main"))
Assert.Fail ("Build failed");
string full_base_dir = Path.GetFullPath (basedir);
foreach (string prefix in new string[] { "CI1: ", "CI2: " }) {
logger.CheckLoggedAny (prefix + PathCombine (full_base_dir, aaa, "foo.dll"),
MessageImportance.Normal, "A1");
logger.CheckLoggedAny (prefix + PathCombine (full_base_dir, bb, "bar.dll"), MessageImportance.Normal, "A2");
logger.CheckLoggedAny (prefix + PathCombine (full_base_dir, "abc.dll"),
MessageImportance.Normal, "A3");
}
} catch (AssertionException) {
logger.DumpMessages ();
throw;
} finally {
Directory.Delete (basedir, true);
}
}
#endif
void CreateDirectoriesAndFiles (string basedir, string[] dirs, string[] files) {
foreach (string dir in dirs)
Directory.CreateDirectory (Path.Combine (basedir, dir));
foreach (string file in files)
File.WriteAllText (Path.Combine (basedir, file), String.Empty);
}
string PathCombine (string path1, params string[] parts) {
if (parts == null || parts.Length == 0)
return path1;
string final_path = path1;
foreach (string part in parts)
final_path = Path.Combine (final_path, part);
return final_path;
}
public static void CheckBuildItem (BuildItem item, string name, string [,] metadata, string finalItemSpec, string prefix)
{
Assert.AreEqual (name, item.Name, prefix + "#1");
for (int i = 0; i < metadata.GetLength (0); i ++) {
string key = metadata [i, 0];
string val = metadata [i, 1];
Assert.IsTrue (item.HasMetadata (key), String.Format ("{0}#2: Expected metadata '{1}' not found", prefix, key));
Assert.AreEqual (val, item.GetMetadata (key), String.Format ("{0}#3: Value for metadata {1}", prefix, key));
Assert.AreEqual (val, item.GetEvaluatedMetadata (key), String.Format ("{0}#4: Value for evaluated metadata {1}", prefix, key));
}
Assert.AreEqual (finalItemSpec, item.FinalItemSpec, prefix + "#5");
}
}
}

View File

@@ -0,0 +1,171 @@
//
// CreatePropertyTest.cs
//
// Author:
// Marek Sieradzki (marek.sieradzki@gmail.com)
//
// (C) 2006 Marek Sieradzki
//
// 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;
using System.IO;
using Microsoft.Build.BuildEngine;
using Microsoft.Build.Framework;
using Microsoft.Build.Tasks;
using Microsoft.Build.Utilities;
using NUnit.Framework;
namespace MonoTests.Microsoft.Build.Tasks {
[TestFixture]
public class CreatePropertyTest {
[Test]
public void TestAssignment ()
{
CreateProperty cp = new CreateProperty ();
cp.Value = new string [1] { "1" };
Assert.AreEqual ("1", cp.Value [0], "A1");
Assert.AreEqual ("1", cp.ValueSetByTask [0], "A2");
}
[Test]
public void TestExecution1 ()
{
Engine engine;
Project project;
string documentString = @"
<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
<PropertyGroup>
<A>1</A>
<B>2</B>
</PropertyGroup>
<Target Name='1'>
<CreateProperty Value='$(A)$(B)' >
<Output
TaskParameter='Value'
PropertyName='Value'
/>
<Output
TaskParameter='ValueSetByTask'
PropertyName='ValueSetByTask'
/>
</CreateProperty>
</Target>
</Project>
";
engine = new Engine (Consts.BinPath);
project = engine.CreateNewProject ();
project.LoadXml (documentString);
Assert.IsTrue (project.Build ("1"), "A1");
Assert.AreEqual ("12", project.EvaluatedProperties ["Value"].Value, "A2");
Assert.AreEqual ("12", project.EvaluatedProperties ["Value"].FinalValue, "A3");
Assert.AreEqual ("12", project.EvaluatedProperties ["ValueSetByTask"].Value, "A4");
Assert.AreEqual ("12", project.EvaluatedProperties ["ValueSetByTask"].FinalValue, "A5");
}
[Test]
public void TestExecution2 () {
Engine engine;
Project project;
string documentString = @"
<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
<ItemGroup>
<Second Include=""Abc""/>
<IG Include=""@(Second)""/></ItemGroup>
<PropertyGroup>
<C>@(IG)</C>
</PropertyGroup>
<Target Name='1'>
<CreateProperty Value='$(C)' >
<Output
TaskParameter='Value'
PropertyName='Value'
/>
<Output
TaskParameter='ValueSetByTask'
PropertyName='ValueSetByTask'
/>
</CreateProperty>
</Target>
</Project>
";
engine = new Engine (Consts.BinPath);
project = engine.CreateNewProject ();
project.LoadXml (documentString);
Assert.IsTrue (project.Build ("1"), "A1");
Assert.AreEqual ("Abc", project.EvaluatedProperties["Value"].Value, "A2");
Assert.AreEqual ("Abc", project.EvaluatedProperties["Value"].FinalValue, "A3");
Assert.AreEqual ("Abc", project.EvaluatedProperties["ValueSetByTask"].Value, "A4");
Assert.AreEqual ("Abc", project.EvaluatedProperties["ValueSetByTask"].FinalValue, "A5");
Assert.AreEqual ("@(IG)", project.EvaluatedProperties["C"].FinalValue, "A6");
}
[Test]
public void TestEmptyPropertyValue ()
{
Engine engine;
Project project;
string documentString = @"
<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
<PropertyGroup>
<A>1</A>
</PropertyGroup>
<Target Name='1'>
<Message Text='Before: $(A)'/>
<CreateProperty Value=''>
<Output
TaskParameter='Value'
PropertyName='A'
/>
</CreateProperty>
<Message Text='After: $(A)'/>
</Target>
</Project>
";
engine = new Engine (Consts.BinPath);
TestMessageLogger testLogger = new TestMessageLogger ();
engine.RegisterLogger (testLogger);
project = engine.CreateNewProject ();
project.LoadXml (documentString);
if (!project.Build ("1")) {
testLogger.DumpMessages ();
Assert.Fail ("Build failed");
}
testLogger.CheckLoggedMessageHead ("Before: 1", "A1");
testLogger.CheckLoggedMessageHead ("After: ", "A2");
Assert.AreEqual (0, testLogger.NormalMessageCount, "Unexpected messages found");
}
}
}

View File

@@ -0,0 +1,298 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using NUnit.Framework;
using Microsoft.Build.BuildEngine;
namespace MonoTests.Microsoft.Build.Tasks
{
[TestFixture]
public class CreateVisualBasicManifestResourceNameTest
{
string [,] resx_no_culture_files, resx_with_culture_files;
string [,] non_resx_no_culture_files, non_resx_with_culture_files;
public CreateVisualBasicManifestResourceNameTest ()
{
string junk_file = Path.Combine ("Test", Path.Combine ("resources", "junk.txt"));
string sample_vb_path = Path.Combine ("Test", Path.Combine ("resources", "Sample.vb"));
string curdir = Path.GetDirectoryName (Environment.CurrentDirectory);
/* {Include, LogicalName, DependentUpon, TargetPath} */
resx_no_culture_files = new string [,] {
// With dependent file
{ "foo with space.resx", null, sample_vb_path, null },
{ "foo with space.resx", "RandomName", sample_vb_path, null },
{ "foo with space.resx", "RandomName", sample_vb_path, "bar with space.resx" },
// can't find a C# class in the .vb file
{ "foo with space.resx", "RandomName", junk_file, "bar with space.resx" },
{ "Test/resources/foo with space.resx", null, "Sample.vb", null },
{ "Test/resources/foo with space.resx", "RandomName", "Sample.vb", null },
{ "Test/resources/foo with space.resx", "RandomName", "Sample.vb", "bar with space.resx"},
// W/o dependent file
{ "foo with space.resx", null, null, null },
{ "foo with space.resx", "RandomName", null, null },
{ "Test/resources folder/foo with space.resx", null, null, null },
{ "Test/resources folder/foo with space.resx", "RandomName", null, null },
};
resx_with_culture_files = new string [,] {
// With dependent file
{ "foo with space.de.resx", null, sample_vb_path, null },
{ "foo with space.de.resx", "RandomName", sample_vb_path, null },
{ "foo with space.de.resx", "RandomName", sample_vb_path, "bar with space.fr.resx" },
// can't find a C# class in the .vb file
{ "foo with space.de.resx", "RandomName", junk_file, "bar with space.fr.resx" },
{ "Test/resources/foo with space.de.resx", null, "Sample.vb", null },
{ "Test/resources/foo with space.de.resx", "RandomName", "Sample.vb", null},
// W/o dependent file
{ "foo with space.de.resx", null, null, null },
{ "foo with space.de.resx", "RandomName", null, null },
{ "Test/resources folder/foo with space.de.resx", null, null, null },
{ "Test/resources folder/foo with space.de.resx", "RandomName", null, null }
};
non_resx_no_culture_files = new string [,] {
{ "foo with space.txt", null, null },
{ "foo with space.txt", "RandomName", null },
{ "Test/resources folder/foo with space.txt", null, null },
{ "Test/resources folder/foo with space.txt", "RandomName", null }
};
non_resx_with_culture_files = new string [,] {
{ "foo with space.de.txt", null, null },
{ "foo with space.de.txt", "RandomName", null },
{ "Test/resources folder/foo with space.de.txt", null, null },
{ "Test/resources folder/foo with space.de.txt", "RandomName", null }
};
}
[Test]
public void TestNoRootNamespaceNoCulture ()
{
CheckResourceNames (resx_no_culture_files, new string [] {
// w/ dependent file
"Mono.Tests.Sample", "Mono.Tests.Sample",
"Mono.Tests.Sample", "bar with space",
"Mono.Tests.Sample", "Mono.Tests.Sample",
// W/o dependent file
"Mono.Tests.Sample", "foo with space" ,
"foo with space", "foo with space",
"foo with space",
}, null);
}
[Test]
public void TestWithRootNamespaceNoCulture ()
{
//FIXME: How does LogicalName affect things??
CheckResourceNames (resx_no_culture_files, new string [] {
// With dependent file
"RN1.RN2.Mono.Tests.Sample", "RN1.RN2.Mono.Tests.Sample",
"RN1.RN2.Mono.Tests.Sample", "RN1.RN2.bar with space",
"RN1.RN2.Mono.Tests.Sample", "RN1.RN2.Mono.Tests.Sample",
// W/o dependent file
"RN1.RN2.Mono.Tests.Sample", "RN1.RN2.foo with space",
"RN1.RN2.foo with space", "RN1.RN2.foo with space",
"RN1.RN2.foo with space"},
"RN1.RN2");
}
[Test]
public void TestNoRootNamespaceWithCulture ()
{
CheckResourceNames (resx_with_culture_files, new string [] {
// With dependent file
"Mono.Tests.Sample.de", "Mono.Tests.Sample.de",
"Mono.Tests.Sample.fr", "bar with space.fr",
"Mono.Tests.Sample.de", "Mono.Tests.Sample.de",
// W/o dependent file
"foo with space.de", "foo with space.de",
"foo with space.de", "foo with space.de" }, null);
}
[Test]
public void TestWithRootNamespaceWithCulture ()
{
CheckResourceNames (resx_with_culture_files, new string [] {
// With dependent file
"RN1.RN2.Mono.Tests.Sample.de", "RN1.RN2.Mono.Tests.Sample.de",
"RN1.RN2.Mono.Tests.Sample.fr", "RN1.RN2.bar with space.fr",
"RN1.RN2.Mono.Tests.Sample.de", "RN1.RN2.Mono.Tests.Sample.de",
// W/o dependent file
"RN1.RN2.foo with space.de", "RN1.RN2.foo with space.de",
"RN1.RN2.foo with space.de", "RN1.RN2.foo with space.de"},
"RN1.RN2");
}
[Test]
public void TestNonResxNoRootNamespaceWithCulture ()
{
CheckResourceNames (non_resx_with_culture_files, new string [] {
Path.Combine ("de", "foo with space.txt"), Path.Combine ("de", "foo with space.txt"),
Path.Combine ("de", "foo with space.txt"), Path.Combine ("de", "foo with space.txt")}, null);
}
[Test]
public void TestNonResxWithRootNamespaceWithCulture ()
{
CheckResourceNames (non_resx_with_culture_files, new string [] {
Path.Combine ("de", "RN1.RN2.foo with space.txt"), Path.Combine ("de", "RN1.RN2.foo with space.txt"),
Path.Combine ("de", "RN1.RN2.foo with space.txt"), Path.Combine ("de", "RN1.RN2.foo with space.txt")},
"RN1.RN2");
}
[Test]
public void TestNonResxNoRootNamespaceNoCulture ()
{
CheckResourceNames (non_resx_no_culture_files, new string [] {
"foo with space.txt", "foo with space.txt",
"foo with space.txt", "foo with space.txt"}, null);
}
[Test]
public void TestNonResxWithRootNamespaceNoCulture ()
{
CheckResourceNames (non_resx_no_culture_files, new string [] {
// With dependent file
"RN1.RN2.foo with space.txt", "RN1.RN2.foo with space.txt",
"RN1.RN2.foo with space.txt", "RN1.RN2.foo with space.txt"},
"RN1.RN2");
}
[Test]
public void TestExternalResourcesNoRootNamespaceWithTargetPath ()
{
CheckResourceNames (new string[,] {
{"../folder/foo.txt", null, null, "abc.txt"},
{"../folder/foo.de.txt", null, null, "xyz.txt"}},
new string[] { "abc.txt", "xyz.txt" }, null);
}
[Test]
public void TestExternalResourcesWithRootNamespaceWithTargetPath ()
{
CheckResourceNames (new string[,] {
{"../folder/foo.txt", null, null, "abc.txt"},
{"../folder/foo.de.txt", null, null, "xyz.txt"}},
new string[] { "RN.abc.txt", "RN.xyz.txt" }, "RN");
}
[Test]
public void TestExternalResourcesNoRootNamespaceNoTargetPath ()
{
CheckResourceNames (new string[,] {
{"../folder/foo.txt", null, null},
{"../folder/foo.de.txt", null, null}},
new string[] { "foo.txt", Path.Combine ("de", "foo.txt") }, null);
}
[Test]
public void TestExternalResourcesWithRootNamespaceNoTargetPath ()
{
CheckResourceNames (new string[,] {
{"../folder/foo.txt", null, null},
{"../folder/foo.de.txt", null, null}},
new string[] { "RN.foo.txt", Path.Combine ("de", "RN.foo.txt") }, "RN");
}
[Test]
public void TestInvalidCulture ()
{
string [,] files = new string [,] {
{ "Foo.invalid.txt", null, null },
{ "Foo.invalid.resx", null, null }
};
CheckResourceNames (files, new string [] {"RN1.RN2.Foo.invalid.txt", "RN1.RN2.Foo.invalid"},
"RN1.RN2");
}
void CheckResourceNames (string [,] files, string [] names, string rootNamespace)
{
Assert.AreEqual (files.GetUpperBound (0) + 1, names.Length, "Number of files and names must match");
string projectText = CreateProject (files, rootNamespace);
Engine engine = new Engine (Consts.BinPath);
Project project = engine.CreateNewProject ();
TestMessageLogger logger = new TestMessageLogger ();
engine.RegisterLogger (logger);
project.LoadXml (projectText);
if (!project.Build ("1")) {
Console.WriteLine (projectText);
logger.DumpMessages ();
Assert.Fail ("Build failed");
}
bool has_targetpaths = files.GetUpperBound (1) == 3;
BuildItemGroup group = project.GetEvaluatedItemsByName ("ResourceNames");
Assert.AreEqual (names.Length, group.Count, "A2");
for (int i = 0; i <= files.GetUpperBound (0); i++) {
Assert.AreEqual (names [i], group [i].FinalItemSpec, "A3 #" + (i + 1));
Assert.AreEqual (files [i, 1] != null, group [i].HasMetadata ("LogicalName"), "A4 #" + (i + 1));
if (files [i, 1] != null)
Assert.AreEqual (files [i, 1], group [i].GetMetadata ("LogicalName"), "A5 #" + (i + 1));
Assert.AreEqual (files [i, 2] != null, group [i].HasMetadata ("DependentUpon"), "A6 #" + (i + 1));
if (files [i, 2] != null)
Assert.AreEqual (files [i, 2], group [i].GetMetadata ("DependentUpon"), "A7 #" + (i + 1));
if (has_targetpaths && files [i, 3] != null)
Assert.AreEqual (files [i, 3], group [i].GetMetadata ("TargetPath"), "A8 #" + (i + 1));
}
}
string CreateProject (string [,] files, string rootNamespace)
{
StringBuilder sb = new StringBuilder ();
sb.Append ("<Project xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n");
bool has_targetpaths = files.GetUpperBound (1) == 3;
sb.Append ("\t<ItemGroup>\n");
for (int i = 0; i <= files.GetUpperBound (0); i ++) {
sb.AppendFormat ("\t\t<ResourceFiles Include = \"{0}\">\n", files [i, 0]);
if (has_targetpaths && files [i, 3] != null)
sb.AppendFormat ("\t\t\t<TargetPath>{0}</TargetPath>\n", files [i, 3]);
if (files [i, 1] != null)
sb.AppendFormat ("\t\t\t<LogicalName>{0}</LogicalName>\n", files [i, 1]);
if (files [i, 2] != null)
sb.AppendFormat ("\t\t\t<DependentUpon>{0}</DependentUpon>\n", files [i, 2]);
sb.AppendFormat ("\t\t</ResourceFiles>\n");
}
sb.Append ("\t</ItemGroup>\n");
sb.Append ("\t<Target Name=\"1\">\n");
sb.Append ("\t\t<CreateVisualBasicManifestResourceName ResourceFiles=\"@(ResourceFiles)\" ");
if (rootNamespace != null)
sb.AppendFormat (" RootNamespace = \"{0}\"", rootNamespace);
sb.Append (">\n \t\t\t<Output TaskParameter=\"ManifestResourceNames\" ItemName=\"ResourceNames\" />\n");
sb.Append ("\t\t</CreateVisualBasicManifestResourceName>\n\t</Target>\n");
sb.Append ("\t" + GetUsingTask ("CreateVisualBasicManifestResourceName"));
sb.Append ("</Project>");
return sb.ToString ();
}
string GetUsingTask (string taskName)
{
return "<UsingTask TaskName='Microsoft.Build.Tasks." + taskName + "' AssemblyFile='" + Consts.GetTasksAsmPath () + "' />";
}
}
}

View File

@@ -0,0 +1,466 @@
//
// CscTest.cs
//
// Author:
// Marek Sieradzki (marek.sieradzki@gmail.com)
//
// (C) 2006 Marek Sieradzki
//
// 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.Reflection;
using System.Collections;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using Microsoft.Build.Tasks;
using NUnit.Framework;
namespace MonoTests.Microsoft.Build.Tasks {
class CscExtended : Csc {
public CscExtended ()
: base ()
{
}
public void ARFC (CommandLineBuilderExtension commandLine)
{
base.AddResponseFileCommands (commandLine);
#if !NET_4_0
string s = commandLine.ToString ();
if (s.Length == 6)
Assert.AreEqual ("/sdk:2", s);
else
Assert.AreEqual ("/sdk:2 ", s.Substring (0, 7));
BindingFlags flags = BindingFlags.Instance | BindingFlags.NonPublic;
PropertyInfo pi = typeof (CommandLineBuilderExtension).GetProperty ("CommandLine", flags);
System.Text.StringBuilder sb = (System.Text.StringBuilder) pi.GetValue (commandLine, null);
sb.Length = 0;
if (s.Length > 6)
sb.Append (s.Substring (7));
#endif
}
public void ACLC (CommandLineBuilderExtension commandLine)
{
base.AddCommandLineCommands (commandLine);
}
}
[TestFixture]
public class CscTest {
[Test]
public void TestAssignment ()
{
Csc csc = new Csc ();
csc.AllowUnsafeBlocks = true;
csc.BaseAddress = "1";
csc.CheckForOverflowUnderflow = true;
csc.DisabledWarnings = "2";
csc.DocumentationFile = "3";
csc.ErrorReport = "4";
csc.GenerateFullPaths = true;
csc.LangVersion = "5";
csc.ModuleAssemblyName = "6";
csc.NoStandardLib = true;
csc.PdbFile = "7";
csc.Platform = "8";
csc.UseHostCompilerIfAvailable = true;
csc.WarningLevel = 9;
csc.WarningsAsErrors = "10";
csc.WarningsNotAsErrors = "11";
Assert.AreEqual (true, csc.AllowUnsafeBlocks, "A1");
Assert.AreEqual ("1", csc.BaseAddress, "A2");
Assert.AreEqual (true, csc.CheckForOverflowUnderflow, "A3");
Assert.AreEqual ("2", csc.DisabledWarnings, "A4");
Assert.AreEqual ("3", csc.DocumentationFile, "A5");
Assert.AreEqual ("4", csc.ErrorReport, "A6");
Assert.AreEqual (true, csc.GenerateFullPaths, "A7");
Assert.AreEqual ("5", csc.LangVersion, "A8");
Assert.AreEqual ("6", csc.ModuleAssemblyName, "A9");
Assert.AreEqual ("7", csc.PdbFile, "A10");
Assert.AreEqual ("8", csc.Platform, "A11");
Assert.AreEqual (true, csc.UseHostCompilerIfAvailable, "A12");
Assert.AreEqual (9, csc.WarningLevel, "A13");
Assert.AreEqual ("10", csc.WarningsAsErrors, "A14");
Assert.AreEqual ("11", csc.WarningsNotAsErrors, "A15");
}
[Test]
public void TestDefaultValues ()
{
Csc csc = new Csc ();
Assert.IsFalse (csc.AllowUnsafeBlocks, "A1");
Assert.IsNull (csc.BaseAddress, "A2");
Assert.IsFalse (csc.CheckForOverflowUnderflow, "A3");
Assert.IsNull (csc.DisabledWarnings, "A4");
Assert.IsNull (csc.DocumentationFile, "A5");
Assert.IsNull (csc.ErrorReport, "A6");
Assert.IsFalse (csc.GenerateFullPaths, "A7");
Assert.IsNull (csc.LangVersion, "A8");
Assert.IsNull (csc.ModuleAssemblyName, "A9");
Assert.IsNull (csc.PdbFile, "A10");
Assert.IsNull (csc.Platform, "A11");
Assert.IsFalse (csc.UseHostCompilerIfAvailable, "A12");
Assert.AreEqual (4, csc.WarningLevel, "A13");
Assert.IsNull (csc.WarningsAsErrors, "A14");
Assert.IsNull (csc.WarningsNotAsErrors, "A15");
}
#region CscSpecificVariables
[Test]
public void TestAllowUnsafeBlocks1 ()
{
CscExtended csc = new CscExtended ();
CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
csc.AllowUnsafeBlocks = true;
csc.ARFC (clbe);
Assert.AreEqual ("/unsafe+", clbe.ToString (), "A1");
}
[Test]
public void TestAllowUnsafeBlocks2 ()
{
CscExtended csc = new CscExtended ();
CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
csc.AllowUnsafeBlocks = false;
csc.ARFC (clbe);
Assert.AreEqual ("/unsafe-", clbe.ToString (), "A1");
}
[Test]
[Category ("NotWorking")]
public void TestBaseAddress ()
{
CscExtended csc = new CscExtended ();
CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
csc.BaseAddress = "A";
csc.ARFC (clbe);
Assert.AreEqual ("/baseaddress:A", clbe.ToString (), "A1");
}
[Test]
public void TestCheckForOverflowUnderflow1 ()
{
CscExtended csc = new CscExtended ();
CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
csc.CheckForOverflowUnderflow = true;
csc.ARFC (clbe);
Assert.AreEqual ("/checked+", clbe.ToString (), "A1");
}
[Test]
public void TestCheckForOverflowUnderflow2 ()
{
CscExtended csc = new CscExtended ();
CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
csc.CheckForOverflowUnderflow = false;
csc.ARFC (clbe);
Assert.AreEqual ("/checked-", clbe.ToString (), "A1");
}
[Test]
public void TestDisabledWarnings ()
{
CscExtended csc = new CscExtended ();
CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
csc.DisabledWarnings = "A";
csc.ARFC (clbe);
Assert.AreEqual ("/nowarn:A", clbe.ToString (), "A1");
}
[Test]
public void TestDisabledWarningsComma ()
{
CscExtended csc = new CscExtended ();
CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
csc.DisabledWarnings = "A, B";
csc.ARFC (clbe);
Assert.AreEqual ("/nowarn:A;B", clbe.ToString (), "A1");
}
[Test]
public void TestDocumentationFile ()
{
CscExtended csc = new CscExtended ();
CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
csc.DocumentationFile = "A";
csc.ARFC (clbe);
Assert.AreEqual ("/doc:A", clbe.ToString (), "A1");
}
[Test]
[Category ("NotWorking")]
public void TestErrorReport ()
{
CscExtended csc = new CscExtended ();
CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
csc.ErrorReport = "A";
csc.ARFC (clbe);
Assert.AreEqual ("/errorreport:A", clbe.ToString (), "A1");
}
[Test]
public void TestGenerateFullPaths1 ()
{
CscExtended csc = new CscExtended ();
CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
csc.GenerateFullPaths = true;
csc.ARFC (clbe);
Assert.AreEqual ("/fullpaths", clbe.ToString (), "A1");
}
[Test]
public void TestGenerateFullPaths2 ()
{
CscExtended csc = new CscExtended ();
CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
csc.GenerateFullPaths = false;
csc.ARFC (clbe);
Assert.AreEqual ("", clbe.ToString (), "A1");
}
[Test]
public void TestLangVersion ()
{
CscExtended csc = new CscExtended ();
CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
csc.LangVersion = "A'B";
csc.ARFC (clbe);
Assert.AreEqual ("/langversion:\"A'B\"", clbe.ToString (), "A1");
}
[Test]
[Category ("NotWorking")]
public void TestModuleAssemblyName ()
{
CscExtended csc = new CscExtended ();
CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
csc.ModuleAssemblyName = "A'B";
csc.ARFC (clbe);
Assert.AreEqual ("/moduleassemblyname:\"A'B\"", clbe.ToString (), "A1");
}
[Test]
[Category ("NotWorking")]
public void TestPdbFile ()
{
CscExtended csc = new CscExtended ();
CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
csc.PdbFile = "A";
csc.ARFC (clbe);
Assert.AreEqual ("/pdb:A", clbe.ToString (), "A1");
}
[Test]
[Category ("NotWorking")]
public void TestPlatform ()
{
CscExtended csc = new CscExtended ();
CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
csc.Platform = "A";
csc.ARFC (clbe);
Assert.AreEqual ("/platform:A", clbe.ToString (), "A1");
}
[Test]
public void TestWarning ()
{
CscExtended csc = new CscExtended ();
CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
csc.WarningLevel = 4;
csc.ARFC (clbe);
Assert.AreEqual ("/warn:4", clbe.ToString (), "A1");
}
[Test]
public void TestWarningAsErrors ()
{
CscExtended csc = new CscExtended ();
CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
csc.WarningsAsErrors = "A'B";
csc.ARFC (clbe);
Assert.AreEqual ("/warnaserror+:\"A'B\"", clbe.ToString (), "A1");
}
[Test]
public void TestWarningNotAsErrors ()
{
CscExtended csc = new CscExtended ();
CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
csc.WarningsNotAsErrors = "A'B";
csc.ARFC (clbe);
Assert.AreEqual ("/warnaserror-:\"A'B\"", clbe.ToString (), "A1");
}
#endregion
[Test]
public void TestAdditionalLibPaths ()
{
CscExtended csc = new CscExtended ();
CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
csc.AdditionalLibPaths = new string [2] { "A'Foo", "B" };
csc.ARFC (c1);
csc.ACLC (c2);
Assert.AreEqual ("/lib:\"A'Foo\",B", c1.ToString (), "A1");
Assert.AreEqual (String.Empty, c2.ToString (), "A2");
}
// Behavior for this intentionally differs from .net .
// msbuild doesn't quote the define args, but we do
// that to make it easier to copy/paste and execute
// compiler command lines, helps in debugging.
[Category ("NotDotNet")]
[Test]
public void TestDefineConstants ()
{
CscExtended csc = new CscExtended ();
CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
csc.DefineConstants = "A;B;;CD;;;Foo Bar";
csc.ARFC (c1);
csc.ACLC (c2);
Assert.AreEqual ("/define:\"A;B;CD;Foo;Bar\"", c1.ToString (), "A1");
Assert.AreEqual (String.Empty, c2.ToString (), "A2");
}
[Test]
public void TestDefineConstants2 ()
{
CscExtended csc = new CscExtended ();
CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
csc.DefineConstants = ";;;";
csc.ARFC (c1);
csc.ACLC (c2);
Assert.AreEqual (String.Empty, c1.ToString (), "A1");
Assert.AreEqual (String.Empty, c2.ToString (), "A2");
}
[Test]
public void TestMainEntryPoint ()
{
CscExtended csc = new CscExtended ();
CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
csc.MainEntryPoint = "A;B";
csc.ARFC (c1);
csc.ACLC (c2);
Assert.AreEqual ("/main:\"A;B\"", c1.ToString (), "A1");
Assert.AreEqual (String.Empty, c2.ToString (), "A2");
}
[Test]
public void TestReferences ()
{
CscExtended csc = new CscExtended ();
CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
csc.References = new ITaskItem [2] { new TaskItem ("A;C"), new TaskItem ("B") };
csc.ARFC (c1);
csc.ACLC (c2);
Assert.AreEqual ("/reference:\"A;C\" /reference:B", c1.ToString (), "A1");
Assert.AreEqual (String.Empty, c2.ToString (), "A2");
}
[Test]
public void TestResponseFiles ()
{
CscExtended csc = new CscExtended ();
CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
csc.ResponseFiles = new ITaskItem [2] { new TaskItem ("A\'Foo"), new TaskItem ("B") };
csc.ARFC (c1);
csc.ACLC (c2);
Assert.AreEqual ("@\"A'Foo\" @B", c1.ToString (), "A1");
Assert.AreEqual (String.Empty, c2.ToString (), "A2");
}
[Test]
public void TestWin32Resource ()
{
CscExtended csc = new CscExtended ();
CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
csc.Win32Resource = "A;B";
csc.ARFC (c1);
csc.ACLC (c2);
Assert.AreEqual ("/win32res:\"A;B\"", c1.ToString (), "A1");
Assert.AreEqual (String.Empty, c2.ToString (), "A2");
}
}
}

View File

@@ -0,0 +1,262 @@
//
// DeleteTest.cs
//
// Author:
// Jonathan Chambers (joncham@gmail.com)
//
// (C) 2008 Jonathan Chambers
//
// 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;
using System.IO;
using Microsoft.Build.BuildEngine;
using Microsoft.Build.Framework;
using Microsoft.Build.Tasks;
using Microsoft.Build.Utilities;
using NUnit.Framework;
namespace MonoTests.Microsoft.Build.Tasks {
[TestFixture]
public class DeleteTest {
string path;
[SetUp]
public void CreateDir ()
{
path = Path.Combine (Path.Combine ("Test", "resources"), "Delete");
Directory.CreateDirectory (path);
}
[TearDown]
public void RemoveDirectories ()
{
Directory.Delete (path, true);
}
[Test]
public void TestDelete1 ()
{
Engine engine;
Project project;
string file_path = Path.Combine(path, "delete.txt");
using (File.CreateText (file_path)) { }
string documentString = @"
<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
<Target Name='1'>
<Delete Files='" + file_path + @"'/>
</Target>
</Project>
";
engine = new Engine (Consts.BinPath);
project = engine.CreateNewProject ();
project.LoadXml (documentString);
Assert.IsTrue (project.Build ("1"), "A1");
Assert.IsTrue (!File.Exists (file_path), "A2");
}
[Test]
public void TestDelete2 ()
{
Engine engine;
Project project;
string file_path = Path.Combine (path, "delete.txt");
string file_path2 = Path.Combine (path, "delete2.txt");
using (File.CreateText (file_path)) { }
using (File.CreateText (file_path2)) { }
string documentString = @"
<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
<Target Name='1'>
<Delete Files='" + file_path + ";" + file_path2 + @"'/>
</Target>
</Project>
";
engine = new Engine (Consts.BinPath);
project = engine.CreateNewProject ();
project.LoadXml (documentString);
Assert.IsTrue (project.Build ("1"), "A1");
Assert.IsTrue (!File.Exists (file_path), "A2");
Assert.IsTrue (!File.Exists (file_path), "A3");
}
[Test]
public void TestDelete3 ()
{
Engine engine;
Project project;
string file_path = Path.Combine (path, "delete.txt");
using (File.CreateText (file_path)) { }
string documentString = @"
<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
<PropertyGroup>
<FileToDelete>" + file_path + @"</FileToDelete>
</PropertyGroup>
<Target Name='1'>
<Delete Files='$(FileToDelete)'/>
</Target>
</Project>
";
engine = new Engine (Consts.BinPath);
project = engine.CreateNewProject ();
project.LoadXml (documentString);
Assert.IsTrue (project.Build ("1"), "A1");
Assert.IsTrue (!File.Exists (file_path), "A2");
}
[Test]
public void TestDelete4 ()
{
Engine engine;
Project project;
string file_path = Path.Combine (path, "delete.txt");
string file_path2 = Path.Combine (path, "delete2.txt");
using (File.CreateText (file_path)) { }
using (File.CreateText (file_path2)) { }
string documentString = @"
<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
<PropertyGroup>
<FileToDelete>" + file_path + @"</FileToDelete>
<FileToDelete2>" + file_path2 + @"</FileToDelete2>
</PropertyGroup>
<Target Name='1'>
<Delete Files='$(FileToDelete);$(FileToDelete2)'/>
</Target>
</Project>
";
engine = new Engine (Consts.BinPath);
project = engine.CreateNewProject ();
project.LoadXml (documentString);
Assert.IsTrue (project.Build ("1"), "A1");
Assert.IsTrue (!File.Exists (file_path), "A2");
Assert.IsTrue (!File.Exists (file_path2), "A3");
}
[Test]
public void TestDelete5 ()
{
Engine engine;
Project project;
string file_path = Path.Combine (path, "delete.txt");
using (File.CreateText (file_path)) { }
string documentString = @"
<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
<ItemGroup>
<File Include='" + file_path + @"' />
</ItemGroup>
<Target Name='1'>
<Delete Files='@(File)'/>
</Target>
</Project>
";
engine = new Engine (Consts.BinPath);
project = engine.CreateNewProject ();
project.LoadXml (documentString);
Assert.IsTrue (project.Build ("1"), "A1");
Assert.IsTrue (!File.Exists (file_path), "A2");
}
[Test]
public void TestDelete6 ()
{
Engine engine;
Project project;
string file_path = Path.Combine (path, "delete.txt");
string file_path2 = Path.Combine (path, "delete2.txt");
using (File.CreateText (file_path)) { }
using (File.CreateText (file_path2)) { }
string documentString = @"
<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
<ItemGroup>
<File Include='" + file_path + @"' />
<File Include='" + file_path2 + @"' />
</ItemGroup>
<Target Name='1'>
<Delete Files='@(File)'/>
</Target>
</Project>
";
engine = new Engine (Consts.BinPath);
project = engine.CreateNewProject ();
project.LoadXml (documentString);
Assert.IsTrue (project.Build ("1"), "A1");
Assert.IsTrue (!File.Exists (file_path), "A2");
Assert.IsTrue (!File.Exists (file_path2), "A3");
}
[Test]
[Category ("NotWorking")]
public void TestDelete7 ()
{
Engine engine;
Project project;
string file_path = Path.Combine (path, "delete.txt");
using (File.CreateText (file_path)) { }
string documentString = @"
<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
<PropertyGroup>
<FolderToDelete>" + path + @"</FolderToDelete>
<FileToDelete>delete</FileToDelete>
<ExtToDelete>txt</ExtToDelete>
</PropertyGroup>
<Target Name='1'>
<Delete Files='$(FolderToDelete)\$(FileToDelete).$(ExtToDelete)'/>
</Target>
</Project>
";
engine = new Engine (Consts.BinPath);
project = engine.CreateNewProject ();
project.LoadXml (documentString);
Assert.IsTrue (project.Build ("1"), "A1");
Assert.IsTrue (!File.Exists (file_path), "A2");
}
}
}

View File

@@ -0,0 +1,157 @@
//
// ErrorTest.cs
//
// Author:
// Marek Sieradzki (marek.sieradzki@gmail.com)
//
// (C) 2006 Marek Sieradzki
//
// 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;
using Microsoft.Build.BuildEngine;
using Microsoft.Build.Framework;
using Microsoft.Build.Tasks;
using Microsoft.Build.Utilities;
using NUnit.Framework;
namespace MonoTests.Microsoft.Build.Tasks {
internal class TestErrorLogger : ILogger {
IList errors;
public TestErrorLogger ()
{
errors = new ArrayList ();
}
public LoggerVerbosity Verbosity { get { return LoggerVerbosity.Normal; } set { } }
public string Parameters { get { return null; } set { } }
public void Initialize (IEventSource eventSource)
{
eventSource.ErrorRaised += new BuildErrorEventHandler (ErrorHandler);
}
public void Shutdown ()
{
}
private void ErrorHandler (object sender, BuildErrorEventArgs args)
{
errors.Add (args);
}
public int CheckHead (string text, string helpKeyword, string code)
{
BuildErrorEventArgs actual;
if (errors.Count > 0) {
actual = (BuildErrorEventArgs) errors [0];
errors.RemoveAt (0);
} else
return 1;
if (text == actual.Message && helpKeyword == actual.HelpKeyword && code == actual.Code)
return 0;
else {
return 2;
}
}
}
[TestFixture]
public class ErrorTest {
Engine engine;
Project project;
TestErrorLogger testLogger;
[Test]
public void TestAssignment ()
{
string code = "code";
string helpKeyword = "helpKeyword";
string text = "text";
Error error = new Error ();
error.Code = code;
error.HelpKeyword = helpKeyword;
error.Text = text;
Assert.AreEqual (code, error.Code, "#1");
Assert.AreEqual (helpKeyword, error.HelpKeyword, "#2");
Assert.AreEqual (text, error.Text, "#3");
}
[Test]
public void TestExecution1 ()
{
string documentString = @"
<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
<Target Name='1'>
<Error Text='Text' HelpKeyword='HelpKeyword' Code='Code' />
</Target>
</Project>
";
engine = new Engine (Consts.BinPath);
project = engine.CreateNewProject ();
project.LoadXml (documentString);
bool result = project.Build ("1");
Assert.AreEqual (false, result, "#1");
}
[Test]
public void TestExecution2 ()
{
string documentString = @"
<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
<Target Name='1'>
<Error Text='Text' HelpKeyword='HelpKeyword' Code='Code' />
</Target>
</Project>
";
engine = new Engine (Consts.BinPath);
testLogger = new TestErrorLogger ();
engine.RegisterLogger (testLogger);
project = engine.CreateNewProject ();
project.LoadXml (documentString);
project.Build ("1");
Assert.AreEqual (0, testLogger.CheckHead ("Text", "HelpKeyword", "Code"), "A1");
}
[Test]
public void TestExecute1 ()
{
Error error = new Error ();
Assert.AreEqual (false, error.Execute (), "A1");
}
}
}

View File

@@ -0,0 +1,128 @@
//
// FindAppConfigFileTest.cs
//
// Author:
// Ankit Jain (jankit@novell.com)
//
// Copyright 2009 Novell, Inc (http://www.novell.com)
//
// 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.
#if NET_3_5
using System;
using System.Collections;
using Microsoft.Build.BuildEngine;
using Microsoft.Build.Framework;
using Microsoft.Build.Tasks;
using Microsoft.Build.Utilities;
using NUnit.Framework;
using System.Text;
namespace MonoTests.Microsoft.Build.Tasks {
[TestFixture]
public class FindAppConfigFileTest {
[Test]
public void TestExecution1 ()
{
CheckOutput (new string [] {"app.config"}, new string [] {"app.config"}, "AppConfigWithTargetPath: app.config List1 Foo.exe.config");
}
[Test]
public void TestExecution2 ()
{
CheckOutput (new string [] {"foobar"}, new string [] {"app.config"}, "AppConfigWithTargetPath: app.config List2 Foo.exe.config");
}
[Test]
public void TestExecution3 ()
{
CheckOutput (new string [] {"foo\\app.config"}, new string [] {"app.config"}, "AppConfigWithTargetPath: app.config List2 Foo.exe.config");
}
[Category ("NotWorking")]
[Test]
public void TestExecution4 ()
{
CheckOutput (new string[] { "foo\\app.config" }, new string[] { "bar\\app.config" }, "AppConfigWithTargetPath: foo\\app.config List1 Foo.exe.config");
}
[Category ("NotWorking")]
[Test]
public void TestExecution5 ()
{
CheckOutput (new string[] { "foobar" }, new string[] { "bar\\app.config" }, "AppConfigWithTargetPath: bar\\app.config List2 Foo.exe.config");
}
[Test]
public void TestExecution6 ()
{
CheckOutput (new string[] { "foobar" }, new string[] { "bar\\foo.config" }, "AppConfigWithTargetPath: ");
}
[Test]
public void TestExecution7 () {
CheckOutput (new string[] { ".\\app.config" }, new string[] { "app.config" }, "AppConfigWithTargetPath: app.config List2 Foo.exe.config");
}
void CheckOutput (string[] primary_list, string[] secondary_list, string expected) {
StringBuilder sb = new StringBuilder ();
sb.Append (@"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"" " + Consts.ToolsVersionString + ">");
sb.Append ("\t<ItemGroup>");
if (primary_list != null)
foreach (string s in primary_list)
sb.AppendFormat ("\t\t<List1 Include=\"{0}\"><Source>List1</Source></List1>", s);
if (secondary_list != null)
foreach (string s in secondary_list)
sb.AppendFormat ("\t\t<List2 Include=\"{0}\"><Source>List2</Source></List2>", s);
sb.Append ("\t</ItemGroup>");
sb.Append (@"
<Target Name='1'>
<FindAppConfigFile PrimaryList=""@(List1)"" SecondaryList=""@(List2)"" TargetPath=""Foo.exe.config"">
<Output TaskParameter=""AppConfigFile"" ItemName=""AppConfigWithTargetPath""/>
</FindAppConfigFile>
<Message Text=""AppConfigWithTargetPath: %(AppConfigWithTargetPath.Identity) %(AppConfigWithTargetPath.Source) %(AppConfigWithTargetPath.TargetPath)""/>
</Target>
</Project>");
string projectXml = sb.ToString ();
Engine engine = new Engine (Consts.BinPath);
TestMessageLogger testLogger = new TestMessageLogger ();
engine.RegisterLogger (testLogger);
Project project = engine.CreateNewProject ();
project.LoadXml (projectXml);
if (!project.Build ("1")) {
testLogger.DumpMessages ();
Assert.Fail ("Build failed");
}
Assert.AreEqual (1, testLogger.NormalMessageCount, "Expected number of messages");
testLogger.CheckLoggedMessageHead (expected, "A1");
}
}
}
#endif

View File

@@ -0,0 +1,69 @@
//
// GetFrameworkPathTest.cs
//
// Author:
// Marek Sieradzki (marek.sieradzki@gmail.com)
//
// (C) 2006 Marek Sieradzki
//
// 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;
using System.IO;
using Microsoft.Build.BuildEngine;
using Microsoft.Build.Framework;
using Microsoft.Build.Tasks;
using Microsoft.Build.Utilities;
using NUnit.Framework;
namespace MonoTests.Microsoft.Build.Tasks {
[TestFixture]
public class GetFrameworkPathTest {
[Test]
public void TestExecution1 ()
{
Engine engine;
Project project;
string documentString = @"
<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
<Target Name='1'>
<GetFrameworkPath>
<Output
TaskParameter='Path'
PropertyName='Path'
/>
</GetFrameworkPath>
</Target>
</Project>
";
engine = new Engine (Consts.BinPath);
project = engine.CreateNewProject ();
project.LoadXml (documentString);
Assert.IsTrue (project.Build ("1"), "A1");
Assert.IsNotNull (project.EvaluatedProperties ["Path"], "A2");
Assert.IsTrue (String.Empty != project.EvaluatedProperties ["Path"].FinalValue, "A3");
}
}
}

View File

@@ -0,0 +1,69 @@
//
// GetFrameworkSdkPathTest.cs
//
// Author:
// Marek Sieradzki (marek.sieradzki@gmail.com)
//
// (C) 2006 Marek Sieradzki
//
// 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;
using System.IO;
using Microsoft.Build.BuildEngine;
using Microsoft.Build.Framework;
using Microsoft.Build.Tasks;
using Microsoft.Build.Utilities;
using NUnit.Framework;
namespace MonoTests.Microsoft.Build.Tasks {
[TestFixture]
public class GetFrameworkSdkPathTest {
[Test]
public void TestExecution1 ()
{
Engine engine;
Project project;
string documentString = @"
<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
<Target Name='1'>
<GetFrameworkSdkPath>
<Output
TaskParameter='Path'
PropertyName='Path'
/>
</GetFrameworkSdkPath>
</Target>
</Project>
";
engine = new Engine (Consts.BinPath);
project = engine.CreateNewProject ();
project.LoadXml (documentString);
Assert.IsTrue (project.Build ("1"), "A1");
Assert.IsNotNull (project.EvaluatedProperties ["Path"], "A2");
Assert.IsTrue (String.Empty != project.EvaluatedProperties ["Path"].FinalValue, "A3");
}
}
}

View File

@@ -0,0 +1,101 @@
//
// LCTest.cs
//
// Author:
// Ankit Jain (jankit@novell.com)
//
// Copyright 2010 Novell, Inc (http://www.novell.com)
//
// 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;
using System.IO;
using Microsoft.Build.BuildEngine;
using Microsoft.Build.Framework;
using Microsoft.Build.Tasks;
using Microsoft.Build.Utilities;
using NUnit.Framework;
namespace MonoTests.Microsoft.Build.Tasks {
class LCExtended : LC {
public LCExtended ()
: base ()
{
}
public void ACLC (CommandLineBuilderExtension commandLine)
{
base.AddCommandLineCommands (commandLine);
}
public string TN {
get { return base.ToolName; }
}
}
[TestFixture]
public class LCTest {
[Test]
public void TestAssignment1 ()
{
LC lc = new LC ();
lc.LicenseTarget = new TaskItem ("bar.exe");
lc.NoLogo = true;
lc.OutputDirectory = "abc\\def";
lc.OutputLicense = new TaskItem ("bar.exe.licenses");
lc.ReferencedAssemblies = new ITaskItem [] { new TaskItem ("Test.dll") };
lc.Sources = new ITaskItem [] { new TaskItem ("foo.licx") };
Assert.AreEqual ("bar.exe", lc.LicenseTarget.ItemSpec, "LicenseTarget");
Assert.AreEqual (true, lc.NoLogo, "NoLogo");
Assert.AreEqual ("abc\\def", lc.OutputDirectory, "OutputDirectory");
Assert.AreEqual ("bar.exe.licenses", lc.OutputLicense.ItemSpec, "OutputLicense");
Assert.AreEqual (1, lc.ReferencedAssemblies.Length, "Number of ReferenceAssemblies");
Assert.AreEqual ("Test.dll", lc.ReferencedAssemblies [0].ItemSpec, "ReferencedAssemblies[0]");
Assert.AreEqual (1, lc.Sources.Length, "Number of Sources");
Assert.AreEqual ("foo.licx", lc.Sources [0].ItemSpec, "Sources [0]");
}
[Test]
public void TestDefaults ()
{
LC lc = new LC ();
lc.LicenseTarget = new TaskItem ("bar.exe");
lc.Sources = new ITaskItem [] { new TaskItem ("foo.licx") };
Assert.AreEqual ("bar.exe", lc.LicenseTarget.ItemSpec, "LicenseTarget");
Assert.AreEqual (false, lc.NoLogo, "NoLogo");
Assert.IsNull (lc.OutputDirectory, "OutputDirectory");
Assert.AreEqual (null, lc.OutputLicense, "OutputLicense");
Assert.IsNull (lc.ReferencedAssemblies, "ReferencedAssemblies");
Assert.AreEqual (1, lc.Sources.Length, "Number of Sources");
Assert.AreEqual ("foo.licx", lc.Sources [0].ItemSpec, "Sources [0]");
}
}
}

View File

@@ -0,0 +1,107 @@
//
// MakeDirTest.cs
//
// Author:
// Marek Sieradzki (marek.sieradzki@gmail.com)
//
// (C) 2006 Marek Sieradzki
//
// 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;
using System.IO;
using Microsoft.Build.BuildEngine;
using Microsoft.Build.Framework;
using Microsoft.Build.Tasks;
using Microsoft.Build.Utilities;
using NUnit.Framework;
namespace MonoTests.Microsoft.Build.Tasks {
[TestFixture]
public class MakeDirTest {
[SetUp]
public void CreateDir ()
{
string path = Path.Combine (Path.Combine ("Test", "resources"), "MakeDir");
Directory.CreateDirectory (path);
}
[TearDown]
public void RemoveDirectories ()
{
string path = Path.Combine (Path.Combine ("Test", "resources"), "MakeDir");
Directory.Delete (path, true);
}
[Test]
public void TestAssignment ()
{
MakeDir md = new MakeDir ();
md.Directories = new ITaskItem [2] { new TaskItem ("A"), new TaskItem ("B") };
Assert.AreEqual (2, md.Directories.Length, "A1");
}
[Test]
public void TestExecution1 ()
{
Engine engine;
Project project;
string path = Path.Combine (Path.Combine ("Test", "resources"), "MakeDir");
string documentString = @"
<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
<ItemGroup>
<Dir Include='Test\resources\MakeDir\A' />
<Dir Include='Test\resources\MakeDir\B' />
<Dir Include='Test\resources\MakeDir\C' />
</ItemGroup>
<Target Name='1'>
<MakeDir Directories='@(Dir)'>
<Output
TaskParameter='DirectoriesCreated'
ItemName='Out'
/>
</MakeDir>
</Target>
</Project>
";
engine = new Engine (Consts.BinPath);
project = engine.CreateNewProject ();
project.LoadXml (documentString);
project.Build ("1");
Assert.AreEqual (3, Directory.GetDirectories (path).Length, "A1");
Assert.AreEqual (Path.Combine (path, "A"), Directory.GetDirectories (path) [0], "A2");
Assert.AreEqual (Path.Combine (path, "B"), Directory.GetDirectories (path) [1], "A3");
Assert.AreEqual (Path.Combine (path, "C"), Directory.GetDirectories (path) [2], "A4");
BuildItemGroup output = project.GetEvaluatedItemsByName ("Out");
Assert.AreEqual (Path.Combine (path, "A"), output [0].FinalItemSpec, "A5");
Assert.AreEqual (Path.Combine (path, "B"), output [1].FinalItemSpec, "A6");
Assert.AreEqual (Path.Combine (path, "C"), output [2].FinalItemSpec, "A7");
}
}
}

Some files were not shown because too many files have changed in this diff Show More