Skip to content

Commit

Permalink
Implement environment variable as a possible path source for diff too…
Browse files Browse the repository at this point in the history
…ls (#314)
  • Loading branch information
ldeluigi authored May 28, 2023
1 parent 563f3a3 commit afa3381
Show file tree
Hide file tree
Showing 31 changed files with 403 additions and 148 deletions.
142 changes: 95 additions & 47 deletions docs/diff-tool.md

Large diffs are not rendered by default.

22 changes: 21 additions & 1 deletion src/DiffEngine.Tests/DefinitionsTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
public class DefinitionsTest :
public class DefinitionsTest :
XunitContextBase
{
[Fact]
Expand All @@ -14,6 +14,26 @@ public void WriteList()
}
}

[Fact]
public void EnvironmentVariablesShouldBeUnique()
{
static void FindDuplicates(Func<OsSupport, OsSettings?> SelectOs)
{
var findDuplicates = Definitions.Tools
.Select(d => d.OsSupport)
.Select(SelectOs)
.Where(s => s is not null)
.GroupBy(x => x);
foreach (var group in findDuplicates)
{
Assert.Equal(1, group.Count());
}
}
FindDuplicates(os => os.Windows);
FindDuplicates(os => os.Osx);
FindDuplicates(os => os.Linux);
}

static void AddToolLink(TextWriter writer, Definition tool)
{
var osSupport = GetOsSupport(tool.OsSupport);
Expand Down
21 changes: 18 additions & 3 deletions src/DiffEngine.Tests/OsSettingsResolverTest.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
public class OsSettingsResolverTest :
public class OsSettingsResolverTest :
XunitContextBase
{
[Fact]
public void Simple()
{
var paths = OsSettingsResolver.ExpandProgramFiles(new[] {"Path"}).ToList();
var paths = OsSettingsResolver.ExpandProgramFiles(new[] { "Path" }).ToList();
Assert.Equal("Path", paths.Single());
}

[Fact]
public void Expand()
{
var paths = OsSettingsResolver.ExpandProgramFiles(new[] {@"%ProgramFiles%\Path"}).ToList();
var paths = OsSettingsResolver.ExpandProgramFiles(new[] { @"%ProgramFiles%\Path" }).ToList();
Assert.Equal(@"%ProgramFiles%\Path", paths[0]);
Assert.Equal(@"%ProgramW6432%\Path", paths[1]);
Assert.Equal(@"%ProgramFiles(x86)%\Path", paths[2]);
Expand All @@ -36,6 +36,21 @@ public void EnvPath()
}
}

[Fact]
public void EnvVar()
{
var launchArguments = new LaunchArguments(
Left: (temp, target) => string.Empty,
Right: (temp, target) => string.Empty);

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
var found = OsSettingsResolver.Resolve(new OsSupport(Windows: new OsSettings("ComSpec", "cmd.exe", launchArguments, "")), out var filePath, out var launchArgs);
Assert.Equal(true, found);
Assert.Equal(@"C:\Windows\System32\cmd.exe", filePath, ignoreCase: true);
}
}

