Skip to content

Commit

Permalink
Add sync API (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp authored Sep 20, 2020
1 parent fc59eaf commit 8b9b69e
Show file tree
Hide file tree
Showing 15 changed files with 453 additions and 135 deletions.
6 changes: 3 additions & 3 deletions docs/diff-tool.custom.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ New tools are added to the top of the order, the last tool added will resolve be
<!-- snippet: DiffRunnerLaunch -->
<a id='snippet-diffrunnerlaunch'></a>
```cs
await DiffRunner.Launch(tempFile, targetFile);
await DiffRunner.LaunchAsync(tempFile, targetFile);
```
<sup><a href='/src/DiffEngine.Tests/DiffRunnerTests.cs#L46-L50' title='File snippet `diffrunnerlaunch` was extracted from'>snippet source</a> | <a href='#snippet-diffrunnerlaunch' title='Navigate to start of snippet `diffrunnerlaunch`'>anchor</a></sup>
<sup><a href='/src/DiffEngine.Tests/DiffRunnerTests.cs#L71-L75' title='File snippet `diffrunnerlaunch` was extracted from'>snippet source</a> | <a href='#snippet-diffrunnerlaunch' title='Navigate to start of snippet `diffrunnerlaunch`'>anchor</a></sup>
<!-- endSnippet -->

Alternatively the instance returned from `AddTool*` can be used to explicitly launch that tool.
Expand All @@ -61,7 +61,7 @@ var resolvedTool = DiffTools.AddToolBasedOn(
name: "MyCustomDiffTool",
arguments: (temp, target) => $"\"custom args {temp}\" \"{target}\"");

await DiffRunner.Launch(resolvedTool!, "PathToTempFile", "PathToTargetFile");
await DiffRunner.LaunchAsync(resolvedTool!, "PathToTempFile", "PathToTargetFile");
```
<sup><a href='/src/DiffEngine.Tests/DiffToolsTest.cs#L77-L84' title='File snippet `addtoolandlaunch` was extracted from'>snippet source</a> | <a href='#snippet-addtoolandlaunch' title='Navigate to start of snippet `addtoolandlaunch`'>anchor</a></sup>
<!-- endSnippet -->
Expand Down
6 changes: 3 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ A tool can be launched using the following:
<!-- snippet: DiffRunnerLaunch -->
<a id='snippet-diffrunnerlaunch'></a>
```cs
await DiffRunner.Launch(tempFile, targetFile);
await DiffRunner.LaunchAsync(tempFile, targetFile);
```
<sup><a href='/src/DiffEngine.Tests/DiffRunnerTests.cs#L46-L50' title='File snippet `diffrunnerlaunch` was extracted from'>snippet source</a> | <a href='#snippet-diffrunnerlaunch' title='Navigate to start of snippet `diffrunnerlaunch`'>anchor</a></sup>
<sup><a href='/src/DiffEngine.Tests/DiffRunnerTests.cs#L71-L75' title='File snippet `diffrunnerlaunch` was extracted from'>snippet source</a> | <a href='#snippet-diffrunnerlaunch' title='Navigate to start of snippet `diffrunnerlaunch`'>anchor</a></sup>
<!-- endSnippet -->

Note that this method will respect the above [difference behavior](/docs/diff-tool.md#detected-difference-behavior) in terms of Auto refresh and MDI behaviors.
Expand All @@ -99,7 +99,7 @@ A tool can be closed using the following:
```cs
DiffRunner.Kill(file1, file2);
```
<sup><a href='/src/DiffEngine.Tests/DiffRunnerTests.cs#L58-L60' title='File snippet `diffrunnerkill` was extracted from'>snippet source</a> | <a href='#snippet-diffrunnerkill' title='Navigate to start of snippet `diffrunnerkill`'>anchor</a></sup>
<sup><a href='/src/DiffEngine.Tests/DiffRunnerTests.cs#L84-L88' title='File snippet `diffrunnerkill` was extracted from'>snippet source</a> | <a href='#snippet-diffrunnerkill' title='Navigate to start of snippet `diffrunnerkill`'>anchor</a></sup>
<!-- endSnippet -->

Note that this method will respect the above [difference behavior](/docs/diff-tool.md#detected-difference-behavior) in terms of MDI behavior.
Expand Down
90 changes: 81 additions & 9 deletions src/DiffEngine.Tests/DiffRunnerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class DiffRunnerTests :
string file2;
string file1;
string command;

[Fact(Skip = "Explicit")]
public async Task MaxInstancesToLaunch()
{
Expand All @@ -22,11 +23,35 @@ public async Task MaxInstancesToLaunch()
{
await Task.Delay(500);
ProcessCleanup.Refresh();
var result = await DiffRunner.Launch(file1, "fake.txt");
var result = DiffRunner.Launch(file1, "fake.txt");
await Task.Delay(300);
Assert.Equal(LaunchResult.StartedNewInstance, result);
ProcessCleanup.Refresh();
result = await DiffRunner.Launch(file2, "fake.txt");
result = DiffRunner.Launch(file2, "fake.txt");
Assert.Equal(LaunchResult.TooManyRunningDiffTools, result);
ProcessCleanup.Refresh();
DiffRunner.Kill(file1, "fake.txt");
DiffRunner.Kill(file2, "fake.txt");
}
finally
{
DiffRunner.MaxInstancesToLaunch(5);
}
}

[Fact(Skip = "Explicit")]
public async Task MaxInstancesToLaunchAsync()
{
DiffRunner.MaxInstancesToLaunch(1);
try
{
await Task.Delay(500);
ProcessCleanup.Refresh();
var result = await DiffRunner.LaunchAsync(file1, "fake.txt");
await Task.Delay(300);
Assert.Equal(LaunchResult.StartedNewInstance, result);
ProcessCleanup.Refresh();
result = await DiffRunner.LaunchAsync(file2, "fake.txt");
Assert.Equal(LaunchResult.TooManyRunningDiffTools, result);
ProcessCleanup.Refresh();
DiffRunner.Kill(file1, "fake.txt");
Expand All @@ -45,30 +70,33 @@ async Task Launch()

#region DiffRunnerLaunch

await DiffRunner.Launch(tempFile, targetFile);
await DiffRunner.LaunchAsync(tempFile, targetFile);

#endregion
}

[Fact(Skip = "Explicit")]
public async Task Kill()
public async Task KillAsync()
{
await DiffRunner.Launch(file1, file2);
await DiffRunner.LaunchAsync(file1, file2);
ProcessCleanup.Refresh();

#region DiffRunnerKill

DiffRunner.Kill(file1, file2);

#endregion
}

[Fact]
public async Task LaunchAndKillDisabled()
public void LaunchAndKillDisabled()
{
DiffRunner.Disabled = true;
try
{
Assert.False(IsRunning());
Assert.False(ProcessCleanup.IsRunning(command));
var result = await DiffRunner.Launch(file1, file2);
var result = DiffRunner.Launch(file1, file2);
Assert.Equal(LaunchResult.Disabled, result);
Thread.Sleep(500);
ProcessCleanup.Refresh();
Expand All @@ -87,11 +115,55 @@ public async Task LaunchAndKillDisabled()
}

[Fact]
public async Task LaunchAndKill()
public async Task LaunchAndKillDisabledAsync()
{
DiffRunner.Disabled = true;
try
{
Assert.False(IsRunning());
Assert.False(ProcessCleanup.IsRunning(command));
var result = await DiffRunner.LaunchAsync(file1, file2);
Assert.Equal(LaunchResult.Disabled, result);
Thread.Sleep(500);
ProcessCleanup.Refresh();
Assert.False(IsRunning());
Assert.False(ProcessCleanup.IsRunning(command));
DiffRunner.Kill(file1, file2);
Thread.Sleep(500);
ProcessCleanup.Refresh();
Assert.False(IsRunning());
Assert.False(ProcessCleanup.IsRunning(command));
}
finally
{
DiffRunner.Disabled = false;
}
}

[Fact]
public void LaunchAndKill()
{
Assert.False(IsRunning());
Assert.False(ProcessCleanup.IsRunning(command));
var result = DiffRunner.Launch(file1, file2);
Assert.Equal(LaunchResult.StartedNewInstance, result);
Thread.Sleep(500);
ProcessCleanup.Refresh();
Assert.True(IsRunning());
Assert.True(ProcessCleanup.IsRunning(command));
DiffRunner.Kill(file1, file2);
Thread.Sleep(500);
ProcessCleanup.Refresh();
Assert.False(IsRunning());
Assert.False(ProcessCleanup.IsRunning(command));
}

[Fact]
public async Task LaunchAndKillAsync()
{
Assert.False(IsRunning());
Assert.False(ProcessCleanup.IsRunning(command));
var result = await DiffRunner.Launch(file1, file2);
var result = await DiffRunner.LaunchAsync(file1, file2);
Assert.Equal(LaunchResult.StartedNewInstance, result);
Thread.Sleep(500);
ProcessCleanup.Refresh();
Expand Down
6 changes: 3 additions & 3 deletions src/DiffEngine.Tests/DiffToolsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void MaxInstancesToLaunch()
[Fact]
public void AddTool()
{
string diffToolPath = FakeDiffTool.Exe;
var diffToolPath = FakeDiffTool.Exe;
#region AddTool
var resolvedTool = DiffTools.AddTool(
name: "MyCustomDiffTool",
Expand All @@ -40,7 +40,7 @@ public void AddTool()
[Fact]
public void OrderShouldNotMessWithAddTool()
{
string diffToolPath = FakeDiffTool.Exe;
var diffToolPath = FakeDiffTool.Exe;
var resolvedTool = DiffTools.AddTool(
name: "MyCustomDiffTool",
autoRefresh: true,
Expand Down Expand Up @@ -80,7 +80,7 @@ async Task AddToolAndLaunch()
name: "MyCustomDiffTool",
arguments: (temp, target) => $"\"custom args {temp}\" \"{target}\"");

await DiffRunner.Launch(resolvedTool!, "PathToTempFile", "PathToTargetFile");
await DiffRunner.LaunchAsync(resolvedTool!, "PathToTempFile", "PathToTargetFile");
#endregion
}

Expand Down
Loading

0 comments on commit 8b9b69e

Please # to comment.