tazel
A build system for C, C++, Objective-C, Objective-C++ and Zig, with C# project files.
Clonegit clone https://git.progmasoft.com/tazel
End every value of tazel_envs.txt with ;
- Commit
eec8fe2ec5405fce243be68b0667b732c5700473- Author
- Leitwolf11 ·
- Parents
6d4e6ed5add9
Changes
docs/commands.md | 9 ++++----- fuzz/corpus/envs/sample | 6 +++--- src/Progmasoft.Tazel/Dsl/Envs/TazelEnvs.cs | 7 ++----- tests/Progmasoft.Tazel.Tests/EnvsTests.cs | 29 +++++++++++++++-------------- 4 files changed, 24 insertions(+), 27 deletions(-) diff --git a/docs/commands.md b/docs/commands.md index 46d3f99..f0a50ab 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -152,9 +152,9 @@ than one group. `--` ends the options, so a query may start with a dash. # comment <# comment #> -example-version: '0.1.0' -example-output: ("rustc" "--help") -shell-expansion: s(`$HOME`) +example-version: '0.1.0'; +example-output: ("rustc" "--help"); +shell-expansion: s(`$HOME`); ``` `tazel_envs.txt` sits beside the `MODULE.csx` of a module and names values that its `MODULE.csx` and `BUILD.csx` @@ -166,8 +166,7 @@ using Progmasoft.Tazel.Dsl.Environment; var exampleVersion = GetEnvironment.From("example-version"); // "0.1.0"; null for a name the file does not have ``` -- It is read with the lexer of `tazel_custom.txt`: the same comments and strings; the entries follow one another - with no `;` between them. +- It is read with the lexer of `tazel_custom.txt`: the same comments and strings; every value ends with `;`. - A string is the value as written. `("program" "argument")` starts a program directly, each string one argument; `s("line")` gives one line to `/bin/sh` on Linux, macOS and the BSDs and to `cmd.exe` on Windows. Their value is what they print, less the line endings at its end. A program runs when its value is first asked for, once per diff --git a/fuzz/corpus/envs/sample b/fuzz/corpus/envs/sample index a4e3338..726390a 100644 --- a/fuzz/corpus/envs/sample +++ b/fuzz/corpus/envs/sample @@ -1,6 +1,6 @@ # comment <# comment #> -example-version: '0.1.0' -example-output: ("rustc" "--help") -shell-expension: s(`$HOME`) +example-version: '0.1.0'; +example-output: ("rustc" "--help"); +shell-expension: s(`$HOME`); diff --git a/src/Progmasoft.Tazel/Dsl/Envs/TazelEnvs.cs b/src/Progmasoft.Tazel/Dsl/Envs/TazelEnvs.cs index a4aa61e..df74e94 100644 --- a/src/Progmasoft.Tazel/Dsl/Envs/TazelEnvs.cs +++ b/src/Progmasoft.Tazel/Dsl/Envs/TazelEnvs.cs @@ -38,7 +38,7 @@ public sealed record EnvEntry(string Name, EnvValue Value, int Line); /// <summary> /// Reads <c>tazel_envs.txt</c> with the lexer of <c>tazel_custom.txt</c> and <c>tazel_options.txt</c>: the same comments -/// and strings, <c>name: value</c> one after another, with no <c>;</c> between them. +/// and strings, <c>name: value;</c> one after another, each value ended by <c>;</c>. /// </summary> public static class TazelEnvsFile { @@ -91,11 +91,8 @@ public static class TazelEnvsFile throw Fail(Peek() ?? name, $"expected the value of {name.Text}: a string, (\"program\" \"argument\") or s(\"line\")"); } + Take(TokenKind.Semicolon, $"';' after the value of {name.Text}"); entries.Add(new EnvEntry(name.Text, value, name.Line)); - if (Peek() is { Kind: TokenKind.Semicolon } semicolon) - { - throw Fail(semicolon, $"a value of tazel_envs.txt has no ';' after it: {name.Text}: ..."); - } } return entries; diff --git a/tests/Progmasoft.Tazel.Tests/EnvsTests.cs b/tests/Progmasoft.Tazel.Tests/EnvsTests.cs index dab7e15..9a71a76 100644 --- a/tests/Progmasoft.Tazel.Tests/EnvsTests.cs +++ b/tests/Progmasoft.Tazel.Tests/EnvsTests.cs @@ -17,9 +17,9 @@ public sealed class EnvsTests # comment <# comment #> - example-version: '0.1.0' - example-output: ("rustc" "--help") - shell-expension: s(`$HOME`) + example-version: '0.1.0'; + example-output: ("rustc" "--help"); + shell-expension: s(`$HOME`); """; [Fact] @@ -34,16 +34,17 @@ public sealed class EnvsTests } [Fact] - public void ValuesFollowOneAnotherWithoutSemicolons() => - Assert.Equal(2, TazelEnvsFile.Parse("a: 'x' b: \"y\"").Count); + public void EveryValueEndsWithASemicolon() => + Assert.Equal(2, TazelEnvsFile.Parse("a: 'x'; b: \"y\";").Count); [Theory] - [InlineData("a: 'x'\na: 'y'", "'a' is set twice")] - [InlineData("a: 'x';", "has no ';' after it")] + [InlineData("a: 'x';\na: 'y';", "'a' is set twice")] + [InlineData("a: 'x'", "expected ';' after the value of a")] + [InlineData("a: 'x' b: 'y';", "expected ';' after the value of a")] [InlineData("a 'x'", "expected ':' after a")] - [InlineData("a: ()", "a program names at least itself")] - [InlineData("a: s('x' 'y')", "s(...) takes one string")] - [InlineData("a: ('echo' <1>)", "takes no <N> or <*>")] + [InlineData("a: ();", "a program names at least itself")] + [InlineData("a: s('x' 'y');", "s(...) takes one string")] + [InlineData("a: ('echo' <1>);", "takes no <N> or <*>")] [InlineData("a: b", "expected the value of a")] [InlineData("a: 'x", "has no closing '")] public void RefusesWhatIsWrongWithItsPlace(string text, string message) @@ -72,9 +73,9 @@ public sealed class EnvsTests .Write("MODULE.csx", TemporaryModule.ModuleFile) .Write("BUILD.csx", Build) .Write("tazel_envs.txt", """ - example-version: '0.1.0' - from-shell: s('echo shell-said') - from-program: ("dotnet" "--version") + example-version: '0.1.0'; + from-shell: s('echo shell-said'); + from-program: ("dotnet" "--version"); """); var workspace = await module.LoadAsync(); var name = workspace.Targets.Keys.Single().Name; @@ -95,7 +96,7 @@ public sealed class EnvsTests using var module = new TemporaryModule() .Write("MODULE.csx", TemporaryModule.ModuleFile) .Write("BUILD.csx", "using Progmasoft.Tazel.Dsl.Environment;\nvar x = GetEnvironment.From(\"broken\");") - .Write("tazel_envs.txt", "broken: s('exit 3')\n"); + .Write("tazel_envs.txt", "broken: s('exit 3');\n"); var error = await Assert.ThrowsAsync<ProjectException>(() => module.LoadAsync()); Assert.Contains("tazel_envs.txt:1: broken ran", error.Message, StringComparison.Ordinal); Assert.Contains("failed with 3", error.Message, StringComparison.Ordinal);