App-Test-Generator
view release on metacpan or search on metacpan
lib/App/Test/Generator/Template.pm view on Meta::CPAN
} else {
push @cases, { %mandatory_args, ( $arg_name => $string ) };
}
}
}
# --- memberof ---
if (defined $spec->{memberof}) {
my @set = @{ $spec->{memberof} };
push @cases, { %mandatory_args, ( $arg_name => $set[0] ) } if @set;
push @cases, { %mandatory_args, ( $arg_name => '_not_in_set_', _STATUS => 'DIES' ) };
}
# --- notmemberof ---
if (defined $spec->{notmemberof}) {
my @set = @{ $spec->{notmemberof} };
push @cases, { %mandatory_args, ( $arg_name => $set[0], _STATUS => 'DIES' ) } if @set;
push @cases, { %mandatory_args, ( $arg_name => '_not_in_set_' ) };
}
# --- semantic ---
if(defined(my $semantic = $spec->{'semantic'})) {
if(defined(my $semantic = $spec->{'semantic'})) {
push @cases, { %mandatory_args, ( -1, _STATUS => 'DIES' ) },
{ %mandatory_args, ( $arg_name => 0 ) },
{ %mandatory_args, ( $arg_name => 1 ) },
{ %mandatory_args, ( $arg_name => time ) },
{ %mandatory_args, ( $arg_name => 2147483647 ) },
lib/App/Test/Generator/Template.pm view on Meta::CPAN
}
# Add notmemberof tests
if (defined $spec->{notmemberof}) {
my @blacklist = @{$spec->{notmemberof}};
# Each blacklisted value should die
foreach my $val (@blacklist) {
push @cases, { %mandatory_args, ( $field => $val, _STATUS => 'DIES' ) };
}
# Non-blacklisted value should pass
push @cases, { %mandatory_args, ( $field => '_not_in_blacklist_' ) };
}
# semantic tests
if(defined(my $semantic = $spec->{'semantic'})) {
if($semantic eq 'unix_timestamp') {
push @cases, { %mandatory_args, ( -1, _STATUS => 'DIES' ) },
{ %mandatory_args, ( 0 ) },
{ %mandatory_args, ( 1 ) },
{ %mandatory_args, ( time ) },
{ %mandatory_args, ( 2147483647 ) },
t/40-more.t view on Meta::CPAN
};
# Test YAML corpus validation
subtest 'YAML corpus validation' => sub {
my $corpus_conf = File::Spec->catfile($dir, 'corpus_test.yml');
my $corpus_t = File::Spec->catfile($dir, 'corpus_test.t');
my $bad_corpus = File::Spec->catfile($dir, 'bad_corpus.yml');
# Create invalid YAML corpus (non-array values)
write_yaml($bad_corpus, {
'expected1' => 'not_an_array', # Invalid - should be array
'expected2' => { hash => 'value' } # Invalid - should be array
});
write_yaml($corpus_conf, {
module => 'Test::Most',
function => 'test',
input => { test => { type => 'string' } },
output => { type => 'string' },
yaml_cases => $bad_corpus
});
t/cli-fuzz-harness-generator.t view on Meta::CPAN
is($exit, 0, 'Normal run exits cleanly');
ok(-e $outfile, 'Output file created');
ok(-s $outfile, 'Output file is non-empty');
unlink $outfile;
}
# Invalid config fails
{
my ($exit, $out, $err) = run_cmd($script, '--dry-run', '--input', 't/conf/does_not_exist.conf');
isnt($exit, 0, 'Invalid config causes failure');
like($err, qr/(No such file|failed|error)/i,
'Error message shown for invalid input');
}
done_testing();
module: Test::Simple
function: ok
input:
arg1:
type: string
output:
type: string
yaml_cases: /not_there_at_all
CONF
close $fh;
throws_ok(sub { App::Test::Generator->generate($conf_file) }, qr/not_there_at_all:\s/, 'Dies when yaml_cases file is not found');
unlink $conf_file;
open $fh, '>', $conf_file or die $!;
print $fh <<"CONF";
---
module: Test::Simple
function: nan
CONF
( run in 1.976 second using v1.01-cache-2.11-cpan-39bf76dae61 )