Progmasoft Git

tazel

A build system for C, C++, Objective-C, Objective-C++ and Zig, with C# project files.

Clonegit clone https://git.progmasoft.com/tazel

fix(test): preserve earlier recorded test pass when --no-cache fails

Commit
c7bae07dc2b60a71dbbe26cf63d6b7107717d774
Author
Leitwolf11 ·
Parents
5af68c598693

Files · Download .tar.gz

Changes

 docs/commands.md                                 |  2 +-
 src/Progmasoft.Tazel/Driver/TestRunner.cs        |  4 ++--
 tests/Progmasoft.Tazel.Tests/CachePolicyTests.cs | 21 +++++++++++++++++++++
 3 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/docs/commands.md b/docs/commands.md
index a82a3ba..0c7298a 100644
--- a/docs/commands.md
+++ b/docs/commands.md
@@ -87,7 +87,7 @@ the `PublicKey` takes; HTTP caches have no delete, so nothing is removed there.
 
 Neither flag deletes a cache, changes `--jobs` or changes a key: a record written before is kept, and the next build
 checks it against the files, as it checks every record. With both, `--no-cache` holds. A test that fails under
-`--no-cache` loses the pass recorded before it. The tag `no-cache` of a test keeps its meaning. Fetched modules are
+`--no-cache` keeps the pass recorded before it, since `--no-cache` neither writes nor deletes cache records. The tag `no-cache` of a test keeps its meaning. Fetched modules are
 fetched as always.
 
 zig keeps what it compiled in a cache of its own: a forced zig action runs with an empty one in `.tazel/forced/`,
diff --git a/src/Progmasoft.Tazel/Driver/TestRunner.cs b/src/Progmasoft.Tazel/Driver/TestRunner.cs
index fa8bd0c..2c5c226 100644
--- a/src/Progmasoft.Tazel/Driver/TestRunner.cs
+++ b/src/Progmasoft.Tazel/Driver/TestRunner.cs
@@ -131,7 +131,7 @@ internal sealed class TestRunner(OutputLayout layout, int jobs, Reporter reporte
             return cached;
         }
 
-        // --no-cache keeps an earlier pass; only a failure below makes it untrue.
+        // --no-cache never writes or deletes the recorded pass.
         Forget(run, keepPass: noCache);
         var attempts = settings.Flaky ? 3 : 1;
         var watch = Stopwatch.StartNew();
@@ -154,7 +154,7 @@ internal sealed class TestRunner(OutputLayout layout, int jobs, Reporter reporte
             }
         }
 
-        if (File.Exists(run.Passed))
+        if (!noCache && File.Exists(run.Passed))
         {
             File.Delete(run.Passed);
         }
diff --git a/tests/Progmasoft.Tazel.Tests/CachePolicyTests.cs b/tests/Progmasoft.Tazel.Tests/CachePolicyTests.cs
index 7c71738..70eeb8f 100644
--- a/tests/Progmasoft.Tazel.Tests/CachePolicyTests.cs
+++ b/tests/Progmasoft.Tazel.Tests/CachePolicyTests.cs
@@ -100,6 +100,27 @@ public sealed class CachePolicyTests
         Assert.Contains("PASSED (cached)", await Ok(module, "test", "//:math_test", "--recompile"), StringComparison.Ordinal);
     }
 
+    [Fact]
+    public async Task NoCacheFailureKeepsAnEarlierTestPass()
+    {
+        Assert.SkipWhen(Host.Which("cc") is null && Host.Which("gcc") is null && Host.Which("clang") is null, "no C compiler");
+        using var module = new TemporaryModule()
+            .Write("MODULE.csx", TemporaryModule.ModuleFile)
+            .Write("BUILD.csx", "using Progmasoft.Tazel.Dsl.Build.Prelude;\nCC.Test(\"gate_test\", new() { Sources = [\"gate.c\"] });\n");
+        var flag = Path.Combine(module.Root, "fail.flag");
+        var flagLiteral = flag.Replace("\\", "/", StringComparison.Ordinal);
+        module.Write("gate.c", $"#include <stdio.h>\nint main(void) {{ FILE *f = fopen(\"{flagLiteral}\", \"r\"); if (f) {{ fclose(f); return 1; }} return 0; }}\n");
+        Assert.Contains("PASSED", await Ok(module, "test", "//:gate_test"), StringComparison.Ordinal);
+        // Trigger a failure under --no-cache without changing declared test inputs.
+        File.WriteAllText(flag, "fail");
+        var (status, output) = await module.TazelAsync(".", ["--color", "never", "test", "//:gate_test", "--no-cache"]);
+        Assert.NotEqual(0, status);
+        Assert.Contains("FAILED", output, StringComparison.Ordinal);
+        // The earlier recorded pass must survive the --no-cache run.
+        File.Delete(flag);
+        Assert.Contains("PASSED (cached)", await Ok(module, "test", "//:gate_test"), StringComparison.Ordinal);
+    }
+
     [Fact]
     public async Task NoCacheDominatesRecompile()
     {