Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Jul 12, 2021
2 parents 4c31ff8 + a9bede2 commit 8704a6b
Show file tree
Hide file tree
Showing 35 changed files with 87 additions and 88 deletions.
2 changes: 1 addition & 1 deletion src/DiffEngine.Tests/DefinitionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static void AddToolLink(StreamWriter writer, Definition tool)

static string GetOsSupport(Definition tool)
{
StringBuilder builder = new();
var builder = new StringBuilder();
if (tool.Windows != null)
{
builder.Append("Win/");
Expand Down
3 changes: 1 addition & 2 deletions src/DiffEngine.Tests/LinuxOsxProcessTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
public class LinuxOsxProcessTests :
XunitContextBase
{

[Fact]
public void TryParseWithZshInstalled()
{
Expand All @@ -14,7 +13,7 @@ public void TryParseWithZshInstalled()
Assert.Equal(20872, processCommand.Process);
Assert.Equal("-zsh", processCommand.Command);
}

[Fact]
public void TryParse()
{
Expand Down
8 changes: 4 additions & 4 deletions src/DiffEngine/DiffRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,12 @@ static bool TryCreate(ResolvedTool tool, string targetFile)

static int LaunchProcess(ResolvedTool tool, string arguments)
{
var startInfo = new ProcessStartInfo(tool.ExePath, arguments)
{
UseShellExecute = true
};
try
{
ProcessStartInfo startInfo = new(tool.ExePath, arguments)
{
UseShellExecute = true
};
using var process = Process.Start(startInfo);
if (process != null)
{
Expand Down
2 changes: 1 addition & 1 deletion src/DiffEngine/DiffTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public static class DiffTools
return null;
}

ResolvedTool resolvedTool = new(
var resolvedTool = new ResolvedTool(
name,
diffTool,
resolvedExePath,
Expand Down
10 changes: 5 additions & 5 deletions src/DiffEngine/Process/LinuxOsxProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ static class LinuxOsxProcess
//https://www.man7.org/linux/man-pages/man1/ps.1.html
public static bool TryTerminateProcess(int processId)
{
using Process process = new()
using var process = new Process
{
StartInfo = new()
{
Expand All @@ -34,7 +34,7 @@ public static bool TryTerminateProcess(int processId)
public static IEnumerable<ProcessCommand> FindAll()
{
var processList = RunPs();
using StringReader reader = new(processList);
using var reader = new StringReader(processList);
string? line;
reader.ReadLine();
while ((line = reader.ReadLine()) != null)
Expand Down Expand Up @@ -88,10 +88,10 @@ public static bool TryParse(string line, out ProcessCommand? processCommand)

static string RunPs()
{
StringBuilder errorBuilder = new();
StringBuilder outputBuilder = new();
var errorBuilder = new StringBuilder();
var outputBuilder = new StringBuilder();
const string? arguments = "-o pid,command -x";
using Process process = new()
using var process = new Process
{
StartInfo = new()
{
Expand Down
2 changes: 1 addition & 1 deletion src/DiffEngine/Process/WindowsProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static IEnumerable<ProcessCommand> FindAll()
select CommandLine, ProcessId
from Win32_Process
where CommandLine like '% %.%.%'";
using ManagementObjectSearcher searcher = new(wmiQuery);
using var searcher = new ManagementObjectSearcher(wmiQuery);
using var collection = searcher.Get();
foreach (var process in collection)
{
Expand Down
4 changes: 2 additions & 2 deletions src/DiffEngine/WildcardFileFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ static IEnumerable<string> EnumerateDirectories(string directory)
}

var segments = expanded.Split(separators);
List<string> currentRoots = new()
var currentRoots = new List<string>
{
segments[0] + Path.DirectorySeparatorChar
};
foreach (var segment in segments.Skip(1))
{
List<string> newRoots = new();
var newRoots = new List<string>();
foreach (var root in currentRoots)
{
if (segment.Contains('*'))
Expand Down
24 changes: 12 additions & 12 deletions src/DiffEngineTray.Tests/AsyncTimerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ public class AsyncTimerTests
[Fact]
public async Task It_calls_error_callback()
{
TaskCompletionSource<bool> errorCallbackInvoked = new();
var errorCallbackInvoked = new TaskCompletionSource<bool>();

AsyncTimer timer = new(
var timer = new AsyncTimer(
callback: (_, _) => throw new("Simulated!"),
interval: TimeSpan.Zero,
errorCallback: _ => { errorCallbackInvoked.SetResult(true); });
Expand All @@ -20,11 +20,11 @@ public async Task It_calls_error_callback()
[Fact]
public async Task It_continues_to_run_after_an_error()
{
TaskCompletionSource<bool> callbackInvokedAfterError = new();
var callbackInvokedAfterError = new TaskCompletionSource<bool>();

var fail = true;
var exceptionThrown = false;
AsyncTimer timer = new(
var timer = new AsyncTimer(
callback: (_, _) =>
{
if (fail)
Expand All @@ -47,8 +47,8 @@ public async Task It_continues_to_run_after_an_error()
public async Task Stop_cancels_token_while_waiting()
{
var waitCanceled = false;
TaskCompletionSource<bool> delayStarted = new();
AsyncTimer timer = new(
var delayStarted = new TaskCompletionSource<bool>();
var timer = new AsyncTimer(
callback: (_, _) => throw new("Simulated!"),
interval: TimeSpan.FromDays(7),
delayStrategy: async (delayTime, token) =>
Expand All @@ -74,9 +74,9 @@ public async Task Stop_cancels_token_while_waiting()
public async Task Stop_cancels_token_while_in_callback()
{
var callbackCanceled = false;
TaskCompletionSource<bool> callbackStarted = new();
TaskCompletionSource<bool> stopInitiated = new();
AsyncTimer timer = new(
var callbackStarted = new TaskCompletionSource<bool>();
var stopInitiated = new TaskCompletionSource<bool>();
var timer = new AsyncTimer(
callback: async (_, token) =>
{
callbackStarted.SetResult(true);
Expand All @@ -98,9 +98,9 @@ public async Task Stop_cancels_token_while_in_callback()
[Fact]
public async Task Stop_waits_for_callback_to_complete()
{
TaskCompletionSource<bool> callbackCompleted = new();
TaskCompletionSource<bool> callbackTaskStarted = new();
AsyncTimer timer = new(
var callbackCompleted = new TaskCompletionSource<bool>();
var callbackTaskStarted = new TaskCompletionSource<bool>();
var timer = new AsyncTimer(
callback: (_, _) =>
{
callbackTaskStarted.SetResult(true);
Expand Down
4 changes: 2 additions & 2 deletions src/DiffEngineTray.Tests/HotKeyControlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public HotKeyControlTests(ITestOutputHelper output) :
[Fact]
public async Task WithKeys()
{
using HotKeyControl target = new()
using var target = new HotKeyControl
{
HotKey = new()
{
Expand All @@ -30,7 +30,7 @@ public async Task WithKeys()
[Fact]
public async Task Default()
{
using HotKeyControl target = new();
using var target = new HotKeyControl();
await Verifier.Verify(target);
}
}
Expand Down
Binary file modified src/DiffEngineTray.Tests/MenuBuilderTest.Full.verified.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/DiffEngineTray.Tests/MenuBuilderTest.FullGrouped.verified.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/DiffEngineTray.Tests/MenuBuilderTest.Grouped.verified.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/DiffEngineTray.Tests/MenuBuilderTest.Many.verified.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/DiffEngineTray.Tests/MenuBuilderTest.OnlyDelete.verified.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/DiffEngineTray.Tests/MenuBuilderTest.OnlyMove.verified.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 7 additions & 7 deletions src/DiffEngineTray.Tests/MenuBuilderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ public class MenuBuilderTest :
[Fact]
public async Task Empty()
{
await using RecordingTracker tracker = new();
await using var tracker = new RecordingTracker();
var menu = MenuBuilder.Build(() => { }, () => { }, tracker);
await Verifier.Verify(menu, settings);
}

[Fact]
public async Task OnlyMove()
{
await using RecordingTracker tracker = new();
await using var tracker = new RecordingTracker();
tracker.AddMove(file2, file2, "theExe", "theArguments", true, null);
var menu = MenuBuilder.Build(() => { }, () => { }, tracker);
await Verifier.Verify(menu, settings);
Expand All @@ -29,7 +29,7 @@ public async Task OnlyMove()
[Fact]
public async Task OnlyDelete()
{
await using RecordingTracker tracker = new();
await using var tracker = new RecordingTracker();
tracker.AddDelete(file1);
var menu = MenuBuilder.Build(() => { }, () => { }, tracker);
await Verifier.Verify(menu, settings);
Expand All @@ -38,7 +38,7 @@ public async Task OnlyDelete()
[Fact]
public async Task Full()
{
await using RecordingTracker tracker = new();
await using var tracker = new RecordingTracker();
tracker.AddDelete(file1);
tracker.AddDelete(file2);
tracker.AddMove(file3, file3, "theExe", "theArguments", true, null);
Expand All @@ -50,7 +50,7 @@ public async Task Full()
[Fact]
public async Task Many()
{
await using RecordingTracker tracker = new();
await using var tracker = new RecordingTracker();
foreach (var file in EmptyFiles.AllFiles.AllPaths)
{
tracker.AddDelete(file);
Expand All @@ -63,7 +63,7 @@ public async Task Many()
[Fact]
public async Task Grouped()
{
await using RecordingTracker tracker = new();
await using var tracker = new RecordingTracker();
tracker.AddDelete("file2.txt");
tracker.AddMove(file4, "file4.txt", "theExe", "theArguments", true, null);
var menu = MenuBuilder.Build(() => { }, () => { }, tracker);
Expand All @@ -73,7 +73,7 @@ public async Task Grouped()
[Fact]
public async Task FullGrouped()
{
await using RecordingTracker tracker = new();
await using var tracker = new RecordingTracker();
tracker.AddDelete(file1);
tracker.AddDelete("file2.txt");
tracker.AddMove(file3, file3, "theExe", "theArguments", true, null);
Expand Down
4 changes: 2 additions & 2 deletions src/DiffEngineTray.Tests/OptionsFormTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public OptionsFormTests(ITestOutputHelper output) :
[Fact]
public async Task WithKeys()
{
using OptionsForm form = new(
using var form = new OptionsForm(
new()
{
AcceptAllHotKey = new()
Expand All @@ -51,7 +51,7 @@ public async Task WithKeys()
[Fact]
public async Task Default()
{
using OptionsForm form = new(
using var form = new OptionsForm(
new(),
_ => Task.FromResult<IReadOnlyList<string>>(new List<string>()));
await Verifier.Verify(form);
Expand Down
6 changes: 3 additions & 3 deletions src/DiffEngineTray.Tests/PiperTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class PiperTest :
public async Task Delete()
{
DeletePayload received = null!;
CancellationTokenSource source = new();
var source = new CancellationTokenSource();
var task = PiperServer.Start(_ => { }, s => received = s, source.Token);
await PiperClient.SendDeleteAsync("Foo", source.Token);
await Task.Delay(1000);
Expand All @@ -28,7 +28,7 @@ public async Task Delete()
public async Task Move()
{
MovePayload received = null!;
CancellationTokenSource source = new();
var source = new CancellationTokenSource();
var task = PiperServer.Start(s => received = s, _ => { }, source.Token);
await PiperClient.SendMoveAsync("Foo", "Bar", "theExe", "TheArguments \"s\"", true, 10, source.Token);
await Task.Delay(1000);
Expand All @@ -53,7 +53,7 @@ public async Task SendOnly()
{
}

VerifySettings settings = new();
var settings = new VerifySettings();
settings.ScrubLinesContaining("temp.txt");
//TODO: add "scrub source dir" to verify and remove the below
settings.ScrubLinesContaining("PiperClient");
Expand Down
2 changes: 1 addition & 1 deletion src/DiffEngineTray.Tests/TrackerClearTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class TrackerClearTest :
[Fact]
public async Task Simple()
{
await using RecordingTracker tracker = new();
await using var tracker = new RecordingTracker();
tracker.AddDelete(file1);
tracker.AddMove(file2, file2, "theExe", "theArguments", true, null);
tracker.Clear();
Expand Down
16 changes: 8 additions & 8 deletions src/DiffEngineTray.Tests/TrackerDeleteTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class TrackerDeleteTest :
[Fact]
public async Task AddSingle()
{
await using RecordingTracker tracker = new();
await using var tracker = new RecordingTracker();
tracker.AddDelete(file1);
Assert.Equal(1, tracker.Deletes.Count);
Assert.True(tracker.TrackingAny);
Expand All @@ -19,7 +19,7 @@ public async Task AddSingle()
[Fact]
public async Task AddSingle_BackgroundDelete()
{
await using RecordingTracker tracker = new();
await using var tracker = new RecordingTracker();
tracker.AddDelete(file1);
File.Delete(file1);
Thread.Sleep(3000);
Expand All @@ -29,7 +29,7 @@ public async Task AddSingle_BackgroundDelete()
[Fact]
public async Task AddMultiple()
{
await using RecordingTracker tracker = new();
await using var tracker = new RecordingTracker();
tracker.AddDelete(file1);
tracker.AddDelete(file2);
Assert.Equal(2, tracker.Deletes.Count);
Expand All @@ -39,7 +39,7 @@ public async Task AddMultiple()
[Fact]
public async Task AddSame()
{
await using RecordingTracker tracker = new();
await using var tracker = new RecordingTracker();
tracker.AddDelete(file1);
tracker.AddDelete(file1);
Assert.Equal(1, tracker.Deletes.Count);
Expand All @@ -49,7 +49,7 @@ public async Task AddSame()
[Fact]
public async Task AcceptAllSingle()
{
await using RecordingTracker tracker = new();
await using var tracker = new RecordingTracker();
tracker.AddDelete(file1);
tracker.AcceptAll();
tracker.AssertEmpty();
Expand All @@ -58,7 +58,7 @@ public async Task AcceptAllSingle()
[Fact]
public async Task AcceptAllMultiple()
{
await using RecordingTracker tracker = new();
await using var tracker = new RecordingTracker();
tracker.AddDelete(file1);
tracker.AddDelete(file2);
tracker.AcceptAll();
Expand All @@ -68,7 +68,7 @@ public async Task AcceptAllMultiple()
[Fact]
public async Task AcceptSingle()
{
await using RecordingTracker tracker = new();
await using var tracker = new RecordingTracker();
var tracked = tracker.AddDelete(file1);
tracker.Accept(tracked);
tracker.AssertEmpty();
Expand All @@ -77,7 +77,7 @@ public async Task AcceptSingle()
[Fact]
public async Task AcceptSingle_NotEmpty()
{
await using RecordingTracker tracker = new();
await using var tracker = new RecordingTracker();
var tracked = tracker.AddDelete(file1);
tracker.AddDelete(file2);
tracker.Accept(tracked);
Expand Down
Loading

0 comments on commit 8704a6b

Please sign in to comment.