#!perl # THIS IS A WORK IN PROGRESS # IT SHOULD BE CONSIDERED ALPHA # BUT I EXPECT IT TO IMPROVE # THIS IS A RE-IMPLEMENTATION OF PREVIOUS CODE THAT WAS WRITTEN # ON-THE-FLY AS NEEDED. # YOU ARE ADVISED TO RUN THE TEST SCRIPT!!! use strict; use warnings; use Test::More; use Data::Dumper; use Smart::Comments; use feature qw(state say); BEGIN { ### - ### ----------- ### - ### TESTS BEGIN ### - ### ----------- ### - use_ok ( 'File::Copy' ); use_ok ( 'Carp' ); use_ok ( 'Debug::Xray', qw( start_sub end_sub dprint set_debug_verbose hook_subs add_watch_var errorHandler warnHandler is_carp_debug ) ) or die 'Can\'t use Debug::Xray'; use_ok ( 'IO::CaptureOutput', qw(capture capture_exec) ); #use_ok ( 'Debug::Xray::WatchScalar' ) or die 'Can\t use Debug::Xray::WatchScalar'; }; ### Validate my module construction by trying out skeletal modules if (0) { use_ok ( 'Minimal', qw(i_am_here) ) or die 'Something wrong with module access'; # Can I even use a module in this directory? use_ok ( 'Minimal2::Minimal3', qw(i_am_here_3) ) or die 'Something wrong with module access'; # Can I even use a module in this directory? can_ok ( 'Minimal' , 'i_am_here' ) or die 'Something wrong with module access - exiting'; can_ok ( 'main' , 'i_am_here' ) or die 'Something wrong with module access - exiting'; is ( Minimal::i_am_here() , 'I am here' ) or die 'Something wrong with module access - exiting'; is ( i_am_here() , 'I am here' ) or die 'Something wrong with module access - exiting'; can_ok ( 'Minimal2::Minimal3' , 'i_am_here_3' ) or die 'Something wrong with module access - exiting'; can_ok ( 'main' , 'i_am_here_3' ) or die 'Something wrong with module access - exiting'; is ( Minimal2::Minimal3::i_am_here_3() , 'I am here 3' ) or die 'Something wrong with module access - exiting'; is ( i_am_here_3() , 'I am here 3' ) or die 'Something wrong with module access - exiting'; ### Minimal module tests passed } ### Validate subroutine access... { can_ok ('Debug::Xray', 'start_sub' ) or die 'Can\'t start_sub - exiting'; can_ok ('main', 'start_sub' ) or die 'Can\'t start_sub - exiting'; can_ok ('Debug::Xray', 'set_debug_verbose' ) or die 'Can\'t set_debug_verbose - exiting'; can_ok ('main', 'set_debug_verbose' ) or die 'Can\'t set_debug_verbose - exiting'; can_ok ('Debug::Xray', 'dprint' ) or die 'Can\'t dprint - exiting'; can_ok ('main', 'dprint' ) or die 'Can\'t dprint - exiting'; } ### Die if Debug is not configured to run this script... { is ( Debug::Xray::is_verbose() , 1 , 'Debug::Xray is verbose' ) or die 'Debug::Xray must be verbose'; is ( Debug::Xray::dprint('this is a test'), 'this is a test', 'Debug::Xray::dprint ok' ) or die 'Can\t dprint'; is ( Debug::Xray::dprint('this is a test'), 'this is a test', 'Debug::Xray::dprint ok' ) or die 'Can\t dprint'; ok ( is_carp_debug, 'Carp::Assert on' ) or die 'Carp::Assert must be turned on in Xray to run tests'; } ### Test Hooks... { { my $expected_sub_1_output = <new(); # or my $stack = caller_stack(); # Get all callers my @callers = $stack->all_list(); # Limit to specific callers: $stack->filter( 'line', 100 ); $stack->filter( 'subroutine', qr/mysub$/ ); $stack->filter( 'package', 'My::Package' ); #my @specific_callers = $stack->filtered_list() while ( my $level = $stack->next ) { warn $level; } } ### You are advised to turn off assertions in Debug/Xray.pm... ### Change the line that uses Carp's Assert module; Change 'use ' to 'no' ### Assertions must be on to run this test script... ### End of test script... done_testing(); sub sub_1 { start_sub(); dprint ('this is sub 1'); sub_2(); end_sub(); } sub sub_2 { start_sub(); dprint ('this is sub 2'); sub_3(); end_sub(); } sub sub_3 { start_sub(); dprint ('this is sub 3'); end_sub(); } sub sub_4 { start_sub(); dprint ('this is sub 4'); end_sub(); } sub sub_10 { dprint ('this is sub 10'); sub_20(); } sub sub_20 { dprint ('this is sub 20'); sub_30(); } sub sub_30 { dprint ('this is sub 30'); sub_40(); } sub sub_40 { }