From 8d1681dbfc3f09c2774779f4b717d8dfc09a5ccb Mon Sep 17 00:00:00 2001 From: "Eric A. Miller" Date: Thu, 26 Apr 2018 20:48:02 -0400 Subject: [PATCH] Validate funcs and globals rather than using can() to avoid unintended side effects --- xt/lib/My/Test/Class.pm | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/xt/lib/My/Test/Class.pm b/xt/lib/My/Test/Class.pm index 83d3ec0f..e4bd6683 100644 --- a/xt/lib/My/Test/Class.pm +++ b/xt/lib/My/Test/Class.pm @@ -122,13 +122,19 @@ sub globals : Tests(2) { can_ok($test->{info}, 'globals'); - subtest 'Globals can() subtest' => sub { + subtest 'Globals validate subtest' => sub { my $test_globals = $test->{info}->globals; if (scalar keys %$test_globals) { foreach my $key (sort (keys %$test_globals)) { - can_ok($test->{info}, $key); + + # Note: was going to use can_ok() as test method, but can() will insert + # AUTOLOAD methods such as the Globals and Funcs into the symbol table. + # This causes conflicts with the library inheritance scheme and + # manifests itself seemingly random test failures + ok($test->{info}->_validate_autoload_method($key), + qq('$key' validates)); } } else { @@ -142,13 +148,19 @@ sub funcs : Tests(2) { can_ok($test->{info}, 'funcs'); - subtest 'Funcs can() subtest' => sub { + subtest 'Funcs validate subtest' => sub { my $test_funcs = $test->{info}->funcs; if (scalar keys %$test_funcs) { foreach my $key (sort (keys %$test_funcs)) { - can_ok($test->{info}, $key); + + # Note: was going to use can_ok() as test method, but can() will insert + # AUTOLOAD methods such as the Globals and Funcs into the symbol table. + # This causes conflicts with the library inheritance scheme and + # manifests itself seemingly random test failures + ok($test->{info}->_validate_autoload_method($key), + qq('$key' validates)); } } else {