App-Test-Generator
view release on metacpan or search on metacpan
lib/App/Test/Generator.pm view on Meta::CPAN
# TODO: $seed should be passed to Data::Random::String::Matches
# TODO: positional args - when config_undef is set, see what happens when not all args are given
use 5.036;
use strict;
use warnings;
use autodie qw(:all);
use utf8;
binmode STDOUT, ':utf8';
binmode STDERR, ':utf8';
use open qw(:std :encoding(UTF-8));
use App::Test::Generator::Template;
use Carp qw(carp croak);
use Config::Abstraction 0.36;
use Data::Dumper;
use Data::Section::Simple;
use File::Basename qw(basename);
use File::Spec;
lib/App/Test/Generator.pm view on Meta::CPAN
#
# Entry: $name - the string to check.
# Exit: Returns 1 if builtin, 0 otherwise.
# Side effects: None.
# --------------------------------------------------
sub _is_perl_builtin {
my $name = $_[0];
return 0 unless defined $name;
state %BUILTINS = map { $_ => 1 } qw(
abs accept alarm atan2 bind binmode bless
caller chdir chmod chomp chop chown chr chroot
close closedir connect cos crypt
dbmclose dbmopen defined delete die do dump
each endgrent endhostent endnetent endprotoent endpwent endservent
eof eval exec exists exit exp
fcntl fileno flock fork format formline
getc getgrent getgrgid getgrnam gethostbyaddr gethostbyname
gethostent getlogin getnetbyaddr getnetbyname getnetent
getpeername getpgrp getppid getpriority getprotobyname
getprotobynumber getprotoent getpwent getpwnam getpwuid
t/SchemaExtractor.t view on Meta::CPAN
# --------------------------------------------------
# Helper: create a temporary .pm file containing
# the given Perl source and return its path.
# Opens with UTF-8 encoding to avoid wide-character
# warnings when the source contains Unicode.
# --------------------------------------------------
sub _write_pm {
my ($source) = @_;
my ($fh, $path) = tempfile(SUFFIX => '.pm', UNLINK => 1);
# Use UTF-8 encoding so Unicode in source strings does not warn
binmode $fh, ':encoding(UTF-8)';
print $fh $source;
close $fh;
return $path;
}
# --------------------------------------------------
# Helper: construct a minimal SchemaExtractor
# pointing at a real (possibly empty) temp file.
# Accepts additional constructor options via %opts.
# --------------------------------------------------
t/edge_cases.t view on Meta::CPAN
close $fh;
# Should not crash even with inverted constraints
lives_ok(
sub { capture(sub { App::Test::Generator->generate($path) }) },
'inverted min/max does not crash',
);
};
subtest 'Generator: schema with unicode function name' => sub {
my ($fh, $path) = tempfile(SUFFIX => '.yml', UNLINK => 1);
binmode $fh, ':utf8';
print $fh "module: builtin\nfunction: my_func\n";
print $fh "input:\n type: string\noutput:\n type: string\n";
close $fh;
lives_ok(
sub { capture(sub { App::Test::Generator->generate($path) }) },
'unicode in schema file does not crash',
);
};
# ==================================================================
t/edge_cases.t view on Meta::CPAN
);
my $schemas = $e->extract_all(no_write => 1);
is(scalar keys %{$schemas}, 0, 'no schemas from comment-only file');
},
'comment-only source does not crash',
);
};
subtest 'SchemaExtractor: source with Unicode identifiers' => sub {
my ($fh, $pm) = tempfile(SUFFIX => '.pm', UNLINK => 1);
binmode $fh, ':utf8';
print $fh "package Unicode;\nuse utf8;\nsub greet { return 'héllo'; }\n1;\n";
close $fh;
lives_ok(
sub {
my $e = App::Test::Generator::SchemaExtractor->new(
input_file => $pm
);
$e->extract_all(no_write => 1);
},
'unicode source does not crash',
t/generate.t view on Meta::CPAN
use strict;
use warnings;
use Test::Most;
use Test::Needs 'Class::Simple';
use_ok('App::Test::Generator');
binmode STDOUT, ':utf8';
binmode STDERR, ':utf8';
use open qw(:std :encoding(UTF-8));
my $conf_file = 't/conf/app_generator.yml';
ok(-e $conf_file, 'config file exists: $conf_file');
# Generate into a scalar
{
local *STDOUT;
open STDOUT, '>', \my $output;
( run in 1.426 second using v1.01-cache-2.11-cpan-140bd7fdf52 )