App-Test-Generator
view release on metacpan or search on metacpan
#### Custom Property Code
Custom properties allows the definition additional invariants and relationships that should hold for their transforms,
beyond what's auto-detected.
For example:
- Idempotence: f(f(x)) == f(x)
- Commutativity: f(x, y) == f(y, x)
- Associativity: f(f(x, y), z) == f(x, f(y, z))
- Inverse relationships: decode(encode(x)) == x
- Domain-specific invariants: Custom business logic
Define your own properties with custom Perl code:
transforms:
normalize:
input:
text:
type: string
output:
type: string
properties:
- name: single_spaces
description: "No multiple consecutive spaces"
code: $result !~ / /
- name: no_leading_space
description: "No space at start"
code: $result !~ /^\s/
- name: reversible
description: "Can be reversed back"
code: length($result) == length($text)
The code has access to:
- `$result` - The function's return value
- Input variables - All input parameters (e.g., `$text`, `$number`)
- The function itself - Can call it again for idempotence checks
#### Combining Auto-detected and Custom Properties
The generator automatically detects properties from your output spec, and adds
your custom properties:
transforms:
sanitize:
input:
html:
type: string
output:
type: string
min: 0 # Auto-detects: defined, min_length >= 0
max: 10000
properties: # Additional custom checks:
- name: no_scripts
code: $result !~ /<script/i
- name: no_iframes
code: $result !~ /<iframe/i
## GENERATED OUTPUT
The generated test:
- Seeds RND (if configured) for reproducible fuzz runs
- Uses edge cases (per-field and per-type) with configurable probability
- Runs `$iterations` fuzz cases plus appended edge-case runs
- Validates inputs with Params::Get / Params::Validate::Strict
- Validates outputs with [Return::Set](https://metacpan.org/pod/Return%3A%3ASet)
- Runs static `is(... )` corpus tests from Perl and/or YAML corpus
- Runs [Test::LectroTest](https://metacpan.org/pod/Test%3A%3ALectroTest) tests
# METHODS
## generate
Takes a schema file and produces a test file (or STDOUT).
# Modern named API
App::Test::Generator->generate(
schema_file => 'schemas/foo.yml',
output_file => 'test/foo.t',
);
# Legacy positional API
App::Test::Generator->generate($schema_file, $test_file);
### API Specification
#### Input
{
schema_file => { type => 'string', optional => 1 },
input_file => { type => 'string', optional => 1 },
output_file => { type => 'string', optional => 1 },
schema => { type => 'hashref', optional => 1 },
quiet => { type => 'boolean', optional => 1 },
}
#### Output
{ type => 'string' }
## render\_fallback
Render any Perl value into a compact Perl source-code string using
[Data::Dumper](https://metacpan.org/pod/Data%3A%3ADumper). Used as a catch-all when no more specific renderer
applies.
my $code = render_fallback({ key => 'value' });
# returns: "{'key' => 'value'}"
### Arguments
- `$v`
Any Perl value, including undef, scalars, refs, and blessed objects.
### Returns
A string of Perl source code that reproduces the value when evaluated.
( run in 0.509 second using v1.01-cache-2.11-cpan-13bb782fe5a )