Skip to content

Commit

Permalink
Merge pull request #487 from jrnail23/fix-copyfile-logging
Browse files Browse the repository at this point in the history
Closes #486: CopyFile logs incorrect targetFilePath
  • Loading branch information
devlead committed Nov 6, 2015
2 parents adda979 + 94ca297 commit af62492
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/Cake.Common.Tests/Fixtures/IO/FileCopyFixture.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System.Collections.Generic;
using Cake.Core;
using Cake.Core.Diagnostics;
using Cake.Core.IO;
using Cake.Testing;
using NSubstitute;

namespace Cake.Common.Tests.Fixtures.IO
Expand All @@ -12,6 +14,7 @@ internal sealed class FileCopyFixture
public ICakeContext Context { get; set; }
public IGlobber Globber { get; set; }
public IDirectory TargetDirectory { get; set; }
public FakeLog Log { get; set; }

public List<FilePath> SourceFilePaths { get; set; }
public List<IFile> TargetFiles { get; set; }
Expand Down Expand Up @@ -44,11 +47,15 @@ public FileCopyFixture()
Environment = Substitute.For<ICakeEnvironment>();
Environment.WorkingDirectory.Returns("/Working");

// Setup the logger
Log = new FakeLog();

// Prepare the context.
Context = Substitute.For<ICakeContext>();
Context.FileSystem.Returns(FileSystem);
Context.Environment.Returns(Environment);
Context.Globber.Returns(Globber);
Context.Log.Returns(Log);
}

private void CreateTargetFile(FilePath sourcePath, FilePath targetPath)
Expand Down
18 changes: 18 additions & 0 deletions src/Cake.Common.Tests/Unit/IO/FileAliasesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
using Cake.Testing;
using NSubstitute;
using Xunit;
using LogLevel = Cake.Core.Diagnostics.LogLevel;
using Verbosity = Cake.Core.Diagnostics.Verbosity;

namespace Cake.Common.Tests.Unit.IO
{
Expand Down Expand Up @@ -200,6 +202,22 @@ public void Should_Copy_File()
fixture.TargetFiles[0].Received(1).Copy(
Arg.Is<FilePath>(p => p.FullPath == "/Working/target/file1.txt"), true);
}

[Fact]
public void Should_Log_Verbose_Message_With_Correct_Target()
{
// Given
var fixture = new FileCopyFixture();

// When
FileAliases.CopyFile(fixture.Context, "./file1.txt", "./target/file1.txt");

// Then
Assert.Contains(fixture.Log.Entries,
entry =>
entry.Level == LogLevel.Verbose && entry.Verbosity == Verbosity.Verbose &&
entry.Message == "Copying file file1.txt to /Working/target/file1.txt");
}
}

public sealed class TheCopyFilesMethod
Expand Down
5 changes: 3 additions & 2 deletions src/Cake.Common/IO/FileCopier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,10 @@ private static void CopyFileCore(ICakeContext context, FilePath filePath, FilePa
}

// Copy the file.
context.Log.Verbose("Copying file {0} to {1}", absoluteFilePath.GetFilename(), absoluteFilePath);
var absoluteTargetPath = targetFilePath.MakeAbsolute(context.Environment);
context.Log.Verbose("Copying file {0} to {1}", absoluteFilePath.GetFilename(), absoluteTargetPath);
var file = context.FileSystem.GetFile(absoluteFilePath);
file.Copy(targetFilePath.MakeAbsolute(context.Environment), true);
file.Copy(absoluteTargetPath, true);
}
}
}

0 comments on commit af62492

Please sign in to comment.