From: Tomas Doran Date: Tue, 12 Jan 2010 20:11:43 +0000 (+0000) Subject: Refactor testing code a class before and after it's regenerated into a function X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a80b827d6c24150c20ccf8285e4be63f1804ad80;p=gitmo%2FMooseX-Antlers.git Refactor testing code a class before and after it's regenerated into a function --- diff --git a/t/one.t b/t/one.t index b789f65..83c7f87 100644 --- a/t/one.t +++ b/t/one.t @@ -9,8 +9,6 @@ use IO::All; use Data::Dumper::Concise; use Data::Dump::Streamer; -my $compiler = MooseX::Antlers::Compiler->load_with_compiler('One'); - sub dump_meta { my $meta = $_[0]; local $meta->{methods}{meta}; @@ -42,52 +40,56 @@ sub test_One { foo_called(2 => 'trigger called for setter'); } -my %orig_src = map +($_ => join '', Dump(One->can($_))), qw(new DESTROY foo); +my $class = 'One'; +test_class($class, \&test_One); -One->meta->get_method_list; # fill cache +sub test_class { + my ($class, $test) = @_; -my $orig_meta = dump_meta One->meta; + my $compiler = MooseX::Antlers::Compiler->load_with_compiler($class); -test_One(); + # FIXME - foo + my %orig_src = map +($_ => join '', Dump($class->can($_))), qw(new DESTROY foo); -my $compiled = $compiler->compiled_source; + $class->meta->get_method_list; # fill cache -#warn $compiled; done_testing; exit 0; + my $orig_meta = dump_meta $class->meta; -Class::Unload->unload('One'); -Class::MOP::remove_metaclass_by_name('One'); + $test->($class); -io('/tmp/One.pmc')->print($compiled); + my $compiled = $compiler->compiled_source; -require '/tmp/One.pmc'; + #warn $compiled; done_testing; exit 0; -#eval "no warnings; $compiled"; + Class::Unload->unload($class); + Class::MOP::remove_metaclass_by_name($class); -#die "Shit. failed.\n\n${compiled}\n\nError: $@" if $@; + io("/tmp/$class.pmc")->print($compiled); -my %compiled_src = map +($_ => join '', Dump(One->can($_))), qw(new DESTROY foo); + require "/tmp/$class.pmc"; -foreach my $method (qw(new DESTROY foo)) { - is($compiled_src{$method}, $orig_src{$method}, "${method} restored ok"); -} + #eval "no warnings; $compiled"; + + #die "Shit. failed.\n\n${compiled}\n\nError: $@" if $@; -my $compiled_meta = dump_meta One->meta; + my %compiled_src = map +($_ => join '', Dump($class->can($_))), qw(new DESTROY foo); -test_One; + # FIXME - foo + foreach my $method (qw(new DESTROY foo)) { + is($compiled_src{$method}, $orig_src{$method}, "${method} restored ok"); + } -#io('orig')->print($orig_meta); -#io('comp')->print($compiled_meta); + my $compiled_meta = dump_meta $class->meta; -is($orig_meta, $compiled_meta, 'metaclass restored ok'); + $test->($class); -# write test_class method that checks method including call -# Class::Unload One -# build compiled source -# eval compiled source -# run test_class after that as well as before unload + #io('orig')->print($orig_meta); + #io('comp')->print($compiled_meta); -#warn Dumper \%attr_refs; -#warn Dumper \%attr_et; -#warn Dumper $im_et; + is($orig_meta, $compiled_meta, 'metaclass restored ok'); + + Class::Unload->unload($class); + Class::MOP::remove_metaclass_by_name($class); +} done_testing;