|
| 1 | +/// <summary> |
| 2 | +/// Which pending moves the "Accept all open" hot key sweeps. |
| 3 | +/// <para> |
| 4 | +/// The rule is "a window is showing this pair", and for every tool but one that is a live process |
| 5 | +/// DiffRunner started for it. The viewer is the exception: it draws every pending pair as a row in |
| 6 | +/// one shared window, so no process id is ever sent for one and none may be killed. Testing the |
| 7 | +/// process alone therefore left exactly the pairs that were on screen out of the sweep, and the |
| 8 | +/// hot key looked dead to anyone whose diff tool is the viewer. |
| 9 | +/// </para> |
| 10 | +/// </summary> |
| 11 | +public class TrackerAcceptOpenTest : |
| 12 | + IDisposable |
| 13 | +{ |
| 14 | + [Test] |
| 15 | + public async Task AViewerPairIsOpenEvenWithNoProcess() |
| 16 | + { |
| 17 | + await using var tracker = new RecordingTracker(inline: new StubInlineHost()); |
| 18 | + tracker.AddMove(temp, target, viewerExe, "--diff", false, null); |
| 19 | + |
| 20 | + await tracker.AcceptOpen(); |
| 21 | + |
| 22 | + await tracker.AssertEmpty(); |
| 23 | + await Assert.That(File.Exists(temp)).IsFalse(); |
| 24 | + await Assert.That(File.ReadAllText(target)).IsEqualTo("received"); |
| 25 | + } |
| 26 | + |
| 27 | + /// <summary> |
| 28 | + /// The other half of the rule, so the fix for the viewer does not quietly turn "accept all |
| 29 | + /// open" into "accept all": a pair whose own window has gone is still not open. |
| 30 | + /// </summary> |
| 31 | + [Test] |
| 32 | + public async Task AnotherToolWithNoProcessIsNotOpen() |
| 33 | + { |
| 34 | + await using var tracker = new RecordingTracker(inline: new StubInlineHost()); |
| 35 | + tracker.AddMove(temp, target, "theExe", "theArguments", true, null); |
| 36 | + |
| 37 | + await tracker.AcceptOpen(); |
| 38 | + |
| 39 | + await Assert.That(tracker.Moves).HasSingleItem(); |
| 40 | + } |
| 41 | + |
| 42 | + [Test] |
| 43 | + public async Task TheViewerIsRecognisedByNameRatherThanByPath() |
| 44 | + { |
| 45 | + // The sender resolved the copy bundled in its own DiffEngine package, so the path is one |
| 46 | + // this process has never seen and the tool lookup finds nothing for it. |
| 47 | + await Assert.That(PendingFiles.IsViewerExe(viewerExe)).IsTrue(); |
| 48 | + await Assert.That(PendingFiles.IsViewerExe("theExe")).IsFalse(); |
| 49 | + await Assert.That(PendingFiles.IsViewerExe(null)).IsFalse(); |
| 50 | + } |
| 51 | + |
| 52 | + static readonly string viewerExe = Path.Combine( |
| 53 | + Path.GetTempPath(), |
| 54 | + "some-other-package", |
| 55 | + "viewer", |
| 56 | + OperatingSystem.IsWindows() ? "DiffEngineViewer.exe" : "DiffEngineViewer"); |
| 57 | + |
| 58 | + readonly string directory = Path.Combine(Path.GetTempPath(), $"AcceptOpen {Guid.NewGuid():N}"); |
| 59 | + readonly string temp; |
| 60 | + readonly string target; |
| 61 | + |
| 62 | + public TrackerAcceptOpenTest() |
| 63 | + { |
| 64 | + Directory.CreateDirectory(directory); |
| 65 | + temp = Path.Combine(directory, "Sample.Test.received.txt"); |
| 66 | + target = Path.Combine(directory, "Sample.Test.verified.txt"); |
| 67 | + File.WriteAllText(temp, "received"); |
| 68 | + File.WriteAllText(target, "verified"); |
| 69 | + } |
| 70 | + |
| 71 | + public void Dispose() => |
| 72 | + Directory.Delete(directory, true); |
| 73 | +} |
0 commit comments