Skip to content

Commit

Permalink
Addition changes to enable Verify.Cli app
Browse files Browse the repository at this point in the history
- Add simple constructor to InnerVerifier for just comparing files
- Ensure replacements field is valid even if we haven't called UseAssembly
  • Loading branch information
flcdrg committed May 21, 2023
1 parent ba5f4eb commit 85ab34e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Verify/Serialization/Scrubbers/ApplyScrubbers.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// ReSharper disable RedundantSuppressNullableWarningExpression
// ReSharper disable RedundantSuppressNullableWarningExpression

static class ApplyScrubbers
{
static char dirSeparator = Path.DirectorySeparatorChar;
static char altDirSeparator = Path.AltDirectorySeparatorChar;
static List<KeyValuePair<string, string>> replacements = null!;
static List<KeyValuePair<string, string>> replacements = new List<KeyValuePair<string, string>>();

static string ReplaceAltDirChar(this string directory) =>
directory.Replace(dirSeparator, altDirSeparator);
Expand Down Expand Up @@ -55,7 +55,7 @@ public static void UseAssembly(string? solutionDir, string projectDir)
}

AddProjectAndSolutionReplacements(solutionDir, projectDir, replacements);
ApplyScrubbers.replacements = replacements.OrderByDescending(_ => _.Key).ToList();
ApplyScrubbers.replacements.AddRange(replacements.OrderByDescending(_ => _.Key));
}

static void AddProjectAndSolutionReplacements(string? solutionDir, string projectDir, Dictionary<string, string> replacements)
Expand Down
32 changes: 32 additions & 0 deletions src/Verify/Verifier/InnerVerifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,38 @@ public InnerVerifier(
}
}

public InnerVerifier(string sourceFile, VerifySettings settings)
{
Guard.AgainstEmpty(sourceFile);

this.settings = settings;
directory = ResolveDirectory(sourceFile, settings, new());

counter = Counter.Start(
#if NET6_0_OR_GREATER
settings.namedDates,
settings.namedTimes,
#endif
settings.namedDateTimes,
settings.namedGuids,
settings.namedDateTimeOffsets
);

IoHelpers.CreateDirectory(directory);

ValidatePrefix(settings, directory);

verifiedFiles = new List<string> { Path.Combine(directory, $"{Path.GetFileNameWithoutExtension(sourceFile)}.verified.{Path.GetExtension(sourceFile)}") };

getFileNames = target => new(
target.Extension,
sourceFile,
Path.Combine(directory, $"{Path.GetFileNameWithoutExtension(sourceFile)}.verified.{target.Extension}")
);

getIndexedFileNames = (_, _) => throw new NotImplementedException();
}

void InitForDirectoryConvention(Namer namer, string typeAndMethod, string parameters)
{
var verifiedPrefix = PrefixForDirectoryConvention(namer, typeAndMethod, parameters);
Expand Down

0 comments on commit 85ab34e

Please sign in to comment.