public OsSettingsResolverTest(ITestOutputHelper output) :
base(output)
{
Expand Down
135 changes: 90 additions & 45 deletions src/DiffEngine.Tests/diffTools.include.md

Large diffs are not rendered by default.

11 changes: 8 additions & 3 deletions src/DiffEngine/Implementation/AraxisMerge.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
static partial class Implementation
static partial class Implementation
{
public static Definition AraxisMerge() =>
new(
public static Definition AraxisMerge()
{
var environmentVariable = $"${DefaultEnvironmentVariablePrefix}_{nameof(DiffTool.AraxisMerge)}";
return new(
Tool: DiffTool.AraxisMerge,
Url: "https://www.araxis.com/merge",
AutoRefresh: true,
Expand Down Expand Up @@ -36,12 +38,14 @@ public static Definition AraxisMerge() =>
},
OsSupport: new(
Windows: new(
environmentVariable,
"Compare.exe",
new(
Left: (temp, target) => $"/nowait \"{target}\" \"{temp}\"",
Right: (temp, target) => $"/nowait \"{temp}\" \"{target}\""),
@"%ProgramFiles%\Araxis\Araxis Merge\"),
Osx: new(
environmentVariable,
"compare",
new(
Left: (temp, target) => $"-nowait \"{target}\" \"{temp}\"",
Expand All @@ -53,5 +57,6 @@ public static Definition AraxisMerge() =>
* [MacOS command line usage](https://www.araxis.com/merge/documentation-os-x/command-line.en)
* [Installing MacOS command line](https://www.araxis.com/merge/documentation-os-x/installing.en)
""");
}
//TODO: add doco about auto refresh
}
6 changes: 5 additions & 1 deletion src/DiffEngine/Implementation/BeyondCompare.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
static partial class Implementation
static partial class Implementation
{
public static Definition BeyondCompare()
{
Expand All @@ -22,6 +22,7 @@ static string RightOsxLinuxArguments(string temp, string target)
return $"-solo -leftreadonly \"{temp}\" \"{target}\"";
}

var environmentVariable = $"${DefaultEnvironmentVariablePrefix}_{nameof(DiffTool.BeyondCompare)}";
return new(
Tool: DiffTool.BeyondCompare,
Url: "https://www.scootersoftware.com",
Expand All @@ -47,18 +48,21 @@ static string RightOsxLinuxArguments(string temp, string target)
},
OsSupport: new(
Windows: new(
environmentVariable,
"BCompare.exe",
new(
LeftWindowsArguments,
RightWindowsArguments),
@"%ProgramFiles%\Beyond Compare *\"),
Linux: new(
environmentVariable,
"bcomp",
new(
LeftOsxLinuxArguments,
RightOsxLinuxArguments),
"/usr/lib/beyondcompare/"),
Osx: new(
environmentVariable,
"bcomp",
new(
LeftOsxLinuxArguments,
Expand Down
10 changes: 7 additions & 3 deletions src/DiffEngine/Implementation/CodeCompare.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
static partial class Implementation
static partial class Implementation
{
public static Definition CodeCompare() =>
new(
public static Definition CodeCompare()
{
var environmentVariable = $"${DefaultEnvironmentVariablePrefix}_{nameof(DiffTool.CodeCompare)}";
return new(
Tool: DiffTool.CodeCompare,
Url: "https://www.devart.com/codecompare/",
AutoRefresh: false,
Expand All @@ -12,10 +14,12 @@ public static Definition CodeCompare() =>
BinaryExtensions: Array.Empty<string>(),
OsSupport: new(
Windows: new(
environmentVariable,
"CodeCompare.exe",
new(
Left: (temp, target) => $"\"{target}\" \"{temp}\"",
Right: (temp, target) => $"\"{temp}\" \"{target}\""),
@"%ProgramFiles%\Devart\Code Compare\")),
Notes: @" * [Command line reference](https://docs.devart.com/code-compare/using-command-line/comparing-via-command-line.html)");
}
}
6 changes: 5 additions & 1 deletion src/DiffEngine/Implementation/DeltaWalker.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
static partial class Implementation
static partial class Implementation
{
public static Definition DeltaWalker()
{
var launchArguments = new LaunchArguments(
Left: (temp, target) => $"-mi \"{target}\" \"{temp}\"",
Right: (temp, target) => $"-mi \"{temp}\" \"{target}\"");

var environmentVariable = $"${DefaultEnvironmentVariablePrefix}_{nameof(DiffTool.DeltaWalker)}";

return new(
Tool: DiffTool.DeltaWalker,
Url: "https://www.deltawalker.com/",
Expand Down Expand Up @@ -52,10 +54,12 @@ public static Definition DeltaWalker()
},
OsSupport: new(
Osx: new(
environmentVariable,
"DeltaWalker",
launchArguments,
"/Applications/DeltaWalker.app/Contents/MacOS/"),
Windows: new(
environmentVariable,
"DeltaWalker.exe",
launchArguments,
@"C:\Program Files\Deltopia\DeltaWalker\")),
Expand Down
3 changes: 2 additions & 1 deletion src/DiffEngine/Implementation/DiffMerge.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
static partial class Implementation
static partial class Implementation
{
public static Definition DiffMerge()
{
var launchArguments = new LaunchArguments(
Left: (temp, target) => $"--nosplash \"{target}\" \"{temp}\"",
Right: (temp, target) => $"--nosplash \"{temp}\" \"{target}\"");

var environmentVariable = $"${DefaultEnvironmentVariablePrefix}_{nameof(DiffTool.DiffMerge)}";
return new(
Tool: DiffTool.DiffMerge,
Url: "https://www.sourcegear.com/diffmerge/",
Expand Down
10 changes: 7 additions & 3 deletions src/DiffEngine/Implementation/Diffinity.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
static partial class Implementation
static partial class Implementation
{
public static Definition Diffinity() =>
new(
public static Definition Diffinity()
{
var environmentVariable = $"${DefaultEnvironmentVariablePrefix}_{nameof(DiffTool.Diffinity)}";
return new(
Tool: DiffTool.Diffinity,
Url: "https://truehumandesign.se/s_diffinity.php",
AutoRefresh: true,
Expand All @@ -12,6 +14,7 @@ public static Definition Diffinity() =>
BinaryExtensions: Array.Empty<string>(),
OsSupport: new(
Windows: new(
environmentVariable,
"Diffinity.exe",
new(
Left: (temp, target) => $"\"{target}\" \"{temp}\"",
Expand All @@ -21,4 +24,5 @@ public static Definition Diffinity() =>
* Disable single instance:
\ Preferences \ Tabs \ uncheck `Use single instance and open new diffs in tabs`.
""");
}
}
4 changes: 3 additions & 1 deletion src/DiffEngine/Implementation/ExamDiff.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
static partial class Implementation
static partial class Implementation
{
public static Definition ExamDiff()
{
Expand All @@ -16,6 +16,7 @@ static string RightArguments(string temp, string target)
return $"\"{temp}\" \"{target}\" /nh /diffonly /dn1:{tempTitle} /dn2:{targetTitle}";
}

var environmentVariable = $"${DefaultEnvironmentVariablePrefix}_{nameof(DiffTool.ExamDiff)}";
return new(
Tool: DiffTool.ExamDiff,
Url: "https://www.prestosoft.com/edp_examdiffpro.asp",
Expand All @@ -27,6 +28,7 @@ static string RightArguments(string temp, string target)
BinaryExtensions: Array.Empty<string>(),
OsSupport: new(
Windows: new(
environmentVariable,
"ExamDiff.exe",
new(LeftArguments, RightArguments),
@"%ProgramFiles%\ExamDiff Pro\")),
Expand Down
3 changes: 2 additions & 1 deletion src/DiffEngine/Implementation/Guiffy.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
static partial class Implementation
static partial class Implementation
{
public static Definition Guiffy()
{
var launchArguments = new LaunchArguments(
Left: (temp, target) => $"\"{target}\" \"{temp}\" -ge2",
Right: (temp, target) => $"\"{temp}\" \"{target}\" -ge1");

var environmentVariable = $"${DefaultEnvironmentVariablePrefix}_{nameof(DiffTool.Guiffy)}";
return new(
Tool: DiffTool.Guiffy,
Url: "https://www.guiffy.com/",
Expand Down
4 changes: 4 additions & 0 deletions src/DiffEngine/Implementation/ImplementationDefaults.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
static partial class Implementation
{
const string DefaultEnvironmentVariablePrefix = "DiffEngine";
}
5 changes: 4 additions & 1 deletion src/DiffEngine/Implementation/KDiff3.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
static partial class Implementation
static partial class Implementation
{
public static Definition KDiff3()
{
var launchArguments = new LaunchArguments(
Left: (temp, target) => $"\"{target}\" \"{temp}\" --cs CreateBakFiles=0",
Right: (temp, target) => $"\"{temp}\" \"{target}\" --cs CreateBakFiles=0");

var environmentVariable = $"${DefaultEnvironmentVariablePrefix}_{nameof(DiffTool.KDiff3)}";
return new(
Tool: DiffTool.KDiff3,
Url: "https://github.com/KDE/kdiff3",
Expand All @@ -17,10 +18,12 @@ public static Definition KDiff3()
BinaryExtensions: Array.Empty<string>(),
OsSupport: new(
Windows: new(
environmentVariable,
"kdiff3.exe",
launchArguments,
@"%ProgramFiles%\KDiff3\"),
Osx: new(
environmentVariable,
"kdiff3",
launchArguments,
"/Applications/kdiff3.app/Contents/MacOS/")),
Expand Down
10 changes: 7 additions & 3 deletions src/DiffEngine/Implementation/Kaleidoscope.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
static partial class Implementation
static partial class Implementation
{
public static Definition Kaleidoscope() =>
new(
public static Definition Kaleidoscope()
{
var environmentVariable = $"${DefaultEnvironmentVariablePrefix}_{nameof(DiffTool.Kaleidoscope)}";
return new(
Tool: DiffTool.Kaleidoscope,
Url: "https://www.kaleidoscopeapp.com/",
AutoRefresh: true,
Expand All @@ -22,8 +24,10 @@ public static Definition Kaleidoscope() =>
},
OsSupport: new(
Osx: new(
environmentVariable,
"ksdiff",
new(
Left: (temp, target) => $"\"{target}\" \"{temp}\"",
Right: (temp, target) => $"\"{temp}\" \"{target}\""))));
}
}
6 changes: 5 additions & 1 deletion src/DiffEngine/Implementation/Meld.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
static partial class Implementation
static partial class Implementation
{
public static Definition Meld()
{
var launchArguments = new LaunchArguments(
Left: (temp, target) => $"\"{target}\" \"{temp}\"",
Right: (temp, target) => $"\"{temp}\" \"{target}\"");

var environmentVariable = $"${DefaultEnvironmentVariablePrefix}_{nameof(DiffTool.Meld)}";
return new(
Tool: DiffTool.Meld,
Url: "https://meldmerge.org/",
Expand All @@ -17,14 +18,17 @@ public static Definition Meld()
BinaryExtensions: Array.Empty<string>(),
OsSupport: new(
Windows: new(
environmentVariable,
"meld.exe",
launchArguments,
@"%LOCALAPPDATA%\Programs\Meld\",
@"%ProgramFiles%\Meld\"),
Linux: new(
environmentVariable,
"meld",
launchArguments),
Osx: new(
environmentVariable,
"meld",
launchArguments,
"/Applications/meld.app/Contents/MacOS/")),
Expand Down
Loading

0 comments on commit afa3381

Please sign in to comment.