Failing test for using a custom message in a subtype
Shawn M Moore [Thu, 5 Feb 2009 00:46:24 +0000 (00:46 +0000)]
t/039-subtype.t [new file with mode: 0644]

diff --git a/t/039-subtype.t b/t/039-subtype.t
new file mode 100644 (file)
index 0000000..5c4d9e1
--- /dev/null
@@ -0,0 +1,26 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More tests => 2;
+use Test::Exception;
+
+do {
+    package My::Class;
+    use Mouse;
+    use Mouse::Util::TypeConstraints;
+
+    subtype 'NonemptyStr'
+        => as 'Str'
+        => where { length $_ }
+        => message { "The string is empty!" };
+
+    has name => (
+        is  => 'ro',
+        isa => 'NonemptyStr',
+    );
+};
+
+ok(My::Class->new(name => 'foo'));
+
+throws_ok { My::Class->new(name => '') } qr/^Attribute \(name\) does not pass the type constraint because: The string is empty!/;
+