/// <summary> /// Find and kill a diff tool process. /// </summary> public static void Kill(string tempFile, string targetFile) { if (Disabled) { return; } var extension = Extensions.GetExtension(tempFile); if (!DiffTools.TryFindByExtension(extension, out var diffTool)) { Logging.Write($"Extension not found. {extension}"); return; } var command = diffTool.BuildCommand(tempFile, targetFile); if (diffTool.IsMdi) { Logging.Write($"DiffTool is Mdi so not killing. diffTool: {diffTool.ExePath}"); return; } ProcessCleanup.Kill(command); }
public void Launch() { if (DiffTools.TryGetTextDiff("txt", out var diffTool)) { DiffRunner.Launch(diffTool, Path.Combine(SourceDirectory, "DiffRunnerFile1.txt"), Path.Combine(SourceDirectory, "DiffRunnerFile2.txt")); } }
public void ChangeOrder() { #region UseOrder DiffTools.UseOrder(DiffTool.VisualStudio, DiffTool.AraxisMerge); #endregion Assert.Equal(DiffTool.VisualStudio, DiffTools.Resolved.First().Tool); }
public static void ShouldMatchApproved(this string actual, Func <string> customMessage, Action <ShouldMatchConfigurationBuilder> configureOptions) { var configurationBuilder = new ShouldMatchConfigurationBuilder(new ShouldMatchConfiguration { StringCompareOptions = StringCompareShould.IgnoreLineEndings, FileExtension = "txt" }); configureOptions(configurationBuilder); var config = configurationBuilder.Build(); if (config.Scrubber != null) { actual = config.Scrubber(actual); } var approvalFileFolder = config.ApprovalFileFolder; if (!Directory.Exists(approvalFileFolder)) { Directory.CreateDirectory(approvalFileFolder); } var approvedFile = Path.Combine(approvalFileFolder, $"{config.Name}{config.FilenameDescriminator}.approved.{config.FileExtension}"); var receivedFile = Path.Combine(approvalFileFolder, $"{config.Name}{config.FilenameDescriminator}.received.{config.FileExtension}"); File.WriteAllText(receivedFile, actual); if (!File.Exists(approvedFile)) { if (DiffTools.ShouldOpenDiffTool()) { DiffTools.GetDiffTool().Open(receivedFile, approvedFile, false); } throw new ShouldMatchApprovedException($@"Approval file {approvedFile} does not exist", receivedFile, approvedFile); } try { var approvedFileContents = File.ReadAllText(approvedFile); var receivedFileContents = File.ReadAllText(receivedFile); receivedFileContents.ShouldBe(approvedFileContents, config.StringCompareOptions); if (File.Exists(receivedFile)) { File.Delete(receivedFile); } } catch (Exception) { if (DiffTools.ShouldOpenDiffTool()) { DiffTools.GetDiffTool().Open(receivedFile, approvedFile, true); } throw; } }
internal List <Change> Diff() { List <Change> changes = new List <Change>(); //Removed and Added Types changes.AddRange(DiffTools.AddedElements(oldTypes, newTypes, t => new TypeAddedChange((IGraphType)t))); changes.AddRange(DiffTools.RemovedElements(oldTypes, newTypes, t => new TypeRemovedChange((IGraphType)t))); //Type Diff for common types foreach (var newType in this.newTypes) { var oldType = this.oldTypes.Where(t => t.Name.Equals(newType.Name)).SingleOrDefault(); if (oldType != null) { changes.AddRange(ChangesInType(oldType, newType)); } } //# Diff Schemas changes.AddRange(ChangesInSchema()); // Diff Directives changes.AddRange(ChangesInDirectives()); return(changes); }
static Tests() { BuildServerDetector.Detected = false; DiffTools.AddTool( name: "MyTools", autoRefresh: true, isMdi: false, supportsText: true, requiresTarget: true, arguments: (path1, path2) => $"\"{path1}\" \"{path2}\"", exePath: diffToolPath, binaryExtensions: new[] { "knownBin" }); var binPath = AllFiles.Files["jpg"]; var newPath = Path.ChangeExtension(binPath.Path, "knownBin"); File.Copy(binPath.Path, newPath, true); AllFiles.UseFile(Category.Image, newPath); SharedVerifySettings.RegisterFileConverter <TypeToSplit>( "txt", (split, settings) => new ConversionResult( split.Info, new List <Stream> { new MemoryStream(FileHelpers.Utf8NoBOM.GetBytes(split.Property1)), new MemoryStream(FileHelpers.Utf8NoBOM.GetBytes(split.Property2)) })); DiffRunner.MaxInstancesToLaunch(int.MaxValue); }
static Tests() { BuildServerDetector.Detected = false; DiffRunner.Disabled = false; DiffTools.AddTool( name: "MyTools", autoRefresh: true, isMdi: false, supportsText: true, requiresTarget: true, arguments: (path1, path2) => $"\"{path1}\" \"{path2}\"", exePath: diffToolPath, binaryExtensions: new[] { "knownBin" }); var binPath = AllFiles.Files["jpg"]; var newPath = Path.ChangeExtension(binPath.Path, "knownBin"); File.Copy(binPath.Path, newPath, true); AllFiles.UseFile(Category.Image, newPath); VerifierSettings.RegisterFileConverter <TypeToSplit>( (split, _) => new ConversionResult( split.Info, new List <Target> { new("txt", split.Property1), new("txt", split.Property2) }));
public void TryFind() { Assert.True(DiffTools.TryFindByExtension("txt", out var resolved)); Assert.NotNull(resolved); Assert.False(DiffTools.TryFindByExtension("notFound", out resolved)); Assert.Null(resolved); }
public void TryFindByName() { Assert.True(DiffTools.TryFindByName(DiffTool.VisualStudio, out var resolved)); Assert.NotNull(resolved); Assert.True(DiffTools.TryFindByName(resolved !.Name, out resolved)); Assert.NotNull(resolved); }
static PipelineApprovals() { Extensions.AddTextExtension("dot"); DiffTools.AddToolBasedOn( DiffTool.VisualStudioCode, "Vs Code for Visgraph", arguments: (temp, target) => $"-r \"{temp}\"", binaryExtensions: new[] { ".dot" }); }
public MessageConverterTests() { DiffTools.UseOrder(DiffTool.VisualStudioCode, DiffTool.Rider, DiffTool.VisualStudio); VerifierSettings.AddExtraSettings(s => s.Converters.Add(new EncodingConverter())); settings = new VerifySettings(); settings.ModifySerialization(_ => { _.IgnoreMembersWithType <Stream>(); }); }
void AddToolAndLaunch() { #region AddToolAndLaunch var resolvedTool = DiffTools.AddToolBasedOn( DiffTool.VisualStudio, name: "MyCustomDiffTool", arguments: (temp, target) => $"\"custom args {temp}\" \"{target}\""); DiffRunner.Launch(resolvedTool !, "PathToTempFile", "PathToTargetFile"); #endregion }
static DiffRunnerTests() { tool = DiffTools.AddTool( name: "FakeDiffTool", autoRefresh: true, isMdi: false, supportsText: true, requiresTarget: true, arguments: (path1, path2) => $"\"{path1}\" \"{path2}\"", exePath: FakeDiffTool.Exe, binaryExtensions: new[] { "knownBin" }) !; }
public void AddToolBasedOn() { #region AddToolBasedOn var resolvedTool = DiffTools.AddToolBasedOn( DiffTool.VisualStudio, name: "MyCustomDiffTool", arguments: (temp, target) => $"\"custom args {temp}\" \"{target}\""); #endregion Assert.Equal(resolvedTool, DiffTools.Resolved.First()); Assert.True(DiffTools.TryFind("txt", out var forExtension)); Assert.Equal(resolvedTool, forExtension); Assert.Equal("\"custom args foo\" \"bar\"", resolvedTool !.Arguments("foo", "bar")); }
public void OneTimeSetUp() { EmptyFiles.Extensions.AddTextExtension(".cst"); DiffTools.AddToolBasedOn( DiffTool.WinMerge, name: "WritableWinMerge", arguments: (temp, target) => { var leftTitle = Path.GetFileName(temp); var rightTitle = Path.GetFileName(target); return($"/u /wr /e \"{temp}\" \"{target}\" /dl \"{leftTitle}\" /dr \"{rightTitle}\""); } ); }
public void TryFind() { Assert.True(DiffTools.TryFind("txt", out var resolved)); Assert.NotNull(resolved); Assert.True(DiffTools.TryFind(DiffTool.VisualStudio, out resolved)); Assert.NotNull(resolved); Assert.False(DiffTools.TryFind("notFound", out resolved)); Assert.Null(resolved); Assert.False(DiffTools.TryFind(DiffTool.Kaleidoscope, out resolved)); Assert.Null(resolved); }
async Task AddToolAndLaunch() { #region AddToolAndLaunch var resolvedTool = DiffTools.AddToolBasedOn( DiffTool.VisualStudio, name: "MyCustomDiffTool", targetLeftArguments: (temp, target) => $"\"custom args \"{target}\" \"{temp}\"", targetRightArguments: (temp, target) => $"\"custom args \"{temp}\" \"{target}\""); await DiffRunner.LaunchAsync(resolvedTool !, "PathToTempFile", "PathToTargetFile"); #endregion }
private IEnumerable <Change> ChangesInDirectives() { List <Change> changes = new List <Change>(); changes.AddRange(DiffTools.AddedElements(oldDirectives, newDirectives, d => new DirectiveAdded((DirectiveGraphType)d))); changes.AddRange(DiffTools.RemovedElements(oldDirectives, newDirectives, d => new DirectiveRemoved((DirectiveGraphType)d))); foreach (var newDirective in this.newDirectives) { var oldDirective = oldDirectives.Where(t => t.Name.Equals(newDirective.Name)).SingleOrDefault(); if (oldDirective != null) { changes.AddRange(new Directive(oldDirective, newDirective).Diff()); } } return(changes); }
public void OrderShouldNotMessWithAddTool() { string diffToolPath = FakeDiffTool.Exe; var resolvedTool = DiffTools.AddTool( name: "MyCustomDiffTool", autoRefresh: true, isMdi: false, supportsText: true, requiresTarget: true, arguments: (tempFile, targetFile) => $"\"{tempFile}\" \"{targetFile}\"", exePath: diffToolPath, binaryExtensions: Enumerable.Empty <string>()) !; DiffTools.UseOrder(DiffTool.VisualStudio, DiffTool.AraxisMerge); Assert.Equal(resolvedTool.Name, DiffTools.Resolved.First().Name); Assert.True(DiffTools.TryFind("txt", out var forExtension)); Assert.Equal(resolvedTool.Name, forExtension !.Name); }
public void AddTool() { string diffToolPath = FakeDiffTool.Exe; #region AddTool var resolvedTool = DiffTools.AddTool( name: "MyCustomDiffTool", autoRefresh: true, isMdi: false, supportsText: true, requiresTarget: true, arguments: (tempFile, targetFile) => $"\"{tempFile}\" \"{targetFile}\"", exePath: diffToolPath, binaryExtensions: new[] { "jpg" }) !; #endregion Assert.Equal(resolvedTool.Name, DiffTools.Resolved.First().Name); Assert.True(DiffTools.TryFind("jpg", out var forExtension)); Assert.Equal(resolvedTool.Name, forExtension !.Name); }
public VerifyEngine( string extension, VerifySettings settings, Type testType, string directory, string testName) { this.settings = settings; this.testType = testType; this.testName = testName; diffTool = DiffTools.Find(extension); var verifiedPattern = FileNameBuilder.GetVerifiedPattern(extension, settings.Namer, this.testType, this.testName); danglingVerified = Directory.EnumerateFiles(directory, verifiedPattern).ToList(); var receivedPattern = FileNameBuilder.GetReceivedPattern(extension, settings.Namer, this.testType, this.testName); foreach (var file in Directory.EnumerateFiles(directory, receivedPattern)) { File.Delete(file); } diffTool = DiffTools.Find(extension); }
public void LaunchAndKill() { if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { return; } DiffTools.AddTool( name: "FakeDiffTool", autoRefresh: true, isMdi: false, supportsText: true, requiresTarget: true, arguments: (path1, path2) => $"\"{path1}\" \"{path2}\"", exePath: FakeDiffTool.Exe, binaryExtensions: new[] { "knownBin" }); var tempFile = Path.Combine(SourceDirectory, "DiffRunner.file1.txt"); var targetFile = Path.Combine(SourceDirectory, "DiffRunner.file2.txt"); DiffRunner.Launch(tempFile, targetFile); Assert.True(IsRunning()); ProcessCleanup.Refresh(); DiffRunner.Kill(tempFile, targetFile); Assert.False(IsRunning()); }
public bool IsWorkingInThisEnvironment(string forFile) { return(DiffTools.IsDetectedFor(diffTool, forFile)); }
public async Task WriteFoundTools() { var md = Path.Combine(SourceDirectory, "diffTools.include.md"); File.Delete(md); using var writer = File.CreateText(md); foreach (var tool in DiffTools.Tools()) { await writer.WriteLineAsync($@" ## [{tool.Name}]({tool.Url})"); if (tool.WindowsExePaths.Any()) { await writer.WriteLineAsync(@" ### Windows scanned paths: "); foreach (var path in tool.WindowsExePaths) { await writer.WriteLineAsync($@" * `{path}`"); } } if (tool.OsxExePaths.Any()) { await writer.WriteLineAsync(@" ### OSX scanned paths: "); foreach (var path in tool.OsxExePaths) { await writer.WriteLineAsync($@" * `{path}`"); } } if (tool.LinuxExePaths.Any()) { await writer.WriteLineAsync(@" ### Linux scanned paths: "); foreach (var path in tool.LinuxExePaths) { await writer.WriteLineAsync($@" * `{path}`"); } } if (!tool.BinaryExtensions.Any()) { continue; } await writer.WriteLineAsync(@" ### Supported binary extensions: "); foreach (var extension in tool.BinaryExtensions) { await writer.WriteLineAsync($@" * {extension}"); } } }
public static void Init() { DiffTools.UseOrder(DiffTool.VisualStudioCode); VerifySourceGenerators.Enable(); ClipboardAccept.Enable(); }
public DiffToolsTest(ITestOutputHelper output) : base(output) { DiffTools.Reset(); }