App-Test-Generator

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

      methods (Pass 3)
    - App::Test::Generator: added relationships_code emission so schemas
      containing relationship metadata produced by SchemaExtractor are
      serialised into the generated test file
    - Template test.tt: added semantic type test cases for filepath
      (including Windows paths, reserved device names, UNC paths),
      email, date_string, and iso8601_string; added relationship test
      loop covering all six relationship types (mutually_exclusive,
      required_group, conditional_requirement, dependency,
      value_constraint, value_conditional); added float edge cases for
      Inf, -Inf, and NaN with correct status handling based on whether
      max is defined

0.32	Sun Apr 12 08:16:47 EDT 2026

    - Added detect_scattered_failures() root cause detector. Surfaces a
      weak-confidence advisory when failures and passes coexist across
      2 or more common Perl series with no detectable version cliff or
      OS pattern, suggesting flaky tests, optional dependency
      differences, or CGI environment assumptions rather than a
      compatibility issue. Complements detect_universal_failure() which

README.md  view on Meta::CPAN

Values can be strings or numbers; strings will be properly quoted.
Note that this only works with routines that take named parameters.

#### `%type_edge_cases`

An optional hash mapping types to arrayrefs of extra values to try for any field of that type:

```
    type_edge_cases:
            string: [ '', ' ', "\t", "\n", "\0", 'long' x 1024, chr(0x1F600) ]
            number: [ 0, 1.0, -1.0, 1e308, -1e308, 1e-308, -1e-308, 'NaN', 'Infinity' ]
            integer: [ 0, 1, -1, 2**31-1, -(2**31), 2**63-1, -(2**63) ]
```

#### `%edge_case_array`

Specify edge case values for routines that accept a single unnamed parameter.
This is specifically designed for simple functions that take one argument without a parameter name.
These edge cases supplement the normal random string generation, ensuring specific problematic values are always tested.
During fuzzing iterations, there's a 40% probability that a test case will use a value from edge\_case\_array instead of randomly generated data.

bin/test-generator-index  view on Meta::CPAN

		const cellB = b.cells[colIndex];
		let x = (cellA?.dataset.value ?? cellA?.innerText ?? "").trim();
		let y = (cellB?.dataset.value ?? cellB?.innerText ?? "").trim();

		if(isDate) {
			x = Date.parse(x) || 0;
			y = Date.parse(y) || 0;
		} else {
			const nx = parseFloat(x);
			const ny = parseFloat(y);
			if(!isNaN(nx) && !isNaN(ny)) {
				x = nx;
				y = ny;
			} else {
				x = x.toLowerCase();
				y = y.toLowerCase();
			}
		}

		if(x < y) return asc ? -1 : 1;
		if(x > y) return asc ? 1 : -1;

lib/App/Test/Generator.pm  view on Meta::CPAN


Values can be strings or numbers; strings will be properly quoted.
Note that this only works with routines that take named parameters.

=head3 C<%type_edge_cases>

An optional hash mapping types to arrayrefs of extra values to try for any field of that type:

	type_edge_cases:
		string: [ '', ' ', "\t", "\n", "\0", 'long' x 1024, chr(0x1F600) ]
		number: [ 0, 1.0, -1.0, 1e308, -1e308, 1e-308, -1e-308, 'NaN', 'Infinity' ]
		integer: [ 0, 1, -1, 2**31-1, -(2**31), 2**63-1, -(2**63) ]

=head3 C<%edge_case_array>

Specify edge case values for routines that accept a single unnamed parameter.
This is specifically designed for simple functions that take one argument without a parameter name.
These edge cases supplement the normal random string generation, ensuring specific problematic values are always tested.
During fuzzing iterations, there's a 40% probability that a test case will use a value from edge_case_array instead of randomly generated data.

  ---

lib/App/Test/Generator/BenchmarkGenerator.pm  view on Meta::CPAN

	integer => 42,
	float   => 3.14,
	string  => "'hello'",
	boolean => 1,
	arrayref => '[]',
	hashref  => '{}',
);

Readonly my $BAREWORD_RE => qr/^[A-Za-z_]\w*\z/a;

