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

test(cli): cover every cause tazel log why can name

Motivation: codecov/patch on #61 found the messages of most causes untested;
only "changed" was reached by the real C build.

Changes: a theory writes a why.json with one reason of each cause
(NoRecord, CommandChanged, InputChanged with and without a new digest,
InputAdded, OutputChanged, Forced) and runs `tazel log why :tool` from the
package directory, which also covers resolving a :name label against the
nearest BUILD.csx.

Verification: RebuildReasonsTests 16/16.
Commit
16e37df639ec46252d324ee2bc574aa6d4374e4c
Author
Leitwolf11 ·
Parents
39172d97f007

Files · Download .tar.gz

Changes

 .../Progmasoft.Tazel.Tests/RebuildReasonsTests.cs  | 26 ++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/tests/Progmasoft.Tazel.Tests/RebuildReasonsTests.cs b/tests/Progmasoft.Tazel.Tests/RebuildReasonsTests.cs
index 9d8cfe2..ef5da9c 100644
--- a/tests/Progmasoft.Tazel.Tests/RebuildReasonsTests.cs
+++ b/tests/Progmasoft.Tazel.Tests/RebuildReasonsTests.cs
@@ -135,6 +135,32 @@ public sealed class RebuildReasonsTests
     public void LogWhyTakesExactlyOneLabel(string line) =>
         Assert.Throws<CommandLineException>(() => CommandLine.Parse(line.Split(' ')));
 
+    [Theory]
+    [InlineData(RebuildCause.NoRecord, null, null, null, "no earlier run was recorded")]
+    [InlineData(RebuildCause.CommandChanged, null, null, null, "its command, directory or environment changed")]
+    [InlineData(RebuildCause.InputChanged, "src/a.h", "aaaaaaaaaaaaaaaa", null, "src/a.h was removed")]
+    [InlineData(RebuildCause.InputChanged, "src/a.h", "aaaaaaaaaaaaaaaa", "bbbbbbbbbbbbbbbb", "src/a.h changed (aaaaaaaaaaaa -> bbbbbbbbbbbb)")]
+    [InlineData(RebuildCause.InputAdded, "src/b.h", null, "cccccccccccccccc", "src/b.h is read for the first time")]
+    [InlineData(RebuildCause.OutputChanged, "out/a.o", "aaaaaaaaaaaaaaaa", null, "out/a.o, which it writes, was changed or removed since")]
+    [InlineData(RebuildCause.Forced, null, null, null, "--no-cache, --recompile or a disabled local cache ran it regardless")]
+    public async Task LogWhyNamesEachCause(RebuildCause cause, string? file, string? was, string? now, string expected)
+    {
+        using var module = new TemporaryModule()
+            .Write("MODULE.csx", TemporaryModule.ModuleFile)
+            .Write("app/BUILD.csx", "using Progmasoft.Tazel.Dsl.Build.Prelude;\n");
+        var full = file is null ? null : Path.Combine(module.Root, file);
+        RebuildReasons.Write(Path.Combine(module.Root, ".tazel"),
+            [new RebuildReason("//app:tool", "Compiling //app:tool main.c", cause, full, was, now, [Path.Combine(module.Root, "out/a.o")])]);
+
+        // :tool is read in the package of the working directory, app/.
+        using var output = new StringWriter();
+        var status = await Program.RunAsync(["--color", "never", "log", "why", ":tool"], Path.Combine(module.Root, "app"), output,
+            TestContext.Current.CancellationToken);
+        Assert.True(status == 0, output.ToString());
+        Assert.Contains(expected, output.ToString(), StringComparison.Ordinal);
+        Assert.Contains("-> Compiling //app:tool main.c", output.ToString(), StringComparison.Ordinal);
+    }
+
     [Fact]
     public void LogWhyParsesItsLabel()
     {