Exemplo n.º 1
0
        public void AbsoluteAbsolute1()
        {
            CombinePath t = new CombinePath();

            t.BuildEngine = new MockEngine();

            t.BasePath = NativeMethodsShared.IsWindows ? @"\\fileserver\public" : "/rootdir/public";
            string path1        = NativeMethodsShared.IsWindows ? @"c:\ghi.txt" : "/ghi.txt";
            string path2        = NativeMethodsShared.IsWindows ? @"d:\jkl\mno.txt" : "/jkl/mno.txt";
            string path3        = @"\\myserver\myshare";
            string pathsToMatch = string.Format(NativeMethodsShared.IsWindows ? @"
                {0}
                {1}
                {2}
                " : @"
                {0}
                {1}
                ", path1, path2, path3);

            t.Paths = NativeMethodsShared.IsWindows
                          ? new ITaskItem[] { new TaskItem(path1), new TaskItem(path2), new TaskItem(path3) }
                          : new ITaskItem[] { new TaskItem(path1), new TaskItem(path2) };
            Assert.True(t.Execute()); // "success"

            ObjectModelHelpers.AssertItemsMatch(pathsToMatch, t.CombinedPaths, true);
        }
Exemplo n.º 2
0
        public void MetadataPreserved()
        {
            CombinePath t = new CombinePath();

            t.BuildEngine = new MockEngine();
            string expected;

            if (NativeMethodsShared.IsWindows)
            {
                t.BasePath = @"c:\abc\def\";
                t.Paths    = new ITaskItem[] { new TaskItem(@"jkl\mno.txt") };
                expected   = @"
                c:\abc\def\jkl\mno.txt : Culture=english
                ";
            }
            else
            {
                t.BasePath = "/abc/def/";
                t.Paths    = new ITaskItem[] { new TaskItem("jkl/mno.txt") };
                expected   = @"
                /abc/def/jkl/mno.txt : Culture=english
                ";
            }
            t.Paths[0].SetMetadata("Culture", "english");
            Assert.True(t.Execute()); // "success"

            ObjectModelHelpers.AssertItemsMatch(expected, t.CombinedPaths, true);
        }
Exemplo n.º 3
0
        public void NoPaths()
        {
            CombinePath t = new CombinePath();

            t.BuildEngine = new MockEngine();

            t.BasePath = @"c:\abc\def";
            t.Paths    = new ITaskItem[0];
            Assert.True(t.Execute()); // "success"

            ObjectModelHelpers.AssertItemsMatch(@"
                ", t.CombinedPaths, true);
        }
Exemplo n.º 4
0
        public void NoBasePath()
        {
            CombinePath t = new CombinePath();

            t.BuildEngine = new MockEngine();

            t.Paths = new ITaskItem[] { new TaskItem(@"jkl\mno.txt"), new TaskItem(@"c:\abc\def\ghi.txt") };
            Assert.True(t.Execute()); // "success"

            ObjectModelHelpers.AssertItemsMatch(@"
                jkl\mno.txt
                c:\abc\def\ghi.txt
                ", t.CombinedPaths, true);
        }
Exemplo n.º 5
0
        public void CaptureTargetOutputs()
        {
            Project project = ObjectModelHelpers.CreateInMemoryProject(@"

                <Project DefaultTargets=`build` ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`>
                    <Target Name=`build` >

                        <CallTarget Targets=` a; b; c ` >
                            <Output ItemName=`myfancytargetoutputs` TaskParameter=`TargetOutputs`/>
                        </CallTarget>

                    </Target>
                    <!-- include some nice characters that need escaping -->
                    <Target Name=`a` Outputs=`a.t!@#$%^xt`>
	                    <Message Text=`Inside A` />
                    </Target>
                    <Target Name=`b` Outputs=`b.txt`>
	                    <Message Text=`Inside B` />
                    </Target>
                    <Target Name=`c` Outputs=`c.txt`>
	                    <Message Text=`Inside C` />
                    </Target>
                </Project>

                ");

            ProjectInstance instance = project.CreateProjectInstance();
            bool            success  = instance.Build();

            Assert.True(success); // "Build failed.  See test output (Attachments in Azure Pipelines) for details"

            IEnumerable <ProjectItemInstance> targetOutputs = instance.GetItems("myfancytargetoutputs");

            // Convert to a list of TaskItems for easier verification.
            List <ITaskItem> targetOutputsTaskItems = new List <ITaskItem>();

            foreach (ProjectItemInstance item in targetOutputs)
            {
                targetOutputsTaskItems.Add(new TaskItem(item.EvaluatedInclude));
            }

            // Order independent verification of the right set of items.
            ObjectModelHelpers.AssertItemsMatch(@"
                c.txt
                b.txt
                a.t!@#$%^xt
                ",
                                                targetOutputsTaskItems.ToArray(), false /* ignore the order */);
        }
Exemplo n.º 6
0
        public void AbsoluteRelative1()
        {
            CombinePath t = new CombinePath();

            t.BuildEngine = new MockEngine();

            t.BasePath = NativeMethodsShared.IsWindows ? @"c:\abc\def" : "/abc/def";
            string path1     = Path.DirectorySeparatorChar + Path.Combine("ghi", "jkl.txt");
            string path2     = Path.Combine("mno", "qrs.txt");
            string fullPath2 = Path.Combine(t.BasePath, path2);

            t.Paths = new ITaskItem[] { new TaskItem(path1), new TaskItem(path2) };
            Assert.True(t.Execute()); // "success"

            ObjectModelHelpers.AssertItemsMatch(string.Format("{0}\r\n{1}", path1, fullPath2), t.CombinedPaths, true);
        }
Exemplo n.º 7
0
        public void InvalidPath()
        {
            CombinePath t = new CombinePath();

            t.BuildEngine = new MockEngine(true);

            t.BasePath = @"c:\abc\def";
            t.Paths    = new ITaskItem[] { new TaskItem("ghi.txt"), new TaskItem("|.txt"), new TaskItem("jkl.txt") };
            Assert.False(t.Execute()); // "should have failed"
            ((MockEngine)t.BuildEngine).AssertLogContains("MSB3095");

            ObjectModelHelpers.AssertItemsMatch(@"
                c:\abc\def\ghi.txt
                c:\abc\def\jkl.txt
                ", t.CombinedPaths, true);
        }
Exemplo n.º 8
0
        public void RelativeRelative1()
        {
            CombinePath t = new CombinePath();

            t.BuildEngine = new MockEngine();

            t.BasePath = Path.Combine("abc", "def");
            string path1     = "ghi.txt";
            string fullPath1 = Path.Combine(t.BasePath, path1);
            string path2     = Path.Combine("jkl", "mno.txt");
            string fullPath2 = Path.Combine(t.BasePath, path2);

            t.Paths = new ITaskItem[] { new TaskItem(path1), new TaskItem(path2) };
            Assert.True(t.Execute()); // "success"

            ObjectModelHelpers.AssertItemsMatch(string.Format("{0}\r\n{1}", fullPath1, fullPath2), t.CombinedPaths, true);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Amazingly sophisticated :) helper function to determine if the set of ITaskItems returned from
        /// a task match the expected set of ITaskItems.  It can also check that the ITaskItems have the expected
        /// metadata, and that the ITaskItems are returned in the correct order.
        ///
        /// The "expectedItemsString" is a formatted way of easily specifying which items you expect to see.
        /// The format is:
        ///
        ///         itemspec1 :   metadataname1=metadatavalue1 ; metadataname2=metadatavalue2 ; ...
        ///         itemspec2 :   metadataname3=metadatavalue3 ; metadataname4=metadatavalue4 ; ...
        ///         itemspec3 :   metadataname5=metadatavalue5 ; metadataname6=metadatavalue6 ; ...
        ///
        /// (Each item needs to be on its own line.)
        ///
        /// </summary>
        /// <param name="expectedItemsString"></param>
        /// <param name="actualItems"></param>
        /// <owner>RGoel</owner>
        static internal void AssertItemsMatch
        (
            string expectedItemsString,
            BuildItem[] actualItems,
            bool orderOfItemsShouldMatch
        )
        {
            ITaskItem[] actualTaskItems = new ITaskItem[actualItems.Length];

            int i = 0;

            foreach (BuildItem actualItem in actualItems)
            {
                actualTaskItems[i++] = new net.r_eg.IeXod.BuildEngine.TaskItem(actualItem);
            }

            ObjectModelHelpers.AssertItemsMatch(expectedItemsString, actualTaskItems, orderOfItemsShouldMatch);
        }