App-Test-Generator

 view release on metacpan or  search on metacpan

t/generator-regression.t  view on Meta::CPAN

		_accessor => { type => 'getter', field => 'foo' },
		input	 => { bogus => { type => 'string' } },
	};

	# simulate getter post-processing
	if ($schema->{_accessor} && $schema->{_accessor}{type} eq 'getter') {
		$schema->{input} = {};
		$schema->{input_style} = 'none';
	}

	is_deeply(
		$schema->{input},
		{},
		'getter clears input schema'
	);

	is(
		$schema->{input_style},
		'none',
		'getter sets input_style to none'
	);
}

#--------------------------------------------------------------------------
# 5. Semantic generator lookup must be stable
#--------------------------------------------------------------------------
my $sem = App::Test::Generator::_get_semantic_generators();

ok(exists $sem->{email}, 'email semantic generator exists');
ok(exists $sem->{uuid},  'uuid semantic generator exists');
ok(exists $sem->{ipv4},  'ipv4 semantic generator exists');

#--------------------------------------------------------------------------
# 6. LectroTest generator generation should not croak
#--------------------------------------------------------------------------
lives_ok {
	App::Test::Generator::_schema_to_lectrotest_generator(
		'count',
		{ type => 'integer', min => 1, max => 10 }
	);
} 'integer schema generates LectroTest code';

lives_ok {
	App::Test::Generator::_schema_to_lectrotest_generator(
		'name',
		{ type => 'string', min => 3, max => 12 }
	);
} 'string schema generates LectroTest code';

#--------------------------------------------------------------------------
# 7. Hashref generator regression
#--------------------------------------------------------------------------
lives_ok {
	App::Test::Generator::_schema_to_lectrotest_generator(
		'data',
		{ type => 'hashref', min => 1, max => 3 }
	);
} 'hashref schema generates LectroTest code';

#--------------------------------------------------------------------------
# 8. 'matches' patterns containing an unescaped '/' must not break out of
#    the generated qr// delimiter and inject code into the generated test
#--------------------------------------------------------------------------
{
	my $breakout = q{a/; system('touch /tmp/pwned'); qr/b};

	my $code;
	lives_ok {
		$code = App::Test::Generator::_schema_to_lectrotest_generator(
			'name',
			{ type => 'string', matches => $breakout }
		);
	} 'matches pattern containing / does not croak';

	unlike(
		$code, qr/\);\s*system\(/,
		'matches pattern is not spliced as a bare statement-breaking system() call'
	);

	like(
		$code, qr/qr\{/,
		'matches pattern is re-embedded via the safe qr{} form'
	);
}

done_testing();



( run in 0.645 second using v1.01-cache-2.11-cpan-788537b7465 )