Skip to content

Commit

Permalink
fixes #23 - issue with unit tests being path dependent
Browse files Browse the repository at this point in the history
  • Loading branch information
activescott committed Mar 1, 2014
1 parent f7adcf0 commit c0c8b56
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/Lessmsi.Tests/CommandLineExtractTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,12 @@ private void TestExtraction(string commandLineArguments, string testName, string
exitCode = base.RunCommandLineInProccess(commandLineArguments);
else
exitCode = base.RunCommandLine(commandLineArguments, out consoleOutput);
var actualEntries = FileEntryGraph.GetActualEntries(actualEntriesOutputDir, "Actual Entries");

var actualEntries = FileEntryGraph.GetActualEntries(actualOutDir.FullName, "Actual Entries");
var actualEntriesFile = GetActualOutputFile(testName);
actualEntries.Save(actualEntriesFile);
Console.WriteLine("Actual entries saved to " + actualEntriesFile.FullName);
var expectedEntries = GetExpectedEntriesForMsi(testName);
var expectedEntries = GetExpectedEntriesForMsi(testName);
AssertAreEqual(expectedEntries, actualEntries);
}

Expand Down
32 changes: 21 additions & 11 deletions src/Lessmsi.Tests/FileEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ namespace LessMsi.Tests
[DebuggerDisplay("{Path}")]
public sealed class FileEntry : IEquatable<FileEntry>
{
/// <summary>
/// Initializes a new FileEntry.
/// </summary>
/// <param name="path">The initial value for <see cref="FileEntry.Path"/>.</param>
/// <param name="size">The initial value for <see cref="FileEntry.Size"/>.</param>
public FileEntry(string path, long size, DateTime creationTime, DateTime lastWriteTime, FileAttributes attributes)
/// <summary>
/// Initializes a new FileEntry.
/// </summary>
/// <param name="path">The initial value for <see cref="FileEntry.Path"/>.</param>
/// <param name="size">The initial value for <see cref="FileEntry.Size"/>.</param>
/// <param name="creationTime"> </param>
/// <param name="lastWriteTime"> </param>
/// <param name="attributes"> </param>
public FileEntry(string path, long size, DateTime creationTime, DateTime lastWriteTime, FileAttributes attributes)
{
Size = size;
Path = path;
Expand All @@ -25,15 +28,22 @@ public FileEntry(string path, long size, DateTime creationTime, DateTime lastWri
/// Initializes a new FileEntry
/// </summary>
/// <param name="file">The file this object represents.</param>
/// <param name="relativeTo">The root path that the specified file is relative to. The value of <see cref="FileEntry.Path"/> will be changed to be relative to this value.</param>
public FileEntry(FileInfo file, string relativeTo)
/// <param name="basePathToRemove">
/// The root of the path of the specified file that should be removed to ensure that the output is a relative portion of the file.
/// Essentially the value of <see cref="FileEntry.Path"/> will be changed by stripping of the begining portion of this file.
/// </param>
public FileEntry(FileInfo file, string basePathToRemove)
{
Size = file.Length;

if (file.FullName.StartsWith(relativeTo))
Path = file.FullName.Substring(relativeTo.Length);
if (file.FullName.StartsWith(basePathToRemove, StringComparison.InvariantCultureIgnoreCase))
Path = file.FullName.Substring(basePathToRemove.Length);
else
Path = file.FullName;
{
Path = file.FullName;
Debug.Fail("Why would this happen? Normally the file should be rooted in that path.");
}


this.CreationTime = file.CreationTime;
this.LastWriteTime = file.LastWriteTime;
Expand Down
18 changes: 17 additions & 1 deletion src/Lessmsi.Tests/FileEntryGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,23 @@ public static FileEntryGraph Load(FileInfo file, string forFileName)
var line = f.ReadLine().Split(',');
if (line.Length != 5)
throw new IOException("Expected 5 fields!");
graph.Add(new FileEntry(line[0], Int64.Parse(line[1]), DeserializeDate(line[2]), DeserializeDate(line[3]), DeserializeAttributes(line[4])) );
/* FIX for github issue #23:
* The problem was that old ExpectedOutput files were all prefixed with C:\projects\lessmsi\src\Lessmsi.Tests\bin\Debug\<msiFileNameWithoutExtension> (something like C:\projects\lessmsi\src\Lessmsi.Tests\bin\Debug\NUnit-2.5.2.9222\SourceDir\PFiles\NUnit 2.5.2\fit-license.txt)
* We need to remove Since we don't reasonably know what the original msi filename was, we do know it was the subdirectory of C:\projects\lessmsi\src\Lessmsi.Tests\bin\Debug\. So we should remove C:\projects\lessmsi\src\Lessmsi.Tests\bin\Debug\ and the next subdirectory from the path.
* HACK: A better fix would undoubtedly be to cleanup those old file swith code like this and remove this hack from this code forever!
*/
var path = line[0];
const string oldRootPath = @"C:\projects\lessmsi\src\Lessmsi.Tests\bin\Debug\";
if (path.StartsWith(oldRootPath, StringComparison.InvariantCultureIgnoreCase))
{
//this is an old file that would trigger github issue #23, so we'll fix it here...
// first remove the old root path:
path = path.Substring(oldRootPath.Length);
// now romove the msi filename (which we don't know, but we know it is the next subdirectory of the old root):
var lengthOfSubDirectoryName = path.IndexOf('\\', 0);
path = path.Substring(lengthOfSubDirectoryName);
}
graph.Add(new FileEntry(path, Int64.Parse(line[1]), DeserializeDate(line[2]), DeserializeDate(line[3]), DeserializeAttributes(line[4])) );
}
}
return graph;
Expand Down

0 comments on commit c0c8b56

Please sign in to comment.