Skip to content

Commit

Permalink
Fix unit test broken by LfMergeBridge's new logic
Browse files Browse the repository at this point in the history
LfMergeBridge has become smarter about finding the location of FixFwData
so the test that checks what happens if it's missing now has to work a
lot harder to hide it. It used to be enough to simply change the current
working directory, but now we have to actually hide the FixFwData file
AND the FixFwData.exe file by renaming them temporarily.
  • Loading branch information
rmunn committed Nov 9, 2024
1 parent 93416ec commit c1fbce9
Showing 1 changed file with 31 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,37 @@ public void Teardown()
[Test]
public void MissingFwDataFixer_Throws()
{
// Setup
var tmpFolder = Path.Combine(_languageDepotFolder.Path, "WorkDir");
Directory.CreateDirectory(tmpFolder);
Directory.SetCurrentDirectory(tmpFolder);

// Execute/Verify
Assert.That(() => _synchronizeAction.Run(_lfProject),
// This can't happen in real life because we ensure that we have a clone
// before we call sync. Therefore it is acceptable to get an exception.
Throws.TypeOf<InvalidOperationException>());
// This used to just change the current directory, which was enough when LfMergeBridge only
// looked for FixFwData in the current directory. However, LfMergeBridge is now smart enough
// to look for FixFwData in the folder where LfMergeBridge.dll is being run from, which finds
// it no matter the current working directory. So we need to move it out of the way, and ensure
// that it gets moved back at the end of the test so other tests don't start failing.

string fixFwDataPath = null;
string fixFwDataExePath = null;
try {
// Setup
var assembly = typeof(LfMergeBridge.LfMergeBridge).Assembly;
var dir = Directory.GetParent(assembly.Location).FullName;
if (File.Exists(Path.Join(dir, "FixFwData"))) {
fixFwDataPath = Path.Join(dir, "FixFwData");
File.Move(fixFwDataPath, fixFwDataPath + ".renamed");
}
if (File.Exists(Path.Join(dir, "FixFwData.exe"))) {
fixFwDataExePath = Path.Join(dir, "FixFwData.exe");
File.Move(fixFwDataExePath, fixFwDataExePath + ".renamed");
}

// Execute/Verify
Assert.That(() => _synchronizeAction.Run(_lfProject),
// This can't happen in real life because we ensure that we have a clone
// before we call sync. Therefore it is acceptable to get an exception.
Throws.TypeOf<InvalidOperationException>());

} finally {
if (fixFwDataPath != null) File.Move(fixFwDataPath + ".renamed", fixFwDataPath);
if (fixFwDataExePath != null) File.Move(fixFwDataExePath + ".renamed", fixFwDataExePath);
}
}

[Test]
Expand Down

0 comments on commit c1fbce9

Please sign in to comment.