From 4d3f95ec3f21c390df8bdeae998bd66eab284e32 Mon Sep 17 00:00:00 2001 From: kobaken Date: Wed, 18 Dec 2024 08:41:28 +0900 Subject: [PATCH 1/6] Refactor: split t/01_assert.t --- t/01_assert.t | 217 ++------------------------------ t/01_assert/number_comparison.t | 94 ++++++++++++++ t/01_assert/string_comparison.t | 80 ++++++++++++ t/lib/TestUtil.pm | 52 ++++++++ 4 files changed, 235 insertions(+), 208 deletions(-) create mode 100644 t/01_assert/number_comparison.t create mode 100644 t/01_assert/string_comparison.t create mode 100644 t/lib/TestUtil.pm diff --git a/t/01_assert.t b/t/01_assert.t index d144b62..478f8a0 100644 --- a/t/01_assert.t +++ b/t/01_assert.t @@ -2,216 +2,17 @@ use Test2::V0; use Syntax::Keyword::Assert; -use constant HAS_36 => $] >= 5.036; +use lib 't/lib'; +use TestUtil; subtest 'Test `assert` keyword' => sub { - like dies { - assert(0); - }, qr/\AAssertion failed/; - - ok lives { - assert(1); - }; - - my $hello = sub { - my ($message) = @_; - assert(defined $message); - return "Hello, $message!"; - }; - - ok lives { $hello->('world') }; - ok dies { $hello->(undef) }; - - like dies { assert(undef) }, qr/\AAssertion failed \(undef\)/; - like dies { assert(0) }, qr/\AAssertion failed \(0\)/; - like dies { assert('0') }, qr/\AAssertion failed \("0"\)/; - like dies { assert('') }, qr/\AAssertion failed \(""\)/; - - my $false = HAS_36 ? 'false' : '""'; - like dies { assert(!1) }, qr/\AAssertion failed \($false\)/; -}; - -sub expected_assert_bin { - my ($left, $op, $right) = @_; - - my $m = match qr/\AAssertion failed \($left $op $right\)/; - - if (HAS_36) { - return $m; - } - - # Workaround to less than 5.36 - - if ($left eq 'true') { $left = 1 if !HAS_36 } - if ($left eq 'false') { $left = "" if !HAS_36 } - - my $m1 = match qr/\AAssertion failed \($left $op $right\)/; - my $m2 = match qr/\AAssertion failed \("$left" $op $right\)/; - my $m3 = match qr/\AAssertion failed \("$left" $op "$right"\)/; - return in_set($m, $m1, $m2, $m3); -} - -subtest 'Test `assert(binary)` keyword' => sub { - - subtest 'NUM_EQ' => sub { - my $x = 1; - my $y = 2; - ok lives { assert($x + $y == 3) }; - - is dies { assert($x + $y == 100) }, expected_assert_bin(3, '==', 100); - is dies { assert($x == 100) }, expected_assert_bin(1, '==', 100); - - is dies { assert(!!$x == 100) }, expected_assert_bin('true', '==', 100); - is dies { assert(!$x == 100) }, expected_assert_bin('false', '==', 100); - - my $message = 'hello'; - my $undef = undef; - - my $warnings = warnings { - is dies { assert($message == 100) }, expected_assert_bin('"hello"', '==', 100); - is dies { assert($undef == 100) }, expected_assert_bin('undef', '==', 100); - }; - - # suppressed warnings - is scalar @$warnings, 2; - }; - - subtest 'NUM_NE' => sub { - my $x = 2; - ok lives { assert($x != 1) }; - is dies { assert($x != 2) }, expected_assert_bin(2, '!=', 2); - }; - - subtest 'NUM_LT' => sub { - my $x = 2; - is dies { assert($x < 1) }, expected_assert_bin(2, '<', 1); - is dies { assert($x < 2) }, expected_assert_bin(2, '<', 2); - ok lives { assert($x < 3) }; - - my $x2 = 2.01; - is dies { assert($x2 < 2) }, expected_assert_bin(2.01, '<', 2); - is dies { assert($x2 < 2.01) }, expected_assert_bin(2.01, '<', 2.01); - ok lives { assert($x2 < 3) }; - - my $x3 = -1; - ok lives { assert($x3 < 0) }; - is dies { assert($x3 < -1) }, expected_assert_bin(-1, '<', -1); - is dies { assert($x3 < -2) }, expected_assert_bin(-1, '<', -2); - - my $x4 = -1.01; - ok lives { assert($x4 < 0) }; - is dies { assert($x4 < -1.01) }, expected_assert_bin(-1.01, '<', -1.01); - is dies { assert($x4 < -2) }, expected_assert_bin(-1.01, '<', -2); - }; - - subtest 'NUM_GT' => sub { - my $x = 2; - ok lives { assert($x > 1) }; - is dies { assert($x > 2) }, expected_assert_bin(2, '>', 2); - is dies { assert($x > 3) }, expected_assert_bin(2, '>', 3); - - my $x2 = 2.01; - ok lives { assert($x2 > 2) }; - is dies { assert($x2 > 2.01) }, expected_assert_bin(2.01, '>', 2.01); - is dies { assert($x2 > 3) }, expected_assert_bin(2.01, '>', 3); - - my $x3 = -1; - is dies { assert($x3 > 0) }, expected_assert_bin(-1, '>', 0); - is dies { assert($x3 > -1) }, expected_assert_bin(-1, '>', -1); - ok lives { assert($x3 > -2) }; - - my $x4 = -1.01; - is dies { assert($x4 > 0) }, expected_assert_bin(-1.01, '>', 0); - is dies { assert($x4 > -1.01) }, expected_assert_bin(-1.01, '>', -1.01); - ok lives { assert($x4 > -2) }; - }; - - subtest 'NUM_LE' => sub { - my $x = 2; - is dies { assert($x <= 1) }, expected_assert_bin(2, '<=', 1); - ok lives { assert($x <= 2) }; - ok lives { assert($x <= 3) }; - }; - - subtest 'NUM_GE' => sub { - my $x = 2; - ok lives { assert($x >= 1) }; - ok lives { assert($x >= 2) }; - is dies { assert($x >= 3) }, expected_assert_bin(2, '>=', 3); - }; - - subtest 'STR_EQ' => sub { - my $message = 'hello'; - - ok lives { assert($message eq 'hello') }; - is dies { assert($message eq 'world') }, expected_assert_bin('"hello"', 'eq', '"world"'); - - my $x = 1; - my $undef = undef; - - is dies { assert($x eq 'world') }, expected_assert_bin(1, 'eq', '"world"'); - - my $warnings = warnings { - is dies { assert($undef eq 'world') }, expected_assert_bin('undef', 'eq', '"world"'); - }; - - # suppressed warnings - is scalar @$warnings, 1; - }; - - subtest 'STR_NE' => sub { - my $message = 'hello'; - ok lives { assert($message ne 'world') }; - is dies { assert($message ne 'hello') }, expected_assert_bin('"hello"', 'ne', '"hello"'); - }; - - subtest 'STR_LT' => sub { - my $message = 'b'; - is dies { assert($message lt 'a') }, expected_assert_bin('"b"', 'lt', '"a"'); - is dies { assert($message lt 'b') }, expected_assert_bin('"b"', 'lt', '"b"'); - ok lives { assert($message lt 'c') }; - - my $unicode = "い"; - is dies { assert($unicode lt 'あ') }, expected_assert_bin('"い"', 'lt', '"あ"'); - is dies { assert($unicode lt 'い') }, expected_assert_bin('"い"', 'lt', '"い"'); - ok lives { assert($unicode lt 'う') }; - }; - - subtest 'STR_GT' => sub { - my $message = 'b'; - ok lives { assert($message gt 'a') }; - is dies { assert($message gt 'b') }, expected_assert_bin('"b"', 'gt', '"b"'); - is dies { assert($message gt 'c') }, expected_assert_bin('"b"', 'gt', '"c"'); - - my $unicode = "い"; - ok lives { assert($unicode gt 'あ') }; - is dies { assert($unicode gt 'い') }, expected_assert_bin('"い"', 'gt', '"い"'); - is dies { assert($unicode gt 'う') }, expected_assert_bin('"い"', 'gt', '"う"'); - }; - - subtest 'STR_LE' => sub { - my $message = 'b'; - is dies { assert($message le 'a') }, expected_assert_bin('"b"', 'le', '"a"'); - ok lives { assert($message le 'b') }; - ok lives { assert($message le 'c') }; - - my $unicode = "い"; - is dies { assert($unicode le 'あ') }, expected_assert_bin('"い"', 'le', '"あ"'); - ok lives { assert($unicode le 'い') }; - ok lives { assert($unicode le 'う') }; - }; - - subtest 'STR_GE' => sub { - my $message = 'b'; - ok lives { assert($message ge 'a') }; - ok lives { assert($message ge 'b') }; - is dies { assert($message ge 'c') }, expected_assert_bin('"b"', 'ge', '"c"'); - - my $unicode = "い"; - ok lives { assert($unicode ge 'あ') }; - ok lives { assert($unicode ge 'い') }; - is dies { assert($unicode ge 'う') }, expected_assert_bin('"い"', 'ge', '"う"'); - }; + ok lives { assert(1) }; + ok lives { assert("hello") }; + like dies { assert(undef) }, expected_assert('undef'); + like dies { assert(0) }, expected_assert('0'); + like dies { assert('0') }, expected_assert('"0"'); + like dies { assert('') }, expected_assert('""'); + like dies { assert(!!0) }, expected_assert('false'); }; done_testing; diff --git a/t/01_assert/number_comparison.t b/t/01_assert/number_comparison.t new file mode 100644 index 0000000..57a4ebf --- /dev/null +++ b/t/01_assert/number_comparison.t @@ -0,0 +1,94 @@ +use Test2::V0; +use Syntax::Keyword::Assert; + +use lib 't/lib'; +use TestUtil; + +subtest 'NUM_EQ' => sub { + my $x = 1; + my $y = 2; + ok lives { assert($x + $y == 3) }; + + is dies { assert($x + $y == 100) }, expected_assert_bin(3, '==', 100); + is dies { assert($x == 100) }, expected_assert_bin(1, '==', 100); + + is dies { assert(!!$x == 100) }, expected_assert_bin('true', '==', 100); + is dies { assert(!$x == 100) }, expected_assert_bin('false', '==', 100); + + my $message = 'hello'; + my $undef = undef; + + my $warnings = warnings { + is dies { assert($message == 100) }, expected_assert_bin('"hello"', '==', 100); + is dies { assert($undef == 100) }, expected_assert_bin('undef', '==', 100); + }; + + # suppressed warnings + is scalar @$warnings, 2; +}; + +subtest 'NUM_NE' => sub { + my $x = 2; + ok lives { assert($x != 1) }; + is dies { assert($x != 2) }, expected_assert_bin(2, '!=', 2); +}; + +subtest 'NUM_LT' => sub { + my $x = 2; + is dies { assert($x < 1) }, expected_assert_bin(2, '<', 1); + is dies { assert($x < 2) }, expected_assert_bin(2, '<', 2); + ok lives { assert($x < 3) }; + + my $x2 = 2.01; + is dies { assert($x2 < 2) }, expected_assert_bin(2.01, '<', 2); + is dies { assert($x2 < 2.01) }, expected_assert_bin(2.01, '<', 2.01); + ok lives { assert($x2 < 3) }; + + my $x3 = -1; + ok lives { assert($x3 < 0) }; + is dies { assert($x3 < -1) }, expected_assert_bin(-1, '<', -1); + is dies { assert($x3 < -2) }, expected_assert_bin(-1, '<', -2); + + my $x4 = -1.01; + ok lives { assert($x4 < 0) }; + is dies { assert($x4 < -1.01) }, expected_assert_bin(-1.01, '<', -1.01); + is dies { assert($x4 < -2) }, expected_assert_bin(-1.01, '<', -2); +}; + +subtest 'NUM_GT' => sub { + my $x = 2; + ok lives { assert($x > 1) }; + is dies { assert($x > 2) }, expected_assert_bin(2, '>', 2); + is dies { assert($x > 3) }, expected_assert_bin(2, '>', 3); + + my $x2 = 2.01; + ok lives { assert($x2 > 2) }; + is dies { assert($x2 > 2.01) }, expected_assert_bin(2.01, '>', 2.01); + is dies { assert($x2 > 3) }, expected_assert_bin(2.01, '>', 3); + + my $x3 = -1; + is dies { assert($x3 > 0) }, expected_assert_bin(-1, '>', 0); + is dies { assert($x3 > -1) }, expected_assert_bin(-1, '>', -1); + ok lives { assert($x3 > -2) }; + + my $x4 = -1.01; + is dies { assert($x4 > 0) }, expected_assert_bin(-1.01, '>', 0); + is dies { assert($x4 > -1.01) }, expected_assert_bin(-1.01, '>', -1.01); + ok lives { assert($x4 > -2) }; +}; + +subtest 'NUM_LE' => sub { + my $x = 2; + is dies { assert($x <= 1) }, expected_assert_bin(2, '<=', 1); + ok lives { assert($x <= 2) }; + ok lives { assert($x <= 3) }; +}; + +subtest 'NUM_GE' => sub { + my $x = 2; + ok lives { assert($x >= 1) }; + ok lives { assert($x >= 2) }; + is dies { assert($x >= 3) }, expected_assert_bin(2, '>=', 3); +}; + +done_testing; diff --git a/t/01_assert/string_comparison.t b/t/01_assert/string_comparison.t new file mode 100644 index 0000000..762268f --- /dev/null +++ b/t/01_assert/string_comparison.t @@ -0,0 +1,80 @@ +use Test2::V0; +use Syntax::Keyword::Assert; + +use lib 't/lib'; +use TestUtil; + +subtest 'STR_EQ' => sub { + my $message = 'hello'; + + ok lives { assert($message eq 'hello') }; + is dies { assert($message eq 'world') }, expected_assert_bin('"hello"', 'eq', '"world"'); + + my $x = 1; + my $undef = undef; + + is dies { assert($x eq 'world') }, expected_assert_bin(1, 'eq', '"world"'); + + my $warnings = warnings { + is dies { assert($undef eq 'world') }, expected_assert_bin('undef', 'eq', '"world"'); + }; + + # suppressed warnings + is scalar @$warnings, 1; +}; + +subtest 'STR_NE' => sub { + my $message = 'hello'; + ok lives { assert($message ne 'world') }; + is dies { assert($message ne 'hello') }, expected_assert_bin('"hello"', 'ne', '"hello"'); +}; + +subtest 'STR_LT' => sub { + my $message = 'b'; + is dies { assert($message lt 'a') }, expected_assert_bin('"b"', 'lt', '"a"'); + is dies { assert($message lt 'b') }, expected_assert_bin('"b"', 'lt', '"b"'); + ok lives { assert($message lt 'c') }; + + my $unicode = "い"; + is dies { assert($unicode lt 'あ') }, expected_assert_bin('"い"', 'lt', '"あ"'); + is dies { assert($unicode lt 'い') }, expected_assert_bin('"い"', 'lt', '"い"'); + ok lives { assert($unicode lt 'う') }; +}; + +subtest 'STR_GT' => sub { + my $message = 'b'; + ok lives { assert($message gt 'a') }; + is dies { assert($message gt 'b') }, expected_assert_bin('"b"', 'gt', '"b"'); + is dies { assert($message gt 'c') }, expected_assert_bin('"b"', 'gt', '"c"'); + + my $unicode = "い"; + ok lives { assert($unicode gt 'あ') }; + is dies { assert($unicode gt 'い') }, expected_assert_bin('"い"', 'gt', '"い"'); + is dies { assert($unicode gt 'う') }, expected_assert_bin('"い"', 'gt', '"う"'); +}; + +subtest 'STR_LE' => sub { + my $message = 'b'; + is dies { assert($message le 'a') }, expected_assert_bin('"b"', 'le', '"a"'); + ok lives { assert($message le 'b') }; + ok lives { assert($message le 'c') }; + + my $unicode = "い"; + is dies { assert($unicode le 'あ') }, expected_assert_bin('"い"', 'le', '"あ"'); + ok lives { assert($unicode le 'い') }; + ok lives { assert($unicode le 'う') }; +}; + +subtest 'STR_GE' => sub { + my $message = 'b'; + ok lives { assert($message ge 'a') }; + ok lives { assert($message ge 'b') }; + is dies { assert($message ge 'c') }, expected_assert_bin('"b"', 'ge', '"c"'); + + my $unicode = "い"; + ok lives { assert($unicode ge 'あ') }; + ok lives { assert($unicode ge 'い') }; + is dies { assert($unicode ge 'う') }, expected_assert_bin('"い"', 'ge', '"う"'); +}; + +done_testing; diff --git a/t/lib/TestUtil.pm b/t/lib/TestUtil.pm new file mode 100644 index 0000000..a3a1e85 --- /dev/null +++ b/t/lib/TestUtil.pm @@ -0,0 +1,52 @@ +package TestUtil; +use Exporter 'import'; + +our @EXPORT = qw( + expected_assert + expected_assert_bin +); + +use Test2::V0; + +use constant HAS_36 => $] >= 5.036; + +sub expected_assert { + my ($expr) = @_; + + my $m = match qr/\AAssertion failed \($expr\)/; + + if (HAS_36) { + return $m; + } + + # Workaround to less than 5.36 + + if ($expr eq 'true') { $expr = 1 if !HAS_36 } + if ($expr eq 'false') { $expr = "" if !HAS_36 } + + my $m1 = match qr/\AAssertion failed \($expr\)/; + my $m2 = match qr/\AAssertion failed \("$expr"\)/; + return in_set($m, $m1, $m2); +} + +sub expected_assert_bin { + my ($left, $op, $right) = @_; + + my $m = match qr/\AAssertion failed \($left $op $right\)/; + + if (HAS_36) { + return $m; + } + + # Workaround to less than 5.36 + + if ($left eq 'true') { $left = 1 if !HAS_36 } + if ($left eq 'false') { $left = "" if !HAS_36 } + + my $m1 = match qr/\AAssertion failed \($left $op $right\)/; + my $m2 = match qr/\AAssertion failed \("$left" $op $right\)/; + my $m3 = match qr/\AAssertion failed \("$left" $op "$right"\)/; + return in_set($m, $m1, $m2, $m3); +} + +1; From f5b5d699c5bd743ebaec0214335a3eb951ed8e43 Mon Sep 17 00:00:00 2001 From: kobaken Date: Wed, 18 Dec 2024 08:59:27 +0900 Subject: [PATCH 2/6] Added isa --- lib/Syntax/Keyword/Assert.xs | 8 ++++++++ t/01_assert/isa.t | 15 +++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 t/01_assert/isa.t diff --git a/lib/Syntax/Keyword/Assert.xs b/lib/Syntax/Keyword/Assert.xs index b07fb38..c3b838d 100644 --- a/lib/Syntax/Keyword/Assert.xs +++ b/lib/Syntax/Keyword/Assert.xs @@ -71,6 +71,7 @@ enum BinopType { BINOP_STR_GT, BINOP_STR_LE, BINOP_STR_GE, + BINOP_ISA, }; static enum BinopType classify_binop(int type) @@ -88,6 +89,7 @@ static enum BinopType classify_binop(int type) case OP_SGT: return BINOP_STR_GT; case OP_SLE: return BINOP_STR_LE; case OP_SGE: return BINOP_STR_GE; + case OP_ISA: return BINOP_ISA; } return BINOP_NONE; } @@ -187,6 +189,12 @@ static OP *pp_assertbin(pTHX) op_str = "ge"; break; + case BINOP_ISA: + if(sv_isa_sv(lhs, rhs)) + goto ok; + + op_str = "isa"; + break; default: croak("ARGH unreachable"); } diff --git a/t/01_assert/isa.t b/t/01_assert/isa.t new file mode 100644 index 0000000..2228ee6 --- /dev/null +++ b/t/01_assert/isa.t @@ -0,0 +1,15 @@ +use Test2::V0; +use Syntax::Keyword::Assert; + +use lib 't/lib'; +use TestUtil; + +use Test2::Require::Module 'feature' => '1.45'; + +use experimental 'isa'; + +my $obj = bless {}, 'Foo'; +ok lives { assert($obj isa Foo) }; +ok dies { assert($obj isa Bar) }, expected_assert_bin('Foo', 'isa', 'Bar'); + +done_testing; From 2456bea8291ff7e5a447e01546f740d05efb5995 Mon Sep 17 00:00:00 2001 From: kobaken Date: Wed, 18 Dec 2024 09:18:16 +0900 Subject: [PATCH 3/6] Run `isa` assert with perl unser 5.31.7 --- hax/isa.c.inc | 3 +++ lib/Syntax/Keyword/Assert.xs | 4 ++++ 2 files changed, 7 insertions(+) create mode 100644 hax/isa.c.inc diff --git a/hax/isa.c.inc b/hax/isa.c.inc new file mode 100644 index 0000000..0b10ba3 --- /dev/null +++ b/hax/isa.c.inc @@ -0,0 +1,3 @@ +#ifndef OP_ISA +# define OP_ISA 0 // 0 means BINOP_NONE +#endif diff --git a/lib/Syntax/Keyword/Assert.xs b/lib/Syntax/Keyword/Assert.xs index c3b838d..79f9871 100644 --- a/lib/Syntax/Keyword/Assert.xs +++ b/lib/Syntax/Keyword/Assert.xs @@ -12,6 +12,7 @@ #include "sv_numeq.c.inc" #include "sv_numcmp.c.inc" #include "sv_streq.c.inc" +#include "isa.c.inc" static bool assert_enabled = TRUE; @@ -189,12 +190,15 @@ static OP *pp_assertbin(pTHX) op_str = "ge"; break; +#if HAVE_PERL_VERSION(5,31,7) case BINOP_ISA: if(sv_isa_sv(lhs, rhs)) goto ok; op_str = "isa"; break; +#endif + default: croak("ARGH unreachable"); } From 17acdc38bfadf014d5cd0514c7aeaaffcf096510 Mon Sep 17 00:00:00 2001 From: kobaken Date: Wed, 18 Dec 2024 09:20:43 +0900 Subject: [PATCH 4/6] Fixed feature version --- t/01_assert/isa.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/01_assert/isa.t b/t/01_assert/isa.t index 2228ee6..ff8c4bb 100644 --- a/t/01_assert/isa.t +++ b/t/01_assert/isa.t @@ -4,7 +4,7 @@ use Syntax::Keyword::Assert; use lib 't/lib'; use TestUtil; -use Test2::Require::Module 'feature' => '1.45'; +use Test2::Require::Module 'feature' => '1.58'; use experimental 'isa'; From 7f57de1f3b1b664dc09b050898e128eb45437dd5 Mon Sep 17 00:00:00 2001 From: kobaken Date: Wed, 18 Dec 2024 09:24:16 +0900 Subject: [PATCH 5/6] Added example of isa assertion --- README.md | 1 + lib/Syntax/Keyword/Assert.pm | 1 + 2 files changed, 2 insertions(+) diff --git a/README.md b/README.md index ff9b423..9f0bccd 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ Here are some examples: assert("apple" eq "banana"); # => Assertion failed ("apple" eq "banana") assert(123 != 123); # => Assertion failed (123 != 123) assert(1 > 10); # => Assertion failed (1 > 10) +assert($foo isa Bar); # => Assertion failed (Foo=HASH(0x11e022818) isa "Bar" ``` # SEE ALSO diff --git a/lib/Syntax/Keyword/Assert.pm b/lib/Syntax/Keyword/Assert.pm index d683ec9..3fe8cfb 100644 --- a/lib/Syntax/Keyword/Assert.pm +++ b/lib/Syntax/Keyword/Assert.pm @@ -76,6 +76,7 @@ Here are some examples: assert("apple" eq "banana"); # => Assertion failed ("apple" eq "banana") assert(123 != 123); # => Assertion failed (123 != 123) assert(1 > 10); # => Assertion failed (1 > 10) + assert($foo isa Bar); # => Assertion failed (Foo=HASH(0x11e022818) isa "Bar" =head1 SEE ALSO From f3bb24c661a81eb0a62b63ae1641db1a0331284f Mon Sep 17 00:00:00 2001 From: kobaken Date: Wed, 18 Dec 2024 09:27:15 +0900 Subject: [PATCH 6/6] Fixed SYNOPSIS --- README.md | 6 +++--- lib/Syntax/Keyword/Assert.pm | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9f0bccd..e02fd1d 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,9 @@ Syntax::Keyword::Assert - assert keyword for Perl with zero runtime cost ```perl use Syntax::Keyword::Assert; -assert { 1 >= 10 }; -# => Assertion failed (1 >= 10) +my $obj = bless {}, "Foo"; +assert($obj isa "Bar"); +# => Assertion failed (Foo=HASH(0x11e022818) isa "Bar") ``` # DESCRIPTION @@ -40,7 +41,6 @@ Here are some examples: assert("apple" eq "banana"); # => Assertion failed ("apple" eq "banana") assert(123 != 123); # => Assertion failed (123 != 123) assert(1 > 10); # => Assertion failed (1 > 10) -assert($foo isa Bar); # => Assertion failed (Foo=HASH(0x11e022818) isa "Bar" ``` # SEE ALSO diff --git a/lib/Syntax/Keyword/Assert.pm b/lib/Syntax/Keyword/Assert.pm index 3fe8cfb..1be21ff 100644 --- a/lib/Syntax/Keyword/Assert.pm +++ b/lib/Syntax/Keyword/Assert.pm @@ -50,8 +50,9 @@ Syntax::Keyword::Assert - assert keyword for Perl with zero runtime cost use Syntax::Keyword::Assert; - assert { 1 >= 10 }; - # => Assertion failed (1 >= 10) + my $obj = bless {}, "Foo"; + assert($obj isa "Bar"); + # => Assertion failed (Foo=HASH(0x11e022818) isa "Bar") =head1 DESCRIPTION @@ -76,7 +77,6 @@ Here are some examples: assert("apple" eq "banana"); # => Assertion failed ("apple" eq "banana") assert(123 != 123); # => Assertion failed (123 != 123) assert(1 > 10); # => Assertion failed (1 > 10) - assert($foo isa Bar); # => Assertion failed (Foo=HASH(0x11e022818) isa "Bar" =head1 SEE ALSO