From b7b5f6222c8eb91b0ae9629cb9f1713e012fe809 Mon Sep 17 00:00:00 2001 From: James Nail Date: Wed, 4 Nov 2015 14:42:54 -0500 Subject: [PATCH] Closes #486: CopyFile logs incorrect targetFilePath --- .../Fixtures/IO/FileCopyFixture.cs | 7 +++++++ .../Unit/IO/FileAliasesTests.cs | 18 ++++++++++++++++++ src/Cake.Common/IO/FileCopier.cs | 5 +++-- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/Cake.Common.Tests/Fixtures/IO/FileCopyFixture.cs b/src/Cake.Common.Tests/Fixtures/IO/FileCopyFixture.cs index 6c611c8503..f234b30ef4 100644 --- a/src/Cake.Common.Tests/Fixtures/IO/FileCopyFixture.cs +++ b/src/Cake.Common.Tests/Fixtures/IO/FileCopyFixture.cs @@ -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 @@ -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 SourceFilePaths { get; set; } public List TargetFiles { get; set; } @@ -44,11 +47,15 @@ public FileCopyFixture() Environment = Substitute.For(); Environment.WorkingDirectory.Returns("/Working"); + // Setup the logger + Log = new FakeLog(); + // Prepare the context. Context = Substitute.For(); Context.FileSystem.Returns(FileSystem); Context.Environment.Returns(Environment); Context.Globber.Returns(Globber); + Context.Log.Returns(Log); } private void CreateTargetFile(FilePath sourcePath, FilePath targetPath) diff --git a/src/Cake.Common.Tests/Unit/IO/FileAliasesTests.cs b/src/Cake.Common.Tests/Unit/IO/FileAliasesTests.cs index f568b9092b..5ed1f13673 100644 --- a/src/Cake.Common.Tests/Unit/IO/FileAliasesTests.cs +++ b/src/Cake.Common.Tests/Unit/IO/FileAliasesTests.cs @@ -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 { @@ -200,6 +202,22 @@ public void Should_Copy_File() fixture.TargetFiles[0].Received(1).Copy( Arg.Is(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 diff --git a/src/Cake.Common/IO/FileCopier.cs b/src/Cake.Common/IO/FileCopier.cs index 3e683667e0..3f79cd9b70 100644 --- a/src/Cake.Common/IO/FileCopier.cs +++ b/src/Cake.Common/IO/FileCopier.cs @@ -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); } } } \ No newline at end of file