Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 42 additions & 4 deletions src/Tasks.UnitTests/RemoveDir_Tests.cs
Original file line number Diff line number Diff line change
@@ -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
*
Expand All @@ -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<TaskItem> list = new List<TaskItem>();

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();
}
}
}
}
}
Expand Down
10 changes: 1 addition & 9 deletions src/Tasks/RemoveDir.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ITaskItem>();

Expand Down Expand Up @@ -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)
{
Expand All @@ -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
Expand Down