tazel
A build system for C, C++, Objective-C, Objective-C++ and Zig, with C# project files.
Clonegit clone https://git.progmasoft.com/tazel
Collect coverage on every system and test the commands
- Commit
5382e40250e07d4b2b437a17fb6ee3f842c9d607- Author
- Leitwolf11 ·
- Parents
6185ec224ceb
Changes
.github/workflows/ci.yml | 55 ++++++- src/Progmasoft.Tazel/Cli/Commands.cs | 16 +- src/Progmasoft.Tazel/Cli/MoreCommands.cs | 7 +- src/Progmasoft.Tazel/Dsl/Custom/CustomCommands.cs | 9 ++ tests/Progmasoft.Tazel.Tests/CommandTests.cs | 178 ++++++++++++++++++++++ 5 files changed, 246 insertions(+), 19 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index df7383b..14651ba 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -106,6 +106,7 @@ jobs: run: >- dotnet test --project tests/Progmasoft.Tazel.Tests -c Release --no-build --output Detailed --filter-class Progmasoft.Tazel.Tests.ActionCacheTests + --coverlet --coverlet-output-format cobertura --results-directory artifacts/coverage - name: Test ArchiveTests (macOS) if: runner.os == 'macOS' @@ -113,6 +114,7 @@ jobs: run: >- dotnet test --project tests/Progmasoft.Tazel.Tests -c Release --no-build --output Detailed --filter-class Progmasoft.Tazel.Tests.ArchiveTests + --coverlet --coverlet-output-format cobertura --results-directory artifacts/coverage - name: Test BuildCommandTests (macOS) if: runner.os == 'macOS' @@ -120,6 +122,7 @@ jobs: run: >- dotnet test --project tests/Progmasoft.Tazel.Tests -c Release --no-build --output Detailed --filter-class Progmasoft.Tazel.Tests.BuildCommandTests + --coverlet --coverlet-output-format cobertura --results-directory artifacts/coverage - name: Test CacheSigningTests (macOS) if: runner.os == 'macOS' @@ -127,6 +130,15 @@ jobs: run: >- dotnet test --project tests/Progmasoft.Tazel.Tests -c Release --no-build --output Detailed --filter-class Progmasoft.Tazel.Tests.CacheSigningTests + --coverlet --coverlet-output-format cobertura --results-directory artifacts/coverage + + - name: Test CommandTests (macOS) + if: runner.os == 'macOS' + timeout-minutes: 10 + run: >- + dotnet test --project tests/Progmasoft.Tazel.Tests -c Release --no-build --output Detailed + --filter-class Progmasoft.Tazel.Tests.CommandTests + --coverlet --coverlet-output-format cobertura --results-directory artifacts/coverage - name: Test CommandLineTests (macOS) if: runner.os == 'macOS' @@ -134,6 +146,7 @@ jobs: run: >- dotnet test --project tests/Progmasoft.Tazel.Tests -c Release --no-build --output Detailed --filter-class Progmasoft.Tazel.Tests.CommandLineTests + --coverlet --coverlet-output-format cobertura --results-directory artifacts/coverage - name: Test CoverageTests (macOS) if: runner.os == 'macOS' @@ -141,6 +154,7 @@ jobs: run: >- dotnet test --project tests/Progmasoft.Tazel.Tests -c Release --no-build --output Detailed --filter-class Progmasoft.Tazel.Tests.CoverageTests + --coverlet --coverlet-output-format cobertura --results-directory artifacts/coverage - name: Test CustomCommandTests (macOS) if: runner.os == 'macOS' @@ -148,6 +162,7 @@ jobs: run: >- dotnet test --project tests/Progmasoft.Tazel.Tests -c Release --no-build --output Detailed --filter-class Progmasoft.Tazel.Tests.CustomCommandTests + --coverlet --coverlet-output-format cobertura --results-directory artifacts/coverage - name: Test DepfileTests (macOS) if: runner.os == 'macOS' @@ -155,6 +170,7 @@ jobs: run: >- dotnet test --project tests/Progmasoft.Tazel.Tests -c Release --no-build --output Detailed --filter-class Progmasoft.Tazel.Tests.DepfileTests + --coverlet --coverlet-output-format cobertura --results-directory artifacts/coverage - name: Test DiagnosticTests (macOS) if: runner.os == 'macOS' @@ -162,6 +178,7 @@ jobs: run: >- dotnet test --project tests/Progmasoft.Tazel.Tests -c Release --no-build --output Detailed --filter-class Progmasoft.Tazel.Tests.DiagnosticTests + --coverlet --coverlet-output-format cobertura --results-directory artifacts/coverage - name: Test EnvsTests (macOS) if: runner.os == 'macOS' @@ -169,6 +186,7 @@ jobs: run: >- dotnet test --project tests/Progmasoft.Tazel.Tests -c Release --no-build --output Detailed --filter-class Progmasoft.Tazel.Tests.EnvsTests + --coverlet --coverlet-output-format cobertura --results-directory artifacts/coverage - name: Test GlobTests (macOS) if: runner.os == 'macOS' @@ -176,6 +194,7 @@ jobs: run: >- dotnet test --project tests/Progmasoft.Tazel.Tests -c Release --no-build --output Detailed --filter-class Progmasoft.Tazel.Tests.GlobTests + --coverlet --coverlet-output-format cobertura --results-directory artifacts/coverage - name: Test HelpTests (macOS) if: runner.os == 'macOS' @@ -183,6 +202,7 @@ jobs: run: >- dotnet test --project tests/Progmasoft.Tazel.Tests -c Release --no-build --output Detailed --filter-class Progmasoft.Tazel.Tests.HelpTests + --coverlet --coverlet-output-format cobertura --results-directory artifacts/coverage - name: Test LabelTests (macOS) if: runner.os == 'macOS' @@ -190,6 +210,7 @@ jobs: run: >- dotnet test --project tests/Progmasoft.Tazel.Tests -c Release --no-build --output Detailed --filter-class Progmasoft.Tazel.Tests.LabelTests + --coverlet --coverlet-output-format cobertura --results-directory artifacts/coverage - name: Test MarkerTests (macOS) if: runner.os == 'macOS' @@ -197,6 +218,7 @@ jobs: run: >- dotnet test --project tests/Progmasoft.Tazel.Tests -c Release --no-build --output Detailed --filter-class Progmasoft.Tazel.Tests.MarkerTests + --coverlet --coverlet-output-format cobertura --results-directory artifacts/coverage - name: Test MicroVMBootTests (macOS) if: runner.os == 'macOS' @@ -204,6 +226,7 @@ jobs: run: >- dotnet test --project tests/Progmasoft.Tazel.Tests -c Release --no-build --output Detailed --filter-class Progmasoft.Tazel.Tests.MicroVMBootTests + --coverlet --coverlet-output-format cobertura --results-directory artifacts/coverage - name: Test MicroVMFilesTests (macOS) if: runner.os == 'macOS' @@ -211,6 +234,7 @@ jobs: run: >- dotnet test --project tests/Progmasoft.Tazel.Tests -c Release --no-build --output Detailed --filter-class Progmasoft.Tazel.Tests.MicroVMFilesTests + --coverlet --coverlet-output-format cobertura --results-directory artifacts/coverage - name: Test MicroVMProtocolTests (macOS) if: runner.os == 'macOS' @@ -218,6 +242,7 @@ jobs: run: >- dotnet test --project tests/Progmasoft.Tazel.Tests -c Release --no-build --output Detailed --filter-class Progmasoft.Tazel.Tests.MicroVMProtocolTests + --coverlet --coverlet-output-format cobertura --results-directory artifacts/coverage - name: Test PlannerTests (macOS) if: runner.os == 'macOS' @@ -225,6 +250,7 @@ jobs: run: >- dotnet test --project tests/Progmasoft.Tazel.Tests -c Release --no-build --output Detailed --filter-class Progmasoft.Tazel.Tests.PlannerTests + --coverlet --coverlet-output-format cobertura --results-directory artifacts/coverage - name: Test PluginLoadingTests (macOS) if: runner.os == 'macOS' @@ -232,6 +258,7 @@ jobs: run: >- dotnet test --project tests/Progmasoft.Tazel.Tests -c Release --no-build --output Detailed --filter-class Progmasoft.Tazel.Tests.PluginLoadingTests + --coverlet --coverlet-output-format cobertura --results-directory artifacts/coverage - name: Test PluginSdkTests (macOS) if: runner.os == 'macOS' @@ -239,6 +266,7 @@ jobs: run: >- dotnet test --project tests/Progmasoft.Tazel.Tests -c Release --no-build --output Detailed --filter-class Progmasoft.Tazel.Tests.PluginSdkTests + --coverlet --coverlet-output-format cobertura --results-directory artifacts/coverage - name: Test PortalCommandLineTests (macOS) if: runner.os == 'macOS' @@ -246,6 +274,7 @@ jobs: run: >- dotnet test --project tests/Progmasoft.Tazel.Tests -c Release --no-build --output Detailed --filter-class Progmasoft.Tazel.Tests.PortalCommandLineTests + --coverlet --coverlet-output-format cobertura --results-directory artifacts/coverage - name: Test PortalTests (macOS) if: runner.os == 'macOS' @@ -253,6 +282,7 @@ jobs: run: >- dotnet test --project tests/Progmasoft.Tazel.Tests -c Release --no-build --output Detailed --filter-class Progmasoft.Tazel.Tests.PortalTests + --coverlet --coverlet-output-format cobertura --results-directory artifacts/coverage - name: Test ProcessTreeTests (macOS) if: runner.os == 'macOS' @@ -260,6 +290,7 @@ jobs: run: >- dotnet test --project tests/Progmasoft.Tazel.Tests -c Release --no-build --output Detailed --filter-class Progmasoft.Tazel.Tests.ProcessTreeTests + --coverlet --coverlet-output-format cobertura --results-directory artifacts/coverage - name: Test QueryTests (macOS) if: runner.os == 'macOS' @@ -267,6 +298,7 @@ jobs: run: >- dotnet test --project tests/Progmasoft.Tazel.Tests -c Release --no-build --output Detailed --filter-class Progmasoft.Tazel.Tests.QueryTests + --coverlet --coverlet-output-format cobertura --results-directory artifacts/coverage - name: Test RemoteCacheTests (macOS) if: runner.os == 'macOS' @@ -274,6 +306,7 @@ jobs: run: >- dotnet test --project tests/Progmasoft.Tazel.Tests -c Release --no-build --output Detailed --filter-class Progmasoft.Tazel.Tests.RemoteCacheTests + --coverlet --coverlet-output-format cobertura --results-directory artifacts/coverage - name: Test SnapshotTests (macOS) if: runner.os == 'macOS' @@ -281,6 +314,7 @@ jobs: run: >- dotnet test --project tests/Progmasoft.Tazel.Tests -c Release --no-build --output Detailed --filter-class Progmasoft.Tazel.Tests.SnapshotTests + --coverlet --coverlet-output-format cobertura --results-directory artifacts/coverage - name: Test StepTests (macOS) if: runner.os == 'macOS' @@ -288,6 +322,7 @@ jobs: run: >- dotnet test --project tests/Progmasoft.Tazel.Tests -c Release --no-build --output Detailed --filter-class Progmasoft.Tazel.Tests.StepTests + --coverlet --coverlet-output-format cobertura --results-directory artifacts/coverage - name: Test TazelOptionsTests (macOS) if: runner.os == 'macOS' @@ -295,6 +330,7 @@ jobs: run: >- dotnet test --project tests/Progmasoft.Tazel.Tests -c Release --no-build --output Detailed --filter-class Progmasoft.Tazel.Tests.TazelOptionsTests + --coverlet --coverlet-output-format cobertura --results-directory artifacts/coverage - name: Test TestCacheTests (macOS) if: runner.os == 'macOS' @@ -302,6 +338,7 @@ jobs: run: >- dotnet test --project tests/Progmasoft.Tazel.Tests -c Release --no-build --output Detailed --filter-class Progmasoft.Tazel.Tests.TestCacheTests + --coverlet --coverlet-output-format cobertura --results-directory artifacts/coverage - name: Test WorkspaceTests (macOS) if: runner.os == 'macOS' @@ -309,6 +346,7 @@ jobs: run: >- dotnet test --project tests/Progmasoft.Tazel.Tests -c Release --no-build --output Detailed --filter-class Progmasoft.Tazel.Tests.WorkspaceTests + --coverlet --coverlet-output-format cobertura --results-directory artifacts/coverage - name: Test # A test that hangs is named and dumped at 15 minutes, and the run stops itself at 20, before the step's own @@ -334,12 +372,15 @@ jobs: - name: Run the built Tazel run: dotnet src/Progmasoft.Tazel/bin/Release/net10.0/tazel.dll version + # Every system uploads what its tests ran, under its own flag; Codecov merges them, so a branch for one system is + # covered by that system's run. - name: Upload coverage - if: runner.os == 'Linux' + if: always() uses: codecov/codecov-action@303a32d7a59b442fa8d48b6a1cc6825c09c847a5 # v7.1.1 with: use_oidc: true directory: artifacts/coverage + flags: ${{ runner.os }} fail_ci_if_error: false reference: @@ -375,6 +416,7 @@ jobs: timeout-minutes: 45 permissions: contents: read # the checkout + id-token: write # Codecov takes the coverage with an OIDC token instead of a secret steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: @@ -417,4 +459,13 @@ jobs: --filter-class 'Progmasoft.Tazel.Tests.MicroVMBootTests' --filter-class 'Progmasoft.Tazel.Tests.MicroVMProtocolTests' --filter-class 'Progmasoft.Tazel.Tests.MicroVMFilesTests' - --no-progress + --no-progress --coverlet --coverlet-output-format cobertura --results-directory artifacts/coverage + + - name: Upload coverage + if: always() + uses: codecov/codecov-action@303a32d7a59b442fa8d48b6a1cc6825c09c847a5 # v7.1.1 + with: + use_oidc: true + directory: artifacts/coverage + flags: MicroVM + fail_ci_if_error: false diff --git a/src/Progmasoft.Tazel/Cli/Commands.cs b/src/Progmasoft.Tazel/Cli/Commands.cs index 510c735..163f4a8 100644 --- a/src/Progmasoft.Tazel/Cli/Commands.cs +++ b/src/Progmasoft.Tazel/Cli/Commands.cs @@ -72,13 +72,12 @@ internal sealed partial class Commands(Reporter reporter, string workingDirector return 0; } - case DaemonCommand daemon: + default: + // The daemon's command, the one left: RunAsync gives every other kind to its own handler. reporter.Error(ErrorCodes.NoDaemon, - $"tazel dotnet {daemon.Action}: this Tazel runs every command in a process of its own and has no daemon", null, - "Tazel is a morning person: awake at once, every time, no daemon needed."); + $"tazel dotnet {((DaemonCommand)command).Action}: this Tazel runs every command in a process of its own " + + "and has no daemon", null, "Tazel is a morning person: awake at once, every time, no daemon needed."); return 1; - default: - throw new InvalidOperationException($"no handler for {command.GetType().Name}"); } } @@ -192,12 +191,7 @@ internal sealed partial class Commands(Reporter reporter, string workingDirector var environment = Processes.Inherited(); foreach (var step in command.Steps) { - var started = step switch - { - CustomStep.Program program => program.Expanded(arguments), - CustomStep.Shell shell => shell.Started(OperatingSystem.IsWindows()), - _ => throw new InvalidOperationException("a step of no kind"), - }; + var started = step.ToStart(arguments, OperatingSystem.IsWindows()); var found = Host.Which(started[0]) ?? throw new CustomCommandsException( $"'{command.Name}': the program '{started[0]}' is not found"); var status = Processes.RunAttached([found, .. started.Skip(1)], workingDirectory, environment); diff --git a/src/Progmasoft.Tazel/Cli/MoreCommands.cs b/src/Progmasoft.Tazel/Cli/MoreCommands.cs index bb17493..76aa935 100644 --- a/src/Progmasoft.Tazel/Cli/MoreCommands.cs +++ b/src/Progmasoft.Tazel/Cli/MoreCommands.cs @@ -232,12 +232,7 @@ internal sealed partial class Commands var errors = Console.OpenStandardError(); foreach (var step in command.Steps) { - var started = step switch - { - Dsl.Custom.CustomStep.Program program => program.Expanded(arguments), - Dsl.Custom.CustomStep.Shell shell => shell.Started(windows: false), - _ => throw new InvalidOperationException("a step of no kind"), - }; + var started = step.ToStart(arguments, windows: false); var status = await sandbox.RunAsync(started, Path.GetFullPath(workingDirectory), output, errors, cancel) .ConfigureAwait(false); if (status != 0) diff --git a/src/Progmasoft.Tazel/Dsl/Custom/CustomCommands.cs b/src/Progmasoft.Tazel/Dsl/Custom/CustomCommands.cs index 27a6752..3ca3cc6 100644 --- a/src/Progmasoft.Tazel/Dsl/Custom/CustomCommands.cs +++ b/src/Progmasoft.Tazel/Dsl/Custom/CustomCommands.cs @@ -69,6 +69,9 @@ public abstract record CustomArgument /// <summary>One step of a custom command.</summary> public abstract record CustomStep { + /// <summary>What to start: the program and its arguments, given those of the command line and the host.</summary> + public abstract IReadOnlyList<string> ToStart(IReadOnlyList<string> given, bool windows); + /// <summary> /// A program started directly, with these arguments and no shell between; the first is the program, a string. /// </summary> @@ -86,6 +89,9 @@ public abstract record CustomStep _ => given, }).ToList(); } + + /// <inheritdoc/> + public override IReadOnlyList<string> ToStart(IReadOnlyList<string> given, bool windows) => Expanded(given); } /// <summary>A whole command line for the shell of the host: CMD on Windows, <c>sh</c> elsewhere.</summary> @@ -95,6 +101,9 @@ public abstract record CustomStep /// <summary>What to start on this machine; the line reaches the shell unchanged.</summary> public IReadOnlyList<string> Started(bool windows) => windows ? ["cmd.exe", "/d", "/s", "/c", $"\"{Line}\""] : ["sh", "-c", Line]; + + /// <inheritdoc/> + public override IReadOnlyList<string> ToStart(IReadOnlyList<string> given, bool windows) => Started(windows); } } diff --git a/tests/Progmasoft.Tazel.Tests/CommandTests.cs b/tests/Progmasoft.Tazel.Tests/CommandTests.cs new file mode 100644 index 0000000..fb791dc --- /dev/null +++ b/tests/Progmasoft.Tazel.Tests/CommandTests.cs @@ -0,0 +1,178 @@ +// SPDX-FileCopyrightText: 2026 Progmasoft <support@progmasoft.com> +// SPDX-License-Identifier: MIT + +using System; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using Progmasoft.Tazel.Driver; +using Xunit; + +namespace Progmasoft.Tazel.Tests; + +/// <summary>The commands that print, remove or refuse, through tazel's own entry, as a user types them.</summary> +public sealed class CommandTests +{ + private static TemporaryModule Empty() => new TemporaryModule() + .Write("MODULE.csx", TemporaryModule.ModuleFile) + .Write("BUILD.csx", "using Progmasoft.Tazel.Dsl.Build.Prelude;\n"); + + [Fact] + public async Task VersionNamesTazelDotNetAndThePlatform() + { + using var module = Empty(); + var (status, output) = await module.TazelAsync(".", "version"); + Assert.Equal(0, status); + Assert.Matches(@"^tazel \d+\.\d+\.\d+ \(\.NET \d+\.\d+\.\d+, [a-z0-9_-]+\)", output); + } + + [Fact] + public async Task HelpListsTheCommandsAndHelpOfOneSaysWhatItTakes() + { + using var module = Empty(); + var (status, output) = await module.TazelAsync(".", "help"); + Assert.Equal(0, status); + Assert.Contains("cache", output, StringComparison.Ordinal); + Assert.Contains("a key pair", (await module.TazelAsync(".", "help", "cache")).Output, StringComparison.Ordinal); + (status, output) = await module.TazelAsync(".", "help", "cache", "--long"); + Assert.Equal(0, status); + Assert.Contains("--algorithm ed25519|rsa-4096|ml-dsa", output, StringComparison.Ordinal); + } + + [Fact] + public async Task KeygenPrintsAPairOfTheAlgorithmAsked() + { + using var module = Empty(); + var (status, output) = await module.TazelAsync(".", "cache", "keygen", "--algorithm=rsa-4096"); + Assert.Equal(0, status); + Assert.Contains("PublicKey: rsa-4096:", output, StringComparison.Ordinal); + Assert.Contains("SigningKey: rsa-4096:", output, StringComparison.Ordinal); + Assert.Contains("keep the SigningKey secret", output, StringComparison.Ordinal); + } + + [Fact] + public async Task TheDaemonCommandsSayThereIsNoDaemon() + { + using var module = Empty(); + var (status, output) = await module.TazelAsync(".", "dotnet", "start-daemon"); + Assert.Equal(1, status); + Assert.Contains("error[E0502]", output, StringComparison.Ordinal); + Assert.Contains("tazel dotnet start-daemon", output, StringComparison.Ordinal); + } + + [Fact] + public async Task CleanRemovesTheOutputsAndExpungeAllOfTheState() + { + using var module = Empty(); + var state = Path.Combine(module.Root, ".tazel"); + module.Write(".tazel/out/x.o", "o").Write(".tazel/testlogs/t.log", "log").Write(".tazel/external/kept.txt", "kept"); + + var (status, output) = await module.TazelAsync(".", "clean"); + Assert.Equal(0, status); + Assert.Contains("removed the outputs", output, StringComparison.Ordinal); + Assert.False(Directory.Exists(Path.Combine(state, "out"))); + Assert.False(Directory.Exists(Path.Combine(state, "testlogs"))); + Assert.True(File.Exists(Path.Combine(state, "external", "kept.txt"))); + + (status, output) = await module.TazelAsync(".", "clean", "--expunge"); + Assert.Equal(0, status); + Assert.Contains("removed", output, StringComparison.Ordinal); + Assert.False(Directory.Exists(state)); + } + + [Fact] + public async Task SettingsThisTazelDoesNotActOnAreSaid() + { + using var module = new TemporaryModule() + .Write("MODULE.csx", """ + using Progmasoft.Tazel.Dsl.Module.Prelude; + using Progmasoft.Tazel.Dsl.Common; + module = Module.Define(new() { Group = "com.example", Name = "sample", Version = "0.1.0" }); + execution = Execution.Define(new() { + Memory = 2L.Gibibytes(), + Remote = Remote.From("https://build.example.com", new()) + }); + """) + .Write("BUILD.csx", "using Progmasoft.Tazel.Dsl.Build.Prelude;\n"); + + var (status, output) = await module.TazelAsync(".", "build"); + Assert.True(status == 0, output); + Assert.Contains("names the remote execution https://build.example.com/", output, StringComparison.Ordinal); + Assert.Contains("sets Execution.Memory", output, StringComparison.Ordinal); + } + + [Fact] + public async Task ACustomCommandRunsItsStepsUntilOneFails() + { + Assert.SkipWhen(OperatingSystem.IsWindows(), "the steps are written for sh"); + using var module = Empty().Write("tazel_custom.txt", """ + make-file: ("sh" "-c" "echo made > made.txt") s("echo more >> made.txt"); + fail-early: s("exit 3") ("sh" "-c" "echo never > never.txt"); + missing: ("no-such-program-of-tazel"); + """); + + var (status, output) = await module.TazelAsync(".", "custom", "make-file"); + Assert.True(status == 0, output); + Assert.Equal("made\nmore\n", File.ReadAllText(Path.Combine(module.Root, "made.txt"))); + + (status, _) = await module.TazelAsync(".", "custom", "fail-early"); + Assert.Equal(3, status); + Assert.False(File.Exists(Path.Combine(module.Root, "never.txt"))); + + (status, output) = await module.TazelAsync(".", "custom", "missing"); + Assert.Equal(1, status); + Assert.Contains("the program 'no-such-program-of-tazel' is not found", output, StringComparison.Ordinal); + } + + [Fact] + public async Task ACustomCommandNeedsItsFileAndAtMostTheWordsItTakes() + { + using var module = Empty(); + var (status, output) = await module.TazelAsync(".", "custom", "anything"); + Assert.Equal(1, status); + Assert.Contains("there is no tazel_custom.txt", output, StringComparison.Ordinal); + + module.Write("tazel_custom.txt", "hello: (\"sh\" \"-c\" \"true\");\n"); + var words = Enumerable.Range(0, Dsl.Custom.CustomCommandFiles.MaxArguments + 1).Select(i => $"w{i}").ToArray(); + (status, output) = await module.TazelAsync(".", ["custom", .. words]); + Assert.NotEqual(0, status); + Assert.Contains($"tazel custom takes at most {Dsl.Custom.CustomCommandFiles.MaxArguments} words", output, + StringComparison.Ordinal); + } + + [Fact] + public async Task RunWantsExactlyOneProgram() + { + using var module = Empty().Write("BUILD.csx", """ + using Progmasoft.Tazel.Dsl.Build.Prelude; + CC.StaticLibrary("lib", new() { Sources = ["lib.c"] }); + CC.Executable("one", new() { Sources = ["main.c"] }); + CC.Executable("two", new() { Sources = ["main.c"] }); + """).Write("lib.c", "int f(void) { return 0; }\n").Write("main.c", "int main(void) { return 0; }\n"); + + var (status, output) = await module.TazelAsync(".", "run", "//:lib"); + Assert.Equal(1, status); + Assert.True(output.Contains("an executable or a test", StringComparison.Ordinal) || + output.Contains("found no executable", StringComparison.Ordinal), output); + + (status, output) = await module.TazelAsync(".", "run", "//..."); + Assert.Equal(1, status); + Assert.Contains("tazel run runs one program, and these are 2", output, StringComparison.Ordinal); + } + + [Fact] + public async Task TargetsThatDoNotBuildForThePlatformAreLeftOutAndCounted() + { + var other = Host.Platform == Dsl.Common.Platform.LinuxAmd64 ? "MacOSArm64" : "LinuxAmd64"; + using var module = Empty().Write("BUILD.csx", $$""" + using Progmasoft.Tazel.Dsl.Build.Prelude; + using Progmasoft.Tazel.Dsl.Common; + CC.StaticLibrary("elsewhere", new() { Sources = ["lib.c"], TargetConstraints = [Platform.{{other}}] }); + """).Write("lib.c", "int f(void) { return 0; }\n"); + + var (status, output) = await module.TazelAsync(".", "build", "//..."); + Assert.True(status == 0, output); + Assert.Contains("left out 1 target that does not build for", output.Replace("do not", "does not", StringComparison.Ordinal), + StringComparison.Ordinal); + } +}