Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions IconHelper.Test/ProcessDirectoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,45 @@ public void SkipsFilesAlreadyMarkedAsGenerated()
Assert.IsFalse(File.Exists(Path.Combine(output, "already.new.png")));
}

[TestMethod]
public void SkipsOnTheFileNameRatherThanTheContainingPath()
{
using TempDirectory temp = new();
// The marker is in the directory name, and in no file name. Directory.GetFiles hands back
// full paths, so testing the whole string made every file below such a directory look
// already generated -- nothing written, and exit 0 to say so.
string input = temp.Combine(Path.Combine("icons.new.png.dir", "in"));
Comment thread
matt-edmondson marked this conversation as resolved.
string output = temp.Combine("out");
Directory.CreateDirectory(input);
WritePng(Path.Combine(input, "keep.png"), 64);
Comment thread
matt-edmondson marked this conversation as resolved.
WritePng(Path.Combine(input, "also-keep.png"), 64);
Comment thread
matt-edmondson marked this conversation as resolved.

BatchResult result = IconHelper.ProcessDirectory(ArgumentsFor(input, output), NamedColors.White);

Assert.AreEqual(2, result.Written, "'.new.png' in a parent directory should not skip anything.");
Assert.IsTrue(File.Exists(Path.Combine(output, "keep.png")));
Comment thread
matt-edmondson marked this conversation as resolved.
Assert.IsTrue(File.Exists(Path.Combine(output, "also-keep.png")));
Comment thread
matt-edmondson marked this conversation as resolved.
}

[TestMethod]
public void SkipsOnTheFileNameEvenBelowAMatchingPath()
{
using TempDirectory temp = new();
// Both at once, so a fix that stops looking at the path cannot also stop looking at the
// name: the marked file is still skipped, and the unmarked one beside it is still written.
string input = temp.Combine(Path.Combine("icons.new.png.dir", "in"));
Comment thread
matt-edmondson marked this conversation as resolved.
string output = temp.Combine("out");
Directory.CreateDirectory(input);
WritePng(Path.Combine(input, "keep.png"), 64);
Comment thread
matt-edmondson marked this conversation as resolved.
WritePng(Path.Combine(input, "already.new.png"), 64);
Comment thread
matt-edmondson marked this conversation as resolved.

BatchResult result = IconHelper.ProcessDirectory(ArgumentsFor(input, output), NamedColors.White);

Assert.AreEqual(1, result.Written, "The marked file should be skipped and the other one written.");
Assert.IsTrue(File.Exists(Path.Combine(output, "keep.png")));
Comment thread
matt-edmondson marked this conversation as resolved.
Assert.IsFalse(File.Exists(Path.Combine(output, "already.new.png")));
Comment thread
matt-edmondson marked this conversation as resolved.
}

[TestMethod]
public void ContinuesAfterAFileThatCannotBeDecoded()
{
Expand Down
6 changes: 5 additions & 1 deletion IconHelper/IconHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,11 @@ internal static BatchResult ProcessDirectory(Arguments args, Color color)
System.Collections.ObjectModel.Collection<string> files = Directory.GetFiles(inputDirectory, "*").ToCollection();
foreach (string? file in files)
{
if (file.Contains(".new.png"))
// The name, not the path. Directory.GetFiles hands back full paths, so testing the
// whole string let a directory anywhere above the input -- a user name, a date stamp,
// a project folder -- decide that every file below it was already generated. That
// failure is silent and total: nothing is written and the run still exits 0.
if (Path.GetFileName(file).Contains(".new.png", StringComparison.Ordinal))
{
continue;
}
Expand Down
Loading