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
7 changes: 5 additions & 2 deletions src/Heddle.Tests/FileWatcherByteIdentityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ namespace Heddle.Tests
/// </summary>
public class FileWatcherByteIdentityTests
{
// Per-test watched-file stem: isolates this test from concurrent tests and parallel TFM hosts.
private readonly string _stem = FileWatcherTestSupport.NewStem();

private const string Source = "<p>@()</p>|@raw()";
// Pre-recorded baseline for Source with model "<b>x</b>" under the default options (Html profile,
// legacy WebUtility encoder): the unnamed sink encodes, @raw does not.
Expand All @@ -31,8 +34,8 @@ public void FlagOffAndInlineOutputsAreByteIdentical()
var dir = FileWatcherTestSupport.NewTempDir();
try
{
File.WriteAllText(Path.Combine(dir, "home.heddle"), Source);
var options = FileWatcherTestSupport.WatchOptions(dir, "home");
File.WriteAllText(Path.Combine(dir, _stem + ".heddle"), Source);
var options = FileWatcherTestSupport.WatchOptions(dir, _stem);
options.EnableFileChangeCheck = false;
using var fromFile = new HeddleTemplate(options);
Assert.True(fromFile.CompileResult.Success, fromFile.CompileResult.ToString());
Expand Down
11 changes: 7 additions & 4 deletions src/Heddle.Tests/FileWatcherFailedRecompileTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ namespace Heddle.Tests
/// </summary>
public class FileWatcherFailedRecompileTests
{
// Per-test watched-file stem: isolates this test from concurrent tests and parallel TFM hosts.
private readonly string _stem = FileWatcherTestSupport.NewStem();

/// <summary>The pinned scenario: break the file, reload → <c>CompileResult.Success == false</c> with
/// the error in <c>ErrorList</c> while <c>Generate</c> still renders the previous content; fix the
/// file, reload → success again with the new content (the edit-to-fix loop D2 arms for).</summary>
Expand All @@ -19,21 +22,21 @@ public void FailedRecompileKeepsLastGoodAndSurfacesErrorOnCompileResult()
var dir = FileWatcherTestSupport.NewTempDir();
try
{
var path = Path.Combine(dir, "home.heddle");
var path = Path.Combine(dir, _stem + ".heddle");
File.WriteAllText(path, "GOOD");
using var template = new HeddleTemplate(FileWatcherTestSupport.WatchOptions(dir, "home"));
using var template = new HeddleTemplate(FileWatcherTestSupport.WatchOptions(dir, _stem));
Assert.True(template.CompileResult.Success, template.CompileResult.ToString());
FileWatcherTestSupport.Disarm(template);

File.WriteAllText(path, "@profile(){{pdf}}broken"); // deterministic compile error (unknown profile)
FileWatcherTestSupport.InvokeChanged(template, dir, "home.heddle");
FileWatcherTestSupport.InvokeChanged(template, dir, _stem + ".heddle");

Assert.False(template.CompileResult.Success, "the broken edit must surface a failed CompileResult");
Assert.NotEmpty(template.CompileResult.ErrorList);
Assert.Equal("GOOD", template.Generate(null)); // last-good stays published and renderable

File.WriteAllText(path, "FIXED"); // the edit-to-fix save recovers
FileWatcherTestSupport.InvokeChanged(template, dir, "home.heddle");
FileWatcherTestSupport.InvokeChanged(template, dir, _stem + ".heddle");
Assert.True(template.CompileResult.Success, template.CompileResult.ToString());
Assert.Equal("FIXED", template.Generate(null));
}
Expand Down
18 changes: 13 additions & 5 deletions src/Heddle.Tests/FileWatcherFilterAndArmingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ public static string NewTempDir()
return dir;
}

/// <summary>A per-test watched-file stem, unique across concurrently running tests AND across the
/// parallel per-TFM test hosts — no two watchers can ever agree on a file name, so a write in one
/// process can never be picked up by another's watcher.</summary>
public static string NewStem() => "home-" + Guid.NewGuid().ToString("N").Substring(0, 8);

public static void CleanupDir(string dir)
{
try
Expand Down Expand Up @@ -138,6 +143,9 @@ public static bool WaitFor(Func<bool> condition, int timeoutMs = 10000)
/// </summary>
public class FileWatcherFilterAndArmingTests
{
// Per-test watched-file stem: isolates this test from concurrent tests and parallel TFM hosts.
private readonly string _stem = FileWatcherTestSupport.NewStem();

/// <summary>D1 + D2: a file compile of <c>home</c> + <c>.heddle</c> with the flag on watches
/// <c>home.heddle</c> (not the postfix-less <c>home</c> of the old bug) and is armed.</summary>
[Fact]
Expand All @@ -146,13 +154,13 @@ public void FilterEqualsTemplateNamePlusPostfix()
var dir = FileWatcherTestSupport.NewTempDir();
try
{
File.WriteAllText(Path.Combine(dir, "home.heddle"), "HELLO");
using var template = new HeddleTemplate(FileWatcherTestSupport.WatchOptions(dir, "home"));
File.WriteAllText(Path.Combine(dir, _stem + ".heddle"), "HELLO");
using var template = new HeddleTemplate(FileWatcherTestSupport.WatchOptions(dir, _stem));
Assert.True(template.CompileResult.Success, template.CompileResult.ToString());

var watcher = FileWatcherTestSupport.GetWatcher(template);
Assert.NotNull(watcher);
Assert.Equal("home.heddle", watcher.Filter);
Assert.Equal(_stem + ".heddle", watcher.Filter);
Assert.True(watcher.EnableRaisingEvents, "the watcher must be armed (EnableRaisingEvents)");
}
finally
Expand All @@ -177,8 +185,8 @@ public void FlagOffFileCompileInstallsNoWatcher()
var dir = FileWatcherTestSupport.NewTempDir();
try
{
File.WriteAllText(Path.Combine(dir, "home.heddle"), "HELLO");
var options = FileWatcherTestSupport.WatchOptions(dir, "home");
File.WriteAllText(Path.Combine(dir, _stem + ".heddle"), "HELLO");
var options = FileWatcherTestSupport.WatchOptions(dir, _stem);
options.EnableFileChangeCheck = false;
using var template = new HeddleTemplate(options);
Assert.True(template.CompileResult.Success, template.CompileResult.ToString());
Expand Down
Loading
Loading