App-Test-Generator

 view release on metacpan or  search on metacpan

website/html/schema.html  view on Meta::CPAN

      - name: single_spaces
        description: No run of two or more spaces remains
        code: $result !~ /  /

      - name: reversible
        description: Length is unchanged
        code: length($result) == length($text)
</code></pre>

	<h2 id="corpus">cases and yaml_cases</h2>
	<p>
		A small static corpus maps an expected result to the arguments that
		produce it. This is the cheapest way to pin down behaviour you already
		know:
	</p>
<pre><code>cases:
  ok:
    input: ping
    _STATUS: OK
  error:
    input: ""
    _STATUS: DIES
</code></pre>
	<p>
		<code>yaml_cases</code> names a separate YAML file with the same shape, so
		a large corpus does not clutter the schema:
	</p>
<pre><code>yaml_cases: t/conf/corpus/greet.yml
</code></pre>

	<h2 id="edges">edge cases</h2>
	<p>
		Random generation will not stumble on the value that broke production.
		Say it instead. For named parameters, map parameter names to values:
	</p>
<pre><code>edge_cases:
  name: [ "", "a" x 1024, "\x{263A}" ]
  age: [ -1, 0, 99999999 ]
</code></pre>
	<p>
		For a routine with one unnamed parameter, use a list:
	</p>
<pre><code>edge_case_array:
  - "&lt;script&gt;alert('xss')&lt;/script&gt;"
  - "'; DROP TABLE users; --"
  - "\0null\0byte"
  - "emoji😊test"
  - ""
  - " "
</code></pre>
	<p>
		During fuzzing there is a 40% chance that a case draws from the array
		instead of the random generator, so these values are always exercised.
	</p>
	<p>
		<code>type_edge_cases</code> applies to every parameter of a given type,
		which is useful when a whole family of routines shares the same weakness:
	</p>
<pre><code>type_edge_cases:
  string: [ "", " ", "\t", "\n", "\0", "long" x 1024, "\x{1F600}" ]
  number: [ 0, 1.0, -1.0, 1e308, -1e308, 1e-308, "NaN", "Infinity" ]
  integer: [ 0, 1, -1, 2147483647, -2147483648 ]
</code></pre>

	<h2 id="repro">seed and iterations</h2>
<pre><code>seed: 42
iterations: 200
</code></pre>
	<p>
		<code>seed</code> makes the generated harness call <code>srand()</code>
		with that value, so a failing run repeats exactly — including strings
		generated from a <code>matches</code> pattern. A failing case names the
		seed and the input that was sent. <code>iterations</code>
		defaults to 30 random cases; the boundary and corpus cases are added on
		top of that, so the total test count is always higher.
	</p>

	<h2 id="accessor">accessor</h2>
<pre><code>accessor:
  property: ua
  type: getset
</code></pre>
	<p>
		Declares the routine an accessor on <code>property</code>, with
		<code>type</code> one of <code>getter</code>, <code>setter</code> or
		<code>getset</code>. The generated tests then check the getter/setter
		contract — that a set is visible to a get, and that the getter with no
		argument does not change state.
	</p>

	<div class="note">
		<span class="note-title">A schema is a promise, not a description</span>
		<p>
			The generated tests are black-box: they assert what the schema says the
			routine does. If a test fails, the question is whether the code or the
			schema is wrong — and the honest answer is sometimes the schema.
			Constraining a parameter to what the implementation happens to do today
			throws away the value of the test.
		</p>
	</div>

	<div class="pager">
		<a href="quickstart.html">← Quick start</a>
		<a href="commands.html">Commands →</a>
	</div>
</main>

<footer class="site-footer">
	<div class="wrap">
		<p>App::Test::Generator 0.52 — Copyright 2025&ndash;2026 Nigel Horne. Released under the GNU General Public License, version 2.</p>
		<p>
			<a href="https://metacpan.org/dist/App-Test-Generator">MetaCPAN</a> ·
			<a href="https://github.com/nigelhorne/App-Test-Generator">Source</a> ·
			<a href="https://nigelhorne.github.io/App-Test-Generator/coverage/">Test dashboard</a>
		</p>
	</div>
</footer>
</body>
</html>



( run in 1.401 second using v1.01-cache-2.11-cpan-60884a8df76 )