Skip to content

Commit

Permalink
Split out clipboard to a different nuget (#469)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp authored Feb 3, 2022
1 parent 536bb8f commit 25221a2
Show file tree
Hide file tree
Showing 26 changed files with 160 additions and 155 deletions.
2 changes: 1 addition & 1 deletion docs/build-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,5 @@ if (BuildServerDetector.Detected)
});
}
```
<sup><a href='/src/Verify.Tests/Snippets/Snippets.cs#L75-L89' title='Snippet source file'>snippet source</a> | <a href='#snippet-derivepathinfoappveyor' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Snippets/Snippets.cs#L66-L80' title='Snippet source file'>snippet source</a> | <a href='#snippet-derivepathinfoappveyor' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->
30 changes: 16 additions & 14 deletions docs/clipboard.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,24 @@ Verify makes use of the clipboard.

This is done via the [TextCopy project](https://github.com/CopyText/TextCopy).

Clipboard support is shipped via the [Verify.ClipboardAccept nuget](https://www.nuget.org/packages/Verify.ClipboardAccept/).

**An alternative to using the clipboard is the [DiffEngineTray tool](https://github.com/VerifyTests/DiffEngine/blob/master/docs/tray.md).**


## Enable

The clipboard behavior can be enabled using the following:

<!-- snippet: EnableClipboard -->
<a id='snippet-enableclipboard'></a>
```cs
ClipboardAccept.Enable();
```
<sup><a href='/src/Verify.Integration.Tests/Tests.cs#L12-L16' title='Snippet source file'>snippet source</a> | <a href='#snippet-enableclipboard' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


## Accept received

When a verification fails, a command to accept the received version is added to the clipboard:
Expand All @@ -29,7 +44,7 @@ On Linux or OS:

## Cleanup dangling converter files

When the number of files outputted from a [converter](converter.mc) reduces, a command to delete the extra files is added to the clipboard:
When the number of files outputted from a [converter](converter.md) reduces, a command to delete the extra files is added to the clipboard:

On Windows:

Expand All @@ -55,19 +70,6 @@ Add a variable named `Verify.MoveCommand` where `{0}` and `{1}` will be replaced
Add a variable named `Verify.DeleteCommand` where `{0}` will be replaced with the file to be cleaned up.


## Disable Clipboard

The clipboard behavior can be disabled using the following:

<!-- snippet: DisableClipboardGlobal -->
<a id='snippet-disableclipboardglobal'></a>
```cs
VerifierSettings.DisableClipboard();
```
<sup><a href='/src/Verify.Tests/Snippets/Snippets.cs#L50-L54' title='Snippet source file'>snippet source</a> | <a href='#snippet-disableclipboardglobal' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


### For a machine

Set a `Verify_DisableClipboard` environment variable to `true`. This overrides the above settings.
18 changes: 10 additions & 8 deletions docs/mdsource/clipboard.source.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,18 @@ Verify makes use of the clipboard.

This is done via the [TextCopy project](https://github.com/CopyText/TextCopy).

Clipboard support is shipped via the [Verify.ClipboardAccept nuget](https://www.nuget.org/packages/Verify.ClipboardAccept/).

**An alternative to using the clipboard is the [DiffEngineTray tool](https://github.com/VerifyTests/DiffEngine/blob/master/docs/tray.md).**


## Enable

The clipboard behavior can be enabled using the following:

snippet: EnableClipboard


## Accept received

When a verification fails, a command to accept the received version is added to the clipboard:
Expand All @@ -22,7 +31,7 @@ On Linux or OS:

## Cleanup dangling converter files

When the number of files outputted from a [converter](converter.mc) reduces, a command to delete the extra files is added to the clipboard:
When the number of files outputted from a [converter](converter.md) reduces, a command to delete the extra files is added to the clipboard:

On Windows:

Expand All @@ -48,13 +57,6 @@ Add a variable named `Verify.MoveCommand` where `{0}` and `{1}` will be replaced
Add a variable named `Verify.DeleteCommand` where `{0}` will be replaced with the file to be cleaned up.


## Disable Clipboard

The clipboard behavior can be disabled using the following:

snippet: DisableClipboardGlobal


### For a machine

Set a `Verify_DisableClipboard` environment variable to `true`. This overrides the above settings.
2 changes: 1 addition & 1 deletion docs/naming.md
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ VerifierSettings.DerivePathInfo(
methodName: method.Name);
});
```
<sup><a href='/src/Verify.Tests/Snippets/Snippets.cs#L59-L70' title='Snippet source file'>snippet source</a> | <a href='#snippet-derivepathinfo' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Snippets/Snippets.cs#L50-L61' title='Snippet source file'>snippet source</a> | <a href='#snippet-derivepathinfo' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Return null to any of the values to use the standard behavior. The returned path can be relative to the directory sourceFile exists in.
Expand Down
8 changes: 4 additions & 4 deletions docs/serializer-settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ VerifierSettings.AddExtraSettings(_ =>
_.TypeNameHandling = TypeNameHandling.All;
});
```
<sup><a href='/src/Verify.Tests/Snippets/Snippets.cs#L114-L121' title='Snippet source file'>snippet source</a> | <a href='#snippet-extrasettingsglobal' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Snippets/Snippets.cs#L105-L112' title='Snippet source file'>snippet source</a> | <a href='#snippet-extrasettingsglobal' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


Expand All @@ -546,7 +546,7 @@ settings.AddExtraSettings(_ =>
_.TypeNameHandling = TypeNameHandling.All;
});
```
<sup><a href='/src/Verify.Tests/Snippets/Snippets.cs#L123-L131' title='Snippet source file'>snippet source</a> | <a href='#snippet-extrasettingsinstance' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Snippets/Snippets.cs#L114-L122' title='Snippet source file'>snippet source</a> | <a href='#snippet-extrasettingsinstance' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


