Skip to content

Commit fbfc590

Browse files
authored
ensure DerivePathInfo is only called once (#1430)
1 parent 4b235b5 commit fbfc590

File tree

11 files changed

+55
-9
lines changed

11 files changed

+55
-9
lines changed

src/Verify.Expecto/DerivePaths/Verifier.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@ internal static PathInfo GetPathInfo(string sourceFile, string typeName, string
1818
/// To move to this approach, any existing `.verified.` files will need to be moved to the new directory
1919
/// </remarks>
2020
/// <param name="derivePathInfo">Custom callback to control the behavior.</param>
21-
public static void DerivePathInfo(DerivePathInfo derivePathInfo) =>
21+
public static void DerivePathInfo(DerivePathInfo derivePathInfo)
22+
{
23+
InnerVerifier.ThrowIfVerifyHasBeenRun();
2224
Verifier.derivePathInfo = derivePathInfo;
25+
}
2326

2427
/// <summary>
2528
/// Use a directory relative to the project directory for storing for `.verified.` files.

src/Verify.Fixie/DerivePaths/Verifier.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@ internal static PathInfo GetPathInfo(string sourceFile, Type type, MethodInfo me
1818
/// To move to this approach, any existing `.verified.` files will need to be moved to the new directory
1919
/// </remarks>
2020
/// <param name="derivePathInfo">Custom callback to control the behavior.</param>
21-
public static void DerivePathInfo(DerivePathInfo derivePathInfo) =>
21+
public static void DerivePathInfo(DerivePathInfo derivePathInfo)
22+
{
23+
InnerVerifier.ThrowIfVerifyHasBeenRun();
2224
Verifier.derivePathInfo = derivePathInfo;
25+
}
2326

2427
/// <summary>
2528
/// Use a directory relative to the project directory for storing for `.verified.` files.

src/Verify.MSTest.DerivePaths.Tests/Tests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ public partial class Tests
55
[TestMethod]
66
public Task Test()
77
{
8+
VerifierSettings.Reset();
89
DerivePathInfo(
910
(sourceFile, projectDirectory, methodName, typeName) =>
1011
{
@@ -26,27 +27,31 @@ public Task Test()
2627
[TestMethod]
2728
public Task ReturnNulls()
2829
{
30+
VerifierSettings.Reset();
2931
DerivePathInfo((_, _, _, _) => new(null));
3032
return Verify("Value");
3133
}
3234

3335
[TestMethod]
3436
public Task ProjectRelativeDirectory()
3537
{
38+
VerifierSettings.Reset();
3639
UseProjectRelativeDirectory("Relative");
3740
return Verify("Value");
3841
}
3942

4043
[TestMethod]
4144
public Task SourceFileRelativeDirectory()
4245
{
46+
VerifierSettings.Reset();
4347
UseSourceFileRelativeDirectory("Relative");
4448
return Verify("Value");
4549
}
4650

4751
[TestMethod]
4852
public Task InvalidMethod()
4953
{
54+
VerifierSettings.Reset();
5055
DerivePathInfo((_, _, _, _) => new(null, null, Path
5156
.GetInvalidFileNameChars()
5257
.First()
@@ -57,6 +62,7 @@ public Task InvalidMethod()
5762
[TestMethod]
5863
public Task InvalidType()
5964
{
65+
VerifierSettings.Reset();
6066
DerivePathInfo((_, _, _, _) => new(null, Path
6167
.GetInvalidFileNameChars()
6268
.First()
@@ -67,6 +73,7 @@ public Task InvalidType()
6773
[TestMethod]
6874
public Task InvalidDirectory()
6975
{
76+
VerifierSettings.Reset();
7077
DerivePathInfo((_, _, _, _) => new(Path
7178
.GetInvalidPathChars()
7279
.First()

src/Verify.MSTest/DerivePaths/Verifier.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@ internal static PathInfo GetPathInfo(string sourceFile, Type type, MethodInfo me
1818
/// To move to this approach, any existing `.verified.` files will need to be moved to the new directory
1919
/// </remarks>
2020
/// <param name="derivePathInfo">Custom callback to control the behavior.</param>
21-
public static void DerivePathInfo(DerivePathInfo derivePathInfo) =>
21+
public static void DerivePathInfo(DerivePathInfo derivePathInfo)
22+
{
23+
InnerVerifier.ThrowIfVerifyHasBeenRun();
2224
Verifier.derivePathInfo = derivePathInfo;
25+
}
2326

2427
/// <summary>
2528
/// Use a directory relative to the project directory for storing for `.verified.` files.

src/Verify.NUnit.DerivePaths.Tests/Tests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ public class Tests
66
[Test]
77
public Task Test()
88
{
9+
VerifierSettings.Reset();
910
DerivePathInfo(
1011
(sourceFile, projectDirectory, methodName, typeName) =>
1112
{
@@ -23,27 +24,31 @@ public Task Test()
2324
[Test]
2425
public Task ReturnNulls()
2526
{
27+
VerifierSettings.Reset();
2628
DerivePathInfo((_, _, _, _) => new(null));
2729
return Verify("Value");
2830
}
2931

3032
[Test]
3133
public Task ProjectRelativeDirectory()
3234
{
35+
VerifierSettings.Reset();
3336
UseProjectRelativeDirectory("Relative");
3437
return Verify("Value");
3538
}
3639

3740
[Test]
3841
public Task SourceFileRelativeDirectory()
3942
{
43+
VerifierSettings.Reset();
4044
UseSourceFileRelativeDirectory("Relative");
4145
return Verify("Value");
4246
}
4347

4448
[Test]
4549
public void InvalidMethod()
4650
{
51+
VerifierSettings.Reset();
4752
DerivePathInfo((_, _, _, _) => new(null, null, Path
4853
.GetInvalidFileNameChars()
4954
.First()
@@ -54,6 +59,7 @@ public void InvalidMethod()
5459
[Test]
5560
public void InvalidType()
5661
{
62+
VerifierSettings.Reset();
5763
DerivePathInfo((_, _, _, _) => new(null, Path
5864
.GetInvalidFileNameChars()
5965
.First()
@@ -64,6 +70,7 @@ public void InvalidType()
6470
[Test]
6571
public void InvalidDirectory()
6672
{
73+
VerifierSettings.Reset();
6774
DerivePathInfo((_, _, _, _) => new(Path
6875
.GetInvalidPathChars()
6976
.First()

src/Verify.NUnit/DerivePaths/Verifier.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@ internal static PathInfo GetPathInfo(string sourceFile, Type type, MethodInfo me
1818
/// To move to this approach, any existing `.verified.` files will need to be moved to the new directory
1919
/// </remarks>
2020
/// <param name="derivePathInfo">Custom callback to control the behavior.</param>
21-
public static void DerivePathInfo(DerivePathInfo derivePathInfo) =>
21+
public static void DerivePathInfo(DerivePathInfo derivePathInfo)
22+
{
23+
InnerVerifier.ThrowIfVerifyHasBeenRun();
2224
Verifier.derivePathInfo = derivePathInfo;
25+
}
2326

2427
/// <summary>
2528
/// Use a directory relative to the project directory for storing for `.verified.` files.

src/Verify.TUnit/DerivePaths/Verifier.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@ internal static PathInfo GetPathInfo(string sourceFile, Type type, MethodInfo me
1818
/// To move to this approach, any existing `.verified.` files will need to be moved to the new directory
1919
/// </remarks>
2020
/// <param name="derivePathInfo">Custom callback to control the behavior.</param>
21-
public static void DerivePathInfo(DerivePathInfo derivePathInfo) =>
21+
public static void DerivePathInfo(DerivePathInfo derivePathInfo)
22+
{
23+
InnerVerifier.ThrowIfVerifyHasBeenRun();
2224
Verifier.derivePathInfo = derivePathInfo;
25+
}
2326

2427
/// <summary>
2528
/// Use a directory relative to the project directory for storing for `.verified.` files.

src/Verify.Xunit.DerivePaths.Tests/Tests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
[Fact]
44
public Task Test()
55
{
6+
VerifierSettings.Reset();
67
DerivePathInfo(
78
(sourceFile, projectDirectory, methodName, typeName) =>
89
{
@@ -20,27 +21,31 @@ public Task Test()
2021
[Fact]
2122
public Task ReturnNulls()
2223
{
24+
VerifierSettings.Reset();
2325
DerivePathInfo((_, _, _, _) => new(null));
2426
return Verify("Value");
2527
}
2628

2729
[Fact]
2830
public Task ProjectRelativeDirectory()
2931
{
32+
VerifierSettings.Reset();
3033
UseProjectRelativeDirectory("Relative");
3134
return Verify("Value");
3235
}
3336

3437
[Fact]
3538
public Task SourceFileRelativeDirectory()
3639
{
40+
VerifierSettings.Reset();
3741
UseSourceFileRelativeDirectory("Relative");
3842
return Verify("Value");
3943
}
4044

4145
[Fact]
4246
public Task InvalidMethod()
4347
{
48+
VerifierSettings.Reset();
4449
DerivePathInfo((_, _, _, _) => new(null, null, Path
4550
.GetInvalidFileNameChars()
4651
.First()
@@ -51,6 +56,7 @@ public Task InvalidMethod()
5156
[Fact]
5257
public Task InvalidType()
5358
{
59+
VerifierSettings.Reset();
5460
DerivePathInfo((_, _, _, _) => new(null, Path
5561
.GetInvalidFileNameChars()
5662
.First()
@@ -61,6 +67,7 @@ public Task InvalidType()
6167
[Fact]
6268
public Task InvalidDirectory()
6369
{
70+
VerifierSettings.Reset();
6471
DerivePathInfo((_, _, _, _) => new(Path
6572
.GetInvalidPathChars()
6673
.First()

src/Verify.Xunit/DerivePaths/Verifier.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@ internal static PathInfo GetPathInfo(string sourceFile, Type type, MethodInfo me
1818
/// To move to this approach, any existing `.verified.` files will need to be moved to the new directory
1919
/// </remarks>
2020
/// <param name="derivePathInfo">Custom callback to control the behavior.</param>
21-
public static void DerivePathInfo(DerivePathInfo derivePathInfo) =>
21+
public static void DerivePathInfo(DerivePathInfo derivePathInfo)
22+
{
23+
InnerVerifier.ThrowIfVerifyHasBeenRun();
2224
Verifier.derivePathInfo = derivePathInfo;
25+
}
2326

2427
/// <summary>
2528
/// Use a directory relative to the project directory for storing for `.verified.` files.

src/Verify.XunitV3/DerivePaths/Verifier.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@ internal static PathInfo GetPathInfo(string sourceFile, Type type, MethodInfo me
1818
/// To move to this approach, any existing `.verified.` files will need to be moved to the new directory
1919
/// </remarks>
2020
/// <param name="derivePathInfo">Custom callback to control the behavior.</param>
21-
public static void DerivePathInfo(DerivePathInfo derivePathInfo) =>
21+
public static void DerivePathInfo(DerivePathInfo derivePathInfo)
22+
{
23+
InnerVerifier.ThrowIfVerifyHasBeenRun();
2224
Verifier.derivePathInfo = derivePathInfo;
25+
}
2326

2427
/// <summary>
2528
/// Use a directory relative to the project directory for storing for `.verified.` files.

0 commit comments

Comments
 (0)