Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Jul 12, 2021
1 parent 09bd145 commit 4604aa7
Show file tree
Hide file tree
Showing 19 changed files with 58 additions and 58 deletions.
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
14 changes: 7 additions & 7 deletions src/DiffEngineTray.Tests/AsyncTimerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class AsyncTimerTests
[Fact]
public async Task It_calls_error_callback()
{
TaskCompletionSource<bool> errorCallbackInvoked = new();
var errorCallbackInvoked = new TaskCompletionSource<bool>();

AsyncTimer timer = new(
callback: (_, _) => throw new("Simulated!"),
Expand All @@ -20,7 +20,7 @@ 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;
Expand All @@ -47,7 +47,7 @@ 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();
var delayStarted = new TaskCompletionSource<bool>();
AsyncTimer timer = new(
callback: (_, _) => throw new("Simulated!"),
interval: TimeSpan.FromDays(7),
Expand All @@ -74,8 +74,8 @@ 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();
var callbackStarted = new TaskCompletionSource<bool>();
var stopInitiated = new TaskCompletionSource<bool>();
AsyncTimer timer = new(
callback: async (_, token) =>
{
Expand All @@ -98,8 +98,8 @@ 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();
var callbackCompleted = new TaskCompletionSource<bool>();
var callbackTaskStarted = new TaskCompletionSource<bool>();
AsyncTimer timer = new(
callback: (_, _) =>
{
Expand Down
2 changes: 1 addition & 1 deletion 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 Down
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
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
16 changes: 8 additions & 8 deletions src/DiffEngineTray.Tests/TrackerMoveTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class TrackerMoveTest :
[Fact]
public async Task AddSingle()
{
await using RecordingTracker tracker = new();
await using var tracker = new RecordingTracker();
tracker.AddMove(file1, file1, "theExe", "theArguments", true, null);
Assert.Equal(1, tracker.Moves.Count);
Assert.True(tracker.TrackingAny);
Expand All @@ -20,7 +20,7 @@ public async Task AddSingle()
[Fact]
public async Task AddMultiple()
{
await using RecordingTracker tracker = new();
await using var tracker = new RecordingTracker();
tracker.AddMove(file1, file1, "theExe", "theArguments", true, null);
tracker.AddMove(file2, file2, "theExe", "theArguments", true, null);
Assert.Equal(2, tracker.Moves.Count);
Expand All @@ -30,7 +30,7 @@ public async Task AddMultiple()
[Fact]
public async Task AddSame()
{
await using RecordingTracker tracker = new();
await using var tracker = new RecordingTracker();
tracker.AddMove(file1, file1, "theExe", "theArguments", true, null);
using var process = Process.GetCurrentProcess();
var processId = process.Id;
Expand All @@ -43,7 +43,7 @@ public async Task AddSame()
[Fact]
public async Task AcceptAllSingle()
{
await using RecordingTracker tracker = new();
await using var tracker = new RecordingTracker();
tracker.AddMove(file1, file1, "theExe", "theArguments", true, null);
tracker.AcceptAll();
tracker.AssertEmpty();
Expand All @@ -52,7 +52,7 @@ public async Task AcceptAllSingle()
[Fact]
public async Task AcceptAllMultiple()
{
await using RecordingTracker tracker = new();
await using var tracker = new RecordingTracker();
tracker.AddMove(file1, file1, "theExe", "theArguments", true, null);
tracker.AddMove(file2, file2, "theExe", "theArguments", true, null);
tracker.AcceptAll();
Expand All @@ -62,7 +62,7 @@ public async Task AcceptAllMultiple()
[Fact]
public async Task AcceptSingle()
{
await using RecordingTracker tracker = new();
await using var tracker = new RecordingTracker();
var tracked = tracker.AddMove(file1, file1, "theExe", "theArguments", true, null);
tracker.Accept(tracked);
tracker.AssertEmpty();
Expand All @@ -71,7 +71,7 @@ public async Task AcceptSingle()
[Fact]
public async Task AddSingle_BackgroundDelete()
{
await using RecordingTracker tracker = new();
await using var tracker = new RecordingTracker();
tracker.AddMove(file1, file1, "theExe", "theArguments", true, null);
File.Delete(file1);
Thread.Sleep(3000);
Expand All @@ -81,7 +81,7 @@ public async Task AddSingle_BackgroundDelete()
[Fact]
public async Task AcceptSingle_NotEmpty()
{
await using RecordingTracker tracker = new();
await using var tracker = new RecordingTracker();
var tracked = tracker.AddMove(file1, file1, "theExe", "theArguments", true, null);
tracker.AddMove(file2, file2, "theExe", "theArguments", true, null);
tracker.Accept(tracked);
Expand Down
2 changes: 1 addition & 1 deletion src/DiffEngineTray/DirectoryLauncher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static void OpenDirectory(string directory)

public static void ShowFileInExplorer(string file)
{
ProcessStartInfo info = new()
var info = new ProcessStartInfo
{
FileName = "explorer.exe",
Arguments = $"/select, \"{file}\"",
Expand Down
Loading

0 comments on commit 4604aa7

Please sign in to comment.