# Narrower than looks_like_number(), which also accepts Inf, NaN and
# surrounding whitespace - none of which are valid unquoted Perl source.
Readonly my $NUMERIC_LITERAL_RE => qr/^-?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?\z/a;

=encoding utf8

=head1 NAME

App::Test::Generator::BenchmarkGenerator - Generate Benchmark harnesses from ATG schemas

=head1 VERSION

lib/App/Test/Generator/BenchmarkGenerator.pm  view on Meta::CPAN

=item Names that are not plain words are quoted for you

Transform names, parameter names and the keys under C<new> can contain
any characters.  They are quoted and escaped in the generated script when
needed.  Only C<module> and C<function> must be valid Perl names.

=item Which text is written as a number

A string under C<new> is written without quotes only when it is a plain
decimal number such as C<42>, C<-1.5> or C<2e10>.  Everything else,
including C<'Inf'>, C<'NaN'> and C<' 12'>, is written as a quoted string.
Be careful with a leading zero: C<'007'> is written as C<007>, which Perl
reads as an octal number.

=back

=head1 ENCODING

=over 4

=item * C<module> and C<function>

lib/App/Test/Generator/Template.pm  view on Meta::CPAN

			if(!defined($spec->{max}) || ($spec->{max} >= 43.56));
	}

	[% IF module %]
		# Send wrong data type - builtins aren't good at checking this
		push @cases,
			_spec_type_is_enforced($spec) ? (
			{ %{$mandatory_args}, ( $arg_name => "test string in float field $arg_name", _STATUS => 'DIES', _LINE => __LINE__ ) },
			{ %{$mandatory_args}, ( $arg_name => {}, _STATUS => 'DIES', _LINE => __LINE__ ) },
			{ %{$mandatory_args}, ( $arg_name => \42.1, _STATUS => 'DIES' ) },	# Scalar ref
			# NaN and Inf are valid according to looks_like_number() so we
			# cannot assume they die
			# { %{$mandatory_args}, ( $arg_name => "NaN", _STATUS => 'DIES' ) },
			{ %{$mandatory_args}, ( $arg_name => [], _STATUS => 'DIES', _LINE => __LINE__ ) }
			) : ();
	[% END %]

	# min/max numeric boundaries
	if (defined $spec->{min}) {
		my $min = $spec->{min};
		if($min_strict) {
			push @cases, { %{$mandatory_args}, ( $arg_name => $min - 0.001, _STATUS => 'DIES' ), _DESCRIPTION => 'float below minimum value is denied' };
		} else {

t/BenchmarkGenerator_unit.t  view on Meta::CPAN

	ok(!defined $schema->{input}{x}, 'undef parameter spec is still undef');
	like($src, qr/x => undef/, 'undef parameter spec is passed as undef');
};

subtest 'generate() writes constructor values as valid literals' => sub {
	my $bg = App::Test::Generator::BenchmarkGenerator->new(schema => {
		module   => 'My::Mod',
		function => 'ping',
		new      => {
			inf    => 'Inf',
			nan    => 'NaN',
			padded => ' 12',
			sci    => '-1.5e3',
			slash  => 'ends\\',
			nested => { list => [ 1, q{x'y} ] },
		},
	});
	my $src = $bg->generate();
	like($src, qr/inf => 'Inf'/,    'Inf is quoted');
	like($src, qr/nan => 'NaN'/,    'NaN is quoted');
	like($src, qr/padded => ' 12'/, 'number with leading space is quoted');
	like($src, qr/sci => -1\.5e3/,  'plain number is not quoted');
	unlike($src, qr/HASH\(0x/,      'nested hashref is not stringified');
	like($src, qr/nested => \{'list' => \[1,'x\\'y'\]\}/, 'nested data is written out');
	ok(_compiles($src), 'generated Perl compiles');
};

subtest 'generate() croaks on a constructor value it cannot write' => sub {
	my $bg = App::Test::Generator::BenchmarkGenerator->new(schema => {
		module   => 'My::Mod',

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

	<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



( run in 2.758 seconds using v1.01-cache-2.11-cpan-60884a8df76 )