[xbuild] Fix test on windows.
[mono.git] / mcs / class / Microsoft.Build.Tasks / Test / Microsoft.Build.Tasks / AssignTargetPathTest.cs
index 6cac0b6c5a89c434e8e9623adb8fc0096e8e9d66..43917b03e340b8917fac8248808ced3b00b13c5c 100755 (executable)
@@ -64,7 +64,7 @@ namespace MonoTests.Microsoft.Build.Tasks
                {
                        if (OS == OsType.Unix) {
                                CheckTargetPath(
-                                       new string[] { "/a/b/./abc.cs", "/a/c/def.cs", "xyz.cs", "/different/xyz/foo.cs", "rel/bar.resx"},
+                                       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) {
@@ -78,35 +78,106 @@ namespace MonoTests.Microsoft.Build.Tasks
                [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", "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[] { @"C:\\a\b\abc.cs", @"k\..\def.cs", @"C:\xyz.cs", @"C:\different\xyz\foo.cs"},
-                                       new string[] { "a\\b\\abc.cs", "def.cs", "xyz.cs", "different\\xyz\\foo.cs"},
-                                       "C:\\", "A");
+                                       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[] { "xyz.cs", "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[] { "xyz.cs", "bar.resx" },
-                                       "C:\\", "A");
+                                       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);
@@ -142,7 +213,6 @@ namespace MonoTests.Microsoft.Build.Tasks
                                        <Output TaskParameter=""AssignedFiles"" ItemName=""FooPath"" />
                                </AssignTargetPath>
                        </Target>
-                       <Import Project=""$(MSBuildBinPath)\Microsoft.Common.targets"" />
                </Project>", rootFolder);
 
                        return sb.ToString();