fix(cli): resolve CLI-008..013 — format validation, exit-code semantics, debug-stream cancellation/disposal, test coverage
This commit is contained in:
44
tests/ScadaLink.CLI.Tests/FormatOptionValidationTests.cs
Normal file
44
tests/ScadaLink.CLI.Tests/FormatOptionValidationTests.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System.CommandLine;
|
||||
using ScadaLink.CLI.Commands;
|
||||
|
||||
namespace ScadaLink.CLI.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// Regression tests for CLI-008 — the <c>--format</c> option previously accepted any
|
||||
/// string, so a typo like <c>--format tabel</c> silently fell through to JSON output
|
||||
/// with no feedback. The option must reject values outside {json, table} with a parse
|
||||
/// error.
|
||||
/// </summary>
|
||||
public class FormatOptionValidationTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData("json")]
|
||||
[InlineData("table")]
|
||||
public void FormatOption_AcceptsValidValues(string value)
|
||||
{
|
||||
var formatOption = CliOptions.CreateFormatOption();
|
||||
var root = new RootCommand();
|
||||
root.Add(formatOption);
|
||||
|
||||
var result = root.Parse(new[] { "--format", value });
|
||||
|
||||
Assert.Empty(result.Errors);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("tabel")]
|
||||
[InlineData("xml")]
|
||||
[InlineData("yaml")]
|
||||
[InlineData("")]
|
||||
[InlineData("JSON")] // case-sensitive: documented values are lowercase
|
||||
public void FormatOption_RejectsInvalidValues(string value)
|
||||
{
|
||||
var formatOption = CliOptions.CreateFormatOption();
|
||||
var root = new RootCommand();
|
||||
root.Add(formatOption);
|
||||
|
||||
var result = root.Parse(new[] { "--format", value });
|
||||
|
||||
Assert.NotEmpty(result.Errors);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user