diff --git a/src/Tasks.UnitTests/RemoveDir_Tests.cs b/src/Tasks.UnitTests/RemoveDir_Tests.cs index 7f88ef17839..0dee182082b 100644 --- a/src/Tasks.UnitTests/RemoveDir_Tests.cs +++ b/src/Tasks.UnitTests/RemoveDir_Tests.cs @@ -1,15 +1,25 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using System.Collections.Generic; +using System.IO; using Microsoft.Build.Framework; using Microsoft.Build.Tasks; using Microsoft.Build.Utilities; +using Shouldly; using Xunit; +using Xunit.Abstractions; namespace Microsoft.Build.UnitTests { sealed public class RemoveDir_Tests { + ITestOutputHelper _output; + public RemoveDir_Tests(ITestOutputHelper output) + { + _output = output; + } + /* * Method: AttributeForwarding * @@ -23,14 +33,42 @@ public void AttributeForwarding() ITaskItem i = new TaskItem("MyNonExistentDirectory"); i.SetMetadata("Locale", "en-GB"); t.Directories = new ITaskItem[] { i }; - t.BuildEngine = new MockEngine(); + t.BuildEngine = new MockEngine(_output); t.Execute(); - Assert.Equal("en-GB", t.RemovedDirectories[0].GetMetadata("Locale")); + t.RemovedDirectories[0].GetMetadata("Locale").ShouldBe("en-GB"); + t.RemovedDirectories[0].ItemSpec.ShouldBe("MyNonExistentDirectory"); + Directory.Exists(t.RemovedDirectories[0].ItemSpec).ShouldBeFalse(); + } + + [Fact] + public void SimpleDelete() + { + + using (TestEnvironment env = TestEnvironment.Create(_output)) + { + List list = new List(); + + for (int i = 0; i < 20; i++) + { + list.Add(new TaskItem(env.CreateFolder().Path)); + } + + RemoveDir t = new RemoveDir(); + + t.Directories = list.ToArray(); + t.BuildEngine = new MockEngine(_output); + + t.Execute().ShouldBeTrue(); + + t.RemovedDirectories.Length.ShouldBe(list.Count); - // Output ItemSpec should not be overwritten. - Assert.Equal("MyNonExistentDirectory", t.RemovedDirectories[0].ItemSpec); + for (int i = 0; i < 20; i++) + { + Directory.Exists(list[i].ItemSpec).ShouldBeFalse(); + } + } } } } diff --git a/src/Tasks/RemoveDir.cs b/src/Tasks/RemoveDir.cs index f802cbfc70d..c19be8486f6 100644 --- a/src/Tasks/RemoveDir.cs +++ b/src/Tasks/RemoveDir.cs @@ -44,8 +44,6 @@ public ITaskItem[] Directories //----------------------------------------------------------------------------------- public override bool Execute() { - // Delete each directory - bool overallSuccess = true; // Our record of the directories that were removed var removedDirectoriesList = new List(); @@ -73,12 +71,6 @@ public override bool Execute() } } - // The current directory was not removed successfully - if (!currentSuccess) - { - overallSuccess = false; - } - // We successfully removed the directory, so add the removed directory to our record if (currentSuccess) { @@ -97,7 +89,7 @@ public override bool Execute() } // convert the list of deleted files into an array of ITaskItems RemovedDirectories = removedDirectoriesList.ToArray(); - return overallSuccess; + return !Log.HasLoggedErrors; } // Core implementation of directory removal