Skip to content

Add Test-Toml function for validation #4

@MariusStorhaug

Description

Scripts that load TOML content from external sources need to validate it before parsing. Once ConvertFrom-Toml lands (#2), the only signal of invalid input will be a thrown exception. PowerShell's Test-Json sets the established pattern for serialization-format validators: returns [bool], writes parser errors to the error stream when invalid.

Request

Desired capability

Test-Toml -Path Cargo.toml          # validate a file
$content | Test-Toml                 # validate a string
'[invalid' | Test-Toml               # returns $false, writes error

Parameters

Parameter Description
-Path File path to validate (parameter set: Path)
-LiteralPath Literal path (parameter set: LiteralPath)
-InputObject String to validate (ValueFromPipeline, default set)

Acceptance criteria


Technical decisions

Implementation: Wraps ConvertFrom-Toml in try/catch. On exception, writes the parser error via Write-Error and returns $false. On success, returns $true.

Function placement: src/functions/public/Test-Toml.ps1.

No new parser logic: Reuses the existing ConvertFrom-Toml parser. This keeps validation behavior consistent with parsing behavior.

Output type: [bool] only — never throws on invalid input.

Alias: Test-Tml, matching the planned alias pattern in #2.


Implementation plan

  • Add Test-Toml in src/functions/public/Test-Toml.ps1 with Test-Tml alias
  • Add Pester tests — valid string, invalid string, valid file, invalid file, pipeline input, error-stream contents on failure
  • Update README with usage example

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions