lib/App/Test/Generator.pm

filter: Statementstmt 88.8% 904 / 1017 Branchbran 80.1% 516 / 644 Conditioncond 69.6% 280 / 402 MC/DCmcdc 51.7% 121 / 234 Subroutinesub 98.6% 75 / 76 Podpod 75.0% 6 / 8 totaltotal 79.8% 1902 / 2381 CC 504 SCAR 57.3
CC
504
Cov
82%
generate
869.4
_schema_to_lectrotest_generator
41.1
_detect_transform_properties
36.9
CRAP 309.1
↑ Summary blib/lib/App/Test/Generator/SchemaExtractor.pm »
1 package App::Test::Generator;
2  
3 # FIXME: SchemaExtractor does not strip comments before scanning for a sub's parameters,
4 # so a comment that quotes a parameter-declaration idiom is read as a real declaration
5 # and fails --strict-pod=fatal (seen in generate(); the comment there was reworded)
6 # FIXME: Schema extraction is not deterministic: SchemaExtractor::_build_schema_from_meta
7 # extracts its output type as hashref on some runs and string on others (hash order)
8 # TODO: Test validator from Params::Validate::Strict 0.16
9 # TODO: positional args - when config_undef is set, see what happens when not all args are given
10 # TODO: The Dup and TER1/2/3 columns should be moved from the Mutation table
11 # to a new table called Metrics. Add Halstead and McCabes metrics to
12 # this new Metrics table. Include links to the definitions of TER1/2/3,
13 # Halstead and McCabes metrics, perhaps from Wikipedia
14 # TODO: Template.pm public API (27/28 subs) lacks POD documentation; add =head2 sections
15 # with =head4 input / =head4 output formal specs for each public sub
16 # TODO: SchemaExtractor does not traverse @ISA for inherited constructors; if a module's
17 # constructor is defined in a parent class, extract_all() may miss representative
18 # constructor args and emit new:~ (unenrichable) instead of inferring from the base class
19 # TODO: Magic-number probability constants in Template.pm (e.g. rand() < 0.3) should be
20 # Readonly module-level constants with ALL_CAPS_SNAKE names for maintainability
21 # TODO: Difficulty constants are duplicated between bin/test-generator-mutate and Mutator.pm;
22 # consolidate into a single source of truth (e.g. Readonly constants in Mutator.pm,
23 # imported by the CLI)
24 # TODO: validate_email in Sample::Module needs a matches: regex in its formal input spec
25 # so fuzz-harness-generator can generate structurally valid email inputs and the harness
26 # can be removed from %no_fuzz in t/self-fuzz.t
27  
28 225 ▶use 5.036;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 225 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 225 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 225 ▶use autodie qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
33  
34 225 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 225 ▶use open qw(:std :encoding(UTF-8));
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37 225 ▶use App::Test::Generator::Provenance ();
Subroutine BEGIN: called CC=1 SCAR=0.0
38 225 ▶use App::Test::Generator::Template;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 225 ▶use Carp qw(carp croak confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
40 225 ▶use Config::Abstraction 0.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 225 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
42 225 ▶use Data::Section::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
43 225 ▶use File::Basename qw(basename);
Subroutine BEGIN: called CC=1 SCAR=0.0
44 225 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
45 225 ▶use Module::Load::Conditional qw(check_install can_load);
Subroutine BEGIN: called CC=1 SCAR=0.0
46 225 ▶use Params::Get;
Subroutine BEGIN: called CC=1 SCAR=0.0
47 225 ▶use Params::Validate::Strict 0.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
48 225 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
49 225 ▶use Readonly::Values::Boolean;
Subroutine BEGIN: called CC=1 SCAR=0.0
50 225 ▶use Scalar::Util qw(looks_like_number);
Subroutine BEGIN: called CC=1 SCAR=0.0
51 225 ▶use re 'regexp_pattern';
Subroutine BEGIN: called CC=1 SCAR=0.0
52 225 ▶use Template;
Subroutine BEGIN: called CC=1 SCAR=0.0
53 225 ▶use YAML::XS qw(LoadFile);
Subroutine BEGIN: called CC=1 SCAR=0.0
54  
55 225 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
56  
57 225 our @EXPORT_OK = qw(generate);
58  
59 225 our $VERSION = '0.52';
60  
61 225 Readonly my $DEFAULT_ITERATIONS => 30;
62 225 Readonly my $DEFAULT_PROPERTY_TRIALS => 1000;
63  
64 # Hash for O(1) lookup rather than a list needing grep O(n)
65 225 Readonly my %VALID_CONFIG_KEYS => map { $_ => 1 } qw(
66 test_nuls test_undef test_empty test_non_ascii
67 dedup properties close_stdin test_security timeout regex_timeout
68 check_files check_fds check_accessors
69 );
70  
71 # --------------------------------------------------
72 # Delimiter pairs tried in order when wrapping a
73 # string with q{} — bracket forms are preferred as
74 # they are most readable in generated test code
75 # --------------------------------------------------
76 225 Readonly my @Q_BRACKET_PAIRS => (
77 ['{', '}'],
78 ['(', ')'],
79 ['[', ']'],
80 ['<', '>'],
81 );
82  
83 # --------------------------------------------------
84 # Single-character delimiters tried when no bracket
85 # pair is usable — each is tried in order and the
86 # first one not present in the string is used.
87 # The # character is last since it starts comments
88 # in many contexts and is least readable
89 # --------------------------------------------------
90 225 Readonly my @Q_SINGLE_DELIMITERS => (
91 '~', '!', '%', '^', '=', '+', ':', ',', ';', '|', '/', '#'
92 );
93  
94 # --------------------------------------------------
95 # Sentinel returned by index() when the search
96 # string is not found — used to make the >= 0
97 # boundary check self-documenting and to prevent
98 # NumericBoundary mutants from surviving
99 # --------------------------------------------------
100 225 Readonly my $INDEX_NOT_FOUND => -1;
101  
102 # --------------------------------------------------
103 # Readonly constants for schema validation
104 # --------------------------------------------------
105 225 Readonly my $CONFIG_PROPERTIES_KEY => 'properties';
106 225 Readonly my $LEGACY_PERL_KEY_1 => '$module';
107 225 Readonly my $LEGACY_PERL_KEY_2 => 'our $module';
108 225 Readonly my $SOURCE_KEY => '_source';
109  
110 # --------------------------------------------------
111 # Readonly constants for render_hash key detection
112 # --------------------------------------------------
113 225 Readonly my $KEY_MATCHES => 'matches';
114 225 Readonly my $KEY_NOMATCH => 'nomatch';
115  
116 # --------------------------------------------------
117 # Reserved module name indicating a Perl builtin
118 # function rather than a CPAN or user module
119 # --------------------------------------------------
120 225 Readonly my $MODULE_BUILTIN => 'builtin';
121  
122 # --------------------------------------------------
123 # Regex pattern matched against transform names to
124 # detect the positive/non-negative idempotence
125 # heuristic in _detect_transform_properties
126 # --------------------------------------------------
127 225 Readonly my $TRANSFORM_POSITIVE_PATTERN => 'positive';
128  
129 # --------------------------------------------------
130 # Default type assumed for schema fields that declare
131 # no explicit type — used in generator selection and
132 # dominant-type detection
133 # --------------------------------------------------
134 225 Readonly my $DEFAULT_FIELD_TYPE => 'string';
135  
136 # --------------------------------------------------
137 # Default range used by the LectroTest float/integer
138 # generators when no min or max constraint is given.
139 # Chosen to provide a useful spread without producing
140 # values so large they overflow downstream arithmetic.
141 # --------------------------------------------------
142 225 Readonly my $DEFAULT_GENERATOR_RANGE => 1000;
143  
144 # --------------------------------------------------
145 # Default upper bound on the number of elements in
146 # generated arrayrefs and hashrefs when no max is
147 # declared in the schema.
148 # --------------------------------------------------
149 225 Readonly my $DEFAULT_MAX_COLLECTION_SIZE => 10;
150  
151 # --------------------------------------------------
152 # Default upper bound on generated string length
153 # when no max is declared in the schema.
154 # --------------------------------------------------
155 225 Readonly my $DEFAULT_MAX_STRING_LEN => 100;
156  
157 # --------------------------------------------------
158 # Sentinel for the zero boundary used in float
159 # generator selection — comparing min/max against
160 # this constant makes the boundary intent explicit
161 # and prevents NumericBoundary mutants from surviving.
162 # --------------------------------------------------
163 225 Readonly my $ZERO_BOUNDARY => 0;
164  
165 # --------------------------------------------------
166 # Environment variable names used to control verbose
167 # output and optional load validation in
168 # _validate_module. Centralised here so they are
169 # easy to find and consistent across the codebase.
170 # --------------------------------------------------
171 225 Readonly my $ENV_TEST_VERBOSE => 'TEST_VERBOSE';
172 225 Readonly my $ENV_GENERATOR_VERBOSE => 'GENERATOR_VERBOSE';
173 225 Readonly my $ENV_VALIDATE_LOAD => 'GENERATOR_VALIDATE_LOAD';
174  
175 =encoding utf8
176  
177 =head1 NAME
178  
179 App::Test::Generator - Fuzz Testing, Mutation Testing, LCSAJ Metrics and Test Dashboard for Perl modules
180  
181 =head1 VERSION
182  
183 Version 0.52
184  
185 =head1 SYNOPSIS
186  
187 C<App::Test::Generator> is a suite to help the testing of CPAN modules.
188 It consists of 6 subsystems:
189  
190 =over 4
191  
192 =item * Fuzz Tester
193  
194 =item * Mutation Testing
195  
196 =item * LCSAJ Metrics
197  
198 =item * Test Dashboard
199  
200 =item * Benchmark Generation
201  
202 =item * Workflow Deployment
203  
204 =back
205  
206 From the command line:
207  
208 # Takes the formal definition of a routine, creates tests against that routine, and runs the test
209 fuzz-harness-generator -r t/conf/abs.yml
210  
211 # Attempt to create a formal definition from a routine package, then run tests against that formal definition
212 # This is the Holy Grail of test generation, a set of tests is automatically created directly from the source code,
213 extract-schemas lib/App/Test/Generator/Sample/Module.pm && fuzz-harness-generator -r schemas/greet.yml
214  
215 # Fuzz a module and keep the corpus bounded: trim to the minimum subset that still covers every branch
216 extract-schemas --fuzz --minimize-corpus lib/My/Module.pm
217  
218 # Generate round-trip tests that run every code example in a module's POD and verify the results
219 pod-example-tester lib/My/Module.pm --output t/pod_examples.t
220  
221 # Generate a Benchmark::cmpthese script from a schema; each transform becomes one timed variant
222 benchmark-generator -i schemas/abs.yml -o benchmarks/abs.pl
223  
224 # Copy dashboard.yml and mutate.yml into a module repository's .github/workflows/ directory
225 deploy-workflows --target /path/to/my-module
226  
227 From Perl:
228  
229 use App::Test::Generator qw(generate);
230 use App::Test::Generator::SchemaExtractor;
231  
232 # Generate to STDOUT
233 App::Test::Generator->generate("t/conf/abs.yml");
234  
235 # Generate directly to a file
236 App::Test::Generator->generate('t/conf/abs.yml', 't/add_fuzz.t');
237  
238 # Holy grail mode - read a Perl file, generate tests, and run them
239 # This is a long way away yet, but see t/schema_input.t for a proof of concept
240 my $extractor = App::Test::Generator::SchemaExtractor->new(
241 input_file => 'lib/App/Test/Generator/Template.pm',
242 output_dir => '/tmp',
243 );
244 my $schemas = $extractor->extract_all();
245 use File::Temp qw(tempfile);
246 foreach my $schema(keys %{$schemas}) {
247 my ($fh, $tempfile) = tempfile(SUFFIX => '.t', UNLINK => 1);
248 close $fh;
249 App::Test::Generator->generate(
250 schema => $schemas->{$schema},
251 output_file => $tempfile,
252 );
253 system($^X, '-Ilib', $tempfile);
254 }
255  
256 =head1 OVERVIEW
257  
258 This module takes a formal input/output specification for a routine or
259 method and automatically generates test cases. In effect, it allows you
260 to easily add comprehensive black-box tests in addition to the more
261 common white-box tests that are typically written for CPAN modules and other
262 subroutines.
263  
264 The generated tests combine:
265  
266 =over 4
267  
268 =item * Random fuzzing based on input types
269  
270 =item * Deterministic edge cases for min/max constraints
271  
272 =item * Static corpus tests defined in Perl or YAML
273  
274 =back
275  
276 This approach strengthens your test suite by probing both expected and
277 unexpected inputs, helping you to catch boundary errors, invalid data
278 handling, and regressions without manually writing every case.
279  
280 =head1 TOOLS
281  
282 The distribution ships the following command-line tools:
283  
284 =over 4
285  
286 =item * L<benchmark-generator> - generate a self-contained L<Benchmark> C<cmpthese> script from a YAML schema. Each transform in the schema becomes one named variant; representative input values are derived from each parameter's type and range constraints.
287  
288 =item * L<deploy-workflows> - copy C<dashboard.yml> and C<mutate.yml> into the target repository's C<.github/workflows/> directory. Both files are embedded verbatim in the script, so no ATG source tree is needed after installation. Supports C<--target>, C<--force>, and C<--dry-run>.
289  
290 To add a test dashboard to your CPAN module: copy these scripts into your C<.github/workflows> directory,
291 then commit the changes to GitHub and enable the page through C<Settings-Pages-branch = gh_pages>:
292  
293 =over 4
294  
295 =item * L<https://github.com/nigelhorne/App-Test-Generator/blob/master/.github/workflows/dashboard.yml>
296  
297 =item * L<https://github.com/nigelhorne/App-Test-Generator/blob/master/.github/workflows/mutate.yml>
298  
299 =back
300  
301 =item * L<extract-schemas> - heuristically extract YAML parameter schemas from a C<.pm> file, with optional coverage-guided fuzzing (C<--fuzz>) and corpus minimization (C<--minimize-corpus>).
302  
303 =item * L<fuzz-harness-generator> - generate a C<Test::Most> fuzzing harness from a YAML schema.
304  
305 =item * L<pod-example-tester> - generate a C<Test::Most> round-trip test file from a module's POD code examples. Annotated examples (C<# returns value> / C<< # => value >>) get C<is()> assertions; unannotated verbatim blocks are wrapped in C<eval{}> and checked for no exception.
306  
307 =item * L<test-generator-mutate> - run mutation testing against a module's test suite.
308  
309 =item * L<test-generator-index> - generate the HTML test-quality dashboard, combining Devel::Cover statement/branch data, LCSAJ path coverage, mutation results, and CPAN Testers failure analysis. For each CPAN Testers FAIL report, also writes a self-contained shell script (C<cover_html/reproduce/reproduce-GUID.sh>) that pins every installed module at its exact failing version, enabling local reproduction of the failure environment.
310  
311 =back
312  
313 =head1 DESCRIPTION
314  
315 This module implements the logic behind L<fuzz-harness-generator>.
316 It parses configuration files (fuzz and/or corpus YAML), and
317 produces a ready-to-run F<.t> test script to run through C<prove>.
318  
319 It reads configuration files in any format,
320 and optional YAML corpus files.
321 All of the examples in this documentation are in C<YAML> format,
322 other formats may not work as they aren't so heavily tested.
323 It then generates a L<Test::Most>-based fuzzing harness combining:
324  
325 =over 4
326  
327 =item * Randomized fuzzing of inputs (with edge cases)
328  
329 =item * Optional static corpus tests from Perl C<%cases> or YAML file (C<yaml_cases> key)
330  
331 =item * Functional or OO mode (via C<$new>)
332  
333 =item * Reproducible runs via C<$seed> and configurable iterations via C<$iterations>
334  
335 =back
336  
337 =head1 MUTATION-GUIDED TEST GENERATION
338  
339 C<App::Test::Generator> includes a pipeline that automatically closes the
340 feedback loop between mutation testing, schema extraction, and fuzz
341 testing. The goal is that surviving mutants drive the creation of new
342 tests that kill them on the next run, without manual intervention.
343  
344 =head2 The Pipeline
345  
346 mutation survivor
347 |
348 v
349 SchemaExtractor extracts the schema for the enclosing sub
350 |
351 v
352 Schema augmented with boundary values from the mutant
353 |
354 v
355 Augmented schema written to t/conf/
356 |
357 v
358 t/fuzz.t picks up the new schema and runs fuzz tests
359 |
360 v
361 Mutation killed on next run
362  
363 =head2 How to Use It
364  
365 The pipeline is driven by three flags passed to
366 C<bin/test-generator-index>, which is invoked automatically by
367 C<bin/generate-test-dashboard> on each CI push.
368  
369 =head3 Step 1: Generate TODO stubs for all survivors
370  
371 bin/test-generator-index --generate_mutant_tests=t
372  
373 Produces C<t/mutant_YYYYMMDD_HHMMSS.t> containing:
374  
375 =over 4
376  
377 =item * TODO stubs for HIGH and MEDIUM difficulty survivors, with
378 boundary value suggestions, environment variable hints, and the
379 enclosing subroutine name for navigation context.
380  
381 =item * Comment-only hints for LOW difficulty survivors.
382  
383 =back
384  
385 Multiple mutations on the same source line are deduplicated into one
386 stub. One good test kills all variants on that line.
387  
388 =head3 Step 2: Generate runnable schemas for NUM_BOUNDARY survivors
389  
390 bin/test-generator-index \
391 --generate_mutant_tests=t \
392 --generate_test=mutant
393  
394 For each NUM_BOUNDARY survivor, calls
395 L<App::Test::Generator::SchemaExtractor> to extract the schema for
396 the enclosing subroutine. If the confidence level is sufficient, the
397 schema is augmented with the boundary value from the mutant (plus one
398 value either side) and written to C<t/conf/> as a runnable YAML file.
399 L<t/fuzz.t> picks it up automatically on the next test run.
400  
401 Falls back to a TODO stub if:
402  
403 =over 4
404  
405 =item * SchemaExtractor cannot parse the file
406  
407 =item * The enclosing sub cannot be determined
408  
409 =item * The extracted schema confidence is C<very_low> or C<none>
410  
411 =back
412  
413 =head3 Step 3: Augment existing schemas with survivor boundary values
414  
415 bin/test-generator-index \
416 --generate_mutant_tests=t \
417 --generate_test=mutant \
418 --generate_fuzz
419  
420 Scans C<t/conf/> for existing YAML schema files (hand-written or
421 previously generated) and writes augmented copies with boundary values
422 from surviving NUM_BOUNDARY mutants merged in. The original schema is
423 never modified. Augmented copies are written as
424 C<t/conf/mutant_fuzz_YYYYMMDD_HHMMSS_FUNCTION.yml> and picked up
425 automatically by C<t/fuzz.t>.
426  
427 Schemas whose filename already starts with C<mutant_fuzz_> are skipped
428 to prevent cascading augmentation. Schemas with no matching survivors
429 are skipped, with a note if C<--verbose> is active.
430  
431 =head3 Putting It All Together
432  
433 The recommended invocation in C<bin/generate-test-dashboard>
434 Step 7 runs all three stages together:
435  
436 bin/test-generator-index \
437 --generate_mutant_tests=t \
438 --generate_test=mutant \
439 --generate_fuzz
440  
441 The GitHub Actions workflow in C<.github/workflows/dashboard.yml>
442 then commits any new C<t/mutant_*.t> and C<t/conf/mutant_*.yml> files
443 to the repository so they accumulate over time as the test suite
444 improves.
445  
446 =head2 Confidence Levels
447  
448 L<App::Test::Generator::SchemaExtractor> assigns a confidence level
449 to each extracted schema:
450  
451 =over 4
452  
453 =item * C<high> / C<medium> / C<low> - Schema is used for test generation
454  
455 =item * C<very_low> / C<none> - Falls back to TODO stub
456  
457 =back
458  
459 Confidence is based on how much type and constraint information could
460 be inferred from the source code and its POD documentation. Methods
461 with explicit parameter validation (L<Params::Validate::Strict>,
462 L<Params::Get>) or comprehensive POD will produce higher-confidence
463 schemas.
464  
465 =head2 Files Produced
466  
467 =over 4
468  
469 =item * C<t/mutant_YYYYMMDD_HHMMSS.t>
470  
471 TODO stub file for all survivors. Committed to the repository by the
472 GitHub Actions workflow.
473  
474 =item * C<t/conf/mutant_MODNAME_FUNCTION_YYYYMMDD_HHMMSS.yml>
475  
476 Runnable YAML schema for a NUM_BOUNDARY survivor where SchemaExtractor
477 confidence was sufficient. Picked up by C<t/fuzz.t>.
478  
479 =item * C<t/conf/mutant_fuzz_YYYYMMDD_HHMMSS_FUNCTION.yml>
480  
481 Augmented copy of an existing schema with survivor boundary values
482 merged in. Picked up by C<t/fuzz.t>.
483  
484 =back
485  
486 =head2 See Also
487  
488 =over 4
489  
490 =item * L<App::Test::Generator::SchemaExtractor> - Schema extraction
491 from Perl source code
492  
493 =item * L<bin/test-generator-index> - Dashboard generator and
494 pipeline driver
495  
496 =item * L<bin/generate-test-dashboard> - Full pipeline runner
497  
498 =back
499  
500 =head1 CONFIGURATION
501  
502 The configuration file,
503 for each set of tests to be produced,
504 is a file containing a schema that can be read by L<Config::Abstraction>.
505  
506 =head2 SCHEMA
507  
508 The schema is split into several sections.
509  
510 =head3 C<%input> - input params with keys => type/optional specs
511  
512 When using named parameters
513  
514 input:
515 name:
516 type: string
517 optional: false
518 age:
519 type: integer
520 optional: true
521  
522 Supported basic types used by the fuzzer: C<string>, C<integer>, C<float>, C<number>, C<boolean>, C<arrayref>, C<hashref>.
523 See also L<Params::Validate::Strict>.
524 You can add more custom types using properties.
525  
526 A nested C<schema> describes the elements of an C<arrayref> or the values of a
527 C<hashref>. Element schemas are full specs, so they carry their own
528 constraints and can nest again:
529  
530 input:
531 words:
532 type: arrayref
533 min: 1
534 max: 3
535 schema:
536 type: string
537 min: 3
538 max: 10
539 scores:
540 type: hashref
541 schema:
542 type: integer
543 min: 0
544 max: 100
545 record:
546 type: hashref
547 schema:
548 name:
549 type: string
550 min: 2
551 max: 20
552 age: integer
553 grid:
554 type: arrayref
555 schema:
556 type: arrayref
557 min: 1
558 max: 2
559 schema:
560 type: integer
561 min: 0
562 max: 9
563 things:
564 type: arrayref
565 schema:
566 type: object
567 isa: My::Thing # needs a no-argument constructor
568 # or: can: label # mocked with Class::Simple
569  
570 A hashref C<schema> without a C<type> is a map of fixed key names to element
571 schemas, so generated valid data uses those keys instead of random filler.
572 Generated element values satisfy the element's own constraints.
573  
574 For routines with one unnamed parameter
575  
576 input:
577 type: string
578  
579 For routines with more than one named parameter, use the C<position> keyword.
580  
581 module: Math::Simple::MinMax
582 fuction: max
583  
584 input:
585 left:
586 type: number
587 position: 0
588 right:
589 type: number
590 position: 1
591  
592 output:
593 type: number
594  
595 A routine can take positional arguments followed by named options, as
596 C<< sub publish { my ($message, %opts) = @_ } >> does. Give the leading
597 arguments their positions and mark every trailing option C<named: 1>:
598  
599 input:
600 message:
601 type: string
602 position: 0
603 priority:
604 type: integer
605 optional: 1
606 named: 1
607  
608 # publish($message, priority => $priority)
609  
610 A parameter in a schema that declares positions must say which it is: a
611 missing position on a parameter without C<named: 1> is an error, not a
612 second call shape.
613  
614 A numeric parameter can document a range whose top end this harness cannot
615 afford to reach: a count of hashing rounds costs time in proportion to the
616 value, so one call at the documented maximum can take minutes. C<sample_max>
617 limits the valid data that is generated while C<max> stays the documented
618 bound, so a value above C<max> is still probed (and refused cheaply):
619  
620 input:
621 rounds:
622 type: integer
623 named: 1
624 optional: 1
625 min: 10_000
626 max: 100_000_000
627 sample_max: 200_000
628  
629 The keyword C<undef> is used to indicate that the C<function> takes no arguments.
630  
631 =head3 C<%output> - output param types for L<Return::Set> checking
632  
633 output:
634 type: string
635  
636 If the output hash contains the key _STATUS, and if that key is set to DIES,
637 the routine should die with the given arguments; otherwise, it should live.
638 If it's set to WARNS,
639 the routine should warn with the given arguments.
640 The output can be set to the string 'undef' if the routine should return the undefined value:
641  
642 ---
643 module: Scalar::Util
644 function: blessed
645  
646 input:
647 type: string
648  
649 output: undef
650  
651 The keyword C<undef> is used to indicate that the C<function> returns nothing.
652  
653 For methods that return a list (rather than a reference), use C<type: array>.
654 The generated test captures the result in list context and validates it as an
655 arrayref, which requires L<Test::Returns> 0.03 or later:
656  
657 output:
658 type: array
659  
660 =head3 C<%config> - optional hash of configuration.
661  
662 The current supported variables are
663  
664 =over 4
665  
666 =item * C<close_stdin>
667  
668 Tests should not attempt to read from STDIN (default: 1).
669 This is ignored on Windows, when never closes STDIN.
670  
671 =item * C<test_nuls>, inject NUL bytes into strings (default: 1)
672  
673 With this test enabled, the function is expected to die when a NUL byte is passed in.
674  
675 =item * C<test_undef>, test with undefined value (default: 1)
676  
677 =item * C<test_empty>, test with empty strings (default: 1)
678  
679 =item * C<test_non_ascii>, test with strings that contain non ascii characters (default: 1)
680  
681 =item * C<timeout>, ensure tests don't hang (default: 10)
682  
683 =item * C<regex_timeout>, seconds allowed for generating one string that
684 matches a regex pattern (default: 5)
685  
686 A pattern the generator cannot satisfy, or one that makes it search for too
687 long, falls back to a fixed matching value; when none exists the pattern's
688 cases are skipped and reported once instead of failing the run. Matching
689 strings are generated from the seeded RNG, so a schema's C<seed> makes them
690 reproducible.
691  
692 Setting this to 0 disables timeout testing.
693  
694 =item * C<check_files>, assert the routine leaves no files in the working
695 directory (default: 1)
696  
697 Every call is checked for files it created. They are removed afterwards
698 whatever the setting, so a routine that writes a file cannot break the cases
699 that follow it; set this to 0 for a routine whose purpose is to write one.
700 C<extract-schemas> sets it to 0 when the routine's POD documents creating or
701 writing a file in its SIDE EFFECTS section.
702  
703 =item * C<check_fds>, assert the routine leaks no file descriptors
704 (default: 1)
705  
706 Only checked where F</proc/self/fd> exists. Set this to 0 for a routine that
707 returns a filehandle to its caller, which still holds a descriptor.
708  
709 The first descriptor a call opens on a given file (or its first socket or
710 pipe) is taken as a resource held on purpose, such as a log file an object
711 opens on first use, and is not reported. A later call that opens the same
712 target again is.
713  
714 =item * C<check_accessors>, assert an accessor leaves the object it was called
715 on alone (default: 1)
716  
717 The object is deep copied before each call and the state it was handed
718 compared afterwards. A getter that overwrites or deletes that state fails
719 "getter leaves its object unmodified"; a getset that changes anything but the
720 property it is named for fails "setter changes nothing but its property".
721 Values the call fills in where it was handed undef, and keys it adds, are
722 ignored, so a getter that memoises what it computed is not reported. Set this
723 to 0 for an accessor whose purpose is to change state, such as an iterator's
724 C<next()>; a getter that declares no input is called with no arguments either
725 way.
726  
727 =item * C<dedup>, fuzzing can create duplicate tests, go some way to remove duplicates (default: 1)
728  
729 =item * C<properties>, enable L<Test::LectroTest> Property tests (default: 0)
730  
731 *item * C<test_security>, send some security string based tests (default: 0)
732  
733 =back
734  
735 All values default to C<true>.
736  
737 =head3 C<%accessor> - this is an accessor routine
738  
739 accessor:
740 property: ua
741 type: getset
742  
743 Has two mandatory elements:
744  
745 =over 4
746  
747 =item * C<property>
748  
749 The name of the property in the object that the routine controls.
750  
751 =item * C<type>
752  
753 One of C<getter>, C<setter>, C<getset>.
754  
755 =back
756  
757 =head3 C<%transforms> - list of transformations from input sets to output sets
758  
759 Transforms allow you to define how input data should be transformed into output data.
760 This is useful for testing functions that convert between formats, normalize data,
761 or apply business logic transformations on a set of data to different set of data.
762 It takes a list of subsets of the input and output definitions,
763 and verifies that data from each input subset is correctly transformed into data from the matching output subset.
764  
765 A transform whose input names at least one field that the top-level input does not
766 introduces its own call shape: its test cases are built from those fields rather
767 than the top-level ones. This lets one schema cover two calls, such as an
768 arrayref argument and a list of scalar arguments. A transform whose input only
769 names fields that are already at the top level adjusts the top-level input and
770 keeps the usual behaviour.
771  
772 =head4 Transform Validation Rules
773  
774 For each transform:
775  
776 =over 4
777  
778 =item 1. Generate test cases using the transform's input schema
779  
780 =item 2. Call the function with those inputs
781  
782 =item 3. Validate the output matches the transform's output schema
783  
784 =item 4. If output has a specific 'value', check exact match
785  
786 =item 5. If output has constraints (min/max), validate within bounds
787  
788 =back
789  
790 =head4 Example 1
791  
792 ---
793 module: builtin
794 function: abs
795  
796 config:
797 test_undef: no
798 test_empty: no
799 test_nuls: no
800 test_non_ascii: no
801  
802 input:
803 number:
804 type: number
805 position: 0
806  
807 output:
808 type: number
809 min: 0
810  
811 transforms:
812 positive:
813 input:
814 number:
815 type: number
816 position: 0
817 min: 0
818 output:
819 type: number
820 min: 0
821 negative:
822 input:
823 number:
824 type: number
825 position: 0
826 max: 0
827 output:
828 type: number
829 min: 0
830 error:
831 input:
832 undef
833 output:
834 _STATUS: DIES
835  
836 If the output hash contains the key _STATUS, and if that key is set to DIES,
837 the routine should die with the given arguments; otherwise, it should live.
838 If it's set to WARNS, the routine should warn with the given arguments.
839  
840 The keyword C<undef> is used to indicate that the C<function> returns nothing.
841  
842 =head4 Example 2
843  
844 ---
845 module: Math::Utils
846 function: normalize_number
847  
848 input:
849 value:
850 type: number
851 position: 0
852  
853 output:
854 type: number
855  
856 transforms:
857 positive_stays_positive:
858 input:
859 value:
860 type: number
861 min: 0
862 max: 1000
863 output:
864 type: number
865 min: 0
866 max: 1
867  
868 negative_becomes_zero:
869 input:
870 value:
871 type: number
872 max: 0
873 output:
874 type: number
875 value: 0
876  
877 preserves_zero:
878 input:
879 value:
880 type: number
881 value: 0
882 output:
883 type: number
884 value: 0
885  
886 =head3 C<$module>
887  
888 The name of the module (optional).
889  
890 Using the reserved word C<builtin> means you're testing a Perl builtin function.
891  
892 If omitted, the generator will guess from the config filename:
893 C<My-Widget.conf> -> C<My::Widget>.
894  
895 =head3 C<$function>
896  
897 The function/method to test.
898  
899 This defaults to C<run>.
900  
901 =head3 C<%new>
902  
903 An optional hashref of args to pass to the module's constructor.
904  
905 new:
906 api_key: ABC123
907 verbose: true
908  
909 To ensure C<new()> is called with no arguments, you still need to define new, thus:
910  
911 module: MyModule
912 function: my_function
913  
914 new:
915  
916 =head3 C<$invocant>
917  
918 The word C<class> when the routine is a class method: the harness calls
919 C<Module-E<gt>routine(...)> instead of C<Module::routine(...)>. With C<new>
920 set the routine is called on the object C<new> builds, and without an
921 C<invocant> it is called as a plain function.
922  
923 invocant: class
924  
925 =head3 C<%cases>
926  
927 An optional Perl static corpus, when the output is a simple string (expected => [ args... ]).
928  
929 Maps the expected output string to the input and _STATUS
930  
931 cases:
932 ok:
933 input: ping
934 _STATUS: OK
935 error:
936 input: ""
937 _STATUS: DIES
938  
939 =head3 C<$yaml_cases>
940  
941 An optional path to a YAML file with the same shape as C<%cases>.
942  
943 =head3 C<$seed>
944  
945 An optional integer.
946 When provided, the generated C<t/fuzz.t> will call C<srand($seed)> so fuzz runs are reproducible.
947  
948 =head3 C<$iterations>
949  
950 An optional integer controlling how many fuzz iterations to perform (default 30).
951  
952 =head3 C<%edge_cases>
953  
954 An optional hash mapping of extra values to inject.
955  
956 # Two named parameters
957 edge_cases:
958 name: [ '', 'a' x 1024, \"\x{263A}" ]
959 age: [ -1, 0, 99999999 ]
960  
961 # Takes a string input
962 edge_cases: [ 'foo', 'bar' ]
963  
964 Values can be strings or numbers; strings will be properly quoted.
965 Note that this only works with routines that take named parameters.
966  
967 =head3 C<%type_edge_cases>
968  
969 An optional hash mapping types to arrayrefs of extra values to try for any field of that type:
970  
971 type_edge_cases:
972 string: [ '', ' ', "\t", "\n", "\0", 'long' x 1024, chr(0x1F600) ]
973 number: [ 0, 1.0, -1.0, 1e308, -1e308, 1e-308, -1e-308, 'NaN', 'Infinity' ]
974 integer: [ 0, 1, -1, 2**31-1, -(2**31), 2**63-1, -(2**63) ]
975  
976 =head3 C<%edge_case_array>
977  
978 Specify edge case values for routines that accept a single unnamed parameter.
979 This is specifically designed for simple functions that take one argument without a parameter name.
980 These edge cases supplement the normal random string generation, ensuring specific problematic values are always tested.
981 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.
982  
983 ---
984 module: Text::Processor
985 function: sanitize
986  
987 input:
988 type: string
989 min: 1
990 max: 1000
991  
992 edge_case_array:
993 - "<script>alert('xss')</script>"
994 - "'; DROP TABLE users; --"
995 - "\0null\0byte"
996 - "emoji\U0001F60Atest"
997 - ""
998 - " "
999  
1000 seed: 42
1001 iterations: 30
1002  
1003 =head3 Semantic Data Generators
1004  
1005 For property-based testing with L<Test::LectroTest>,
1006 you can use semantic generators to create realistic test data.
1007  
1008 C<unix_timestamp> is currently fully supported,
1009 other fuzz testing support for C<semantic> entries is being developed.
1010  
1011 input:
1012 email:
1013 type: string
1014 semantic: email
1015  
1016 user_id:
1017 type: string
1018 semantic: uuid
1019  
1020 phone:
1021 type: string
1022 semantic: phone_us
1023  
1024 =head4 Available Semantic Types
1025  
1026 =over 4
1027  
1028 =item * C<email> - Valid email addresses (user@domain.tld)
1029  
1030 =item * C<url> - HTTP/HTTPS URLs
1031  
1032 =item * C<uuid> - UUIDv4 identifiers
1033  
1034 =item * C<phone_us> - US phone numbers (XXX-XXX-XXXX)
1035  
1036 =item * C<phone_e164> - International E.164 format (+XXXXXXXXXXXX)
1037  
1038 =item * C<ipv4> - IPv4 addresses (0.0.0.0 - 255.255.255.255)
1039  
1040 =item * C<ipv6> - IPv6 addresses
1041  
1042 =item * C<username> - Alphanumeric usernames with _ and -
1043  
1044 =item * C<slug> - URL slugs (lowercase-with-hyphens)
1045  
1046 =item * C<hex_color> - Hex color codes (#RRGGBB)
1047  
1048 =item * C<iso_date> - ISO 8601 dates (YYYY-MM-DD)
1049  
1050 =item * C<iso_datetime> - ISO 8601 datetimes (YYYY-MM-DDTHH:MM:SSZ)
1051  
1052 =item * C<semver> - Semantic version strings (major.minor.patch)
1053  
1054 =item * C<jwt> - JWT-like tokens (base64url format)
1055  
1056 =item * C<json> - Simple JSON objects
1057  
1058 =item * C<base64> - Base64-encoded strings
1059  
1060 =item * C<md5> - MD5 hashes (32 hex chars)
1061  
1062 =item * C<sha256> - SHA-256 hashes (64 hex chars)
1063  
1064 =item * C<bytes> - Byte strings (arbitrary octets, not text)
1065  
1066 The property test draws octets rather than characters. A byte string holds
1067 data, not a document, so no text-oriented case applies to it;
1068 L<App::Test::Generator::SchemaExtractor> sets this for a parameter that is a
1069 file's contents (`$bytes`, `blob`, "raw bytes").
1070  
1071 =item * C<directory> - The path of an existing, writable directory
1072  
1073 The harness creates a temporary directory and passes its path, because no
1074 pattern can describe "a directory that exists".
1075 No empty-string case is generated for such a parameter, since routines
1076 commonly read an empty path as "not given".
1077 L<App::Test::Generator::SchemaExtractor> sets this for a parameter that the
1078 routine tests with C<-d>.
1079  
1080 =item * C<existing_file> - The path of an existing file
1081  
1082 The harness creates a temporary file and passes its path, because no pattern
1083 can describe "a file that exists". L<App::Test::Generator::SchemaExtractor>
1084 sets this for a parameter that the routine tests with C<-e> or C<-f> but does
1085 not read.
1086  
1087 =item * C<unix_timestamp>
1088  
1089 =back
1090  
1091 =head2 EDGE CASE GENERATION
1092  
1093 In addition to purely random fuzz cases, the harness generates
1094 deterministic edge cases for parameters that declare C<min>, C<max> or C<len> in their schema definitions.
1095  
1096 For each constraint, three edge cases are added:
1097  
1098 =over 4
1099  
1100 =item * Just inside the allowable range
1101  
1102 This case should succeed, since it lies strictly within the bounds.
1103  
1104 =item * Exactly on the boundary
1105  
1106 This case should succeed, since it meets the constraint exactly.
1107  
1108 =item * Just outside the boundary
1109  
1110 This case is annotated with C<_STATUS = 'DIES'> in the corpus and
1111 should cause the harness to fail validation or croak.
1112  
1113 A constraint that came only from L<extract-schemas> reading POD (marked
1114 with C<_source: pod> for prose or C<_source: input_spec> for a formal spec)
1115 is a claim about valid input, not a check the routine has been seen to make.
1116 The constraint still sizes the valid data that is generated. It also gets
1117 explicit out-of-bound probes: a probe that dies is accepted as enforcement
1118 of the documented limit, while one that survives is recorded as a
1119 documentation contradiction. Provenance is tracked per constraint in
1120 C<_constraint_source>, so a documented minimum does not make a maximum that
1121 the code enforces tolerant on the same field. This applies to array and hash sizes, string
1122 lengths and numeric ranges, to constraints parsed from POD prose
1123 (C<3-50>, C<at least 5>), and to C<memberof> lists and C<matches> patterns.
1124 Every documented constraint gets an outside value as an advisory probe; in
1125 the normal advisory mode a probe that survives is reported as a routine
1126 accepting a value its POD says is invalid, without failing the run. A
1127 constraint written by hand in a schema is still required to die outside
1128 it. Because tolerance reduces what the
1129 harness proves, every tolerated bound is reported with C<diag>, so a
1130 passing run never hides the concession. Without this, a routine whose POD
1131 says C<min =E<gt> 1> but which accepts an empty list failed every harness
1132 run.
1133  
1134 Fuzzing can still reveal a contradiction in either direction: a routine may
1135 reject a value inside a documented constraint, or accept one outside it. The
1136 harness records those observations and reports them together at the end of
1137 the run. Advisory mode tolerates them, so POD-derived documentation cannot
1138 fail a routine that merely documents differently; pass C<--strict-documented>
1139 to C<fuzz-harness-generator> to make each recorded contradiction a failing
1140 test. The strict choice is embedded in the generated harness, so a later
1141 C<prove> run behaves the same way.
1142  
1143 =back
1144  
1145 Supported constraint types:
1146  
1147 =over 4
1148  
1149 =item * C<number>, C<integer>, C<float>
1150  
1151 Uses numeric values one below, equal to, and one above the boundary.
1152  
1153 =item * C<string>
1154  
1155 Uses strings of lengths one below, equal to, and one above the boundary.
1156  
1157 =item * C<arrayref>
1158  
1159 Uses references to arrays of with the number of elements one below, equal to, and one above the boundary.
1160  
1161 =item * C<hashref>
1162  
1163 Uses hashes with key counts one below, equal to, and one above the
1164 boundary (C<min> = minimum number of keys, C<max> = maximum number
1165 of keys).
1166  
1167 =item * C<memberof> - arrayref of allowed values for a parameter
1168  
1169 This example is for a routine called C<input()> that takes two arguments: C<status> and C<level>.
1170 C<status> is a string that must have the value C<ok>, C<error> or C<pending>.
1171 The C<level> argument is an integer that must be one of C<1>, C<5> or C<111>.
1172  
1173 ---
1174 input:
1175 status:
1176 type: string
1177 memberof:
1178 - ok
1179 - error
1180 - pending
1181 level:
1182 type: integer
1183 memberof:
1184 - 1
1185 - 5
1186 - 111
1187  
1188 The generator will automatically create test cases for each allowed value (inside the member list),
1189 and at least one value outside the list (which should die or C<croak>, C<_STATUS = 'DIES'>).
1190 This works for strings, integers, and numbers.
1191  
1192 =item * C<enum> - synonym of C<memberof>
1193  
1194 =item * C<boolean> - automatic boundary tests for boolean fields
1195  
1196 input:
1197 flag:
1198 type: boolean
1199  
1200 The generator will automatically create test cases for 0 and 1; true and false; off and on, and values that should trigger C<_STATUS = 'DIES'>.
1201  
1202 =back
1203  
1204 These edge cases are inserted automatically, in addition to the random
1205 fuzzing inputs, so each run will reliably probe boundary conditions
1206 without relying solely on randomness.
1207  
1208 =head1 EXAMPLES
1209  
1210 See the files in C<t/conf> for examples.
1211  
1212 =head2 Adding Scheduled fuzz Testing with GitHub Actions to Your Code
1213  
1214 To automatically create and run tests on a regular basis on GitHub Actions,
1215 you need to create a configuration file for each method and subroutine that you're testing,
1216 and a GitHub Actions configuration file.
1217  
1218 This example takes you through testing the online_render method of L<HTML::Genealogy::Map>.
1219  
1220 =head3 t/conf/online_render.yml
1221  
1222 ---
1223  
1224 module: HTML::Genealogy::Map
1225 function: onload_render
1226  
1227 input:
1228 gedcom:
1229 type: object
1230 can: individuals
1231 geocoder:
1232 type: object
1233 can: geocode
1234 debug:
1235 type: boolean
1236 optional: true
1237 google_key:
1238 type: string
1239 optional: true
1240 min: 39
1241 max: 39
1242 matches: "^AIza[0-9A-Za-z_-]{35}$"
1243  
1244 config:
1245 test_undef: 0
1246  
1247 =head3 .github/actions/fuzz.t
1248  
1249 ---
1250 name: Fuzz Testing
1251  
1252 permissions:
1253 contents: read
1254  
1255 on:
1256 push:
1257 branches: [main, master]
1258 pull_request:
1259 branches: [main, master]
1260 schedule:
1261 - cron: '29 5 14 * *'
1262  
1263 jobs:
1264 generate-fuzz-tests:
1265 strategy:
1266 fail-fast: false
1267 matrix:
1268 os:
1269 - macos-latest
1270 - ubuntu-latest
1271 - windows-latest
1272 perl: ['5.42', '5.40', '5.38', '5.36', '5.34', '5.32', '5.30', '5.28', '5.22']
1273  
1274 runs-on: ${{ matrix.os }}
1275 name: Fuzz testing with perl ${{ matrix.perl }} on ${{ matrix.os }}
1276  
1277 steps:
1278 - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
1279  
1280 - name: Set up Perl
1281 uses: shogo82148/actions-setup-perl@8b574cdc2dffdae49f803204a4f2b716a2fa1db7 # v1.44.2
1282 with:
1283 perl-version: ${{ matrix.perl }}
1284  
1285 - name: Install App::Test::Generator this module's dependencies
1286 run: |
1287 cpanm App::Test::Generator
1288 cpanm --installdeps .
1289  
1290 - name: Make Module
1291 run: |
1292 perl Makefile.PL
1293 make
1294 env:
1295 AUTOMATED_TESTING: 1
1296 NONINTERACTIVE_TESTING: 1
1297  
1298 - name: Generate fuzz tests
1299 run: |
1300 mkdir t/fuzz
1301 find t/conf -name '*.yml' | while read config; do
1302 test_name=$(basename "$config" .conf)
1303 fuzz-harness-generator "$config" > "t/fuzz/${test_name}_fuzz.t"
1304 done
1305  
1306 - name: Run generated fuzz tests
1307 run: |
1308 prove -lr t/fuzz/
1309 env:
1310 AUTOMATED_TESTING: 1
1311 NONINTERACTIVE_TESTING: 1
1312  
1313 =head2 Fuzz Testing your CPAN Module
1314  
1315 Running fuzz tests when you run C<make test> in your CPAN module.
1316  
1317 Create a directory <t/conf> which contains the schemas.
1318  
1319 Then create this file as <t/fuzz.t>:
1320  
1321 #!/usr/bin/env perl
1322  
1323 use strict;
1324 use warnings;
1325  
1326 use FindBin qw($Bin);
1327 use IPC::Run3;
1328 use IPC::System::Simple qw(system);
1329 use Test::Needs 'App::Test::Generator';
1330 use Test::Most;
1331  
1332 my $dirname = "$Bin/conf";
1333  
1334 if((-d $dirname) && opendir(my $dh, $dirname)) {
1335 while (my $filename = readdir($dh)) {
1336 # Skip '.' and '..' entries and vi temporary files
1337 next if ($filename eq '.' || $filename eq '..') || ($filename =~ /\.swp$/);
1338  
1339 my $filepath = "$dirname/$filename";
1340  
1341 if(-f $filepath) { # Check if it's a regular file
1342 my ($stdout, $stderr);
1343 run3 ['fuzz-harness-generator', '-r', $filepath], undef, \$stdout, \$stderr;
1344  
1345 ok($? == 0, 'Generated test script exits successfully');
1346  
1347 if($? == 0) {
1348 ok($stdout =~ /^Result: PASS/ms);
1349 if($stdout =~ /Files=1, Tests=(\d+)/ms) {
1350 diag("$1 tests run");
1351 }
1352 } else {
1353 diag("$filepath: STDOUT:\n$stdout");
1354 diag($stderr) if(length($stderr));
1355 diag("$filepath Failed");
1356 last;
1357 }
1358 diag($stderr) if(length($stderr));
1359 }
1360 }
1361 closedir($dh);
1362 }
1363  
1364 done_testing();
1365  
1366 =head2 Property-Based Testing with Transforms
1367  
1368 The generator can create property-based tests using L<Test::LectroTest> when the
1369 C<properties> configuration option is enabled.
1370 This provides more comprehensive
1371 testing by automatically generating thousands of test cases and verifying that
1372 mathematical properties hold across all inputs.
1373  
1374 =head3 Basic Property-Based Transform Example
1375  
1376 Here's a complete example testing the C<abs> builtin function:
1377  
1378 B<t/conf/abs.yml>:
1379  
1380 ---
1381 module: builtin
1382 function: abs
1383  
1384 config:
1385 test_undef: no
1386 test_empty: no
1387 test_nuls: no
1388 properties:
1389 enable: true
1390 trials: 1000
1391  
1392 input:
1393 number:
1394 type: number
1395 position: 0
1396  
1397 output:
1398 type: number
1399 min: 0
1400  
1401 transforms:
1402 positive:
1403 input:
1404 number:
1405 type: number
1406 min: 0
1407 output:
1408 type: number
1409 min: 0
1410  
1411 negative:
1412 input:
1413 number:
1414 type: number
1415 max: 0
1416 output:
1417 type: number
1418 min: 0
1419  
1420 This configuration:
1421  
1422 =over 4
1423  
1424 =item * Enables property-based testing with 1000 trials per property
1425  
1426 =item * Defines two transforms: one for positive numbers, one for negative
1427  
1428 =item * Automatically generates properties that verify C<abs()> always returns non-negative numbers
1429  
1430 =back
1431  
1432 Generate the test:
1433  
1434 fuzz-harness-generator t/conf/abs.yml > t/abs_property.t
1435  
1436 The generated test will include:
1437  
1438 =over 4
1439  
1440 =item * Traditional edge-case tests for boundary conditions
1441  
1442 =item * Random fuzzing with 30 iterations (or as configured)
1443  
1444 =item * Property-based tests that verify the transforms with 1000 trials each
1445  
1446 =back
1447  
1448 =head3 What Properties Are Tested?
1449  
1450 The generator automatically detects and tests these properties based on your transform specifications:
1451  
1452 =over 4
1453  
1454 =item * B<Range constraints> - If output has C<min> or C<max>, verifies results stay within bounds
1455  
1456 =item * B<Type preservation> - Ensures numeric inputs produce numeric outputs
1457  
1458 =item * B<Definedness> - Verifies the function doesn't return C<undef> unexpectedly
1459  
1460 =item * B<Specific values> - If output specifies a C<value>, checks exact equality
1461  
1462 =back
1463  
1464 For the C<abs> example above, the generated properties verify:
1465  
1466 # For the "positive" transform:
1467 - Given a positive number, abs() returns >= 0
1468 - The result is a valid number
1469 - The result is defined
1470  
1471 # For the "negative" transform:
1472 - Given a negative number, abs() returns >= 0
1473 - The result is a valid number
1474 - The result is defined
1475  
1476 =head3 Advanced Example: String Normalization
1477  
1478 Here's a more complex example testing a string normalization function:
1479  
1480 B<t/conf/normalize.yml>:
1481  
1482 ---
1483 module: Text::Processor
1484 function: normalize_whitespace
1485  
1486 config:
1487 properties:
1488 enable: true
1489 trials: 500
1490  
1491 input:
1492 text:
1493 type: string
1494 min: 0
1495 max: 1000
1496 position: 0
1497  
1498 output:
1499 type: string
1500 min: 0
1501 max: 1000
1502  
1503 transforms:
1504 empty_preserved:
1505 input:
1506 text:
1507 type: string
1508 value: ""
1509 output:
1510 type: string
1511 value: ""
1512  
1513 single_space:
1514 input:
1515 text:
1516 type: string
1517 min: 1
1518 matches: '^\S+(\s+\S+)*$'
1519 output:
1520 type: string
1521 matches: '^\S+( \S+)*$'
1522  
1523 length_bounded:
1524 input:
1525 text:
1526 type: string
1527 min: 1
1528 max: 100
1529 output:
1530 type: string
1531 min: 1
1532 max: 100
1533  
1534 This tests that the normalization function:
1535  
1536 =over 4
1537  
1538 =item * Preserves empty strings (C<empty_preserved> transform)
1539  
1540 =item * Collapses multiple spaces into single spaces (C<single_space> transform)
1541  
1542 =item * Maintains length constraints (C<length_bounded> transform)
1543  
1544 =back
1545  
1546 =head3 Interpreting Property Test Results
1547  
1548 When property-based tests run, you'll see output like:
1549  
1550 ok 123 - negative property holds (1000 trials)
1551 ok 124 - positive property holds (1000 trials)
1552  
1553 If a property fails, Test::LectroTest will attempt to find the minimal failing
1554 case and display it:
1555  
1556 not ok 123 - positive property holds (47 trials)
1557 # Property failed
1558 # Reason: counterexample found
1559  
1560 This helps you quickly identify edge cases that your function doesn't handle correctly.
1561  
1562 =head3 Configuration Options for Property-Based Testing
1563  
1564 In the C<config> section:
1565  
1566 config:
1567 properties:
1568 enable: true # Enable property-based testing (default: false)
1569 trials: 1000 # Number of test cases per property (default: 1000)
1570  
1571 You can also disable traditional fuzzing and only use property-based tests:
1572  
1573 config:
1574 properties:
1575 enable: true
1576 trials: 5000
1577  
1578 iterations: 0 # Disable random fuzzing, use only property tests
1579  
1580 =head3 When to Use Property-Based Testing
1581  
1582 Property-based testing with transforms is particularly useful for:
1583  
1584 =over 4
1585  
1586 =item * Mathematical functions (C<abs>, C<sqrt>, C<min>, C<max>, etc.)
1587  
1588 =item * Data transformations (encoding, normalization, sanitization)
1589  
1590 =item * Parsers and formatters
1591  
1592 =item * Functions with clear input-output relationships
1593  
1594 =item * Code that should satisfy mathematical properties (commutativity, associativity, idempotence)
1595  
1596 =back
1597  
1598 =head3 Requirements
1599  
1600 Property-based testing requires both L<Test::LectroTest> and
1601 L<Test::LectroTest::Compat> to be installed:
1602  
1603 cpanm Test::LectroTest Test::LectroTest::Compat
1604  
1605 L<Test::LectroTest::Compat> provides the C<use_ok> bridge between
1606 L<Test::LectroTest> and L<Test::Most>; it is used in every generated
1607 property-based test file. Both are declared in the distribution's
1608 C<TEST_REQUIRES> so they are installed automatically during C<make test>.
1609  
1610 If not installed, the generated tests will automatically skip the property-based
1611 portion with a message.
1612  
1613 =head3 Testing Email Validation
1614  
1615 ---
1616 module: Email::Valid
1617 function: rfc822
1618  
1619 config:
1620 properties:
1621 enable: true
1622 trials: 200
1623 close_stdin: true
1624 test_undef: no
1625 test_empty: no
1626 test_nuls: no
1627  
1628 input:
1629 email:
1630 type: string
1631 semantic: email
1632 position: 0
1633  
1634 output:
1635 type: boolean
1636  
1637 transforms:
1638 valid_emails:
1639 input:
1640 email:
1641 type: string
1642 semantic: email
1643 output:
1644 type: boolean
1645  
1646 This generates 200 realistic email addresses for testing, rather than random strings.
1647  
1648 =head3 Combining Semantic with Regex
1649  
1650 You can combine semantic generators with regex validation:
1651  
1652 input:
1653 corporate_email:
1654 type: string
1655 semantic: email
1656 matches: '@company\.com$'
1657  
1658 The semantic generator creates realistic emails, and the regex ensures they match your domain.
1659  
1660 =head3 Custom Properties for Transforms
1661  
1662 You can define additional properties that should hold for your transforms beyond
1663 the automatically detected ones.
1664  
1665 =head4 Using Built-in Properties
1666  
1667 transforms:
1668 positive:
1669 input:
1670 number:
1671 type: number
1672 min: 0
1673 output:
1674 type: number
1675 min: 0
1676 properties:
1677 - idempotent # f(f(x)) == f(x)
1678 - non_negative # result >= 0
1679 - positive # result > 0
1680  
1681 Available built-in properties:
1682  
1683 =over 4
1684  
1685 =item * C<idempotent> - Function is idempotent: f(f(x)) == f(x)
1686  
1687 =item * C<non_negative> - Result is always >= 0
1688  
1689 =item * C<positive> - Result is always > 0
1690  
1691 =item * C<non_empty> - String result is never empty
1692  
1693 =item * C<length_preserved> - Output length equals input length
1694  
1695 =item * C<uppercase> - Result is all uppercase
1696  
1697 =item * C<lowercase> - Result is all lowercase
1698  
1699 =item * C<trimmed> - No leading/trailing whitespace
1700  
1701 =item * C<sorted_ascending> - Array is sorted ascending
1702  
1703 =item * C<sorted_descending> - Array is sorted descending
1704  
1705 =item * C<unique_elements> - Array has no duplicates
1706  
1707 =item * C<preserves_keys> - Hash has same keys as input
1708  
1709 =back
1710  
1711 =head4 Custom Property Code
1712  
1713 Custom properties allows the definition additional invariants and relationships that should hold for their transforms,
1714 beyond what's auto-detected.
1715 For example:
1716  
1717 =over 4
1718  
1719 =item * Idempotence: f(f(x)) == f(x)
1720  
1721 =item * Commutativity: f(x, y) == f(y, x)
1722  
1723 =item * Associativity: f(f(x, y), z) == f(x, f(y, z))
1724  
1725 =item * Inverse relationships: decode(encode(x)) == x
1726  
1727 =item * Domain-specific invariants: Custom business logic
1728  
1729 =back
1730  
1731 Define your own properties with custom Perl code:
1732  
1733 transforms:
1734 normalize:
1735 input:
1736 text:
1737 type: string
1738 output:
1739 type: string
1740 properties:
1741 - name: single_spaces
1742 description: "No multiple consecutive spaces"
1743 code: $result !~ / /
1744  
1745 - name: no_leading_space
1746 description: "No space at start"
1747 code: $result !~ /^\s/
1748  
1749 - name: reversible
1750 description: "Can be reversed back"
1751 code: length($result) == length($text)
1752  
1753 The code has access to:
1754  
1755 =over 4
1756  
1757 =item * C<$result> - The function's return value
1758  
1759 =item * Input variables - All input parameters (e.g., C<$text>, C<$number>)
1760  
1761 =item * The function itself - Can call it again for idempotence checks
1762  
1763 =back
1764  
1765 =head4 Combining Auto-detected and Custom Properties
1766  
1767 The generator automatically detects properties from your output spec, and adds
1768 your custom properties:
1769  
1770 transforms:
1771 sanitize:
1772 input:
1773 html:
1774 type: string
1775 output:
1776 type: string
1777 min: 0 # Auto-detects: defined, min_length >= 0
1778 max: 10000
1779 properties: # Additional custom checks:
1780 - name: no_scripts
1781 code: $result !~ /<script/i
1782 - name: no_iframes
1783 code: $result !~ /<iframe/i
1784  
1785 =head2 GENERATED OUTPUT
1786  
1787 The generated test:
1788  
1789 =over 4
1790  
1791 =item * Seeds RND (if configured) for reproducible fuzz runs
1792  
1793 =item * Uses edge cases (per-field and per-type) with configurable probability
1794  
1795 =item * Runs C<$iterations> fuzz cases plus appended edge-case runs
1796  
1797 =item * Validates inputs with Params::Get / Params::Validate::Strict
1798  
1799 =item * Asserts that a wrong-typed argument dies, where the type is enforced
1800  
1801 Passing a reference where a string is declared is only expected to die for a
1802 parameter whose input spec sets C<_source: validator>.
1803 L<App::Test::Generator::SchemaExtractor> sets that source when the routine
1804 checks its arguments with a validator such as L<Params::Validate::Strict>.
1805 A type taken from POD, or inferred from the code, documents intent but does not
1806 promise rejection, so no such case is generated for it.
1807 Add the source by hand to a schema whose routine does check its argument types.
1808  
1809 =item * Validates outputs with L<Return::Set>
1810  
1811 =item * Runs static C<is(... )> corpus tests from Perl and/or YAML corpus
1812  
1813 =item * Runs L<Test::LectroTest> tests
1814  
1815 =back
1816  
1817 =cut
1818  
1819 =head1 METHODS
1820  
1821 =head2 generate
1822  
1823 Takes a schema file and produces a test file (or STDOUT).
1824  
1825 # Modern named API
1826 App::Test::Generator->generate(
1827 schema_file => 'schemas/foo.yml',
1828 output_file => 'test/foo.t',
1829 );
1830  
1831 # Feed surviving mutants into the generated harness
1832 App::Test::Generator->generate(
1833 schema_file => 'schemas/foo.yml',
1834 mutation_results => 'mutation.json',
1835 output_file => 'test/foo.t',
1836 );
1837  
1838 # Legacy positional API
1839 App::Test::Generator->generate($schema_file, $test_file);
1840  
1841 =head3 API SPECIFICATION
1842  
1843 =head4 Input
1844  
1845 {
1846 schema_file => { type => 'string', optional => 0 },
1847 input_file => { type => 'string', optional => 1 },
1848 output_file => { type => 'string', optional => 1, max => 255 },
1849 strict_documented => { type => 'boolean', optional => 1 },
1850 mutation_results => { type => 'string', optional => 1 },
1851 }
1852  
1853 C<mutation_results> is the JSON report written by
1854 C<test-generator-mutate --json>. Surviving numeric-boundary mutants are
1855 converted into C<min> or C<max> constraints on the matching input field, so
1856 the harness generates data either side of the boundary the survivor exposed.
1857 Existing constraints are never replaced. See
1858 L<App::Test::Generator::Mutation::Feedback>.
1859  
1860 =head4 Output
1861  
1862 { type => 'boolean' }
1863  
1864 Always 1. The test source itself is written to C<output_file>, or printed
1865 on STDOUT when no output file is given; it is not returned.
1866  
1867 The mathematical description is in L</FORMAL SPECIFICATION>.
1868  
1869 =cut
1870  
1871 sub generate
1872 445 ▶{
Subroutine generate: called CC=198 SCAR=67.7
Pod documented
1873 445 ▶ croak 'Usage: generate(schema_file [, outfile])' if(scalar(@_) == 0);
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ == 0 0 445 445
1874  
1875 # Accept both class-method call (App::Test::Generator->generate(...))
1876 # and plain-function call with a hashref (generate({...})).
1877 # In the method form the first arg is the class name (a plain string);
1878 # in the function form with a hashref the first arg IS the hashref.
1879 445 ▶ my $class = (ref($_[0]) ne 'HASH') ? shift : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ne 'HASH' ? : 445 0 445
1880 445 my ($schema_file, $test_file, $schema);
1881 # Globals loaded from the user's conf (all optional except function maybe)
1882 445 my ($module, $function, $new, $yaml_cases, $invocant);
1883 445 my ($seed, $iterations);
1884 445 my $strict_documented = 0;
1885  
1886 445 ▶ if((ref($_[0]) eq 'HASH') || defined($_[2])) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq 'HASH' or defined $_[2]) { } 324 121 445
Condition100%3/3
ref $_[0] eq "HASH" or defined $_[2]
l!l&&r!l&&!r
181143121
MC/DC100%2/2
ref $_[0] eq "HASH" or defined $_[2]
ref $_[0] eq "HASH" defined $_[2]
Truth table100%3/3
A or B
A= ref $_[0] eq "HASH"B= defined $_[2]
ABresult
1X1
011
000
1887 # Modern API
1888 324 my $params = Params::Validate::Strict::validate_strict({
1889 args => Params::Get::get_params(undef, \@_),
1890 schema => {
1891 input_file => { type => 'string', optional => 1 },
1892 schema_file => { type => 'string', optional => 1 },
1893 output_file => { type => 'string', optional => 1 },
1894 schema => { type => 'hashref', optional => 1 },
1895 quiet => { type => 'boolean', optional => 1 }, # Not yet used
1896 strict_documented => { type => 'boolean', optional => 1 },
1897 mutation_results => { type => 'string', optional => 1 },
1898 }
1899 });
1900 324 ▶ $strict_documented = $params->{'strict_documented'} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$params->{'strict_documented'} ? : 4 320 324
1901 324 ▶ if($params->{'schema_file'}) {
Branch: 3 branches
BranchTrueFalseTotal
if ($params->{'schema_file'}) { } 117 207 324
elsif ($params->{'input_file'}) { } 177 30 207
elsif ($params->{'schema'}) { } 30 0 30
1902 117 $schema_file = $params->{'schema_file'};
1903 } elsif($params->{'input_file'}) {
1904 177 $schema_file = $params->{'input_file'};
1905 } elsif($params->{'schema'}) {
1906 30 $schema = $params->{'schema'};
1907 } else {
1908 0 croak(__PACKAGE__, ': Usage: generate(input_file|schema [, output_file]');
1909 }
1910 324 ▶ if(defined($schema_file)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $schema_file) 294 30 324
1911 294 $schema = _load_schema($schema_file);
1912 }
1913 324 ▶ if($params->{'mutation_results'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params->{"mutation_results"}) 2 322 324
1914 # Surviving mutants add constraints the schema is missing, so
1915 # the harness exercises the boundary that survived the suite.
1916 2 require App::Test::Generator::Mutation::Feedback;
1917 my $feedback = App::Test::Generator::Mutation::Feedback->new(
1918 mutation_results => $params->{'mutation_results'},
1919 2 ▶ (defined($schema->{module}) ? (module => $schema->{module}) : ()),
Branch: 1 branch
BranchTrueFalseTotal
defined $schema->{'module'} ? : 2 0 2
1920 );
1921 2 $feedback->apply_to_schema($schema);
1922 }
1923 324 $test_file = $params->{'output_file'};
1924 } else {
1925 # Legacy API
1926 121 ($schema_file, $test_file) = @_;
1927 121 ▶ if(defined($schema_file)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $schema_file) { } 115 6 121
1928 115 $schema = _load_schema($schema_file);
1929 } else {
1930 6 croak 'Usage: generate(schema_file [, outfile])';
1931 }
1932 }
1933  
1934 # Parse the schema file and load into our structures
1935 436 my %input = %{_load_schema_section($schema, 'input', $schema_file)};
1936 435 my %output = %{_load_schema_section($schema, 'output', $schema_file)};
1937 434 my %transforms = %{_load_schema_section($schema, 'transforms', $schema_file)};
1938 433 my %accessor = %{_load_schema_section($schema, 'accessor', $schema_file)};
1939  
1940 433 ▶ my %cases = %{$schema->{cases}} if(exists($schema->{cases}));
Branch: 1 branch
BranchTrueFalseTotal
if exists $schema->{"cases"} 2 431 433
1941 0 ▶ my %edge_cases = %{$schema->{edge_cases}} if(exists($schema->{edge_cases}));
Branch: 1 branch
BranchTrueFalseTotal
if exists $schema->{"edge_cases"} 0 433 433
1942 433 ▶ my %type_edge_cases = %{$schema->{type_edge_cases}} if(exists($schema->{type_edge_cases}));
Branch: 1 branch
BranchTrueFalseTotal
if exists $schema->{"type_edge_cases"} 1 432 433
1943  
1944 433 ▶ $module = $schema->{module} if(exists($schema->{module}) && length($schema->{module}));
Branch: 1 branch
BranchTrueFalseTotal
if exists $schema->{"module"} and length $schema->{"module"} 426 7 433
Condition66%2/3
exists $schema->{"module"} and length $schema->{"module"}
!ll&&!rl&&r
70426
MC/DC50%1/2
exists $schema->{"module"} and length $schema->{"module"}
exists $schema->{"module"} length $schema->{"module"}
Truth table66%2/3
A and B
A= exists $schema->{"module"}B= length $schema->{"module"}
ABresult
0X0
100
111
1945 433 ▶ $function = $schema->{function} if(exists($schema->{function}));
Branch: 1 branch
BranchTrueFalseTotal
if exists $schema->{"function"} 431 2 433
1946 433 ▶ if(exists($schema->{new})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $schema->{"new"}) 133 300 433
1947 133 ▶ $new = defined($schema->{'new'}) ? $schema->{new} : '_UNDEF';
Branch: 1 branch
BranchTrueFalseTotal
defined $schema->{'new'} ? : 109 24 133
1948 }
1949 433 ▶ $invocant = $schema->{invocant} if(exists($schema->{invocant}) && defined($schema->{invocant}));
Branch: 1 branch
BranchTrueFalseTotal
if exists $schema->{"invocant"} and defined $schema->{"invocant"} 1 432 433
Condition66%2/3
exists $schema->{"invocant"} and defined $schema->{"invocant"}
!ll&&!rl&&r
43201
MC/DC50%1/2
exists $schema->{"invocant"} and defined $schema->{"invocant"}
exists $schema->{"invocant"} defined $schema->{"invocant"}
Truth table66%2/3
A and B
A= exists $schema->{"invocant"}B= defined $schema->{"invocant"}
ABresult
0X0
100
111
1950 433 ▶ $yaml_cases = $schema->{yaml_cases} if(exists($schema->{yaml_cases}));
Branch: 1 branch
BranchTrueFalseTotal
if exists $schema->{"yaml_cases"} 5 428 433
1951 433 ▶ $seed = $schema->{seed} if(exists($schema->{seed}));
Branch: 1 branch
BranchTrueFalseTotal
if exists $schema->{"seed"} 14 419 433
1952 433 ▶ $iterations = $schema->{iterations} if(exists($schema->{iterations}));
Branch: 1 branch
BranchTrueFalseTotal
if exists $schema->{"iterations"} 117 316 433
1953  
1954 433 ▶ my @edge_case_array = @{$schema->{edge_case_array}} if(exists($schema->{edge_case_array}));
Branch: 1 branch
BranchTrueFalseTotal
if exists $schema->{"edge_case_array"} 3 430 433
1955 433 _validate_config($schema);
1956  
1957 428 ▶ my %config = %{$schema->{config}} if(exists($schema->{config}));
Branch: 1 branch
BranchTrueFalseTotal
if exists $schema->{"config"} 338 90 428
1958  
1959 428 _normalize_config(\%config);
1960 428 $config{'strict_documented'} = $strict_documented;
1961  
1962 # Guess module name from config file if not set
1963 428 ▶ if(!$module) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $module) { } 5 423 428
elsif ($module eq $MODULE_BUILTIN) { } 55 368 423
1964 5 ▶ if($schema_file) {
Branch: 1 branch
BranchTrueFalseTotal
if ($schema_file) 4 1 5
1965 4 ($module = basename($schema_file)) =~ s/\.(conf|pl|pm|yml|yaml)$//;
1966 4 $module =~ s/-/::/g;
1967 # Guard against Perl builtin function names being mistaken
1968 # for module names — builtins have no module to load
1969 4 ▶ if(_is_perl_builtin($module)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_perl_builtin($module)) 1 3 4
1970 1 undef $module;
1971 }
1972 }
1973 } elsif($module eq $MODULE_BUILTIN) {
1974 55 undef $module;
1975 }
1976  
1977 428 ▶ if($module && length($module) && ($module ne 'builtin')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($module and length $module and $module ne "builtin") 371 57 428
Condition66%4/6
$module and length $module and $module ne "builtin"
!ll&&!rl&&r
570371
$module and length $module
!ll&&!rl&&r
570371
MC/DC33%1/3
$module and length $module and $module ne "builtin"
$module length $module $module ne "builtin"
Truth table50%2/4
A and B and C
A= $moduleB= length $moduleC= $module ne "builtin"
ABCresult
0XX0
10X0
1100
1111
1978 371 _validate_module($module, $schema_file);
1979 }
1980  
1981 # $module/$function are spliced unescaped into generated test
1982 # source below (use_ok, new_ok, ->$function, $module::$function)
1983 # — reject anything that isn't identifier-shaped before that happens.
1984 428 ▶ _assert_identifier($module, 'module', package => 1) if defined($module) && length($module);
Branch: 1 branch
BranchTrueFalseTotal
if defined $module and length $module 371 57 428
Condition66%2/3
defined $module and length $module
!ll&&!rl&&r
570371
MC/DC50%1/2
defined $module and length $module
defined $module length $module
Truth table66%2/3
A and B
A= defined $moduleB= length $module
ABresult
0X0
100
111
1985  
1986 # sensible defaults
1987 427 ▶ $function ||= 'run';
Condition50%1/2
$function ||= "run"
l!l
4270
MC/DC0%0/1
$function ||= "run"
$function
Truth table50%1/2
A
A= $function
Aresult
11
00
1988 # package => 1: fully-qualified sub names (e.g. DB::DB, a debugger
1989 # hook installed into the DB:: package regardless of its source
1990 # package) are legitimate function names, not just bare identifiers
1991 427 _assert_identifier($function, 'function', package => 1);
1992 425 ▶ $iterations ||= $DEFAULT_ITERATIONS; # default fuzz runs if not specified
Condition66%2/3
$iterations ||= $DEFAULT_ITERATIONS
l!l&&r!l&&!r
1163090
MC/DC0%0/2
$iterations ||= $DEFAULT_ITERATIONS
$iterations $DEFAULT_ITERATIONS
Truth table66%2/3
A ||= B
A= $iterationsB= $DEFAULT_ITERATIONS
ABresult
1X1
011
000
1993 425 ▶ $seed = undef if defined $seed && $seed eq ''; # treat empty as undef
Branch: 1 branch
BranchTrueFalseTotal
if defined $seed and $seed eq "" 0 425 425
Condition66%2/3
defined $seed and $seed eq ""
!ll&&!rl&&r
411140
MC/DC0%0/2
defined $seed and $seed eq ""
defined $seed $seed eq ""
Truth table66%2/3
A and B
A= defined $seedB= $seed eq ""
ABresult
0X0
100
111
1994  
1995 # --- YAML corpus support (yaml_cases is filename string) ---
1996 425 my %yaml_corpus_data;
1997 425 ▶ if (defined $yaml_cases) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $yaml_cases) 5 420 425
1998 5 ▶ croak("$yaml_cases: $!") if(!-f $yaml_cases);
Branch: 1 branch
BranchTrueFalseTotal
unless -f $yaml_cases 1 4 5
1999  
2000 4 my $yaml_data = LoadFile(Encode::decode('utf8', $yaml_cases));
2001 4 ▶ if ($yaml_data && ref($yaml_data) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if ($yaml_data and ref $yaml_data eq "HASH") 4 0 4
Condition33%1/3
$yaml_data and ref $yaml_data eq "HASH"
!ll&&!rl&&r
004
MC/DC0%0/2
$yaml_data and ref $yaml_data eq "HASH"
$yaml_data ref $yaml_data eq "HASH"
Truth table33%1/3
A and B
A= $yaml_dataB= ref $yaml_data eq "HASH"
ABresult
0X0
100
111
2002 # Validate that the corpus inputs are arrayrefs
2003 # e.g: "FooBar": ["foo_bar"]
2004 # Skip only invalid entries:
2005 4 for my $expected (keys %{$yaml_data}) {
2006 6 my $outputs = $yaml_data->{$expected};
2007 6 ▶ unless($outputs && (ref $outputs eq 'ARRAY')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($outputs and ref $outputs eq "ARRAY") 2 4 6
Condition66%2/3
$outputs and ref $outputs eq "ARRAY"
!ll&&!rl&&r
024
MC/DC50%1/2
$outputs and ref $outputs eq "ARRAY"
$outputs ref $outputs eq "ARRAY"
Truth table66%2/3
A and B
A= $outputsB= ref $outputs eq "ARRAY"
ABresult
0X0
100
111
2008 2 carp("$yaml_cases: $expected does not point to an array ref, ignoring");
2009 2 next;
2010 }
2011 4 $yaml_corpus_data{$expected} = $outputs;
2012 }
2013 }
2014 }
2015  
2016 # Merge Perl %cases and YAML corpus safely
2017 # my %all_cases = (%cases, %yaml_corpus_data);
2018 424 my %all_cases = (%yaml_corpus_data, %cases);
2019 424 for my $k (keys %yaml_corpus_data) {
2020 4 ▶ if (exists $cases{$k} && ref($cases{$k}) eq 'ARRAY' && ref($yaml_corpus_data{$k}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $cases{$k} and ref $cases{$k} eq "ARRAY" and ref $yaml_corpus_data{$k} eq "ARRAY") 1 3 4
Condition66%4/6
exists $cases{$k} and ref $cases{$k} eq "ARRAY" and ref $yaml_corpus_data{$k} eq "ARRAY"
!ll&&!rl&&r
301
exists $cases{$k} and ref $cases{$k} eq "ARRAY"
!ll&&!rl&&r
301
MC/DC33%1/3
exists $cases{$k} and ref $cases{$k} eq "ARRAY" and ref $yaml_corpus_data{$k} eq "ARRAY"
exists $cases{$k} ref $cases{$k} eq "ARRAY" ref $yaml_corpus_data{$k} eq "ARRAY"
Truth table50%2/4
A and B and C
A= exists $cases{$k}B= ref $cases{$k} eq "ARRAY"C= ref $yaml_corpus_data{$k} eq "ARRAY"
ABCresult
0XX0
10X0
1100
1111
2021 1 $all_cases{$k} = [ @{$yaml_corpus_data{$k}}, @{$cases{$k}} ];
2022 }
2023 }
2024  
2025 424 ▶ if(my $hints = delete $schema->{_yamltest_hints}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $hints = delete $schema->{"_yamltest_hints"}) 9 415 424
2026 9 ▶ if(my $boundaries = $hints->{boundary_values}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $boundaries = $hints->{"boundary_values"}) 9 0 9
2027 9 push @edge_case_array, @{$boundaries};
2028 }
2029 9 ▶ if(my $invalid = $hints->{invalid}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $invalid = $hints->{"invalid"}) 0 9 9
2030 0 carp('TODO: handle yamltest_hints->invalid');
2031 }
2032 }
2033  
2034 # If the schema says the type is numeric, normalize
2035 424 ▶ if ($schema->{type} && $schema->{type} =~ /^(integer|number|float)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($schema->{"type"} and $schema->{"type"} =~ /^(integer|number|float)$/u) 1 423 424
Condition66%2/3
$schema->{"type"} and $schema->{"type"} =~ /^(integer|number|float)$/u
!ll&&!rl&&r
42301
MC/DC50%1/2
$schema->{"type"} and $schema->{"type"} =~ /^(integer|number|float)$/u
$schema->{"type"} $schema->{"type"} =~ /^(integer|number|float)$/u
Truth table66%2/3
A and B
A= $schema->{"type"}B= $schema->{"type"} =~ /^(integer|number|float)$/u
ABresult
0X0
100
111
2036 1 for (@edge_case_array) {
2037 2 ▶ next unless defined $_;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_ 0 2 2
2038 2 ▶ $_ += 0 if Scalar::Util::looks_like_number($_);
Branch: 1 branch
BranchTrueFalseTotal
if &Scalar::Util::looks_like_number($_) 1 1 2
2039 }
2040 }
2041  
2042 # Load relationships from the schema if present and well-formed.
2043 # SchemaExtractor may set this to undef or an empty arrayref when
2044 # no relationships were detected, so guard both existence and type.
2045 424 my @relationships;
2046 424 ▶ if(exists($schema->{relationships}) && ref($schema->{relationships}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $schema->{"relationships"} and ref $schema->{"relationships"} eq "ARRAY") 0 424 424
Condition33%1/3
exists $schema->{"relationships"} and ref $schema->{"relationships"} eq "ARRAY"
!ll&&!rl&&r
42400
MC/DC0%0/2
exists $schema->{"relationships"} and ref $schema->{"relationships"} eq "ARRAY"
exists $schema->{"relationships"} ref $schema->{"relationships"} eq "ARRAY"
Truth table33%1/3
A and B
A= exists $schema->{"relationships"}B= ref $schema->{"relationships"} eq "ARRAY"
ABresult
0X0
100
111
2047 0 @relationships = @{$schema->{relationships}};
2048 }
2049  
2050 # Serialise the relationships array from the schema into Perl source
2051 # code for embedding in the generated test file. Each relationship
2052 # type is rendered as a hashref in the @relationships array.
2053  
2054 424 my $relationships_code = '';
2055  
2056 # Walk each relationship in the order SchemaExtractor produced them
2057 424 for my $rel (@relationships) {
2058 0 ▶ my $type = $rel->{type} // '';
Condition0%0/2
$rel->{"type"} // ""
l!l
00
MC/DC0%0/1
$rel->{"type"} // ""
$rel->{"type"}
Truth table0%0/2
A
A= $rel->{"type"}
Aresult
11
00
2059  
2060 # Mutually exclusive: both params being set should cause the method to die
2061 0 ▶ if($type eq 'mutually_exclusive') {
Branch: 6 branches
BranchTrueFalseTotal
if ($type eq 'mutually_exclusive') { } 0 0 0
elsif ($type eq 'required_group') { } 0 0 0
elsif ($type eq 'conditional_requirement') { } 0 0 0
elsif ($type eq 'dependency') { } 0 0 0
elsif ($type eq 'value_constraint') { } 0 0 0
elsif ($type eq 'value_conditional') { } 0 0 0
2062 $relationships_code .= "{ type => 'mutually_exclusive', params => [" .
2063 0 join(', ', map { perl_quote($_) } @{$rel->{params}}) .
2064 "] },\n";
2065  
2066 # Required group: at least one of the params must be present
2067 } elsif($type eq 'required_group') {
2068 $relationships_code .= "{ type => 'required_group', params => [" .
2069 0 ▶ join(', ', map { perl_quote($_) } @{$rel->{params}}) .
Condition0%0/2
$rel->{"logic"} // "or"
l!l
00
MC/DC0%0/1
$rel->{"logic"} // "or"
$rel->{"logic"}
Truth table0%0/2
A
A= $rel->{"logic"}
Aresult
11
00
2070 0 "], logic => " . perl_quote($rel->{logic} // 'or') . " },\n";
2071  
2072 # Conditional requirement: if one param is set, another becomes mandatory
2073 } elsif($type eq 'conditional_requirement') {
2074 $relationships_code .= "{ type => 'conditional_requirement', if => " .
2075 perl_quote($rel->{'if'}) . ", then_required => " .
2076 0 perl_quote($rel->{then_required}) . " },\n";
2077  
2078 # Dependency: one param requires another to also be present
2079 } elsif($type eq 'dependency') {
2080 $relationships_code .= "{ type => 'dependency', param => " .
2081 perl_quote($rel->{param}) . ", requires => " .
2082 0 perl_quote($rel->{requires}) . " },\n";
2083  
2084 # Value constraint: one param being set forces another to a specific value
2085 } elsif($type eq 'value_constraint') {
2086 $relationships_code .= "{ type => 'value_constraint', if => " .
2087 perl_quote($rel->{'if'}) . ", then => " .
2088 perl_quote($rel->{then}) . ", operator => " .
2089 perl_quote($rel->{operator}) . ", value => " .
2090 0 perl_quote($rel->{value}) . " },\n";
2091  
2092 # Value conditional: one param equalling a specific value requires another param
2093 } elsif($type eq 'value_conditional') {
2094 $relationships_code .= "{ type => 'value_conditional', if => " .
2095 perl_quote($rel->{'if'}) . ", equals => " .
2096 perl_quote($rel->{equals}) . ", then_required => " .
2097 0 perl_quote($rel->{then_required}) . " },\n";
2098  
2099 # Unknown type — warn and skip rather than emitting broken code
2100 } else {
2101 0 carp "Unknown relationship type '$type', skipping";
2102 }
2103 }
2104  
2105 # Dedup the edge cases
2106 424 my %seen;
2107 @edge_case_array = grep {
2108 424 ▶ my $key = defined($_) ? (Scalar::Util::looks_like_number($_) ? "N:$_" : "S:$_") : 'U';
Branch: 2 branches
BranchTrueFalseTotal
defined $_ ? : 113 0 113
&Scalar::Util::looks_like_number($_) ? : 99 14 113
2109 113 !$seen{$key}++;
2110 } @edge_case_array;
2111  
2112 # Sort the edge cases to keep it consistent across runs
2113 @edge_case_array = sort {
2114 424 ▶ return -1 if !defined $a;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $a 0 156 156
2115 156 ▶ return 1 if !defined $b;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $b 0 156 156
2116  
2117 156 my $na = Scalar::Util::looks_like_number($a);
2118 156 my $nb = Scalar::Util::looks_like_number($b);
2119  
2120 156 ▶ return $a <=> $b if $na && $nb;
Branch: 1 branch
BranchTrueFalseTotal
if $na and $nb 138 18 156
Condition100%3/3
$na and $nb
!ll&&!rl&&r
135138
MC/DC100%2/2
$na and $nb
$na $nb
Truth table100%3/3
A and B
A= $naB= $nb
ABresult
0X0
100
111
2121 18 ▶ return -1 if $na;
Branch: 1 branch
BranchTrueFalseTotal
if $na 5 13 18
2122 13 ▶ return 1 if $nb;
Branch: 1 branch
BranchTrueFalseTotal
if $nb 2 11 13
2123 11 return $a cmp $b;
2124 } @edge_case_array;
2125  
2126 # render edge case maps for inclusion in the .t
2127 424 my $edge_cases_code = render_arrayref_map(\%edge_cases);
2128 424 my $type_edge_cases_code = render_arrayref_map(\%type_edge_cases);
2129  
2130 424 my $edge_case_array_code = '';
2131 424 ▶ if(scalar(@edge_case_array)) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @edge_case_array) 23 401 424
2132 23 $edge_case_array_code = join(', ', map { q_wrap($_) } @edge_case_array);
2133 }
2134  
2135 # Render configuration - all the values are integers for now, if that changes, wrap the $config{$key} in single quotes
2136 424 my $config_code = '';
2137 424 foreach my $key (sort keys %config) {
2138 # Skip nested structures like 'properties' - they're used during
2139 # generation but don't need to be in the generated test
2140 5624 ▶ if(ref($config{$key}) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $config{$key} eq "HASH") 424 5200 5624
2141 424 next;
2142 }
2143 5200 ▶ if((!defined($config{$key})) || !$config{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $config{$key} && $config{$key}) { } 1843 3357 5200
Condition66%2/3
defined $config{$key} && $config{$key}
!ll&&!rl&&r
018433357
MC/DC50%1/2
defined $config{$key} && $config{$key}
defined $config{$key} $config{$key}
Truth table66%2/3
A && B
A= defined $config{$key}B= $config{$key}
ABresult
0X0
100
111
2144 # YAML will strip the word 'false'
2145 # e.g. in 'test_undef: false'
2146 1843 $config_code .= "'$key' => 0,\n";
2147 } else {
2148 3357 $config_code .= "'$key' => $config{$key},\n";
2149 }
2150 }
2151  
2152 # Render input/output
2153 424 my $input_code = '';
2154 424 ▶ if(((scalar keys %input) == 1) && exists($input{'type'}) && !ref($input{'type'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %input == 1 and exists $input{'type'} and not ref $input{'type'}) { } 50 374 424
Condition83%5/6
scalar keys %input == 1 and exists $input{"type"} and not ref $input{"type"}
!ll&&!rl&&r
374050
scalar keys %input == 1 and exists $input{"type"}
!ll&&!rl&&r
17619850
MC/DC66%2/3
scalar keys %input == 1 and exists $input{"type"} and not ref $input{"type"}
scalar keys %input == 1 exists $input{"type"} not ref $input{"type"}
Truth table75%3/4
A and B and not(C)
A= scalar keys %input == 1B= exists $input{"type"}C= not ref $input{"type"}
ABCresult
0XX0
10X0
1100
1111
2155 # %input = ( type => 'string' );
2156 50 foreach my $key (sort keys %input) {
2157 50 $input_code .= "'$key' => '$input{$key}',\n";
2158 }
2159 } else {
2160 # %input = ( str => { type => 'string' } );
2161 374 $input_code = render_hash(\%input);
2162 }
2163 424 ▶ if(defined(my $re = $output{'matches'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $re = $output{"matches"})) 0 424 424
2164 0 ▶ if(ref($re) ne 'Regexp') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $re ne "Regexp") 0 0 0
2165 # Use eval to compile safely — qr/$re/ would interpolate
2166 # the string first, corrupting patterns containing [ or \
2167 0 my $compiled = eval { qr/$re/ };
2168 0 ▶ if($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 0 0
2169 0 carp("Invalid matches pattern '$re': $@");
2170 } else {
2171 0 $output{'matches'} = $compiled;
2172 }
2173 }
2174 }
2175  
2176 # Compile nomatch pattern to a Regexp object so it renders
2177 # as qr{} in the generated test rather than a raw string.
2178 # Without this, patterns containing [ or other regex
2179 # metacharacters cause compilation failures in validators
2180 424 ▶ if(defined(my $re = $output{'nomatch'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $re = $output{"nomatch"})) 0 424 424
2181 0 ▶ if(ref($re) ne 'Regexp') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $re ne "Regexp") 0 0 0
2182 # Use eval to compile safely — qr/$re/ would interpolate
2183 # the string first, corrupting patterns containing [ or \
2184 0 my $compiled = eval { qr/$re/ };
2185 0 ▶ if($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 0 0
2186 0 carp("Invalid nomatch pattern '$re': $@");
2187 } else {
2188 0 $output{'nomatch'} = $compiled;
2189 }
2190 }
2191 }
2192  
2193 424 my $output_code = render_args_hash(\%output);
2194 424 ▶ my $new_code = ($new && (ref $new eq 'HASH')) ? render_args_hash($new) : '';
Branch: 1 branch
BranchTrueFalseTotal
$new && ref $new eq 'HASH' ? : 100 324 424
Condition100%3/3
$new and ref $new eq "HASH"
!ll&&!rl&&r
29133100
MC/DC100%2/2
$new and ref $new eq "HASH"
$new ref $new eq "HASH"
Truth table100%3/3
A and B
A= $newB= ref $new eq "HASH"
ABresult
0X0
100
111
2195  
2196 424 my $transforms_code;
2197 424 ▶ if(keys %transforms) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %transforms) 8 416 424
2198 8 foreach my $transform(keys %transforms) {
2199 12 my $properties = render_fallback($transforms{$transform}->{'properties'});
2200  
2201 12 ▶ if($transforms_code) {
Branch: 1 branch
BranchTrueFalseTotal
if ($transforms_code) 4 8 12
2202 4 $transforms_code .= "},\n";
2203 }
2204 $transforms_code .= "$transform => {\n" .
2205 "\t'input' => { " .
2206 render_args_hash($transforms{$transform}->{'input'}) .
2207 "\t}, 'output' => { " .
2208 12 render_args_hash($transforms{$transform}->{'output'}) .
2209 "\t}, 'properties' => $properties\n" .
2210 "\t,\n";
2211 }
2212 8 $transforms_code .= "}\n";
2213 }
2214  
2215 424 my $transform_properties_code = '';
2216 424 my $use_properties = 0;
2217  
2218 424 ▶ if (keys %transforms && ($config{properties}{enable} // 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %transforms and $config{"properties"}{"enable"} // 0) 5 419 424
Condition80%4/5
keys %transforms and $config{"properties"}{"enable"} // 0
!ll&&!rl&&r
41635
$config{"properties"}{"enable"} // 0
l!l
80
MC/DC50%1/2
keys %transforms and $config{"properties"}{"enable"} // 0
keys %transforms $config{"properties"}{"enable"}
Truth table66%2/3
A and B
A= keys %transformsB= $config{"properties"}{"enable"}
ABresult
0X0
100
111
2219 5 $use_properties = 1;
2220  
2221 # Generate property-based tests for transforms
2222 5 my $properties = _generate_transform_properties(
2223 \%transforms,
2224 $function,
2225 $module,
2226 \%input,
2227 \%config,
2228 $new
2229 );
2230  
2231 # Convert to code for template
2232 4 $transform_properties_code = _render_properties($properties);
2233 }
2234  
2235 423 ▶ if(keys %accessor) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %accessor) 29 394 423
2236 # Sanity test
2237 29 my $property = $accessor{property};
2238 29 my $type = $accessor{type};
2239  
2240 29 ▶ if(!defined($new)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $new) 0 29 29
2241 # Internal invariant — schema has a contradictory accessor+type combination;
2242 # confess gives the full call chain to aid debugging
2243 0 confess("invariant violation: $property: accessor $type can only work on an object, incorrectly tagged as $type");
2244 }
2245 29 ▶ if($type eq 'getset') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "getset") 9 20 29
2246 9 ▶ if(scalar(keys %input) != 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %input != 1) 1 8 9
2247 1 confess("invariant violation: $property: getset must take one input argument, incorrectly tagged as getset");
2248 }
2249 8 ▶ if(scalar(keys %output) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %output == 0) 1 7 8
2250 1 confess("invariant violation: $property: getset must give one output, incorrectly tagged as getset");
2251 }
2252 }
2253 }
2254  
2255 # Setup / call code (always load module)
2256 421 ▶ my $setup_code = ($module) ? "BEGIN { use_ok('$module') }" : '';
Branch: 1 branch
BranchTrueFalseTotal
$module ? : 367 54 421
2257 421 my $call_code; # Code to call the function being test when used with named arguments
2258 my $position_code; # Code to call the function being test when used with position arguments
2259 421 my $has_positions = _has_positions(\%input);
2260  
2261 # Numeric values have no single string form: one and the same integer can
2262 # stringify as "5967331536404480" (an IV) or "5.96733153640448e+15" (an
2263 # NV), so a getset round trip on an integer or number parameter is compared
2264 # numerically. The routine returns the value unchanged, yet eq failed on
2265 # the harness's own input about once in forty runs.
2266 421 my $cmp_op = 'eq';
2267 421 ▶ if(scalar(keys %input) == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %input == 1) 246 175 421
2268 246 my ($spec) = values %input;
2269 246 ▶ my $type = (ref($spec) eq 'HASH') ? $spec->{type} : $spec;
Branch: 1 branch
BranchTrueFalseTotal
ref $spec eq 'HASH' ? : 196 50 246
2270 246 ▶ $cmp_op = '==' if(defined($type) && !ref($type) && ($type =~ /^(?:integer|number|float)$/));
Branch: 1 branch
BranchTrueFalseTotal
if defined $type and not ref $type and $type =~ /^(?:integer|number|float)$/u 43 203 246
Condition50%3/6
defined $type and not ref $type and $type =~ /^(?:integer|number|float)$/u
!ll&&!rl&&r
020343
defined $type and not ref $type
!ll&&!rl&&r
00246
MC/DC33%1/3
defined $type and not ref $type and $type =~ /^(?:integer|number|float)$/u
defined $type not ref $type $type =~ /^(?:integer|number|float)$/u
Truth table50%2/4
A and not(B) and C
A= defined $typeB= not ref $typeC= $type =~ /^(?:integer|number|float)$/u
ABCresult
0XX0
10X0
1100
1111
2271 }
2272 421 ▶ if(defined($new) && defined($module)) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $new and defined $module) { } 130 291 421
elsif (defined $module and length $module) { } 237 54 291
Condition100%3/3
defined $new and defined $module
!ll&&!rl&&r
2901130
MC/DC100%2/2
defined $new and defined $module
defined $new defined $module
Truth table100%3/3
A and B
A= defined $newB= defined $module
ABresult
0X0
100
111
2273 # keep use_ok regardless (user found earlier issue)
2274 130 ▶ if($new_code eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($new_code eq '') { } 95 35 130
2275 95 $new_code = "new_ok('$module')";
2276 } else {
2277 35 $new_code = "new_ok('$module' => [ $new_code ] )";
2278 }
2279 130 $setup_code .= "\nmy \$obj = $new_code;";
2280 130 ▶ if($has_positions) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has_positions) { } 66 64 130
2281 66 $position_code = "\$result = (scalar(\@alist) == 1) ? \$obj->$function(\$alist[0]) : (scalar(\@alist) == 0) ? \$obj->$function() : \$obj->$function(\@alist);";
2282 66 ▶ if(defined($accessor{type})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $accessor{"type"}) 5 61 66
2283 5 ▶ if($accessor{type} eq 'getter') {
Branch: 2 branches
BranchTrueFalseTotal
if ($accessor{'type'} eq 'getter') { } 0 5 5
elsif ($accessor{'type'} eq 'getset') { } 5 0 5
2284 0 $position_code .= "my \$prev_value = \$obj->{$accessor{property}};";
2285 } elsif($accessor{type} eq 'getset') {
2286 5 $position_code .= 'if(scalar(@alist) == 1) { ';
2287 5 $position_code .= "cmp_ok(\$result, '$cmp_op', \$alist[0], 'getset function returns what was put in'); ok(\$obj->$function() $cmp_op \$result, 'test getset accessor');";
2288 5 $position_code .= '}';
2289 }
2290 5 ▶ if(($accessor{type} eq 'getset') || ($accessor{type} eq 'getter')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($accessor{"type"} eq "getset" or $accessor{"type"} eq "getter") 5 0 5
Condition33%1/3
$accessor{"type"} eq "getset" or $accessor{"type"} eq "getter"
l!l&&r!l&&!r
500
MC/DC0%0/2
$accessor{"type"} eq "getset" or $accessor{"type"} eq "getter"
$accessor{"type"} eq "getset" $accessor{"type"} eq "getter"
Truth table33%1/3
A or B
A= $accessor{"type"} eq "getset"B= $accessor{"type"} eq "getter"
ABresult
1X1
011
000
2291 # Since Perl doesn't support data encapsulation, we can test the getter returns the correct item
2292 5 $position_code .= 'if(scalar(@alist) == 1) { ';
2293 5 $position_code .= "cmp_ok(\$result, '$cmp_op', \$obj->{$accessor{property}}, 'getset function returns correct item');";
2294 5 ▶ if($accessor{type} eq 'getter') {
Branch: 1 branch
BranchTrueFalseTotal
if ($accessor{"type"} eq "getter") 0 5 5
2295 0 $position_code .= "if(defined(\$prev_value)) { cmp_ok(\$result, 'eq', \$prev_value, 'getter does not change value'); } ";
2296 }
2297 5 $position_code .= '}';
2298 }
2299 5 ▶ if($output{'_returns_self'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($output{"_returns_self"}) 0 5 5
2300 0 croak("$accessor{type} for $accessor{property} cannot return \$self");
2301 }
2302 }
2303 } else {
2304 64 $call_code = "\$result = \$obj->$function(_fuzz_args(\$input));";
2305 64 ▶ if($output{'_returns_self'}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($output{'_returns_self'}) { } 0 64 64
elsif (defined $accessor{'type'} and $accessor{'type'} eq 'getset') { } 2 104 106
2306 0 $call_code .= "ok(defined(\$result)); ok(\$result eq \$obj, '$function returns self')";
2307 ▶ } elsif(defined($accessor{type}) && ($accessor{type} eq 'getset')) {
Condition100%3/3
defined $accessor{"type"} and $accessor{"type"} eq "getset"
!ll&&!rl&&r
42202
MC/DC100%2/2
defined $accessor{"type"} and $accessor{"type"} eq "getset"
defined $accessor{"type"} $accessor{"type"} eq "getset"
Truth table100%3/3
A and B
A= defined $accessor{"type"}B= $accessor{"type"} eq "getset"
ABresult
0X0
100
111
2308 2 $call_code .= "ok(\$obj->$function() $cmp_op \$result, 'test getset accessor');"
2309 }
2310 64 ▶ if(scalar(keys %input) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %input == 0) 55 9 64
2311 55 ▶ if(defined($accessor{type}) && ($accessor{type} eq 'getter')) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $accessor{"type"} and $accessor{"type"} eq "getter") 20 35 55
Condition66%2/3
defined $accessor{"type"} and $accessor{"type"} eq "getter"
!ll&&!rl&&r
35020
MC/DC50%1/2
defined $accessor{"type"} and $accessor{"type"} eq "getter"
defined $accessor{"type"} $accessor{"type"} eq "getter"
Truth table66%2/3
A and B
A= defined $accessor{"type"}B= $accessor{"type"} eq "getter"
ABresult
0X0
100
111
2312 20 $call_code .= "cmp_ok(\$result, 'eq', \$obj->{$accessor{property}}, 'getter function returns correct item') if(defined(\$result));";
2313 }
2314 }
2315 }
2316 ▶ } elsif(defined($module) && length($module)) {
Condition66%2/3
defined $module and length $module
!ll&&!rl&&r
540237
MC/DC50%1/2
defined $module and length $module
defined $module length $module
Truth table66%2/3
A and B
A= defined $moduleB= length $module
ABresult
0X0
100
111
2317 # `import` is a class method: `use Module` calls Module->import(...).
2318 # Some modules (Database::Abstraction) take the class as their first
2319 # argument, so a plain Module::import() with no named arguments dies.
2320 # A documented $class invocant (or new/import) is called on the class
2321 # itself; without one the routine is a plain function of the module.
2322 237 ▶ if(($function eq 'new') || ($function eq 'import') || (defined($invocant) && ($invocant eq 'class') && !defined($new))) {
Branch: 1 branch
BranchTrueFalseTotal
if ($function eq 'new' or $function eq 'import' or defined $invocant and $invocant eq 'class' and not defined $new) { } 45 192 237
Condition83%10/12
$function eq "new" or $function eq "import" or defined $invocant and $invocant eq "class" and not defined $new
l!l&&r!l&&!r
441192
$function eq "new" or $function eq "import"
l!l&&r!l&&!r
431193
defined $invocant and $invocant eq "class" and not defined $new
!ll&&!rl&&r
19201
defined $invocant and $invocant eq "class"
!ll&&!rl&&r
19201
MC/DC60%3/5
$function eq "new" or $function eq "import" or defined $invocant and $invocant eq "class" and not defined $new
$function eq "new" $function eq "import" defined $invocant $invocant eq "class" not defined $new
Truth table66%4/6
A or B or C and D and not(E)
A= $function eq "new"B= $function eq "import"C= defined $invocantD= $invocant eq "class"E= not defined $new
ABCDEresult
1XXXX1
01XXX1
001111
000XX0
0010X0
001100
2323 45 ▶ if($has_positions) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has_positions) { } 1 44 45
2324 1 $position_code = "\$result = (scalar(\@alist) == 1) ? ${module}\->$function(\$alist[0]) : (scalar(\@alist) == 0) ? ${module}\->$function() : ${module}\->$function(\@alist);";
2325 } else {
2326 44 $call_code = "\$result = ${module}\->$function(_fuzz_args(\$input));";
2327 }
2328 } else {
2329 192 ▶ if($has_positions) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has_positions) { } 123 69 192
2330 123 $position_code = "\$result = (scalar(\@alist) == 1) ? ${module}::$function(\$alist[0]) : (scalar(\@alist) == 0) ? ${module}::$function() : ${module}::$function(\@alist);";
2331 } else {
2332 69 $call_code = "\$result = ${module}::$function(_fuzz_args(\$input));";
2333 }
2334 }
2335 } else {
2336 54 ▶ if($has_positions) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has_positions) { } 8 46 54
2337 8 $position_code = "\$result = $function(\@alist);";
2338 } else {
2339 46 $call_code = "\$result = $function(_fuzz_args(\$input));";
2340 }
2341 }
2342  
2343 # List-context capture: $result = func() in scalar context returns a count, not the list.
2344 # When the schema says output type is 'array', capture into @_r then take a ref.
2345 421 ▶ if(($output{type} // '') eq 'array') {
Branch: 1 branch
BranchTrueFalseTotal
if (($output{"type"} // "") eq "array") 12 409 421
Condition100%2/2
$output{"type"} // ""
l!l
40714
MC/DC100%1/1
$output{"type"} // ""
$output{"type"}
Truth table100%2/2
A
A= $output{"type"}
Aresult
11
00
2346 12 ▶ if(defined($call_code)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $call_code) 10 2 12
2347 10 $call_code =~ s/\A\$result = ([^;]+);/my \@_r = ($1); \$result = \\\@_r;/;
2348 }
2349 12 ▶ if(defined($position_code)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $position_code) 2 10 12
2350 2 $position_code =~ s/\A\$result = ([^;]+);/my \@_r = ($1); \$result = \\\@_r;/;
2351 }
2352 }
2353  
2354 # A getter is called for its return value, so it must not change the state
2355 # of the object it was handed. The object is deep copied before the call
2356 # and its existing state compared afterwards; values it fills in where it
2357 # was handed undef are ignored along with keys it adds, because a getter
2358 # that caches the value it worked out is doing its job, while one that
2359 # overwrites or removes state it was given is not
2360 # - the change is invisible to the caller, which still holds the object,
2361 # and the next call sees different behaviour for the same input.
2362 421 ▶ if(defined($accessor{type}) && ($accessor{type} eq 'getter')) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $accessor{"type"} and $accessor{"type"} eq "getter") 20 401 421
Condition100%3/3
defined $accessor{"type"} and $accessor{"type"} eq "getter"
!ll&&!rl&&r
394720
MC/DC100%2/2
defined $accessor{"type"} and $accessor{"type"} eq "getter"
defined $accessor{"type"} $accessor{"type"} eq "getter"
Truth table100%3/3
A and B
A= defined $accessor{"type"}B= $accessor{"type"} eq "getter"
ABresult
0X0
100
111
2363 # A getter with no declared input must be called with no arguments:
2364 # $input is the schema's own hashref, and a getter that takes
2365 # an optional second argument would store it as if it were a value.
2366 20 foreach my $code (\$call_code, \$position_code) {
2367 40 ▶ next unless(defined($$code));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$code 20 20 40
2368 20 $$code =~ s/\Q$function\E\(_fuzz_args\(\$input\)\)/$function()/g;
2369 }
2370 20 my $snapshot = 'my $getter_copy = eval { require Storable; Storable::dclone($obj) }; ';
2371 20 my $check = 'if(defined($getter_copy) && eval { scalar(keys %{$getter_copy}); 1 }) {'
2372 . ' my %getter_state = map { $_ => $getter_copy->{$_} } grep { defined($getter_copy->{$_}) } keys %{$getter_copy};'
2373 . ' is_deeply({ map { $_ => $obj->{$_} } grep { exists($obj->{$_}) } keys %getter_state }, \\%getter_state, q{getter leaves its object unmodified});'
2374 . ' }';
2375 20 foreach my $code (\$call_code, \$position_code) {
2376 40 ▶ next unless(defined($$code) && ($config{'check_accessors'} // 1));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$code and $config{"check_accessors"} // 1 21 19 40
Condition80%4/5
defined $$code and $config{"check_accessors"} // 1
!ll&&!rl&&r
20119
$config{"check_accessors"} // 1
l!l
200
MC/DC50%1/2
defined $$code and $config{"check_accessors"} // 1
defined $$code $config{"check_accessors"}
Truth table66%2/3
A and B
A= defined $$codeB= $config{"check_accessors"}
ABresult
0X0
100
111
2377 19 $$code = $snapshot . $$code . ' ' . $check;
2378 }
2379 }
2380  
2381 # A setter is called to change one property, so everything else the object
2382 # was handed must come back untouched. The object is deep copied before the
2383 # call and the rest of its state compared afterwards; the property itself is
2384 # excluded, since changing that is the point, and values it fills in where it
2385 # was handed undef are ignored along with keys it adds, so that lazy
2386 # initialisation is not reported as damage.
2387 421 ▶ if(defined($accessor{type}) && ($accessor{type} eq 'getset') && defined($accessor{property})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $accessor{"type"} and $accessor{"type"} eq "getset" and defined $accessor{"property"}) 7 414 421
Condition83%5/6
defined $accessor{"type"} and $accessor{"type"} eq "getset" and defined $accessor{"property"}
!ll&&!rl&&r
41407
defined $accessor{"type"} and $accessor{"type"} eq "getset"
!ll&&!rl&&r
394207
MC/DC66%2/3
defined $accessor{"type"} and $accessor{"type"} eq "getset" and defined $accessor{"property"}
defined $accessor{"type"} $accessor{"type"} eq "getset" defined $accessor{"property"}
Truth table75%3/4
A and B and C
A= defined $accessor{"type"}B= $accessor{"type"} eq "getset"C= defined $accessor{"property"}
ABCresult
0XX0
10X0
1100
1111
2388 7 my $property = perl_quote($accessor{property});
2389 7 my $snapshot = 'my $setter_copy = eval { require Storable; Storable::dclone($obj) }; ';
2390 7 my $check = 'if(defined($setter_copy) && eval { scalar(keys %{$setter_copy}); 1 }) {'
2391 . ' my %setter_state = map { $_ => $setter_copy->{$_} } grep { defined($setter_copy->{$_}) && ($_ ne ' . $property . ') } keys %{$setter_copy};'
2392 . ' is_deeply({ map { $_ => $obj->{$_} } grep { exists($obj->{$_}) } keys %setter_state }, \\%setter_state, q{setter changes nothing but its property});'
2393 . ' }';
2394 7 foreach my $code (\$call_code, \$position_code) {
2395 14 ▶ next unless(defined($$code) && ($config{'check_accessors'} // 1));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$code and $config{"check_accessors"} // 1 8 6 14
Condition80%4/5
defined $$code and $config{"check_accessors"} // 1
!ll&&!rl&&r
716
$config{"check_accessors"} // 1
l!l
70
MC/DC50%1/2
defined $$code and $config{"check_accessors"} // 1
defined $$code $config{"check_accessors"}
Truth table66%2/3
A and B
A= defined $$codeB= $config{"check_accessors"}
ABresult
0X0
100
111
2396 6 $$code = $snapshot . $$code . ' ' . $check;
2397 }
2398 }
2399  
2400 # Build static corpus code
2401 421 my $corpus_code = '';
2402 421 ▶ if (%all_cases) {
Branch: 1 branch
BranchTrueFalseTotal
if (%all_cases) 3 418 421
2403 3 $corpus_code = "\n# --- Static Corpus Tests ---\n" .
2404 "diag('Running " . scalar(keys %all_cases) . " corpus tests');\n";
2405  
2406 3 for my $expected (sort keys %all_cases) {
2407 6 my $inputs = $all_cases{$expected};
2408 6 ▶ next unless($inputs);
Branch: 1 branch
BranchTrueFalseTotal
unless $inputs 0 6 6
2409  
2410 6 my $expected_str = perl_quote($expected);
2411 6 ▶ my $status = ((ref($inputs) eq 'HASH') && $inputs->{'_STATUS'}) // 'OK';
Condition40%2/5
ref $inputs eq "HASH" && $inputs->{"_STATUS"} // "OK"
l!l
60
ref $inputs eq "HASH" and $inputs->{"_STATUS"}
!ll&&!rl&&r
600
MC/DC0%0/2
ref $inputs eq "HASH" && $inputs->{"_STATUS"} // "OK"
ref $inputs eq "HASH" $inputs->{"_STATUS"}
Truth table33%1/3
A and B
A= ref $inputs eq "HASH"B= $inputs->{"_STATUS"}
ABresult
111
0X0
100
2412 6 ▶ if($expected_str eq "'_STATUS:DIES'") {
Branch: 2 branches
BranchTrueFalseTotal
if ($expected_str eq q['_STATUS:DIES']) { } 0 6 6
elsif ($expected_str eq q['_STATUS:WARNS']) { } 0 6 6
2413 0 $status = 'DIES';
2414 } elsif($expected_str eq "'_STATUS:WARNS'") {
2415 0 $status = 'WARNS';
2416 }
2417  
2418 6 ▶ if(ref($inputs) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $inputs eq "HASH") 0 6 6
2419 0 $inputs = $inputs->{'input'};
2420 }
2421 6 my $input_str;
2422 6 ▶ if(ref($inputs) eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $inputs eq 'ARRAY') { } 6 0 6
elsif (ref $inputs eq 'HASH') { } 0 0 0
2423 6 $input_str = join(', ', map { perl_quote($_) } @{$inputs});
2424 } elsif(ref($inputs) eq 'HASH') {
2425 0 $input_str = render_fallback($inputs);
2426  
2427 # YAML can't express Perl's undef, so a corpus value of
2428 # the sentinel string 'undef' means "this param is
2429 # undef" -- convert the quoted sentinel back to the
2430 # bareword so the generated test passes real undef
2431 0 $input_str =~ s/=> 'undef'/=> undef/gms;
2432 } else {
2433 0 $input_str = $inputs;
2434 }
2435 6 ▶ if(($input_str eq 'undef') && (!$config{'test_undef'})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input_str eq "undef" and not $config{"test_undef"}) 0 6 6
Condition33%1/3
$input_str eq "undef" and not $config{"test_undef"}
!ll&&!rl&&r
600
MC/DC0%0/2
$input_str eq "undef" and not $config{"test_undef"}
$input_str eq "undef" not $config{"test_undef"}
Truth table33%1/3
A and not(B)
A= $input_str eq "undef"B= not $config{"test_undef"}
ABresult
0X0
100
111
2436 0 carp('corpus case set to undef, yet test_undef is not set in config');
2437 }
2438 6 ▶ if($new) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new) { } 0 6 6
2439 0 ▶ if($status eq 'DIES') {
Branch: 2 branches
BranchTrueFalseTotal
if ($status eq 'DIES') { } 0 0 0
elsif ($status eq 'WARNS') { } 0 0 0
2440 $corpus_code .= "dies_ok { \$obj->$function($input_str) } " .
2441 0 ▶ "'$function(" . join(', ', map { $_ // '' } @$inputs ) . ") dies';\n";
Condition0%0/2
$_ // ""
l!l
00
MC/DC0%0/1
$_ // ""
$_
Truth table0%0/2
A
A= $_
Aresult
11
00
2442 } elsif($status eq 'WARNS') {
2443 $corpus_code .= "warnings_exist { \$obj->$function($input_str) } qr/./, " .
2444 0 ▶ "'$function(" . join(', ', map { $_ // '' } @$inputs ) . ") warns';\n";
Condition0%0/2
$_ // ""
l!l
00
MC/DC0%0/1
$_ // ""
$_
Truth table0%0/2
A
A= $_
Aresult
11
00
2445 } else {
2446 my $desc = sprintf("$function(%s) returns %s",
2447 0 ▶ perl_quote(join(', ', map { $_ // '' } @$inputs )),
Condition0%0/2
$_ // ""
l!l
00
MC/DC0%0/1
$_ // ""
$_
Truth table0%0/2
A
A= $_
Aresult
11
00
2448 $expected_str
2449 );
2450 0 ▶ if(($output{'type'} // '') eq 'boolean') {
Branch: 1 branch
BranchTrueFalseTotal
if (($output{'type'} // '') eq 'boolean') { } 0 0 0
Condition0%0/2
$output{"type"} // ""
l!l
00
MC/DC0%0/1
$output{"type"} // ""
$output{"type"}
Truth table0%0/2
A
A= $output{"type"}
Aresult
11
00
2451 0 ▶ if($expected_str eq '1') {
Branch: 2 branches
BranchTrueFalseTotal
if ($expected_str eq '1') { } 0 0 0
elsif ($expected_str eq '0') { } 0 0 0
2452 0 $corpus_code .= "ok(\$obj->$function($input_str), " . q_wrap($desc) . ");\n";
2453 } elsif($expected_str eq '0') {
2454 0 $corpus_code .= "ok(!\$obj->$function($input_str), " . q_wrap($desc) . ");\n";
2455 } else {
2456 0 croak("Boolean is expected to return $expected_str");
2457 }
2458 } else {
2459 0 $corpus_code .= "is(\$obj->$function($input_str), $expected_str, " . q_wrap($desc) . ");\n";
2460 }
2461 }
2462 } else {
2463 6 ▶ if($status eq 'DIES') {
Branch: 2 branches
BranchTrueFalseTotal
if ($status eq 'DIES') { } 0 6 6
elsif ($status eq 'WARNS') { } 0 6 6
2464 0 ▶ if($module) {
Branch: 1 branch
BranchTrueFalseTotal
if ($module) { } 0 0 0
2465 0 $corpus_code .= "dies_ok { $module\::$function($input_str) } " .
2466 "'Corpus $expected dies';\n";
2467 } else {
2468 0 $corpus_code .= "dies_ok { $function($input_str) } " .
2469 "'Corpus $expected dies';\n";
2470 }
2471 } elsif($status eq 'WARNS') {
2472 0 ▶ if($module) {
Branch: 1 branch
BranchTrueFalseTotal
if ($module) { } 0 0 0
2473 0 $corpus_code .= "warnings_exist { $module\::$function($input_str) } qr/./, " .
2474 "'Corpus $expected warns';\n";
2475 } else {
2476 0 $corpus_code .= "warnings_exist { $function($input_str) } qr/./, " .
2477 "'Corpus $expected warns';\n";
2478 }
2479 } else {
2480 my $desc = sprintf("$function(%s) returns %s",
2481 6 ▶ perl_quote((ref $inputs eq 'ARRAY') ? (join(', ', map { $_ // '' } @{$inputs})) : $inputs),
Branch: 1 branch
BranchTrueFalseTotal
ref $inputs eq 'ARRAY' ? : 6 0 6
Condition50%1/2
$_ // ""
l!l
90
MC/DC0%0/1
$_ // ""
$_
Truth table50%1/2
A
A= $_
Aresult
11
00
2482 $expected_str
2483 );
2484 6 ▶ if(($output{'type'} // '') eq 'boolean') {
Branch: 1 branch
BranchTrueFalseTotal
if (($output{'type'} // '') eq 'boolean') { } 0 6 6
Condition50%1/2
$output{"type"} // ""
l!l
60
MC/DC0%0/1
$output{"type"} // ""
$output{"type"}
Truth table50%1/2
A
A= $output{"type"}
Aresult
11
00
2485 0 ▶ if($expected_str eq '1') {
Branch: 2 branches
BranchTrueFalseTotal
if ($expected_str eq '1') { } 0 0 0
elsif ($expected_str eq '0') { } 0 0 0
2486 0 $corpus_code .= "ok(\$obj->$function($input_str), " . q_wrap($desc) . ");\n";
2487 } elsif($expected_str eq '0') {
2488 0 $corpus_code .= "ok(!\$obj->$function($input_str), " . q_wrap($desc) . ");\n";
2489 } else {
2490 0 croak("Boolean is expected to return $expected_str");
2491 }
2492 } else {
2493 6 $corpus_code .= "is(\$obj->$function($input_str), $expected_str, " . q_wrap($desc) . ");\n";
2494 }
2495 }
2496 }
2497 }
2498 }
2499  
2500 # Prepare seed/iterations code fragment for the generated test
2501 # A schema can record a precondition that no generated value can meet (for
2502 # example a file the routine parses). The harness then has nothing to
2503 # assert and says so instead of failing on a call it cannot make.
2504 421 my $skip_reason = $schema->{skip};
2505  
2506 # The generated harness needs the seed both to seed Perl's RNG (which the
2507 # regex generator uses) and to name it in failure diagnostics.
2508 421 my $seed_code = "our \$seed;\n";
2509 421 ▶ if (defined $seed) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $seed) 14 407 421
2510 # ensure integer-ish
2511 14 $seed = int($seed);
2512 14 $seed_code .= "srand(\$seed = $seed);\n";
2513 }
2514  
2515 421 ▶ my $determinism_code = 'my $result2;' .
Branch: 1 branch
BranchTrueFalseTotal
defined $position_code ? : 198 223 421
2516 'eval { $result2 = do { ' . (defined($position_code) ? $position_code : $call_code) . " }; };\n" .
2517 'is_deeply($result2, $result, "deterministic result for same input");' .
2518 "\n";
2519  
2520 # Generate the test content
2521 421 my $tt = Template->new({ ENCODING => 'utf8', TRIM => 1 });
2522  
2523 # Read template from DATA handle
2524 421 my $template_package = __PACKAGE__ . '::Template';
2525 421 my $template = $template_package->get_data_section('test.tt');
2526  
2527 my $vars = {
2528 setup_code => $setup_code,
2529 edge_cases_code => $edge_cases_code,
2530 edge_case_array_code => $edge_case_array_code,
2531 type_edge_cases_code => $type_edge_cases_code,
2532 config_code => $config_code,
2533 seed_code => $seed_code,
2534 input_code => $input_code,
2535 output_code => $output_code,
2536 transforms_code => $transforms_code,
2537 corpus_code => $corpus_code,
2538 call_code => $call_code,
2539 position_code => $position_code,
2540 determinism_code => $determinism_code,
2541 documented_sources => join(' ', App::Test::Generator::Provenance::documented_sources()),
2542 type_checks_source => App::Test::Generator::Provenance::type_checks_source(),
2543 function => $function,
2544 iterations_code => int($iterations),
2545 use_properties => $use_properties,
2546 transform_properties_code => $transform_properties_code,
2547 421 ▶ property_trials => $config{properties}{trials} // $DEFAULT_PROPERTY_TRIALS,
Condition100%3/3
$config{"properties"}{"trials"} // $DEFAULT_PROPERTY_TRIALS
l!l&&r!l&&!r
4220197
MC/DC100%2/2
$config{"properties"}{"trials"} // $DEFAULT_PROPERTY_TRIALS
$config{"properties"}{"trials"} $DEFAULT_PROPERTY_TRIALS
Truth table100%3/3
A // B
A= $config{"properties"}{"trials"}B= $DEFAULT_PROPERTY_TRIALS
ABresult
1X1
011
000
2548 relationships_code => $relationships_code,
2549 module => $module,
2550 skip_reason => $skip_reason
2551 };
2552  
2553 421 my $test;
2554 421 ▶ $tt->process($template, $vars, \$test) or croak($tt->error());
Branch: 1 branch
BranchTrueFalseTotal
$tt->process($template, $vars, \$test) or croak($tt->error) 421 0 421
2555  
2556 421 ▶ if ($test_file) {
Branch: 1 branch
BranchTrueFalseTotal
if ($test_file) { } 362 59 421
2557 # autodie is disabled for this open -- under "use autodie qw(:all)"
2558 # open() never returns false on failure, it throws its own exception
2559 # instead, which would silently make the "or croak" dead code.
2560 225 ▶ no autodie qw(open);
Subroutine BEGIN: called CC=1 SCAR=0.0
2561 362 ▶ open my $fh, '>:encoding(UTF-8)', $test_file or croak "Cannot open $test_file: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">:encoding(UTF-8)", $test_file or croak("Cannot open ${test_file}: $!") 362 0 362
2562 362 print $fh "$test\n";
2563 362 close $fh;
2564 362 ▶ if($module) {
Branch: 1 branch
BranchTrueFalseTotal
if ($module) { } 348 14 362
2565 348 print "Generated $test_file for $module\::$function with fuzzing + corpus support\n";
2566 } else {
2567 14 print "Generated $test_file for $function with fuzzing + corpus support\n";
2568 }
2569 } else {
2570 59 print "$test\n";
2571 }
2572  
2573 421 return 1;
2574 }
2575  
2576 # --- Helpers for rendering data structures into Perl code for the generated test ---
2577  
2578 # --------------------------------------------------
2579 # _is_perl_builtin
2580 #
2581 # Purpose: Return true if a string is the name of
2582 # a Perl core builtin function, to prevent
2583 # it being used as a module name in
2584 # use_ok() calls in generated tests.
2585 #
2586 # Entry: $name - the string to check.
2587 # Exit: Returns 1 if builtin, 0 otherwise.
2588 # --------------------------------------------------
2589 34 ▶sub _is_perl_builtin {
Subroutine _is_perl_builtin: called CC=3 SCAR=11.0
2590 34 my $name = $_[0];
2591 34 ▶ return 0 unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 2 32 34
2592  
2593 32 state %BUILTINS = map { $_ => 1 } qw(
2594 abs accept alarm atan2 bind binmode bless
2595 caller chdir chmod chomp chop chown chr chroot
2596 close closedir connect cos crypt
2597 dbmclose dbmopen defined delete die do dump
2598 each endgrent endhostent endnetent endprotoent endpwent endservent
2599 eof eval exec exists exit exp
2600 fcntl fileno flock fork format formline
2601 getc getgrent getgrgid getgrnam gethostbyaddr gethostbyname
2602 gethostent getlogin getnetbyaddr getnetbyname getnetent
2603 getpeername getpgrp getppid getpriority getprotobyname
2604 getprotobynumber getprotoent getpwent getpwnam getpwuid
2605 getservbyname getservbyport getservent getsockname getsockopt
2606 glob gmtime goto grep
2607 hex
2608 index int ioctl
2609 join
2610 keys kill
2611 last lc lcfirst length link listen local localtime log lstat
2612 map mkdir msgctl msgget msgrcv msgsnd my
2613 next no
2614 oct open opendir ord our
2615 pack pipe pop pos print printf prototype push
2616 quotemeta
2617 rand read readdir readline readlink readpipe recv redo
2618 ref rename require reset return reverse rewinddir rindex rmdir
2619 say scalar seek seekdir select semctl semget semop send
2620 setgrent sethostent setnetent setpgrp setpriority setprotoent
2621 setpwent setservent setsockopt shift shmctl shmget shmread
2622 shmwrite shutdown sin sleep socket socketpair sort splice split
2623 sprintf sqrt srand stat study sub substr symlink syscall
2624 sysopen sysread sysseek system syswrite
2625 tell telldir tie tied time times truncate
2626 uc ucfirst umask undef unlink unpack unshift untie use
2627 utime values vec wait waitpid wantarray warn write
2628 );
2629 32 ▶ return $BUILTINS{lc $name} // 0;
Condition100%2/2
$BUILTINS{lc $name} // 0
l!l
2012
MC/DC100%1/1
$BUILTINS{lc $name} // 0
$BUILTINS{lc $name}
Truth table100%2/2
A
A= $BUILTINS{lc $name}
Aresult
11
00
2630 }
2631  
2632 # --------------------------------------------------
2633 # _load_schema
2634 #
2635 # Load and parse a schema file using
2636 # Config::Abstraction, returning the
2637 # schema as a hashref.
2638 #
2639 # Entry: $schema_file - path to the schema file.
2640 # Must be defined, non-empty, and readable.
2641 #
2642 # Exit: Returns a hashref of the parsed schema
2643 # with a '_source' key added containing
2644 # the originating file path.
2645 # Croaks on any error.
2646 #
2647 # Side effects: Reads from the filesystem.
2648 #
2649 # Notes: Legacy Perl-file configs (containing
2650 # '$module' or 'our $module' keys) are
2651 # rejected with a clear error. Config::
2652 # Abstraction is used rather than require()
2653 # to avoid executing arbitrary code from
2654 # user-supplied config files.
2655 # --------------------------------------------------
2656 417 ▶sub _load_schema {
Subroutine _load_schema: called CC=8 SCAR=21.1
2657 417 my $schema_file = $_[0];
2658  
2659 # Validate the argument before touching the filesystem
2660 417 ▶ croak(__PACKAGE__, ': Usage: _load_schema($schema_file)') unless defined $schema_file;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $schema_file 2 415 417
2661  
2662 415 ▶ croak(__PACKAGE__, ': _load_schema given empty filename') unless length($schema_file);
Branch: 1 branch
BranchTrueFalseTotal
unless length $schema_file 2 413 415
2663  
2664 # Confirm the file exists and is readable before attempting
2665 # to load it — gives a clearer error than Config::Abstraction would
2666 413 ▶ croak(__PACKAGE__, ": _load_schema($schema_file): $!") unless -r $schema_file;
Branch: 1 branch
BranchTrueFalseTotal
unless -r $schema_file 5 408 413
2667  
2668 # Load configuration via Config::Abstraction which supports
2669 # YAML, JSON, and other formats without executing arbitrary code.
2670 # no_fixate prevents automatic type coercion that could alter values
2671 408 ▶ if(my $schema = Config::Abstraction->new(
Branch: 1 branch
BranchTrueFalseTotal
if (my $schema = "Config::Abstraction"->new("config_dirs", [".", ""], "config_file", $schema_file, "no_fixate", 1)) 408 0 408
2672 config_dirs => ['.', ''],
2673 config_file => $schema_file,
2674 no_fixate => 1,
2675 )) {
2676 408 ▶ if($schema = $schema->all()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($schema = $schema->all) 408 0 408
2677 # Detect legacy Perl config files by the presence of
2678 # variable declaration keys — these are no longer supported
2679 408 ▶ if(exists($schema->{$LEGACY_PERL_KEY_1}) ||
Branch: 1 branch
BranchTrueFalseTotal
if (exists $schema->{$LEGACY_PERL_KEY_1} or exists $schema->{$LEGACY_PERL_KEY_2}) 1 407 408
Condition66%2/3
exists $schema->{$LEGACY_PERL_KEY_1} or exists $schema->{$LEGACY_PERL_KEY_2}
l!l&&r!l&&!r
10407
MC/DC50%1/2
exists $schema->{$LEGACY_PERL_KEY_1} or exists $schema->{$LEGACY_PERL_KEY_2}
exists $schema->{$LEGACY_PERL_KEY_1} exists $schema->{$LEGACY_PERL_KEY_2}
Truth table66%2/3
A or B
A= exists $schema->{$LEGACY_PERL_KEY_1}B= exists $schema->{$LEGACY_PERL_KEY_2}
ABresult
1X1
011
000
2680 exists($schema->{$LEGACY_PERL_KEY_2})) {
2681 1 croak("$schema_file: Loading perl files as configs is no longer supported");
2682 }
2683  
2684 # Tag the schema with its source path for error messages
2685 407 $schema->{$SOURCE_KEY} = $schema_file;
2686 407 return $schema;
2687 }
2688 }
2689  
2690 0 croak "Failed to load schema from $schema_file";
2691 }
2692  
2693 # --------------------------------------------------
2694 # _load_schema_section
2695 #
2696 # Purpose: Extract a named section from a parsed
2697 # schema hashref, validating that it is
2698 # a hashref if present.
2699 #
2700 # Entry: $schema - the full parsed schema hashref.
2701 # $section - name of the section to extract
2702 # (e.g. 'input', 'output').
2703 # $schema_file - path of the schema file,
2704 # used in error messages only.
2705 #
2706 # Exit: Returns the section hashref if present,
2707 # or an empty hashref {} if absent.
2708 # Croaks if the section exists but is not
2709 # a hashref (and not the string 'undef').
2710 #
2711 # Notes: The string 'undef' is treated as an
2712 # absent section — callers that set a
2713 # section to 'undef' in YAML get the same
2714 # result as omitting it entirely.
2715 # --------------------------------------------------
2716 1746 ▶sub _load_schema_section {
Subroutine _load_schema_section: called CC=6 SCAR=18.0
2717 1746 my ($schema, $section, $schema_file) = @_;
2718  
2719 # Section absent — return empty hash as the safe default
2720 1746 ▶ return {} unless exists $schema->{$section};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $schema->{$section} 960 786 1746
2721  
2722 # Section present and is a hashref — return it directly
2723 return $schema->{$section}
2724 786 ▶ if ref($schema->{$section}) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $schema->{$section} eq "HASH" 778 8 786
2725  
2726 # Treat the YAML scalar 'undef' as equivalent to absent
2727 return {}
2728 if defined($schema->{$section}) &&
2729 8 ▶ $schema->{$section} eq 'undef';
Branch: 1 branch
BranchTrueFalseTotal
if defined $schema->{$section} and $schema->{$section} eq "undef" 3 5 8
Condition66%2/3
defined $schema->{$section} and $schema->{$section} eq "undef"
!ll&&!rl&&r
053
MC/DC50%1/2
defined $schema->{$section} and $schema->{$section} eq "undef"
defined $schema->{$section} $schema->{$section} eq "undef"
Truth table66%2/3
A and B
A= defined $schema->{$section}B= $schema->{$section} eq "undef"
ABresult
0X0
100
111
2730  
2731 # Section present but wrong type — croak with a clear message
2732 # showing what type was found so the user can fix their schema
2733 croak(
2734 "$schema_file: $section should be a hash, not ",
2735 5 ▶ ref($schema->{$section}) || $schema->{$section}
Condition66%2/3
ref $schema->{$section} || $schema->{$section}
l!l&&r!l&&!r
140
MC/DC0%0/2
ref $schema->{$section} || $schema->{$section}
ref $schema->{$section} $schema->{$section}
Truth table66%2/3
A || B
A= ref $schema->{$section}B= $schema->{$section}
ABresult
1X1
011
000
2736 );
2737 }
2738  
2739 # --------------------------------------------------
2740 # _validate_config
2741 #
2742 # Purpose: Validate the top-level schema hashref
2743 # loaded from a schema file, checking that
2744 # required fields are present and that all
2745 # input parameters, types, positions, and
2746 # transform properties are well-formed.
2747 #
2748 # Entry: $schema - the full parsed schema hashref
2749 # as returned by _load_schema().
2750 #
2751 # Exit: Returns nothing on success.
2752 # Croaks on any structural error.
2753 # Carps on non-fatal warnings (unknown
2754 # semantic types, position gaps, missing
2755 # input/output definitions).
2756 #
2757 # Side effects: May delete $schema->{input} if its
2758 # value is the string 'undef'.
2759 #
2760 # Notes: The parameter is named $schema throughout
2761 # to distinguish the top-level schema from
2762 # the nested config sub-hash. _validate_config
2763 # is called before _normalize_config so config
2764 # boolean normalisation has not yet occurred.
2765 # --------------------------------------------------
2766 448 ▶sub _validate_config {
Subroutine _validate_config: called CC=14 SCAR=26.4
2767 448 my $schema = $_[0];
2768  
2769 # At least one of module or function must be present —
2770 # without these we cannot generate any meaningful test
2771 448 ▶ if(!defined($schema->{'module'}) && !defined($schema->{'function'})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $schema->{"module"} or defined $schema->{"function"}) 4 444 448
Condition100%3/3
defined $schema->{"module"} or defined $schema->{"function"}
l!l&&r!l&&!r
427174
MC/DC100%2/2
defined $schema->{"module"} or defined $schema->{"function"}
defined $schema->{"module"} defined $schema->{"function"}
Truth table100%3/3
A or B
A= defined $schema->{"module"}B= defined $schema->{"function"}
ABresult
1X1
011
000
2772 4 croak('At least one of function and module must be defined');
2773 }
2774  
2775 # Warn if neither input nor output is defined — a few
2776 # generic tests can still be generated but it is unusual
2777 444 ▶ if(!defined($schema->{'input'}) && !defined($schema->{'output'})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $schema->{"input"} or defined $schema->{"output"}) 9 435 444
Condition100%3/3
defined $schema->{"input"} or defined $schema->{"output"}
l!l&&r!l&&!r
3141219
MC/DC100%2/2
defined $schema->{"input"} or defined $schema->{"output"}
defined $schema->{"input"} defined $schema->{"output"}
Truth table100%3/3
A or B
A= defined $schema->{"input"}B= defined $schema->{"output"}
ABresult
1X1
011
000
2778 9 carp('Neither input nor output is defined, only a few tests will be generated');
2779 }
2780  
2781 # Normalise input: the string 'undef' means no input defined
2782 444 ▶ if($schema->{'input'} && ref($schema->{input}) ne 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if ($schema->{"input"} and ref $schema->{"input"} ne "HASH") 3 441 444
Condition100%3/3
$schema->{"input"} and ref $schema->{"input"} ne "HASH"
!ll&&!rl&&r
1303113
MC/DC100%2/2
$schema->{"input"} and ref $schema->{"input"} ne "HASH"
$schema->{"input"} ref $schema->{"input"} ne "HASH"
Truth table100%3/3
A and B
A= $schema->{"input"}B= ref $schema->{"input"} ne "HASH"
ABresult
0X0
100
111
2783 3 ▶ if($schema->{'input'} eq 'undef') {
Branch: 1 branch
BranchTrueFalseTotal
if ($schema->{'input'} eq 'undef') { } 1 2 3
2784 1 delete $schema->{'input'};
2785 } else {
2786 2 croak("Invalid input specification: expected hash, got '$schema->{'input'}'");
2787 }
2788 }
2789  
2790 # Validate each input parameter if input is defined
2791 442 ▶ if($schema->{input}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($schema->{"input"}) 311 131 442
2792 311 _validate_input_params($schema);
2793 308 _validate_input_positions($schema);
2794 308 _validate_input_semantics($schema);
2795 }
2796  
2797 # Validate transform property definitions if present
2798 439 ▶ if(exists($schema->{transforms}) && ref($schema->{transforms}) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $schema->{"transforms"} and ref $schema->{"transforms"} eq "HASH") 15 424 439
Condition66%2/3
exists $schema->{"transforms"} and ref $schema->{"transforms"} eq "HASH"
!ll&&!rl&&r
424015
MC/DC50%1/2
exists $schema->{"transforms"} and ref $schema->{"transforms"} eq "HASH"
exists $schema->{"transforms"} ref $schema->{"transforms"} eq "HASH"
Truth table66%2/3
A and B
A= exists $schema->{"transforms"}B= ref $schema->{"transforms"} eq "HASH"
ABresult
0X0
100
111
2799 15 _validate_transform_properties($schema);
2800 }
2801  
2802 # Validate any nested config sub-hash keys against known types
2803 439 ▶ if(ref($schema->{config}) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $schema->{"config"} eq "HASH") 340 99 439
2804 340 for my $k (keys %{$schema->{'config'}}) {
2805 # %VALID_CONFIG_KEYS is the authoritative set — O(1) hash lookup
2806 croak "unknown config setting '$k'"
2807 2294 ▶ unless $VALID_CONFIG_KEYS{$k};
Branch: 1 branch
BranchTrueFalseTotal
unless $VALID_CONFIG_KEYS{$k} 2 2292 2294
2808 }
2809 }
2810 }
2811  
2812 # --------------------------------------------------
2813 # _validate_input_params
2814 #
2815 # Purpose: Validate type specifications for each
2816 # named input parameter.
2817 #
2818 # Entry: $schema - the full parsed schema hashref.
2819 # $schema->{input} must be a hashref.
2820 #
2821 # Exit: Returns nothing. Croaks on invalid type.
2822 # --------------------------------------------------
2823 # Validate a nested element specification. `schema` on an arrayref describes
2824 # every element; on a hashref it describes every value, or -- when it has no
2825 # type of its own -- maps fixed key names to element specs.
2826 9 ▶sub _validate_element_spec {
Subroutine _validate_element_spec: called CC=23 SCAR=35.0
2827 9 my ($element, $param, $allow_keys) = @_;
2828  
2829 9 ▶ return unless defined($element);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $element 0 9 9
2830 9 ▶ if(!ref($element)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $element) 0 9 9
2831 0 ▶ croak("Invalid element type '$element' for '$param'")
Branch: 1 branch
BranchTrueFalseTotal
unless _valid_nested_type($element) 0 0 0
2832 unless _valid_nested_type($element);
2833 0 return;
2834 }
2835 9 ▶ croak("schema for parameter '$param' must be a hash or a type name")
Branch: 1 branch
BranchTrueFalseTotal
if ref $element ne "HASH" 0 9 9
2836 if ref($element) ne 'HASH';
2837  
2838 9 ▶ if($allow_keys && !exists($element->{type})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($allow_keys and not exists $element->{"type"}) 1 8 9
Condition100%3/3
$allow_keys and not exists $element->{"type"}
!ll&&!rl&&r
171
MC/DC100%2/2
$allow_keys and not exists $element->{"type"}
$allow_keys not exists $element->{"type"}
Truth table100%3/3
A and not(B)
A= $allow_keysB= not exists $element->{"type"}
ABresult
0X0
100
111
2839 croak("A hashref schema for '$param' with fixed keys needs at least one key")
2840 1 ▶ unless keys %{$element};
Branch: 1 branch
BranchTrueFalseTotal
unless keys %{$element;} 0 1 1
2841 1 foreach my $key (sort keys %{$element}) {
2842 2 my $value = $element->{$key};
2843 2 ▶ if(!ref($value)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $value) 1 1 2
2844 1 ▶ croak("Invalid element type '$value' for '$param.$key'")
Branch: 1 branch
BranchTrueFalseTotal
unless _valid_nested_type($value) 0 1 1
2845 unless _valid_nested_type($value);
2846 1 next;
2847 }
2848 1 ▶ croak("Element schema for '$param.$key' must be a hash")
Branch: 1 branch
BranchTrueFalseTotal
unless ref $value eq "HASH" 0 1 1
2849 unless ref($value) eq 'HASH';
2850 1 _validate_element_spec($value, "$param.$key", 0);
2851 }
2852 1 return;
2853 }
2854  
2855 croak("Missing type in the element schema for '$param'")
2856 8 ▶ unless defined($element->{type});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $element->{"type"} 0 8 8
2857 croak("Invalid element type '$element->{type}' for '$param'")
2858 8 ▶ unless !ref($element->{type}) && _valid_nested_type($element->{type});
Branch: 1 branch
BranchTrueFalseTotal
unless not ref $element->{"type"} and _valid_nested_type($element->{"type"}) 1 7 8
Condition66%2/3
not ref $element->{"type"} and _valid_nested_type($element->{"type"})
!ll&&!rl&&r
017
MC/DC50%1/2
not ref $element->{"type"} and _valid_nested_type($element->{"type"})
not ref $element->{"type"} _valid_nested_type($element->{"type"})
Truth table66%2/3
not(A) and B
A= not ref $element->{"type"}B= _valid_nested_type($element->{"type"})
ABresult
0X0
100
111
2859 croak("Object element schema for '$param' needs 'isa' or 'can'")
2860 7 ▶ if(($element->{type} eq 'object') && !defined($element->{isa}) && !defined($element->{can}));
Branch: 1 branch
BranchTrueFalseTotal
if $element->{"type"} eq "object" and not defined $element->{"isa"} and not defined $element->{"can"} 1 6 7
Condition83%5/6
$element->{"type"} eq "object" and not defined $element->{"isa"} and not defined $element->{"can"}
!ll&&!rl&&r
601
$element->{"type"} eq "object" and not defined $element->{"isa"}
!ll&&!rl&&r
511
MC/DC66%2/3
$element->{"type"} eq "object" and not defined $element->{"isa"} and not defined $element->{"can"}
$element->{"type"} eq "object" not defined $element->{"isa"} not defined $element->{"can"}
Truth table75%3/4
A and not(B) and not(C)
A= $element->{"type"} eq "object"B= not defined $element->{"isa"}C= not defined $element->{"can"}
ABCresult
0XX0
10X0
1100
1111
2861  
2862 6 ▶ if(($element->{type} eq 'arrayref') || ($element->{type} eq 'array')) {
Branch: 2 branches
BranchTrueFalseTotal
if ($element->{'type'} eq 'arrayref' or $element->{'type'} eq 'array') { } 1 5 6
elsif ($element->{'type'} eq 'hashref') { } 0 5 5
Condition66%2/3
$element->{"type"} eq "arrayref" or $element->{"type"} eq "array"
l!l&&r!l&&!r
105
MC/DC50%1/2
$element->{"type"} eq "arrayref" or $element->{"type"} eq "array"
$element->{"type"} eq "arrayref" $element->{"type"} eq "array"
Truth table66%2/3
A or B
A= $element->{"type"} eq "arrayref"B= $element->{"type"} eq "array"
ABresult
1X1
011
000
2863 # An array's elements can be hashes with fixed keys, just as a
2864 # hashref's values can: a type-less schema maps key names to specs.
2865 1 ▶ _validate_element_spec($element->{schema}, $param, 1) if defined($element->{schema});
Branch: 1 branch
BranchTrueFalseTotal
if defined $element->{"schema"} 1 0 1
2866 } elsif($element->{type} eq 'hashref') {
2867 0 ▶ _validate_element_spec($element->{schema}, $param, 1) if defined($element->{schema});
Branch: 1 branch
BranchTrueFalseTotal
if defined $element->{"schema"} 0 0 0
2868 }
2869 }
2870  
2871 9 ▶sub _valid_nested_type {
Subroutine _valid_nested_type: called CC=5 SCAR=19.4
2872 9 my ($type) = @_;
2873  
2874 9 ▶ return 0 unless defined($type) && !ref($type);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type and not ref $type 0 9 9
Condition33%1/3
defined $type and not ref $type
!ll&&!rl&&r
009
MC/DC0%0/2
defined $type and not ref $type
defined $type not ref $type
Truth table33%1/3
A and not(B)
A= defined $typeB= not ref $type
ABresult
0X0
100
111
2875 9 ▶ return 1 if($type eq 'array') || ($type eq 'coderef');
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "array" or $type eq "coderef" 0 9 9
Condition33%1/3
$type eq "array" or $type eq "coderef"
l!l&&r!l&&!r
009
MC/DC0%0/2
$type eq "array" or $type eq "coderef"
$type eq "array" $type eq "coderef"
Truth table33%1/3
A or B
A= $type eq "array"B= $type eq "coderef"
ABresult
1X1
011
000
2876 9 return _valid_type($type);
2877 }
2878  
2879 317 ▶sub _validate_input_params {
Subroutine _validate_input_params: called CC=21 SCAR=30.8
2880 317 my $schema = $_[0];
2881  
2882 317 for my $param (keys %{$schema->{input}}) {
2883 # Catch empty parameter names — these would produce
2884 # broken Perl variable names in the generated test
2885 415 ▶ croak 'Empty input parameter name'
Branch: 1 branch
BranchTrueFalseTotal
unless length $param 1 414 415
2886 unless length($param);
2887  
2888 414 my $spec = $schema->{input}{$param};
2889  
2890 # A sampling ceiling is not a second maximum: it must sit inside
2891 # the documented range, or generated data would not be valid.
2892 414 ▶ if(ref($spec) eq 'HASH' && defined($spec->{sample_max})) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $spec eq "HASH" and defined $spec->{"sample_max"}) 3 411 414
Condition100%3/3
ref $spec eq "HASH" and defined $spec->{"sample_max"}
!ll&&!rl&&r
533583
MC/DC100%2/2
ref $spec eq "HASH" and defined $spec->{"sample_max"}
ref $spec eq "HASH" defined $spec->{"sample_max"}
Truth table100%3/3
A and B
A= ref $spec eq "HASH"B= defined $spec->{"sample_max"}
ABresult
0X0
100
111
2893 croak("sample_max for parameter '$param' must be a non-negative number")
2894 3 ▶ unless !ref($spec->{sample_max}) && ($spec->{sample_max} =~ /\A\d+(?:\.\d+)?\z/);
Branch: 1 branch
BranchTrueFalseTotal
unless not ref $spec->{"sample_max"} and $spec->{"sample_max"} =~ /\A\d+(?:\.\d+)?\z/u 0 3 3
Condition33%1/3
not ref $spec->{"sample_max"} and $spec->{"sample_max"} =~ /\A\d+(?:\.\d+)?\z/u
!ll&&!rl&&r
003
MC/DC0%0/2
not ref $spec->{"sample_max"} and $spec->{"sample_max"} =~ /\A\d+(?:\.\d+)?\z/u
not ref $spec->{"sample_max"} $spec->{"sample_max"} =~ /\A\d+(?:\.\d+)?\z/u
Truth table33%1/3
not(A) and B
A= not ref $spec->{"sample_max"}B= $spec->{"sample_max"} =~ /\A\d+(?:\.\d+)?\z/u
ABresult
0X0
100
111
2895 croak("sample_max for parameter '$param' is above max")
2896 3 ▶ if defined($spec->{max}) && ($spec->{sample_max} > $spec->{max});
Branch: 1 branch
BranchTrueFalseTotal
if defined $spec->{"max"} and $spec->{"sample_max"} > $spec->{"max"} 1 2 3
Condition66%2/3
defined $spec->{"max"} and $spec->{"sample_max"} > $spec->{"max"}
!ll&&!rl&&r
021
MC/DC50%1/2
defined $spec->{"max"} and $spec->{"sample_max"} > $spec->{"max"}
defined $spec->{"max"} $spec->{"sample_max"} > $spec->{"max"}
Truth table66%2/3
A and B
A= defined $spec->{"max"}B= $spec->{"sample_max"} > $spec->{"max"}
ABresult
0X0
100
111
2897 croak("sample_max for parameter '$param' is below min")
2898 2 ▶ if defined($spec->{min}) && ($spec->{sample_max} < $spec->{min});
Branch: 1 branch
BranchTrueFalseTotal
if defined $spec->{"min"} and $spec->{"sample_max"} < $spec->{"min"} 1 1 2
Condition66%2/3
defined $spec->{"min"} and $spec->{"sample_max"} < $spec->{"min"}
!ll&&!rl&&r
011
MC/DC50%1/2
defined $spec->{"min"} and $spec->{"sample_max"} < $spec->{"min"}
defined $spec->{"min"} $spec->{"sample_max"} < $spec->{"min"}
Truth table66%2/3
A and B
A= defined $spec->{"min"}B= $spec->{"sample_max"} < $spec->{"min"}
ABresult
0X0
100
111
2899 }
2900  
2901 # Validate the type field — required for all parameters
2902 412 ▶ if(ref($spec)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $spec) { } 359 53 412
2903 croak("Missing type for parameter '$param'")
2904 359 ▶ unless defined $spec->{type};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $spec->{"type"} 1 358 359
2905 # 'coderef' is a SchemaExtractor-specific type, not one of the
2906 # schema's value types: the harness satisfies it with a no-op
2907 # coderef rather than generating values for it.
2908 358 ▶ next if $spec->{type} eq 'coderef';
Branch: 1 branch
BranchTrueFalseTotal
if $spec->{"type"} eq "coderef" 4 354 358
2909 croak("Invalid type '$spec->{type}' for parameter '$param'")
2910 354 ▶ unless _valid_type($spec->{type});
Branch: 1 branch
BranchTrueFalseTotal
unless _valid_type($spec->{"type"}) 2 352 354
2911  
2912 352 ▶ if(($spec->{type} eq 'arrayref') || ($spec->{type} eq 'array')) {
Branch: 2 branches
BranchTrueFalseTotal
if ($spec->{'type'} eq 'arrayref' or $spec->{'type'} eq 'array') { } 15 337 352
elsif ($spec->{'type'} eq 'hashref') { } 54 283 337
Condition66%2/3
$spec->{"type"} eq "arrayref" or $spec->{"type"} eq "array"
l!l&&r!l&&!r
150337
MC/DC50%1/2
$spec->{"type"} eq "arrayref" or $spec->{"type"} eq "array"
$spec->{"type"} eq "arrayref" $spec->{"type"} eq "array"
Truth table66%2/3
A or B
A= $spec->{"type"} eq "arrayref"B= $spec->{"type"} eq "array"
ABresult
1X1
011
000
2913 15 ▶ _validate_element_spec($spec->{schema}, $param, 1) if defined($spec->{schema});
Branch: 1 branch
BranchTrueFalseTotal
if defined $spec->{"schema"} 5 10 15
2914 } elsif($spec->{type} eq 'hashref') {
2915 54 ▶ _validate_element_spec($spec->{schema}, $param, 1) if defined($spec->{schema});
Branch: 1 branch
BranchTrueFalseTotal
if defined $spec->{"schema"} 2 52 54
2916 }
2917 } else {
2918 53 ▶ croak("Invalid type '$spec' for parameter '$param'")
Branch: 1 branch
BranchTrueFalseTotal
unless _valid_type($spec) 0 53 53
2919 unless _valid_type($spec);
2920 }
2921 }
2922 }
2923  
2924 # --------------------------------------------------
2925 # _validate_input_positions
2926 #
2927 # Purpose: Validate positional argument declarations
2928 # in the input schema — positions must be
2929 # non-negative integers with no duplicates,
2930 # and either all or no parameters must have
2931 # positions.
2932 #
2933 # Entry: $schema - the full parsed schema hashref.
2934 # $schema->{input} must be a hashref.
2935 #
2936 # Exit: Returns nothing. Croaks on invalid or
2937 # duplicate positions. Carps on gaps.
2938 # --------------------------------------------------
2939 318 ▶sub _validate_input_positions {
Subroutine _validate_input_positions: called CC=14 SCAR=26.4
2940 318 my $schema = $_[0];
2941  
2942 318 my $has_positions = 0;
2943 318 my %positions;
2944  
2945 318 for my $param (keys %{$schema->{input}}) {
2946 424 my $spec = $schema->{input}{$param};
2947  
2948 # Only process params that explicitly declare a position
2949 424 ▶ next unless ref($spec) eq 'HASH' && defined($spec->{position});
Branch: 1 branch
BranchTrueFalseTotal
unless ref $spec eq "HASH" and defined $spec->{"position"} 183 241 424
Condition100%3/3
ref $spec eq "HASH" and defined $spec->{"position"}
!ll&&!rl&&r
53130241
MC/DC100%2/2
ref $spec eq "HASH" and defined $spec->{"position"}
ref $spec eq "HASH" defined $spec->{"position"}
Truth table100%3/3
A and B
A= ref $spec eq "HASH"B= defined $spec->{"position"}
ABresult
0X0
100
111
2950  
2951 241 $has_positions = 1;
2952 241 my $pos = $spec->{position};
2953  
2954 # Position must be a non-negative integer
2955 241 ▶ croak "Position for '$param' must be a non-negative integer"
Branch: 1 branch
BranchTrueFalseTotal
unless $pos =~ /^\d+$/u 1 240 241
2956 unless $pos =~ /^\d+$/;
2957  
2958 # Duplicate positions would produce ambiguous generated tests
2959 croak "Duplicate position $pos for parameters '$positions{$pos}' and '$param'"
2960 240 ▶ if exists $positions{$pos};
Branch: 1 branch
BranchTrueFalseTotal
if exists $positions{$pos} 2 238 240
2961  
2962 238 $positions{$pos} = $param;
2963 }
2964  
2965 # If any param has a position, the rest are named options passed after
2966 # the positional arguments (sub f { my ($x, %opts) = @_ }), and each must
2967 # say so: an omission is otherwise a forgotten position, which would be
2968 # called by name and test nothing.
2969 315 ▶ if($has_positions) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has_positions) 206 109 315
2970 206 for my $param (keys %{$schema->{input}}) {
2971 239 my $spec = $schema->{input}{$param};
2972 239 ▶ next if(ref($spec) eq 'HASH' && defined($spec->{position}));
Branch: 1 branch
BranchTrueFalseTotal
if ref $spec eq "HASH" and defined $spec->{"position"} 234 5 239
Condition66%2/3
ref $spec eq "HASH" and defined $spec->{"position"}
!ll&&!rl&&r
05234
MC/DC50%1/2
ref $spec eq "HASH" and defined $spec->{"position"}
ref $spec eq "HASH" defined $spec->{"position"}
Truth table66%2/3
A and B
A= ref $spec eq "HASH"B= defined $spec->{"position"}
ABresult
0X0
100
111
2973 croak "Parameter '$param' missing position " .
2974 '(give it one, or named: 1 for a trailing named option)'
2975 5 ▶ unless(ref($spec) eq 'HASH' && $spec->{named});
Branch: 1 branch
BranchTrueFalseTotal
unless ref $spec eq "HASH" and $spec->{"named"} 2 3 5
Condition66%2/3
ref $spec eq "HASH" and $spec->{"named"}
!ll&&!rl&&r
023
MC/DC50%1/2
ref $spec eq "HASH" and $spec->{"named"}
ref $spec eq "HASH" $spec->{"named"}
Truth table66%2/3
A and B
A= ref $spec eq "HASH"B= $spec->{"named"}
ABresult
0X0
100
111
2976 }
2977  
2978 # Check for gaps — positions must be a contiguous sequence
2979 # starting at 0, otherwise the generated test will be wrong
2980 204 my @sorted = sort { $a <=> $b } keys %positions;
2981 204 for my $i (0 .. $#sorted) {
2982 234 ▶ if($sorted[$i] != $i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sorted[$i] != $i) 1 233 234
2983 1 carp "Position sequence has gaps (positions: @sorted)";
2984 1 last;
2985 }
2986 }
2987 }
2988 }
2989  
2990 # --------------------------------------------------
2991 # _validate_input_semantics
2992 #
2993 # Purpose: Validate semantic type annotations and
2994 # enum/memberof constraints on input params.
2995 #
2996 # Entry: $schema - the full parsed schema hashref.
2997 # $schema->{input} must be a hashref.
2998 #
2999 # Exit: Returns nothing. Croaks on conflicting
3000 # or malformed enum/memberof. Carps on
3001 # unknown semantic types.
3002 # --------------------------------------------------
3003 319 ▶sub _validate_input_semantics {
Subroutine _validate_input_semantics: called CC=10 SCAR=23.0
3004 319 my $schema = $_[0];
3005  
3006 319 my $semantic_generators = _get_semantic_generators();
3007  
3008 319 for my $param (keys %{$schema->{input}}) {
3009 416 my $spec = $schema->{input}{$param};
3010 416 ▶ next unless ref($spec) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $spec eq "HASH" 54 362 416
3011  
3012 # Warn on unknown semantic types rather than croaking —
3013 # new semantic types may be added without updating this list
3014 362 ▶ if(defined($spec->{semantic})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $spec->{"semantic"}) 13 349 362
3015 13 my $semantic = $spec->{semantic};
3016 13 ▶ unless(exists $semantic_generators->{$semantic}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $semantic_generators->{$semantic}) 2 11 13
3017 carp "Unknown semantic type '$semantic' for parameter '$param'. " .
3018 'Available types: ' .
3019 2 join(', ', sort keys %{$semantic_generators});
3020 }
3021 }
3022  
3023 # enum and memberof are mutually exclusive representations
3024 # of the same concept — having both is always a schema error
3025 362 ▶ if($spec->{'enum'} && $spec->{'memberof'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($spec->{"enum"} and $spec->{"memberof"}) 2 360 362
Condition100%3/3
$spec->{"enum"} and $spec->{"memberof"}
!ll&&!rl&&r
35552
MC/DC100%2/2
$spec->{"enum"} and $spec->{"memberof"}
$spec->{"enum"} $spec->{"memberof"}
Truth table100%3/3
A and B
A= $spec->{"enum"}B= $spec->{"memberof"}
ABresult
0X0
100
111
3026 2 croak "$param: has both enum and memberof";
3027 }
3028  
3029 # Both enum and memberof must be arrayrefs when present
3030 360 for my $type ('enum', 'memberof') {
3031 719 ▶ if(exists $spec->{$type}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $spec->{$type}) 20 699 719
3032 croak "$type must be an arrayref"
3033 20 ▶ unless ref($spec->{$type}) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $spec->{$type} eq "ARRAY" 3 17 20
3034 }
3035 }
3036 }
3037 }
3038  
3039 # --------------------------------------------------
3040 # _validate_transform_properties
3041 #
3042 # Purpose: Validate the properties array in each
3043 # transform definition, checking that each
3044 # property is either a known builtin name
3045 # or a custom hashref with name and code.
3046 #
3047 # Entry: $schema - the full parsed schema hashref.
3048 # $schema->{transforms} must be a hashref.
3049 #
3050 # Exit: Returns nothing. Croaks on invalid property
3051 # definitions. Carps on unknown builtins.
3052 # --------------------------------------------------
3053 21 ▶sub _validate_transform_properties {
Subroutine _validate_transform_properties: called CC=10 SCAR=23.0
3054 21 my $schema = $_[0];
3055  
3056 21 my $builtin_props = _get_builtin_properties();
3057  
3058 21 for my $transform_name (keys %{$schema->{transforms}}) {
3059 19 my $transform = $schema->{transforms}{$transform_name};
3060  
3061 # properties is optional — skip transforms that don't define it
3062 19 ▶ next unless exists $transform->{properties};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $transform->{"properties"} 13 6 19
3063  
3064 croak "Transform '$transform_name': properties must be an array"
3065 6 ▶ unless ref($transform->{properties}) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $transform->{"properties"} eq "ARRAY" 1 5 6
3066  
3067 5 for my $prop (@{$transform->{properties}}) {
3068 5 ▶ if(!ref($prop)) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $prop) { } 2 3 5
elsif (ref $prop eq 'HASH') { } 2 1 3
3069 # Plain string — must be a known builtin property name
3070 2 ▶ unless(exists $builtin_props->{$prop}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $builtin_props->{$prop}) 1 1 2
3071 carp "Transform '$transform_name': unknown built-in property '$prop'. " .
3072 'Available: ' .
3073 1 join(', ', sort keys %{$builtin_props});
3074 }
3075 } elsif(ref($prop) eq 'HASH') {
3076 # Custom property — must have both name and code fields
3077 2 ▶ unless($prop->{name} && $prop->{code}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($prop->{"name"} and $prop->{"code"}) 1 1 2
Condition66%2/3
$prop->{"name"} and $prop->{"code"}
!ll&&!rl&&r
011
MC/DC50%1/2
$prop->{"name"} and $prop->{"code"}
$prop->{"name"} $prop->{"code"}
Truth table66%2/3
A and B
A= $prop->{"name"}B= $prop->{"code"}
ABresult
0X0
100
111
3078 1 croak "Transform '$transform_name': " .
3079 "custom properties must have 'name' and 'code' fields";
3080 }
3081 } else {
3082 1 croak "Transform '$transform_name': invalid property definition";
3083 }
3084 }
3085 }
3086 }
3087  
3088 # --------------------------------------------------
3089 # _normalize_config
3090 #
3091 # Purpose: Normalise boolean string values in the
3092 # config sub-hash to Perl integers (1/0),
3093 # and default absent boolean fields to 1
3094 # (enabled). The 'properties' field is a
3095 # hashref not a boolean and is handled
3096 # separately.
3097 #
3098 # Entry: $config - the config sub-hash extracted
3099 # from the schema (i.e. $schema->{config}).
3100 # May be empty.
3101 #
3102 # Exit: Returns nothing. Modifies $config in place.
3103 #
3104 # Side effects: Modifies the caller's config hashref.
3105 #
3106 # Notes: String-to-boolean conversion is delegated
3107 # to %Readonly::Values::Boolean::booleans
3108 # which handles 'yes'/'no', 'on'/'off',
3109 # 'true'/'false' etc. Fields not present in
3110 # the config hash are defaulted to 1 so
3111 # that test generation is maximally thorough
3112 # unless the schema explicitly disables a
3113 # feature.
3114 # --------------------------------------------------
3115 437 ▶sub _normalize_config {
Subroutine _normalize_config: called CC=8 SCAR=20.8
3116 437 my $config = $_[0];
3117  
3118 437 for my $field (keys %VALID_CONFIG_KEYS) {
3119 # Non-boolean fields are handled separately
3120 5681 ▶ next if $field eq $CONFIG_PROPERTIES_KEY;
Branch: 1 branch
BranchTrueFalseTotal
if $field eq $CONFIG_PROPERTIES_KEY 437 5244 5681
3121 5244 ▶ next if $field eq 'timeout'; # numeric, not boolean; absence means use generated-test default
Branch: 1 branch
BranchTrueFalseTotal
if $field eq "timeout" 437 4807 5244
3122  
3123 4807 ▶ if(exists($config->{$field}) && defined($config->{$field})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $config->{$field} and defined $config->{$field}) { } 2982 1825 4807
Condition100%3/3
exists $config->{$field} and defined $config->{$field}
!ll&&!rl&&r
182412982
MC/DC100%2/2
exists $config->{$field} and defined $config->{$field}
exists $config->{$field} defined $config->{$field}
Truth table100%3/3
A and B
A= exists $config->{$field}B= defined $config->{$field}
ABresult
0X0
100
111
3124 # Convert string boolean representations to integers
3125 # using the lookup table from Readonly::Values::Boolean
3126 2982 ▶ if(defined(my $b = $Readonly::Values::Boolean::booleans{$config->{$field}})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $b = $Readonly::Values::Boolean::booleans{$config->{$field}})) 2982 0 2982
3127 2982 $config->{$field} = $b;
3128 }
3129 } else {
3130 # Default absent boolean fields to enabled (1) so that
3131 # test generation is comprehensive unless explicitly disabled
3132 1825 $config->{$field} = 1;
3133 }
3134 }
3135  
3136 # Ensure properties is always a hashref — if absent or set to
3137 # a non-hash value, replace with a disabled default so that
3138 # downstream code can safely dereference it without checking ref()
3139 437 ▶ $config->{$CONFIG_PROPERTIES_KEY} = { enable => 0 } unless ref($config->{$CONFIG_PROPERTIES_KEY}) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $config->{$CONFIG_PROPERTIES_KEY} eq "HASH" 357 80 437
3140 }
3141  
3142 # --------------------------------------------------
3143 # _valid_type
3144 #
3145 # Determine whether a string is a
3146 # recognised schema field type accepted
3147 # by the generator.
3148 #
3149 # Entry: $type - the type string to validate.
3150 # May be undef.
3151 #
3152 # Exit: Returns 1 if the type is known,
3153 # 0 if the type is unknown or undef.
3154 #
3155 # Notes: The lookup hash is declared with
3156 # 'state' so it is built only once per
3157 # process rather than on every call —
3158 # important since _valid_type is called
3159 # in a loop over all input parameters.
3160 #
3161 # 'int' and 'bool' are accepted as
3162 # aliases for 'integer' and 'boolean'
3163 # respectively, for compatibility with
3164 # schemas generated by external tools
3165 # that use the shorter forms.
3166 # --------------------------------------------------
3167 477 ▶sub _valid_type {
Subroutine _valid_type: called CC=3 SCAR=11.0
3168 477 my $type = $_[0];
3169  
3170 # Undef is never a valid type
3171 477 ▶ return 0 unless defined($type);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type 3 474 477
3172  
3173 # Build the lookup table once and cache it for
3174 # the lifetime of the process via 'state'
3175 474 state %VALID = map { $_ => 1 } qw(
3176 string boolean integer number float
3177 hashref arrayref object int bool any
3178 );
3179  
3180 474 ▶ return($VALID{$type} // 0);
Condition100%2/2
$VALID{$type} // 0
l!l
45519
MC/DC100%1/1
$VALID{$type} // 0
$VALID{$type}
Truth table100%2/2
A
A= $VALID{$type}
Aresult
11
00
3181 }
3182  
3183 # --------------------------------------------------
3184 # _assert_identifier
3185 #
3186 # Purpose: Validate that a string is shaped like a
3187 # plain Perl identifier (or, with
3188 # package => 1, a "::"-separated package
3189 # name) before it is spliced into generated
3190 # test source as a bareword, package name,
3191 # method name, or variable name rather than
3192 # a quoted string literal. Schema-derived
3193 # names (module, function, transform names)
3194 # are spliced unescaped at the call sites
3195 # that use this guard, so an unvalidated
3196 # name could otherwise break out of the
3197 # generated source and inject arbitrary
3198 # Perl into a file that L<prove> will run.
3199 #
3200 # Entry: $name - the string to validate.
3201 # $what - short label for the value, used
3202 # only in the croak message.
3203 # %opts - package => 1 allows "::"
3204 # separators in $name.
3205 #
3206 # Exit: Returns $name unchanged on success.
3207 # Croaks if $name is not identifier-shaped.
3208 # --------------------------------------------------
3209 838 ▶sub _assert_identifier {
Subroutine _assert_identifier: called CC=5 SCAR=16.1
3210 838 my ($name, $what, %opts) = @_;
3211  
3212 838 ▶ croak(__PACKAGE__, ": $what is missing or empty")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name and length $name 2 836 838
Condition100%3/3
defined $name and length $name
!ll&&!rl&&r
11836
MC/DC100%2/2
defined $name and length $name
defined $name length $name
Truth table100%3/3
A and B
A= defined $nameB= length $name
ABresult
0X0
100
111
3213 unless defined($name) && length($name);
3214  
3215 my $re = $opts{package}
3216 836 ▶ ? qr/^[A-Za-z_]\w*(?:::[A-Za-z_]\w*)*\z/
Branch: 1 branch
BranchTrueFalseTotal
$opts{'package'} ? : 805 31 836
3217 : qr/^[A-Za-z_]\w*\z/;
3218  
3219 836 ▶ croak(__PACKAGE__, ": $what '$name' is not a valid Perl identifier")
Branch: 1 branch
BranchTrueFalseTotal
unless $name =~ /$re/u 10 826 836
3220 unless $name =~ $re;
3221  
3222 826 return $name;
3223 }
3224  
3225 # --------------------------------------------------
3226 # _validate_module
3227 #
3228 # Purpose: Check whether the module named in a
3229 # schema can be found in @INC during
3230 # test generation. Optionally also
3231 # attempts to load it if the
3232 # GENERATOR_VALIDATE_LOAD environment
3233 # variable is set.
3234 #
3235 # Entry: $module - the module name to
3236 # check. If undef or
3237 # empty, returns 1
3238 # immediately (builtin
3239 # functions need no
3240 # module).
3241 # $schema_file - path to the schema
3242 # file, used in warning
3243 # messages only.
3244 #
3245 # Exit: Returns 1 if the module was found
3246 # (and loaded, if validation was
3247 # requested).
3248 # Returns 0 if the module was not
3249 # found or failed to load — this is
3250 # non-fatal; generation continues.
3251 # Returns 1 immediately for undef or
3252 # empty $module.
3253 #
3254 # Side effects: Prints to STDERR when TEST_VERBOSE
3255 # or GENERATOR_VERBOSE is set.
3256 # Carps (non-fatally) when the module
3257 # cannot be found or loaded.
3258 # May attempt to load the module into
3259 # the current process when
3260 # GENERATOR_VALIDATE_LOAD is set —
3261 # this can have side effects depending
3262 # on the module.
3263 #
3264 # Notes: Not finding a module during generation
3265 # is intentionally non-fatal — the module
3266 # may be available on the target machine
3267 # even if not on the generation machine.
3268 # Verbose output goes to STDERR via
3269 # print rather than carp since it is
3270 # informational, not a warning.
3271 # --------------------------------------------------
3272 377 ▶sub _validate_module {
Subroutine _validate_module: called CC=13 SCAR=32.9
3273 377 my ($module, $schema_file) = @_;
3274  
3275 # Builtin functions have no module to validate
3276 377 ▶ return 1 unless $module;
Branch: 1 branch
BranchTrueFalseTotal
unless $module 2 375 377
3277  
3278 # Check whether the module is findable in @INC
3279 375 my $mod_info = check_install(module => $module);
3280  
3281 375 ▶ if($schema_file && !$mod_info) {
Branch: 1 branch
BranchTrueFalseTotal
if ($schema_file and not $mod_info) 21 354 375
Condition100%3/3
$schema_file and not $mod_info
!ll&&!rl&&r
2732721
MC/DC100%2/2
$schema_file and not $mod_info
$schema_file not $mod_info
Truth table100%3/3
A and not(B)
A= $schema_fileB= not $mod_info
ABresult
0X0
100
111
3282 # Non-fatal — emit a single consolidated warning so
3283 # the caller sees one message rather than four
3284 21 carp(
3285 "Module '$module' not found in \@INC during generation.\n" .
3286 " Config file: $schema_file\n" .
3287 " This is OK if the module will be available when tests run.\n" .
3288 ' If unexpected, check your module name and installation.'
3289 );
3290 21 return 0;
3291 }
3292  
3293 # Check once and reuse — avoids evaluating two env vars twice
3294 354 ▶ my $verbose = $ENV{$ENV_TEST_VERBOSE} || $ENV{$ENV_GENERATOR_VERBOSE};
Condition33%1/3
$ENV{$ENV_TEST_VERBOSE} || $ENV{$ENV_GENERATOR_VERBOSE}
l!l&&r!l&&!r
00354
MC/DC0%0/2
$ENV{$ENV_TEST_VERBOSE} || $ENV{$ENV_GENERATOR_VERBOSE}
$ENV{$ENV_TEST_VERBOSE} $ENV{$ENV_GENERATOR_VERBOSE}
Truth table33%1/3
A || B
A= $ENV{$ENV_TEST_VERBOSE}B= $ENV{$ENV_GENERATOR_VERBOSE}
ABresult
1X1
011
000
3295  
3296 354 ▶ if($verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose) 0 354 354
3297 # check_install() returns undef when the module is not in @INC, which
3298 # is normal for a schema whose module only exists when the tests run
3299 # (and when no schema file was given, the miss is not reported
3300 # above). Never read a location from a missing result: it would be
3301 # concatenated as an undefined value.
3302 0 ▶ if($mod_info) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mod_info) { } 0 0 0
3303 carp "Found module '$module' at: " .
3304 ($mod_info->{'file'} // 'an unknown location') .
3305 0 ▶ ' (version ' . ($mod_info->{'version'} || 'unknown') . ')';
Condition0%0/4
$mod_info->{"file"} // "an unknown location"
l!l
00
$mod_info->{'version'} || 'unknown'
l!l
00
MC/DC0%0/1
$mod_info->{"file"} // "an unknown location"
$mod_info->{"file"}
MC/DC0%0/1
$mod_info->{'version'} || 'unknown'
$mod_info->{'version'}
Truth table0%0/2
A
A= $mod_info->{"file"}
Aresult
11
00
Truth table0%0/2
A
A= $mod_info->{'version'}
Aresult
11
00
3306 } else {
3307 0 carp "Module '$module' is not in \@INC during generation; " .
3308 'continuing (it may be available when the tests run)';
3309 }
3310 }
3311  
3312 # Optional load validation — disabled by default because
3313 # loading a module can have side effects (e.g. BEGIN blocks,
3314 # database connections, file I/O) that are undesirable
3315 # during generation
3316 354 ▶ if($ENV{$ENV_VALIDATE_LOAD}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{$ENV_VALIDATE_LOAD}) 1 353 354
3317 1 my $loaded = can_load(modules => { $module => undef }, verbose => 0);
3318  
3319 1 ▶ if(!$loaded) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($loaded) 0 1 1
3320 0 ▶ my $err = $Module::Load::Conditional::ERROR || 'unknown error';
Condition0%0/2
$Module::Load::Conditional::ERROR || 'unknown error'
l!l
00
MC/DC0%0/1
$Module::Load::Conditional::ERROR || 'unknown error'
$Module::Load::Conditional::ERROR
Truth table0%0/2
A
A= $Module::Load::Conditional::ERROR
Aresult
11
00
3321 0 carp(
3322 "Module '$module' found but failed to load: $err\n" .
3323 ' This might indicate a broken installation or missing dependencies.'
3324 );
3325 0 return 0;
3326 }
3327  
3328 1 ▶ if($verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose) 0 1 1
3329 0 carp "Successfully loaded module '$module'";
3330 }
3331 }
3332  
3333 354 return 1;
3334 }
3335  
3336 =head2 render_fallback
3337  
3338 Render any Perl value into a compact Perl source-code string using
3339 L<Data::Dumper>. Used as a catch-all when no more specific renderer
3340 applies.
3341  
3342 my $code = render_fallback({ key => 'value' });
3343 # returns: "{'key' => 'value'}"
3344  
3345 =head3 Arguments
3346  
3347 =over 4
3348  
3349 =item * C<$v>
3350  
3351 Any Perl value, including undef, scalars, refs, and blessed objects.
3352  
3353 =back
3354  
3355 =head3 Returns
3356  
3357 A string of Perl source code that reproduces the value when evaluated.
3358 Returns the string C<'undef'> when C<$v> is undef.
3359  
3360 =head3 Side effects
3361  
3362 Temporarily sets C<$Data::Dumper::Terse> and C<$Data::Dumper::Indent>
3363 to produce compact single-line output. Both are restored on return via
3364 C<local>.
3365  
3366 =head3 Notes
3367  
3368 The output is always a single line with no trailing newline. Suitable
3369 for embedding in generated test code where readability is secondary to
3370 correctness.
3371  
3372 =head3 API SPECIFICATION
3373  
3374 =head4 input
3375  
3376 { v => { type => 'any', optional => 1 } }
3377  
3378 =head4 output
3379  
3380 { type => 'string' }
3381  
3382 The mathematical description is in L</FORMAL SPECIFICATION>.
3383  
3384 =cut
3385  
3386 85 ▶sub render_fallback {
Subroutine render_fallback: called CC=2 SCAR=6.9
Pod documented
3387 85 my $v = $_[0];
3388  
3389 # Handle undef explicitly rather than letting Dumper produce
3390 # 'undef' without the localised settings applied
3391 85 ▶ return 'undef' unless defined $v;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 14 71 85
3392  
3393 # Use Terse+Indent=0 to produce compact single-line output
3394 # suitable for embedding in generated test code
3395 71 local $Data::Dumper::Terse = 1;
3396 71 local $Data::Dumper::Indent = 0;
3397  
3398 71 my $s = Dumper($v);
3399  
3400 # Remove trailing newline that Dumper always appends
3401 71 chomp $s;
3402 71 return $s;
3403 }
3404  
3405 =head2 render_hash
3406  
3407 Render a two-level hashref (parameter name => spec hashref) into Perl
3408 source code suitable for embedding in a generated test file as the
3409 input specification passed to L<Params::Validate::Strict>.
3410  
3411 my $code = render_hash(\%input);
3412  
3413 =head3 Arguments
3414  
3415 =over 4
3416  
3417 =item * C<$href>
3418  
3419 A hashref whose values are themselves hashrefs containing field
3420 specifications. A scalar value that is a recognised type string (see
3421 C<_valid_type>) is expanded to C<{ type =E<gt> $value }>. Any other
3422 non-hashref value is skipped with a warning.
3423  
3424 =back
3425  
3426 =head3 Returns
3427  
3428 A string of comma-separated Perl source-code lines, one per key, of
3429 the form:
3430  
3431 'key' => { subkey => value, ... }
3432  
3433 Returns an empty string if C<$href> is undef, empty, or not a hashref.
3434  
3435 =head3 Notes
3436  
3437 The C<matches> and C<nomatch> sub-keys are treated specially - their
3438 values are compiled to C<Regexp> objects via C<eval { qr/.../ }> and
3439 then rendered using C<perl_quote> so they appear as C<qr{...}> in the
3440 generated test. This prevents unmatched bracket characters in the
3441 pattern from causing compilation failures.
3442  
3443 Other sub-keys are rendered via C<perl_quote>.
3444  
3445 =head3 API SPECIFICATION
3446  
3447 =head4 input
3448  
3449 { href => { type => 'any', optional => 1 } }
3450  
3451 =head4 output
3452  
3453 { type => 'string' }
3454  
3455 The mathematical description is in L</FORMAL SPECIFICATION>.
3456  
3457 =cut
3458  
3459 # Render a nested hashref of scalars (and further hashrefs) as Perl source.
3460 # _constraint_source is such a map: constraint name => provenance.
3461 61 ▶sub _render_nested_hash {
Subroutine _render_nested_hash: called CC=4 SCAR=13.9
3462 61 my ($href) = @_;
3463  
3464 61 my @pairs;
3465 61 foreach my $key (sort keys %{$href}) {
3466 97 my $value = $href->{$key};
3467 97 ▶ next unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 97 97
3468 97 ▶ push @pairs, perl_quote($key) . ' => ' . (ref($value) eq 'HASH'
Branch: 1 branch
BranchTrueFalseTotal
ref $value eq 'HASH' ? : 2 95 97
3469 ? _render_nested_hash($value)
3470 : perl_quote($value));
3471 }
3472  
3473 61 return '{ ' . join(', ', @pairs) . ' }';
3474 }
3475  
3476 403 ▶sub render_hash {
Subroutine render_hash: called CC=21 SCAR=31.3
Pod documented
3477 403 my $href = $_[0];
3478  
3479 # Return empty string for absent or non-hash input — callers
3480 # treat '' as "no input specification" in the generated test
3481 403 ▶ return '' unless $href && ref($href) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless $href and ref $href eq "HASH" 13 390 403
Condition100%3/3
$href and ref $href eq "HASH"
!ll&&!rl&&r
310390
MC/DC100%2/2
$href and ref $href eq "HASH"
$href ref $href eq "HASH"
Truth table100%3/3
A and B
A= $hrefB= ref $href eq "HASH"
ABresult
0X0
100
111
3482  
3483 390 my @lines;
3484  
3485 390 for my $k (sort keys %{$href}) {
3486 359 my $def = $href->{$k};
3487  
3488 # Handle scalar shorthand — 'arg1: string' is equivalent to
3489 # 'arg1: { type: string }' and is explicitly supported by the
3490 # validation layer in _validate_input_params
3491 359 ▶ unless(defined($def) && ref($def) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $def and ref $def eq "HASH") 6 353 359
Condition66%2/3
defined $def and ref $def eq "HASH"
!ll&&!rl&&r
06353
MC/DC50%1/2
defined $def and ref $def eq "HASH"
defined $def ref $def eq "HASH"
Truth table66%2/3
A and B
A= defined $defB= ref $def eq "HASH"
ABresult
0X0
100
111
3492 6 ▶ if(defined($def) && !ref($def) && _valid_type($def)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $def and not ref $def and _valid_type($def)) { } 4 2 6
Condition50%3/6
defined $def and not ref $def and _valid_type($def)
!ll&&!rl&&r
024
defined $def and not ref $def
!ll&&!rl&&r
006
MC/DC33%1/3
defined $def and not ref $def and _valid_type($def)
defined $def not ref $def _valid_type($def)
Truth table50%2/4
A and not(B) and C
A= defined $defB= not ref $defC= _valid_type($def)
ABCresult
0XX0
10X0
1100
1111
3493 # Expand scalar type shorthand to a full spec hashref
3494 4 $def = { type => $def };
3495 } else {
3496 2 carp "render_hash: skipping key '$k' — value is not a hashref or recognised type string";
3497 2 next;
3498 }
3499 }
3500  
3501 357 my @pairs;
3502  
3503 357 for my $subk (sort keys %{$def}) {
3504 # Skip undef sub-values — they contribute nothing to the spec
3505 1408 ▶ next unless defined $def->{$subk};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $def->{$subk} 1 1407 1408
3506  
3507 # Validate that reference types are ones we can render. A nested
3508 # hashref of scalars (such as _constraint_source) is rendered as a
3509 # nested Perl hash literal.
3510 1407 ▶ if(ref($def->{$subk})) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $def->{$subk}) 82 1325 1407
3511 82 ▶ unless((ref($def->{$subk}) eq 'ARRAY') ||
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $def->{$subk} eq "ARRAY" or ref $def->{$subk} eq "Regexp" or ref $def->{$subk} eq "HASH") 0 82 82
Condition83%5/6
ref $def->{$subk} eq "ARRAY" or ref $def->{$subk} eq "Regexp" or ref $def->{$subk} eq "HASH"
l!l&&r!l&&!r
23590
ref $def->{$subk} eq "ARRAY" or ref $def->{$subk} eq "Regexp"
l!l&&r!l&&!r
18559
MC/DC0%0/3
ref $def->{$subk} eq "ARRAY" or ref $def->{$subk} eq "Regexp" or ref $def->{$subk} eq "HASH"
ref $def->{$subk} eq "ARRAY" ref $def->{$subk} eq "Regexp" ref $def->{$subk} eq "HASH"
Truth table75%3/4
A or B or C
A= ref $def->{$subk} eq "ARRAY"B= ref $def->{$subk} eq "Regexp"C= ref $def->{$subk} eq "HASH"
ABCresult
1XX1
01X1
0011
0000
3512 (ref($def->{$subk}) eq 'Regexp') ||
3513 (ref($def->{$subk}) eq 'HASH')) {
3514 croak(
3515 __PACKAGE__,
3516 ": $subk is a nested element, not yet supported (",
3517 0 ref($def->{$subk}), ')'
3518 );
3519 }
3520 }
3521  
3522 # matches and nomatch values must be Regexp objects in the
3523 # generated test — compile raw strings safely via eval so
3524 # patterns containing [ or \ don't cause compile failures
3525 1407 ▶ if(($subk eq $KEY_MATCHES) || ($subk eq $KEY_NOMATCH)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($subk eq $KEY_MATCHES or $subk eq $KEY_NOMATCH) { } 23 1384 1407
elsif (ref $def->{$subk} eq 'HASH') { } 59 1325 1384
Condition100%3/3
$subk eq $KEY_MATCHES or $subk eq $KEY_NOMATCH
l!l&&r!l&&!r
2211384
MC/DC100%2/2
$subk eq $KEY_MATCHES or $subk eq $KEY_NOMATCH
$subk eq $KEY_MATCHES $subk eq $KEY_NOMATCH
Truth table100%3/3
A or B
A= $subk eq $KEY_MATCHESB= $subk eq $KEY_NOMATCH
ABresult
1X1
011
000
3526 my $re = ref($def->{$subk}) eq 'Regexp'
3527 ? $def->{$subk}
3528 23 ▶ : eval { qr/$def->{$subk}/ };
Branch: 1 branch
BranchTrueFalseTotal
ref $def->{$subk} eq 'Regexp' ? : 5 18 23
3529 23 ▶ if($@ || !defined($re)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@ or not defined $re) 0 23 23
Condition33%1/3
$@ or not defined $re
l!l&&r!l&&!r
0023
MC/DC0%0/2
$@ or not defined $re
$@ not defined $re
Truth table33%1/3
A or not(B)
A= $@B= not defined $re
ABresult
1X1
011
000
3530 0 carp "render_hash: invalid $subk pattern '$def->{$subk}': $@";
3531 0 next;
3532 }
3533 23 push @pairs, "$subk => " . perl_quote($re);
3534 } elsif(ref($def->{$subk}) eq 'HASH') {
3535 59 push @pairs, "$subk => " . _render_nested_hash($def->{$subk});
3536 } else {
3537 # All other sub-keys are rendered via perl_quote which
3538 # handles scalars, arrayrefs, and Regexp objects correctly
3539 1325 push @pairs, "$subk => " . perl_quote($def->{$subk});
3540 }
3541 }
3542  
3543 # Use "\t" rather than a literal tab for clarity and grep-ability
3544 357 push @lines, "\t" . perl_quote($k) . ' => { ' . join(', ', @pairs) . ' }';
3545 }
3546  
3547 390 return join(",\n", @lines);
3548 }
3549  
3550 =head2 render_args_hash
3551  
3552 Render a flat hashref into a Perl source-code argument list of the
3553 form C<'key' => value, ...>, suitable for embedding in a function call
3554 in a generated test file.
3555  
3556 my $code = render_args_hash({ type => 'string', min => 1 });
3557 # returns: "'min' => 1, 'type' => 'string'"
3558  
3559 =head3 Arguments
3560  
3561 =over 4
3562  
3563 =item * C<$href>
3564  
3565 A flat hashref of key-value pairs. Values may be scalars, arrayrefs,
3566 or Regexp objects - all are handled by C<perl_quote>.
3567  
3568 =back
3569  
3570 =head3 Returns
3571  
3572 A comma-separated string of C<key => value> pairs sorted by key.
3573 Returns an empty string if C<$href> is undef, empty, or not a hashref.
3574  
3575 =head3 Notes
3576  
3577 Keys and values are both rendered via C<perl_quote>. In particular,
3578 C<Regexp> values are rendered as C<qr{...}> which is correct for
3579 L<Params::Validate::Strict> and L<Return::Set> schema arguments in
3580 the generated test.
3581  
3582 =head3 API SPECIFICATION
3583  
3584 =head4 input
3585  
3586 { href => { type => 'any', optional => 1 } }
3587  
3588 =head4 output
3589  
3590 { type => 'string' }
3591  
3592 The mathematical description is in L</FORMAL SPECIFICATION>.
3593  
3594 =cut
3595  
3596 # --------------------------------------------------
3597 # _render_arg_value
3598 #
3599 # Purpose: Render one constructor argument. A marked path is replaced by a
3600 # temporary file or directory the generated test makes at run time,
3601 # so a constructor documented to take a directory can be called as
3602 # its POD says instead of being left unbuilt.
3603 #
3604 # Entry: $value - the schema value for the argument.
3605 #
3606 # Exit: Perl source for the argument.
3607 # --------------------------------------------------
3608 sub _render_arg_value
3609 627 ▶{
Subroutine _render_arg_value: called CC=8 SCAR=21.3
3610 627 my ($value) = @_;
3611  
3612 627 ▶ if(ref($value) eq 'HASH' && ($value->{'_path'} // '') =~ /^(?:file|directory)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value eq "HASH" and ($value->{"_path"} // "") =~ /^(?:file|directory)$/u) 1 626 627
Condition100%5/5
ref $value eq "HASH" and ($value->{"_path"} // "") =~ /^(?:file|directory)$/u
!ll&&!rl&&r
581451
$value->{"_path"} // ""
l!l
145
MC/DC100%2/2
ref $value eq "HASH" and ($value->{"_path"} // "") =~ /^(?:file|directory)$/u
ref $value eq "HASH" $value->{"_path"}
Truth table100%3/3
A and B
A= ref $value eq "HASH"B= $value->{"_path"}
ABresult
0X0
100
111
3613 return '(do { require File::Temp; File::Temp::tempdir(CLEANUP => 1) })'
3614 1 ▶ if $value->{'_path'} eq 'directory';
Branch: 1 branch
BranchTrueFalseTotal
if $value->{"_path"} eq "directory" 1 0 1
3615 0 return '(do { require File::Temp; my ($_fh, $_path) = File::Temp::tempfile(UNLINK => 1); close $_fh; $_path })';
3616 }
3617  
3618 # Render element by element: an element may be an object stand-in, which
3619 # perl_quote() would emit as the marker hashref rather than build.
3620 626 ▶ if(ref($value) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value eq "ARRAY") 1 625 626
3621 1 return '[ ' . join(', ', map { _render_arg_value($_) } @{$value}) . ' ]';
3622 }
3623  
3624 625 ▶ if(ref($value) eq 'HASH' && ref($value->{'_stub'}) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value eq "HASH" and ref $value->{"_stub"} eq "HASH") 0 625 625
Condition66%2/3
ref $value eq "HASH" and ref $value->{"_stub"} eq "HASH"
!ll&&!rl&&r
580450
MC/DC0%0/2
ref $value eq "HASH" and ref $value->{"_stub"} eq "HASH"
ref $value eq "HASH" ref $value->{"_stub"} eq "HASH"
Truth table66%2/3
A and B
A= ref $value eq "HASH"B= ref $value->{"_stub"} eq "HASH"
ABresult
0X0
100
111
3625 0 return '_build_stub_object(' . _render_stub_spec($value->{'_stub'}) . ')';
3626 }
3627  
3628 625 return perl_quote($value);
3629 }
3630  
3631 # A stub description as Perl source, keys sorted so the generated file is
3632 # deterministic. Values are scalars, arrayrefs or hashrefs of them.
3633 sub _render_stub_spec
3634 0 ▶{
Subroutine _render_stub_spec: not called CC=2 SCAR=17.9
3635 0 my ($spec) = @_;
3636  
3637 my @methods = map {
3638 0 perl_quote($_) . ' => ' . perl_quote($spec->{methods}{$_})
3639 0 ▶ } sort keys %{ $spec->{methods} // {} };
Condition0%0/2
$spec->{"methods"} // {}
l!l
00
MC/DC0%0/1
$spec->{"methods"} // {}
$spec->{"methods"}
Truth table0%0/2
A
A= $spec->{"methods"}
Aresult
11
00
3640  
3641 return '{ isa => ' . perl_quote($spec->{isa})
3642 0 . ', methods => { ' . join(', ', @methods) . ' } }';
3643 }
3644  
3645 574 ▶sub render_args_hash {
Subroutine render_args_hash: called CC=3 SCAR=11.0
Pod documented
3646 574 my $href = $_[0];
3647  
3648 # Return empty string for absent or non-hash input
3649 574 ▶ return '' unless $href && ref($href) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless $href and ref $href eq "HASH" 12 562 574
Condition100%3/3
$href and ref $href eq "HASH"
!ll&&!rl&&r
39562
MC/DC100%2/2
$href and ref $href eq "HASH"
$href ref $href eq "HASH"
Truth table100%3/3
A and B
A= $hrefB= ref $href eq "HASH"
ABresult
0X0
100
111
3650  
3651 # Sort keys for deterministic output across runs — important for
3652 # generated test files that are committed to version control
3653 my @pairs = map {
3654 624 perl_quote($_) . ' => ' . _render_arg_value($href->{$_})
3655 562 } sort keys %{$href};
3656  
3657 562 return join(', ', @pairs);
3658 }
3659  
3660 =head2 render_arrayref_map
3661  
3662 Render a hashref whose values are arrayrefs into a Perl source-code
3663 fragment suitable for use as a hash literal in a generated test file.
3664  
3665 my $code = render_arrayref_map({ name => ['', 'a' x 100] });
3666  
3667 =head3 Arguments
3668  
3669 =over 4
3670  
3671 =item * C<$href>
3672  
3673 A hashref whose values are arrayrefs. Keys whose values are not
3674 arrayrefs are silently skipped.
3675  
3676 =back
3677  
3678 =head3 Returns
3679  
3680 A comma-separated string of C<'key' => [ val, ... ]> entries, one per
3681 qualifying key, sorted alphabetically. Returns the string C<'()'> if
3682 C<$href> is undef or not a hashref - this produces an empty
3683 hash assignment in the generated test rather than a syntax error.
3684 Returns an empty string if C<$href> is a hashref with no arrayref values.
3685  
3686 =head3 Notes
3687  
3688 Array element values are rendered via C<perl_quote> which handles
3689 scalars, arrayrefs, and Regexp objects. Non-arrayref values are
3690 skipped without warning - this is intentional since callers may pass
3691 mixed-value hashes and only want the arrayref entries rendered.
3692  
3693 =head3 API SPECIFICATION
3694  
3695 =head4 input
3696  
3697 { href => { type => 'any', optional => 1 } }
3698  
3699 =head4 output
3700  
3701 { type => 'string' }
3702  
3703 The mathematical description is in L</FORMAL SPECIFICATION>.
3704  
3705 =cut
3706  
3707 871 ▶sub render_arrayref_map {
Subroutine render_arrayref_map: called CC=5 SCAR=16.1
Pod documented
3708 871 my $href = $_[0];
3709  
3710 # Return '()' rather than '' so callers get a valid empty hash
3711 # literal rather than a syntax error in the generated test
3712 871 ▶ return '()' unless $href && ref($href) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless $href and ref $href eq "HASH" 11 860 871
Condition100%3/3
$href and ref $href eq "HASH"
!ll&&!rl&&r
38860
MC/DC100%2/2
$href and ref $href eq "HASH"
$href ref $href eq "HASH"
Truth table100%3/3
A and B
A= $hrefB= ref $href eq "HASH"
ABresult
0X0
100
111
3713  
3714 860 my @entries;
3715  
3716 860 for my $k (sort keys %{$href}) {
3717 10 my $aref = $href->{$k};
3718  
3719 # Skip non-arrayref values — mixed hashes are allowed by callers
3720 10 ▶ next unless ref($aref) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $aref eq "ARRAY" 3 7 10
3721  
3722 # Render each array element via perl_quote so strings are
3723 # properly quoted and numbers are left unquoted
3724 7 my $vals = join(', ', map { perl_quote($_) } @{$aref});
3725  
3726 # Use "\t" rather than a literal tab for clarity
3727 7 push @entries, "\t" . perl_quote($k) . " => [ $vals ]";
3728 }
3729  
3730 860 return join(",\n", @entries);
3731 }
3732  
3733 # --------------------------------------------------
3734 # _has_positions
3735 #
3736 # Purpose: Determine whether any field in an input
3737 # spec hashref declares a positional argument
3738 # via the 'position' key.
3739 #
3740 # Entry: $input_spec - the input section of a parsed
3741 # schema, expected to be a hashref whose values
3742 # are themselves hashrefs containing field specs.
3743 # May be undef or a non-hash ref.
3744 #
3745 # Exit: Returns 1 if any field has a defined
3746 # 'position' key, 0 otherwise.
3747 #
3748 # Notes: Returns 0 immediately for undef or non-hash
3749 # input rather than throwing — callers use the
3750 # return value as a boolean and do not expect
3751 # exceptions from this function.
3752 # --------------------------------------------------
3753 450 ▶sub _has_positions {
Subroutine _has_positions: called CC=6 SCAR=17.9
3754 450 my $input_spec = $_[0];
3755  
3756 # Guard against undef or non-hash input — keys %$undef would throw
3757 450 ▶ return 0 unless defined($input_spec) && ref($input_spec) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless defined $input_spec and ref $input_spec eq "HASH" 4 446 450
Condition100%3/3
defined $input_spec and ref $input_spec eq "HASH"
!ll&&!rl&&r
31446
MC/DC100%2/2
defined $input_spec and ref $input_spec eq "HASH"
defined $input_spec ref $input_spec eq "HASH"
Truth table100%3/3
A and B
A= defined $input_specB= ref $input_spec eq "HASH"
ABresult
0X0
100
111
3758  
3759 446 for my $field (keys %{$input_spec}) {
3760 # Only examine fields whose spec is a hashref — scalar specs
3761 # (e.g. input: { type: string }) cannot have positions
3762 390 ▶ next unless ref($input_spec->{$field}) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $input_spec->{$field} eq "HASH" 53 337 390
3763  
3764 # Return immediately on first match — no need to scan further
3765 337 ▶ return 1 if defined $input_spec->{$field}{position};
Branch: 1 branch
BranchTrueFalseTotal
if defined $input_spec->{$field}{"position"} 214 123 337
3766 }
3767  
3768 # No positional arguments found in any field
3769 232 return 0;
3770 }
3771  
3772 # --------------------------------------------------
3773 # q_wrap
3774 #
3775 # Purpose: Wrap a string in the most readable
3776 # q{} form that does not require escaping,
3777 # falling back to single-quoted form with
3778 # escaped apostrophes if no delimiter is
3779 # available.
3780 #
3781 # Entry: $s - the string to wrap. May be undef.
3782 # Exit: Returns a Perl source-code fragment that
3783 # evaluates to the original string value,
3784 # or the string 'undef' if $s is undef.
3785 #
3786 # Notes: index() returns -1 when not found and
3787 # any value >= 0 when found, including 0
3788 # for a delimiter at the start of the
3789 # string. We compare against $INDEX_NOT_FOUND
3790 # to make this boundary explicit and to
3791 # prevent off-by-one mutation survivors.
3792 # See GitHub issue #1.
3793 # --------------------------------------------------
3794 382 ▶sub q_wrap {
Subroutine q_wrap: called CC=7 SCAR=19.5
Pod undocumented
3795 382 my $s = $_[0];
3796  
3797 382 ▶ croak('q_wrap: argument must be a plain string, not a reference') if ref($s);
Branch: 1 branch
BranchTrueFalseTotal
if ref $s 0 382 382
3798  
3799 # Return empty string for undef — this function is a low-level
3800 # string quoter only. Callers that need the Perl literal 'undef'
3801 # for undefined values should use perl_quote() instead, which
3802 # handles the undef -> 'undef' semantic conversion correctly.
3803 # Returning '' here preserves the original behaviour and avoids
3804 # injecting the bare word 'undef' into contexts that expect a
3805 # quoted string value.
3806 382 ▶ return "''" unless defined $s;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s 3 379 382
3807  
3808 # Try bracket-form q{} delimiters first — most readable
3809 379 for my $p (@Q_BRACKET_PAIRS) {
3810 396 my ($l, $r) = @{$p};
3811  
3812 # Only use this bracket pair if neither bracket
3813 # appears in the string — both must be checked
3814 396 ▶ return "q$l$s$r" unless $s =~ /\Q$l\E|\Q$r\E/;
Branch: 1 branch
BranchTrueFalseTotal
unless $s =~ /\Q$l\E|\Q$r\E/u 375 21 396
3815 }
3816  
3817 # Try single-character delimiters in preference order
3818 4 for my $d (@Q_SINGLE_DELIMITERS) {
3819 # index() returns $INDEX_NOT_FOUND (-1) when not found.
3820 # Must use != $INDEX_NOT_FOUND rather than > 0 since
3821 # the delimiter may legitimately appear at position 0
3822 26 ▶ return "q$d$s$d" if index($s, $d) == $INDEX_NOT_FOUND;
Branch: 1 branch
BranchTrueFalseTotal
if index($s, $d) == $INDEX_NOT_FOUND 2 24 26
3823 }
3824  
3825 # Last resort — single-quoted string with escaped apostrophes
3826 2 (my $esc = $s) =~ s/'/\\'/g;
3827 2 return "'$esc'";
3828 }
3829  
3830 # --------------------------------------------------
3831 # perl_sq
3832 #
3833 # Purpose: Escape a string for safe inclusion
3834 # inside a single-quoted Perl string
3835 # literal in generated test code.
3836 #
3837 # Entry: $s - the string to escape.
3838 # Exit: Returns the escaped string, or an
3839 # empty string if $s is undef.
3840 #
3841 # Notes: NUL byte replacement produces the
3842 # two-character sequence \0 which is
3843 # only correct when the result is used
3844 # inside a double-quoted string context
3845 # in the generated test.
3846 #
3847 # The \b substitution (backspace) is
3848 # intentionally omitted — in Perl regex
3849 # context \b means word boundary, not
3850 # backspace, so substituting it here
3851 # would corrupt strings containing word
3852 # boundaries.
3853 # --------------------------------------------------
3854 2727 ▶sub perl_sq {
Subroutine perl_sq: called CC=3 SCAR=11.0
Pod undocumented
3855 2727 my $s = $_[0];
3856  
3857 2727 ▶ croak('perl_sq: argument must be a plain string, not a reference') if ref($s);
Branch: 1 branch
BranchTrueFalseTotal
if ref $s 0 2727 2727
3858  
3859 # Return empty string for undef — callers that need
3860 # 'undef' literal should use perl_quote instead
3861 2727 ▶ return '' unless defined $s;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s 2 2725 2727
3862  
3863 # Escape backslashes first so later substitutions
3864 # don't double-escape already-escaped sequences
3865 2725 $s =~ s/\\/\\\\/g;
3866  
3867 # Escape apostrophes so they don't terminate the
3868 # surrounding single-quoted string literal
3869 2725 $s =~ s/'/\\'/g;
3870  
3871 # Escape common control characters to their
3872 # printable two-character escape sequences
3873 2725 $s =~ s/\n/\\n/g;
3874 2725 $s =~ s/\r/\\r/g;
3875 2725 $s =~ s/\t/\\t/g;
3876 2725 $s =~ s/\f/\\f/g;
3877  
3878 # Replace NUL bytes with \0 — valid only in
3879 # double-quoted string context in generated code
3880 2725 $s =~ s/\0/\\0/g;
3881  
3882 2725 return $s;
3883 }
3884  
3885 =head2 perl_quote
3886  
3887 Convert any Perl value into a source-code fragment that reproduces that value
3888 when evaluated in a generated test file.
3889  
3890 =head3 Arguments
3891  
3892 =over 4
3893  
3894 =item * C<$v>
3895  
3896 Any Perl value. May be undef, a scalar, an arrayref, a Regexp, or a blessed
3897 object. All types are handled - undef becomes C<'undef'>, the strings
3898 C<'true'>/C<'false'> become the Perl boolean constants C<!!1>/C<!!0>,
3899 numbers are unquoted, other strings are single-quoted, arrayrefs recurse,
3900 Regexps become C<qr{...}>, and anything else (including hashrefs and
3901 blessed objects) falls through to C<render_fallback>.
3902  
3903 =back
3904  
3905 =head3 API SPECIFICATION
3906  
3907 =head4 input
3908  
3909 { v => { type => 'any', optional => 1 } }
3910  
3911 =head4 output
3912  
3913 { type => 'string' }
3914  
3915 The mathematical description is in L</FORMAL SPECIFICATION>.
3916  
3917 =cut
3918  
3919 3255 ▶sub perl_quote {
Subroutine perl_quote: called CC=1 SCAR=0.0
Pod documented
3920 3255 my ($v) = @_;
3921 3255 return _perl_quote($v, 0);
3922 }
3923  
3924 3433 ▶sub _perl_quote {
Subroutine _perl_quote: called CC=10 SCAR=23.0
3925 3433 my ($v, $depth) = @_;
3926 225 ▶ no warnings 'recursion'; ## no critic (TestingAndDebugging::ProhibitNoWarnings)
Subroutine BEGIN: called CC=1 SCAR=0.0
3927 3433 ▶ croak('perl_quote: structure too deeply nested (circular reference?)') if $depth > 100;
Branch: 1 branch
BranchTrueFalseTotal
if $depth > 100 1 3432 3433
3928  
3929 # Undef produces the Perl literal 'undef'
3930 3432 ▶ return 'undef' unless defined $v;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 5 3427 3432
3931  
3932 # Convert YAML boolean string literals to Perl
3933 # boolean constants so they survive round-tripping
3934 3427 ▶ return '!!1' if $v eq 'true';
Branch: 1 branch
BranchTrueFalseTotal
if $v eq "true" 3 3424 3427
3935 3424 ▶ return '!!0' if $v eq 'false';
Branch: 1 branch
BranchTrueFalseTotal
if $v eq "false" 5 3419 3424
3936  
3937 3419 ▶ if(ref($v)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $v) 213 3206 3419
3938 # Recursively quote each element of an arrayref
3939 213 ▶ if(ref($v) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $v eq "ARRAY") 130 83 213
3940 130 my @quoted_v = map { _perl_quote($_, $depth + 1) } @{$v};
3941 29 return '[ ' . join(', ', @quoted_v) . ' ]';
3942 }
3943  
3944 # Render Regexp objects as qr{} with modifiers
3945 83 ▶ if(ref($v) eq 'Regexp') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $v eq "Regexp") 32 51 83
3946 32 my ($pat, $mods) = regexp_pattern($v);
3947 32 my $re = "qr{$pat}";
3948  
3949 # Append modifiers (e.g. 'i', 'x') if present
3950 32 ▶ $re .= $mods if $mods;
Branch: 1 branch
BranchTrueFalseTotal
if $mods 23 9 32
3951 32 return $re;
3952 }
3953  
3954 # Hashrefs and other reference types fall through
3955 # to render_fallback which uses Data::Dumper
3956 51 return render_fallback($v);
3957 }
3958  
3959 # Numeric values are emitted unquoted so the generated
3960 # test performs numeric rather than string comparison
3961 3206 ▶ return looks_like_number($v) ? $v : "'" . perl_sq($v) . "'";
Branch: 1 branch
BranchTrueFalseTotal
&looks_like_number($v) ? : 758 2448 3206
3962 }
3963  
3964 # --------------------------------------------------
3965 # _generate_transform_properties
3966 #
3967 # Convert a hashref of transform
3968 # specifications into an arrayref of
3969 # LectroTest property definition hashrefs,
3970 # one per transform. Each hashref contains
3971 # all the information needed by
3972 # _render_properties to emit a runnable
3973 # Test::LectroTest property block.
3974 #
3975 # Entry: $transforms - hashref of transform name
3976 # => transform spec, as
3977 # loaded from the schema.
3978 # $function - name of the function under
3979 # test.
3980 # $module - module name, or undef for
3981 # builtin functions.
3982 # $input - the top-level input spec
3983 # hashref from the schema
3984 # (used for position sorting).
3985 # $config - the normalised config
3986 # hashref, used to read
3987 # properties.trials.
3988 # $new - defined if the function is
3989 # an object method; the value
3990 # is not used here since
3991 # property tests always
3992 # construct a fresh object
3993 # via new_ok() with no args.
3994 # Presence vs absence is the
3995 # only signal used.
3996 #
3997 # Exit: Returns an arrayref of property hashrefs.
3998 # Returns an empty arrayref if no transforms
3999 # produce any testable properties.
4000 # Never returns undef.
4001 #
4002 # Notes: Transforms whose input is the string
4003 # 'undef' or whose input spec is not a
4004 # hashref are silently skipped — they
4005 # represent error-case transforms that have
4006 # no meaningful generator.
4007 #
4008 # The 'WARN' vs 'WARNS' distinction in
4009 # _STATUS: the schema convention uses
4010 # 'WARNS' throughout. This function checks
4011 # for 'WARNS' to match that convention.
4012 # --------------------------------------------------
4013 12 ▶sub _generate_transform_properties {
Subroutine _generate_transform_properties: called CC=22 SCAR=33.3
4014 12 my ($transforms, $function, $module, $input, $config, $new) = @_;
4015  
4016 12 my @properties;
4017  
4018 12 for my $transform_name (sort keys %{$transforms}) {
4019 # $transform_name is spliced by _render_properties as a Perl
4020 # *variable name* (my $$transform_name = Property {...}), not
4021 # just inside a string literal — reject anything that isn't
4022 # identifier-shaped before it reaches that point.
4023 15 _assert_identifier($transform_name, 'transform name');
4024  
4025 14 my $transform = $transforms->{$transform_name};
4026  
4027 14 my $input_spec = $transform->{input};
4028  
4029 # Guard: skip transforms with no input or with the
4030 # YAML scalar 'undef' as their input — these have no
4031 # generator and cannot produce meaningful properties
4032 14 ▶ if(!defined($input_spec) ||
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $input_spec or not ref $input_spec and $input_spec eq "undef") 2 12 14
Condition83%5/6
not defined $input_spec or not ref $input_spec and $input_spec eq "undef"
l!l&&r!l&&!r
1112
not ref $input_spec and $input_spec eq "undef"
!ll&&!rl&&r
1201
MC/DC66%2/3
not defined $input_spec or not ref $input_spec and $input_spec eq "undef"
not defined $input_spec not ref $input_spec $input_spec eq "undef"
Truth table75%3/4
not(A) or not(B) and C
A= not defined $input_specB= not ref $input_specC= $input_spec eq "undef"
ABCresult
1XX1
0111
00X0
0100
4033 (!ref($input_spec) && $input_spec eq 'undef')) {
4034 2 next;
4035 }
4036  
4037 # Guard: skip transforms whose input is not a hashref —
4038 # must come before the helper calls below so we never
4039 # pass a non-hash to _detect_transform_properties or
4040 # _process_custom_properties
4041 12 ▶ next unless ref($input_spec) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $input_spec eq "HASH" 1 11 12
4042  
4043 # Default output spec to empty hash so _STATUS lookups
4044 # below are always safe regardless of schema content
4045 11 ▶ my $output_spec = $transform->{output} // {};
Condition50%1/2
$transform->{"output"} // {}
l!l
110
MC/DC0%0/1
$transform->{"output"} // {}
$transform->{"output"}
Truth table50%1/2
A
A= $transform->{"output"}
Aresult
11
00
4046  
4047 # Detect automatic properties from the transform spec
4048 # (range constraints, type preservation, definedness)
4049 11 my @detected_props = _detect_transform_properties(
4050 $transform_name,
4051 $input_spec,
4052 $output_spec
4053 );
4054  
4055 # Process any custom properties defined in the schema
4056 11 my @custom_props = ();
4057 11 ▶ if(exists($transform->{properties}) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $transform->{"properties"} and ref $transform->{"properties"} eq "ARRAY") 0 11 11
Condition33%1/3
exists $transform->{"properties"} and ref $transform->{"properties"} eq "ARRAY"
!ll&&!rl&&r
1100
MC/DC0%0/2
exists $transform->{"properties"} and ref $transform->{"properties"} eq "ARRAY"
exists $transform->{"properties"} ref $transform->{"properties"} eq "ARRAY"
Truth table33%1/3
A and B
A= exists $transform->{"properties"}B= ref $transform->{"properties"} eq "ARRAY"
ABresult
0X0
100
111
4058 ref($transform->{properties}) eq 'ARRAY') {
4059 @custom_props = _process_custom_properties(
4060 $transform->{properties},
4061 0 $function,
4062 $module,
4063 $input_spec,
4064 $output_spec,
4065 $new
4066 );
4067 }
4068  
4069 # Combine auto-detected and custom properties into one list
4070 11 my @all_props = (@detected_props, @custom_props);
4071  
4072 # Skip this transform if no properties were produced —
4073 # nothing useful to render into the generated test
4074 11 ▶ next unless @all_props;
Branch: 1 branch
BranchTrueFalseTotal
unless @all_props 0 11 11
4075  
4076 # Build the LectroTest generator specification string,
4077 # one entry per input field that has a generator
4078 11 my @generators;
4079 my @var_names;
4080  
4081 11 for my $field (sort keys %{$input_spec}) {
4082 11 my $spec = $input_spec->{$field};
4083  
4084 # Skip non-hashref field specs — scalar types
4085 # like 'string' have no generator sub-structure
4086 11 ▶ next unless ref($spec) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $spec eq "HASH" 0 11 11
4087  
4088 # $field is spliced unescaped into the generated
4089 # LectroTest generator spec by
4090 # _schema_to_lectrotest_generator() — reject anything
4091 # that isn't identifier-shaped first.
4092 11 _assert_identifier($field, 'input field name');
4093  
4094 11 my $gen = _schema_to_lectrotest_generator($field, $spec);
4095 11 ▶ if(defined($gen) && length($gen)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $gen and length $gen) 11 0 11
Condition33%1/3
defined $gen and length $gen
!ll&&!rl&&r
0011
MC/DC0%0/2
defined $gen and length $gen
defined $gen length $gen
Truth table33%1/3
A and B
A= defined $genB= length $gen
ABresult
0X0
100
111
4096 11 push @generators, $gen;
4097 11 push @var_names, $field;
4098 }
4099 }
4100  
4101 11 my $gen_spec = join(', ', @generators);
4102  
4103 # Build the call expression for the function under test.
4104 # Note: property tests always construct a fresh object
4105 # via new_ok() with no constructor arguments, regardless
4106 # of what $new holds in the caller — the intent here is
4107 # to test the method in isolation, not with specific
4108 # construction state.
4109 11 my $call_code;
4110 11 ▶ if($module && defined($new)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($module and defined $new) { } 1 10 11
elsif ($module and $module ne $MODULE_BUILTIN) { } 0 10 10
Condition66%2/3
$module and defined $new
!ll&&!rl&&r
1001
MC/DC50%1/2
$module and defined $new
$module defined $new
Truth table66%2/3
A and B
A= $moduleB= defined $new
ABresult
0X0
100
111
4111 # OO mode — construct a fresh object for each trial
4112 1 $call_code = "my \$obj = new_ok('$module');";
4113 1 $call_code .= "\$obj->$function";
4114 ▶ } elsif($module && $module ne $MODULE_BUILTIN) {
Condition33%1/3
$module and $module ne $MODULE_BUILTIN
!ll&&!rl&&r
1000
MC/DC0%0/2
$module and $module ne $MODULE_BUILTIN
$module $module ne $MODULE_BUILTIN
Truth table33%1/3
A and B
A= $moduleB= $module ne $MODULE_BUILTIN
ABresult
0X0
100
111
4115 # Functional mode with a named module
4116 0 $call_code = "$module\::$function";
4117 } else {
4118 # Builtin or unqualified function call
4119 10 $call_code = $function;
4120 }
4121  
4122 # Build the argument list, respecting positional order
4123 # if the input spec declares positions
4124 11 my @args;
4125 11 ▶ if(_has_positions($input_spec)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_has_positions($input_spec)) { } 11 0 11
4126 # Sort fields by declared position so the generated
4127 # call passes arguments in the correct order, then pass
4128 # the named options as name/value pairs after them
4129 my @sorted = sort {
4130 $input_spec->{$a}{position} <=>
4131 $input_spec->{$b}{position}
4132 0 } grep { defined $input_spec->{$_}{position} } keys %{$input_spec};
4133 11 my @named = grep { !defined $input_spec->{$_}{position} } @var_names;
4134 0 @args = (map { "\$$_" } @sorted, map { "'$_' => \$$_" } @named);
4135 } else {
4136 # No positions — use alphabetical order from @var_names
4137 0 @args = map { "\$$_" } @var_names;
4138 }
4139  
4140 11 my $args_str = join(', ', @args);
4141  
4142 # Concatenate all property check expressions with &&
4143 # so the generated property block passes only when
4144 # every check holds
4145 11 my @checks = map { $_->{code} } @all_props;
4146 11 my $property_checks = join(" &&\n\t", @checks);
4147  
4148 # Determine expected behaviour from output _STATUS.
4149 # Note: the schema convention uses 'WARNS' not 'WARN'
4150 11 ▶ my $should_die = ($output_spec->{'_STATUS'} // '') eq 'DIES';
Condition100%2/2
$output_spec->{"_STATUS"} // ""
l!l
110
MC/DC100%1/1
$output_spec->{"_STATUS"} // ""
$output_spec->{"_STATUS"}
Truth table100%2/2
A
A= $output_spec->{"_STATUS"}
Aresult
11
00
4151 11 ▶ my $should_warn = ($output_spec->{'_STATUS'} // '') eq 'WARNS';
Condition100%2/2
$output_spec->{"_STATUS"} // ""
l!l
110
MC/DC100%1/1
$output_spec->{"_STATUS"} // ""
$output_spec->{"_STATUS"}
Truth table100%2/2
A
A= $output_spec->{"_STATUS"}
Aresult
11
00
4152  
4153 push @properties, {
4154 name => $transform_name,
4155 generator_spec => $gen_spec,
4156 call_code => "$call_code($args_str)",
4157 property_checks => $property_checks,
4158 should_die => $should_die,
4159 should_warn => $should_warn,
4160 11 ▶ trials => $config->{'properties'}{'trials'} // $DEFAULT_PROPERTY_TRIALS,
Condition33%1/3
$config->{"properties"}{"trials"} // $DEFAULT_PROPERTY_TRIALS
l!l&&r!l&&!r
1100
MC/DC0%0/2
$config->{"properties"}{"trials"} // $DEFAULT_PROPERTY_TRIALS
$config->{"properties"}{"trials"} $DEFAULT_PROPERTY_TRIALS
Truth table33%1/3
A // B
A= $config->{"properties"}{"trials"}B= $DEFAULT_PROPERTY_TRIALS
ABresult
1X1
011
000
4161 };
4162 }
4163  
4164 11 return \@properties;
4165 }
4166  
4167 # --------------------------------------------------
4168 # _get_semantic_generators
4169 #
4170 # Return a hashref of named semantic
4171 # generator definitions for use in
4172 # LectroTest property-based tests.
4173 # Each entry contains a 'code' key
4174 # holding a Gen {} block string and a
4175 # 'description' key for documentation
4176 # and validation messages.
4177 #
4178 # Entry: None.
4179 #
4180 # Exit: Returns a hashref keyed by semantic
4181 # type name. Each value is a hashref
4182 # with 'code' and 'description' keys.
4183 #
4184 # Notes: The returned hashref is built fresh
4185 # on every call — callers that need it
4186 # repeatedly should cache the result.
4187 # The 'code' strings are multi-line
4188 # Gen {} blocks; callers are responsible
4189 # for compressing whitespace before
4190 # embedding them in generated test files.
4191 # --------------------------------------------------
4192 325 ▶sub _get_semantic_generators {
Subroutine _get_semantic_generators: called CC=1 SCAR=0.0
4193 return {
4194 325 email => {
4195 code => q{
4196 Gen {
4197 my $len = 5 + int(rand(10));
4198 my @addr;
4199 my @tlds = qw(com org net edu gov io co uk de fr);
4200  
4201 for(my $i = 0; $i < $len; $i++) {
4202 push @addr, pack('c', (int(rand 26))+97);
4203 }
4204 push @addr, '@';
4205 $len = 5 + int(rand(10));
4206 for(my $i = 0; $i < $len; $i++) {
4207 push @addr, pack('c', (int(rand 26))+97);
4208 }
4209 push @addr, '.';
4210 $len = rand($#tlds+1);
4211 push @addr, $tlds[$len];
4212 return join('', @addr);
4213 }
4214 },
4215 description => 'Valid email addresses',
4216 }, url => {
4217 code => q{
4218 Gen {
4219 my @schemes = qw(http https);
4220 my @tlds = qw(com org net io);
4221 my $scheme = $schemes[int(rand(@schemes))];
4222 my $domain = join('', map { ('a'..'z')[int(rand(26))] } 1..(5 + int(rand(10))));
4223 my $tld = $tlds[int(rand(@tlds))];
4224 my $path = join('', map { ('a'..'z', '0'..'9', '-', '_')[int(rand(38))] } 1..int(rand(20)));
4225  
4226 return "$scheme://$domain.$tld" . ($path ? "/$path" : '');
4227 }
4228 },
4229 description => 'Valid HTTP/HTTPS URLs',
4230 }, uuid => {
4231 code => q{
4232 Gen {
4233 require UUID::Tiny;
4234 UUID::Tiny::create_uuid_as_string(UUID::Tiny::UUID_V4());
4235 }
4236 },
4237 description => 'Valid UUIDv4 identifiers',
4238 }, phone_us => {
4239 code => q{
4240 Gen {
4241 my $area = 200 + int(rand(800));
4242 my $exchange = 200 + int(rand(800));
4243 my $subscriber = int(rand(10000));
4244 sprintf('%03d-%03d-%04d', $area, $exchange, $subscriber);
4245 }
4246 },
4247 description => 'US phone numbers (XXX-XXX-XXXX format)',
4248 }, phone_e164 => {
4249 code => q{
4250 Gen {
4251 my $country = 1 + int(rand(999));
4252 my $area = 100 + int(rand(900));
4253 my $number = int(rand(10000000));
4254 sprintf('+%d%03d%07d', $country, $area, $number);
4255 }
4256 },
4257 description => 'E.164 international phone numbers',
4258 }, ipv4 => {
4259 code => q{
4260 Gen {
4261 join('.', map { int(rand(256)) } 1..4);
4262 }
4263 },
4264 description => 'IPv4 addresses',
4265 }, ipv6 => {
4266 code => q{
4267 Gen {
4268 join(':', map { sprintf('%04x', int(rand(0x10000))) } 1..8);
4269 }
4270 },
4271 description => 'IPv6 addresses',
4272 }, username => {
4273 code => q{
4274 Gen {
4275 my $len = 3 + int(rand(13));
4276 my @chars = ('a'..'z', '0'..'9', '_', '-');
4277 my $first = ('a'..'z')[int(rand(26))];
4278 $first . join('', map { $chars[int(rand(@chars))] } 1..($len-1));
4279 }
4280 },
4281 description => 'Valid usernames (alphanumeric with _ and -)',
4282 }, slug => {
4283 code => q{
4284 Gen {
4285 my @words = qw(quick brown fox jumps over lazy dog hello world test data);
4286 my $count = 1 + int(rand(4));
4287 join('-', map { $words[int(rand(@words))] } 1..$count);
4288 }
4289 },
4290 description => 'URL slugs (lowercase words separated by hyphens)',
4291 }, hex_color => {
4292 code => q{
4293 Gen {
4294 sprintf('#%06x', int(rand(0x1000000)));
4295 }
4296 },
4297 description => 'Hex color codes (#RRGGBB)',
4298 }, iso_date => {
4299 code => q{
4300 Gen {
4301 my $year = 2000 + int(rand(25));
4302 my $month = 1 + int(rand(12));
4303 my $day = 1 + int(rand(28));
4304 sprintf('%04d-%02d-%02d', $year, $month, $day);
4305 }
4306 },
4307 description => 'ISO 8601 date format (YYYY-MM-DD)',
4308 },
4309 iso_datetime => {
4310 code => q{
4311 Gen {
4312 my $year = 2000 + int(rand(25));
4313 my $month = 1 + int(rand(12));
4314 my $day = 1 + int(rand(28));
4315 my $hour = int(rand(24));
4316 my $minute = int(rand(60));
4317 my $second = int(rand(60));
4318 sprintf('%04d-%02d-%02dT%02d:%02d:%02dZ',
4319 $year, $month, $day, $hour, $minute, $second);
4320 }
4321 },
4322 description => 'ISO 8601 datetime format (YYYY-MM-DDTHH:MM:SSZ)',
4323 }, semver => {
4324 code => q{
4325 Gen {
4326 my $major = int(rand(10));
4327 my $minor = int(rand(20));
4328 my $patch = int(rand(50));
4329 "$major.$minor.$patch";
4330 }
4331 },
4332 description => 'Semantic version strings (major.minor.patch)',
4333 }, jwt => {
4334 code => q{
4335 Gen {
4336 my @chars = ('A'..'Z', 'a'..'z', '0'..'9', '-', '_');
4337 my $header = join('', map { $chars[int(rand(@chars))] } 1..20);
4338 my $payload = join('', map { $chars[int(rand(@chars))] } 1..40);
4339 my $signature = join('', map { $chars[int(rand(@chars))] } 1..30);
4340 "$header.$payload.$signature";
4341 }
4342 },
4343 description => 'JWT-like tokens (base64url format)',
4344 }, json => {
4345 code => q{
4346 Gen {
4347 my @keys = qw(id name value status count);
4348 my $key = $keys[int(rand(@keys))];
4349 my $value = 1 + int(rand(1000));
4350 qq({"$key":$value});
4351 }
4352 },
4353 description => 'Simple JSON objects',
4354 }, base64 => {
4355 code => q{
4356 Gen {
4357 my @chars = ('A'..'Z', 'a'..'z', '0'..'9', '+', '/');
4358 my $len = 12 + int(rand(20));
4359 my $str = join('', map { $chars[int(rand(@chars))] } 1..$len);
4360 $str .= '=' x (4 - ($len % 4)) if $len % 4;
4361 $str;
4362 }
4363 },
4364 description => 'Base64-encoded strings',
4365 }, md5 => {
4366 code => q{
4367 Gen {
4368 join('', map { sprintf('%x', int(rand(16))) } 1..32);
4369 }
4370 },
4371 description => 'MD5 hashes (32 hex characters)',
4372 }, sha256 => {
4373 code => q{
4374 Gen {
4375 join('', map { sprintf('%x', int(rand(16))) } 1..64);
4376 }
4377 },
4378 description => 'SHA-256 hashes (64 hex characters)',
4379 }, bytes => {
4380 code => q{
4381 Gen {
4382 my $len = 1 + int(rand(32));
4383 join('', map { pack('C', int(rand(256))) } 1..$len);
4384 }
4385 },
4386 description => 'Byte strings (arbitrary octets, not text)',
4387 }, directory => {
4388 code => q{
4389 Gen {
4390 require File::Temp;
4391 File::Temp::tempdir(CLEANUP => 1);
4392 }
4393 },
4394 description => 'Paths to existing writable directories',
4395 }, existing_file => {
4396 code => q{
4397 Gen {
4398 require File::Temp;
4399 my ($fh, $path) = File::Temp::tempfile(SUFFIX => '.pm', UNLINK => 1);
4400 close $fh;
4401 $path;
4402 }
4403 },
4404 description => 'Paths to existing files',
4405 }, unix_timestamp => {
4406 code => q{
4407 Gen {
4408 time;
4409 }
4410 },
4411 description => 'Unix timestamps (seconds since epoch)',
4412 },
4413 };
4414 }
4415  
4416 # --------------------------------------------------
4417 # _get_builtin_properties
4418 #
4419 # Purpose: Return a hashref of named built-in
4420 # property templates that can be
4421 # referenced by name in a transform's
4422 # 'properties' list in the schema.
4423 # Each entry contains a 'description'
4424 # string, a 'code_template' coderef, and
4425 # an 'applicable_to' arrayref.
4426 #
4427 # Entry: None.
4428 #
4429 # Exit: Returns a hashref keyed by property
4430 # name. Each value is a hashref with
4431 # 'description', 'code_template', and
4432 # 'applicable_to' keys.
4433 #
4434 # Notes: 'applicable_to' lists the types for
4435 # which each property is meaningful. It
4436 # is stored for documentation purposes
4437 # and potential future filtering — it is
4438 # not currently enforced by any caller.
4439 #
4440 # Each 'code_template' coderef receives
4441 # three arguments: ($function, $call_code,
4442 # $input_vars). Most templates use only
4443 # $call_code; $function and $input_vars
4444 # are provided for templates that need
4445 # them (e.g. idempotent, length_preserved,
4446 # preserves_keys).
4447 #
4448 # 'monotonic_increasing' has been
4449 # intentionally omitted. A correct
4450 # implementation requires calling the
4451 # function twice with ordered inputs,
4452 # which the current single-call property
4453 # framework does not support. A
4454 # placeholder that unconditionally returns
4455 # true would give false confidence and has
4456 # therefore been removed.
4457 # --------------------------------------------------
4458 32 ▶sub _get_builtin_properties {
Subroutine _get_builtin_properties: called CC=1 SCAR=0.0
4459 return {
4460 idempotent => {
4461 description => 'Function is idempotent: f(f(x)) == f(x)',
4462 2 ▶ code_template => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
4463 2 my ($function, $call_code, $input_vars) = @_;
4464  
4465 # String comparison works for all scalar types in Perl —
4466 # numeric values stringify consistently for eq
4467 2 return "do { my \$tmp = $call_code; \$result eq \$tmp }";
4468 },
4469 applicable_to => ['all'],
4470 }, non_negative => {
4471 description => 'Result is always non-negative',
4472 3 ▶ code_template => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
4473 3 my ($function, $call_code, $input_vars) = @_;
4474 3 return '$result >= 0';
4475 },
4476 applicable_to => ['number', 'integer', 'float'],
4477 }, positive => {
4478 description => 'Result is always positive (> 0)',
4479 2 ▶ code_template => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
4480 2 my ($function, $call_code, $input_vars) = @_;
4481 2 return '$result > 0';
4482 },
4483 applicable_to => ['number', 'integer', 'float'],
4484 }, non_empty => {
4485 description => 'Result is never empty',
4486 2 ▶ code_template => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
4487 2 my ($function, $call_code, $input_vars) = @_;
4488 2 return 'length($result) > 0';
4489 },
4490 applicable_to => ['string'],
4491 },
4492  
4493 length_preserved => {
4494 description => 'Output length equals input length',
4495 2 ▶ code_template => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
4496 2 my ($function, $call_code, $input_vars) = @_;
4497 2 my $first_var = $input_vars->[0];
4498 2 return "length(\$result) == length(\$$first_var)";
4499 },
4500 applicable_to => ['string'],
4501 },
4502  
4503 uppercase => {
4504 description => 'Result is all uppercase',
4505 2 ▶ code_template => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
4506 2 my ($function, $call_code, $input_vars) = @_;
4507 2 return '$result eq uc($result)';
4508 },
4509 applicable_to => ['string'],
4510 },
4511  
4512 lowercase => {
4513 description => 'Result is all lowercase',
4514 2 ▶ code_template => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
4515 2 my ($function, $call_code, $input_vars) = @_;
4516 2 return '$result eq lc($result)';
4517 },
4518 applicable_to => ['string'],
4519 },
4520  
4521 trimmed => {
4522 description => 'Result has no leading or trailing whitespace',
4523 2 ▶ code_template => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
4524 2 my ($function, $call_code, $input_vars) = @_;
4525 2 return '$result !~ /^\s/ && $result !~ /\s$/';
4526 },
4527 applicable_to => ['string'],
4528 },
4529  
4530 sorted_ascending => {
4531 description => 'Array is sorted in ascending order',
4532 2 ▶ code_template => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
4533 2 my ($function, $call_code, $input_vars) = @_;
4534 2 return 'do { my @arr = @$result; my $sorted = 1; ' .
4535 'for my $i (1..$#arr) { $sorted = 0 if $arr[$i] < $arr[$i-1]; } ' .
4536 '$sorted }';
4537 },
4538 applicable_to => ['arrayref'],
4539 },
4540  
4541 sorted_descending => {
4542 description => 'Array is sorted in descending order',
4543 2 ▶ code_template => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
4544 2 my ($function, $call_code, $input_vars) = @_;
4545 2 return 'do { my @arr = @$result; my $sorted = 1; ' .
4546 'for my $i (1..$#arr) { $sorted = 0 if $arr[$i] > $arr[$i-1]; } ' .
4547 '$sorted }';
4548 },
4549 applicable_to => ['arrayref'],
4550 },
4551  
4552 unique_elements => {
4553 description => 'Array has no duplicate elements',
4554 2 ▶ code_template => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
4555 2 my ($function, $call_code, $input_vars) = @_;
4556 2 return 'do { my @arr = @$result; my %seen; !grep { $seen{$_}++ } @arr }';
4557 },
4558 applicable_to => ['arrayref'],
4559 },
4560  
4561 preserves_keys => {
4562 description => 'Hash has same keys as input',
4563 2 ▶ code_template => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
4564 2 my ($function, $call_code, $input_vars) = @_;
4565 2 my $first_var = $input_vars->[0];
4566 2 return 'do { my @in = sort keys %{$' . $first_var . '}; ' .
4567 'my @out = sort keys %$result; ' .
4568 'join(",", @in) eq join(",", @out) }';
4569 },
4570 32 applicable_to => ['hashref'],
4571 },
4572 };
4573 }
4574  
4575 # --------------------------------------------------
4576 # _schema_to_lectrotest_generator
4577 #
4578 # Purpose: Convert a single schema field spec
4579 # hashref into a LectroTest generator
4580 # declaration string of the form
4581 # '$field <- Generator(...)'.
4582 # Used to build the ##[ ... ]## generator
4583 # block inside a Property definition.
4584 #
4585 # Entry: $field_name - the parameter name as it
4586 # will appear in the
4587 # generated test code.
4588 # $spec - hashref containing at
4589 # minimum a 'type' key.
4590 # May also contain 'min',
4591 # 'max', 'semantic', and
4592 # 'matches' keys depending
4593 # on type.
4594 #
4595 # Exit: Returns a string of the form
4596 # '$field <- Generator(...)' on success.
4597 # Returns undef if the spec is not a
4598 # hashref or if range constraints are
4599 # invalid (min >= max for numeric types).
4600 # Returns a String generator with a carp
4601 # warning for unknown types.
4602 #
4603 # Side effects: Carps on unknown semantic types,
4604 # invalid numeric ranges, and unknown
4605 # field types.
4606 #
4607 # Notes: Semantic generators are checked first
4608 # for string fields and take precedence
4609 # over the regular string generator.
4610 # The $input_spec parameter in the type-
4611 # detection helpers is reserved for future
4612 # use and is currently unused.
4613 # --------------------------------------------------
4614 56 ▶sub _schema_to_lectrotest_generator {
Subroutine _schema_to_lectrotest_generator: called CC=40 SCAR=37.2
4615 56 my ($field_name, $spec) = @_;
4616  
4617 # Guard: must be a hashref to dereference safely
4618 56 ▶ return unless defined($spec) && ref($spec) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless defined $spec and ref $spec eq "HASH" 3 53 56
Condition100%3/3
defined $spec and ref $spec eq "HASH"
!ll&&!rl&&r
2153
MC/DC100%2/2
defined $spec and ref $spec eq "HASH"
defined $spec ref $spec eq "HASH"
Truth table100%3/3
A and B
A= defined $specB= ref $spec eq "HASH"
ABresult
0X0
100
111
4619  
4620 # Default to string when no type is declared
4621 53 ▶ my $type = $spec->{'type'} || $DEFAULT_FIELD_TYPE;
Condition33%1/3
$spec->{'type'} || $DEFAULT_FIELD_TYPE
l!l&&r!l&&!r
5300
MC/DC0%0/2
$spec->{'type'} || $DEFAULT_FIELD_TYPE
$spec->{'type'} $DEFAULT_FIELD_TYPE
Truth table33%1/3
A || B
A= $spec->{'type'}B= $DEFAULT_FIELD_TYPE
ABresult
1X1
011
000
4622  
4623 # --------------------------------------------------
4624 # Semantic generators take precedence for string
4625 # fields — they produce realistic domain-specific
4626 # values rather than random character sequences
4627 # --------------------------------------------------
4628 53 ▶ if($type eq 'string' && defined($spec->{'semantic'})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "string" and defined $spec->{"semantic"}) 2 51 53
Condition100%3/3
$type eq "string" and defined $spec->{"semantic"}
!ll&&!rl&&r
41102
MC/DC100%2/2
$type eq "string" and defined $spec->{"semantic"}
$type eq "string" defined $spec->{"semantic"}
Truth table100%3/3
A and B
A= $type eq "string"B= defined $spec->{"semantic"}
ABresult
0X0
100
111
4629 2 my $semantic_type = $spec->{'semantic'};
4630 2 my $generators = _get_semantic_generators();
4631  
4632 2 ▶ if(exists($generators->{$semantic_type})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $generators->{$semantic_type}) { } 2 0 2
4633 2 my $gen_code = $generators->{$semantic_type}{'code'};
4634  
4635 # Compress the multi-line generator code into a
4636 # single line for embedding in the ##[ ]## block
4637 2 $gen_code =~ s/^\s+//;
4638 2 $gen_code =~ s/\s+$//;
4639 2 $gen_code =~ s/\n\s+/ /g;
4640  
4641 2 return "$field_name <- $gen_code";
4642 } else {
4643 0 carp "Unknown semantic type '$semantic_type', " .
4644 "falling back to regular string generator";
4645 # Fall through to regular string generation below
4646 }
4647 }
4648  
4649 # --------------------------------------------------
4650 # Integer generator
4651 # --------------------------------------------------
4652 51 ▶ if($type eq 'integer') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "integer") 10 41 51
4653 10 my $min = $spec->{'min'};
4654 10 my $max = $spec->{'max'};
4655  
4656 10 ▶ if(!defined($min) && !defined($max)) {
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $min || defined $max) { } 4 6 10
elsif (not defined $min) { } 1 5 6
elsif (not defined $max) { } 1 4 5
Condition100%3/3
defined $min || defined $max
l!l&&r!l&&!r
514
MC/DC100%2/2
defined $min || defined $max
defined $min defined $max
Truth table100%3/3
A || B
A= defined $minB= defined $max
ABresult
1X1
011
000
4657 # Unconstrained — use LectroTest's built-in Int
4658 4 return "$field_name <- Int";
4659 } elsif(!defined($min)) {
4660 # Only max defined — generate 0 to max
4661 1 return "$field_name <- Int(sized => sub { int(rand($max + 1)) })";
4662 } elsif(!defined($max)) {
4663 # Only min defined — generate min to min + range
4664 1 return "$field_name <- Int(sized => sub { $min + int(rand($DEFAULT_GENERATOR_RANGE)) })";
4665 } else {
4666 # Both defined — generate within [min, max]
4667 4 my $range = $max - $min;
4668 4 return "$field_name <- Int(sized => sub { $min + int(rand($range + 1)) })";
4669 }
4670 }
4671  
4672 # --------------------------------------------------
4673 # Float / number generator
4674 # --------------------------------------------------
4675 41 ▶ if($type eq 'number' || $type eq 'float') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "number" or $type eq "float") 23 18 41
Condition100%3/3
$type eq "number" or $type eq "float"
l!l&&r!l&&!r
111218
MC/DC100%2/2
$type eq "number" or $type eq "float"
$type eq "number" $type eq "float"
Truth table100%3/3
A or B
A= $type eq "number"B= $type eq "float"
ABresult
1X1
011
000
4676 23 my $min = $spec->{'min'};
4677 23 my $max = $spec->{'max'};
4678  
4679 23 ▶ if(!defined($min) && !defined($max)) {
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $min || defined $max) { } 3 20 23
elsif (not defined $min) { } 8 12 20
elsif (not defined $max) { } 7 5 12
Condition100%3/3
defined $min || defined $max
l!l&&r!l&&!r
1283
MC/DC100%2/2
defined $min || defined $max
defined $min defined $max
Truth table100%3/3
A || B
A= defined $minB= defined $max
ABresult
1X1
011
000
4680 # Unconstrained — symmetric range around zero
4681 3 return "$field_name <- Float(sized => sub { rand($DEFAULT_GENERATOR_RANGE) - $DEFAULT_GENERATOR_RANGE / 2 })";
4682  
4683 } elsif(!defined($min)) {
4684 # Only max defined — choose range based on sign of max
4685 8 ▶ if($max == $ZERO_BOUNDARY) {
Branch: 2 branches
BranchTrueFalseTotal
if ($max == $ZERO_BOUNDARY) { } 6 2 8
elsif ($max > $ZERO_BOUNDARY) { } 1 1 2
4686 # max=0: negative numbers only
4687 6 return "$field_name <- Float(sized => sub { -rand($DEFAULT_GENERATOR_RANGE) })";
4688 } elsif($max > $ZERO_BOUNDARY) {
4689 # Positive max: generate 0 to max
4690 1 return "$field_name <- Float(sized => sub { rand($max) })";
4691 } else {
4692 # Negative max: generate from (max - range) to max
4693 1 return "$field_name <- Float(sized => sub { ($max - $DEFAULT_GENERATOR_RANGE) + rand($DEFAULT_GENERATOR_RANGE + $max) })";
4694 }
4695  
4696 } elsif(!defined($max)) {
4697 # Only min defined — choose range based on sign of min
4698 7 ▶ if($min == $ZERO_BOUNDARY) {
Branch: 2 branches
BranchTrueFalseTotal
if ($min == $ZERO_BOUNDARY) { } 5 2 7
elsif ($min > $ZERO_BOUNDARY) { } 1 1 2
4699 # min=0: positive numbers only
4700 5 return "$field_name <- Float(sized => sub { rand($DEFAULT_GENERATOR_RANGE) })";
4701 } elsif($min > $ZERO_BOUNDARY) {
4702 # Positive min: generate min to min + range
4703 1 return "$field_name <- Float(sized => sub { $min + rand($DEFAULT_GENERATOR_RANGE) })";
4704 } else {
4705 # Negative min: generate from min to min + range
4706 1 return "$field_name <- Float(sized => sub { $min + rand(-$min + $DEFAULT_GENERATOR_RANGE) })";
4707 }
4708  
4709 } else {
4710 # Both min and max defined — validate then generate
4711 5 my $range = $max - $min;
4712 5 ▶ if($range <= $ZERO_BOUNDARY) {
Branch: 1 branch
BranchTrueFalseTotal
if ($range <= $ZERO_BOUNDARY) 4 1 5
4713 4 carp "Invalid range for '$field_name': min=$min, max=$max";
4714 # Return undef rather than emitting a degenerate
4715 # generator that would silently produce wrong values
4716 4 return;
4717 }
4718 1 return "$field_name <- Float(sized => sub { $min + rand($range) })";
4719 }
4720 }
4721  
4722 # --------------------------------------------------
4723 # String generator
4724 # --------------------------------------------------
4725 18 ▶ if($type eq 'string') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "string") 10 8 18
4726 10 ▶ my $min_len = $spec->{'min'} // 0;
Condition100%2/2
$spec->{"min"} // 0
l!l
28
MC/DC100%1/1
$spec->{"min"} // 0
$spec->{"min"}
Truth table100%2/2
A
A= $spec->{"min"}
Aresult
11
00
4727 10 ▶ my $max_len = $spec->{'max'} // $DEFAULT_MAX_STRING_LEN;
Condition100%3/3
$spec->{"max"} // $DEFAULT_MAX_STRING_LEN
l!l&&r!l&&!r
244
MC/DC100%2/2
$spec->{"max"} // $DEFAULT_MAX_STRING_LEN
$spec->{"max"} $DEFAULT_MAX_STRING_LEN
Truth table100%3/3
A // B
A= $spec->{"max"}B= $DEFAULT_MAX_STRING_LEN
ABresult
1X1
011
000
4728  
4729 # If a regex pattern is declared, delegate to
4730 # Data::Random::String::Matches for pattern-aware generation
4731 10 ▶ if(defined($spec->{'matches'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $spec->{"matches"}) 6 4 10
4732 6 my $pattern = $spec->{'matches'};
4733  
4734 # Compile the pattern safely rather than splicing the raw
4735 # string into qr/$pattern/ — the raw form lets a pattern
4736 # containing an unescaped '/' break out of the qr//
4737 # delimiter and inject arbitrary Perl into the generated
4738 # test. regexp_pattern() decomposes the already-compiled
4739 # Regexp object back into pattern text that is guaranteed
4740 # to be a self-contained regex body, safe to re-embed.
4741 6 ▶ my $compiled = ref($pattern) eq 'Regexp' ? $pattern : eval { qr/$pattern/ };
Branch: 1 branch
BranchTrueFalseTotal
ref $pattern eq 'Regexp' ? : 3 3 6
4742 6 ▶ if($@ || !defined($compiled)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@ or not defined $compiled) 0 6 6
Condition33%1/3
$@ or not defined $compiled
l!l&&r!l&&!r
006
MC/DC0%0/2
$@ or not defined $compiled
$@ not defined $compiled
Truth table33%1/3
A or not(B)
A= $@B= not defined $compiled
ABresult
1X1
011
000
4743 0 carp "Invalid matches pattern '$pattern' for field '$field_name': $@";
4744 0 return "$field_name <- String(length => [$min_len, $max_len])";
4745 }
4746 6 my ($pat, $mods) = regexp_pattern($compiled);
4747 6 ▶ my $safe_re = "qr{$pat}" . ($mods // '');
Condition50%1/2
$mods // ""
l!l
60
MC/DC0%0/1
$mods // ""
$mods
Truth table50%1/2
A
A= $mods
Aresult
11
00
4748  
4749 6 ▶ if(defined($spec->{'max'})) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $spec->{'max'}) { } 1 5 6
elsif (defined $spec->{'min'}) { } 1 4 5
4750 1 return "$field_name <- Gen { Data::Random::String::Matches->create_random_string({ regex => $safe_re, length => $spec->{'max'} }) }";
4751 } elsif(defined($spec->{'min'})) {
4752 1 return "$field_name <- Gen { Data::Random::String::Matches->create_random_string({ regex => $safe_re, length => $spec->{'min'} }) }";
4753 } else {
4754 4 return "$field_name <- Gen { Data::Random::String::Matches->create_random_string({ regex => $safe_re }) }";
4755 }
4756 }
4757  
4758 4 return "$field_name <- String(length => [$min_len, $max_len])";
4759 }
4760  
4761 # --------------------------------------------------
4762 # Boolean generator
4763 # --------------------------------------------------
4764 8 ▶ if($type eq 'boolean') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "boolean") 2 6 8
4765 2 return "$field_name <- Bool";
4766 }
4767  
4768 # --------------------------------------------------
4769 # Arrayref generator
4770 # --------------------------------------------------
4771 6 ▶ if($type eq 'arrayref') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "arrayref") 2 4 6
4772 2 ▶ my $min_size = $spec->{'min'} // 0;
Condition50%1/2
$spec->{"min"} // 0
l!l
02
MC/DC0%0/1
$spec->{"min"} // 0
$spec->{"min"}
Truth table50%1/2
A
A= $spec->{"min"}
Aresult
11
00
4773 2 ▶ my $max_size = $spec->{'max'} // $DEFAULT_MAX_COLLECTION_SIZE;
Condition33%1/3
$spec->{"max"} // $DEFAULT_MAX_COLLECTION_SIZE
l!l&&r!l&&!r
002
MC/DC0%0/2
$spec->{"max"} // $DEFAULT_MAX_COLLECTION_SIZE
$spec->{"max"} $DEFAULT_MAX_COLLECTION_SIZE
Truth table33%1/3
A // B
A= $spec->{"max"}B= $DEFAULT_MAX_COLLECTION_SIZE
ABresult
1X1
011
000
4774 2 return "$field_name <- List(Int, length => [$min_size, $max_size])";
4775 }
4776  
4777 # --------------------------------------------------
4778 # Hashref generator
4779 # LectroTest has no built-in Hash generator so we
4780 # use Elements over a pre-built list of hashrefs
4781 # --------------------------------------------------
4782 4 ▶ if($type eq 'hashref') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "hashref") 3 1 4
4783 3 ▶ my $min_keys = $spec->{'min'} // 0;
Condition100%2/2
$spec->{"min"} // 0
l!l
21
MC/DC100%1/1
$spec->{"min"} // 0
$spec->{"min"}
Truth table100%2/2
A
A= $spec->{"min"}
Aresult
11
00
4784 3 ▶ my $max_keys = $spec->{'max'} // $DEFAULT_MAX_COLLECTION_SIZE;
Condition66%2/3
$spec->{"max"} // $DEFAULT_MAX_COLLECTION_SIZE
l!l&&r!l&&!r
201
MC/DC50%1/2
$spec->{"max"} // $DEFAULT_MAX_COLLECTION_SIZE
$spec->{"max"} $DEFAULT_MAX_COLLECTION_SIZE
Truth table66%2/3
A // B
A= $spec->{"max"}B= $DEFAULT_MAX_COLLECTION_SIZE
ABresult
1X1
011
000
4785 3 return "$field_name <- Elements(map { my \%h; for (1..\$_) { \$h{'key'.\$_} = \$_ }; \\\%h } $min_keys..$max_keys)";
4786 }
4787  
4788 # --------------------------------------------------
4789 # Unknown type — fall back to String with a warning
4790 # --------------------------------------------------
4791 1 carp "Unknown type '$type' for '$field_name' LectroTest generator, using String";
4792 1 return "$field_name <- String";
4793 }
4794  
4795 # --------------------------------------------------
4796 # _is_numeric_transform
4797 #
4798 # Determine whether a transform's output
4799 # spec declares a numeric type, indicating
4800 # that numeric range properties should be
4801 # generated for it.
4802 #
4803 # Entry: $input_spec - the transform's input
4804 # spec hashref. Currently
4805 # unused; reserved for
4806 # future input-type checks.
4807 # $output_spec - the transform's output
4808 # spec hashref.
4809 #
4810 # Exit: Returns 1 if the output type is one of
4811 # 'number', 'integer', or 'float'.
4812 # Returns 0 otherwise.
4813 # --------------------------------------------------
4814 39 ▶sub _is_numeric_transform {
Subroutine _is_numeric_transform: called CC=5 SCAR=16.1
4815 39 my ($input_spec, $output_spec) = @_;
4816  
4817 # $input_spec is currently unused — reserved for future
4818 # input-side type checking when detecting mixed transforms
4819 39 ▶ my $out_type = ($output_spec // {})->{'type'} // '';
Condition100%4/4
+($output_spec // {})->{"type"} // ""
l!l
345
$output_spec // {}
l!l
372
MC/DC100%1/1
+($output_spec // {})->{"type"} // ""
$output_spec
Truth table100%2/2
A
A= $output_spec
Aresult
11
00
4820  
4821 39 ▶ return($out_type eq 'number' || $out_type eq 'integer' || $out_type eq 'float');
Condition100%6/6
$out_type eq 'number' || $out_type eq 'integer' || $out_type eq 'float'
l!l&&r!l&&!r
21216
$out_type eq "number" or $out_type eq "integer"
l!l&&r!l&&!r
17418
MC/DC100%3/3
$out_type eq 'number' || $out_type eq 'integer' || $out_type eq 'float'
$out_type eq "number" $out_type eq "integer" $out_type eq 'float'
Truth table100%4/4
A or B || C
A= $out_type eq "number"B= $out_type eq "integer"C= $out_type eq 'float'
ABCresult
1XX1
01X1
0011
0000
4822 }
4823  
4824 # --------------------------------------------------
4825 # _is_string_transform
4826 #
4827 # Purpose: Determine whether a transform's output
4828 # spec declares a string type, indicating
4829 # that string length and pattern properties
4830 # should be generated for it.
4831 #
4832 # Entry: $input_spec - the transform's input
4833 # spec hashref. Currently
4834 # unused; reserved for
4835 # future input-type checks.
4836 # $output_spec - the transform's output
4837 # spec hashref.
4838 #
4839 # Exit: Returns 1 if the output type is 'string'.
4840 # Returns 0 otherwise.
4841 # --------------------------------------------------
4842 33 ▶sub _is_string_transform {
Subroutine _is_string_transform: called CC=3 SCAR=11.0
4843 33 my ($input_spec, $output_spec) = @_;
4844  
4845 # $input_spec is currently unused — reserved for future
4846 # input-side type checking when detecting mixed transforms
4847 33 ▶ my $out_type = ($output_spec // {})->{'type'} // '';
Condition100%4/4
+($output_spec // {})->{"type"} // ""
l!l
294
$output_spec // {}
l!l
321
MC/DC100%1/1
+($output_spec // {})->{"type"} // ""
$output_spec
Truth table100%2/2
A
A= $output_spec
Aresult
11
00
4848  
4849 33 return($out_type eq 'string');
4850 }
4851  
4852 # --------------------------------------------------
4853 # _same_type
4854 #
4855 # Purpose: Determine whether the dominant type of
4856 # a transform's input and output specs
4857 # match, indicating that type-preservation
4858 # properties are meaningful.
4859 #
4860 # Entry: $input_spec - the transform's input
4861 # spec hashref, or a nested
4862 # multi-field hashref.
4863 # $output_spec - the transform's output
4864 # spec hashref.
4865 #
4866 # Exit: Returns 1 if the dominant input and
4867 # output types are identical strings.
4868 # Returns 0 otherwise.
4869 #
4870 # Notes: Uses _get_dominant_type for both sides.
4871 # For multi-field input specs, dominant
4872 # type is the type of the first field
4873 # encountered — this is a simplification.
4874 # TODO: extend to handle mixed-type inputs
4875 # by checking all fields, not just the
4876 # first one found.
4877 # --------------------------------------------------
4878 33 ▶sub _same_type {
Subroutine _same_type: called CC=3 SCAR=11.0
4879 33 my ($input_spec, $output_spec) = @_;
4880  
4881 # Guard: treat missing specs as untyped — two untyped
4882 # specs both default to $DEFAULT_FIELD_TYPE and would
4883 # compare equal, which is intentionally conservative
4884 33 ▶ my $in_type = _get_dominant_type($input_spec // {});
Condition100%2/2
$input_spec // {}
l!l
312
MC/DC100%1/1
$input_spec // {}
$input_spec
Truth table100%2/2
A
A= $input_spec
Aresult
11
00
4885 33 ▶ my $out_type = _get_dominant_type($output_spec // {});
Condition100%2/2
$output_spec // {}
l!l
312
MC/DC100%1/1
$output_spec // {}
$output_spec
Truth table100%2/2
A
A= $output_spec
Aresult
11
00
4886  
4887 33 return($in_type eq $out_type);
4888 }
4889  
4890 # --------------------------------------------------
4891 # _get_dominant_type
4892 #
4893 # Purpose: Extract the most representative type
4894 # string from a spec hashref. For flat
4895 # output specs this is simply the 'type'
4896 # key. For multi-field input specs it is
4897 # the type of the first sub-field found
4898 # that declares one.
4899 #
4900 # Entry: $spec - a spec hashref. May be a flat
4901 # output spec ({ type => '...' })
4902 # or a multi-field input spec
4903 # ({ field => { type => '...' } }).
4904 # May be undef or empty.
4905 #
4906 # Exit: Returns a type string. Returns
4907 # $DEFAULT_FIELD_TYPE ('string') if no
4908 # type can be determined.
4909 # --------------------------------------------------
4910 99 ▶sub _get_dominant_type {
Subroutine _get_dominant_type: called CC=7 SCAR=19.5
4911 99 my $spec = $_[0];
4912  
4913 # Guard: return default for undef or non-hash input
4914 99 ▶ return $DEFAULT_FIELD_TYPE
Branch: 1 branch
BranchTrueFalseTotal
unless defined $spec and ref $spec eq "HASH" 2 97 99
Condition66%2/3
defined $spec and ref $spec eq "HASH"
!ll&&!rl&&r
2097
MC/DC50%1/2
defined $spec and ref $spec eq "HASH"
defined $spec ref $spec eq "HASH"
Truth table66%2/3
A and B
A= defined $specB= ref $spec eq "HASH"
ABresult
0X0
100
111
4915 unless defined($spec) && ref($spec) eq 'HASH';
4916  
4917 # Flat spec — type declared directly
4918 97 ▶ return $spec->{'type'} if defined($spec->{'type'});
Branch: 1 branch
BranchTrueFalseTotal
if defined $spec->{"type"} 59 38 97
4919  
4920 # Multi-field spec — return the type of the first
4921 # sub-field that declares one
4922 38 for my $field (keys %{$spec}) {
4923 32 ▶ next unless ref($spec->{$field}) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $spec->{$field} eq "HASH" 2 30 32
4924 return $spec->{$field}{'type'}
4925 30 ▶ if defined($spec->{$field}{'type'});
Branch: 1 branch
BranchTrueFalseTotal
if defined $spec->{$field}{"type"} 30 0 30
4926 }
4927  
4928 # No type found anywhere — return the safe default
4929 8 return $DEFAULT_FIELD_TYPE;
4930 }
4931  
4932 # --------------------------------------------------
4933 # _render_properties
4934 #
4935 # Purpose: Render an arrayref of property definition
4936 # hashrefs (as produced by
4937 # _generate_transform_properties) into a
4938 # string of Perl source code suitable for
4939 # embedding in a generated test file.
4940 # The output uses Test::LectroTest::Compat
4941 # to run each property as a holds() check.
4942 #
4943 # Entry: $properties - arrayref of property
4944 # hashrefs, each containing: name,
4945 # generator_spec, call_code,
4946 # property_checks, should_die,
4947 # should_warn, trials.
4948 # May be undef or an empty arrayref.
4949 #
4950 # Exit: Returns a string of Perl source code.
4951 # Returns an empty string if $properties
4952 # is undef, not an arrayref, or empty.
4953 #
4954 # Notes: The generated code uses 4-space
4955 # indentation deliberately — this is the
4956 # indentation style of the generated test
4957 # file, not of this module. Tabs are used
4958 # in this module's own source; spaces are
4959 # emitted into generated output for
4960 # readability of the produced test files.
4961 # --------------------------------------------------
4962 13 ▶sub _render_properties {
Subroutine _render_properties: called CC=6 SCAR=17.9
4963 13 my $properties = $_[0];
4964  
4965 # Return empty string for absent or non-array input —
4966 # callers treat '' as no property block to emit
4967 13 ▶ return '' unless defined($properties) && ref($properties) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless defined $properties and ref $properties eq "ARRAY" 3 10 13
Condition100%3/3
defined $properties and ref $properties eq "ARRAY"
!ll&&!rl&&r
2110
MC/DC100%2/2
defined $properties and ref $properties eq "ARRAY"
defined $properties ref $properties eq "ARRAY"
Truth table100%3/3
A and B
A= defined $propertiesB= ref $properties eq "ARRAY"
ABresult
0X0
100
111
4968 10 ▶ return '' unless @{$properties};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$properties;} 2 8 10
4969  
4970 8 my $code = "use_ok('Test::LectroTest::Compat');\n\n";
4971  
4972 8 for my $prop (@{$properties}) {
4973 # Emit a labelled Property block for each transform property
4974 12 $code .= "# Transform property: $prop->{'name'}\n";
4975 12 $code .= "my \$$prop->{'name'} = Property {\n";
4976 12 $code .= " ##[ $prop->{'generator_spec'} ]##\n";
4977 12 $code .= " \n";
4978 12 $code .= " my \$result = eval { $prop->{'call_code'} };\n";
4979  
4980 12 ▶ if($prop->{'should_die'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prop->{'should_die'}) { } 2 10 12
4981 # For transforms that expect death, pass if the
4982 # eval caught an exception
4983 2 $code .= " my \$died = defined(\$\@) && \$\@;\n";
4984 2 $code .= " \$died;\n";
4985 } else {
4986 # For normal transforms, pass only if no exception
4987 # was thrown and all property checks hold
4988 10 $code .= " my \$error = \$\@;\n";
4989 10 $code .= " \n";
4990 10 $code .= " !\$error && (\n";
4991 10 $code .= " $prop->{'property_checks'}\n";
4992 10 $code .= " );\n";
4993 }
4994  
4995 12 $code .= "}, name => '$prop->{'name'}', trials => $prop->{'trials'};\n\n";
4996 12 $code .= "holds(\$$prop->{'name'});\n";
4997 }
4998  
4999 8 return $code;
5000 }
5001  
5002 # --------------------------------------------------
5003 # _detect_transform_properties
5004 #
5005 # Purpose: Automatically derive a list of testable
5006 # LectroTest property hashrefs from a
5007 # transform's input and output specs.
5008 # Detects numeric range constraints, exact
5009 # value matches, string length constraints,
5010 # type preservation, and definedness.
5011 #
5012 # Entry: $transform_name - string name of the
5013 # transform, used for
5014 # heuristic matching
5015 # (e.g. 'positive').
5016 # $input_spec - the transform's input
5017 # hashref, or the string
5018 # 'undef'.
5019 # $output_spec - the transform's output
5020 # hashref, or undef if
5021 # absent.
5022 #
5023 # Exit: Returns a list of property hashrefs,
5024 # each containing 'name' and 'code' keys.
5025 # Returns an empty list if no properties
5026 # can be detected or if $input_spec is
5027 # undef or the string 'undef'.
5028 #
5029 # Notes: The 'positive' heuristic checks the
5030 # transform name case-insensitively against
5031 # $TRANSFORM_POSITIVE_PATTERN and adds a
5032 # non-negative constraint if matched.
5033 # This is intentionally a rough heuristic
5034 # rather than a precise semantic check.
5035 # --------------------------------------------------
5036 30 ▶sub _detect_transform_properties {
Subroutine _detect_transform_properties: called CC=25 SCAR=36.1
5037 30 my ($transform_name, $input_spec, $output_spec) = @_;
5038  
5039 30 my @properties;
5040  
5041 # Guard: skip undef input and the YAML scalar 'undef'
5042 30 ▶ return @properties unless defined($input_spec);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $input_spec 2 28 30
5043 28 ▶ return @properties if(!ref($input_spec) && $input_spec eq 'undef');
Branch: 1 branch
BranchTrueFalseTotal
if not ref $input_spec and $input_spec eq "undef" 2 26 28
Condition66%2/3
not ref $input_spec and $input_spec eq "undef"
!ll&&!rl&&r
2602
MC/DC50%1/2
not ref $input_spec and $input_spec eq "undef"
not ref $input_spec $input_spec eq "undef"
Truth table66%2/3
not(A) and B
A= not ref $input_specB= $input_spec eq "undef"
ABresult
0X0
100
111
5044  
5045 # Default output spec to empty hash so all key lookups
5046 # below are safe regardless of what the schema provides
5047 26 ▶ $output_spec //= {};
Condition50%1/2
$output_spec //= {}
l!l
260
MC/DC0%0/1
$output_spec //= {}
$output_spec
Truth table50%1/2
A
A= $output_spec
Aresult
11
00
5048  
5049 # --------------------------------------------------
5050 # Property 1: Output range constraints (numeric)
5051 # --------------------------------------------------
5052 26 ▶ if(_is_numeric_transform($input_spec, $output_spec)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_numeric_transform($input_spec, $output_spec)) 17 9 26
5053 17 ▶ if(defined($output_spec->{'min'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $output_spec->{"min"}) 13 4 17
5054 13 my $min = $output_spec->{'min'};
5055 13 push @properties, {
5056 name => 'min_constraint',
5057 code => "defined(\$result) && looks_like_number(\$result) && \$result >= $min",
5058 };
5059 }
5060  
5061 17 ▶ if(defined($output_spec->{'max'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $output_spec->{"max"}) 2 15 17
5062 2 my $max = $output_spec->{'max'};
5063 2 push @properties, {
5064 name => 'max_constraint',
5065 code => "defined(\$result) && looks_like_number(\$result) && \$result <= $max",
5066 };
5067 }
5068  
5069 # Heuristic: transforms named 'positive' (case-insensitive)
5070 # imply a non-negative result constraint
5071 17 ▶ if($transform_name =~ /$TRANSFORM_POSITIVE_PATTERN/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($transform_name =~ /$TRANSFORM_POSITIVE_PATTERN/iu) 7 10 17
5072 7 push @properties, {
5073 name => 'non_negative',
5074 code => "defined(\$result) && looks_like_number(\$result) && \$result >= 0",
5075 };
5076 }
5077 }
5078  
5079 # --------------------------------------------------
5080 # Property 2: Specific value output
5081 # --------------------------------------------------
5082 26 ▶ if(defined($output_spec->{'value'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $output_spec->{"value"}) 2 24 26
5083 2 my $expected = $output_spec->{'value'};
5084  
5085 # Numeric refs use == for comparison; scalars use eq
5086 # via perl_quote to produce the correct quoted literal
5087 2 ▶ push @properties, {
Branch: 1 branch
BranchTrueFalseTotal
ref $expected ? : 0 2 2
5088 name => 'exact_value',
5089 code => ref($expected)
5090 ? "\$result == $expected"
5091 : "\$result eq " . perl_quote($expected),
5092 };
5093 }
5094  
5095 # --------------------------------------------------
5096 # Property 3: String length constraints
5097 # --------------------------------------------------
5098 26 ▶ if(_is_string_transform($input_spec, $output_spec)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_string_transform($input_spec, $output_spec)) 6 20 26
5099 6 ▶ if(defined($output_spec->{'min'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $output_spec->{"min"}) 2 4 6
5100 2 push @properties, {
5101 name => 'min_length',
5102 code => "length(\$result) >= $output_spec->{'min'}",
5103 };
5104 }
5105  
5106 6 ▶ if(defined($output_spec->{'max'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $output_spec->{"max"}) 0 6 6
5107 0 push @properties, {
5108 name => 'max_length',
5109 code => "length(\$result) <= $output_spec->{'max'}",
5110 };
5111 }
5112  
5113 6 ▶ if(defined($output_spec->{'matches'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $output_spec->{"matches"}) 0 6 6
5114 0 my $pattern = $output_spec->{'matches'};
5115  
5116 # See the matching comment in _schema_to_lectrotest_generator —
5117 # compile first and re-embed via regexp_pattern() rather than
5118 # splicing the raw string into qr/$pattern/, which would let
5119 # an unescaped '/' break out of the delimiter.
5120 0 ▶ my $compiled = ref($pattern) eq 'Regexp' ? $pattern : eval { qr/$pattern/ };
Branch: 1 branch
BranchTrueFalseTotal
ref $pattern eq 'Regexp' ? : 0 0 0
5121 0 ▶ if($@ || !defined($compiled)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@ or not defined $compiled) { } 0 0 0
Condition0%0/3
$@ or not defined $compiled
l!l&&r!l&&!r
000
MC/DC0%0/2
$@ or not defined $compiled
$@ not defined $compiled
Truth table0%0/3
A or not(B)
A= $@B= not defined $compiled
ABresult
1X1
011
000
5122 0 carp "Invalid matches pattern '$pattern' for transform '$transform_name': $@";
5123 } else {
5124 0 my ($pat, $mods) = regexp_pattern($compiled);
5125 0 ▶ my $safe_re = "qr{$pat}" . ($mods // '');
Condition0%0/2
$mods // ""
l!l
00
MC/DC0%0/1
$mods // ""
$mods
Truth table0%0/2
A
A= $mods
Aresult
11
00
5126 0 push @properties, {
5127 name => 'pattern_match',
5128 code => "\$result =~ $safe_re",
5129 };
5130 }
5131 }
5132 }
5133  
5134 # --------------------------------------------------
5135 # Property 4: Type preservation
5136 # --------------------------------------------------
5137 26 ▶ if(_same_type($input_spec, $output_spec)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_same_type($input_spec, $output_spec)) 24 2 26
5138 24 my $type = _get_dominant_type($output_spec);
5139  
5140 # Only emit a numeric_type check for numeric types —
5141 # string and other types have no equivalent simple check
5142 24 ▶ if($type eq 'number' || $type eq 'integer' || $type eq 'float') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "number" or $type eq "integer" or $type eq "float") 17 7 24
Condition83%5/6
$type eq "number" or $type eq "integer" or $type eq "float"
l!l&&r!l&&!r
1707
$type eq "number" or $type eq "integer"
l!l&&r!l&&!r
1527
MC/DC66%2/3
$type eq "number" or $type eq "integer" or $type eq "float"
$type eq "number" $type eq "integer" $type eq "float"
Truth table75%3/4
A or B or C
A= $type eq "number"B= $type eq "integer"C= $type eq "float"
ABCresult
1XX1
01X1
0011
0000
5143 17 push @properties, {
5144 name => 'numeric_type',
5145 code => 'looks_like_number($result)',
5146 };
5147 }
5148 }
5149  
5150 # --------------------------------------------------
5151 # Property 5: Definedness
5152 # --------------------------------------------------
5153 # Emit a defined() check for all transforms except those
5154 # whose output type is explicitly 'undef' — those are
5155 # expected to return nothing
5156 26 ▶ unless(($output_spec->{'type'} // '') eq 'undef') {
Branch: 1 branch
BranchTrueFalseTotal
unless (($output_spec->{"type"} // "") eq "undef") 24 2 26
Condition100%2/2
$output_spec->{"type"} // ""
l!l
251
MC/DC100%1/1
$output_spec->{"type"} // ""
$output_spec->{"type"}
Truth table100%2/2
A
A= $output_spec->{"type"}
Aresult
11
00
5157 24 push @properties, {
5158 name => 'defined',
5159 code => 'defined($result)',
5160 };
5161 }
5162  
5163 26 return @properties;
5164 }
5165  
5166 # --------------------------------------------------
5167 # _process_custom_properties
5168 #
5169 # Purpose: Process the 'properties' array from a
5170 # transform definition, resolving each
5171 # entry to either a named builtin property
5172 # (looked up from _get_builtin_properties)
5173 # or a custom property with inline code.
5174 #
5175 # Entry: $properties_spec - arrayref of property
5176 # definitions from the
5177 # schema. Each element
5178 # is either a string
5179 # (builtin name) or a
5180 # hashref with 'name'
5181 # and 'code' fields.
5182 # $function - name of the function
5183 # under test.
5184 # $module - module name, or undef
5185 # for builtins.
5186 # $input_spec - the transform's input
5187 # spec hashref.
5188 # $output_spec - the transform's output
5189 # spec hashref.
5190 # $new - defined if the function
5191 # is an OO method; value
5192 # is not used, only
5193 # presence is checked.
5194 #
5195 # Exit: Returns a list of property hashrefs,
5196 # each containing 'name', 'code', and
5197 # 'description' keys.
5198 # Invalid or unrecognised entries are
5199 # skipped with a carp warning.
5200 #
5201 # Side effects: Carps on unrecognised builtin names,
5202 # missing code fields, and invalid
5203 # property definition types.
5204 #
5205 # Notes: The sixth argument is $new (the OO
5206 # constructor signal), not the full schema
5207 # hashref. It is used only to determine
5208 # whether to emit OO-style call code for
5209 # builtin property templates.
5210 # --------------------------------------------------
5211 7 ▶sub _process_custom_properties {
Subroutine _process_custom_properties: called CC=15 SCAR=29.0
5212 7 my ($properties_spec, $function, $module, $input_spec, $output_spec, $new) = @_;
5213  
5214 7 my @properties;
5215 7 my $builtin_properties = _get_builtin_properties();
5216  
5217 7 for my $prop_def (@{$properties_spec}) {
5218 6 my $prop_name;
5219 my $prop_code;
5220 6 my $prop_desc;
5221  
5222 6 ▶ if(!ref($prop_def)) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $prop_def) { } 2 4 6
elsif (ref $prop_def eq 'HASH') { } 3 1 4
5223 # Plain string — look up as a named builtin property
5224 2 $prop_name = $prop_def;
5225  
5226 2 ▶ unless(exists($builtin_properties->{$prop_name})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $builtin_properties->{$prop_name}) 1 1 2
5227 1 carp "Unknown built-in property '$prop_name', skipping";
5228 1 next;
5229 }
5230  
5231 1 my $builtin = $builtin_properties->{$prop_name};
5232  
5233 # Build the argument list, respecting positional order
5234 1 my @var_names = sort keys %{$input_spec};
5235 1 my @args;
5236 1 ▶ if(_has_positions($input_spec)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_has_positions($input_spec)) { } 1 0 1
5237 0 my @sorted = sort { $input_spec->{$a}{'position'} <=> $input_spec->{$b}{'position'} }
5238 1 grep { defined $input_spec->{$_}{'position'} } @var_names;
5239 1 my @named = grep { !defined $input_spec->{$_}{'position'} } @var_names;
5240 0 @args = (map { "\$$_" } @sorted, map { "'$_' => \$$_" } @named);
5241 } else {
5242 0 @args = map { "\$$_" } @var_names;
5243 }
5244  
5245 # Build the call expression for the builtin template.
5246 # $new here is the raw OO signal from the caller —
5247 # defined means OO mode, undef means functional
5248 1 my $call_code;
5249 1 ▶ if($module && defined($new)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($module and defined $new) { } 0 1 1
elsif ($module and $module ne $MODULE_BUILTIN) { } 0 1 1
Condition33%1/3
$module and defined $new
!ll&&!rl&&r
100
MC/DC0%0/2
$module and defined $new
$module defined $new
Truth table33%1/3
A and B
A= $moduleB= defined $new
ABresult
0X0
100
111
5250 # OO mode — fresh object per trial
5251 0 $call_code = "my \$obj = new_ok('$module');";
5252 0 $call_code .= "\$obj->$function";
5253 ▶ } elsif($module && $module ne $MODULE_BUILTIN) {
Condition33%1/3
$module and $module ne $MODULE_BUILTIN
!ll&&!rl&&r
100
MC/DC0%0/2
$module and $module ne $MODULE_BUILTIN
$module $module ne $MODULE_BUILTIN
Truth table33%1/3
A and B
A= $moduleB= $module ne $MODULE_BUILTIN
ABresult
0X0
100
111
5254 # Functional mode with a named module
5255 0 $call_code = "$module\::$function";
5256 } else {
5257 # Builtin or unqualified function call
5258 1 $call_code = $function;
5259 }
5260 1 $call_code .= '(' . join(', ', @args) . ')';
5261  
5262 # Instantiate the builtin's code template with the
5263 # call expression and input variable list
5264 1 $prop_code = $builtin->{'code_template'}->($function, $call_code, \@var_names);
5265 1 $prop_desc = $builtin->{'description'};
5266  
5267 } elsif(ref($prop_def) eq 'HASH') {
5268 # Hashref — custom property with inline Perl code
5269 3 ▶ $prop_name = $prop_def->{'name'} || 'custom_property';
Condition100%2/2
$prop_def->{'name'} || 'custom_property'
l!l
21
MC/DC100%1/1
$prop_def->{'name'} || 'custom_property'
$prop_def->{'name'}
Truth table100%2/2
A
A= $prop_def->{'name'}
Aresult
11
00
5270 3 $prop_code = $prop_def->{'code'};
5271 3 ▶ $prop_desc = $prop_def->{'description'} || "Custom property: $prop_name";
Condition100%2/2
$prop_def->{'description'} || "Custom property: $prop_name"
l!l
12
MC/DC100%1/1
$prop_def->{'description'} || "Custom property: $prop_name"
$prop_def->{'description'}
Truth table100%2/2
A
A= $prop_def->{'description'}
Aresult
11
00
5272  
5273 3 ▶ unless($prop_code) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($prop_code) 1 2 3
5274 1 carp "Custom property '$prop_name' missing 'code' field, skipping";
5275 1 next;
5276 }
5277  
5278 # Sanity-check: code must contain at least a variable
5279 # reference or a word character to be meaningful
5280 2 ▶ unless($prop_code =~ /\$/ || $prop_code =~ /\w+/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($prop_code =~ /\$/u or $prop_code =~ /\w+/u) 0 2 2
Condition33%1/3
$prop_code =~ /\$/u or $prop_code =~ /\w+/u
l!l&&r!l&&!r
200
MC/DC0%0/2
$prop_code =~ /\$/u or $prop_code =~ /\w+/u
$prop_code =~ /\$/u $prop_code =~ /\w+/u
Truth table33%1/3
A or B
A= $prop_code =~ /\$/uB= $prop_code =~ /\w+/u
ABresult
1X1
011
000
5281 0 carp "Custom property '$prop_name' code looks invalid: $prop_code";
5282 0 next;
5283 }
5284  
5285 } else {
5286 # Neither string nor hashref — unrecognised definition type
5287 1 carp 'Invalid property definition: ', render_fallback($prop_def);
5288 1 next;
5289 }
5290  
5291 3 push @properties, {
5292 name => $prop_name,
5293 code => $prop_code,
5294 description => $prop_desc,
5295 };
5296 }
5297  
5298 7 return @properties;
5299 }
5300  
5301 =head1 NOTES
5302  
5303 C<seed> and C<iterations> really should be within C<config>.
5304  
5305 =head1 SEE ALSO
5306  
5307 =over 4
5308  
5309 =item * L<Test Dashboard|https://nigelhorne.github.io/App-Test-Generator/coverage/>
5310  
5311 =item * L<App::Test::Generator::Template> - Template of the file of tests created by C<App::Test::Generator>
5312  
5313 =item * L<App::Test::Generator::SchemaExtractor> - Create schemas from Perl programs
5314  
5315 =item * L<Params::Validate::Strict>: Schema Definition
5316  
5317 =item * L<Params::Get>: Input validation
5318  
5319 =item * L<Return::Set>: Output validation
5320  
5321 =item * L<Test::LectroTest>
5322  
5323 =item * L<Test::Most>
5324  
5325 =item * L<YAML::XS>
5326  
5327 =back
5328  
5329 =head1 AUTHOR
5330  
5331 Nigel Horne, C<< <njh at nigelhorne.com> >>
5332  
5333 Portions of this module's initial design and documentation were created with the
5334 assistance of AI.
5335  
5336 =head1 SUPPORT
5337  
5338 This module is provided as-is without any warranty.
5339  
5340 You can find documentation for this module with the perldoc command.
5341  
5342 perldoc App::Test::Generator
5343  
5344 You can also look for information at:
5345  
5346 =over 4
5347  
5348 =item * MetaCPAN
5349  
5350 L<https://metacpan.org/release/App-Test-Generator>
5351  
5352 =item * GitHub
5353  
5354 L<https://github.com/nigelhorne/App-Test-Generator>
5355  
5356 =item * CPANTS
5357  
5358 L<http://cpants.cpanauthors.org/dist/App-Test-Generator>
5359  
5360 =item * CPAN Testers' Matrix
5361  
5362 L<http://matrix.cpantesters.org/?dist=App-Test-Generator>
5363  
5364 =item * CPAN Testers Dependencies
5365  
5366 L<http://deps.cpantesters.org/?module=App::Test::Generator>
5367  
5368 =back
5369  
5370 =head1 FORMAL SPECIFICATION
5371  
5372 This section describes the documented routines in Z notation. It is for
5373 readers who want an exact, mathematical statement. You do not need it to use
5374 the module.
5375  
5376 How to read it: a name ending in C<?> is an input and a name ending in C<!> is
5377 an output. None of these routines keeps any state between calls, so there is
5378 no state schema. C<quote(v)> stands for the result of C<perl_quote(v)>.
5379  
5380 =head2 generate
5381  
5382 ┌─ Generate ────────────────────────────────────────
5383 │ schema_file? : STRING
5384 │ output_file? : STRING ∪ { undef }
5385 │ test : STRING
5386 │ result! : BOOLEAN
5387 ├───────────────────────────────────────────────────
5388 │ pre schema_file? names a readable schema
5389 │ the schema defines function
5390 │ every name in the schema is an identifier
5391 │ post test is a complete Perl test file for function
5392 │ output_file? ≠ undef ⇒ file output_file? holds test
5393 │ output_file? = undef ⇒ test is printed on STDOUT
5394 │ result! = 1
5395 └───────────────────────────────────────────────────
5396  
5397 no arguments ⇒ croak 'Usage: generate(...)'
5398 output_file? cannot be written ⇒ croak 'Cannot open ...'
5399  
5400 =head2 render_fallback
5401  
5402 ┌─ RenderFallback ──────────────────────────────────
5403 │ v? : VALUE
5404 │ result! : STRING
5405 ├───────────────────────────────────────────────────
5406 │ post v? = undef ⇒ result! = 'undef'
5407 │ v? ≠ undef ⇒ result! is one line of Perl source
5408 │ ∧ eval(result!) is a copy of v?
5409 └───────────────────────────────────────────────────
5410  
5411 =head2 render_hash
5412  
5413 ┌─ RenderHash ──────────────────────────────────────
5414 │ href? : VALUE
5415 │ result! : STRING
5416 │ kept : ℙ STRING
5417 ├───────────────────────────────────────────────────
5418 │ post ref(href?) ≠ 'HASH' ∨ href? = ∅ ⇒ result! = ''
5419 │ ref(href?) = 'HASH' ⇒
5420 │ kept = { k : dom href? | href?(k) is a hashref
5421 │ ∨ href?(k) is a type name }
5422 │ result! has one "'k' => { ... }" entry for each
5423 │ k in kept, in sorted order
5424 └───────────────────────────────────────────────────
5425  
5426 =head2 render_args_hash
5427  
5428 ┌─ RenderArgsHash ──────────────────────────────────
5429 │ href? : VALUE
5430 │ result! : STRING
5431 ├───────────────────────────────────────────────────
5432 │ post ref(href?) ≠ 'HASH' ∨ href? = ∅ ⇒ result! = ''
5433 │ ref(href?) = 'HASH' ⇒
5434 │ result! = join(', ', ⟨ k : sort(dom href?) •
5435 │ quote(k) . ' => ' . quote(href?(k)) ⟩)
5436 └───────────────────────────────────────────────────
5437  
5438 =head2 render_arrayref_map
5439  
5440 ┌─ RenderArrayrefMap ───────────────────────────────
5441 │ href? : VALUE
5442 │ result! : STRING
5443 │ kept : ℙ STRING
5444 ├───────────────────────────────────────────────────
5445 │ post href? is false ∨ ref(href?) ≠ 'HASH' ⇒ result! = '()'
5446 │ ref(href?) = 'HASH' ⇒
5447 │ kept = { k : dom href? | ref(href?(k)) = 'ARRAY' }
5448 │ kept = ∅ ⇒ result! = ''
5449 │ result! has one "'k' => [ ... ]" entry for each
5450 │ k in kept, in sorted order
5451 └───────────────────────────────────────────────────
5452  
5453 =head2 perl_quote
5454  
5455 ┌─ PerlQuote ───────────────────────────────────────
5456 │ v? : VALUE
5457 │ result! : STRING
5458 ├───────────────────────────────────────────────────
5459 │ pre v? is nested no more than 100 levels deep
5460 │ post v? = undef ⇒ result! = 'undef'
5461 │ v? = 'true' ⇒ result! = '!!1'
5462 │ v? = 'false' ⇒ result! = '!!0'
5463 │ v? looks like a number ⇒ result! = v?
5464 │ v? is any other string ⇒ result! = v? in single quotes,
5465 │ with ' and \ escaped
5466 │ ref(v?) = 'ARRAY' ⇒ result! = '[ ' . join(', ',
5467 │ ⟨ e : v? • quote(e) ⟩) . ' ]'
5468 │ ref(v?) = 'Regexp' ⇒ result! = 'qr{...}'
5469 │ otherwise ⇒ result! = render_fallback(v?)
5470 └───────────────────────────────────────────────────
5471  
5472 nested more than 100 levels deep ⇒ croak 'structure too deeply nested'
5473  
5474 =head1 STATE DIAGRAM
5475  
5476 C<generate> is a class method and keeps no state. One call runs from start
5477 to finish through these stages, and any stage may stop it by croaking.
5478  
5479 +-------------+
5480 | START |
5481 +-------------+
5482 |
5483 | generate(schema_file, output_file)
5484 v
5485 +-------------+ no arguments, file not readable
5486 | LOAD SCHEMA |--------------------------------------+
5487 +-------------+ |
5488 | |
5489 | schema parsed |
5490 v |
5491 +-------------+ missing function, bad name, |
5492 | VALIDATE | contradictory input spec |
5493 +-------------+--------------------------------------+
5494 | |
5495 | schema is good |
5496 v v
5497 +-------------+ +-------------+
5498 | RENDER | | CROAKED |
5499 +-------------+ +-------------+
5500 | ^
5501 | test source built |
5502 v |
5503 +-------------+ output_file cannot be opened |
5504 | WRITE |--------------------------------------+
5505 +-------------+
5506 |
5507 | file written, or source printed on STDOUT
5508 v
5509 +-------------+
5510 | DONE |
5511 +-------------+
5512  
5513 Side effects: C<generate> writes C<output_file> and prints one line saying so,
5514 or prints the test source when no output file is given. The C<render_*>
5515 routines and C<perl_quote> write no files and print nothing.
5516  
5517 =head1 LICENCE AND COPYRIGHT
5518  
5519 Copyright 2025-2026 Nigel Horne.
5520  
5521 Usage is subject to the terms of GPL2.
5522 If you use it,
5523 please let me know.
5524  
5525 =cut
5526  
5527 225 1;
↑ Summary blib/lib/App/Test/Generator/SchemaExtractor.pm »