Skip to content

Commit 93bc4c0

Browse files
committed
Added EnvironmentReader to control automatic test rewrite from the environment
1 parent f0f260d commit 93bc4c0

File tree

11 files changed

+106
-10
lines changed

11 files changed

+106
-10
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,20 @@
44

55
Full documentation on usage and motivating examples at https://github.com/kbilsted/StatePrinter/tree/master/doc
66

7+
## v2.1.207-rc
8+
9+
Added
10+
11+
* Functionality for controlling automatic test rewrite using an environment variable.
12+
13+
714
## v2.1.198-rc
815

916
Added
1017

1118
* Functionality for including or excluding fields and properties based on one or more type descriptions. See IncludeByType() and ExcludeByType()
1219

20+
1321
## v2.1.186
1422

1523
Fixed

DeployToNuget.cmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ REM ON FIRST RUN, RUN THIS (change the key to whatever is found on your profile
22
REM .nuget\NuGet.exe setapikey e39ea-get-the-full-key-on-nuget.org
33

44
call CreateNuget.cmd
5-
.nuget\NuGet.exe push nuget_packages\StatePrinter.2.0.*.nupkg
6-
.nuget\NuGet.exe push nuget_packages\StatePrinter.2.0.*.symbols.nupkg
5+
.nuget\NuGet.exe push nuget_packages\StatePrinter.2.*.*.symbols.nupkg
6+
.nuget\NuGet.exe push nuget_packages\StatePrinter.2.*.*.nupkg
77

88
cd nuget_packages
99
del /q *

StatePrinter.Tests/StatePrinter.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
<Compile Include="FieldHarvesters\ToStringAwareHarvesterTest.cs" />
5858
<Compile Include="Introspection\ReferenceTest.cs" />
5959
<Compile Include="Mocks\Mocks.cs" />
60+
<Compile Include="TestingAssistance\EnvironmentReaderTest.cs" />
6061
<Compile Include="TestingAssistance\ParserTest.cs" />
6162
<Compile Include="IntegrationTests\PublicPropertiesTest.cs" />
6263
<Compile Include="IntegrationTests\PropertiesTest.cs" />

StatePrinter.Tests/TestHelper.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ public static Configuration CreateTestConfiguration()
5353
.SetNewlineDefinition(" ")
5454
.SetCulture(CultureInfo.CreateSpecificCulture("da-DK"))
5555
.Test.SetAreEqualsMethod(NUnit.Framework.Assert.AreEqual)
56-
//.Test.SetAutomaticTestRewrite(x => true);
57-
.Test.SetAutomaticTestRewrite(x => false);
56+
.Test.SetAutomaticTestRewrite(x => new EnvironmentReader().UseTestAutoRewrite());
5857

5958
return cfg;
6059
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright 2014-2015 Kasper B. Graversen
2+
//
3+
// Licensed to the Apache Software Foundation (ASF) under one
4+
// or more contributor license agreements. See the NOTICE file
5+
// distributed with this work for additional information
6+
// regarding copyright ownership. The ASF licenses this file
7+
// to you under the Apache License, Version 2.0 (the
8+
// "License"); you may not use this file except in compliance
9+
// with the License. You may obtain a copy of the License at
10+
//
11+
// http://www.apache.org/licenses/LICENSE-2.0
12+
//
13+
// Unless required by applicable law or agreed to in writing,
14+
// software distributed under the License is distributed on an
15+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
// KIND, either express or implied. See the License for the
17+
// specific language governing permissions and limitations
18+
// under the License.
19+
20+
using System;
21+
22+
using NUnit.Framework;
23+
24+
using StatePrinter.TestAssistance;
25+
26+
namespace StatePrinter.Tests.TestingAssistance
27+
{
28+
[TestFixture]
29+
class EnvironmentReaderTest
30+
{
31+
[Test]
32+
public void TestReadUseAutoReWrite()
33+
{
34+
var org = Environment.GetEnvironmentVariable(EnvironmentReader.Usetestautorewrite, EnvironmentVariableTarget.User);
35+
try
36+
{
37+
var reader = new EnvironmentReader();
38+
Assert.AreEqual(false, reader.UseTestAutoRewrite());
39+
40+
Environment.SetEnvironmentVariable(EnvironmentReader.Usetestautorewrite, "true", EnvironmentVariableTarget.User);
41+
Assert.AreEqual(true, reader.UseTestAutoRewrite());
42+
}
43+
finally
44+
{
45+
Environment.SetEnvironmentVariable(EnvironmentReader.Usetestautorewrite, org, EnvironmentVariableTarget.User);
46+
}
47+
}
48+
}
49+
}

StatePrinter.nuspec

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package>
33
<metadata>
44
<id>StatePrinter</id>
5-
<version>2.0.198-rc</version>
5+
<version>2.1.207-rc</version>
66
<description>
77
An open source utility to turn object graphs into strings. Automate your ToString and unit tests asserts.
88
</description>
@@ -12,7 +12,8 @@ Fixed
1212
* [#22 Make error message configurable upon assertion failure](https://github.com/kbilsted/StatePrinter/issues/22)
1313

1414
Added
15-
* Functionality for including or excluding fields and properties based on one or more type descriptions. See IncludeByType() and ExcludeByType()
15+
* Functionality for controlling automatic test rewrite using an environment variable.
16+
* Functionality for including or excluding fields and properties based on one or more type descriptions. See IncludeByType() and ExcludeByType().
1617
* Added `AreAlike`, replacing `IsSame`.
1718
* Made error message tell about `AreAlike` when two strings are alike but not equals.
1819
* Prepared for future expansion of functionality, by placing unit testing configuration in a sub-configuration class.

StatePrinter/Configurations/Configuration.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ public Configuration(
111111
public IOutputFormatter OutputFormatter;
112112

113113

114-
115114
public Configuration SetOutputFormatter(IOutputFormatter formatter)
116115
{
117116
if (formatter == null)

StatePrinter/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,5 @@
5353
// by using the '*' as shown below:
5454
// [assembly: AssemblyVersion("1.0.*")]
5555
[assembly: AssemblyVersion("2.1.0.0")] // Change this upon breaking changes
56-
[assembly: AssemblyFileVersion("2.1.198.0")] // Bump this at every release
57-
[assembly: AssemblyInformationalVersion("2.0.198-rc")] // Customer public info (setting a version across multiple products each possibly with their own versioning)
56+
[assembly: AssemblyFileVersion("2.1.207.0")] // Bump this at every release
57+
[assembly: AssemblyInformationalVersion("2.0.207-rc")] // Customer public info (setting a version across multiple products each possibly with their own versioning)

StatePrinter/StatePrinter.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
<Compile Include="OutputFormatters\OutputFormatterHelpers.cs" />
8585
<Compile Include="Properties\AssemblyInfo.cs" />
8686
<Compile Include="StatePrinter.cs" />
87+
<Compile Include="TestAssistance\EnvironmentReader.cs" />
8788
<Compile Include="TestAssistance\Asserter.cs" />
8889
<Compile Include="TestAssistance\DefaultAssertMessage.cs" />
8990
<Compile Include="TestAssistance\FileRepository.cs" />

StatePrinter/TestAssistance/Asserter.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ void CallUnderlyingAssert(
142142
UnitTestLocationInfo info)
143143
{
144144
var escapedActual = stringUtils.Escape(actual);
145-
bool rewriteTest = info != null && printer.Configuration.Test.AutomaticTestRewrite(info);
145+
bool rewriteTest = info != null
146+
&& printer.Configuration.Test.AutomaticTestRewrite(info);
146147

147148
var message = printer.Configuration.Test.AssertMessageCreator(
148149
expected,

0 commit comments

Comments
 (0)