Assertion macros: values, fields, arrays, numerics, errors #8
Labels
No labels
area:assertions
area:cli
area:client
area:harness
area:meta
area:reporting
area:runner
type:user-story
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
charles/ws-rpc-test#8
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
User story
As a test author, I want assertion macros that produce structured failure messages with file/line context, so that test failures are immediately actionable without printf-debugging.
Acceptance criteria
Mechanics
#[macro_export]macros invoked from functions that returnTestResult. On failure they returnErr(TestError::Assertion { expected, got, context, location }).concat!(file!(), ":", line!())intolocation.expectedandgotas pretty JSON for readable diffs., "context message"argument that populatescontext.Value & field assertions (spec §3.1)
assert_ok!(value)— fails if value is a JSON-RPC error envelope ({"error": {...}}).assert_field!(value, field, expected)— single-key equality.assert_field!(value, path1, path2, ..., expected)— variadic for nested path traversal, resolving the spec inconsistency between §3.1 (3 args) and §9 (4 args). (Resolves spec review §3.)assert_field_exists!(value, field)/assert_field_absent!(value, field).assert_field_type!(value, field, "string"|"number"|"bool"|"array"|"object"|"null").Array assertions (spec §3.2)
assert_array!(value, range)— accepts anyRangeBounds<usize>:1..,..=5,3..=3, etc. Fails with a clear "expected length in {range}, got {n}" message.assert_array_contains!(value, |item| ...)— at least one item matches the closure.assert_array_all!(value, |item| ...)— all items match.Numeric assertions (spec §3.3)
assert_in_range!(value, range)— works for both integers and floats viaRangeBounds<f64>.assert_greater_than!(value, n),assert_less_than!(value, n).Error assertions (spec §3.4)
assert_error!(value, code)— fails if value is not an error or has a different code.assert_error_contains!(value, substring).Tests
tests/assert.rs.References