App-Test-Generator

 view release on metacpan or  search on metacpan

t/unit.t  view on Meta::CPAN

		$m->apply_mutant($mutant)
	} 'apply_mutant lives with prepared workspace';
	ok($transform_called, 'transform coderef was called');
	done_testing();
};

# ==================================================================
# App::Test::Generator (Generator.pm)
#
# t/Generator.t and t/Generator_unit.t already give thorough black-box
# coverage of generate(), perl_quote(), render_fallback(), render_hash(),
# render_args_hash() and render_arrayref_map() against their POD. The
# subtests below cover the specific POD-documented branches those files
# leave untested: perl_quote()'s hashref/blessed-object fallthrough to
# render_fallback(), render_hash()'s carp-and-skip path for a scalar
# value that is not a recognised type string, and generate()'s
# documented-but-not-yet-implemented quiet flag.
# ==================================================================
sub _unit_schema_file {
	my (%opts) = @_;
	my ($fh, $path) = tempfile(SUFFIX => '.yml', UNLINK => 1);
	my $module   = $opts{module}   // 'builtin';
	my $function = $opts{function} // 'my_func';
	my $input    = $opts{input}    // "input:\n  type: string";
	my $output   = $opts{output}   // "output:\n  type: string";
	print {$fh} "module: $module\nfunction: $function\n$input\n$output\n";
	close $fh;
	return $path;
}

subtest 'Generator::perl_quote - hashref falls through to render_fallback' => sub {
	# POD: "anything else (including hashrefs and blessed objects) falls
	# through to render_fallback" — a bare hashref is not ARRAY/Regexp,
	# so it must take the render_fallback branch rather than stringify
	# as a ref address.
	my $result = App::Test::Generator::perl_quote({ a => 1 });
	is($result, App::Test::Generator::render_fallback({ a => 1 }),
		'hashref renders identically to a direct render_fallback() call');

	done_testing();
};

subtest 'Generator::perl_quote - blessed object falls through to render_fallback' => sub {
	my $obj = bless { x => 1 }, 'Some::Fake::Class';
	my $result = App::Test::Generator::perl_quote($obj);
	is($result, App::Test::Generator::render_fallback($obj),
		'blessed object renders identically to a direct render_fallback() call');

	done_testing();
};

subtest 'Generator::render_hash - carps and skips key whose scalar value is not a recognised type' => sub {
	# POD: "A scalar value that is a recognised type string is expanded
	# ... Any other non-hashref value is skipped with a warning." This
	# distinguishes the valid-type-shorthand branch (already covered in
	# t/Generator.t) from the invalid-scalar-value branch, which is not
	# tested anywhere else.
	my $warning;
	local $SIG{__WARN__} = sub { $warning = $_[0] };

	my $result = App::Test::Generator::render_hash({ arg1 => 'not_a_real_type' });

	is($result, '', 'key with unrecognised scalar value contributes nothing to the output');
	like($warning, qr/skipping key 'arg1'/, 'carp warns about the skipped key');

	done_testing();
};

subtest 'Generator::generate - quiet flag is accepted but documented as not yet implemented' => sub {
	# POD now states quiet is "accepted but not yet implemented; has no
	# effect". Pass it both ways and confirm generate() neither croaks
	# nor changes its output, matching the documented current behaviour.
	my $schema = _unit_schema_file();

	my ($out_quiet) = capture(sub { App::Test::Generator->generate($schema, undef) });
	my ($out_noisy) = capture(sub {
		App::Test::Generator->generate({ schema_file => $schema, quiet => 1 });
	});

	ok(defined $out_quiet, 'generate() without quiet produces output');
	ok(defined $out_noisy, 'generate() with quiet => 1 does not croak');
	is($out_noisy, $out_quiet, 'quiet => 1 does not change generated output');

	done_testing();
};

# ==================================================================
# App::Test::Generator::Analyzer::Complexity
#
# t/Analyzer-Complexity.t already gives analyze() exhaustive black-box
# POD-driven coverage. One documented behaviour is untested anywhere:
# the Notes section states nesting_depth is "naive brace counting and
# will be inaccurate if the source contains braces inside strings or
# regexes" — unlike the keyword/operator counts (which strip strings
# and comments first via _strip_strings_and_comments), nesting_depth
# scans $body directly and so DOES still count braces inside a string
# literal. This documents that the limitation is real, not a typo.
# ==================================================================
subtest 'Analyzer::Complexity::analyze - documented limitation: braces inside string literals inflate nesting_depth' => sub {
	require App::Test::Generator::Analyzer::Complexity;
	my $analyser = App::Test::Generator::Analyzer::Complexity->new;

	# A brace pair that exists only inside a string literal, with no
	# real brace nesting in the surrounding code at all
	my $report = $analyser->analyze({ body => q{return "{not real code}";} });

	is($report->{nesting_depth}, 1,
		'brace characters inside a string literal are still counted, per the documented limitation');

	done_testing();
};

# ==================================================================
# App::Test::Generator::Analyzer::Return
#
# t/Analyzer-Return.t already gives analyze() exhaustive black-box
# coverage when called with a Model::Method-shaped mock object (one
# exposing both source() and add_evidence()). The POD now documents
# a second, defensive code path — a plain hashref with a source/body
# key and no add_evidence method — that is untested anywhere: the
# analyser must read the source without dying and silently no-op



( run in 2.419 seconds using v1.01-cache-2.11-cpan-9581c071862 )