From a0d73b52a0c2de2e8c8f13f4d0d2c387fd1c5c49 Mon Sep 17 00:00:00 2001 From: doy Date: Mon, 20 Apr 2009 01:53:47 -0500 Subject: add a couple todo tests for classes that actually replace the constructor, since i'm not sure if i really want to care about that --- t/022-method-modifiers-new.t | 34 ------------------------- t/022-replaced-constructor.t | 59 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 34 deletions(-) delete mode 100644 t/022-method-modifiers-new.t create mode 100644 t/022-replaced-constructor.t (limited to 't') diff --git a/t/022-method-modifiers-new.t b/t/022-method-modifiers-new.t deleted file mode 100644 index 0d17b7a..0000000 --- a/t/022-method-modifiers-new.t +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/env perl -use strict; -use warnings; -use Test::More tests => 4; - -our $foo_constructed = 0; - -package Foo; - -sub new { - my $class = shift; - bless {}, $class; -} - -package Foo::Moose; -use Moose; -use MooseX::NonMoose; -extends 'Foo'; - -after new => sub { - $main::foo_constructed = 1; -}; - -package main; -my $method = Foo::Moose->meta->get_method('new'); -isa_ok($method, 'Class::MOP::Method::Wrapped'); -my $foo = Foo::Moose->new; -ok($foo_constructed, 'method modifier called for the constructor'); -$foo_constructed = 0; -Foo::Moose->meta->make_immutable; -is($method, Foo::Moose->meta->get_method('new'), - 'make_immutable doesn\'t overwrite constructor with method modifiers'); -$foo = Foo::Moose->new; -ok($foo_constructed, 'method modifier called for the constructor (immutable)'); diff --git a/t/022-replaced-constructor.t b/t/022-replaced-constructor.t new file mode 100644 index 0000000..b16890a --- /dev/null +++ b/t/022-replaced-constructor.t @@ -0,0 +1,59 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Test::More tests => 7; + +our $foo_constructed = 0; + +package Foo; + +sub new { + my $class = shift; + bless {}, $class; +} + +package Foo::Moose; +use Moose; +use MooseX::NonMoose; +extends 'Foo'; + +after new => sub { + $main::foo_constructed = 1; +}; + +package Foo::Moose2; +use Moose; +use MooseX::NonMoose; +extends 'Foo'; + +sub new { + my $class = shift; + $main::foo_constructed = 1; + return $class->meta->new_object(@_); +} + +package main; +my $method = Foo::Moose->meta->get_method('new'); +isa_ok($method, 'Class::MOP::Method::Wrapped'); +my $foo = Foo::Moose->new; +ok($foo_constructed, 'method modifier called for the constructor'); +$foo_constructed = 0; +Foo::Moose->meta->make_immutable; +is($method, Foo::Moose->meta->get_method('new'), + 'make_immutable doesn\'t overwrite constructor with method modifiers'); +$foo = Foo::Moose->new; +ok($foo_constructed, 'method modifier called for the constructor (immutable)'); + +TODO: { +local $TODO = "not quite sure how to handle this (or if I even care)"; +$foo_constructed = 0; +$method = Foo::Moose2->meta->get_method('new'); +$foo = Foo::Moose2->new; +ok($foo_constructed, 'custom constructor called'); +$foo_constructed = 0; +Foo::Moose2->meta->make_immutable; +is($method, Foo::Moose2->meta->get_method('new'), + 'make_immutable doesn\'t overwrite custom constructor'); +$foo = Foo::Moose2->new; +ok($foo_constructed, 'custom constructor called (immutable)'); +} -- cgit v1.2.3-54-g00ecf