Skip to content

Commit

Permalink
Move to underscores for env variables to better support linux
Browse files Browse the repository at this point in the history
fixes #207
  • Loading branch information
SimonCropp committed Sep 11, 2020
1 parent 624839c commit e07a72a
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 17 deletions.
2 changes: 1 addition & 1 deletion docs/clipboard.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,4 @@ settings.EnableClipboard();

### For a machine

Set a `Verify.DisableClipboard` environment variable to `true`. This overrides the above settings.
Set a `Verify_DisableClipboard` environment variable to `true`. This overrides the above settings.
2 changes: 1 addition & 1 deletion docs/mdsource/clipboard.source.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@ snippet: EnableClipboard

### For a machine

Set a `Verify.DisableClipboard` environment variable to `true`. This overrides the above settings.
Set a `Verify_DisableClipboard` environment variable to `true`. This overrides the above settings.
2 changes: 1 addition & 1 deletion src/DeterministicTests/DeterministicTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<IsPackageProject>false</IsPackageProject>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DiffEngine" Version="5.3.1" />
<PackageReference Include="DiffEngine" Version="5.4.0" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.0-preview-20200812-03" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
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</NoWarn>
<Version>6.13.0</Version>
<Version>6.14.0</Version>
<AssemblyVersion>1.0.0</AssemblyVersion>
<PackageTags>Json, Testing, Verify, Snapshot, Approvals</PackageTags>
<Description>Enables verification of complex models and documents.</Description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<GenerateAssemblyInfo>true</GenerateAssemblyInfo>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DiffEngine" Version="5.3.1" />
<PackageReference Include="DiffEngine" Version="5.4.0" />
<PackageReference Include="InfoOf.Fody" Version="2.0.1" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.0-preview-20200812-03" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
UserMessage: 'Could not convert `Verify.DisableClipboard` environment variable to a bool. Value: foo',
Message: 'Could not convert `Verify.DisableClipboard` environment variable to a bool. Value: foo',
UserMessage: 'Could not convert `Verify_DisableClipboard` environment variable to a bool. Value: foo',
Message: 'Could not convert `Verify_DisableClipboard` environment variable to a bool. Value: foo',
Data: {},
Source: 'Verify'
}
2 changes: 1 addition & 1 deletion src/Verify.Tests/Verify.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<Compile Remove="Converters\TypeConverterTests.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="DiffEngine" Version="5.3.1" />
<PackageReference Include="DiffEngine" Version="5.4.0" />
<PackageReference Include="Shipwreck.Phash.Bitmaps" Version="0.5.0" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.0-preview-20200812-03" />
Expand Down
7 changes: 3 additions & 4 deletions src/Verify/Clipboard/ClipboardCapture.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
Expand All @@ -26,13 +25,13 @@ static ClipboardCapture()
deleteCommand = "rm -f \"{0}\"";
}

var envMoveCommand = Environment.GetEnvironmentVariable("Verify.MoveCommand");
var envMoveCommand = EnvironmentEx.GetEnvironmentVariable("Verify_MoveCommand");
if (envMoveCommand != null)
{
moveCommand = envMoveCommand;
}

var envDeleteCommand = Environment.GetEnvironmentVariable("Verify.DeleteCommand");
var envDeleteCommand = EnvironmentEx.GetEnvironmentVariable("Verify_DeleteCommand");
if (envDeleteCommand != null)
{
deleteCommand = envDeleteCommand;
Expand Down
7 changes: 3 additions & 4 deletions src/Verify/Clipboard/ClipboardEnabled.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using System;
using VerifyTests;
using VerifyTests;

static class ClipboardEnabled
{
static bool clipboardDisabled;

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

Expand All @@ -23,7 +22,7 @@ public static bool ParseEnvironmentVariable(string? disabledText)
return disabled;
}

throw InnerVerifier.exceptionBuilder($"Could not convert `Verify.DisableClipboard` environment variable to a bool. Value: {disabledText}");
throw InnerVerifier.exceptionBuilder($"Could not convert `Verify_DisableClipboard` environment variable to a bool. Value: {disabledText}");
}

public static bool IsEnabled(VerifySettings settings)
Expand Down
24 changes: 24 additions & 0 deletions src/Verify/EnvironmentEx.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Diagnostics;

static class EnvironmentEx
{
public static string? GetEnvironmentVariable(string name)
{
var variable = Environment.GetEnvironmentVariable(name);
if (variable != null)
{
return variable;
}

var replace = name.Replace('_', '.');
variable = Environment.GetEnvironmentVariable(replace);
if (variable != null)
{
Trace.WriteLine($"Found environment variable '{replace}'. Should use '{name}' instead.");
return variable;
}

return variable;
}
}
2 changes: 1 addition & 1 deletion src/Verify/Verify.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<TargetFrameworks>netstandard2.0;netstandard2.1;net472</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DiffEngine" Version="5.3.1" />
<PackageReference Include="DiffEngine" Version="5.4.0" />
<PackageReference Include="Fody" Version="6.2.5" PrivateAssets="All" />
<PackageReference Include="Obsolete.Fody" Version="5.2.1" PrivateAssets="All" />
<PackageReference Include="System.CodeDom" Version="4.7.0" />
Expand Down

0 comments on commit e07a72a

Please sign in to comment.