Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nunit #520

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Nunit #520

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/diff-tool.custom.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var resolvedTool = DiffTools.AddTool(
exePath: diffToolPath,
binaryExtensions: [".jpg"])!;
```
<sup><a href='/src/DiffEngine.Tests/DiffToolsTest.cs#L15-L29' title='Snippet source file'>snippet source</a> | <a href='#snippet-AddTool' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/DiffEngine.Tests/DiffToolsTest.cs#L16-L30' title='Snippet source file'>snippet source</a> | <a href='#snippet-AddTool' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Add a tool based on existing resolved tool:
Expand All @@ -39,7 +39,7 @@ var resolvedTool = DiffTools.AddToolBasedOn(
Left: (temp, target) => $"\"custom args \"{target}\" \"{temp}\"",
Right: (temp, target) => $"\"custom args \"{temp}\" \"{target}\""))!;
```
<sup><a href='/src/DiffEngine.Tests/DiffToolsTest.cs#L62-L71' title='Snippet source file'>snippet source</a> | <a href='#snippet-AddToolBasedOn' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/DiffEngine.Tests/DiffToolsTest.cs#L65-L74' title='Snippet source file'>snippet source</a> | <a href='#snippet-AddToolBasedOn' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


Expand All @@ -52,7 +52,7 @@ New tools are added to the top of the order, the last tool added will resolve be
```cs
await DiffRunner.LaunchAsync(tempFile, targetFile);
```
<sup><a href='/src/DiffEngine.Tests/DiffRunnerTests.cs#L63-L67' title='Snippet source file'>snippet source</a> | <a href='#snippet-DiffRunnerLaunch' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/DiffEngine.Tests/DiffRunnerTests.cs#L62-L66' title='Snippet source file'>snippet source</a> | <a href='#snippet-DiffRunnerLaunch' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Alternatively the instance returned from `AddTool*` can be used to explicitly launch that tool.
Expand All @@ -69,7 +69,7 @@ var resolvedTool = DiffTools.AddToolBasedOn(

await DiffRunner.LaunchAsync(resolvedTool!, "PathToTempFile", "PathToTargetFile");
```
<sup><a href='/src/DiffEngine.Tests/DiffToolsTest.cs#L82-L93' title='Snippet source file'>snippet source</a> | <a href='#snippet-AddToolAndLaunch' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/DiffEngine.Tests/DiffToolsTest.cs#L86-L97' title='Snippet source file'>snippet source</a> | <a href='#snippet-AddToolAndLaunch' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


Expand Down
2 changes: 1 addition & 1 deletion docs/diff-tool.order.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@ For example `VisualStudio,Meld` will result in VisualStudio then Meld then all o
```cs
DiffTools.UseOrder(DiffTool.VisualStudio, DiffTool.AraxisMerge);
```
<sup><a href='/src/DiffEngine.Tests/DiffToolsTest.cs#L139-L143' title='Snippet source file'>snippet source</a> | <a href='#snippet-UseOrder' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/DiffEngine.Tests/DiffToolsTest.cs#L143-L147' title='Snippet source file'>snippet source</a> | <a href='#snippet-UseOrder' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ A tool can be launched using the following:
```cs
await DiffRunner.LaunchAsync(tempFile, targetFile);
```
<sup><a href='/src/DiffEngine.Tests/DiffRunnerTests.cs#L63-L67' title='Snippet source file'>snippet source</a> | <a href='#snippet-DiffRunnerLaunch' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/DiffEngine.Tests/DiffRunnerTests.cs#L62-L66' title='Snippet source file'>snippet source</a> | <a href='#snippet-DiffRunnerLaunch' title='Start of snippet'>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 @@ -98,7 +98,7 @@ A tool can be closed using the following:
```cs
DiffRunner.Kill(file1, file2);
```
<sup><a href='/src/DiffEngine.Tests/DiffRunnerTests.cs#L76-L80' title='Snippet source file'>snippet source</a> | <a href='#snippet-DiffRunnerKill' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/DiffEngine.Tests/DiffRunnerTests.cs#L75-L79' title='Snippet source file'>snippet source</a> | <a href='#snippet-DiffRunnerKill' title='Start of snippet'>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
8 changes: 5 additions & 3 deletions src/DiffEngine.Tests/DiffEngine.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
<PackageReference Include="MarkdownSnippets.MsBuild" PrivateAssets="all" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="Argon" />
<PackageReference Include="xunit.v3" />
<PackageReference Include="xunit.runner.visualstudio" PrivateAssets="all" />
<PackageReference Include="NUnit" />
<PackageReference Include="NUnit3TestAdapter" />
<PackageReference Include="Verify.NUnit" />
<PackageReference Include="ProjectDefaults" PrivateAssets="all" />
<PackageReference Include="XunitContext" />
<ProjectReference Include="..\DiffEngine\DiffEngine.csproj" />
<Compile Remove="DefinitionsTest.cs" Condition="'$(TargetFramework)' != 'net8.0'" />
<Using Include="NUnit.Framework.Legacy.ClassicAssert" Static="True" />
<Using Include="NUnit.Framework.Assert" Static="True" />
</ItemGroup>
</Project>
8 changes: 4 additions & 4 deletions src/DiffEngine.Tests/DiffEngineTrayTest.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
public class DiffEngineTrayTest(ITestOutputHelper output) :
XunitContextBase(output)
[TestFixture]
public class DiffEngineTrayTest
{
[Fact]
[Test]
public void IsRunning() =>
Assert.False(DiffEngineTray.IsRunning);
False(DiffEngineTray.IsRunning);
}
19 changes: 9 additions & 10 deletions src/DiffEngine.Tests/DiffRunnerTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#if NET8_0
public class DiffRunnerTests :
XunitContextBase
public class DiffRunnerTests
{
static ResolvedTool tool;
string file2;
Expand All @@ -17,10 +16,10 @@ public async Task MaxInstancesToLaunch()
ProcessCleanup.Refresh();
var result = DiffRunner.Launch(file1, "fake.txt");
await Task.Delay(300);
Assert.Equal(LaunchResult.StartedNewInstance, result);
AreEqual(LaunchResult.StartedNewInstance, result);
ProcessCleanup.Refresh();
result = DiffRunner.Launch(file2, "fake.txt");
Assert.Equal(LaunchResult.TooManyRunningDiffTools, result);
AreEqual(LaunchResult.TooManyRunningDiffTools, result);
ProcessCleanup.Refresh();
DiffRunner.Kill(file1, "fake.txt");
DiffRunner.Kill(file2, "fake.txt");
Expand All @@ -41,10 +40,10 @@ public async Task MaxInstancesToLaunchAsync()
ProcessCleanup.Refresh();
var result = await DiffRunner.LaunchAsync(file1, "fake.txt");
await Task.Delay(300);
Assert.Equal(LaunchResult.StartedNewInstance, result);
AreEqual(LaunchResult.StartedNewInstance, result);
ProcessCleanup.Refresh();
result = await DiffRunner.LaunchAsync(file2, "fake.txt");
Assert.Equal(LaunchResult.TooManyRunningDiffTools, result);
AreEqual(LaunchResult.TooManyRunningDiffTools, result);
ProcessCleanup.Refresh();
DiffRunner.Kill(file1, "fake.txt");
DiffRunner.Kill(file2, "fake.txt");
Expand Down Expand Up @@ -89,7 +88,7 @@ public void LaunchAndKillDisabled()
Assert.False(IsRunning());
Assert.False(ProcessCleanup.IsRunning(command));
var result = DiffRunner.Launch(file1, file2);
Assert.Equal(LaunchResult.Disabled, result);
AreEqual(LaunchResult.Disabled, result);
Thread.Sleep(500);
ProcessCleanup.Refresh();
Assert.False(IsRunning());
Expand All @@ -115,7 +114,7 @@ public async Task LaunchAndKillDisabledAsync()
Assert.False(IsRunning());
Assert.False(ProcessCleanup.IsRunning(command));
var result = await DiffRunner.LaunchAsync(file1, file2);
Assert.Equal(LaunchResult.Disabled, result);
AreEqual(LaunchResult.Disabled, result);
Thread.Sleep(500);
ProcessCleanup.Refresh();
Assert.False(IsRunning());
Expand All @@ -138,7 +137,7 @@ public void LaunchAndKill()
Assert.False(IsRunning());
Assert.False(ProcessCleanup.IsRunning(command));
var result = DiffRunner.Launch(file1, file2);
Assert.Equal(LaunchResult.StartedNewInstance, result);
AreEqual(LaunchResult.StartedNewInstance, result);
Thread.Sleep(500);
ProcessCleanup.Refresh();
Assert.True(IsRunning());
Expand All @@ -156,7 +155,7 @@ public async Task LaunchAndKillAsync()
Assert.False(IsRunning());
Assert.False(ProcessCleanup.IsRunning(command));
var result = await DiffRunner.LaunchAsync(file1, file2);
Assert.Equal(LaunchResult.StartedNewInstance, result);
AreEqual(LaunchResult.StartedNewInstance, result);
Thread.Sleep(500);
ProcessCleanup.Refresh();
Assert.True(IsRunning());
Expand Down
44 changes: 22 additions & 22 deletions src/DiffEngine.Tests/DiffToolsTest.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
public class DiffToolsTest :
XunitContextBase
[TestFixture]
public class DiffToolsTest
{
[Fact]
[Test]
public void MaxInstancesToLaunch() =>
#region MaxInstancesToLaunch
DiffRunner.MaxInstancesToLaunch(10);
#endregion

[Fact]
[Test]
public void AddTool()
{
DiffTools.Reset();
var diffToolPath = FakeDiffTool.Exe;

#region AddTool
Expand All @@ -28,15 +29,16 @@ public void AddTool()

#endregion

Assert.Equal(resolvedTool.Name, DiffTools.Resolved.First()
AreEqual(resolvedTool.Name, DiffTools.Resolved.First()
.Name);
Assert.True(DiffTools.TryFindByExtension(".jpg", out var forExtension));
Assert.Equal(resolvedTool.Name, forExtension.Name);
True(DiffTools.TryFindByExtension(".jpg", out var forExtension));
AreEqual(resolvedTool.Name, forExtension!.Name);
}

[Fact]
[Test]
public void OrderShouldNotMessWithAddTool()
{
DiffTools.Reset();
var diffToolPath = FakeDiffTool.Exe;
var resolvedTool = DiffTools.AddTool(
name: "MyCustomDiffTool",
Expand All @@ -50,15 +52,16 @@ public void OrderShouldNotMessWithAddTool()
exePath: diffToolPath,
binaryExtensions: [])!;
DiffTools.UseOrder(DiffTool.VisualStudio, DiffTool.AraxisMerge);
Assert.Equal("MyCustomDiffTool", resolvedTool.Name);
Assert.True(DiffTools.TryFindByExtension(".txt", out var forExtension));
Assert.Equal("MyCustomDiffTool", forExtension.Name);
AreEqual("MyCustomDiffTool", resolvedTool.Name);
True(DiffTools.TryFindByExtension(".txt", out var forExtension));
AreEqual("MyCustomDiffTool", forExtension!.Name);
}

#if DEBUG
[Fact]
[Test]
public void AddToolBasedOn()
{
DiffTools.Reset();
#region AddToolBasedOn

var resolvedTool = DiffTools.AddToolBasedOn(
Expand All @@ -70,15 +73,16 @@ public void AddToolBasedOn()

#endregion

Assert.Equal(resolvedTool, DiffTools.Resolved.First());
Assert.True(DiffTools.TryFindByExtension(".txt", out var forExtension));
Assert.Equal(resolvedTool, forExtension);
Assert.Equal("\"custom args \"bar\" \"foo\"", resolvedTool.LaunchArguments.Left("foo", "bar"));
Assert.Equal("\"custom args \"foo\" \"bar\"", resolvedTool.LaunchArguments.Right("foo", "bar"));
AreEqual(resolvedTool, DiffTools.Resolved.First());
True(DiffTools.TryFindByExtension(".txt", out var forExtension));
AreEqual(resolvedTool, forExtension);
AreEqual("\"custom args \"bar\" \"foo\"", resolvedTool.LaunchArguments.Left("foo", "bar"));
AreEqual("\"custom args \"foo\" \"bar\"", resolvedTool.LaunchArguments.Right("foo", "bar"));
}
#endif
static async Task AddToolAndLaunch()
{
DiffTools.Reset();
#region AddToolAndLaunch

var resolvedTool = DiffTools.AddToolBasedOn(
Expand Down Expand Up @@ -142,7 +146,7 @@ public void ChangeOrder()

#endregion

Assert.Equal(DiffTool.VisualStudio, DiffTools.Resolved.First()
AreEqual(DiffTool.VisualStudio, DiffTools.Resolved.First()
.Tool);
}

Expand All @@ -167,8 +171,4 @@ public void TryFindByName()
}
#endif
**/
public DiffToolsTest(ITestOutputHelper output)
:
base(output) =>
DiffTools.Reset();
}
3 changes: 3 additions & 0 deletions src/DiffEngine.Tests/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Global using directives

global using NUnit.Framework.Legacy;
36 changes: 18 additions & 18 deletions src/DiffEngine.Tests/LinuxOsxProcessTests.cs
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
public class LinuxOsxProcessTests(ITestOutputHelper output) :
XunitContextBase(output)
[TestFixture]
public class LinuxOsxProcessTests
{
[Fact]
[Test]
public void TryParseWithZshInstalled()
{
var parse = LinuxOsxProcess.TryParse("20872 -zsh", out var command);
Assert.True(parse);
True(parse);
var processCommand = command!.Value;
Assert.Equal(20872, processCommand.Process);
Assert.Equal("-zsh", processCommand.Command);
AreEqual(20872, processCommand.Process);
AreEqual("-zsh", processCommand.Command);
}

[Fact]
[Test]
public void TryParse()
{
var parse = LinuxOsxProcess.TryParse("309 /System/Library/coreauthd -foo", out var command);
Assert.True(parse);
True(parse);
var processCommand = command!.Value;
Assert.Equal(309, processCommand.Process);
Assert.Equal("/System/Library/coreauthd -foo", processCommand.Command);
AreEqual(309, processCommand.Process);
AreEqual("/System/Library/coreauthd -foo", processCommand.Command);
}

[Fact]
[Test]
public void TryParse_noSlash()
{
var parse = LinuxOsxProcess.TryParse("309 System/Library/coreauthd -foo", out var command);
Assert.True(parse);
True(parse);
var processCommand = command!.Value;
Assert.Equal(309, processCommand.Process);
Assert.Equal("System/Library/coreauthd -foo", processCommand.Command);
AreEqual(309, processCommand.Process);
AreEqual("System/Library/coreauthd -foo", processCommand.Command);
}

[Fact]
[Test]
public void TryParse_singleDigit()
{
var parse = LinuxOsxProcess.TryParse("309 System/Library/coreauthd -foo", out var command);
Assert.True(parse);
True(parse);
var processCommand = command!.Value;
Assert.Equal(309, processCommand.Process);
Assert.Equal("System/Library/coreauthd -foo", processCommand.Command);
AreEqual(309, processCommand.Process);
AreEqual("System/Library/coreauthd -foo", processCommand.Command);
}
}
3 changes: 2 additions & 1 deletion src/DiffEngine.Tests/ModuleInitializer.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
[assembly: CollectionBehavior(CollectionBehavior.CollectionPerAssembly, DisableTestParallelization = true)]
[assembly: NonParallelizable]

public static class ModuleInitializer
{
[ModuleInitializer]
public static void Initialize()
{
Source.Init();
Logging.Enable();
DiffRunner.Disabled = false;
}
Expand Down
16 changes: 8 additions & 8 deletions src/DiffEngine.Tests/OrderReaderTest.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
public class OrderReaderTest(ITestOutputHelper output) :
XunitContextBase(output)
[TestFixture]
public class OrderReaderTest
{
[Fact]
[Test]
public void ParseEnvironmentVariable()
{
var diffTools = OrderReader.ParseEnvironment("VisualStudio,Meld").ToList();
Assert.Equal(DiffTool.VisualStudio, diffTools[0]);
Assert.Equal(DiffTool.Meld, diffTools[1]);
AreEqual(DiffTool.VisualStudio, diffTools[0]);
AreEqual(DiffTool.Meld, diffTools[1]);
}

[Fact]
[Test]
public void BadEnvironmentVariable()
{
var exception = Assert.Throws<Exception>(() => OrderReader.ParseEnvironment("Foo").ToList());
Assert.Equal("Unable to parse tool from `DiffEngine_ToolOrder` environment variable: Foo", exception.Message);
var exception = Throws<Exception>(() => OrderReader.ParseEnvironment("Foo").ToList());
AreEqual("Unable to parse tool from `DiffEngine_ToolOrder` environment variable: Foo", exception!.Message);
}
}
Loading
Loading