3 use Test::Base 0.47 -Base;
11 run_roundtrip_nyn roundtrip_nyn
12 run_load_passes load_passes
13 dumper Load Dump LoadFile DumpFile
17 delimiters('===', '+++');
19 sub Dump () { YAML(Dump => @_) }
20 sub Load () { YAML(Load => @_) }
21 sub DumpFile () { YAML(DumpFile => @_) }
22 sub LoadFile () { YAML(LoadFile => @_) }
27 my $code = $YAML->can($meth) or die "$YAML cannot do $meth";
32 my $file = "$YAML.pm";
37 sub run_yaml_tests() {
40 &{_get_function($block)}($block) unless
41 _skip_tests_for_now($block) or
42 _skip_yaml_tests($block);
46 sub run_roundtrip_nyn() {
50 roundtrip_nyn($block, @options);
56 my $option = shift || '';
57 die "'perl' data section required"
58 unless exists $block->{perl};
59 my @values = eval $block->perl;
60 die "roundtrip_nyn eval perl error: $@" if $@;
61 my $config = $block->config || '';
62 my $result = eval "$config; Dump(\@values)";
63 die "roundtrip_nyn YAML::Dump error: $@" if $@;
64 if (exists $block->{yaml}) {
65 is $result, $block->yaml,
66 $block->description . ' (n->y)';
69 pass $block->description . ' (n->y)';
72 return if exists $block->{no_round_trip} or
73 not exists $block->{yaml};
75 if ($option eq 'dumper') {
76 is dumper(Load($block->yaml)), dumper(@values),
77 $block->description . ' (y->n)';
80 is_deeply [Load($block->yaml)], [@values],
81 $block->description . ' (y->n)';
85 sub count_roundtrip_nyn() {
86 my $block = shift or die "Bad call to count_roundtrip_nyn";
87 return 1 if exists $block->{skip_this_for_now};
89 $count++ if exists $block->{perl};
90 $count++ unless exists $block->{no_round_trip} or
91 not exists $block->{yaml};
92 die "Invalid test definition" unless $count;
96 sub run_load_passes() {
99 my $yaml = $block->yaml;
100 eval { YAML(Load => $yaml) };
107 my $yaml = $block->yaml;
108 eval { YAML(Load => $yaml) };
109 is "$@", "", $block->description;
112 sub count_load_passes() {1}
115 require Data::Dumper;
116 $Data::Dumper::Sortkeys = 1;
117 $Data::Dumper::Terse = 1;
118 $Data::Dumper::Indent = 1;
119 return Data::Dumper::Dumper(@_);
130 my $block = shift or die "Bad call to _count_tests";
132 &{'count_' . _get_function_name($block)}($block);
135 sub _get_function_name() {
137 return $block->function || 'roundtrip_nyn';
140 sub _get_function() {
143 \ &{_get_function_name($block)};
146 sub _skip_tests_for_now() {
148 if (exists $block->{skip_this_for_now}) {
151 _count_tests($block),
158 sub _skip_yaml_tests() {
160 if ($block->skip_unless_modules) {
161 my @modules = split /[\s\,]+/, $block->skip_unless_modules;
162 for my $module (@modules) {
163 eval "require $module";
166 "This test requires the '$module' module",
167 _count_tests($block),
177 my ($message, $count) = @_;
179 skip($message, $count);
183 #-------------------------------------------------------------------------------
184 package Test::YAML::Filter;
186 use Test::Base::Filter ();
188 our @ISA = 'Test::Base::Filter';
191 Test::YAML::Dump(@_);
195 Test::YAML::Load(@_);
198 sub Dump { goto &Test::YAML::Dump }
199 sub Load { goto &Test::YAML::Load }
200 sub DumpFile { goto &Test::YAML::DumpFile }
201 sub LoadFile { goto &Test::YAML::LoadFile }
203 sub yaml_load_or_fail {
204 my ($result, $error, $warning) =
205 $self->_yaml_load_result_error_warning(@_);
206 return $error || $result;
209 sub yaml_load_error_or_warning {
210 my ($result, $error, $warning) =
211 $self->_yaml_load_result_error_warning(@_);
212 return $error || $warning || '';
215 sub perl_eval_error_or_warning {
216 my ($result, $error, $warning) =
217 $self->_perl_eval_result_error_warning(@_);
218 return $error || $warning || '';
221 sub _yaml_load_result_error_warning {
222 $self->assert_scalar(@_);
225 local $SIG{__WARN__} = sub { $warning = join '', @_ };
227 $self->yaml_load($yaml);
229 return ($result, $@, $warning);
232 sub _perl_eval_result_error_warning {
233 $self->assert_scalar(@_);
236 local $SIG{__WARN__} = sub { $warning = join '', @_ };
237 my $result = eval $perl;
238 return ($result, $@, $warning);
245 Test::YAML - Testing Module for YAML Implementations
249 use Test::YAML tests => 1;
255 Test::YAML is a subclass of Test::Base with YAML specific support.
259 Ingy döt Net <ingy@cpan.org>
263 Copyright (c) 2006. Ingy döt Net. All rights reserved.
265 This program is free software; you can redistribute it and/or modify it
266 under the same terms as Perl itself.
268 See L<http://www.perl.com/perl/misc/Artistic.html>