-
-
Notifications
You must be signed in to change notification settings - Fork 159
/
Copy pathVerifier.cs
46 lines (40 loc) · 1.87 KB
/
Verifier.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// ReSharper disable UnusedParameter.Local
#pragma warning disable VerifyTestsProjectDir
namespace VerifyMSTest;
public partial class Verifier
{
static DerivePathInfo derivePathInfo = PathInfo.DeriveDefault;
internal static PathInfo GetPathInfo(string sourceFile, Type type, MethodInfo method) =>
derivePathInfo(sourceFile, VerifierSettings.ProjectDir, type, method);
/// <summary>
/// Use custom path information for `.verified.` files.
/// </summary>
/// <remarks>
/// This is sometimes needed on CI systems that move/remove the original source.
/// To move to this approach, any existing `.verified.` files will need to be moved to the new directory
/// </remarks>
/// <param name="derivePathInfo">Custom callback to control the behavior.</param>
public static void DerivePathInfo(DerivePathInfo derivePathInfo)
{
InnerVerifier.ThrowIfVerifyHasBeenRun();
Verifier.derivePathInfo = derivePathInfo;
}
/// <summary>
/// Use a directory relative to the project directory for storing for `.verified.` files.
/// </summary>
public static void UseProjectRelativeDirectory(string directory) =>
DerivePathInfo(
(sourceFile, projectDirectory, type, method) => new(
directory: Path.Combine(projectDirectory, directory),
typeName: type.NameWithParent(),
methodName: method.Name));
/// <summary>
/// Use a directory relative to the source file directory for storing for `.verified.` files.
/// </summary>
public static void UseSourceFileRelativeDirectory(string directory) =>
DerivePathInfo(
(sourceFile, projectDirectory, type, method) => new(
directory: Path.Combine(Path.GetDirectoryName(sourceFile)!, directory),
typeName: type.NameWithParent(),
methodName: method.Name));
}