Expand All @@ -566,7 +566,7 @@ class CompanyConverter :
}
}
```
<sup><a href='/src/Verify.Tests/Snippets/Snippets.cs#L147-L158' title='Snippet source file'>snippet source</a> | <a href='#snippet-companyconverter' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Snippets/Snippets.cs#L138-L149' title='Snippet source file'>snippet source</a> | <a href='#snippet-companyconverter' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

<!-- snippet: JsonConverter -->
Expand All @@ -578,7 +578,7 @@ VerifierSettings.AddExtraSettings(
_.Converters.Add(new CompanyConverter());
});
```
<sup><a href='/src/Verify.Tests/Snippets/Snippets.cs#L136-L144' title='Snippet source file'>snippet source</a> | <a href='#snippet-jsonconverter' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Snippets/Snippets.cs#L127-L135' title='Snippet source file'>snippet source</a> | <a href='#snippet-jsonconverter' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


Expand Down
2 changes: 1 addition & 1 deletion docs/verify-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ This can be done using `AutoVerify()`:
var settings = new VerifySettings();
settings.AutoVerify();
```
<sup><a href='/src/Verify.Tests/Snippets/Snippets.cs#L94-L99' title='Snippet source file'>snippet source</a> | <a href='#snippet-autoverify' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Snippets/Snippets.cs#L85-L90' title='Snippet source file'>snippet source</a> | <a href='#snippet-autoverify' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Note that auto accepted changes in `.verified.` files remain visible in source control tooling.
Expand Down
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ To change this file edit the source file and then run MarkdownSnippets.
[![NuGet Status](https://img.shields.io/nuget/v/Verify.NUnit.svg?label=Verify.NUnit)](https://www.nuget.org/packages/Verify.NUnit/)
[![NuGet Status](https://img.shields.io/nuget/v/Verify.Expecto.svg?label=Verify.Expecto)](https://www.nuget.org/packages/Verify.Expecto/)
[![NuGet Status](https://img.shields.io/nuget/v/Verify.MSTest.svg?label=Verify.MSTest)](https://www.nuget.org/packages/Verify.MSTest/)
[![NuGet Status](https://img.shields.io/nuget/v/Verify.MSTest.svg?label=Verify.ClipboardAccept)](https://www.nuget.org/packages/Verify.ClipboardAccept/)

Verify is a snapshot tool that simplifies the assertion of complex data models and documents.

Expand Down
1 change: 1 addition & 0 deletions readme.source.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
[![NuGet Status](https://img.shields.io/nuget/v/Verify.NUnit.svg?label=Verify.NUnit)](https://www.nuget.org/packages/Verify.NUnit/)
[![NuGet Status](https://img.shields.io/nuget/v/Verify.Expecto.svg?label=Verify.Expecto)](https://www.nuget.org/packages/Verify.Expecto/)
[![NuGet Status](https://img.shields.io/nuget/v/Verify.MSTest.svg?label=Verify.MSTest)](https://www.nuget.org/packages/Verify.MSTest/)
[![NuGet Status](https://img.shields.io/nuget/v/Verify.MSTest.svg?label=Verify.ClipboardAccept)](https://www.nuget.org/packages/Verify.ClipboardAccept/)

Verify is a snapshot tool that simplifies the assertion of complex data models and documents.

Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project>
<PropertyGroup>
<NoWarn>CS1591;CS0649;xUnit1026;xUnit1013;msb3277;CS0436</NoWarn>
<Version>15.2.1</Version>
<Version>16.0.0</Version>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>10</LangVersion>
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
Expand Down
37 changes: 0 additions & 37 deletions src/DisableClipboard/DisableClipboardTests.cs

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6</TargetFramework>
<TargetFrameworks>net6</TargetFrameworks>
</PropertyGroup>
<PropertyGroup Condition=" '$(OS)' == 'Windows_NT' ">
<TargetFrameworks>net48;net6</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="Xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" PrivateAssets="all" />
<PackageReference Include="ProjectDefaults" Version="1.0.68" PrivateAssets="all" />
<ProjectReference Include="..\Verify.ClipboardAccept\Verify.ClipboardAccept.csproj" />
<ProjectReference Include="..\Verify.Xunit\Verify.Xunit.csproj" />
<ProjectReference Include="..\Verify\Verify.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
using System.Runtime.InteropServices;
using DiffEngine;
using TextCopy;

static class ClipboardCapture
namespace VerifyTests;

public static class ClipboardAccept
{
static StringBuilder builder = new();
static SemaphoreSlim semaphore = new(1, 1);

static string moveCommand;
static string deleteCommand;

static ClipboardCapture()
public static void Enable()
{
VerifierSettings.OnFirstVerify(AppendMove);
VerifierSettings.OnDelete(AppendDelete);
VerifierSettings.OnVerifyMismatch((file, _) => AppendMove(file));
}

static Task AppendMove(FilePair file)
{
return Append(string.Format(moveCommand, file.ReceivedPath, file.VerifiedPath));
}

static ClipboardAccept()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
Expand All @@ -35,28 +50,33 @@ static ClipboardCapture()
}
}

public static void Clear()
internal static void Clear()
{
builder = new();
}

public static string Read()
internal static string Read()
{
return builder.ToString();
}

public static Task AppendMove(string received, string verified)
{
return Append(string.Format(moveCommand, received, verified));
}

public static Task AppendDelete(string verified)
internal static Task AppendDelete(string verified)
{
return Append(string.Format(deleteCommand, verified));
}

static async Task Append(string command)
{
if (!ClipboardEnabled.IsEnabled())
{
return;
}

if (DiffEngineTray.IsRunning)
{
return;
}

await semaphore.WaitAsync();

try
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
using DiffEngine;
using VerifyTests;

static class ClipboardEnabled
{
static bool clipboardDisabled;
static bool clipboardDisabledInEnv;

static ClipboardEnabled()
{
var disabledText = Environment.GetEnvironmentVariable("Verify_DisableClipboard");
clipboardDisabled = ParseEnvironmentVariable(disabledText);
clipboardDisabledInEnv = ParseEnvironmentVariable(disabledText);
}

public static bool ParseEnvironmentVariable(string? disabledText)
Expand All @@ -28,21 +27,9 @@ public static bool ParseEnvironmentVariable(string? disabledText)

public static bool IsEnabled()
{
if (clipboardDisabled)
{
return false;
}

if (BuildServerDetector.Detected)
{
return false;
}

if (ContinuousTestingDetector.Detected)
{
return false;
}

return !VerifierSettings.clipboardDisabled;
return !(
clipboardDisabledInEnv ||
ContinuousTestingDetector.Detected ||
BuildServerDetector.Detected);
}
}
11 changes: 11 additions & 0 deletions src/Verify.ClipboardAccept/InternalsVisibleTo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[assembly:InternalsVisibleTo("Shared, PublicKey=00240000048000009400000006020000002400005253413100040000010001000f0a8e4bf1639dce01be6592384e7dfc621915b7759fb5cee42ec5d351bcc43460432da1659ee618ca6cab6b8b8e56a5deb5d4ee1a49783d5c2690752502d31ccbfee9b2c697e20359b55ad100cc9370c8e983fd9496f01d761a060d0435bac7243b1832ba95757aa5adbb67df38c213d717b6751e1217cea9fa5c61e9b799dd")]
[assembly:InternalsVisibleTo("Verify.Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001000f0a8e4bf1639dce01be6592384e7dfc621915b7759fb5cee42ec5d351bcc43460432da1659ee618ca6cab6b8b8e56a5deb5d4ee1a49783d5c2690752502d31ccbfee9b2c697e20359b55ad100cc9370c8e983fd9496f01d761a060d0435bac7243b1832ba95757aa5adbb67df38c213d717b6751e1217cea9fa5c61e9b799dd")]
[assembly:InternalsVisibleTo("Verify.MSTest, PublicKey=00240000048000009400000006020000002400005253413100040000010001000f0a8e4bf1639dce01be6592384e7dfc621915b7759fb5cee42ec5d351bcc43460432da1659ee618ca6cab6b8b8e56a5deb5d4ee1a49783d5c2690752502d31ccbfee9b2c697e20359b55ad100cc9370c8e983fd9496f01d761a060d0435bac7243b1832ba95757aa5adbb67df38c213d717b6751e1217cea9fa5c61e9b799dd")]
[assembly:InternalsVisibleTo("Verify.Xunit, PublicKey=00240000048000009400000006020000002400005253413100040000010001000f0a8e4bf1639dce01be6592384e7dfc621915b7759fb5cee42ec5d351bcc43460432da1659ee618ca6cab6b8b8e56a5deb5d4ee1a49783d5c2690752502d31ccbfee9b2c697e20359b55ad100cc9370c8e983fd9496f01d761a060d0435bac7243b1832ba95757aa5adbb67df38c213d717b6751e1217cea9fa5c61e9b799dd")]
[assembly:InternalsVisibleTo("Verify.NUnit, PublicKey=00240000048000009400000006020000002400005253413100040000010001000f0a8e4bf1639dce01be6592384e7dfc621915b7759fb5cee42ec5d351bcc43460432da1659ee618ca6cab6b8b8e56a5deb5d4ee1a49783d5c2690752502d31ccbfee9b2c697e20359b55ad100cc9370c8e983fd9496f01d761a060d0435bac7243b1832ba95757aa5adbb67df38c213d717b6751e1217cea9fa5c61e9b799dd")]
[assembly:InternalsVisibleTo("Verify.Integration.Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001000f0a8e4bf1639dce01be6592384e7dfc621915b7759fb5cee42ec5d351bcc43460432da1659ee618ca6cab6b8b8e56a5deb5d4ee1a49783d5c2690752502d31ccbfee9b2c697e20359b55ad100cc9370c8e983fd9496f01d761a060d0435bac7243b1832ba95757aa5adbb67df38c213d717b6751e1217cea9fa5c61e9b799dd")]
[assembly:InternalsVisibleTo("StrictJsonTests, PublicKey=00240000048000009400000006020000002400005253413100040000010001000f0a8e4bf1639dce01be6592384e7dfc621915b7759fb5cee42ec5d351bcc43460432da1659ee618ca6cab6b8b8e56a5deb5d4ee1a49783d5c2690752502d31ccbfee9b2c697e20359b55ad100cc9370c8e983fd9496f01d761a060d0435bac7243b1832ba95757aa5adbb67df38c213d717b6751e1217cea9fa5c61e9b799dd")]
[assembly:InternalsVisibleTo("NamingTests, PublicKey=00240000048000009400000006020000002400005253413100040000010001000f0a8e4bf1639dce01be6592384e7dfc621915b7759fb5cee42ec5d351bcc43460432da1659ee618ca6cab6b8b8e56a5deb5d4ee1a49783d5c2690752502d31ccbfee9b2c697e20359b55ad100cc9370c8e983fd9496f01d761a060d0435bac7243b1832ba95757aa5adbb67df38c213d717b6751e1217cea9fa5c61e9b799dd")]
[assembly:InternalsVisibleTo("Verify.Expecto, PublicKey=00240000048000009400000006020000002400005253413100040000010001000f0a8e4bf1639dce01be6592384e7dfc621915b7759fb5cee42ec5d351bcc43460432da1659ee618ca6cab6b8b8e56a5deb5d4ee1a49783d5c2690752502d31ccbfee9b2c697e20359b55ad100cc9370c8e983fd9496f01d761a060d0435bac7243b1832ba95757aa5adbb67df38c213d717b6751e1217cea9fa5c61e9b799dd")]
[assembly:InternalsVisibleTo("Verify.ClipboardAccept.Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001000f0a8e4bf1639dce01be6592384e7dfc621915b7759fb5cee42ec5d351bcc43460432da1659ee618ca6cab6b8b8e56a5deb5d4ee1a49783d5c2690752502d31ccbfee9b2c697e20359b55ad100cc9370c8e983fd9496f01d761a060d0435bac7243b1832ba95757aa5adbb67df38c213d717b6751e1217cea9fa5c61e9b799dd")]
[assembly:InternalsVisibleTo("Verify.ExceptionParsing.Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001000f0a8e4bf1639dce01be6592384e7dfc621915b7759fb5cee42ec5d351bcc43460432da1659ee618ca6cab6b8b8e56a5deb5d4ee1a49783d5c2690752502d31ccbfee9b2c697e20359b55ad100cc9370c8e983fd9496f01d761a060d0435bac7243b1832ba95757aa5adbb67df38c213d717b6751e1217cea9fa5c61e9b799dd")]
13 changes: 13 additions & 0 deletions src/Verify.ClipboardAccept/Verify.ClipboardAccept.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<Using Remove="System.Net.Http" />
<PackageReference Include="DiffEngine" Version="8.5.3" />
<PackageReference Include="TextCopy" Version="6.1.0" />
<PackageReference Include="ProjectDefaults" Version="1.0.68" PrivateAssets="all" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" Condition="$(Configuration) == 'Release'" />
<ProjectReference Include="..\Verify\Verify.csproj" />
</ItemGroup>
</Project>
Loading

0 comments on commit 25221a2

Please sign in to comment.