Skip to content

Commit afa3381

Browse files
authored
Implement environment variable as a possible path source for diff tools (#314)
1 parent 563f3a3 commit afa3381

31 files changed

Lines changed: 403 additions & 148 deletions

docs/diff-tool.md

Lines changed: 95 additions & 47 deletions
Large diffs are not rendered by default.

src/DiffEngine.Tests/DefinitionsTest.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
public class DefinitionsTest :
1+
public class DefinitionsTest :
22
XunitContextBase
33
{
44
[Fact]
@@ -14,6 +14,26 @@ public void WriteList()
1414
}
1515
}
1616

17+
[Fact]
18+
public void EnvironmentVariablesShouldBeUnique()
19+
{
20+
static void FindDuplicates(Func<OsSupport, OsSettings?> SelectOs)
21+
{
22+
var findDuplicates = Definitions.Tools
23+
.Select(d => d.OsSupport)
24+
.Select(SelectOs)
25+
.Where(s => s is not null)
26+
.GroupBy(x => x);
27+
foreach (var group in findDuplicates)
28+
{
29+
Assert.Equal(1, group.Count());
30+
}
31+
}
32+
FindDuplicates(os => os.Windows);
33+
FindDuplicates(os => os.Osx);
34+
FindDuplicates(os => os.Linux);
35+
}
36+
1737
static void AddToolLink(TextWriter writer, Definition tool)
1838
{
1939
var osSupport = GetOsSupport(tool.OsSupport);

src/DiffEngine.Tests/OsSettingsResolverTest.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
public class OsSettingsResolverTest :
1+
public class OsSettingsResolverTest :
22
XunitContextBase
33
{
44
[Fact]
55
public void Simple()
66
{
7-
var paths = OsSettingsResolver.ExpandProgramFiles(new[] {"Path"}).ToList();
7+
var paths = OsSettingsResolver.ExpandProgramFiles(new[] { "Path" }).ToList();
88
Assert.Equal("Path", paths.Single());
99
}
1010

1111
[Fact]
1212
public void Expand()
1313
{
14-
var paths = OsSettingsResolver.ExpandProgramFiles(new[] {@"%ProgramFiles%\Path"}).ToList();
14+
var paths = OsSettingsResolver.ExpandProgramFiles(new[] { @"%ProgramFiles%\Path" }).ToList();
1515
Assert.Equal(@"%ProgramFiles%\Path", paths[0]);
1616
Assert.Equal(@"%ProgramW6432%\Path", paths[1]);
1717
Assert.Equal(@"%ProgramFiles(x86)%\Path", paths[2]);
@@ -36,6 +36,21 @@ public void EnvPath()
3636
}
3737
}
3838

39+
[Fact]
40+
public void EnvVar()
41+
{
42+
var launchArguments = new LaunchArguments(
43+
Left: (temp, target) => string.Empty,
44+
Right: (temp, target) => string.Empty);
45+
46+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
47+
{
48+
var found = OsSettingsResolver.Resolve(new OsSupport(Windows: new OsSettings("ComSpec", "cmd.exe", launchArguments, "")), out var filePath, out var launchArgs);
49+
Assert.Equal(true, found);
50+
Assert.Equal(@"C:\Windows\System32\cmd.exe", filePath, ignoreCase: true);
51+
}
52+
}
53+
3954
public OsSettingsResolverTest(ITestOutputHelper output) :
4055
base(output)
4156
{

src/DiffEngine.Tests/diffTools.include.md

Lines changed: 90 additions & 45 deletions
Large diffs are not rendered by default.

src/DiffEngine/Implementation/AraxisMerge.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
static partial class Implementation
1+
static partial class Implementation
22
{
3-
public static Definition AraxisMerge() =>
4-
new(
3+
public static Definition AraxisMerge()
4+
{
5+
var environmentVariable = $"${DefaultEnvironmentVariablePrefix}_{nameof(DiffTool.AraxisMerge)}";
6+
return new(
57
Tool: DiffTool.AraxisMerge,
68
Url: "https://www.araxis.com/merge",
79
AutoRefresh: true,
@@ -36,12 +38,14 @@ public static Definition AraxisMerge() =>
3638
},
3739
OsSupport: new(
3840
Windows: new(
41+
environmentVariable,
3942
"Compare.exe",
4043
new(
4144
Left: (temp, target) => $"/nowait \"{target}\" \"{temp}\"",
4245
Right: (temp, target) => $"/nowait \"{temp}\" \"{target}\""),
4346
@"%ProgramFiles%\Araxis\Araxis Merge\"),
4447
Osx: new(
48+
environmentVariable,
4549
"compare",
4650
new(
4751
Left: (temp, target) => $"-nowait \"{target}\" \"{temp}\"",
@@ -53,5 +57,6 @@ public static Definition AraxisMerge() =>
5357
* [MacOS command line usage](https://www.araxis.com/merge/documentation-os-x/command-line.en)
5458
* [Installing MacOS command line](https://www.araxis.com/merge/documentation-os-x/installing.en)
5559
""");
60+
}
5661
//TODO: add doco about auto refresh
5762
}

src/DiffEngine/Implementation/BeyondCompare.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
static partial class Implementation
1+
static partial class Implementation
22
{
33
public static Definition BeyondCompare()
44
{
@@ -22,6 +22,7 @@ static string RightOsxLinuxArguments(string temp, string target)
2222
return $"-solo -leftreadonly \"{temp}\" \"{target}\"";
2323
}
2424

25+
var environmentVariable = $"${DefaultEnvironmentVariablePrefix}_{nameof(DiffTool.BeyondCompare)}";
2526
return new(
2627
Tool: DiffTool.BeyondCompare,
2728
Url: "https://www.scootersoftware.com",
@@ -47,18 +48,21 @@ static string RightOsxLinuxArguments(string temp, string target)
4748
},
4849
OsSupport: new(
4950
Windows: new(
51+
environmentVariable,
5052
"BCompare.exe",
5153
new(
5254
LeftWindowsArguments,
5355
RightWindowsArguments),
5456
@"%ProgramFiles%\Beyond Compare *\"),
5557
Linux: new(
58+
environmentVariable,
5659
"bcomp",
5760
new(
5861
LeftOsxLinuxArguments,
5962
RightOsxLinuxArguments),
6063
"/usr/lib/beyondcompare/"),
6164
Osx: new(
65+
environmentVariable,
6266
"bcomp",
6367
new(
6468
LeftOsxLinuxArguments,
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
static partial class Implementation
1+
static partial class Implementation
22
{
3-
public static Definition CodeCompare() =>
4-
new(
3+
public static Definition CodeCompare()
4+
{
5+
var environmentVariable = $"${DefaultEnvironmentVariablePrefix}_{nameof(DiffTool.CodeCompare)}";
6+
return new(
57
Tool: DiffTool.CodeCompare,
68
Url: "https://www.devart.com/codecompare/",
79
AutoRefresh: false,
@@ -12,10 +14,12 @@ public static Definition CodeCompare() =>
1214
BinaryExtensions: Array.Empty<string>(),
1315
OsSupport: new(
1416
Windows: new(
17+
environmentVariable,
1518
"CodeCompare.exe",
1619
new(
1720
Left: (temp, target) => $"\"{target}\" \"{temp}\"",
1821
Right: (temp, target) => $"\"{temp}\" \"{target}\""),
1922
@"%ProgramFiles%\Devart\Code Compare\")),
2023
Notes: @" * [Command line reference](https://docs.devart.com/code-compare/using-command-line/comparing-via-command-line.html)");
24+
}
2125
}

src/DiffEngine/Implementation/DeltaWalker.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
static partial class Implementation
1+
static partial class Implementation
22
{
33
public static Definition DeltaWalker()
44
{
55
var launchArguments = new LaunchArguments(
66
Left: (temp, target) => $"-mi \"{target}\" \"{temp}\"",
77
Right: (temp, target) => $"-mi \"{temp}\" \"{target}\"");
88

9+
var environmentVariable = $"${DefaultEnvironmentVariablePrefix}_{nameof(DiffTool.DeltaWalker)}";
10+
911
return new(
1012
Tool: DiffTool.DeltaWalker,
1113
Url: "https://www.deltawalker.com/",
@@ -52,10 +54,12 @@ public static Definition DeltaWalker()
5254
},
5355
OsSupport: new(
5456
Osx: new(
57+
environmentVariable,
5558
"DeltaWalker",
5659
launchArguments,
5760
"/Applications/DeltaWalker.app/Contents/MacOS/"),
5861
Windows: new(
62+
environmentVariable,
5963
"DeltaWalker.exe",
6064
launchArguments,
6165
@"C:\Program Files\Deltopia\DeltaWalker\")),

src/DiffEngine/Implementation/DiffMerge.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
static partial class Implementation
1+
static partial class Implementation
22
{
33
public static Definition DiffMerge()
44
{
55
var launchArguments = new LaunchArguments(
66
Left: (temp, target) => $"--nosplash \"{target}\" \"{temp}\"",
77
Right: (temp, target) => $"--nosplash \"{temp}\" \"{target}\"");
88

9+
var environmentVariable = $"${DefaultEnvironmentVariablePrefix}_{nameof(DiffTool.DiffMerge)}";
910
return new(
1011
Tool: DiffTool.DiffMerge,
1112
Url: "https://www.sourcegear.com/diffmerge/",

src/DiffEngine/Implementation/Diffinity.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
static partial class Implementation
1+
static partial class Implementation
22
{
3-
public static Definition Diffinity() =>
4-
new(
3+
public static Definition Diffinity()
4+
{
5+
var environmentVariable = $"${DefaultEnvironmentVariablePrefix}_{nameof(DiffTool.Diffinity)}";
6+
return new(
57
Tool: DiffTool.Diffinity,
68
Url: "https://truehumandesign.se/s_diffinity.php",
79
AutoRefresh: true,
@@ -12,6 +14,7 @@ public static Definition Diffinity() =>
1214
BinaryExtensions: Array.Empty<string>(),
1315
OsSupport: new(
1416
Windows: new(
17+
environmentVariable,
1518
"Diffinity.exe",
1619
new(
1720
Left: (temp, target) => $"\"{target}\" \"{temp}\"",
@@ -21,4 +24,5 @@ public static Definition Diffinity() =>
2124
* Disable single instance:
2225
\ Preferences \ Tabs \ uncheck `Use single instance and open new diffs in tabs`.
2326
""");
27+
}
2428
}

0 commit comments

Comments
 (0)