PtcRunner.Lisp.SpecValidator (PtcRunner v0.4.1)
View SourceValidates PTC-Lisp specification against implementation.
Extracts examples from the PTC-Lisp specification and verifies that actual execution matches expected results. Helps detect drift between the specification and implementation.
Usage
# Validate all examples in specification
PtcRunner.Lisp.SpecValidator.validate_spec()
# Validate a single example
PtcRunner.Lisp.SpecValidator.validate_example("(+ 1 2)", 3)
# Get all examples from spec
examples = PtcRunner.Lisp.SpecValidator.extract_examples()
Summary
Functions
Get a hash of all examples in the specification.
Extract all examples from the specification.
Extract examples from specification content string.
Get negative test cases for Section 13 (unsupported features).
Get hashes for each section of the specification.
Validate a single example: code should produce expected result.
Validate a negative test case (should fail with specific error).
Validate all examples in the PTC-Lisp specification.
Functions
Get a hash of all examples in the specification.
Used to detect changes to the specification over time.
Extract all examples from the specification.
Returns a map with categorized examples:
examples- Testable examples as{code, expected, section}tuplestodos- TODO markers as{code, description, section}tuplesbugs- BUG markers as{code, description, section}tuplesskipped- Count of illustrative examples (using...)
Returns
{:ok, %{
examples: [{"(+ 1 2)", 3, "## Section"}, ...],
todos: [{"(code)", "description", "## Section"}, ...],
bugs: [],
skipped: 2
}}
Extract examples from specification content string.
Parses the markdown content and extracts code examples with expected values, TODO markers, BUG markers, and counts skipped illustrative examples.
Parameters
content- The specification markdown content as a string
Returns
%{
examples: [{"(+ 1 2)", 3, "## Section"}, ...],
todos: [{"(code)", "description", "## Section"}, ...],
bugs: [],
skipped: 2
}
@spec negative_tests() :: [tuple()]
Get negative test cases for Section 13 (unsupported features).
Returns a list of tuples: {feature_name, code, expected_error_type}.
These programs should all fail with specific error types.
Returns
[
{"def", "(def x 10)", :validation_error},
{"defn", "(defn foo [x] x)", :validation_error},
...
]
Get hashes for each section of the specification.
Returns a map of section headers to their content hashes. Used to detect drift in specific sections of the spec.
Returns
{:ok, %{
"## 1. Overview" => "hash1",
"## 2. Lexical Structure" => "hash2",
...
}}
Validate a single example: code should produce expected result.
Returns :ok if validation passes, {:error, reason} otherwise.
Examples
iex> PtcRunner.Lisp.SpecValidator.validate_example("(+ 1 2)", 3)
:ok
iex> PtcRunner.Lisp.SpecValidator.validate_example("(+ 1 2)", 4)
{:error, "Expected 4 but got 3"}
Validate a negative test case (should fail with specific error).
Returns :ok if the code fails with the expected error type,
{:error, reason} otherwise.
Validate all examples in the PTC-Lisp specification.
Returns a summary of results with counts of passed, failed, skipped examples, as well as TODO and BUG markers found in the spec.
Returns
{:ok, %{
passed: 95,
failed: 0,
skipped: 2,
todos: [{"(code)", "description", "## Section"}, ...],
bugs: [],
failures: [...]
}}