Skip to content

Commit

Permalink
chore: test for #169
Browse files Browse the repository at this point in the history
  • Loading branch information
activescott committed Oct 25, 2021
1 parent 6d0fe83 commit 7c8618d
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 3 deletions.
34 changes: 34 additions & 0 deletions src/Lessmsi.Tests/MiscTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Xunit;
using LessIO;

namespace LessMsi.Tests
{
Expand Down Expand Up @@ -59,6 +60,39 @@ public void ExtractFromExternalCab()
ExtractAndCompareToMaster("msi_with_external_cab.msi");
}

/// <summary>
/// This test is for github issue 169: https://github.com/activescott/lessmsi/issues/169
/// </summary>
[Fact]
public void ExtractFromExternalCabWithSourceDirAndOutputDirSame()
{
var msiFileName = "vcredist.msi";
var cabFileName = "vcredis1.cab";
// put the msi and cab into the output directory (as this is all about having the source dir and output dir be the same):
var outputDir = GetTestOutputDir(Path.Empty, msiFileName);
if (FileSystem.Exists(outputDir))
{
FileSystem.RemoveDirectory(outputDir, true);
}
FileSystem.CreateDirectory(outputDir);
var msiFileOutputDir = Path.Combine(outputDir, msiFileName);
FileSystem.Copy(GetMsiTestFile(msiFileName), msiFileOutputDir);
FileSystem.Copy(GetMsiTestFile(cabFileName), Path.Combine(outputDir, cabFileName));

// run test normally:
var cleanOutputDirectoryBeforeExtracting = false;
//var actualFileEntries = ExtractFilesFromMsi(msiFileName, null, outputDir, true, cleanOutputDirectoryBeforeExtracting);
LessMsi.Msi.Wixtracts.ExtractFiles(msiFileOutputDir, outputDir.PathString);
// build actual file entries extracted
var actualFileEntries = FileEntryGraph.GetActualEntries(outputDir.PathString, msiFileName);
// this test has the original msi and cab as the first two entries and their times change. so we drop them here:
actualFileEntries.Entries.RemoveRange(0, 2);
// dump to actual dir (for debugging and updating tests)
actualFileEntries.Save(GetActualOutputFile(msiFileName));
var expectedEntries = GetExpectedEntriesForMsi(msiFileName);
AssertAreEqual(expectedEntries, actualFileEntries);
}

/// <summary>
/// This one demonstrates a problem were paths are screwed up.
/// Note that the output path ends up being SourceDir\SlikSvn\bin\Windows\winsxs\... and it should be just \windows\winsxs\...
Expand Down
12 changes: 9 additions & 3 deletions src/Lessmsi.Tests/TestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,24 @@ protected FileEntryGraph ExtractFilesFromMsi(string msiFileName, string[] fileNa
return ExtractFilesFromMsi(msiFileName, fileNamesToExtractOrNull, new Path(outputDir), true);
}

protected FileEntryGraph ExtractFilesFromMsi(string msiFileName, string[] fileNamesToExtractOrNull, Path outputDir, bool returnFileEntryGraph)
{
return ExtractFilesFromMsi(msiFileName, fileNamesToExtractOrNull, outputDir, true, true);
}

/// <summary>
/// Extracts some or all of the files from the specified MSI and returns a <see cref="FileEntryGraph"/> representing the files that were extracted.
/// </summary>
/// <param name="msiFileName">The msi file to extract or null to extract all files.</param>
/// <param name="fileNamesToExtractOrNull">The files to extract from the MSI or null to extract all files.</param>
/// <param name="outputDir">A relative directory to extract output to or an empty string to use the default output directory.</param>
/// <param name="skipReturningFileEntryGraph">True to return the <see cref="FileEntryGraph"/>. Otherwise null will be returned.</param>
protected FileEntryGraph ExtractFilesFromMsi(string msiFileName, string[] fileNamesToExtractOrNull, Path outputDir, bool returnFileEntryGraph)
/// <param name="cleanOutputDirectoryBeforeExtracting">True to delete the output directory before extracting.</param>
protected FileEntryGraph ExtractFilesFromMsi(string msiFileName, string[] fileNamesToExtractOrNull, Path outputDir, bool returnFileEntryGraph, bool cleanOutputDirectoryBeforeExtracting)
{
outputDir = GetTestOutputDir(outputDir, msiFileName);

if (FileSystem.Exists(outputDir))
if (cleanOutputDirectoryBeforeExtracting && FileSystem.Exists(outputDir))
{
FileSystem.RemoveDirectory(outputDir, true);
}
Expand Down Expand Up @@ -210,7 +216,7 @@ protected FileEntryGraph GetExpectedEntriesForMsi(string forMsi)
return FileEntryGraph.Load(GetExpectedOutputFile(forMsi), forMsi);
}

private Path GetMsiTestFile(string msiFileName)
protected Path GetMsiTestFile(string msiFileName)
{
return Path.Combine(AppPath, "TestFiles", "MsiInput", msiFileName);
}
Expand Down
Loading

0 comments on commit 7c8618d

Please sign in to comment.