From 4dacd8269a0739c1677a5cc967b465eed76e8467 Mon Sep 17 00:00:00 2001 From: Matthew Hughes Date: Fri, 6 Mar 2020 20:21:01 +0000 Subject: [PATCH] Add warning when 'unmock' called without arguments --- lib/Test/MockModule.pm | 1 + t/mockmodule.t | 3 +++ 2 files changed, 4 insertions(+) diff --git a/lib/Test/MockModule.pm b/lib/Test/MockModule.pm index 73954f7..9082d71 100644 --- a/lib/Test/MockModule.pm +++ b/lib/Test/MockModule.pm @@ -157,6 +157,7 @@ sub original { sub unmock { my $self = shift; + carp 'Nothing to unmock' unless @_; for my $name (@_) { croak "Invalid subroutine name: $name" unless _valid_subname($name); diff --git a/t/mockmodule.t b/t/mockmodule.t index 03d9026..f0bf5c7 100644 --- a/t/mockmodule.t +++ b/t/mockmodule.t @@ -103,6 +103,9 @@ like($@, qr/Invalid package name/, ' ... croaks if package is undefined'); $mcgi->unmock('Vars'); like($warn, qr/ was not mocked/, "... warns if a subroutine isn't mocked"); + $mcgi->unmock(); + like($warn, qr/Nothing to unmock/, '... warns if no arguments passed to unmock'); + $mcgi->unmock('param'); is(\&{"ExampleModule::param"}, $orig_param, '... restores the original subroutine');