App-Test-Generator
view release on metacpan or search on metacpan
t/cli-benchmark-generator.t view on Meta::CPAN
}
# --help
{
my ($exit, $out) = run_cmd($script, '--help');
is($exit, 0, '--help exits cleanly');
like($out, qr/Usage:|SYNOPSIS/i, '--help output contains usage info');
}
# --version
{
my ($exit, $out) = run_cmd($script, '--version');
is($exit, 0, '--version exits cleanly');
like($out, qr/\d+\.\d+/, '--version prints a version string');
}
# stdout mode â no --output flag
{
my ($exit, $out, $err) = run_cmd($script, '-i', $valid_schema);
is($exit, 0, 'stdout mode exits cleanly');
like($out, qr/cmpthese/, 'output contains cmpthese');
like($out, qr/#!/, 'output starts with shebang');
like($out, qr/abs/, 'output mentions the function name');
is($err, '', 'no stderr in stdout mode');
}
# --output writes a file
{
my ($fh, $outfile) = tempfile(SUFFIX => '.pl', UNLINK => 1);
close $fh;
unlink $outfile;
my ($exit) = run_cmd($script, '-i', $valid_schema, '-o', $outfile);
is($exit, 0, '--output exits cleanly');
ok(-e $outfile, 'output file created');
ok(-s $outfile, 'output file is non-empty');
my $content = do { local $/; open my $r, '<', $outfile or die $!; <$r> };
like($content, qr/cmpthese/, 'written file contains cmpthese');
}
# transforms from schema become named variants
{
my ($exit, $out) = run_cmd($script, '-i', $valid_schema);
is($exit, 0, 'transform schema exits cleanly');
# abs.yml has positive and negative transforms
like($out, qr/'positive'/, 'positive transform variant present');
like($out, qr/'negative'/, 'negative transform variant present');
}
# representative values respect range constraints
{
my ($exit, $out) = run_cmd($script, '-i', $valid_schema);
is($exit, 0, 'exits cleanly for range-constrained schema');
# negative transform has max => 0 so representative value must be <= 0
like($out, qr/abs\(-\d+\)/, 'negative-constrained variant calls abs with a negative value');
}
# missing input file fails gracefully
{
my ($exit, undef, $err) = run_cmd($script, '-i', 't/conf/does_not_exist.yml');
isnt($exit, 0, 'missing schema causes non-zero exit');
}
# generated script is valid Perl
{
my ($fh, $outfile) = tempfile(SUFFIX => '.pl', UNLINK => 1);
close $fh;
run_cmd($script, '-i', $valid_schema, '-o', $outfile);
# run_cmd prepends $^X -Ilib already; pass only the -c flag and file
my ($exit) = run_cmd('-c', $outfile);
is($exit, 0, 'generated benchmark script passes perl -c');
}
done_testing();
( run in 1.494 second using v1.01-cache-2.11-cpan-9581c071862 )