diff options
121 files changed, 2958 insertions, 12539 deletions
@@ -2233,212 +2233,146 @@ cpan/Test-Harness/t/yamlish-output.t Test::Harness test cpan/Test-Harness/t/yamlish.t Test::Harness test cpan/Test-Harness/t/yamlish-writer.t Test::Harness test cpan/Test/lib/Test.pm A simple framework for writing test scripts -cpan/Test-Simple/lib/ok.pm ok tool -cpan/Test-Simple/lib/Test/Builder/Event/Bail.pm Test::Builder module -cpan/Test-Simple/lib/Test/Builder/Event/Child.pm Test::Builder module -cpan/Test-Simple/lib/Test/Builder/Event/Diag.pm Test::Builder module -cpan/Test-Simple/lib/Test/Builder/Event/Finish.pm Test::Builder module -cpan/Test-Simple/lib/Test/Builder/Event/Note.pm Test::Builder module -cpan/Test-Simple/lib/Test/Builder/Event/Ok.pm Test::Builder module -cpan/Test-Simple/lib/Test/Builder/Event/Plan.pm Test::Builder module -cpan/Test-Simple/lib/Test/Builder/Event.pm Test::Builder module -cpan/Test-Simple/lib/Test/Builder/ExitMagic.pm Test::Builder module -cpan/Test-Simple/lib/Test/Builder/Fork.pm Test::Builder module -cpan/Test-Simple/lib/Test/Builder/Formatter/LegacyResults.pm Test::Builder module -cpan/Test-Simple/lib/Test/Builder/Formatter.pm Test::Builder module -cpan/Test-Simple/lib/Test/Builder/Formatter/TAP.pm Test::Builder module -cpan/Test-Simple/lib/Test/Builder/Module.pm Test::Builder module -cpan/Test-Simple/lib/Test/Builder.pm Test::Builder -cpan/Test-Simple/lib/Test/Builder/Provider.pm Test::Builder module -cpan/Test-Simple/lib/Test/Builder/Stream.pm Test::Builder module -cpan/Test-Simple/lib/Test/Builder/Tester/Color.pm Test::Builder module -cpan/Test-Simple/lib/Test/Builder/Tester.pm Test::Builder module -cpan/Test-Simple/lib/Test/Builder/Threads.pm Test::Builder module -cpan/Test-Simple/lib/Test/Builder/Trace/Frame.pm Test::Builder module -cpan/Test-Simple/lib/Test/Builder/Trace.pm Test::Builder module -cpan/Test-Simple/lib/Test/Builder/Util.pm Test::Builder module -cpan/Test-Simple/lib/Test/FAQ.pod Testing FAQ -cpan/Test-Simple/lib/Test/More.pm Test::More -cpan/Test-Simple/lib/Test/Simple.pm Test::Simple -cpan/Test-Simple/lib/Test/Tester2.pm Test::Tester2 -cpan/Test-Simple/lib/Test/Tester/Capture.pm Test::Tester module -cpan/Test-Simple/lib/Test/Tester/CaptureRunner.pm Test::Tester module -cpan/Test-Simple/lib/Test/Tester/Delegate.pm Test::Tester module -cpan/Test-Simple/lib/Test/Tester.pm Test::Tester -cpan/Test-Simple/lib/Test/Tutorial.pod Testing Tutorial -cpan/Test-Simple/lib/Test/use/ok.pm ok.pm documentation -cpan/Test-Simple/t/bad_plan.t Test-Simple test -cpan/Test-Simple/t/bail_out.t Test-Simple test -cpan/Test-Simple/t/BEGIN_require_ok.t Test-Simple test -cpan/Test-Simple/t/BEGIN_use_ok.t Test-Simple test -cpan/Test-Simple/t/buffer.t Test-Simple test -cpan/Test-Simple/t/Builder/Builder.t Test-Simple test -cpan/Test-Simple/t/Builder/carp.t Test-Simple test -cpan/Test-Simple/t/Builder/create.t Test-Simple test -cpan/Test-Simple/t/Builder/current_test.t Test-Simple test -cpan/Test-Simple/t/Builder/current_test_without_plan.t Test-Simple test -cpan/Test-Simple/t/Builder/details.t Test-Simple test -cpan/Test-Simple/t/Builder/done_testing_double.t Test-Simple test -cpan/Test-Simple/t/Builder/done_testing_plan_mismatch.t Test-Simple test -cpan/Test-Simple/t/Builder/done_testing.t Test-Simple test -cpan/Test-Simple/t/Builder/done_testing_with_no_plan.t Test-Simple test -cpan/Test-Simple/t/Builder/done_testing_with_number.t Test-Simple test -cpan/Test-Simple/t/Builder/done_testing_with_plan.t Test-Simple test -cpan/Test-Simple/t/Builder/fork_with_new_stdout.t Test-Simple test -cpan/Test-Simple/t/Builder/has_plan2.t Test-Simple test -cpan/Test-Simple/t/Builder/has_plan.t Test-Simple test -cpan/Test-Simple/t/Builder/is_fh.t Test-Simple test -cpan/Test-Simple/t/Builder/is_passing.t Test-Simple test -cpan/Test-Simple/t/Builder/maybe_regex.t Test-Simple test -cpan/Test-Simple/t/Builder/no_diag.t Test-Simple test -cpan/Test-Simple/t/Builder/no_ending.t Test-Simple test -cpan/Test-Simple/t/Builder/no_header.t Test-Simple test -cpan/Test-Simple/t/Builder/no_plan_at_all.t Test-Simple test -cpan/Test-Simple/t/Builder/ok_obj.t Test-Simple test -cpan/Test-Simple/t/Builder/output.t Test-Simple test -cpan/Test-Simple/t/Builder/reset_outputs.t Test-Simple test -cpan/Test-Simple/t/Builder/reset.t Test-Simple test -cpan/Test-Simple/t/Builder/try.t Test-Simple test -cpan/Test-Simple/t/c_flag.t Test-Simple test -cpan/Test-Simple/t/circular_data.t Test-Simple test -cpan/Test-Simple/t/cmp_ok.t Test-Simple test -cpan/Test-Simple/t/dependents.t Test-Simple test -cpan/Test-Simple/t/diag.t Test-Simple test -cpan/Test-Simple/t/died.t Test-Simple test -cpan/Test-Simple/t/dont_overwrite_die_handler.t Test-Simple test -cpan/Test-Simple/t/eq_set.t Test-Simple test -cpan/Test-Simple/t/exit.t Test-Simple test -cpan/Test-Simple/t/explain.t Test-Simple test -cpan/Test-Simple/t/extra_one.t Test-Simple test -cpan/Test-Simple/t/extra.t Test-Simple test -cpan/Test-Simple/t/fail-like.t Test-Simple test -cpan/Test-Simple/t/fail-more.t Test-Simple test -cpan/Test-Simple/t/fail_one.t Test-Simple test -cpan/Test-Simple/t/fail.t Test-Simple test -cpan/Test-Simple/t/filehandles.t Test-Simple test -cpan/Test-Simple/t/fork.t Test-Simple test -cpan/Test-Simple/t/harness_active.t Test-Simple test -cpan/Test-Simple/t/import.t Test-Simple test -cpan/Test-Simple/t/is_deeply_dne_bug.t Test-Simple test -cpan/Test-Simple/t/is_deeply_fail.t Test-Simple test -cpan/Test-Simple/t/is_deeply_with_threads.t Test-Simple test -cpan/Test-Simple/t/lib/Dev/Null.pm Test-Simple test -cpan/Test-Simple/t/lib/Dummy.pm Test-Simple test -cpan/Test-Simple/t/lib/MyOverload.pm Test-Simple test -cpan/Test-Simple/t/lib/MyTest.pm Test-Simple test -cpan/Test-Simple/t/lib/NoExporter.pm Test-Simple test -cpan/Test-Simple/t/lib/SigDie.pm Test-Simple test -cpan/Test-Simple/t/lib/SmallTest.pm Test-Simple test -cpan/Test-Simple/t/lib/Test/Builder/NoOutput.pm Test-Simple test -cpan/Test-Simple/t/lib/Test/Simple/Catch.pm Test-Simple test -cpan/Test-Simple/t/lib/Test/Simple/sample_tests/death_in_eval.plx Test-Simple test -cpan/Test-Simple/t/lib/Test/Simple/sample_tests/death.plx Test-Simple test -cpan/Test-Simple/t/lib/Test/Simple/sample_tests/death_with_handler.plx Test-Simple test -cpan/Test-Simple/t/lib/Test/Simple/sample_tests/exit.plx Test-Simple test -cpan/Test-Simple/t/lib/Test/Simple/sample_tests/extras.plx Test-Simple test -cpan/Test-Simple/t/lib/Test/Simple/sample_tests/five_fail.plx Test-Simple test -cpan/Test-Simple/t/lib/Test/Simple/sample_tests/last_minute_death.plx Test-Simple test -cpan/Test-Simple/t/lib/Test/Simple/sample_tests/missing_done_testing.plx Test-Simple test -cpan/Test-Simple/t/lib/Test/Simple/sample_tests/one_fail.plx Test-Simple test -cpan/Test-Simple/t/lib/Test/Simple/sample_tests/one_fail_without_plan.plx Test-Simple test -cpan/Test-Simple/t/lib/Test/Simple/sample_tests/pre_plan_death.plx Test-Simple test -cpan/Test-Simple/t/lib/Test/Simple/sample_tests/require.plx Test-Simple test -cpan/Test-Simple/t/lib/Test/Simple/sample_tests/success.plx Test-Simple test -cpan/Test-Simple/t/lib/Test/Simple/sample_tests/too_few_fail.plx Test-Simple test -cpan/Test-Simple/t/lib/Test/Simple/sample_tests/too_few.plx Test-Simple test -cpan/Test-Simple/t/lib/Test/Simple/sample_tests/two_fail.plx Test-Simple test -cpan/Test-Simple/t/lib/TieOut.pm Test-Simple test -cpan/Test-Simple/t/missing.t Test-Simple test -cpan/Test-Simple/t/Modern/Builder_Event_Child.t Test-Simple test -cpan/Test-Simple/t/Modern/Builder_Event_Diag.t Test-Simple test -cpan/Test-Simple/t/Modern/Builder_Event_Finish.t Test-Simple test -cpan/Test-Simple/t/Modern/Builder_Event_Note.t Test-Simple test -cpan/Test-Simple/t/Modern/Builder_Event_Ok.t Test-Simple test -cpan/Test-Simple/t/Modern/Builder_Event_Plan.t Test-Simple test -cpan/Test-Simple/t/Modern/Builder_Event.t Test-Simple test -cpan/Test-Simple/t/Modern/Builder_Fork.t Test-Simple test -cpan/Test-Simple/t/Modern/Builder_Formatter.t Test-Simple test -cpan/Test-Simple/t/Modern/Builder_Formatter_TAP.t Test-Simple test -cpan/Test-Simple/t/Modern/Builder_Module.t Test-Simple test -cpan/Test-Simple/t/Modern/Builder_Provider.t Test-Simple test -cpan/Test-Simple/t/Modern/Builder_Stream.t Test-Simple test -cpan/Test-Simple/t/Modern/Builder.t Test-Simple test -cpan/Test-Simple/t/Modern/Builder_Tester.t Test-Simple test -cpan/Test-Simple/t/Modern/Builder_Trace_Frame.t Test-Simple test -cpan/Test-Simple/t/Modern/Builder_Trace.t Test-Simple test -cpan/Test-Simple/t/Modern/Builder_Util.t Test-Simple test -cpan/Test-Simple/t/Modern/encoding_test.t Test-Simple test -cpan/Test-Simple/t/Modern/More.t Test-Simple test -cpan/Test-Simple/t/Modern/NotTB15.t Test-Simple test -cpan/Test-Simple/t/Modern/Simple.t Test-Simple test -cpan/Test-Simple/t/Modern/Tester2_subtest.t Test-Simple test -cpan/Test-Simple/t/Modern/Tester2.t Test-Simple test -cpan/Test-Simple/t/Modern/tracing.t Test-Simple test -cpan/Test-Simple/t/More.t Test-Simple test -cpan/Test-Simple/t/new_ok.t Test-Simple test -cpan/Test-Simple/t/no_plan.t Test-Simple test -cpan/Test-Simple/t/no_tests.t Test-Simple test -cpan/Test-Simple/t/note.t Test-Simple test -cpan/Test-Simple/t/overload.t Test-Simple test -cpan/Test-Simple/t/overload_threads.t Test-Simple test -cpan/Test-Simple/t/PerlIO.t Test-Simple test -cpan/Test-Simple/t/plan_bad.t Test-Simple test -cpan/Test-Simple/t/plan_is_noplan.t Test-Simple test -cpan/Test-Simple/t/plan_no_plan.t Test-Simple test -cpan/Test-Simple/t/plan_shouldnt_import.t Test-Simple test -cpan/Test-Simple/t/plan_skip_all.t Test-Simple test -cpan/Test-Simple/t/plan.t Test-Simple test -cpan/Test-Simple/t/pod.t Test-Simple test -cpan/Test-Simple/t/require_ok.t Test-Simple test -cpan/Test-Simple/t/ribasushi_diag.t Test-Simple test -cpan/Test-Simple/t/ribasushi_threads.t Test-Simple test -cpan/Test-Simple/t/Simple/load.t Test-Simple test -cpan/Test-Simple/t/simple.t Test-Simple test -cpan/Test-Simple/t/skipall.t Test-Simple test -cpan/Test-Simple/t/skip.t Test-Simple test -cpan/Test-Simple/t/strays.t Test-Simple test -cpan/Test-Simple/t/subtest/args.t Test-Simple test -cpan/Test-Simple/t/subtest/bail_out.t Test-Simple test -cpan/Test-Simple/t/subtest/basic.t Test-Simple test -cpan/Test-Simple/t/subtest/die.t Test-Simple test -cpan/Test-Simple/t/subtest/do.t Test-Simple test -cpan/Test-Simple/t/subtest/exceptions.t Test-Simple test -cpan/Test-Simple/t/subtest/for_do_t.test Test-Simple test -cpan/Test-Simple/t/subtest/fork.t Test-Simple test -cpan/Test-Simple/t/subtest/implicit_done.t Test-Simple test -cpan/Test-Simple/t/subtest/line_numbers.t Test-Simple test -cpan/Test-Simple/t/subtest/plan.t Test-Simple test -cpan/Test-Simple/t/subtest/predicate.t Test-Simple test -cpan/Test-Simple/t/subtest/singleton.t Test-Simple test -cpan/Test-Simple/t/subtest/threads.t Test-Simple test -cpan/Test-Simple/t/subtest/todo.t Test-Simple test -cpan/Test-Simple/t/subtest/wstat.t Test-Simple test -cpan/Test-Simple/t/tbm_doesnt_set_exported_to.t Test-Simple test -cpan/Test-Simple/t/Tester/tbt_01basic.t Test-Simple test -cpan/Test-Simple/t/Tester/tbt_02fhrestore.t Test-Simple test -cpan/Test-Simple/t/Tester/tbt_03die.t Test-Simple test -cpan/Test-Simple/t/Tester/tbt_04line_num.t Test-Simple test -cpan/Test-Simple/t/Tester/tbt_05faildiag.t Test-Simple test -cpan/Test-Simple/t/Tester/tbt_06errormess.t Test-Simple test -cpan/Test-Simple/t/Tester/tbt_07args.t Test-Simple test -cpan/Test-Simple/t/Tester/tbt_08subtest.t Test-Simple test -cpan/Test-Simple/t/Tester/tbt_09do_script.pl Test-Simple test -cpan/Test-Simple/t/Tester/tbt_09do.t Test-Simple test -cpan/Test-Simple/t/Tester/tbt_is_bug.t Test-Simple test -cpan/Test-Simple/t/test_use_ok.t Test-Simple test -cpan/Test-Simple/t/threads.t Test-Simple test -cpan/Test-Simple/t/thread_taint.t Test-Simple test -cpan/Test-Simple/t/todo.t Test-Simple test -cpan/Test-Simple/t/TTLegacy/auto.t Test-Simple test -cpan/Test-Simple/t/TTLegacy/capture.t Test-Simple test -cpan/Test-Simple/t/TTLegacy/check_tests.t Test-Simple test -cpan/Test-Simple/t/TTLegacy/depth.t Test-Simple test -cpan/Test-Simple/t/TTLegacy/run_test.t Test-Simple test -cpan/Test-Simple/t/undef.t Test-Simple test -cpan/Test-Simple/t/useing.t Test-Simple test -cpan/Test-Simple/t/use_ok.t Test-Simple test -cpan/Test-Simple/t/utf8.t Test-Simple test -cpan/Test-Simple/t/versions.t Test-Simple test +cpan/Test-Simple/lib/Test/Builder/Module.pm Base class for test modules +cpan/Test-Simple/lib/Test/Builder.pm For writing new test libraries +cpan/Test-Simple/lib/Test/Builder/Tester/Color.pm Turn on color in Test::Builder::Tester +cpan/Test-Simple/lib/Test/Builder/Tester.pm For testing Test::Builder based classes +cpan/Test-Simple/lib/Test/More.pm More utilities for writing tests +cpan/Test-Simple/lib/Test/Simple.pm Basic utility for writing tests +cpan/Test-Simple/lib/Test/Tutorial.pod A tutorial on writing tests +cpan/Test-Simple/t/00test_harness_check.t Test::Simple test +cpan/Test-Simple/t/bad_plan.t Test::Builder plan() test +cpan/Test-Simple/t/bail_out.t Test::Builder BAIL_OUT test +cpan/Test-Simple/t/BEGIN_require_ok.t Test::More require_ok() testing +cpan/Test-Simple/t/BEGIN_use_ok.t Test::More use_ok() testing +cpan/Test-Simple/t/buffer.t Test::Builder buffering test +cpan/Test-Simple/t/Builder/Builder.t Test::Builder tests +cpan/Test-Simple/t/Builder/carp.t Test::Builder test +cpan/Test-Simple/t/Builder/create.t Test::Builder test +cpan/Test-Simple/t/Builder/current_test.t Test::Builder tests +cpan/Test-Simple/t/Builder/current_test_without_plan.t Test::Builder tests +cpan/Test-Simple/t/Builder/details.t Test::Builder tests +cpan/Test-Simple/t/Builder/done_testing_double.t Test::Builder tests +cpan/Test-Simple/t/Builder/done_testing_plan_mismatch.t Test::Builder tests +cpan/Test-Simple/t/Builder/done_testing.t Test::Builder tests +cpan/Test-Simple/t/Builder/done_testing_with_no_plan.t Test::Builder tests +cpan/Test-Simple/t/Builder/done_testing_with_number.t Test::Builder tests +cpan/Test-Simple/t/Builder/done_testing_with_plan.t Test::Builder tests +cpan/Test-Simple/t/Builder/fork_with_new_stdout.t Test::Builder tests +cpan/Test-Simple/t/Builder/has_plan2.t Test::Builder tests +cpan/Test-Simple/t/Builder/has_plan.t Test::Builder tests +cpan/Test-Simple/t/Builder/is_fh.t Test::Builder tests +cpan/Test-Simple/t/Builder/is_passing.t Test::Builder tests +cpan/Test-Simple/t/Builder/maybe_regex.t Test::Builder tests +cpan/Test-Simple/t/Builder/no_diag.t Test::Builder tests +cpan/Test-Simple/t/Builder/no_ending.t Test::Builder tests +cpan/Test-Simple/t/Builder/no_header.t Test::Builder tests +cpan/Test-Simple/t/Builder/no_plan_at_all.t Test::Builder tests +cpan/Test-Simple/t/Builder/ok_obj.t Test::Builder tests +cpan/Test-Simple/t/Builder/output.t Test::Builder tests +cpan/Test-Simple/t/Builder/reset.t Test::Builder tests +cpan/Test-Simple/t/Builder/try.t Test::Builder tests +cpan/Test-Simple/t/c_flag.t Test::Simple test +cpan/Test-Simple/t/circular_data.t Test::Simple test +cpan/Test-Simple/t/cmp_ok.t Test::More test +cpan/Test-Simple/t/dependents.t Test::More test +cpan/Test-Simple/t/diag.t Test::More diag() test +cpan/Test-Simple/t/died.t Test::Simple test +cpan/Test-Simple/t/dont_overwrite_die_handler.t Test::More tests +cpan/Test-Simple/t/eq_set.t Test::Simple test +cpan/Test-Simple/t/exit.t Test::Simple test, exit codes +cpan/Test-Simple/t/explain.t Test::Simple test +cpan/Test-Simple/t/extra_one.t Test::Simple test +cpan/Test-Simple/t/extra.t Test::Simple test +cpan/Test-Simple/t/fail-like.t Test::More test, like() failures +cpan/Test-Simple/t/fail-more.t Test::More test, tests failing +cpan/Test-Simple/t/fail_one.t Test::Simple test +cpan/Test-Simple/t/fail.t Test::Simple test, test failures +cpan/Test-Simple/t/filehandles.t Test::Simple test, STDOUT can be played with +cpan/Test-Simple/t/fork.t Test::More fork tests +cpan/Test-Simple/t/harness_active.t Test::Simple test +cpan/Test-Simple/t/import.t Test::More test, importing functions +cpan/Test-Simple/t/is_deeply_dne_bug.t Test::More test +cpan/Test-Simple/t/is_deeply_fail.t Test::More test, is_deeply() +cpan/Test-Simple/t/is_deeply_with_threads.t Test::More test +cpan/Test-Simple/t/lib/Dev/Null.pm Test::More test module +cpan/Test-Simple/t/lib/Dummy.pm Test::More test module +cpan/Test-Simple/t/lib/MyOverload.pm Test::More test module +cpan/Test-Simple/t/lib/NoExporter.pm Test::Simple test module +cpan/Test-Simple/t/lib/SigDie.pm Test module for Test::More +cpan/Test-Simple/t/lib/Test/Builder/NoOutput.pm Utility module for testing Test::Builder +cpan/Test-Simple/t/lib/Test/Simple/Catch.pm Utility module for testing Test::Simple +cpan/Test-Simple/t/lib/Test/Simple/sample_tests/death_in_eval.plx for exit.t +cpan/Test-Simple/t/lib/Test/Simple/sample_tests/death.plx for exit.t +cpan/Test-Simple/t/lib/Test/Simple/sample_tests/death_with_handler.plx for exit.t +cpan/Test-Simple/t/lib/Test/Simple/sample_tests/exit.plx for exit.t +cpan/Test-Simple/t/lib/Test/Simple/sample_tests/extras.plx for exit.t +cpan/Test-Simple/t/lib/Test/Simple/sample_tests/five_fail.plx for exit.t +cpan/Test-Simple/t/lib/Test/Simple/sample_tests/last_minute_death.plx for exit.t +cpan/Test-Simple/t/lib/Test/Simple/sample_tests/missing_done_testing.plx for exit.t +cpan/Test-Simple/t/lib/Test/Simple/sample_tests/one_fail.plx for exit.t +cpan/Test-Simple/t/lib/Test/Simple/sample_tests/one_fail_without_plan.plx for exit.t +cpan/Test-Simple/t/lib/Test/Simple/sample_tests/pre_plan_death.plx for exit.t +cpan/Test-Simple/t/lib/Test/Simple/sample_tests/require.plx for exit.t +cpan/Test-Simple/t/lib/Test/Simple/sample_tests/success.plx for exit.t +cpan/Test-Simple/t/lib/Test/Simple/sample_tests/too_few_fail.plx for exit.t +cpan/Test-Simple/t/lib/Test/Simple/sample_tests/too_few.plx for exit.t +cpan/Test-Simple/t/lib/Test/Simple/sample_tests/two_fail.plx for exit.t +cpan/Test-Simple/t/lib/TieOut.pm Testing library to capture prints +cpan/Test-Simple/t/missing.t Test::Simple test, missing tests +cpan/Test-Simple/t/More.t Test::More test, basic stuff +cpan/Test-Simple/t/new_ok.t Test::More test +cpan/Test-Simple/t/no_plan.t Test::Simple test, forgot the plan +cpan/Test-Simple/t/no_tests.t Test::More test +cpan/Test-Simple/t/note.t Test::More test +cpan/Test-Simple/t/overload.t Test::Simple test +cpan/Test-Simple/t/overload_threads.t Test::Simple test +cpan/Test-Simple/t/plan_bad.t Test::Simple test +cpan/Test-Simple/t/plan_is_noplan.t Test::Simple test, no_plan +cpan/Test-Simple/t/plan_no_plan.t Test::More test, plan() w/no_plan +cpan/Test-Simple/t/plan_shouldnt_import.t Test::Simple test +cpan/Test-Simple/t/plan_skip_all.t Test::More test, plan() w/skip_all +cpan/Test-Simple/t/plan.t Test::More test, plan() +cpan/Test-Simple/t/require_ok.t Test::Simple test +cpan/Test-Simple/t/Simple/load.t Test::Builder tests +cpan/Test-Simple/t/simple.t Test::Simple test, basic stuff +cpan/Test-Simple/t/skipall.t Test::More test, skip all tests +cpan/Test-Simple/t/skip.t Test::More test, SKIP tests +cpan/Test-Simple/t/subtest/args.t Test::More test +cpan/Test-Simple/t/subtest/bail_out.t Test::More test +cpan/Test-Simple/t/subtest/basic.t Test::More test +cpan/Test-Simple/t/subtest/die.t Test::More test +cpan/Test-Simple/t/subtest/do.t Test::More test +cpan/Test-Simple/t/subtest/exceptions.t Test::More test +cpan/Test-Simple/t/subtest/for_do_t.test Test::More test +cpan/Test-Simple/t/subtest/fork.t Test::Builder tests +cpan/Test-Simple/t/subtest/implicit_done.t Test::Builder tests +cpan/Test-Simple/t/subtest/line_numbers.t Test::Builder tests +cpan/Test-Simple/t/subtest/plan.t Test::Builder tests +cpan/Test-Simple/t/subtest/predicate.t Test::Builder tests +cpan/Test-Simple/t/subtest/singleton.t Test::More test +cpan/Test-Simple/t/subtest/threads.t Test::More test +cpan/Test-Simple/t/subtest/todo.t Test::Builder tests +cpan/Test-Simple/t/subtest/wstat.t Test::More test +cpan/Test-Simple/t/tbm_doesnt_set_exported_to.t Test::Builder::Module test +cpan/Test-Simple/t/Tester/tbt_01basic.t Test::Builder::Tester test +cpan/Test-Simple/t/Tester/tbt_02fhrestore.t Test::Builder::Tester test +cpan/Test-Simple/t/Tester/tbt_03die.t Test::Builder::Tester test +cpan/Test-Simple/t/Tester/tbt_04line_num.t Test::Builder::Tester test +cpan/Test-Simple/t/Tester/tbt_05faildiag.t Test::Builder::Tester test +cpan/Test-Simple/t/Tester/tbt_06errormess.t Test::Builder::Tester test +cpan/Test-Simple/t/Tester/tbt_07args.t Test::Builder::Tester test +cpan/Test-Simple/t/Tester/tbt_08subtest.t Test::Builder::Tester test +cpan/Test-Simple/t/Tester/tbt_09do_script.pl Test::Builder::Tester test +cpan/Test-Simple/t/Tester/tbt_09do.t Test::Builder::Tester test +cpan/Test-Simple/t/threads.t Test::Builder thread-safe checks +cpan/Test-Simple/t/thread_taint.t Test::Simple test +cpan/Test-Simple/t/todo.t Test::More test, TODO tests +cpan/Test-Simple/t/undef.t Test::More test, undefs don't cause warnings +cpan/Test-Simple/t/useing.t Test::More test, compile test +cpan/Test-Simple/t/use_ok.t Test::More test, use_ok() +cpan/Test-Simple/t/utf8.t Test::More test +cpan/Test-Simple/t/versions.t Test::More test cpan/Test/t/05_about_verbose.t See if Test works cpan/Test/t/fail.t See if Test works cpan/Test/t/mix.t See if Test works diff --git a/Makefile.SH b/Makefile.SH index e1e895c593..cbeed004ab 100755 --- a/Makefile.SH +++ b/Makefile.SH @@ -1297,9 +1297,7 @@ _cleaner2: -rmdir lib/autodie/Scope lib/autodie lib/XS lib/Win32API lib/VMS -rmdir lib/Unicode/Collate/Locale lib/Unicode/Collate/CJK -rmdir lib/Unicode/Collate lib/Tie/Hash lib/Thread lib/Text - -rmdir lib/Test/use lib/Test/Tester lib/Test/Builder/Trace - -rmdir lib/Test/Builder/Tester lib/Test/Builder/Formatter - -rmdir lib/Test/Builder/Event lib/Test/Builder lib/Test lib/Term + -rmdir lib/Test/Builder/Tester lib/Test/Builder lib/Test lib/Term -rmdir lib/TAP/Parser/YAMLish lib/TAP/Parser/SourceHandler -rmdir lib/TAP/Parser/Scheduler lib/TAP/Parser/Result -rmdir lib/TAP/Parser/Iterator lib/TAP/Parser lib/TAP/Harness diff --git a/cpan/Test-Simple/lib/Test/Builder.pm b/cpan/Test-Simple/lib/Test/Builder.pm index bd74daf5b8..00a3ec51ea 100644 --- a/cpan/Test-Simple/lib/Test/Builder.pm +++ b/cpan/Test-Simple/lib/Test/Builder.pm @@ -1,74 +1,153 @@ package Test::Builder; -use 5.008001; +use 5.006; use strict; use warnings; -use Test::Builder::Util qw/try protect/; -use Scalar::Util(); -use Test::Builder::Stream; -use Test::Builder::Event; -use Test::Builder::Event::Ok; -use Test::Builder::Event::Diag; -use Test::Builder::Event::Note; -use Test::Builder::Event::Plan; -use Test::Builder::Event::Bail; -use Test::Builder::Event::Child; -use Test::Builder::Trace; - -our $VERSION = '1.301001_040'; +our $VERSION = '1.001003'; $VERSION = eval $VERSION; ## no critic (BuiltinFunctions::ProhibitStringyEval) -# The mostly-singleton, and other package vars. -our $Test = Test::Builder->new; -our $Level = 1; -our $BLevel = 1; +BEGIN { + if( $] < 5.008 ) { + require Test::Builder::IO::Scalar; + } +} -#################### -# {{{ MAGIC things # -#################### -sub DESTROY { - my $self = shift; - if ( $self->parent and $$ == $self->{Original_Pid} ) { - my $name = $self->name; - $self->parent->{In_Destroy} = 1; - $self->parent->ok(0, $name, "Child ($name) exited without calling finalize()\n"); +# Make Test::Builder thread-safe for ithreads. +BEGIN { + use Config; + # Load threads::shared when threads are turned on. + # 5.8.0's threads are so busted we no longer support them. + if( $] >= 5.008001 && $Config{useithreads} && $INC{'threads.pm'} ) { + require threads::shared; + + # Hack around YET ANOTHER threads::shared bug. It would + # occasionally forget the contents of the variable when sharing it. + # So we first copy the data, then share, then put our copy back. + *share = sub (\[$@%]) { + my $type = ref $_[0]; + my $data; + + if( $type eq 'HASH' ) { + %$data = %{ $_[0] }; + } + elsif( $type eq 'ARRAY' ) { + @$data = @{ $_[0] }; + } + elsif( $type eq 'SCALAR' ) { + $$data = ${ $_[0] }; + } + else { + die( "Unknown type: " . $type ); + } + + $_[0] = &threads::shared::share( $_[0] ); + + if( $type eq 'HASH' ) { + %{ $_[0] } = %$data; + } + elsif( $type eq 'ARRAY' ) { + @{ $_[0] } = @$data; + } + elsif( $type eq 'SCALAR' ) { + ${ $_[0] } = $$data; + } + else { + die( "Unknown type: " . $type ); + } + + return $_[0]; + }; + } + # 5.8.0's threads::shared is busted when threads are off + # and earlier Perls just don't have that module at all. + else { + *share = sub { return $_[0] }; + *lock = sub { 0 }; } } -require Test::Builder::ExitMagic; -my $final = Test::Builder::ExitMagic->new( - tb => Test::Builder->create(shared_stream => 1), -); -END { $final->do_magic() } +=head1 NAME -#################### -# }}} MAGIC things # -#################### +Test::Builder - Backend for building test libraries -#################### -# {{{ Constructors # -#################### +=head1 SYNOPSIS -sub new { - my $class = shift; - my %params = @_; - $Test ||= $class->create(shared_stream => 1); + package My::Test::Module; + use base 'Test::Builder::Module'; + + my $CLASS = __PACKAGE__; + + sub ok { + my($test, $name) = @_; + my $tb = $CLASS->builder; + + $tb->ok($test, $name); + } + + +=head1 DESCRIPTION + +Test::Simple and Test::More have proven to be popular testing modules, +but they're not always flexible enough. Test::Builder provides a +building block upon which to write your own test libraries I<which can +work together>. + +=head2 Construction + +=over 4 +=item B<new> + + my $Test = Test::Builder->new; + +Returns a Test::Builder object representing the current state of the +test. + +Since you only run one test per program C<new> always returns the same +Test::Builder object. No matter how many times you call C<new()>, you're +getting the same object. This is called a singleton. This is done so that +multiple modules share such global information as the test counter and +where test output is going. + +If you want a completely new Test::Builder object different from the +singleton, use C<create>. + +=cut + +our $Test = Test::Builder->new; + +sub new { + my($class) = shift; + $Test ||= $class->create; return $Test; } +=item B<create> + + my $Test = Test::Builder->create; + +Ok, so there can be more than one Test::Builder object and this is how +you get it. You might use this instead of C<new()> if you're testing +a Test::Builder based module, but otherwise you probably want C<new>. + +B<NOTE>: the implementation is not complete. C<level>, for example, is +still shared amongst B<all> Test::Builder objects, even ones created using +this method. Also, the method name may change in the future. + +=cut + sub create { my $class = shift; - my %params = @_; my $self = bless {}, $class; - $self->reset(%params); + $self->reset; return $self; } + # Copy an object, currently a shallow. # This does *not* bless the destination. This keeps the destructor from # firing when we're just storing a copy of the object to restore later. @@ -76,154 +155,114 @@ sub _copy { my($src, $dest) = @_; %$dest = %$src; - #_share_keys($dest); # Not sure the implications here. + _share_keys($dest); return; } -#################### -# }}} Constructors # -#################### - -############################################## -# {{{ Simple accessors/generators/deligators # -############################################## - -sub listen { shift->stream->listen(@_) } -sub munge { shift->stream->munge(@_) } -sub tap { shift->stream->tap } -sub lresults { shift->stream->lresults } -sub is_passing { shift->stream->is_passing(@_) } -sub use_fork { shift->stream->use_fork } -sub no_fork { shift->stream->no_fork } - -BEGIN { - Test::Builder::Util::accessors(qw/Parent Name _old_level _bailed_out default_name/); - Test::Builder::Util::accessor(modern => sub {$ENV{TB_MODERN} || 0}); - Test::Builder::Util::accessor(depth => sub { 0 }); -} - -############################################## -# }}} Simple accessors/generators/deligators # -############################################## - -######################### -# {{{ Stream Management # -######################### - -sub stream { - my $self = shift; - - ($self->{stream}) = @_ if @_; - - # If no stream is set use shared. We do not want to cache that we use - # shared cause shared is a stack, not a constant, and we always want the - # top. - return $self->{stream} || Test::Builder::Stream->shared; -} - -sub intercept { - my $self = shift; - my ($code) = @_; - - Carp::croak("argument to intercept must be a coderef, got: $code") - unless reftype $code eq 'CODE'; - my $stream = Test::Builder::Stream->new(no_follow => 1) || die "Internal Error!"; - $stream->exception_followup; +=item B<child> - local $self->{stream} = $stream; + my $child = $builder->child($name_of_child); + $child->plan( tests => 4 ); + $child->ok(some_code()); + ... + $child->finalize; - my @events; - $stream->listen(INTERCEPTOR => sub { - my ($item) = @_; - push @events => $item; - }); - $code->($stream); +Returns a new instance of C<Test::Builder>. Any output from this child will +be indented four spaces more than the parent's indentation. When done, the +C<finalize> method I<must> be called explicitly. - return \@events; -} +Trying to create a new child with a previous child still active (i.e., +C<finalize> not called) will C<croak>. -######################### -# }}} Stream Management # -######################### +Trying to run a test when you have an open child will also C<croak> and cause +the test suite to fail. -############################# -# {{{ Children and subtests # -############################# +=cut sub child { - my( $self, $name, $is_subtest ) = @_; + my( $self, $name ) = @_; - $self->croak("You already have a child named ($self->{Child_Name}) running") - if $self->{Child_Name}; + if( $self->{Child_Name} ) { + $self->croak("You already have a child named ($self->{Child_Name}) running"); + } my $parent_in_todo = $self->in_todo; # Clear $TODO for the child. my $orig_TODO = $self->find_TODO(undef, 1, undef); - my $class = Scalar::Util::blessed($self); + my $class = ref $self; my $child = $class->create; - $child->{stream} = $self->stream->spawn; + # Add to our indentation + $child->_indent( $self->_indent . ' ' ); + + # Make the child use the same outputs as the parent + for my $method (qw(output failure_output todo_output)) { + $child->$method( $self->$method ); + } # Ensure the child understands if they're inside a TODO - $child->tap->failure_output($self->tap->todo_output) - if $parent_in_todo && $self->tap; + if( $parent_in_todo ) { + $child->failure_output( $self->todo_output ); + } # This will be reset in finalize. We do this here lest one child failure # cause all children to fail. $child->{Child_Error} = $?; $? = 0; - $child->{Parent} = $self; $child->{Parent_TODO} = $orig_TODO; $child->{Name} = $name || "Child of " . $self->name; - $self->{Child_Name} = $child->name; + return $child; +} - $child->depth($self->depth + 1); - my $res = Test::Builder::Event::Child->new( - $self->context, - name => $child->name, - action => 'push', - in_todo => $self->in_todo || 0, - is_subtest => $is_subtest || 0, - ); - $self->stream->send($res); +=item B<subtest> - return $child; -} + $builder->subtest($name, \&subtests); + +See documentation of C<subtest> in Test::More. + +=cut sub subtest { my $self = shift; - my($name, $subtests, @args) = @_; + my($name, $subtests) = @_; - $self->croak("subtest()'s second argument must be a code ref") - unless $subtests && 'CODE' eq Scalar::Util::reftype($subtests); + if ('CODE' ne ref $subtests) { + $self->croak("subtest()'s second argument must be a code ref"); + } # Turn the child into the parent so anyone who has stored a copy of # the Test::Builder singleton will get the child. - my ($success, $error, $child); + my $error; + my $child; my $parent = {}; { - local $Level = $Level + 1; local $BLevel = $BLevel + 1; + # child() calls reset() which sets $Level to 1, so we localize + # $Level first to limit the scope of the reset to the subtest. + local $Test::Builder::Level = $Test::Builder::Level + 1; # Store the guts of $self as $parent and turn $child into $self. - $child = $self->child($name, 1); - + $child = $self->child($name); _copy($self, $parent); _copy($child, $self); my $run_the_subtests = sub { - $subtests->(@args); - $self->done_testing unless defined $self->stream->plan; + # Add subtest name for clarification of starting point + $self->note("Subtest: $name"); + $subtests->(); + $self->done_testing unless $self->_plan_handled; 1; }; - ($success, $error) = try { Test::Builder::Trace->nest($run_the_subtests) }; + if( !eval { $run_the_subtests->() } ) { + $error = $@; + } } # Restore the parent and the copied child. @@ -234,19 +273,68 @@ sub subtest { $self->find_TODO(undef, 1, $child->{Parent_TODO}); # Die *after* we restore the parent. - die $error if $error && !(Scalar::Util::blessed($error) && $error->isa('Test::Builder::Exception')); + die $error if $error and !eval { $error->isa('Test::Builder::Exception') }; - local $Level = $Level + 1; local $BLevel = $BLevel + 1; - my $finalize = $child->finalize(1); + local $Test::Builder::Level = $Test::Builder::Level + 1; + my $finalize = $child->finalize; - $self->BAIL_OUT($child->{Bailed_Out_Reason}) if $child->_bailed_out; + $self->BAIL_OUT($child->{Bailed_Out_Reason}) if $child->{Bailed_Out}; return $finalize; } +=begin _private + +=item B<_plan_handled> + + if ( $Test->_plan_handled ) { ... } + +Returns true if the developer has explicitly handled the plan via: + +=over 4 + +=item * Explicitly setting the number of tests + +=item * Setting 'no_plan' + +=item * Set 'skip_all'. + +=back + +This is currently used in subtests when we implicitly call C<< $Test->done_testing >> +if the developer has not set a plan. + +=end _private + +=cut + +sub _plan_handled { + my $self = shift; + return $self->{Have_Plan} || $self->{No_Plan} || $self->{Skip_All}; +} + + +=item B<finalize> + + my $ok = $child->finalize; + +When your child is done running tests, you must call C<finalize> to clean up +and tell the parent your pass/fail status. + +Calling finalize on a child with open children will C<croak>. + +If the child falls out of scope before C<finalize> is called, a failure +diagnostic will be issued and the child is considered to have failed. + +No attempt to call methods on a child after C<finalize> is called is +guaranteed to succeed. + +Calling this on the root builder is a no-op. + +=cut + sub finalize { my $self = shift; - my ($is_subtest) = @_; return unless $self->parent; if( $self->{Child_Name} ) { @@ -256,738 +344,568 @@ sub finalize { local $? = 0; # don't fail if $subtests happened to set $? nonzero $self->_ending; - local $Level = $Level + 1; local $BLevel = $BLevel + 1; + # XXX This will only be necessary for TAP envelopes (we think) + #$self->_print( $self->is_passing ? "PASS\n" : "FAIL\n" ); + + local $Test::Builder::Level = $Test::Builder::Level + 1; my $ok = 1; $self->parent->{Child_Name} = undef; - - unless ($self->_bailed_out) { + unless ($self->{Bailed_Out}) { if ( $self->{Skip_All} ) { $self->parent->skip($self->{Skip_All}); } - elsif ( ! $self->stream->tests_run ) { + elsif ( not @{ $self->{Test_Results} } ) { $self->parent->ok( 0, sprintf q[No tests run for subtest "%s"], $self->name ); } else { $self->parent->ok( $self->is_passing, $self->name ); } } - $? = $self->{Child_Error}; - my $parent = delete $self->{Parent}; - - my $res = Test::Builder::Event::Child->new( - $self->context, - name => $self->{Name} || undef, - action => 'pop', - in_todo => $self->in_todo || 0, - is_subtest => $is_subtest || 0, - ); - $parent->stream->send($res); + delete $self->{Parent}; return $self->is_passing; } -############################# -# }}} Children and subtests # -############################# +sub _indent { + my $self = shift; -##################################### -# {{{ Finding Testers and Providers # -##################################### + if( @_ ) { + $self->{Indent} = shift; + } -sub trace_test { - my $self = shift; - return $self->{_trace_cache} if $self->{_trace_cache}; - my $out; - protect { $out = Test::Builder::Trace->new }; - return $out; + return $self->{Indent}; } -sub find_TODO { - my( $self, $where, $set, $new_value ) = @_; +=item B<parent> - my $pack; - if ($where && Scalar::Util::blessed($where) && $where->isa('Test::Builder::Trace')) { - $pack = $where->todo_package || $self->exported_to; - } - else { - $pack = $where || $self->trace_test->todo_package || $self->exported_to; - } + if ( my $parent = $builder->parent ) { + ... + } - return unless $pack; +Returns the parent C<Test::Builder> instance, if any. Only used with child +builders for nested TAP. - no strict 'refs'; ## no critic - no warnings 'once'; - my $old_value = ${ $pack . '::TODO' }; - $set and ${ $pack . '::TODO' } = $new_value; - return $old_value; -} +=cut -##################################### -# }}} Finding Testers and Providers # -##################################### +sub parent { shift->{Parent} } -################ -# {{{ Planning # -################ +=item B<name> -my %PLAN_CMDS = ( - no_plan => 'no_plan', - skip_all => 'skip_all', - tests => '_plan_tests', -); + diag $builder->name; -sub plan { - my( $self, $cmd, $arg ) = @_; +Returns the name of the current builder. Top level builders default to C<$0> +(the name of the executable). Child builders are named via the C<child> +method. If no name is supplied, will be named "Child of $parent->name". - return unless $cmd; +=cut - local $Level = $Level + 1; local $BLevel = $BLevel + 1; +sub name { shift->{Name} } - if( my $method = $PLAN_CMDS{$cmd} ) { - local $Level = $Level + 1; local $BLevel = $BLevel + 1; - $self->$method($arg); - } - else { - my @args = grep { defined } ( $cmd, $arg ); - $self->croak("plan() doesn't understand @args"); +sub DESTROY { + my $self = shift; + if ( $self->parent and $$ == $self->{Original_Pid} ) { + my $name = $self->name; + $self->diag(<<"FAIL"); +Child ($name) exited without calling finalize() +FAIL + $self->parent->{In_Destroy} = 1; + $self->parent->ok(0, $name); } - - return 1; } -sub skip_all { - my( $self, $reason ) = @_; +=item B<reset> - $self->{Skip_All} = $self->parent ? $reason : 1; + $Test->reset; - die bless {} => 'Test::Builder::Exception' if $self->parent; - $self->_issue_plan(0, "SKIP", $reason); -} +Reinitializes the Test::Builder singleton to its original state. +Mostly useful for tests run in persistent environments where the same +test might be run multiple times in the same process. -sub no_plan { - my($self, $arg) = @_; +=cut - $self->carp("no_plan takes no arguments") if $arg; +our $Level; - $self->_issue_plan(undef, "NO_PLAN"); +sub reset { ## no critic (Subroutines::ProhibitBuiltinHomonyms) + my($self) = @_; - return 1; -} + # We leave this a global because it has to be localized and localizing + # hash keys is just asking for pain. Also, it was documented. + $Level = 1; -sub _plan_tests { - my($self, $arg) = @_; + $self->{Name} = $0; + $self->is_passing(1); + $self->{Ending} = 0; + $self->{Have_Plan} = 0; + $self->{No_Plan} = 0; + $self->{Have_Output_Plan} = 0; + $self->{Done_Testing} = 0; - if($arg) { - $self->croak("Number of tests must be a positive integer. You gave it '$arg'") - unless $arg =~ /^\+?\d+$/; + $self->{Original_Pid} = $$; + $self->{Child_Name} = undef; + $self->{Indent} ||= ''; - $self->_issue_plan($arg); - } - elsif( !defined $arg ) { - $self->croak("Got an undefined number of tests"); - } - else { - $self->croak("You said to run 0 tests"); - } + $self->{Curr_Test} = 0; + $self->{Test_Results} = &share( [] ); - return; -} + $self->{Exported_To} = undef; + $self->{Expected_Tests} = 0; -sub _issue_plan { - my($self, $max, $directive, $reason) = @_; + $self->{Skip_All} = 0; - if ($directive && $directive eq 'OVERRIDE') { - $directive = undef; - } - elsif ($self->stream->plan) { - $self->croak("You tried to plan twice"); - } + $self->{Use_Nums} = 1; - my $plan = Test::Builder::Event::Plan->new( - $self->context, - directive => $directive || undef, - reason => $reason || undef, - in_todo => $self->in_todo || 0, + $self->{No_Header} = 0; + $self->{No_Ending} = 0; - max => defined($max) ? $max : undef, - ); + $self->{Todo} = undef; + $self->{Todo_Stack} = []; + $self->{Start_Todo} = 0; + $self->{Opened_Testhandles} = 0; - $self->stream->send($plan); + $self->_share_keys; + $self->_dup_stdhandles; - return $plan; + return; } -sub done_testing { - my($self, $num_tests) = @_; - my $expected = $self->stream->expected_tests; - my $total = $self->stream->tests_run; +# Shared scalar values are lost when a hash is copied, so we have +# a separate method to restore them. +# Shared references are retained across copies. +sub _share_keys { + my $self = shift; - # If done_testing() specified the number of tests, shut off no_plan. - if(defined $num_tests && !defined $expected) { - $self->_issue_plan($num_tests, 'OVERRIDE'); - $expected = $num_tests; - } + share( $self->{Curr_Test} ); - if( $self->{Done_Testing} ) { - my($file, $line) = @{$self->{Done_Testing}}[1,2]; - my $ok = Test::Builder::Event::Ok->new( - $self->context, - real_bool => 0, - name => "done_testing() was already called at $file line $line", - bool => $self->in_todo ? 1 : 0, - in_todo => $self->in_todo || 0, - todo => $self->in_todo ? $self->todo() || "" : "", - ); - $self->stream->send($ok); - $self->is_passing(0) unless $self->in_todo; + return; +} - return; - } - $self->{Done_Testing} = [caller]; +=back - if ($expected && defined($num_tests) && $num_tests != $expected) { - my $ok = Test::Builder::Event::Ok->new( - $self->context, - real_bool => 0, - name => "planned to run $expected but done_testing() expects $num_tests", - bool => $self->in_todo ? 1 : 0, - in_todo => $self->in_todo || 0, - todo => $self->in_todo ? $self->todo() || "" : "", - ); - $self->stream->send($ok); - $self->is_passing(0) unless $self->in_todo; - } +=head2 Setting up tests +These methods are for setting up tests and declaring how many there +are. You usually only want to call one of these methods. - $self->_issue_plan($total) unless $expected; +=over 4 - # The wrong number of tests were run - $self->is_passing(0) if defined $expected && $expected != $total; +=item B<plan> - # No tests were run - $self->is_passing(0) unless $total; + $Test->plan('no_plan'); + $Test->plan( skip_all => $reason ); + $Test->plan( tests => $num_tests ); - return 1; -} - -################ -# }}} Planning # -################ +A convenient way to set up your tests. Call this and Test::Builder +will print the appropriate headers and take the appropriate actions. -############################# -# {{{ Base Event Producers # -############################# +If you call C<plan()>, don't call any of the other methods below. -sub _ok_obj { - my $self = shift; - my( $test, $name, @diag ) = @_; +If a child calls "skip_all" in the plan, a C<Test::Builder::Exception> is +thrown. Trap this error, call C<finalize()> and don't run any more tests on +the child. - if ( $self->{Child_Name} and not $self->{In_Destroy} ) { - $name = 'unnamed test' unless defined $name; - $self->is_passing(0); - $self->croak("Cannot run test ($name) with active children"); - } + my $child = $Test->child('some child'); + eval { $child->plan( $condition ? ( skip_all => $reason ) : ( tests => 3 ) ) }; + if ( eval { $@->isa('Test::Builder::Exception') } ) { + $child->finalize; + return; + } + # run your tests - # $test might contain an object which we don't want to accidentally - # store, so we turn it into a boolean. - $test = $test ? 1 : 0; +=cut - # In case $name is a string overloaded object, force it to stringify. - $self->_unoverload_str( \$name ); +my %plan_cmds = ( + no_plan => \&no_plan, + skip_all => \&skip_all, + tests => \&_plan_tests, +); - # Capture the value of $TODO for the rest of this ok() call - # so it can more easily be found by other routines. - my $todo = $self->todo(); - my $in_todo = $self->in_todo; - local $self->{Todo} = $todo if $in_todo; +sub plan { + my( $self, $cmd, $arg ) = @_; - $self->_unoverload_str( \$todo ); + return unless $cmd; - my $ok = Test::Builder::Event::Ok->new( - $self->context, - real_bool => $test, - bool => $self->in_todo ? 1 : $test, - name => $name || $self->default_name || undef, - in_todo => $self->in_todo || 0, - diag => \@diag, - ); + local $Level = $Level + 1; - # # in a name can confuse Test::Harness. - $name =~ s|#|\\#|g if defined $name; + $self->croak("You tried to plan twice") if $self->{Have_Plan}; - if( $self->in_todo ) { - $ok->todo($todo); - $ok->in_todo(1); + if( my $method = $plan_cmds{$cmd} ) { + local $Level = $Level + 1; + $self->$method($arg); } - - if (defined $name and $name =~ /^[\d\s]+$/) { - $ok->diag(<<" ERR"); - You named your test '$name'. You shouldn't use numbers for your test names. - Very confusing. - ERR + else { + my @args = grep { defined } ( $cmd, $arg ); + $self->croak("plan() doesn't understand @args"); } - return $ok; + return 1; } -sub ok { - my $self = shift; - local $self->{_trace_cache} = $self->trace_test unless $self->{_trace_cache}; - my( $test, $name, @diag ) = @_; - my $ok = $self->_ok_obj($test, $name, @diag); - $self->_record_ok($ok); +sub _plan_tests { + my($self, $arg) = @_; - return $test ? 1 : 0; + if($arg) { + local $Level = $Level + 1; + return $self->expected_tests($arg); + } + elsif( !defined $arg ) { + $self->croak("Got an undefined number of tests"); + } + else { + $self->croak("You said to run 0 tests"); + } + + return; } -sub _record_ok { - my $self = shift; - my ($ok) = @_; +=item B<expected_tests> - $self->stream->send($ok); + my $max = $Test->expected_tests; + $Test->expected_tests($max); - $self->is_passing(0) unless $ok->real_bool || $self->in_todo; +Gets/sets the number of tests we expect this test to run and prints out +the appropriate headers. - # Check that we haven't violated the plan - $self->_check_is_passing_plan(); -} +=cut -sub BAIL_OUT { - my( $self, $reason ) = @_; +sub expected_tests { + my $self = shift; + my($max) = @_; - $self->_bailed_out(1); + if(@_) { + $self->croak("Number of tests must be a positive integer. You gave it '$max'") + unless $max =~ /^\+?\d+$/; - if ($self->parent) { - $self->{Bailed_Out_Reason} = $reason; - $self->no_ending(1); - die bless {} => 'Test::Builder::Exception'; - } + $self->{Expected_Tests} = $max; + $self->{Have_Plan} = 1; - my $bail = Test::Builder::Event::Bail->new( - $self->context, - reason => $reason, - in_todo => $self->in_todo || 0, - ); - $self->stream->send($bail); + $self->_output_plan($max) unless $self->no_header; + } + return $self->{Expected_Tests}; } -sub skip { - my( $self, $why ) = @_; - $why ||= ''; - $self->_unoverload_str( \$why ); - - my $ok = Test::Builder::Event::Ok->new( - $self->context, - real_bool => 1, - bool => 1, - in_todo => $self->in_todo || 0, - skip => $why, - ); +=item B<no_plan> - $self->stream->send($ok); -} + $Test->no_plan; -sub todo_skip { - my( $self, $why ) = @_; - $why ||= ''; +Declares that this test will run an indeterminate number of tests. - my $ok = Test::Builder::Event::Ok->new( - $self->context, - real_bool => 0, - bool => 1, - in_todo => $self->in_todo || 0, - skip => $why, - todo => $why, - ); +=cut - $self->stream->send($ok); -} +sub no_plan { + my($self, $arg) = @_; -sub diag { - my $self = shift; + $self->carp("no_plan takes no arguments") if $arg; - my $msg = join '', map { defined($_) ? $_ : 'undef' } @_; + $self->{No_Plan} = 1; + $self->{Have_Plan} = 1; - my $r = Test::Builder::Event::Diag->new( - $self->context, - in_todo => $self->in_todo || 0, - message => $msg, - ); - $self->stream->send($r); + return 1; } -sub note { - my $self = shift; +=begin private - my $msg = join '', map { defined($_) ? $_ : 'undef' } @_; +=item B<_output_plan> - my $r = Test::Builder::Event::Note->new( - $self->context, - in_todo => $self->in_todo || 0, - message => $msg, - ); - $self->stream->send($r); -} + $tb->_output_plan($max); + $tb->_output_plan($max, $directive); + $tb->_output_plan($max, $directive => $reason); -############################# -# }}} Base Event Producers # -############################# +Handles displaying the test plan. -################################# -# {{{ Advanced Event Producers # -################################# +If a C<$directive> and/or C<$reason> are given they will be output with the +plan. So here's what skipping all tests looks like: -my %numeric_cmps = map { ( $_, 1 ) } ( "<", "<=", ">", ">=", "==", "!=", "<=>" ); + $tb->_output_plan(0, "SKIP", "Because I said so"); -# Bad, these are not comparison operators. Should we include more? -my %cmp_ok_bl = map { ( $_, 1 ) } ( "=", "+=", ".=", "x=", "^=", "|=", "||=", "&&=", "..."); +It sets C<< $tb->{Have_Output_Plan} >> and will croak if the plan was already +output. -sub cmp_ok { - my( $self, $got, $type, $expect, $name ) = @_; +=end private - if ($cmp_ok_bl{$type}) { - $self->croak("$type is not a valid comparison operator in cmp_ok()"); - } +=cut - my $test; - my $error; - my @diag; +sub _output_plan { + my($self, $max, $directive, $reason) = @_; - local $self->{_trace_cache} = $self->trace_test unless $self->{_trace_cache}; + $self->carp("The plan was already output") if $self->{Have_Output_Plan}; - my @warnings; - (undef, $error) = try { - local $SIG{__WARN__} = sub { push @warnings => @_ }; - # This is so that warnings come out at the caller's level - ## no critic (BuiltinFunctions::ProhibitStringyEval) - eval qq[ -#line 999 "__REPLACE__ME__" -\$test = \$got $type \$expect; -1; - ] || die $@; - }; + my $plan = "1..$max"; + $plan .= " # $directive" if defined $directive; + $plan .= " $reason" if defined $reason; - for my $warn (@warnings) { - my ($pkg, $file, $line) = $self->trace_test->report->call; - $warn =~ s/at __REPLACE__ME__ line 999/at (eval in cmp_ok) $file line $line/g; - warn $warn; - } + $self->_print("$plan\n"); - # Treat overloaded objects as numbers if we're asked to do a - # numeric comparison. - my $unoverload - = $numeric_cmps{$type} - ? '_unoverload_num' - : '_unoverload_str'; + $self->{Have_Output_Plan} = 1; - push @diag => <<"END" if $error; -An error occurred while using $type: ------------------------------------- -$error ------------------------------------- -END + return; +} - unless($test) { - $self->$unoverload( \$got, \$expect ); - if( $type =~ /^(eq|==)$/ ) { - push @diag => $self->_is_diag( $got, $type, $expect ); - } - elsif( $type =~ /^(ne|!=)$/ ) { - push @diag => $self->_isnt_diag( $got, $type ); - } - else { - push @diag => $self->_cmp_diag( $got, $type, $expect ); - } - } +=item B<done_testing> - local $Level = $Level + 1; local $BLevel = $BLevel + 1; - $self->ok($test, $name, @diag); + $Test->done_testing(); + $Test->done_testing($num_tests); - return $test ? 1 : 0; -} +Declares that you are done testing, no more tests will be run after this point. +If a plan has not yet been output, it will do so. -sub is_eq { - my( $self, $got, $expect, $name ) = @_; - local $Level = $Level + 1; local $BLevel = $BLevel + 1; +$num_tests is the number of tests you planned to run. If a numbered +plan was already declared, and if this contradicts, a failing test +will be run to reflect the planning mistake. If C<no_plan> was declared, +this will override. - if( !defined $got || !defined $expect ) { - # undef only matches undef and nothing else - my $test = !defined $got && !defined $expect; +If C<done_testing()> is called twice, the second call will issue a +failing test. - $self->ok($test, $name, $test ? () : $self->_is_diag( $got, 'eq', $expect )); - return $test; - } +If C<$num_tests> is omitted, the number of tests run will be used, like +no_plan. - return $self->cmp_ok( $got, 'eq', $expect, $name ); -} +C<done_testing()> is, in effect, used when you'd want to use C<no_plan>, but +safer. You'd use it like so: -sub is_num { - my( $self, $got, $expect, $name ) = @_; - local $Level = $Level + 1; local $BLevel = $BLevel + 1; + $Test->ok($a == $b); + $Test->done_testing(); - if( !defined $got || !defined $expect ) { - # undef only matches undef and nothing else - my $test = !defined $got && !defined $expect; +Or to plan a variable number of tests: - $self->ok($test, $name, $test ? () : $self->_is_diag( $got, '==', $expect )); - return $test; + for my $test (@tests) { + $Test->ok($test); } + $Test->done_testing(scalar @tests); - return $self->cmp_ok( $got, '==', $expect, $name ); -} - -sub isnt_eq { - my( $self, $got, $dont_expect, $name ) = @_; - local $Level = $Level + 1; local $BLevel = $BLevel + 1; +=cut - if( !defined $got || !defined $dont_expect ) { - # undef only matches undef and nothing else - my $test = defined $got || defined $dont_expect; +sub done_testing { + my($self, $num_tests) = @_; - $self->ok( $test, $name, $test ? () : $self->_isnt_diag( $got, 'ne' )); - return $test; + # If done_testing() specified the number of tests, shut off no_plan. + if( defined $num_tests ) { + $self->{No_Plan} = 0; + } + else { + $num_tests = $self->current_test; } - return $self->cmp_ok( $got, 'ne', $dont_expect, $name ); -} - -sub isnt_num { - my( $self, $got, $dont_expect, $name ) = @_; - local $Level = $Level + 1; local $BLevel = $BLevel + 1; + if( $self->{Done_Testing} ) { + my($file, $line) = @{$self->{Done_Testing}}[1,2]; + $self->ok(0, "done_testing() was already called at $file line $line"); + return; + } - if( !defined $got || !defined $dont_expect ) { - # undef only matches undef and nothing else - my $test = defined $got || defined $dont_expect; + $self->{Done_Testing} = [caller]; - $self->ok( $test, $name, $test ? () : $self->_isnt_diag( $got, '!=' )); - return $test; + if( $self->expected_tests && $num_tests != $self->expected_tests ) { + $self->ok(0, "planned to run @{[ $self->expected_tests ]} ". + "but done_testing() expects $num_tests"); + } + else { + $self->{Expected_Tests} = $num_tests; } - return $self->cmp_ok( $got, '!=', $dont_expect, $name ); -} + $self->_output_plan($num_tests) unless $self->{Have_Output_Plan}; -sub like { - my( $self, $thing, $regex, $name ) = @_; - local $Level = $Level + 1; local $BLevel = $BLevel + 1; + $self->{Have_Plan} = 1; - return $self->_regex_ok( $thing, $regex, '=~', $name ); -} + # The wrong number of tests were run + $self->is_passing(0) if $self->{Expected_Tests} != $self->{Curr_Test}; -sub unlike { - my( $self, $thing, $regex, $name ) = @_; - local $Level = $Level + 1; local $BLevel = $BLevel + 1; + # No tests were run + $self->is_passing(0) if $self->{Curr_Test} == 0; - return $self->_regex_ok( $thing, $regex, '!~', $name ); + return 1; } +=item B<has_plan> -################################# -# }}} Advanced Event Producers # -################################# + $plan = $Test->has_plan -####################### -# {{{ Public helpers # -####################### +Find out whether a plan has been defined. C<$plan> is either C<undef> (no plan +has been set), C<no_plan> (indeterminate # of tests) or an integer (the number +of expected tests). -sub explain { - my $self = shift; +=cut - return map { - ref $_ - ? do { - $self->_try(sub { require Data::Dumper }, die_on_fail => 1); +sub has_plan { + my $self = shift; - my $dumper = Data::Dumper->new( [$_] ); - $dumper->Indent(1)->Terse(1); - $dumper->Sortkeys(1) if $dumper->can("Sortkeys"); - $dumper->Dump; - } - : $_ - } @_; + return( $self->{Expected_Tests} ) if $self->{Expected_Tests}; + return('no_plan') if $self->{No_Plan}; + return(undef); } -sub carp { - my $self = shift; - return warn $self->_message_at_caller(@_); -} +=item B<skip_all> -sub croak { - my $self = shift; - return die $self->_message_at_caller(@_); -} + $Test->skip_all; + $Test->skip_all($reason); -sub context { - my $self = shift; +Skips all the tests, using the given C<$reason>. Exits immediately with 0. - my $trace = $self->trace_test; +=cut - return ( - depth => $self->depth, - source => $self->name || "", - trace => $trace, - ); -} +sub skip_all { + my( $self, $reason ) = @_; -sub has_plan { - my $self = shift; + $self->{Skip_All} = $self->parent ? $reason : 1; - return($self->stream->expected_tests) if $self->stream->expected_tests; - return('no_plan') if $self->stream->plan; - return(undef); + $self->_output_plan(0, "SKIP", $reason) unless $self->no_header; + if ( $self->parent ) { + die bless {} => 'Test::Builder::Exception'; + } + exit(0); } -sub reset { ## no critic (Subroutines::ProhibitBuiltinHomonyms) - my $self = shift; - my %params; +=item B<exported_to> - if (@_) { - %params = @_; - $self->{reset_params} = \%params; - } - else { - %params = %{$self->{reset_params} || {}}; - } + my $pack = $Test->exported_to; + $Test->exported_to($pack); - my $modern = $params{modern} || $self->modern || 0; - $self->modern($modern); +Tells Test::Builder what package you exported your functions to. - # We leave this a global because it has to be localized and localizing - # hash keys is just asking for pain. Also, it was documented. - $Level = 1; - $BLevel = 1; +This method isn't terribly useful since modules which share the same +Test::Builder object might get exported to different packages and only +the last one will be honored. + +=cut - if ($params{new_stream} || !$params{shared_stream}) { - my $olds = $self->stream; - $self->{stream} = Test::Builder::Stream->new; - $self->{stream}->use_lresults if $olds->lresults; +sub exported_to { + my( $self, $pack ) = @_; + + if( defined $pack ) { + $self->{Exported_To} = $pack; } + return $self->{Exported_To}; +} - $final->pid($$) if $final; +=back - $self->stream->use_tap unless $params{no_tap} || $ENV{TB_NO_TAP}; +=head2 Running tests - $self->stream->plan(undef) unless $params{no_reset_plan}; +These actually run the tests, analogous to the functions in Test::More. - # Don't reset stream stuff when reseting/creating a modern TB object - unless ($modern) { - $self->stream->no_ending(0); - $self->tap->reset if $self->tap; - $self->lresults->reset if $self->lresults; - } +They all return true if the test passed, false if the test failed. - $self->{Name} = $0; +C<$name> is always optional. - $self->{Have_Issued_Plan} = 0; - $self->{Done_Testing} = 0; - $self->{Skip_All} = 0; +=over 4 - $self->{Original_Pid} = $$; - $self->{Child_Name} = undef; - $self->{Indent} ||= ''; - $self->{Depth} = 0; +=item B<ok> - $self->{Exported_To} = undef; - $self->{Expected_Tests} = 0; + $Test->ok($test, $name); - $self->{Todo} = undef; - $self->{Todo_Stack} = []; - $self->{Start_Todo} = 0; - $self->{Opened_Testhandles} = 0; +Your basic test. Pass if C<$test> is true, fail if $test is false. Just +like Test::Simple's C<ok()>. - return; -} +=cut + +sub ok { + my( $self, $test, $name ) = @_; + if ( $self->{Child_Name} and not $self->{In_Destroy} ) { + $name = 'unnamed test' unless defined $name; + $self->is_passing(0); + $self->croak("Cannot run test ($name) with active children"); + } + # $test might contain an object which we don't want to accidentally + # store, so we turn it into a boolean. + $test = $test ? 1 : 0; -####################### -# }}} Public helpers # -####################### + lock $self->{Curr_Test}; + $self->{Curr_Test}++; -#################### -# {{{ TODO related # -#################### + # In case $name is a string overloaded object, force it to stringify. + $self->_unoverload_str( \$name ); -sub todo { - my( $self, $pack ) = @_; + $self->diag(<<"ERR") if defined $name and $name =~ /^[\d\s]+$/; + You named your test '$name'. You shouldn't use numbers for your test names. + Very confusing. +ERR - return $self->{Todo} if defined $self->{Todo}; + # Capture the value of $TODO for the rest of this ok() call + # so it can more easily be found by other routines. + my $todo = $self->todo(); + my $in_todo = $self->in_todo; + local $self->{Todo} = $todo if $in_todo; - local $Level = $Level + 1; local $BLevel = $BLevel + 1; - my $todo = $self->find_TODO($pack); - return $todo if defined $todo; + $self->_unoverload_str( \$todo ); - return ''; -} + my $out; + my $result = &share( {} ); -sub in_todo { - my $self = shift; + unless($test) { + $out .= "not "; + @$result{ 'ok', 'actual_ok' } = ( ( $self->in_todo ? 1 : 0 ), 0 ); + } + else { + @$result{ 'ok', 'actual_ok' } = ( 1, $test ); + } - local $Level = $Level + 1; local $BLevel = $BLevel + 1; - return( defined $self->{Todo} || $self->find_TODO ) ? 1 : 0; -} + $out .= "ok"; + $out .= " $self->{Curr_Test}" if $self->use_numbers; -sub todo_start { - my $self = shift; - my $message = @_ ? shift : ''; + if( defined $name ) { + $name =~ s|#|\\#|g; # # in a name can confuse Test::Harness. + $out .= " - $name"; + $result->{name} = $name; + } + else { + $result->{name} = ''; + } - $self->{Start_Todo}++; if( $self->in_todo ) { - push @{ $self->{Todo_Stack} } => $self->todo; + $out .= " # TODO $todo"; + $result->{reason} = $todo; + $result->{type} = 'todo'; + } + else { + $result->{reason} = ''; + $result->{type} = ''; } - $self->{Todo} = $message; - return; -} + $self->{Test_Results}[ $self->{Curr_Test} - 1 ] = $result; + $out .= "\n"; -sub todo_end { - my $self = shift; + $self->_print($out); - if( !$self->{Start_Todo} ) { - $self->croak('todo_end() called without todo_start()'); + unless($test) { + my $msg = $self->in_todo ? "Failed (TODO)" : "Failed"; + $self->_print_to_fh( $self->_diag_fh, "\n" ) if $ENV{HARNESS_ACTIVE}; + + my( undef, $file, $line ) = $self->caller; + if( defined $name ) { + $self->diag(qq[ $msg test '$name'\n]); + $self->diag(qq[ at $file line $line.\n]); + } + else { + $self->diag(qq[ $msg test at $file line $line.\n]); + } } - $self->{Start_Todo}--; + $self->is_passing(0) unless $test || $self->in_todo; - if( $self->{Start_Todo} && @{ $self->{Todo_Stack} } ) { - $self->{Todo} = pop @{ $self->{Todo_Stack} }; - } - else { - delete $self->{Todo}; - } + # Check that we haven't violated the plan + $self->_check_is_passing_plan(); - return; + return $test ? 1 : 0; } -#################### -# }}} TODO related # -#################### - -####################### -# {{{ Private helpers # -####################### # Check that we haven't yet violated the plan and set # is_passing() accordingly sub _check_is_passing_plan { my $self = shift; - my $plan = $self->stream->expected_tests; + my $plan = $self->has_plan; return unless defined $plan; # no plan yet defined return unless $plan !~ /\D/; # no numeric plan - $self->is_passing(0) if $plan < $self->stream->tests_run; + $self->is_passing(0) if $plan < $self->{Curr_Test}; } -sub _is_object { - my( $self, $thing ) = @_; - - return $self->_try( sub { ref $thing && $thing->isa('UNIVERSAL') } ) ? 1 : 0; -} sub _unoverload { my $self = shift; @@ -1006,6 +924,12 @@ sub _unoverload { return; } +sub _is_object { + my( $self, $thing ) = @_; + + return $self->_try( sub { ref $thing && $thing->isa('UNIVERSAL') } ) ? 1 : 0; +} + sub _unoverload_str { my $self = shift; @@ -1037,6 +961,58 @@ sub _is_dualvar { return ($numval != 0 and $numval ne $val ? 1 : 0); } +=item B<is_eq> + + $Test->is_eq($got, $expected, $name); + +Like Test::More's C<is()>. Checks if C<$got eq $expected>. This is the +string version. + +C<undef> only ever matches another C<undef>. + +=item B<is_num> + + $Test->is_num($got, $expected, $name); + +Like Test::More's C<is()>. Checks if C<$got == $expected>. This is the +numeric version. + +C<undef> only ever matches another C<undef>. + +=cut + +sub is_eq { + my( $self, $got, $expect, $name ) = @_; + local $Level = $Level + 1; + + if( !defined $got || !defined $expect ) { + # undef only matches undef and nothing else + my $test = !defined $got && !defined $expect; + + $self->ok( $test, $name ); + $self->_is_diag( $got, 'eq', $expect ) unless $test; + return $test; + } + + return $self->cmp_ok( $got, 'eq', $expect, $name ); +} + +sub is_num { + my( $self, $got, $expect, $name ) = @_; + local $Level = $Level + 1; + + if( !defined $got || !defined $expect ) { + # undef only matches undef and nothing else + my $test = !defined $got && !defined $expect; + + $self->ok( $test, $name ); + $self->_is_diag( $got, '==', $expect ) unless $test; + return $test; + } + + return $self->cmp_ok( $got, '==', $expect, $name ); +} + sub _diag_fmt { my( $self, $type, $val ) = @_; @@ -1059,1003 +1035,1084 @@ sub _diag_fmt { sub _is_diag { my( $self, $got, $type, $expect ) = @_; - local $Level = $Level + 1; local $BLevel = $BLevel + 1; $self->_diag_fmt( $type, $_ ) for \$got, \$expect; - return <<"DIAGNOSTIC"; + local $Level = $Level + 1; + return $self->diag(<<"DIAGNOSTIC"); got: $got expected: $expect DIAGNOSTIC + } sub _isnt_diag { my( $self, $got, $type ) = @_; - local $Level = $Level + 1; local $BLevel = $BLevel + 1; $self->_diag_fmt( $type, \$got ); - return <<"DIAGNOSTIC"; + local $Level = $Level + 1; + return $self->diag(<<"DIAGNOSTIC"); got: $got expected: anything else DIAGNOSTIC } +=item B<isnt_eq> -sub _cmp_diag { - my( $self, $got, $type, $expect ) = @_; + $Test->isnt_eq($got, $dont_expect, $name); - $got = defined $got ? "'$got'" : 'undef'; - $expect = defined $expect ? "'$expect'" : 'undef'; +Like Test::More's C<isnt()>. Checks if C<$got ne $dont_expect>. This is +the string version. - local $Level = $Level + 1; local $BLevel = $BLevel + 1; - return <<"DIAGNOSTIC"; - $got - $type - $expect -DIAGNOSTIC -} +=item B<isnt_num> -sub _caller_context { - my $self = shift; + $Test->isnt_num($got, $dont_expect, $name); - my($pack, $file, $line) = $self->trace_test->report->call; +Like Test::More's C<isnt()>. Checks if C<$got ne $dont_expect>. This is +the numeric version. - my $code = ''; - $code .= "#line $line $file\n" if defined $file and defined $line; +=cut - return $code; -} +sub isnt_eq { + my( $self, $got, $dont_expect, $name ) = @_; + local $Level = $Level + 1; -sub _regex_ok { - my( $self, $thing, $regex, $cmp, $name ) = @_; + if( !defined $got || !defined $dont_expect ) { + # undef only matches undef and nothing else + my $test = defined $got || defined $dont_expect; - my $ok = 0; - my $usable_regex = _is_qr($regex) ? $regex : $self->maybe_regex($regex); - unless( defined $usable_regex ) { - local $Level = $Level + 1; local $BLevel = $BLevel + 1; - $ok = $self->ok( 0, $name, " '$regex' doesn't look much like a regex to me."); - return $ok; + $self->ok( $test, $name ); + $self->_isnt_diag( $got, 'ne' ) unless $test; + return $test; } - my $test; - my $context = '#line 999 "__REPLACE__ME__"' . "\n"; + return $self->cmp_ok( $got, 'ne', $dont_expect, $name ); +} - my @warnings; - try { - local $SIG{__WARN__} = sub { push @warnings => @_ }; - # No point in issuing an uninit warning, they'll see it in the diagnostics - no warnings 'uninitialized'; - ## no critic (BuiltinFunctions::ProhibitStringyEval) - $test = eval $context . q{$test = $thing =~ /$usable_regex/ ? 1 : 0}; - }; - for my $warn (@warnings) { - my ($pkg, $file, $line) = $self->trace_test->report->call; - $warn =~ s/at __REPLACE__ME__ line 999/at $file line $line/g; - warn $warn; +sub isnt_num { + my( $self, $got, $dont_expect, $name ) = @_; + local $Level = $Level + 1; + + if( !defined $got || !defined $dont_expect ) { + # undef only matches undef and nothing else + my $test = defined $got || defined $dont_expect; + + $self->ok( $test, $name ); + $self->_isnt_diag( $got, '!=' ) unless $test; + return $test; } - $test = !$test if $cmp eq '!~'; + return $self->cmp_ok( $got, '!=', $dont_expect, $name ); +} - my @diag; - unless($test) { - $thing = defined $thing ? "'$thing'" : 'undef'; - my $match = $cmp eq '=~' ? "doesn't match" : "matches"; +=item B<like> - push @diag => sprintf( <<'DIAGNOSTIC', $thing, $match, $regex ); - %s - %13s '%s' -DIAGNOSTIC - } + $Test->like($thing, qr/$regex/, $name); + $Test->like($thing, '/$regex/', $name); - local $Level = $Level + 1; local $BLevel = $BLevel + 1; - $self->ok( $test, $name, @diag ); +Like Test::More's C<like()>. Checks if $thing matches the given C<$regex>. - return $test; -} +=item B<unlike> -# I'm not ready to publish this. It doesn't deal with array return -# values from the code or context. -sub _try { - my( $self, $code, %opts ) = @_; + $Test->unlike($thing, qr/$regex/, $name); + $Test->unlike($thing, '/$regex/', $name); + +Like Test::More's C<unlike()>. Checks if $thing B<does not match> the +given C<$regex>. - my $result; - my ($ok, $error) = try { $result = $code->() }; +=cut - die $error if $opts{die_on_fail} && !$ok; +sub like { + my( $self, $thing, $regex, $name ) = @_; - return wantarray ? ( $result, $error ) : $result; + local $Level = $Level + 1; + return $self->_regex_ok( $thing, $regex, '=~', $name ); } -sub _message_at_caller { - my $self = shift; +sub unlike { + my( $self, $thing, $regex, $name ) = @_; - local $Level = $Level + 1; local $BLevel = $BLevel + 1; - my $trace = $self->trace_test; - my( $pack, $file, $line ) = $trace->report->call; - return join( "", @_ ) . " at $file line $line.\n"; + local $Level = $Level + 1; + return $self->_regex_ok( $thing, $regex, '!~', $name ); } -#'# -sub _sanity_check { - my $self = shift; +=item B<cmp_ok> - $self->_whoa( $self->stream->tests_run < 0, 'Says here you ran a negative number of tests!' ); + $Test->cmp_ok($thing, $type, $that, $name); - $self->lresults->sanity_check($self) if $self->lresults; +Works just like Test::More's C<cmp_ok()>. - return; -} + $Test->cmp_ok($big_num, '!=', $other_big_num); -sub _whoa { - my( $self, $check, $desc ) = @_; - if($check) { - local $Level = $Level + 1; local $BLevel = $BLevel + 1; - $self->croak(<<"WHOA"); -WHOA! $desc -This should never happen! Please contact the author immediately! -WHOA - } +=cut - return; -} +my %numeric_cmps = map { ( $_, 1 ) } ( "<", "<=", ">", ">=", "==", "!=", "<=>" ); -sub _ending { - my $self = shift; - require Test::Builder::ExitMagic; - my $ending = Test::Builder::ExitMagic->new(tb => $self, stream => $self->stream); - $ending->do_magic; -} +# Bad, these are not comparison operators. Should we include more? +my %cmp_ok_bl = map { ( $_, 1 ) } ( "=", "+=", ".=", "x=", "^=", "|=", "||=", "&&=", "..."); -sub _is_qr { - my $regex = shift; +sub cmp_ok { + my( $self, $got, $type, $expect, $name ) = @_; - # is_regexp() checks for regexes in a robust manner, say if they're - # blessed. - return re::is_regexp($regex) if defined &re::is_regexp; - return ref $regex eq 'Regexp'; -} + if ($cmp_ok_bl{$type}) { + $self->croak("$type is not a valid comparison operator in cmp_ok()"); + } + + my $test; + my $error; + { + ## no critic (BuiltinFunctions::ProhibitStringyEval) -####################### -# }}} Private helpers # -####################### + local( $@, $!, $SIG{__DIE__} ); # isolate eval -################################################ -# {{{ Everything below this line is deprecated # -# But it must be maintained for legacy... # -################################################ + my($pack, $file, $line) = $self->caller(); -BEGIN { - my %generate = ( - lresults => [qw/summary details/], - stream => [qw/no_ending/], - tap => [qw/ - no_header no_diag output failure_output todo_output reset_outputs - use_numbers _new_fh - /], - ); + # This is so that warnings come out at the caller's level + $test = eval qq[ +#line $line "(eval in cmp_ok) $file" +\$got $type \$expect; +]; + $error = $@; + } + local $Level = $Level + 1; + my $ok = $self->ok( $test, $name ); - for my $delegate (keys %generate) { - for my $method (@{$generate{$delegate}}) { - #print STDERR "Adding: $method ($delegate)\n"; - my $code = sub { - my $self = shift; + # Treat overloaded objects as numbers if we're asked to do a + # numeric comparison. + my $unoverload + = $numeric_cmps{$type} + ? '_unoverload_num' + : '_unoverload_str'; - $self->carp("Use of \$TB->$method() is deprecated.") if $self->modern; - my $d = $self->$delegate || $self->croak("$method() method only applies when $delegate is in use"); + $self->diag(<<"END") if $error; +An error occurred while using $type: +------------------------------------ +$error +------------------------------------ +END - $d->$method(@_); - }; + unless($ok) { + $self->$unoverload( \$got, \$expect ); - no strict 'refs'; ## no critic - *{$method} = $code; + if( $type =~ /^(eq|==)$/ ) { + $self->_is_diag( $got, $type, $expect ); + } + elsif( $type =~ /^(ne|!=)$/ ) { + $self->_isnt_diag( $got, $type ); + } + else { + $self->_cmp_diag( $got, $type, $expect ); } } + return $ok; } -sub exported_to { - my($self, $pack) = @_; - $self->carp("exported_to() is deprecated") if $self->modern; - $self->{Exported_To} = $pack if defined $pack; - return $self->{Exported_To}; -} +sub _cmp_diag { + my( $self, $got, $type, $expect ) = @_; -sub _indent { - my $self = shift; - $self->carp("_indent() is deprecated") if $self->modern; - return '' unless $self->depth; - return ' ' x $self->depth -} + $got = defined $got ? "'$got'" : 'undef'; + $expect = defined $expect ? "'$expect'" : 'undef'; -sub _output_plan { - my ($self) = @_; - $self->carp("_output_plan() is deprecated") if $self->modern; - goto &_issue_plan; + local $Level = $Level + 1; + return $self->diag(<<"DIAGNOSTIC"); + $got + $type + $expect +DIAGNOSTIC } -sub _diag_fh { +sub _caller_context { my $self = shift; - $self->carp("Use of \$TB->_diag_fh() is deprecated.") if $self->modern; - my $tap = $self->tap || $self->croak("_diag_fh() method only applies when TAP is in use"); + my( $pack, $file, $line ) = $self->caller(1); - local $Level = $Level + 1; local $BLevel = $BLevel + 1; - return $tap->_diag_fh($self->in_todo) -} + my $code = ''; + $code .= "#line $line $file\n" if defined $file and defined $line; -sub _print { - my $self = shift; + return $code; +} - $self->carp("Use of \$TB->_print() is deprecated.") if $self->modern; - my $tap = $self->tap || $self->croak("_print() method only applies when TAP is in use"); +=back - return $tap->_print($self->_indent, @_); -} -sub _print_to_fh { - my( $self, $fh, @msgs ) = @_; +=head2 Other Testing Methods - $self->carp("Use of \$TB->_print_to_fh() is deprecated.") if $self->modern; - my $tap = $self->tap || $self->croak("_print_to_fh() method only applies when TAP is in use"); +These are methods which are used in the course of writing a test but are not themselves tests. - return $tap->_print_to_fh($fh, $self->_indent, @msgs); -} +=over 4 -sub is_fh { - my $self = shift; +=item B<BAIL_OUT> - $self->carp("Use of \$TB->is_fh() is deprecated.") - if Scalar::Util::blessed($self) && $self->modern; + $Test->BAIL_OUT($reason); - require Test::Builder::Formatter::TAP; - return Test::Builder::Formatter::TAP->is_fh(@_); -} +Indicates to the Test::Harness that things are going so badly all +testing should terminate. This includes running any additional test +scripts. -sub current_test { - my $self = shift; +It will exit with 255. - my $tap = $self->tap; - my $lresults = $self->lresults; +=cut - if (@_) { - my ($num) = @_; +sub BAIL_OUT { + my( $self, $reason ) = @_; - $lresults->current_test($num) if $lresults; - $tap->current_test($num) if $tap; + $self->{Bailed_Out} = 1; - $self->stream->tests_run(0 - $self->stream->tests_run + $num); + if ($self->parent) { + $self->{Bailed_Out_Reason} = $reason; + $self->no_ending(1); + die bless {} => 'Test::Builder::Exception'; } - return $self->stream->tests_run; + $self->_print("Bail out! $reason"); + exit 255; } -sub BAILOUT { - my ($self) = @_; - $self->carp("Use of \$TB->BAILOUT() is deprecated.") if $self->modern; - goto &BAIL_OUT; +=for deprecated +BAIL_OUT() used to be BAILOUT() + +=cut + +{ + no warnings 'once'; + *BAILOUT = \&BAIL_OUT; } -sub expected_tests { - my $self = shift; +=item B<skip> - if(@_) { - my ($max) = @_; - $self->carp("Use of \$TB->expected_tests(\$max) is deprecated.") if $self->modern; - $self->_issue_plan($max); - } + $Test->skip; + $Test->skip($why); - return $self->stream->expected_tests || 0; -} +Skips the current test, reporting C<$why>. -sub caller { ## no critic (Subroutines::ProhibitBuiltinHomonyms) - my $self = shift; +=cut + +sub skip { + my( $self, $why ) = @_; + $why ||= ''; + $self->_unoverload_str( \$why ); + + lock( $self->{Curr_Test} ); + $self->{Curr_Test}++; - Carp::confess("Use of Test::Builder->caller() is deprecated.\n") if $self->modern; + $self->{Test_Results}[ $self->{Curr_Test} - 1 ] = &share( + { + 'ok' => 1, + actual_ok => 1, + name => '', + type => 'skip', + reason => $why, + } + ); - local $Level = $Level + 1; local $BLevel = $BLevel + 1; - my $trace = $self->trace_test; - return unless $trace && $trace->report; - my @call = $trace->report->call; + my $out = "ok"; + $out .= " $self->{Curr_Test}" if $self->use_numbers; + $out .= " # skip"; + $out .= " $why" if length $why; + $out .= "\n"; - return wantarray ? @call : $call[0]; -} + $self->_print($out); -sub level { - my( $self, $level ) = @_; - $Level = $level if defined $level; - return $Level; + return 1; } -sub maybe_regex { - my ($self, $regex) = @_; - my $usable_regex = undef; +=item B<todo_skip> - $self->carp("Use of \$TB->maybe_regex() is deprecated.") if $self->modern; + $Test->todo_skip; + $Test->todo_skip($why); - return $usable_regex unless defined $regex; +Like C<skip()>, only it will declare the test as failing and TODO. Similar +to - my( $re, $opts ); + print "not ok $tnum # TODO $why\n"; - # Check for qr/foo/ - if( _is_qr($regex) ) { - $usable_regex = $regex; - } - # Check for '/foo/' or 'm,foo,' - elsif(( $re, $opts ) = $regex =~ m{^ /(.*)/ (\w*) $ }sx or - ( undef, $re, $opts ) = $regex =~ m,^ m([^\w\s]) (.+) \1 (\w*) $,sx - ) - { - $usable_regex = length $opts ? "(?$opts)$re" : $re; - } +=cut - return $usable_regex; -} +sub todo_skip { + my( $self, $why ) = @_; + $why ||= ''; + lock( $self->{Curr_Test} ); + $self->{Curr_Test}++; -################################### -# }}} End of deprecations section # -################################### + $self->{Test_Results}[ $self->{Curr_Test} - 1 ] = &share( + { + 'ok' => 1, + actual_ok => 0, + name => '', + type => 'todo_skip', + reason => $why, + } + ); -#################### -# {{{ TB1.5 stuff # -#################### + my $out = "not ok"; + $out .= " $self->{Curr_Test}" if $self->use_numbers; + $out .= " # TODO & SKIP $why\n"; -# This is just a list of method Test::Builder current does not have that Test::Builder 1.5 does. -my %TB15_METHODS = map {$_ => 1} qw{ - _file_and_line _join_message _make_default _my_exit _reset_todo_state - _result_to_hash _results _todo_state formatter history in_subtest in_test - no_change_exit_code post_event post_result set_formatter set_plan test_end - test_exit_code test_start test_state -}; + $self->_print($out); -our $AUTOLOAD; -sub AUTOLOAD { - $AUTOLOAD =~ m/^(.*)::([^:]+)$/; - my ($package, $sub) = ($1, $2); + return 1; +} - my @caller = CORE::caller(); - my $msg = qq{Can't locate object method "$sub" via package "$package" at $caller[1] line $caller[2]\n}; +=begin _unimplemented - $msg .= <<" EOT" if $TB15_METHODS{$sub}; +=item B<skip_rest> - ************************************************************************* - '$sub' is a Test::Builder 1.5 method. Test::Builder 1.5 is a dead branch. - You need to update your code so that it no longer treats Test::Builders - over a specific version number as anything special. + $Test->skip_rest; + $Test->skip_rest($reason); - See: http://blogs.perl.org/users/chad_exodist_granum/2014/03/testmore---new-maintainer-also-stop-version-checking.html - ************************************************************************* - EOT +Like C<skip()>, only it skips all the rest of the tests you plan to run +and terminates the test. - die $msg; -} +If you're running under C<no_plan>, it skips once and terminates the +test. -#################### -# }}} TB1.5 stuff # -#################### +=end _unimplemented -1; +=back -__END__ -=head1 NAME +=head2 Test building utility methods -Test::Builder - Backend for building test libraries +These methods are useful when writing your own test methods. -=head1 NOTE ON DEPRECATIONS +=over 4 -With version 1.301001 many old methods and practices have been deprecated. What -we mean when we say "deprecated" is that the practices or methods are not to be -used in any new code. Old code that uses them will still continue to work, -possibly forever, but new code should use the newer and better alternatives. +=item B<maybe_regex> -In the future, if enough (read: pretty much everything) is updated and few if -any modules still use these old items, they will be removed completely. This is -not super likely to happen just because of the sheer number of modules that use -Test::Builder. + $Test->maybe_regex(qr/$regex/); + $Test->maybe_regex('/$regex/'); -=head1 SYNOPSIS +This method used to be useful back when Test::Builder worked on Perls +before 5.6 which didn't have qr//. Now its pretty useless. -In general you probably do not want to use this module directly, but instead -want to use L<Test::Builder::Provider> which will help you roll out a testing -library. +Convenience method for building testing functions that take regular +expressions as arguments. - package My::Test::Module; - use Test::Builder::Provider; +Takes a quoted regular expression produced by C<qr//>, or a string +representing a regular expression. - # Export a test tool from an anonymous sub - provide ok => sub { - my ($test, $name) = @_; - builder()->ok($test, $name); - }; +Returns a Perl value which may be used instead of the corresponding +regular expression, or C<undef> if its argument is not recognised. - # Export tools that are package subs - provides qw/is is_deeply/; - sub is { ... } - sub is_deeply { ... } +For example, a version of C<like()>, sans the useful diagnostic messages, +could be written as: -See L<Test::Builder::Provider> for more details. + sub laconic_like { + my ($self, $thing, $regex, $name) = @_; + my $usable_regex = $self->maybe_regex($regex); + die "expecting regex, found '$regex'\n" + unless $usable_regex; + $self->ok($thing =~ m/$usable_regex/, $name); + } -B<Note:> You MUST use 'provide', or 'provides' to export testing tools, this -allows you to use the C<< builder()->trace_test >> tools to determine what -file/line a failed test came from. +=cut -=head2 LOW-LEVEL +sub maybe_regex { + my( $self, $regex ) = @_; + my $usable_regex = undef; - use Test::Builder; - my $tb = Test::Builder->create(modern => 1, shared_stream => 1); - $tb->ok(1); - .... + return $usable_regex unless defined $regex; -=head2 DEPRECATED + my( $re, $opts ); - use Test::Builder; - my $tb = Test::Builder->new; - $tb->ok(1); - ... + # Check for qr/foo/ + if( _is_qr($regex) ) { + $usable_regex = $regex; + } + # Check for '/foo/' or 'm,foo,' + elsif(( $re, $opts ) = $regex =~ m{^ /(.*)/ (\w*) $ }sx or + ( undef, $re, $opts ) = $regex =~ m,^ m([^\w\s]) (.+) \1 (\w*) $,sx + ) + { + $usable_regex = length $opts ? "(?$opts)$re" : $re; + } -=head1 DESCRIPTION + return $usable_regex; +} -L<Test::Simple> and L<Test::More> have proven to be popular testing modules, -but they're not always flexible enough. Test::Builder provides a -building block upon which to write your own test libraries I<which can -work together>. +sub _is_qr { + my $regex = shift; + + # is_regexp() checks for regexes in a robust manner, say if they're + # blessed. + return re::is_regexp($regex) if defined &re::is_regexp; + return ref $regex eq 'Regexp'; +} + +sub _regex_ok { + my( $self, $thing, $regex, $cmp, $name ) = @_; -=head1 TEST COMPONENT MAP + my $ok = 0; + my $usable_regex = $self->maybe_regex($regex); + unless( defined $usable_regex ) { + local $Level = $Level + 1; + $ok = $self->ok( 0, $name ); + $self->diag(" '$regex' doesn't look much like a regex to me."); + return $ok; + } - [Test Script] > [Test Tool] > [Test::Builder] > [Test::Bulder::Stream] > [Event Formatter] - ^ - You are here + { + my $test; + my $context = $self->_caller_context; -A test script uses a test tool such as L<Test::More>, which uses Test::Builder -to produce events. The events are sent to L<Test::Builder::Stream> which then -forwards them on to one or more formatters. The default formatter is -L<Test::Builder::Fromatter::TAP> which produces TAP output. + { + ## no critic (BuiltinFunctions::ProhibitStringyEval) -=head1 METHODS + local( $@, $!, $SIG{__DIE__} ); # isolate eval -=head2 CONSTRUCTION + # No point in issuing an uninit warning, they'll see it in the diagnostics + no warnings 'uninitialized'; -=over 4 + $test = eval $context . q{$test = $thing =~ /$usable_regex/ ? 1 : 0}; + } -=item $Test = Test::Builder->create(%params) + $test = !$test if $cmp eq '!~'; -Create a completely independant Test::Builder object. + local $Level = $Level + 1; + $ok = $self->ok( $test, $name ); + } - my $Test = Test::Builder->create; + unless($ok) { + $thing = defined $thing ? "'$thing'" : 'undef'; + my $match = $cmp eq '=~' ? "doesn't match" : "matches"; -Create a Test::Builder object that sends events to the shared output stream -(usually what you want). + local $Level = $Level + 1; + $self->diag( sprintf <<'DIAGNOSTIC', $thing, $match, $regex ); + %s + %13s '%s' +DIAGNOSTIC - my $Test = Test::Builder->create(shared_stream => 1); + } -Create a Test::Builder object that does not include any legacy cruft. + return $ok; +} - my $Test = Test::Builder->create(modern => 1); +# I'm not ready to publish this. It doesn't deal with array return +# values from the code or context. -=item $Test = Test::Builder->new B<***DEPRECATED***> +=begin private - my $Test = Test::Builder->new; +=item B<_try> -B<This usage is DEPRECATED!> + my $return_from_code = $Test->try(sub { code }); + my($return_from_code, $error) = $Test->try(sub { code }); -Returns the Test::Builder singleton object representing the current state of -the test. +Works like eval BLOCK except it ensures it has no effect on the rest +of the test (ie. C<$@> is not set) nor is effected by outside +interference (ie. C<$SIG{__DIE__}>) and works around some quirks in older +Perls. -Since you only run one test per program C<new> always returns the same -Test::Builder object. No matter how many times you call C<new()>, you're -getting the same object. This is called a singleton. This is done so that -multiple modules share such global information as the test counter and -where test output is going. B<No longer necessary> +C<$error> is what would normally be in C<$@>. -If you want a completely new Test::Builder object different from the -singleton, use C<create>. +It is suggested you use this in place of eval BLOCK. -=back +=cut -=head2 SIMPLE ACCESSORS AND SHORTCUTS +sub _try { + my( $self, $code, %opts ) = @_; -=head3 READ/WRITE ATTRIBUTES + my $error; + my $return; + { + local $!; # eval can mess up $! + local $@; # don't set $@ in the test + local $SIG{__DIE__}; # don't trip an outside DIE handler. + $return = eval { $code->() }; + $error = $@; + } -=over 4 + die $error if $error and $opts{die_on_fail}; -=item $parent = $Test->parent + return wantarray ? ( $return, $error ) : $return; +} -Returns the parent C<Test::Builder> instance, if any. Only used with child -builders for nested TAP. +=end private -=item $Test->name -Defaults to $0, but subtests and child tests will set this. +=item B<is_fh> -=item $Test->modern + my $is_fh = $Test->is_fh($thing); -Defaults to $ENV{TB_MODERN}, or 0. True when the builder object was constructed -with modern practices instead of deprecated ones. +Determines if the given C<$thing> can be used as a filehandle. -=item $Test->depth +=cut -Get/Set the depth. This is usually set for Child tests. +sub is_fh { + my $self = shift; + my $maybe_fh = shift; + return 0 unless defined $maybe_fh; -=item $Test->default_name + return 1 if ref $maybe_fh eq 'GLOB'; # its a glob ref + return 1 if ref \$maybe_fh eq 'GLOB'; # its a glob -Get/Set the default name for tests where no name was provided. Typically this -should be set to undef, there are very few real-world use cases for this. -B<Note:> This functionality was added specifically for L<Test::Exception>, -which has one of the few real-world use cases. + return eval { $maybe_fh->isa("IO::Handle") } || + eval { tied($maybe_fh)->can('TIEHANDLE') }; +} =back -=head3 DELEGATES TO STREAM -Each of these is a shortcut to C<< $Test->stream->NAME >> +=head2 Test style -See the L<Test::Builder::Stream> documentation for details. =over 4 -=item $Test->is_passing(...) +=item B<level> -=item $Test->listen(...) + $Test->level($how_high); -=item $Test->munge(...) +How far up the call stack should C<$Test> look when reporting where the +test failed. -=item $Test->tap +Defaults to 1. -=item $Test->lresults +Setting L<$Test::Builder::Level> overrides. This is typically useful +localized: -=item $Test->use_fork + sub my_ok { + my $test = shift; -=item $Test->no_fork + local $Test::Builder::Level = $Test::Builder::Level + 1; + $TB->ok($test); + } -=back +To be polite to other functions wrapping your own you usually want to increment C<$Level> rather than set it to a constant. -=head2 CHILDREN AND SUBTESTS +=cut -=over 4 +sub level { + my( $self, $level ) = @_; -=item $Test->subtest($name, \&subtests, @args) + if( defined $level ) { + $Level = $level; + } + return $Level; +} -See documentation of C<subtest> in Test::More. +=item B<use_numbers> -C<subtest> also, and optionally, accepts arguments which will be passed to the -subtests reference. + $Test->use_numbers($on_or_off); -=item $child = $Test->child($name) +Whether or not the test should output numbers. That is, this if true: - my $child = $builder->child($name_of_child); - $child->plan( tests => 4 ); - $child->ok(some_code()); - ... - $child->finalize; + ok 1 + ok 2 + ok 3 -Returns a new instance of C<Test::Builder>. Any output from this child will -be indented four spaces more than the parent's indentation. When done, the -C<finalize> method I<must> be called explicitly. +or this if false -Trying to create a new child with a previous child still active (i.e., -C<finalize> not called) will C<croak>. + ok + ok + ok -Trying to run a test when you have an open child will also C<croak> and cause -the test suite to fail. +Most useful when you can't depend on the test output order, such as +when threads or forking is involved. -=item $ok = $Child->finalize +Defaults to on. -When your child is done running tests, you must call C<finalize> to clean up -and tell the parent your pass/fail status. +=cut -Calling C<finalize> on a child with open children will C<croak>. +sub use_numbers { + my( $self, $use_nums ) = @_; -If the child falls out of scope before C<finalize> is called, a failure -diagnostic will be issued and the child is considered to have failed. + if( defined $use_nums ) { + $self->{Use_Nums} = $use_nums; + } + return $self->{Use_Nums}; +} -No attempt to call methods on a child after C<finalize> is called is -guaranteed to succeed. +=item B<no_diag> -Calling this on the root builder is a no-op. + $Test->no_diag($no_diag); -=back +If set true no diagnostics will be printed. This includes calls to +C<diag()>. -=head2 STREAM MANAGEMENT +=item B<no_ending> -=over 4 + $Test->no_ending($no_ending); -=item $stream = $Test->stream +Normally, Test::Builder does some extra diagnostics when the test +ends. It also changes the exit code as described below. -=item $Test->stream($stream) +If this is true, none of that will be done. -=item $Test->stream(undef) +=item B<no_header> -Get/Set the stream. When no stream is set, or is undef it will return the -shared stream. + $Test->no_header($no_header); -B<Note:> Do not set this to the shared stream yourself, set it to undef. This -is because the shared stream is actually a stack, and this always returns the -top of the stack. +If set to true, no "1..N" header will be printed. -=item $events = $Test->intercept(\&code) +=cut -Any tests run inside the codeblock will be intercepted and not sent to the -normal stream. Instead they will be added to C<$events> which is an array of -L<Test::Builder::Event> objects. +foreach my $attribute (qw(No_Header No_Ending No_Diag)) { + my $method = lc $attribute; -B<Note:> This will also intercept BAIL_OUT and skipall. + my $code = sub { + my( $self, $no ) = @_; -B<Note:> This will only intercept events generated with the Test::Builder -object on which C<intercept()> was called. Other builders will still send to -the normal places. + if( defined $no ) { + $self->{$attribute} = $no; + } + return $self->{$attribute}; + }; -See L<Test::Tester2> for a method of capturing events sent to the global -stream. + no strict 'refs'; ## no critic + *{ __PACKAGE__ . '::' . $method } = $code; +} =back -=head2 TRACING THE TEST/PROVIDER BOUNDRY +=head2 Output -When a test fails it will report the filename and line where the failure -occured. In order to do this it needs to look at the stack and figure out where -your tests stop, and the tools you are using begin. These methods help you find -the desired caller frame. +Controlling where the test output goes. -See the L<Test::Builder::Trace> module for more details. +It's ok for your test to change where STDOUT and STDERR point to, +Test::Builder's default output settings will not be affected. =over 4 -=item $trace = $Test->trace_test() +=item B<diag> -Returns an L<Test::Builder::Trace> object. - -=item $reason = $Test->find_TODO - -=item $reason = $Test->find_TODO($pack) - -=item $old_reason = $Test->find_TODO($pack, 1, $new_reason); - -Like C<todo()> but only returns the value of C<$TODO> ignoring -C<todo_start()>. + $Test->diag(@msgs); -Can also be used to set C<$TODO> to a new value while returning the -old value. +Prints out the given C<@msgs>. Like C<print>, arguments are simply +appended together. -=back +Normally, it uses the C<failure_output()> handle, but if this is for a +TODO test, the C<todo_output()> handle is used. -=head2 TEST PLAN +Output will be indented and marked with a # so as not to interfere +with test output. A newline will be put on the end if there isn't one +already. -=over 4 +We encourage using this rather than calling print directly. -=item $Test->plan('no_plan'); +Returns false. Why? Because C<diag()> is often used in conjunction with +a failing test (C<ok() || diag()>) it "passes through" the failure. -=item $Test->plan( skip_all => $reason ); + return ok(...) || diag(...); -=item $Test->plan( tests => $num_tests ); +=for blame transfer +Mark Fowler <mark@twoshortplanks.com> -A convenient way to set up your tests. Call this and Test::Builder -will print the appropriate headers and take the appropriate actions. +=cut -If you call C<plan()>, don't call any of the other methods below. +sub diag { + my $self = shift; -If a child calls "skip_all" in the plan, a C<Test::Builder::Exception> is -thrown. Trap this error, call C<finalize()> and don't run any more tests on -the child. + $self->_print_comment( $self->_diag_fh, @_ ); +} - my $child = $Test->child('some child'); - eval { $child->plan( $condition ? ( skip_all => $reason ) : ( tests => 3 ) ) }; - if ( eval { $@->isa('Test::Builder::Exception') } ) { - $child->finalize; - return; - } - # run your tests +=item B<note> -=item $Test->no_plan; + $Test->note(@msgs); -Declares that this test will run an indeterminate number of tests. +Like C<diag()>, but it prints to the C<output()> handle so it will not +normally be seen by the user except in verbose mode. -=item $Test->skip_all +=cut -=item $Test->skip_all($reason) +sub note { + my $self = shift; -Skips all the tests, using the given C<$reason>. Exits immediately with 0. + $self->_print_comment( $self->output, @_ ); +} -=item $Test->done_testing +sub _diag_fh { + my $self = shift; -=item $Test->done_testing($count) + local $Level = $Level + 1; + return $self->in_todo ? $self->todo_output : $self->failure_output; +} -Declares that you are done testing, no more tests will be run after this point. +sub _print_comment { + my( $self, $fh, @msgs ) = @_; -If a plan has not yet been output, it will do so. + return if $self->no_diag; + return unless @msgs; -$num_tests is the number of tests you planned to run. If a numbered -plan was already declared, and if this contradicts, a failing event -will be run to reflect the planning mistake. If C<no_plan> was declared, -this will override. + # Prevent printing headers when compiling (i.e. -c) + return if $^C; -If C<done_testing()> is called twice, the second call will issue a -failing event. + # Smash args together like print does. + # Convert undef to 'undef' so its readable. + my $msg = join '', map { defined($_) ? $_ : 'undef' } @msgs; -If C<$num_tests> is omitted, the number of tests run will be used, like -no_plan. + # Escape the beginning, _print will take care of the rest. + $msg =~ s/^/# /; -C<done_testing()> is, in effect, used when you'd want to use C<no_plan>, but -safer. You'd use it like so: + local $Level = $Level + 1; + $self->_print_to_fh( $fh, $msg ); - $Test->ok($a == $b); - $Test->done_testing(); + return 0; +} -Or to plan a variable number of tests: +=item B<explain> - for my $test (@tests) { - $Test->ok($test); - } - $Test->done_testing(scalar @tests); + my @dump = $Test->explain(@msgs); -=back +Will dump the contents of any references in a human readable format. +Handy for things like... -=head2 SIMPLE EVENT PRODUCERS + is_deeply($have, $want) || diag explain $have; -Each of these produces 1 or more L<Test::Builder::Event> objects which are fed -into the event stream. +or -=over 4 + is_deeply($have, $want) || note explain $have; -=item $Test->ok($test) +=cut -=item $Test->ok($test, $name) +sub explain { + my $self = shift; -=item $Test->ok($test, $name, @diag) + return map { + ref $_ + ? do { + $self->_try(sub { require Data::Dumper }, die_on_fail => 1); -Your basic test. Pass if C<$test> is true, fail if $test is false. Just -like L<Test::Simple>'s C<ok()>. + my $dumper = Data::Dumper->new( [$_] ); + $dumper->Indent(1)->Terse(1); + $dumper->Sortkeys(1) if $dumper->can("Sortkeys"); + $dumper->Dump; + } + : $_ + } @_; +} -You may also specify diagnostics messages in the form of simple strings, or -complete <Test::Builder::Event> objects. Typically you would only do this in a -failure, but you are allowed to add diags to passes as well. +=begin _private -=item $Test->BAIL_OUT($reason); +=item B<_print> -Indicates to the L<Test::Harness> that things are going so badly all -testing should terminate. This includes running any additional test -scripts. + $Test->_print(@msgs); -It will exit with 255. +Prints to the C<output()> filehandle. -=item $Test->skip +=end _private -=item $Test->skip($why) +=cut -Skips the current test, reporting C<$why>. +sub _print { + my $self = shift; + return $self->_print_to_fh( $self->output, @_ ); +} -=item $Test->todo_skip +sub _print_to_fh { + my( $self, $fh, @msgs ) = @_; -=item $Test->todo_skip($why) + # Prevent printing headers when only compiling. Mostly for when + # tests are deparsed with B::Deparse + return if $^C; -Like C<skip()>, only it will declare the test as failing and TODO. Similar -to + my $msg = join '', @msgs; + my $indent = $self->_indent; - print "not ok $tnum # TODO $why\n"; + local( $\, $", $, ) = ( undef, ' ', '' ); -=item $Test->diag(@msgs) + # Escape each line after the first with a # so we don't + # confuse Test::Harness. + $msg =~ s{\n(?!\z)}{\n$indent# }sg; -Prints out the given C<@msgs>. Like C<print>, arguments are simply -appended together. + # Stick a newline on the end if it needs it. + $msg .= "\n" unless $msg =~ /\n\z/; -Normally, it uses the C<failure_output()> handle, but if this is for a -TODO test, the C<todo_output()> handle is used. + return print $fh $indent, $msg; +} -Output will be indented and marked with a # so as not to interfere -with test output. A newline will be put on the end if there isn't one -already. +=item B<output> -We encourage using this rather than calling print directly. +=item B<failure_output> -Returns false. Why? Because C<diag()> is often used in conjunction with -a failing test (C<ok() || diag()>) it "passes through" the failure. +=item B<todo_output> - return ok(...) || diag(...); + my $filehandle = $Test->output; + $Test->output($filehandle); + $Test->output($filename); + $Test->output(\$scalar); -=item $Test->note(@msgs) +These methods control where Test::Builder will print its output. +They take either an open C<$filehandle>, a C<$filename> to open and write to +or a C<$scalar> reference to append to. It will always return a C<$filehandle>. -Like C<diag()>, but it prints to the C<output()> handle so it will not -normally be seen by the user except in verbose mode. +B<output> is where normal "ok/not ok" test output goes. -=back +Defaults to STDOUT. -=head2 ADVANCED EVENT PRODUCERS +B<failure_output> is where diagnostic output on test failures and +C<diag()> goes. It is normally not read by Test::Harness and instead is +displayed to the user. -=over 4 +Defaults to STDERR. -=item $Test->is_eq($got, $expected, $name) +C<todo_output> is used instead of C<failure_output()> for the +diagnostics of a failing TODO test. These will not be seen by the +user. -Like Test::More's C<is()>. Checks if C<$got eq $expected>. This is the -string version. +Defaults to STDOUT. -C<undef> only ever matches another C<undef>. +=cut -=item $Test->is_num($got, $expected, $name) +sub output { + my( $self, $fh ) = @_; -Like Test::More's C<is()>. Checks if C<$got == $expected>. This is the -numeric version. + if( defined $fh ) { + $self->{Out_FH} = $self->_new_fh($fh); + } + return $self->{Out_FH}; +} -C<undef> only ever matches another C<undef>. +sub failure_output { + my( $self, $fh ) = @_; -=item $Test->isnt_eq($got, $dont_expect, $name) + if( defined $fh ) { + $self->{Fail_FH} = $self->_new_fh($fh); + } + return $self->{Fail_FH}; +} -Like L<Test::More>'s C<isnt()>. Checks if C<$got ne $dont_expect>. This is -the string version. +sub todo_output { + my( $self, $fh ) = @_; -=item $Test->isnt_num($got, $dont_expect, $name) + if( defined $fh ) { + $self->{Todo_FH} = $self->_new_fh($fh); + } + return $self->{Todo_FH}; +} -Like L<Test::More>'s C<isnt()>. Checks if C<$got ne $dont_expect>. This is -the numeric version. +sub _new_fh { + my $self = shift; + my($file_or_fh) = shift; -=item $Test->like($thing, qr/$regex/, $name) + my $fh; + if( $self->is_fh($file_or_fh) ) { + $fh = $file_or_fh; + } + elsif( ref $file_or_fh eq 'SCALAR' ) { + # Scalar refs as filehandles was added in 5.8. + if( $] >= 5.008 ) { + open $fh, ">>", $file_or_fh + or $self->croak("Can't open scalar ref $file_or_fh: $!"); + } + # Emulate scalar ref filehandles with a tie. + else { + $fh = Test::Builder::IO::Scalar->new($file_or_fh) + or $self->croak("Can't tie scalar ref $file_or_fh"); + } + } + else { + open $fh, ">", $file_or_fh + or $self->croak("Can't open test output log $file_or_fh: $!"); + _autoflush($fh); + } -=item $Test->like($thing, '/$regex/', $name) + return $fh; +} -Like L<Test::More>'s C<like()>. Checks if $thing matches the given C<$regex>. +sub _autoflush { + my($fh) = shift; + my $old_fh = select $fh; + $| = 1; + select $old_fh; -=item $Test->unlike($thing, qr/$regex/, $name) + return; +} -=item $Test->unlike($thing, '/$regex/', $name) +my( $Testout, $Testerr ); -Like L<Test::More>'s C<unlike()>. Checks if $thing $Test->does not match the -given C<$regex>. +sub _dup_stdhandles { + my $self = shift; -=item $Test->cmp_ok($thing, $type, $that, $name) + $self->_open_testhandles; -Works just like L<Test::More>'s C<cmp_ok()>. + # Set everything to unbuffered else plain prints to STDOUT will + # come out in the wrong order from our own prints. + _autoflush($Testout); + _autoflush( \*STDOUT ); + _autoflush($Testerr); + _autoflush( \*STDERR ); - $Test->cmp_ok($big_num, '!=', $other_big_num); + $self->reset_outputs; -=back + return; +} -=head2 PUBLIC HELPERS +sub _open_testhandles { + my $self = shift; -=over 4 + return if $self->{Opened_Testhandles}; -=item @dump = $Test->explain(@msgs) + # We dup STDOUT and STDERR so people can change them in their + # test suites while still getting normal test output. + open( $Testout, ">&STDOUT" ) or die "Can't dup STDOUT: $!"; + open( $Testerr, ">&STDERR" ) or die "Can't dup STDERR: $!"; -Will dump the contents of any references in a human readable format. -Handy for things like... + $self->_copy_io_layers( \*STDOUT, $Testout ); + $self->_copy_io_layers( \*STDERR, $Testerr ); - is_deeply($have, $want) || diag explain $have; + $self->{Opened_Testhandles} = 1; -or + return; +} - is_deeply($have, $want) || note explain $have; +sub _copy_io_layers { + my( $self, $src, $dst ) = @_; -=item $tb->carp(@message) + $self->_try( + sub { + require PerlIO; + my @src_layers = PerlIO::get_layers($src); -Warns with C<@message> but the message will appear to come from the -point where the original test function was called (C<< $tb->caller >>). + _apply_layers($dst, @src_layers) if @src_layers; + } + ); -=item $tb->croak(@message) + return; +} -Dies with C<@message> but the message will appear to come from the -point where the original test function was called (C<< $tb->caller >>). +sub _apply_layers { + my ($fh, @layers) = @_; + my %seen; + my @unique = grep { $_ ne 'unix' and !$seen{$_}++ } @layers; + binmode($fh, join(":", "", "raw", @unique)); +} -=item $plan = $Test->has_plan -Find out whether a plan has been defined. C<$plan> is either C<undef> (no plan -has been set), C<no_plan> (indeterminate # of tests) or an integer (the number -of expected tests). +=item reset_outputs -=item $Test->reset + $tb->reset_outputs; -Reinitializes the Test::Builder singleton to its original state. -Mostly useful for tests run in persistent environments where the same -test might be run multiple times in the same process. +Resets all the output filehandles back to their defaults. -=item %context = $Test->context +=cut -Returns a hash of contextual info. +sub reset_outputs { + my $self = shift; - ( - depth => DEPTH, - source => NAME, - trace => TRACE, - ) + $self->output ($Testout); + $self->failure_output($Testerr); + $self->todo_output ($Testout); -=back + return; +} -=head2 TODO MANAGEMENT +=item carp -=over 4 + $tb->carp(@message); -=item $todo_reason = $Test->todo +Warns with C<@message> but the message will appear to come from the +point where the original test function was called (C<< $tb->caller >>). -=item $todo_reason = $Test->todo($pack) +=item croak -If the current tests are considered "TODO" it will return the reason, -if any. This reason can come from a C<$TODO> variable or the last call -to C<todo_start()>. + $tb->croak(@message); -Since a TODO test does not need a reason, this function can return an -empty string even when inside a TODO block. Use C<< $Test->in_todo >> -to determine if you are currently inside a TODO block. +Dies with C<@message> but the message will appear to come from the +point where the original test function was called (C<< $tb->caller >>). -C<todo()> is about finding the right package to look for C<$TODO> in. It's -pretty good at guessing the right package to look at. It considers the stack -trace, C<$Level>, and metadata associated with various packages. +=cut -Sometimes there is some confusion about where C<todo()> should be looking -for the C<$TODO> variable. If you want to be sure, tell it explicitly -what $pack to use. +sub _message_at_caller { + my $self = shift; -=item $in_todo = $Test->in_todo + local $Level = $Level + 1; + my( $pack, $file, $line ) = $self->caller; + return join( "", @_ ) . " at $file line $line.\n"; +} -Returns true if the test is currently inside a TODO block. +sub carp { + my $self = shift; + return warn $self->_message_at_caller(@_); +} -=item $Test->todo_start() +sub croak { + my $self = shift; + return die $self->_message_at_caller(@_); +} -=item $Test->todo_start($message) -This method allows you declare all subsequent tests as TODO tests, up until -the C<todo_end> method has been called. +=back -The C<TODO:> and C<$TODO> syntax is generally pretty good about figuring out -whether or not we're in a TODO test. However, often we find that this is not -possible to determine (such as when we want to use C<$TODO> but -the tests are being executed in other packages which can't be inferred -beforehand). -Note that you can use this to nest "todo" tests +=head2 Test Status and Info - $Test->todo_start('working on this'); - # lots of code - $Test->todo_start('working on that'); - # more code - $Test->todo_end; - $Test->todo_end; +=over 4 -This is generally not recommended, but large testing systems often have weird -internal needs. +=item B<current_test> -We've tried to make this also work with the TODO: syntax, but it's not -guaranteed and its use is also discouraged: + my $curr_test = $Test->current_test; + $Test->current_test($num); - TODO: { - local $TODO = 'We have work to do!'; - $Test->todo_start('working on this'); - # lots of code - $Test->todo_start('working on that'); - # more code - $Test->todo_end; - $Test->todo_end; - } +Gets/sets the current test number we're on. You usually shouldn't +have to set this. -Pick one style or another of "TODO" to be on the safe side. +If set forward, the details of the missing tests are filled in as 'unknown'. +if set backward, the details of the intervening tests are deleted. You +can erase history if you really want to. -=item $Test->todo_end +=cut -Stops running tests as "TODO" tests. This method is fatal if called without a -preceding C<todo_start> method call. +sub current_test { + my( $self, $num ) = @_; + + lock( $self->{Curr_Test} ); + if( defined $num ) { + $self->{Curr_Test} = $num; + + # If the test counter is being pushed forward fill in the details. + my $test_results = $self->{Test_Results}; + if( $num > @$test_results ) { + my $start = @$test_results ? @$test_results : 0; + for( $start .. $num - 1 ) { + $test_results->[$_] = &share( + { + 'ok' => 1, + actual_ok => undef, + reason => 'incrementing test number', + type => 'unknown', + name => undef + } + ); + } + } + # If backward, wipe history. Its their funeral. + elsif( $num < @$test_results ) { + $#{$test_results} = $num - 1; + } + } + return $self->{Curr_Test}; +} -=back +=item B<is_passing> -=head2 DEPRECATED/LEGACY + my $ok = $builder->is_passing; -All of these will issue warnings if called on a modern Test::Builder object. -That is any Test::Builder instance that was created with the 'modern' flag. +Indicates if the test suite is currently passing. -=over +More formally, it will be false if anything has happened which makes +it impossible for the test suite to pass. True otherwise. -=item $self->no_ending +For example, if no tests have run C<is_passing()> will be true because +even though a suite with no tests is a failure you can add a passing +test to it and start passing. -B<Deprecated:> Moved to the L<Test::Builder::Stream> object. +Don't think about it too much. - $Test->no_ending($no_ending); +=cut -Normally, Test::Builder does some extra diagnostics when the test -ends. It also changes the exit code as described below. +sub is_passing { + my $self = shift; -If this is true, none of that will be done. + if( @_ ) { + $self->{Is_Passing} = shift; + } -=item $self->summary + return $self->{Is_Passing}; +} -B<Deprecated:> Moved to the L<Test::Builder::Stream> object. -The style of result recording used here is deprecated. The functionality was -moved to its own object to contain the legacy code. +=item B<summary> my @tests = $Test->summary; @@ -2064,18 +2121,21 @@ This is a logical pass/fail, so todos are passes. Of course, test #1 is $tests[0], etc... -=item $self->details +=cut -B<Deprecated:> Moved to the L<Test::Builder::Formatter::LegacyEvents> object. +sub summary { + my($self) = shift; -The style of result recording used here is deprecated. The functionality was -moved to its own object to contain the legacy code. + return map { $_->{'ok'} } @{ $self->{Test_Results} }; +} + +=item B<details> my @tests = $Test->details; Like C<summary()>, but with a lot more detail. - $tests[$test_num - 1] = + $tests[$test_num - 1] = { 'ok' => is the test considered a pass? actual_ok => did it literally say 'ok'? name => name of the test (if any) @@ -2116,133 +2176,180 @@ result in this structure: reason => 'insufficient donuts' }; -=item $self->no_header +=cut -B<Deprecated:> moved to the L<Test::Builder::Formatter::TAP> object. +sub details { + my $self = shift; + return @{ $self->{Test_Results} }; +} - $Test->no_header($no_header); +=item B<todo> -If set to true, no "1..N" header will be printed. + my $todo_reason = $Test->todo; + my $todo_reason = $Test->todo($pack); -=item $self->no_diag +If the current tests are considered "TODO" it will return the reason, +if any. This reason can come from a C<$TODO> variable or the last call +to C<todo_start()>. -B<Deprecated:> moved to the L<Test::Builder::Formatter::TAP> object. +Since a TODO test does not need a reason, this function can return an +empty string even when inside a TODO block. Use C<< $Test->in_todo >> +to determine if you are currently inside a TODO block. -If set true no diagnostics will be printed. This includes calls to -C<diag()>. +C<todo()> is about finding the right package to look for C<$TODO> in. It's +pretty good at guessing the right package to look at. It first looks for +the caller based on C<$Level + 1>, since C<todo()> is usually called inside +a test function. As a last resort it will use C<exported_to()>. -=item $self->output +Sometimes there is some confusion about where todo() should be looking +for the C<$TODO> variable. If you want to be sure, tell it explicitly +what $pack to use. -=item $self->failure_output +=cut -=item $self->todo_output +sub todo { + my( $self, $pack ) = @_; -B<Deprecated:> moved to the L<Test::Builder::Formatter::TAP> object. + return $self->{Todo} if defined $self->{Todo}; - my $filehandle = $Test->output; - $Test->output($filehandle); - $Test->output($filename); - $Test->output(\$scalar); + local $Level = $Level + 1; + my $todo = $self->find_TODO($pack); + return $todo if defined $todo; -These methods control where Test::Builder will print its output. -They take either an open C<$filehandle>, a C<$filename> to open and write to -or a C<$scalar> reference to append to. It will always return a C<$filehandle>. + return ''; +} -B<output> is where normal "ok/not ok" test output goes. +=item B<find_TODO> -Defaults to STDOUT. + my $todo_reason = $Test->find_TODO(); + my $todo_reason = $Test->find_TODO($pack); -B<failure_output> is where diagnostic output on test failures and -C<diag()> goes. It is normally not read by Test::Harness and instead is -displayed to the user. +Like C<todo()> but only returns the value of C<$TODO> ignoring +C<todo_start()>. -Defaults to STDERR. +Can also be used to set C<$TODO> to a new value while returning the +old value: -C<todo_output> is used instead of C<failure_output()> for the -diagnostics of a failing TODO test. These will not be seen by the -user. + my $old_reason = $Test->find_TODO($pack, 1, $new_reason); -Defaults to STDOUT. +=cut -=item $self->reset_outputs +sub find_TODO { + my( $self, $pack, $set, $new_value ) = @_; -B<Deprecated:> moved to the L<Test::Builder::Formatter::TAP> object. + $pack = $pack || $self->caller(1) || $self->exported_to; + return unless $pack; - $tb->reset_outputs; + no strict 'refs'; ## no critic + my $old_value = ${ $pack . '::TODO' }; + $set and ${ $pack . '::TODO' } = $new_value; + return $old_value; +} -Resets all the output filehandles back to their defaults. +=item B<in_todo> -=item $self->use_numbers + my $in_todo = $Test->in_todo; -B<Deprecated:> moved to the L<Test::Builder::Formatter::TAP> object. +Returns true if the test is currently inside a TODO block. - $Test->use_numbers($on_or_off); +=cut -Whether or not the test should output numbers. That is, this if true: +sub in_todo { + my $self = shift; - ok 1 - ok 2 - ok 3 + local $Level = $Level + 1; + return( defined $self->{Todo} || $self->find_TODO ) ? 1 : 0; +} -or this if false +=item B<todo_start> - ok - ok - ok + $Test->todo_start(); + $Test->todo_start($message); -Most useful when you can't depend on the test output order, such as -when threads or forking is involved. +This method allows you declare all subsequent tests as TODO tests, up until +the C<todo_end> method has been called. -Defaults to on. +The C<TODO:> and C<$TODO> syntax is generally pretty good about figuring out +whether or not we're in a TODO test. However, often we find that this is not +possible to determine (such as when we want to use C<$TODO> but +the tests are being executed in other packages which can't be inferred +beforehand). -=item $pack = $Test->exported_to +Note that you can use this to nest "todo" tests -=item $Test->exported_to($pack) + $Test->todo_start('working on this'); + # lots of code + $Test->todo_start('working on that'); + # more code + $Test->todo_end; + $Test->todo_end; -B<Deprecated:> Use C<< Test::Builder::Trace->anoint($package) >> and -C<< $Test->trace_anointed >> instead. +This is generally not recommended, but large testing systems often have weird +internal needs. -Tells Test::Builder what package you exported your functions to. +We've tried to make this also work with the TODO: syntax, but it's not +guaranteed and its use is also discouraged: -This method isn't terribly useful since modules which share the same -Test::Builder object might get exported to different packages and only -the last one will be honored. + TODO: { + local $TODO = 'We have work to do!'; + $Test->todo_start('working on this'); + # lots of code + $Test->todo_start('working on that'); + # more code + $Test->todo_end; + $Test->todo_end; + } -=item $is_fh = $Test->is_fh($thing); +Pick one style or another of "TODO" to be on the safe side. -Determines if the given C<$thing> can be used as a filehandle. +=cut -=item $curr_test = $Test->current_test; +sub todo_start { + my $self = shift; + my $message = @_ ? shift : ''; -=item $Test->current_test($num); + $self->{Start_Todo}++; + if( $self->in_todo ) { + push @{ $self->{Todo_Stack} } => $self->todo; + } + $self->{Todo} = $message; -Gets/sets the current test number we're on. You usually shouldn't -have to set this. + return; +} -If set forward, the details of the missing tests are filled in as 'unknown'. -if set backward, the details of the intervening tests are deleted. You -can erase history if you really want to. +=item C<todo_end> -=item $Test->BAIL_OUT($reason); + $Test->todo_end; -Indicates to the L<Test::Harness> that things are going so badly all -testing should terminate. This includes running any additional test -scripts. +Stops running tests as "TODO" tests. This method is fatal if called without a +preceding C<todo_start> method call. -It will exit with 255. +=cut + +sub todo_end { + my $self = shift; -=item $max = $Test->expected_tests + if( !$self->{Start_Todo} ) { + $self->croak('todo_end() called without todo_start()'); + } -=item $Test->expected_tests($max) + $self->{Start_Todo}--; -Gets/sets the number of tests we expect this test to run and prints out -the appropriate headers. + if( $self->{Start_Todo} && @{ $self->{Todo_Stack} } ) { + $self->{Todo} = pop @{ $self->{Todo_Stack} }; + } + else { + delete $self->{Todo}; + } -=item $package = $Test->caller + return; +} -=item ($pack, $file, $line) = $Test->caller +=item B<caller> -=item ($pack, $file, $line) = $Test->caller($height) + my $package = $Test->caller; + my($pack, $file, $line) = $Test->caller; + my($pack, $file, $line) = $Test->caller($height); Like the normal C<caller()>, except it reports according to your C<level()>. @@ -2250,103 +2357,232 @@ C<$height> will be added to the C<level()>. If C<caller()> winds up off the top of the stack it report the highest context. -=item $Test->level($how_high) +=cut -B<DEPRECATED> See deprecation notes at the top. The use of C<level()> is -deprecated. +sub caller { ## no critic (Subroutines::ProhibitBuiltinHomonyms) + my( $self, $height ) = @_; + $height ||= 0; -How far up the call stack should C<$Test> look when reporting where the -test failed. + my $level = $self->level + $height + 1; + my @caller; + do { + @caller = CORE::caller( $level ); + $level--; + } until @caller; + return wantarray ? @caller : $caller[0]; +} -Defaults to 1. +=back -Setting L<$Test::Builder::Level> overrides. This is typically useful -localized: +=cut - sub my_ok { - my $test = shift; +=begin _private - local $Test::Builder::Level = $Test::Builder::Level + 1; - $TB->ok($test); - } +=over 4 -To be polite to other functions wrapping your own you usually want to increment -C<$Level> rather than set it to a constant. +=item B<_sanity_check> -=item $Test->maybe_regex(qr/$regex/) + $self->_sanity_check(); -=item $Test->maybe_regex('/$regex/') +Runs a bunch of end of test sanity checks to make sure reality came +through ok. If anything is wrong it will die with a fairly friendly +error message. -This method used to be useful back when Test::Builder worked on Perls -before 5.6 which didn't have qr//. Now its pretty useless. +=cut -Convenience method for building testing functions that take regular -expressions as arguments. +#'# +sub _sanity_check { + my $self = shift; -Takes a quoted regular expression produced by C<qr//>, or a string -representing a regular expression. + $self->_whoa( $self->{Curr_Test} < 0, 'Says here you ran a negative number of tests!' ); + $self->_whoa( $self->{Curr_Test} != @{ $self->{Test_Results} }, + 'Somehow you got a different number of results than tests ran!' ); -Returns a Perl value which may be used instead of the corresponding -regular expression, or C<undef> if its argument is not recognised. + return; +} -For example, a version of C<like()>, sans the useful diagnostic messages, -could be written as: +=item B<_whoa> - sub laconic_like { - my ($self, $thing, $regex, $name) = @_; - my $usable_regex = $self->maybe_regex($regex); - die "expecting regex, found '$regex'\n" - unless $usable_regex; - $self->ok($thing =~ m/$usable_regex/, $name); - } + $self->_whoa($check, $description); + +A sanity check, similar to C<assert()>. If the C<$check> is true, something +has gone horribly wrong. It will die with the given C<$description> and +a note to contact the author. + +=cut + +sub _whoa { + my( $self, $check, $desc ) = @_; + if($check) { + local $Level = $Level + 1; + $self->croak(<<"WHOA"); +WHOA! $desc +This should never happen! Please contact the author immediately! +WHOA + } + + return; +} + +=item B<_my_exit> + + _my_exit($exit_num); + +Perl seems to have some trouble with exiting inside an C<END> block. +5.6.1 does some odd things. Instead, this function edits C<$?> +directly. It should B<only> be called from inside an C<END> block. +It doesn't actually exit, that's your job. + +=cut + +sub _my_exit { + $? = $_[0]; ## no critic (Variables::RequireLocalizedPunctuationVars) + + return 1; +} =back -=head1 PACKAGE VARIABLES +=end _private -B<NOTE>: These are tied to the package, not the instance. Basically that means -touching these can affect more things than you expect. Using these can lead to -unexpected interactions at a distance. +=cut -=over 4 +sub _ending { + my $self = shift; + return if $self->no_ending; + return if $self->{Ending}++; + + my $real_exit_code = $?; + + # Don't bother with an ending if this is a forked copy. Only the parent + # should do the ending. + if( $self->{Original_Pid} != $$ ) { + return; + } -=item C<$Level> + # Ran tests but never declared a plan or hit done_testing + if( !$self->{Have_Plan} and $self->{Curr_Test} ) { + $self->is_passing(0); + $self->diag("Tests were run but no plan was declared and done_testing() was not seen."); + + if($real_exit_code) { + $self->diag(<<"FAIL"); +Looks like your test exited with $real_exit_code just after $self->{Curr_Test}. +FAIL + $self->is_passing(0); + _my_exit($real_exit_code) && return; + } -Originally this was the only way to tell Test::Builder where in the stack -errors should be reported. Now the preferred method of finding where errors -should be reported is using the L<Test::Builder::Trace> and -L<Test::Builder::Provider> modules. + # But if the tests ran, handle exit code. + my $test_results = $self->{Test_Results}; + if(@$test_results) { + my $num_failed = grep !$_->{'ok'}, @{$test_results}[ 0 .. $self->{Curr_Test} - 1 ]; + if ($num_failed > 0) { -C<$Level> should be considered deprecated when possible, that said it will not -be removed any time soon. There is too much legacy code that depends on -C<$Level>. There are also a couple situations in which C<$Level> is necessary: + my $exit_code = $num_failed <= 254 ? $num_failed : 254; + _my_exit($exit_code) && return; + } + } + _my_exit(254) && return; + } -=over 4 + # Exit if plan() was never called. This is so "require Test::Simple" + # doesn't puke. + if( !$self->{Have_Plan} ) { + return; + } -=item Backwards compatibility + # Don't do an ending if we bailed out. + if( $self->{Bailed_Out} ) { + $self->is_passing(0); + return; + } + # Figure out if we passed or failed and print helpful messages. + my $test_results = $self->{Test_Results}; + if(@$test_results) { + # The plan? We have no plan. + if( $self->{No_Plan} ) { + $self->_output_plan($self->{Curr_Test}) unless $self->no_header; + $self->{Expected_Tests} = $self->{Curr_Test}; + } -If code simply cannot depend on a recent version of Test::Builder, then $Level -must be used as there is no alternative. See L<Test::Builder::Compat> for tools -to help make test tools that work in old and new versions. + # Auto-extended arrays and elements which aren't explicitly + # filled in with a shared reference will puke under 5.8.0 + # ithreads. So we have to fill them in by hand. :( + my $empty_result = &share( {} ); + for my $idx ( 0 .. $self->{Expected_Tests} - 1 ) { + $test_results->[$idx] = $empty_result + unless defined $test_results->[$idx]; + } -=item Stack Management + my $num_failed = grep !$_->{'ok'}, @{$test_results}[ 0 .. $self->{Curr_Test} - 1 ]; -Using L<Test::Builder::Provider> is not practical for situations like in -L<Test::Exception> where one needs to munge the call stack to hide frames. + my $num_extra = $self->{Curr_Test} - $self->{Expected_Tests}; -=back + if( $num_extra != 0 ) { + my $s = $self->{Expected_Tests} == 1 ? '' : 's'; + $self->diag(<<"FAIL"); +Looks like you planned $self->{Expected_Tests} test$s but ran $self->{Curr_Test}. +FAIL + $self->is_passing(0); + } -=item C<$BLevel> + if($num_failed) { + my $num_tests = $self->{Curr_Test}; + my $s = $num_failed == 1 ? '' : 's'; -Used internally by the L<Test::Builder::Trace>, do not modify or rely on this -in your own code. Documented for completeness. + my $qualifier = $num_extra == 0 ? '' : ' run'; -=item C<$Test> + $self->diag(<<"FAIL"); +Looks like you failed $num_failed test$s of $num_tests$qualifier. +FAIL + $self->is_passing(0); + } -The singleton returned by C<new()>, which is deprecated in favor of -C<create()>. + if($real_exit_code) { + $self->diag(<<"FAIL"); +Looks like your test exited with $real_exit_code just after $self->{Curr_Test}. +FAIL + $self->is_passing(0); + _my_exit($real_exit_code) && return; + } -=back + my $exit_code; + if($num_failed) { + $exit_code = $num_failed <= 254 ? $num_failed : 254; + } + elsif( $num_extra != 0 ) { + $exit_code = 255; + } + else { + $exit_code = 0; + } + + _my_exit($exit_code) && return; + } + elsif( $self->{Skip_All} ) { + _my_exit(0) && return; + } + elsif($real_exit_code) { + $self->diag(<<"FAIL"); +Looks like your test exited with $real_exit_code before it could output anything. +FAIL + $self->is_passing(0); + _my_exit($real_exit_code) && return; + } + else { + $self->diag("No tests run!\n"); + $self->is_passing(0); + _my_exit(255) && return; + } + + $self->is_passing(0); + $self->_whoa( 1, "We fell off the end of _ending()" ); +} + +END { + $Test->_ending if defined $Test; +} =head1 EXIT CODES @@ -2366,13 +2602,11 @@ So the exit codes are... If you fail more than 254 tests, it will be reported as 254. -B<Note:> The magic that accomplishes this has been moved to -L<Test::Builder::ExitMagic> - =head1 THREADS In perl 5.8.1 and later, Test::Builder is thread-safe. The test -number is shared amongst all threads. +number is shared amongst all threads. This means if one thread sets +the test number using C<current_test()> they will all be effected. While versions earlier than 5.8.1 had threads they contain too many bugs to support. @@ -2382,11 +2616,7 @@ Test::Builder. =head1 MEMORY -B<Note:> This only applies if you turn lresults on. - - $Test->stream->no_lresults; - -An informative hash, accessible via C<details()>, is stored for each +An informative hash, accessible via C<<details()>>, is stored for each test you perform. So memory usage will scale linearly with each test run. Although this is not a problem for most test suites, it can become an issue if you do large (hundred thousands to million) @@ -2394,22 +2624,24 @@ combinatorics tests in the same run. In such cases, you are advised to either split the test file into smaller ones, or use a reverse approach, doing "normal" (code) compares and -triggering C<fail()> should anything go unexpected. +triggering fail() should anything go unexpected. + +Future versions of Test::Builder will have a way to turn history off. + =head1 EXAMPLES -CPAN can provide the best examples. L<Test::Simple>, L<Test::More>, -L<Test::Exception> and L<Test::Differences> all use Test::Builder. +CPAN can provide the best examples. Test::Simple, Test::More, +Test::Exception and Test::Differences all use Test::Builder. =head1 SEE ALSO -L<Test::Simple>, L<Test::More>, L<Test::Harness>, L<Fennec> +Test::Simple, Test::More, Test::Harness =head1 AUTHORS Original code by chromatic, maintained by Michael G Schwern -E<lt>schwern@pobox.comE<gt> until 2014. Currently maintained by Chad Granum -E<lt>exodist7@gmail.comE<gt>. +E<lt>schwern@pobox.comE<gt> =head1 MAINTAINERS @@ -2421,12 +2653,15 @@ E<lt>exodist7@gmail.comE<gt>. =head1 COPYRIGHT -Copyright 2002-2014 by chromatic E<lt>chromatic@wgz.orgE<gt> and - Michael G Schwern E<lt>schwern@pobox.comE<gt> and - Chad Granum E<lt>exodist7@gmail.comE<gt> +Copyright 2002-2008 by chromatic E<lt>chromatic@wgz.orgE<gt> and + Michael G Schwern E<lt>schwern@pobox.comE<gt>. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See F<http://www.perl.com/perl/misc/Artistic.html> +=cut + +1; + diff --git a/cpan/Test-Simple/lib/Test/Builder/Event.pm b/cpan/Test-Simple/lib/Test/Builder/Event.pm deleted file mode 100644 index e48723d8bf..0000000000 --- a/cpan/Test-Simple/lib/Test/Builder/Event.pm +++ /dev/null @@ -1,134 +0,0 @@ -package Test::Builder::Event; -use strict; -use warnings; - -use Carp qw/confess/; -use Scalar::Util qw/blessed/; - -use Test::Builder::Util qw/accessors new/; - -accessors(qw/trace pid depth in_todo source constructed/); - -sub init { - my $self = shift; - my %params = @_; - - $self->constructed([caller(1)]); - $self->pid($$) unless $params{pid}; -} - -sub type { - my $self = shift; - my $class = blessed($self); - if ($class && $class =~ m/^.*::([^:]+)$/) { - return lc($1); - } - - confess "Could not determine event type for $self"; -} - -sub indent { - my $self = shift; - return '' unless $self->depth; - return ' ' x $self->depth; -} - -sub encoding { - my $self = shift; - return unless $self->trace; - return $self->trace->encoding; -} - -1; - -__END__ - -=head1 NAME - -Test::Builder::Event - Base class for events - -=head1 DESCRIPTION - -Base class for all event objects that get passed through -L<Test::Builder::Stream>. - -=head1 METHODS - -=head2 CONSTRUCTORS - -=over 4 - -=item $r = $class->new(...) - -Create a new instance - -=back - -=head2 SIMPLE READ/WRITE ACCESSORS - -=over 4 - -=item $r->trace - -Get the test trace info, including where to report errors. - -=item $r->pid - -PID in which the event was created. - -=item $r->depth - -Builder depth of the event (0 for normal, 1 for subtest, 2 for nested, etc). - -=item $r->in_todo - -True if the event was generated inside a todo. - -=item $r->source - -Builder that created the event, usually $0, but the name of a subtest when -inside a subtest. - -=item $r->constructed - -Package, File, and Line in which the event was built. - -=back - -=head2 INFORMATION - -=over 4 - -=item $r->type - -Type of event. Usually this is the lowercased name from the end of the -package. L<Test::Builder::Event::Ok> = 'ok'. - -=item $r->indent - -Returns the indentation that should be used to display the event (' ' x -depth). - -=back - -=head1 AUTHORS - -=over 4 - -=item Chad Granum E<lt>exodist@cpan.orgE<gt> - -=back - -=head1 SOURCE - -The source code repository for Test::More can be found at -F<http://github.com/Test-More/test-more/>. - -=head1 COPYRIGHT - -Copyright 2014 Chad Granum E<lt>exodist7@gmail.comE<gt>. - -This program is free software; you can redistribute it and/or -modify it under the same terms as Perl itself. - -See F<http://www.perl.com/perl/misc/Artistic.html> diff --git a/cpan/Test-Simple/lib/Test/Builder/Event/Bail.pm b/cpan/Test-Simple/lib/Test/Builder/Event/Bail.pm deleted file mode 100644 index d23dc3753d..0000000000 --- a/cpan/Test-Simple/lib/Test/Builder/Event/Bail.pm +++ /dev/null @@ -1,116 +0,0 @@ -package Test::Builder::Event::Bail; -use strict; -use warnings; - -use base 'Test::Builder::Event'; - -use Test::Builder::Util qw/accessors/; -accessors qw/reason/; - -sub to_tap { - my $self = shift; - return "Bail out! " . $self->reason . "\n"; -} - -1; - -__END__ - -=head1 NAME - -Test::Builder::Event::Bail - Bailout! - -=head1 DESCRIPTION - -Sent when the test needs to bail out. - -=head1 METHODS - -See L<Test::Builder::Event> which is the base class for this module. - -=head2 CONSTRUCTORS - -=over 4 - -=item $r = $class->new(...) - -Create a new instance - -=back - -=head2 SIMPLE READ/WRITE ACCESSORS - -=over 4 - -=item $r->reason - -Reason for the bailout. - -=item $r->trace - -Get the test trace info, including where to report errors. - -=item $r->pid - -PID in which the event was created. - -=item $r->depth - -Builder depth of the event (0 for normal, 1 for subtest, 2 for nested, etc). - -=item $r->in_todo - -True if the event was generated inside a todo. - -=item $r->source - -Builder that created the event, usually $0, but the name of a subtest when -inside a subtest. - -=item $r->constructed - -Package, File, and Line in which the event was built. - -=back - -=head2 INFORMATION - -=over 4 - -=item $r->to_tap - -Returns the TAP string for the plan (not indented). - -=item $r->type - -Type of event. Usually this is the lowercased name from the end of the -package. L<Test::Builder::Event::Ok> = 'ok'. - -=item $r->indent - -Returns the indentation that should be used to display the event (' ' x -depth). - -=back - -=head1 AUTHORS - -=over 4 - -=item Chad Granum E<lt>exodist@cpan.orgE<gt> - -=back - -=head1 SOURCE - -The source code repository for Test::More can be found at -F<http://github.com/Test-More/test-more/>. - -=head1 COPYRIGHT - -Copyright 2014 Chad Granum E<lt>exodist7@gmail.comE<gt>. - -This program is free software; you can redistribute it and/or -modify it under the same terms as Perl itself. - -See F<http://www.perl.com/perl/misc/Artistic.html> diff --git a/cpan/Test-Simple/lib/Test/Builder/Event/Child.pm b/cpan/Test-Simple/lib/Test/Builder/Event/Child.pm deleted file mode 100644 index dd802a1308..0000000000 --- a/cpan/Test-Simple/lib/Test/Builder/Event/Child.pm +++ /dev/null @@ -1,146 +0,0 @@ -package Test::Builder::Event::Child; -use strict; -use warnings; - -use base 'Test::Builder::Event'; - -use Carp qw/confess/; - -use Test::Builder::Util qw/accessors/; -accessors qw/name is_subtest/; - -sub action { - my $self = shift; - if (@_) { - my ($action) = @_; - confess "action must be one of 'push' or 'pop'" - unless $action =~ m/^(push|pop)$/; - - $self->{action} = $action; - } - - confess "action was never set!" - unless $self->{action}; - - return $self->{action}; -} - -sub to_tap { } - -1; - -__END__ - -=head1 NAME - -Test::Builder::Event::Child - Child event type - -=head1 DESCRIPTION - -Sent when a child Builder is spawned, such as a subtest. - -=head1 METHODS - -See L<Test::Builder::Event> which is the base class for this module. - -=head2 CONSTRUCTORS - -=over 4 - -=item $r = $class->new(...) - -Create a new instance - -=back - -=head2 ATTRIBUTES - -=over 4 - -=item $r->action - -Either 'push' or 'pop'. When a child is created a push is sent, when a child -exits a pop is sent. - -=back - -=head2 SIMPLE READ/WRITE ACCESSORS - -=over 4 - -=item $r->name - -Name of the child - -=item $r->is_subtest - -True if the child was spawned for a subtest. - -=item $r->trace - -Get the test trace info, including where to report errors. - -=item $r->pid - -PID in which the event was created. - -=item $r->depth - -Builder depth of the event (0 for normal, 1 for subtest, 2 for nested, etc). - -=item $r->in_todo - -True if the event was generated inside a todo. - -=item $r->source - -Builder that created the event, usually $0, but the name of a subtest when -inside a subtest. - -=item $r->constructed - -Package, File, and Line in which the event was built. - -=back - -=head2 INFORMATION - -=over 4 - -=item $r->to_tap - -no-op, return nothing. - -=item $r->type - -Type of event. Usually this is the lowercased name from the end of the -package. L<Test::Builder::Event::Ok> = 'ok'. - -=item $r->indent - -Returns the indentation that should be used to display the event (' ' x -depth). - -=back - -=head1 AUTHORS - -=over 4 - -=item Chad Granum E<lt>exodist@cpan.orgE<gt> - -=back - -=head1 SOURCE - -The source code repository for Test::More can be found at -F<http://github.com/Test-More/test-more/>. - -=head1 COPYRIGHT - -Copyright 2014 Chad Granum E<lt>exodist7@gmail.comE<gt>. - -This program is free software; you can redistribute it and/or -modify it under the same terms as Perl itself. - -See F<http://www.perl.com/perl/misc/Artistic.html> diff --git a/cpan/Test-Simple/lib/Test/Builder/Event/Diag.pm b/cpan/Test-Simple/lib/Test/Builder/Event/Diag.pm deleted file mode 100644 index 7c1e9b6721..0000000000 --- a/cpan/Test-Simple/lib/Test/Builder/Event/Diag.pm +++ /dev/null @@ -1,156 +0,0 @@ -package Test::Builder::Event::Diag; -use strict; -use warnings; - -use base 'Test::Builder::Event'; - -use Scalar::Util(); -use Test::Builder::Util qw/accessors try/; -use Encode(); -accessors qw/message/; - -my $NORMALIZE = try { require Unicode::Normalize; 1 }; - -sub to_tap { - my $self = shift; - - chomp(my $msg = $self->message); - - if ($self->trace && $self->trace->report) { - my $encoding = $self->trace->encoding; - if ($encoding && $encoding ne 'legacy') { - my $file = $self->trace->report->file; - my $decoded; - try { $decoded = Encode::decode($encoding, "$file", Encode::FB_CROAK) }; - if ($decoded) { - $decoded = Unicode::Normalize::NFKC($decoded) if $NORMALIZE; - $msg =~ s/$file/$decoded/g; - } - } - } - - $msg = "# $msg" unless $msg =~ m/^\n/; - $msg =~ s/\n/\n# /g; - return "$msg\n"; -} - -sub linked { - my $self = shift; - - if (@_) { - ($self->{linked}) = @_; - Scalar::Util::weaken($self->{linked}) if defined $self->{linked}; - } - - return $self->{linked}; -} - -1; - -__END__ - -=head1 NAME - -Test::Builder::Event::Diag - Diag event type - -=head1 DESCRIPTION - -The diag event type. - -=head1 METHODS - -See L<Test::Builder::Event> which is the base class for this module. - -=head2 CONSTRUCTORS - -=over 4 - -=item $r = $class->new(...) - -Create a new instance - -=back - -=head2 SIMPLE READ/WRITE ACCESSORS - -=over 4 - -=item $r->message - -The message in the note. - -=item $r->trace - -Get the test trace info, including where to report errors. - -=item $r->pid - -PID in which the event was created. - -=item $r->depth - -Builder depth of the event (0 for normal, 1 for subtest, 2 for nested, etc). - -=item $r->in_todo - -True if the event was generated inside a todo. - -=item $r->source - -Builder that created the event, usually $0, but the name of a subtest when -inside a subtest. - -=item $r->constructed - -Package, File, and Line in which the event was built. - -=item $r->linked - -If this diag is linked to a specific L<Test::Builder::Event::Ok> object, this -will be set to the object. Note this is automatically turned into a weak -reference as it is assumed that the Ok will also link to this object. This is -to avoid cycled and memory leaks. - -=back - -=head2 INFORMATION - -=over 4 - -=item $r->to_tap - -Returns the TAP string for the plan (not indented). - -=item $r->type - -Type of event. Usually this is the lowercased name from the end of the -package. L<Test::Builder::Event::Ok> = 'ok'. - -=item $r->indent - -Returns the indentation that should be used to display the event (' ' x -depth). - -=back - -=head1 AUTHORS - -=over 4 - -=item Chad Granum E<lt>exodist@cpan.orgE<gt> - -=back - -=head1 SOURCE - -The source code repository for Test::More can be found at -F<http://github.com/Test-More/test-more/>. - -=head1 COPYRIGHT - -Copyright 2014 Chad Granum E<lt>exodist7@gmail.comE<gt>. - -This program is free software; you can redistribute it and/or -modify it under the same terms as Perl itself. - -See F<http://www.perl.com/perl/misc/Artistic.html> diff --git a/cpan/Test-Simple/lib/Test/Builder/Event/Finish.pm b/cpan/Test-Simple/lib/Test/Builder/Event/Finish.pm deleted file mode 100644 index 8c02238689..0000000000 --- a/cpan/Test-Simple/lib/Test/Builder/Event/Finish.pm +++ /dev/null @@ -1,111 +0,0 @@ -package Test::Builder::Event::Finish; -use strict; -use warnings; - -use base 'Test::Builder::Event'; - -use Test::Builder::Util qw/accessors/; -accessors qw/tests_run tests_failed/; - -1; - -__END__ - -=head1 NAME - -Test::Builder::Event::Finish - The finish event type - -=head1 DESCRIPTION - -Sent after testing is finished. - -=head1 METHODS - -See L<Test::Builder::Event> which is the base class for this module. - -=head2 CONSTRUCTORS - -=over 4 - -=item $r = $class->new(...) - -Create a new instance - -=back - -=head2 SIMPLE READ/WRITE ACCESSORS - -=over 4 - -=item $r->tests_run - -How many tests were run. - -=item $r->tests_failed - -How many tests failed. - -=item $r->trace - -Get the test trace info, including where to report errors. - -=item $r->pid - -PID in which the event was created. - -=item $r->depth - -Builder depth of the event (0 for normal, 1 for subtest, 2 for nested, etc). - -=item $r->in_todo - -True if the event was generated inside a todo. - -=item $r->source - -Builder that created the event, usually $0, but the name of a subtest when -inside a subtest. - -=item $r->constructed - -Package, File, and Line in which the event was built. - -=back - -=head2 INFORMATION - -=over 4 - -=item $r->type - -Type of event. Usually this is the lowercased name from the end of the -package. L<Test::Builder::Event::Ok> = 'ok'. - -=item $r->indent - -Returns the indentation that should be used to display the event (' ' x -depth). - -=back - -=head1 AUTHORS - -=over 4 - -=item Chad Granum E<lt>exodist@cpan.orgE<gt> - -=back - -=head1 SOURCE - -The source code repository for Test::More can be found at -F<http://github.com/Test-More/test-more/>. - -=head1 COPYRIGHT - -Copyright 2014 Chad Granum E<lt>exodist7@gmail.comE<gt>. - -This program is free software; you can redistribute it and/or -modify it under the same terms as Perl itself. - -See F<http://www.perl.com/perl/misc/Artistic.html> diff --git a/cpan/Test-Simple/lib/Test/Builder/Event/Note.pm b/cpan/Test-Simple/lib/Test/Builder/Event/Note.pm deleted file mode 100644 index 3af5129868..0000000000 --- a/cpan/Test-Simple/lib/Test/Builder/Event/Note.pm +++ /dev/null @@ -1,120 +0,0 @@ -package Test::Builder::Event::Note; -use strict; -use warnings; - -use base 'Test::Builder::Event'; - -use Test::Builder::Util qw/accessors/; -accessors qw/message/; - -sub to_tap { - my $self = shift; - - chomp(my $msg = $self->message); - $msg = "# $msg" unless $msg =~ m/^\n/; - $msg =~ s/\n/\n# /g; - return "$msg\n"; -} - -1; - -__END__ - -=head1 NAME - -Test::Builder::Event::Note - Note event type - -=head1 DESCRIPTION - -Notes in tests - -=head1 METHODS - -See L<Test::Builder::Event> which is the base class for this module. - -=head2 CONSTRUCTORS - -=over 4 - -=item $r = $class->new(...) - -Create a new instance - -=back - -=head2 SIMPLE READ/WRITE ACCESSORS - -=over 4 - -=item $r->message - -The message in the note. - -=item $r->trace - -Get the test trace info, including where to report errors. - -=item $r->pid - -PID in which the event was created. - -=item $r->depth - -Builder depth of the event (0 for normal, 1 for subtest, 2 for nested, etc). - -=item $r->in_todo - -True if the event was generated inside a todo. - -=item $r->source - -Builder that created the event, usually $0, but the name of a subtest when -inside a subtest. - -=item $r->constructed - -Package, File, and Line in which the event was built. - -=back - -=head2 INFORMATION - -=over 4 - -=item $r->to_tap - -Returns the TAP string for the plan (not indented). - -=item $r->type - -Type of event. Usually this is the lowercased name from the end of the -package. L<Test::Builder::Event::Ok> = 'ok'. - -=item $r->indent - -Returns the indentation that should be used to display the event (' ' x -depth). - -=back - -=head1 AUTHORS - -=over 4 - -=item Chad Granum E<lt>exodist@cpan.orgE<gt> - -=back - -=head1 SOURCE - -The source code repository for Test::More can be found at -F<http://github.com/Test-More/test-more/>. - -=head1 COPYRIGHT - -Copyright 2014 Chad Granum E<lt>exodist7@gmail.comE<gt>. - -This program is free software; you can redistribute it and/or -modify it under the same terms as Perl itself. - -See F<http://www.perl.com/perl/misc/Artistic.html> diff --git a/cpan/Test-Simple/lib/Test/Builder/Event/Ok.pm b/cpan/Test-Simple/lib/Test/Builder/Event/Ok.pm deleted file mode 100644 index 075fc003d7..0000000000 --- a/cpan/Test-Simple/lib/Test/Builder/Event/Ok.pm +++ /dev/null @@ -1,268 +0,0 @@ -package Test::Builder::Event::Ok; -use strict; -use warnings; - -use base 'Test::Builder::Event'; - -use Carp qw/confess/; -use Scalar::Util qw/blessed reftype/; -use Test::Builder::Util qw/accessors/; - -accessors qw/bool real_bool name todo skip/; - -sub init_order { - my $self = shift; - my @attrs = @_; - - my @out; - my $diag; - for my $i (@attrs) { - if ($i eq 'diag') { - $diag++; - next; - } - - push @out => $i; - } - - push @out => 'diag' if $diag; - - return @out; -} - -sub pre_init { - my $self = shift; - my ($params) = @_; - - return if $params->{real_bool} || ($params->{skip} && $params->{todo}); - - my $msg = $params->{in_todo} ? "Failed (TODO)" : "Failed"; - my $prefix = $ENV{HARNESS_ACTIVE} ? "\n" : ""; - - my ($pkg, $file, $line) = $params->{trace}->report->call; - - if (defined $params->{name}) { - my $name = $params->{name}; - $msg = qq[$prefix $msg test '$name'\n at $file line $line.\n]; - } - else { - $msg = qq[$prefix $msg test at $file line $line.\n]; - } - - $params->{diag} ||= []; - unshift @{$params->{diag}} => $msg; -} - -sub to_tap { - my $self = shift; - my ($num) = @_; - - my $out = ""; - $out .= "not " unless $self->real_bool; - $out .= "ok"; - $out .= " $num" if defined $num; - - if (defined $self->name) { - my $name = $self->name; - $name =~ s|#|\\#|g; # # in a name can confuse Test::Harness. - $out .= " - " . $name; - } - - if (defined $self->skip && defined $self->todo) { - my $why = $self->skip; - - unless ($why eq $self->todo) { - require Data::Dumper; - confess "2 different reasons to skip/todo: " . Data::Dumper::Dumper($self); - } - - $out .= " # TODO & SKIP $why"; - } - elsif (defined $self->skip) { - $out .= " # skip"; - $out .= " " . $self->skip if length $self->skip; - } - elsif($self->in_todo) { - $out .= " # TODO " . $self->todo if $self->in_todo; - } - - $out =~ s/\n/\n# /g; - - $out .= "\n"; - - return $out; -} - -sub clear_diag { - my $self = shift; - my @out = @{delete $self->{diag} || []}; - $_->linked(undef) for @out; - return @out; -} - -sub diag { - my $self = shift; - - for my $i (@_) { - next unless $i; - my $type = reftype $i || ""; - - my $array = $type eq 'ARRAY' ? $i : [$i]; - for my $d (@$array) { - if (ref $d) { - confess "Only Diag objects can be linked to events." - unless blessed($d) && $d->isa('Test::Builder::Event::Diag'); - - confess "Diag argument '$d' is already linked to a event." - if $d->linked; - } - else { - $d = Test::Builder::Event::Diag->new( message => $d ); - } - - for (qw/trace pid depth in_todo source/) { - $d->$_($self->$_) unless $d->$_; - } - - $d->linked($self); - push @{$self->{diag}} => $d; - } - } - - return $self->{diag}; -} - -1; - -__END__ - -=head1 NAME - -Test::Builder::Event::Ok - Ok event type - -=head1 DESCRIPTION - -The ok event type. - -=head1 METHODS - -See L<Test::Builder::Event> which is the base class for this module. - -=head2 CONSTRUCTORS - -=over 4 - -=item $r = $class->new(...) - -Create a new instance - -=back - -=head2 SIMPLE READ/WRITE ACCESSORS - -=over 4 - -=item $r->bool - -True if the test passed, or if we are in a todo/skip - -=item $r->real_bool - -True if the test passed, false otherwise, even in todo. - -=item $r->name - -Name of the test. - -=item $r->todo - -Reason for todo (may be empty, even in a todo, check in_todo(). - -=item $r->skip - -Reason for skip - -=item $r->trace - -Get the test trace info, including where to report errors. - -=item $r->pid - -PID in which the event was created. - -=item $r->depth - -Builder depth of the event (0 for normal, 1 for subtest, 2 for nested, etc). - -=item $r->in_todo - -True if the event was generated inside a todo. - -=item $r->source - -Builder that created the event, usually $0, but the name of a subtest when -inside a subtest. - -=item $r->constructed - -Package, File, and Line in which the event was built. - -=item $r->diag - -Either undef, or an arrayref of L<Test::Builder::Event::Diag> objects. These -objects will be linked to this Ok event. Calling C<< $diag->linked >> on them -will return this Ok object. References here are strong references, references -to this object from the linked Diag objects are weakened to avoid cycles. - -You can push diag objects into the arrayref by using them as arguments to this -method. Objects will be validated to ensure that they are Diag objects, and not -already linked to a event. As well C<linked> will be set on them. - -=item $r->clear_diag - -Remove all linked Diag objects, also removes the link within the Diags. Returns -a list of the objects. - -=back - -=head2 INFORMATION - -=over 4 - -=item $r->to_tap - -Returns the TAP string for the plan (not indented). - -=item $r->type - -Type of event. Usually this is the lowercased name from the end of the -package. L<Test::Builder::Event::Ok> = 'ok'. - -=item $r->indent - -Returns the indentation that should be used to display the event (' ' x -depth). - -=back - -=head1 AUTHORS - -=over 4 - -=item Chad Granum E<lt>exodist@cpan.orgE<gt> - -=back - -=head1 SOURCE - -The source code repository for Test::More can be found at -F<http://github.com/Test-More/test-more/>. - -=head1 COPYRIGHT - -Copyright 2014 Chad Granum E<lt>exodist7@gmail.comE<gt>. - -This program is free software; you can redistribute it and/or -modify it under the same terms as Perl itself. - -See F<http://www.perl.com/perl/misc/Artistic.html> diff --git a/cpan/Test-Simple/lib/Test/Builder/Event/Plan.pm b/cpan/Test-Simple/lib/Test/Builder/Event/Plan.pm deleted file mode 100644 index 521aa6b2ba..0000000000 --- a/cpan/Test-Simple/lib/Test/Builder/Event/Plan.pm +++ /dev/null @@ -1,135 +0,0 @@ -package Test::Builder::Event::Plan; -use strict; -use warnings; - -use base 'Test::Builder::Event'; - -use Test::Builder::Util qw/accessors/; -accessors qw/max directive reason/; - -sub to_tap { - my $self = shift; - - my $max = $self->max; - my $directive = $self->directive; - my $reason = $self->reason; - - return if $directive && $directive eq 'NO_PLAN'; - - my $plan = "1..$max"; - $plan .= " # $directive" if defined $directive; - $plan .= " $reason" if defined $reason; - - return "$plan\n"; -} - -1; - -__END__ - -=head1 NAME - -Test::Builder::Event::Plan - The event of a plan - -=head1 DESCRIPTION - -The plan event object. - -=head1 METHODS - -See L<Test::Builder::Event> which is the base class for this module. - -=head2 CONSTRUCTORS - -=over 4 - -=item $r = $class->new(...) - -Create a new instance - -=back - -=head2 SIMPLE READ/WRITE ACCESSORS - -=over 4 - -=item $r->max - -When the plan is specified as a number of tests, this is set to that number. - -=item $r->directive - -This will be set to 'skip_all' or 'no_plan' in some cases. - -=item $r->reason - -If there is a directive, this gives details. - -=item $r->trace - -Get the test trace info, including where to report errors. - -=item $r->pid - -PID in which the event was created. - -=item $r->depth - -Builder depth of the event (0 for normal, 1 for subtest, 2 for nested, etc). - -=item $r->in_todo - -True if the event was generated inside a todo. - -=item $r->source - -Builder that created the event, usually $0, but the name of a subtest when -inside a subtest. - -=item $r->constructed - -Package, File, and Line in which the event was built. - -=back - -=head2 INFORMATION - -=over 4 - -=item $r->to_tap - -Returns the TAP string for the plan (not indented). - -=item $r->type - -Type of event. Usually this is the lowercased name from the end of the -package. L<Test::Builder::Event::Ok> = 'ok'. - -=item $r->indent - -Returns the indentation that should be used to display the event (' ' x -depth). - -=back - -=head1 AUTHORS - -=over 4 - -=item Chad Granum E<lt>exodist@cpan.orgE<gt> - -=back - -=head1 SOURCE - -The source code repository for Test::More can be found at -F<http://github.com/Test-More/test-more/>. - -=head1 COPYRIGHT - -Copyright 2014 Chad Granum E<lt>exodist7@gmail.comE<gt>. - -This program is free software; you can redistribute it and/or -modify it under the same terms as Perl itself. - -See F<http://www.perl.com/perl/misc/Artistic.html> diff --git a/cpan/Test-Simple/lib/Test/Builder/ExitMagic.pm b/cpan/Test-Simple/lib/Test/Builder/ExitMagic.pm deleted file mode 100644 index 9feb117715..0000000000 --- a/cpan/Test-Simple/lib/Test/Builder/ExitMagic.pm +++ /dev/null @@ -1,194 +0,0 @@ -package Test::Builder::ExitMagic; -use strict; -use warnings; - -use Test::Builder::Util qw/new accessors/; -require Test::Builder::Event::Finish; - -accessors qw/stream tb ended pid/; - -sub init { - my $self = shift; - $self->pid($$); -} - -sub do_magic { - my $self = shift; - - return if $self->ended; $self->ended(1); - - # Don't bother with an ending if this is a forked copy. Only the parent - # should do the ending. - return unless $self->pid == $$; - - my $stream = $self->stream || (Test::Builder::Stream->root ? Test::Builder::Stream->shared : undef); - return unless $stream; # No stream? no point! - my $tb = $self->tb; - - return if $stream->no_ending; - - my $real_exit_code = $?; - - my $plan = $stream->plan; - my $total = $stream->tests_run; - my $fails = $stream->tests_failed; - - $stream->send( - Test::Builder::Event::Finish->new( - tests_run => $total, - tests_failed => $fails, - depth => $tb->depth, - source => $tb->name, - ) - ); - - # Ran tests but never declared a plan or hit done_testing - return $self->no_plan_magic($stream, $tb, $total, $fails, $real_exit_code) - if $total && !$plan; - - # Exit if plan() was never called. This is so "require Test::Simple" - # doesn't puke. - return unless $plan; - - # Don't do an ending if we bailed out. - if( $stream->bailed_out ) { - $stream->is_passing(0); - return; - } - - # Figure out if we passed or failed and print helpful messages. - return $self->be_helpful_magic($stream, $tb, $total, $fails, $plan, $real_exit_code) - if $total && $plan; - - if ($plan->directive && $plan->directive eq 'SKIP') { - $? = 0; - return; - } - - if($real_exit_code) { - $tb->diag("Looks like your test exited with $real_exit_code before it could output anything.\n"); - $stream->is_passing(0); - $? = $real_exit_code; - return; - } - - unless ($total) { - $tb->diag("No tests run!\n"); - $tb->is_passing(0); - $? = 255; - return; - } - - $tb->is_passing(0); - $tb->_whoa( 1, "We fell off the end of _ending()" ); - - 1; -} - -sub no_plan_magic { - my $self = shift; - my ($stream, $tb, $total, $fails, $real_exit_code) = @_; - - $stream->is_passing(0); - $tb->diag("Tests were run but no plan was declared and done_testing() was not seen."); - - if($real_exit_code) { - $tb->diag("Looks like your test exited with $real_exit_code just after $total.\n"); - $? = $real_exit_code; - return; - } - - # But if the tests ran, handle exit code. - if ($total && $fails) { - my $exit_code = $fails <= 254 ? $fails : 254; - $? = $exit_code; - return; - } - - $? = 254; - return; -} - -sub be_helpful_magic { - my $self = shift; - my ($stream, $tb, $total, $fails, $plan, $real_exit_code) = @_; - - my $planned = $plan->max; - my $num_extra = $plan->directive && $plan->directive eq 'NO_PLAN' ? 0 : $total - $planned; - - if ($num_extra != 0) { - my $s = $planned == 1 ? '' : 's'; - $tb->diag("Looks like you planned $planned test$s but ran $total.\n"); - $tb->is_passing(0); - } - - if($fails) { - my $s = $fails == 1 ? '' : 's'; - my $qualifier = $num_extra == 0 ? '' : ' run'; - $tb->diag("Looks like you failed $fails test$s of ${total}${qualifier}.\n"); - $tb->is_passing(0); - } - - if($real_exit_code) { - $tb->diag("Looks like your test exited with $real_exit_code just after $total.\n"); - $tb->is_passing(0); - $? = $real_exit_code; - return; - } - - my $exit_code; - if($fails) { - $exit_code = $fails <= 254 ? $fails : 254; - } - elsif($num_extra != 0) { - $exit_code = 255; - } - else { - $exit_code = 0; - } - - $? = $exit_code; - return; -} - -1; - -__END__ - -=head1 NAME - -Test::Builder::ExitMagic - Encapsulate the magic exit logic used by -Test::Builder. - -=head1 DESCRIPTION - -It's magic! well kinda.. - -=head1 SYNOPSYS - -Don't use this yourself, let L<Test::Builder> handle it. - -=head1 AUTHORS - -=over 4 - -=item Chad Granum E<lt>exodist@cpan.orgE<gt> - -=back - -=head1 SOURCE - -The source code repository for Test::More can be found at -F<http://github.com/Test-More/test-more/>. - -=head1 COPYRIGHT - -Copyright 2014 Chad Granum E<lt>exodist7@gmail.comE<gt>. - -Most of this code was pulled out ot L<Test::Builder>, written by Schwern and -others. - -This program is free software; you can redistribute it and/or -modify it under the same terms as Perl itself. - -See F<http://www.perl.com/perl/misc/Artistic.html> diff --git a/cpan/Test-Simple/lib/Test/Builder/Fork.pm b/cpan/Test-Simple/lib/Test/Builder/Fork.pm deleted file mode 100644 index 791270a26b..0000000000 --- a/cpan/Test-Simple/lib/Test/Builder/Fork.pm +++ /dev/null @@ -1,171 +0,0 @@ -package Test::Builder::Fork; -use strict; -use warnings; - -use Carp qw/confess/; -use Scalar::Util qw/blessed/; -use File::Temp(); -use Test::Builder::Util qw/try/; - -sub tmpdir { shift->{tmpdir} } -sub pid { shift->{pid} } - -sub new { - my $class = shift; - - my $dir = File::Temp::tempdir(CLEANUP => 0) || die "Could not get a temp dir"; - - my $self = bless { tmpdir => $dir, pid => $$ }, $class; - - return $self; -} - -my $id = 1; -sub handle { - my $self = shift; - my ($item) = @_; - - return if $item && blessed($item) && $item->isa('Test::Builder::Event::Finish'); - - confess "Did not get a valid Test::Builder::Event object! ($item)" - unless $item && blessed($item) && $item->isa('Test::Builder::Event'); - - my $stream = Test::Builder::Stream->shared; - return 0 if $$ == $stream->pid; - - # First write the file, then rename it so that it is not read before it is ready. - my $name = $self->tmpdir . "/$$-" . $id++; - require Storable; - Storable::store($item, $name); - rename($name, "$name.ready") || die "Could not rename file"; - - return 1; -} - -sub cull { - my $self = shift; - my $dir = $self->tmpdir; - - opendir(my $dh, $dir) || die "could not open temp dir!"; - while(my $file = readdir($dh)) { - next if $file =~ m/^\.+$/; - next unless $file =~ m/\.ready$/; - - require Storable; - my $obj = Storable::retrieve("$dir/$file"); - die "Empty event object found" unless $obj; - - Test::Builder::Stream->shared->send($obj); - - if ($ENV{TEST_KEEP_TMP_DIR}) { - rename("$dir/$file", "$dir/$file.complete") || die "Could not rename file"; - } - else { - unlink("$dir/$file") || die "Could not unlink file: $file"; - } - } - closedir($dh); -} - -sub DESTROY { - my $self = shift; - - return unless $$ == $self->pid; - - my $dir = $self->tmpdir; - - if ($ENV{TEST_KEEP_TMP_DIR}) { - print STDERR "# Not removing temp dir: $dir\n"; - return; - } - - opendir(my $dh, $dir) || die "Could not open temp dir!"; - while(my $file = readdir($dh)) { - next if $file =~ m/^\.+$/; - die "Unculled event! You ran tests in a child process, but never pulled them in!\n" - if $file !~ m/\.complete$/; - unlink("$dir/$file") || die "Could not unlink file: $file"; - } - closedir($dh); - rmdir($dir); -} - -1; - -__END__ - -=head1 NAME - -Test::Builder::Fork - Fork support for Test::Builder - -=head1 DESCRIPTION - -This module is used by L<Test::Builder::Stream> to support forking. - -=head1 SYNOPSYS - - use Test::Builder::Fork; - - my $f = Test::Builder::Fork; - - if ($pid = fork) { - waitpid($pid, 0); - $f->cull; - } - else { - $f->handle(Test::Builder::Event::Ok->new(bool => 1); - } - - ... - -=head1 METHODS - -=over 4 - -=item $f = $class->new - -Create a new instance - -=item $f->pid - -Original PID in which the fork object was created. - -=item $f->tmpdir - -Temp dir used to share events between procs - -=item $f->handle($event) - -Send a event object to the parent - -=item $f->cull - -Retrieve event objects and send them to the stream - -=back - -=head1 SEE ALSO - -L<Child> - Makes forking easier. - -=head1 AUTHORS - -=over 4 - -=item Chad Granum E<lt>exodist@cpan.orgE<gt> - -=back - -=head1 SOURCE - -The source code repository for Test::More can be found at -F<http://github.com/Test-More/test-more/>. - -=head1 COPYRIGHT - -Copyright 2014 Chad Granum E<lt>exodist7@gmail.comE<gt>. - -This program is free software; you can redistribute it and/or -modify it under the same terms as Perl itself. - -See F<http://www.perl.com/perl/misc/Artistic.html> diff --git a/cpan/Test-Simple/lib/Test/Builder/Formatter.pm b/cpan/Test-Simple/lib/Test/Builder/Formatter.pm deleted file mode 100644 index 98465a4beb..0000000000 --- a/cpan/Test-Simple/lib/Test/Builder/Formatter.pm +++ /dev/null @@ -1,180 +0,0 @@ -package Test::Builder::Formatter; -use strict; -use warnings; - -use Carp qw/confess/; -use Scalar::Util qw/blessed/; - -use Test::Builder::Util qw/new package_sub/; - -sub handle { - my $self = shift; - my ($item) = @_; - - confess "Handler did not get a valid Test::Builder::Event object! ($item)" - unless $item && blessed($item) && $item->isa('Test::Builder::Event'); - - my $method = $item->type; - - # Not all formatters will handle all types. - return 0 unless $self->can($method); - - $self->$method($item); - - return 1; -} - -sub to_handler { - my $self = shift; - return sub { $self->handle(@_) }; -} - -sub listen { - my $class = shift; - my %params = @_; - my $caller = caller; - - my $tb = $params{tb}; - $tb ||= package_sub($caller, 'TB_INSTANCE') ? $caller->TB_INSTANCE : undef; - - my $stream = delete $params{stream} || ($tb ? $tb->stream : undef) || Test::Builder::Stream->shared; - - my $id = delete $params{id}; - ($id) = ($class =~ m/^.*::([^:]+)$/g) unless $id; - - return $stream->listen($id => $class->new(%params)); -} - -1; - -__END__ - -=head1 NAME - -Test::Builder::Formatter - Base class for formatters - -=head1 DESCRIPTION - -Events go to L<Test::Builder::Stream> which then forwards them on to one or -more formatters. This module is a base class for formatters. You do not NEED to -use this module to write a formatter, but it can help. - -=head1 TEST COMPONENT MAP - - [Test Script] > [Test Tool] > [Test::Builder] > [Test::Bulder::Stream] > [Event Formatter] - ^ - You are here - -A test script uses a test tool such as L<Test::More>, which uses Test::Builder -to produce events. The events are sent to L<Test::Builder::Stream> which then -forwards them on to one or more formatters. The default formatter is -L<Test::Builder::Fromatter::TAP> which produces TAP output. - -=head1 SYNOPSYS - - package My::Formatter; - use base 'Test::Builder::Formatter'; - - sub ok { - my $self = shift; - my ($event) = @_; - - ... - } - - ... - - 1; - -=head2 TO USE IT - - use Test::More; - use My::Formatter; - - # Creates a new instance of your listener. Any params you pass in will be - # passed into the constructor. Exceptions: 'id', 'stream' and 'tb' which - # are used directly by 'listen' if present. - my $unlisten = My::Formatter->listen(...); - - # To stop listening: - $unlisten->(); - -=head1 METHODS - -=head2 PROVIDED - -=over 4 - -=item $L = $class->new(%params) - -Create a new instance. Arguments must be key => value pairs where the key is a -method name on the object. - -=item $unlisten = $class->listen(%params) - -=item $unlisten = $class->listen(id => 'foo', %params) - -=item $unlisten = $class->listen(stream => $STREAM, %params) - -=item $unlisten = $class->listen(tb => $BUILDER, %params) - -Construct an instance using %params, and add it as a listener on the stream. -'id', 'stream', and 'tb' are special arguments that can be used to specify the -id of the listener, the stream to which the instance will listen, or the -L<Test::Builder> instance from which to find the stream. - -=item $L->handle($event) - -Forward the event on to the correct method. - -=item $subref = $L->to_handler() - -Returns an anonymous sub that accepts events as arguments and passes them into -handle() on this instance. - -=back - -=head2 FOR YOU TO WRITE - -=over 4 - -=item $self->ok($event) - -=item $self->note($event) - -=item $self->diag($event) - -=item $self->plan($event) - -=item $self->finish($event) - -=item $self->bail($event) - -=item $self->child($event) - -Any events given to the handle() method will be passed into the associated -sub. If the sub is not defined then events of that type will be ignored. - -=back - -=head1 AUTHORS - -=over 4 - -=item Chad Granum E<lt>exodist@cpan.orgE<gt> - -=back - -=head1 SOURCE - -The source code repository for Test::More can be found at -F<http://github.com/Test-More/test-more/>. - -=head1 COPYRIGHT - -Copyright 2014 Chad Granum E<lt>exodist7@gmail.comE<gt>. - -This program is free software; you can redistribute it and/or -modify it under the same terms as Perl itself. - -See F<http://www.perl.com/perl/misc/Artistic.html> diff --git a/cpan/Test-Simple/lib/Test/Builder/Formatter/LegacyResults.pm b/cpan/Test-Simple/lib/Test/Builder/Formatter/LegacyResults.pm deleted file mode 100644 index dee2512f33..0000000000 --- a/cpan/Test-Simple/lib/Test/Builder/Formatter/LegacyResults.pm +++ /dev/null @@ -1,166 +0,0 @@ -package Test::Builder::Formatter::LegacyResults; -use strict; -use warnings; - -use base 'Test::Builder::Formatter'; - -use Test::Builder::Threads; - -sub init { - my $self = shift; - $self->reset; -} - -sub reset { - my $self = shift; - - $self->{Test_Results} = &share( [] ); - $self->{Curr_Test} = 0; - - &share(\$self->{Curr_Test}); - - return; -} - -sub summary { - my($self) = shift; - return map { $_->{'ok'} } @{ $self->{Test_Results} }; -} - -sub details { - my $self = shift; - return @{ $self->{Test_Results} }; -} - -sub current_test { - my ($self, $num) = @_; - - lock( $self->{Curr_Test} ); - if( defined $num ) { - my $delta = $num - $self->{Curr_Test}; - $self->{Curr_Test} = $num; - - # If the test counter is being pushed forward fill in the details. - my $test_results = $self->{Test_Results}; - if( $num > @$test_results ) { - my $start = @$test_results ? @$test_results : 0; - for( $start .. $num - 1 ) { - $test_results->[$_] = &share( - { - 'ok' => 1, - actual_ok => undef, - reason => 'incrementing test number', - type => 'unknown', - name => undef - } - ); - } - } - # If backward, wipe history. Its their funeral. - elsif( $num < @$test_results ) { - $#{$test_results} = $num - 1; - } - } - return $self->{Curr_Test}; -} - -sub sanity_check { - my $self = shift; - my ($tb) = @_; - - $tb->_whoa( $self->{Curr_Test} < 0, 'Says here you ran a negative number of tests!' ); - - $tb->_whoa( - $self->{Curr_Test} != @{ $self->{Test_Results} }, - 'Somehow you got a different number of results than tests ran!' - ); - - return; -} - -sub ok { - my $self = shift; - my ($item) = @_; - - my $result = &share( {} ); - - lock $self->{Curr_Test}; - $self->{Curr_Test}++; - - $result->{ok} = $item->bool; - $result->{actual_ok} = $item->real_bool; - - my $name = $item->name; - if(defined $name) { - $name =~ s|#|\\#|g; # # in a name can confuse Test::Harness. - $result->{name} = $name; - } - else { - $result->{name} = ''; - } - - if($item->skip && ($item->in_todo || $item->todo)) { - $result->{type} = 'todo_skip', - $result->{reason} = $item->skip || $item->todo; - } - elsif($item->in_todo || $item->todo) { - $result->{reason} = $item->todo; - $result->{type} = 'todo'; - } - elsif($item->skip) { - $result->{reason} = $item->skip; - $result->{type} = 'skip'; - } - else { - $result->{reason} = ''; - $result->{type} = ''; - } - - $self->{Test_Results}[ $self->{Curr_Test} - 1 ] = $result; -} - -1; - -__END__ - -=head1 NAME - -Test::Builder::Formatter::LegacyResults - Encapsulate some legacy stuff. - -=head1 DESCRIPTION - -Older versions kept track of test results using an array of hashes. This is now -deprecated, but needs to still work for legacy code. - -=head1 TEST COMPONENT MAP - - [Test Script] > [Test Tool] > [Test::Builder] > [Test::Bulder::Stream] > [Event Formatter] - ^ - You are here - -A test script uses a test tool such as L<Test::More>, which uses Test::Builder -to produce results. The results are sent to L<Test::Builder::Stream> which then -forwards them on to one or more formatters. The default formatter is -L<Test::Builder::Fromatter::TAP> which produces TAP output. - -=head1 AUTHORS - -=over 4 - -=item Chad Granum E<lt>exodist@cpan.orgE<gt> - -=back - -=head1 SOURCE - -The source code repository for Test::More can be found at -F<http://github.com/Test-More/test-more/>. - -=head1 COPYRIGHT - -Copyright 2014 Chad Granum E<lt>exodist7@gmail.comE<gt>. - -This program is free software; you can redistribute it and/or -modify it under the same terms as Perl itself. - -See F<http://www.perl.com/perl/misc/Artistic.html> diff --git a/cpan/Test-Simple/lib/Test/Builder/Formatter/TAP.pm b/cpan/Test-Simple/lib/Test/Builder/Formatter/TAP.pm deleted file mode 100644 index 1293bdaf2d..0000000000 --- a/cpan/Test-Simple/lib/Test/Builder/Formatter/TAP.pm +++ /dev/null @@ -1,447 +0,0 @@ -package Test::Builder::Formatter::TAP; -use strict; -use warnings; - -use Test::Builder::Threads; -use Test::Builder::Util qw/accessors try protect new accessor/; -use Carp qw/croak confess/; - -use base 'Test::Builder::Formatter'; - -accessors qw/No_Header No_Diag Depth Use_Numbers _the_plan/; - -accessor io_sets => sub { {} }; - -use constant OUT => 0; -use constant FAIL => 1; -use constant TODO => 2; - -####################### -# {{{ INITIALIZATION -####################### - -sub init { - my $self = shift; - - $self->no_header(0); - $self->use_numbers(1); - - $self->{number} = 0; - - $self->{lock} = 1; - share($self->{lock}); - - $self->init_legacy; - - return $self; -} - -####################### -# }}} INITIALIZATION -####################### - -####################### -# {{{ EVENT METHODS -####################### - -for my $handler (qw/bail nest/) { - my $sub = sub { - my $self = shift; - my ($item) = @_; - $self->_print_to_fh($self->event_handle($item, OUT), $item->indent || "", $item->to_tap); - }; - no strict 'refs'; - *$handler = $sub; -} - -sub child { - my $self = shift; - my ($item) = @_; - - return unless $item->action eq 'push' && $item->is_subtest; - - my $name = $item->name; - $self->_print_to_fh($self->event_handle($item, OUT), $item->indent || "", "# Subtest: $name\n"); -} - -sub finish { - my $self = shift; - my ($item) = @_; - - return if $self->no_header; - return unless $item->tests_run; - - my $plan = $self->_the_plan; - return unless $plan; - - if ($plan) { - return unless $plan->directive; - return unless $plan->directive eq 'NO_PLAN'; - } - - my $total = $item->tests_run; - $self->_print_to_fh($self->event_handle($item, OUT), $item->indent || '', "1..$total\n"); -} - -sub plan { - my $self = shift; - my ($item) = @_; - - $self->_the_plan($item); - - return if $self->no_header; - - return if $item->directive && $item->directive eq 'NO_PLAN'; - - my $out = $item->to_tap; - return unless $out; - - my $handle = $self->event_handle($item, OUT); - $self->_print_to_fh($handle, $item->indent || "", $out); -} - -sub ok { - my $self = shift; - my ($item) = @_; - - $self->atomic_event(sub { - my $num = $self->use_numbers ? ++($self->{number}) : undef; - $self->_print_to_fh($self->event_handle($item, OUT), $item->indent || "", $item->to_tap($num)); - }); -} - -sub diag { - my $self = shift; - my ($item) = @_; - - return if $self->no_diag; - - # Prevent printing headers when compiling (i.e. -c) - return if $^C; - - my $want_handle = $item->in_todo ? TODO : FAIL; - my $handle = $self->event_handle($item, $want_handle); - - $self->_print_to_fh( $handle, $item->indent || "", $item->to_tap ); -} - -sub note { - my $self = shift; - my ($item) = @_; - - return if $self->no_diag; - - # Prevent printing headers when compiling (i.e. -c) - return if $^C; - - $self->_print_to_fh( $self->event_handle($item, OUT), $item->indent || "", $item->to_tap ); -} - -####################### -# }}} EVENT METHODS -####################### - -############################## -# {{{ IO accessors -############################## - -sub io_set { - my $self = shift; - my ($name, @handles) = @_; - - if (@handles) { - my ($out, $fail, $todo) = @handles; - $out = $self->_new_fh($out); - - $fail = $fail ? $self->_new_fh($fail) : $out; - $todo = $todo ? $self->_new_fh($todo) : $out; - - $self->io_sets->{$name} = [$out, $fail, $todo]; - } - - return $self->io_sets->{$name}; -} - -sub encoding_set { - my $self = shift; - my ($encoding) = @_; - - $self->io_sets->{$encoding} ||= do { - my ($out, $fail) = $self->open_handles(); - my $todo = $out; - - binmode($out, ":encoding($encoding)"); - binmode($fail, ":encoding($encoding)"); - - [$out, $fail, $todo]; - }; - - return $self->io_sets->{$encoding}; -} - -sub event_handle { - my $self = shift; - my ($event, $index) = @_; - - my $rencoding = $event ? $event->encoding : undef; - - # Open handles in the encoding if one is set. - $self->encoding_set($rencoding) if $rencoding && $rencoding ne 'legacy'; - - for my $name ($rencoding, qw/utf8 legacy/) { - next unless $name; - my $handles = $self->io_set($name); - return $handles->[$index] if $handles; - } - - confess "This should not happen"; -} - -############################## -# }}} IO accessors -############################## - -######################## -# {{{ Legacy Support -######################## - -my $LEGACY; - -sub full_reset { $LEGACY = undef } - -sub init_legacy { - my $self = shift; - - unless ($LEGACY) { - my ($out, $err) = $self->open_handles(); - - _copy_io_layers(\*STDOUT, $out); - _copy_io_layers(\*STDERR, $err); - - _autoflush($out); - _autoflush($err); - - # LEGACY, BAH! - _autoflush(\*STDOUT); - _autoflush(\*STDERR); - - $LEGACY = [$out, $err, $out]; - } - - $self->reset_outputs; -} - -sub reset_outputs { - my $self = shift; - my ($out, $fail, $todo) = @$LEGACY; - $self->io_sets->{legacy} = [$out, $fail, $todo]; -} - -sub reset { - my $self = shift; - $self->reset_outputs; - $self->no_header(0); - $self->use_numbers(1); - lock $self->{lock}; - $self->{number} = 0; - share( $self->{number} ); - - 1; -} - -sub output { - my $self = shift; - my $handles = $self->io_set('legacy'); - ($handles->[OUT]) = $self->_new_fh($_[0]) if @_; - return $handles->[OUT]; -} - -sub failure_output { - my $self = shift; - my $handles = $self->io_set('legacy'); - ($handles->[FAIL]) = $self->_new_fh($_[0]) if @_; - return $handles->[FAIL]; -} - -sub todo_output { - my $self = shift; - my $handles = $self->io_set('legacy'); - ($handles->[TODO]) = $self->_new_fh($_[0]) if @_; - return $handles->[TODO]; -} - -sub _diag_fh { - my $self = shift; - my ($in_todo) = @_; - - return $in_todo ? $self->todo_output : $self->failure_output; -} - -sub _print { - my $self = shift; - my ($indent, @msgs) = @_; - return $self->_print_to_fh( $self->output, $indent, @msgs ); -} - -sub current_test { - my $self = shift; - - if (@_) { - my ($new) = @_; - $self->atomic_event(sub { $self->{number} = $new }); - } - - return $self->{number}; -} - -######################## -# }}} Legacy Support -######################## - -############### -# {{{ UTILS -############### - -sub _print_to_fh { - my( $self, $fh, $indent, @msgs ) = @_; - - # Prevent printing headers when only compiling. Mostly for when - # tests are deparsed with B::Deparse - return if $^C; - - my $msg = join '', @msgs; - - local( $\, $", $, ) = ( undef, ' ', '' ); - - $msg =~ s/^/$indent/mg; - - return print $fh $msg; -} - -sub open_handles { - my $self = shift; - - open( my $out, ">&STDOUT" ) or die "Can't dup STDOUT: $!"; - open( my $err, ">&STDERR" ) or die "Can't dup STDERR: $!"; - - _autoflush($out); - _autoflush($err); - - return ($out, $err); -} - -sub atomic_event { - my $self = shift; - my ($code) = @_; - lock $self->{lock}; - $code->(); -} - -sub _autoflush { - my($fh) = shift; - my $old_fh = select $fh; - $| = 1; - select $old_fh; - - return; -} - -sub _copy_io_layers { - my($src, $dst) = @_; - - try { - require PerlIO; - my @src_layers = PerlIO::get_layers($src); - _apply_layers($dst, @src_layers) if @src_layers; - }; - - return; -} - -sub _new_fh { - my $self = shift; - my($file_or_fh) = shift; - - return $file_or_fh if $self->is_fh($file_or_fh); - - my $fh; - if( ref $file_or_fh eq 'SCALAR' ) { - open $fh, ">>", $file_or_fh - or croak("Can't open scalar ref $file_or_fh: $!"); - } - else { - open $fh, ">", $file_or_fh - or croak("Can't open test output log $file_or_fh: $!"); - _autoflush($fh); - } - - return $fh; -} - -sub is_fh { - my $self = shift; - my $maybe_fh = shift; - return 0 unless defined $maybe_fh; - - return 1 if ref $maybe_fh eq 'GLOB'; # its a glob ref - return 1 if ref \$maybe_fh eq 'GLOB'; # its a glob - - my $out; - protect { - $out = eval { $maybe_fh->isa("IO::Handle") } - || eval { tied($maybe_fh)->can('TIEHANDLE') }; - }; - - return $out; -} - - -############### -# }}} UTILS -############### - -1; - -__END__ - -=head1 NAME - -Test::Builder::Formatter::TAP - TAP formatter. - -=head1 TEST COMPONENT MAP - - [Test Script] > [Test Tool] > [Test::Builder] > [Test::Bulder::Stream] > [Event Formatter] - ^ - You are here - -A test script uses a test tool such as L<Test::More>, which uses Test::Builder -to produce events. The events are sent to L<Test::Builder::Stream> which then -forwards them on to one or more formatters. The default formatter is -L<Test::Builder::Fromatter::TAP> which produces TAP output. - -=head1 DESCRIPTION - -This module is responsible for taking events from the stream and outputting -TAP. You probably should not directly interact with this. - -=head1 AUTHORS - -=over 4 - -=item Chad Granum E<lt>exodist@cpan.orgE<gt> - -=back - -=head1 SOURCE - -The source code repository for Test::More can be found at -F<http://github.com/Test-More/test-more/>. - -=head1 COPYRIGHT - -Copyright 2014 Chad Granum E<lt>exodist7@gmail.comE<gt>. - -This program is free software; you can redistribute it and/or -modify it under the same terms as Perl itself. - -See F<http://www.perl.com/perl/misc/Artistic.html> diff --git a/cpan/Test-Simple/lib/Test/Builder/Module.pm b/cpan/Test-Simple/lib/Test/Builder/Module.pm index 47173ff68e..a11033eaba 100644 --- a/cpan/Test-Simple/lib/Test/Builder/Module.pm +++ b/cpan/Test-Simple/lib/Test/Builder/Module.pm @@ -7,18 +7,13 @@ use Test::Builder 0.99; require Exporter; our @ISA = qw(Exporter); -our $VERSION = '1.301001_040'; +our $VERSION = '1.001003'; $VERSION = eval $VERSION; ## no critic (BuiltinFunctions::ProhibitStringyEval) =head1 NAME -Test::Builder::Module - *DEPRECATED* Base class for test modules - -=head1 DEPRECATED - -B<This module is deprecated> See L<Test::Builder::Provider> for what you should -use instead. +Test::Builder::Module - Base class for test modules =head1 SYNOPSIS @@ -34,61 +29,59 @@ use instead. my $tb = $CLASS->builder; return $tb->ok(@_); } - + 1; =head1 DESCRIPTION -This is a superclass for L<Test::Builder>-based modules. It provides a +This is a superclass for Test::Builder-based modules. It provides a handful of common functionality and a method of getting at the underlying -L<Test::Builder> object. +Test::Builder object. =head2 Importing -Test::Builder::Module is a subclass of L<Exporter> which means your +Test::Builder::Module is a subclass of Exporter which means your module is also a subclass of Exporter. @EXPORT, @EXPORT_OK, etc... all act normally. -A few methods are provided to do the C<< use Your::Module tests => 23 >> part +A few methods are provided to do the C<use Your::Module tests => 23> part for you. =head3 import -Test::Builder::Module provides an C<import()> method which acts in the -same basic way as L<Test::More>'s, setting the plan and controlling +Test::Builder::Module provides an import() method which acts in the +same basic way as Test::More's, setting the plan and controlling exporting of functions and variables. This allows your module to set -the plan independent of L<Test::More>. +the plan independent of Test::More. -All arguments passed to C<import()> are passed onto -C<< Your::Module->builder->plan() >> with the exception of +All arguments passed to import() are passed onto +C<< Your::Module->builder->plan() >> with the exception of C<< import =>[qw(things to import)] >>. use Your::Module import => [qw(this that)], tests => 23; -says to import the functions C<this()> and C<that()> as well as set the plan +says to import the functions this() and that() as well as set the plan to be 23 tests. -C<import()> also sets the C<exported_to()> attribute of your builder to be -the caller of the C<import()> function. +import() also sets the exported_to() attribute of your builder to be +the caller of the import() function. -Additional behaviors can be added to your C<import()> method by overriding -C<import_extra()>. +Additional behaviors can be added to your import() method by overriding +import_extra(). =cut sub import { my($class) = shift; - my $test = $class->builder; - my $caller = caller; - - warn __PACKAGE__ . " is deprecated!\n" if $caller->can('TB_INSTANCE') && $caller->TB_INSTANCE->modern; - # Don't run all this when loading ourself. return 1 if $class eq 'Test::Builder::Module'; + my $test = $class->builder; + + my $caller = caller; $test->exported_to($caller); @@ -130,13 +123,13 @@ sub _strip_imports { Your::Module->import_extra(\@import_args); -C<import_extra()> is called by C<import()>. It provides an opportunity for you +import_extra() is called by import(). It provides an opportunity for you to add behaviors to your module based on its import list. -Any extra arguments which shouldn't be passed on to C<plan()> should be +Any extra arguments which shouldn't be passed on to plan() should be stripped off by this method. -See L<Test::More> for an example of its use. +See Test::More for an example of its use. B<NOTE> This mechanism is I<VERY ALPHA AND LIKELY TO CHANGE> as it feels like a bit of an ugly hack in its current form. @@ -154,15 +147,15 @@ Test::Builder object. my $builder = Your::Class->builder; -This method returns the L<Test::Builder> object associated with Your::Class. +This method returns the Test::Builder object associated with Your::Class. It is not a constructor so you can call it as often as you like. -This is the preferred way to get the L<Test::Builder> object. You should +This is the preferred way to get the Test::Builder object. You should I<not> get it via C<< Test::Builder->new >> as was previously recommended. -The object returned by C<builder()> may change at runtime so you should -call C<builder()> inside each function rather than store it in a global. +The object returned by builder() may change at runtime so you should +call builder() inside each function rather than store it in a global. sub ok { my $builder = Your::Class->builder; diff --git a/cpan/Test-Simple/lib/Test/Builder/Provider.pm b/cpan/Test-Simple/lib/Test/Builder/Provider.pm deleted file mode 100644 index 01d942e6a8..0000000000 --- a/cpan/Test-Simple/lib/Test/Builder/Provider.pm +++ /dev/null @@ -1,463 +0,0 @@ -package Test::Builder::Provider; -use strict; -use warnings; - -use Test::Builder 1.301001; -use Test::Builder::Util qw/package_sub is_tester is_provider find_builder/; -use Test::Builder::Trace; -use Carp qw/croak/; -use Scalar::Util qw/reftype set_prototype/; -use B(); - -my %SIG_MAP = ( - '$' => 'SCALAR', - '@' => 'ARRAY', - '%' => 'HASH', - '&' => 'CODE', -); - -my $ID = 1; - -sub import { - my $class = shift; - my $caller = caller; - - $class->export_into($caller, @_); -} - -sub export_into { - my $class = shift; - my ($dest, @sym_list) = @_; - - my %subs; - - my $meta = $class->make_provider($dest); - - $subs{TB} = \&find_builder; - $subs{builder} = \&find_builder; - $subs{anoint} = \&anoint; - $subs{import} = \&provider_import; - $subs{nest} = \&nest; - $subs{provide} = $class->_build_provide($dest, $meta); - $subs{export} = $class->_build_export($dest, $meta); - $subs{modernize} = \&modernize; - - $subs{gives} = sub { $subs{provide}->($_, undef, give => 1) for @_ }; - $subs{give} = sub { $subs{provide}->($_[0], $_[1], give => 1) }; - $subs{provides} = sub { $subs{provide}->($_) for @_ }; - - @sym_list = keys %subs unless @sym_list; - - my %seen; - for my $name (grep { !$seen{$_}++ } @sym_list) { - no strict 'refs'; - my $ref = $subs{$name} || package_sub($class, $name); - croak "$class does not export '$name'" unless $ref; - *{"$dest\::$name"} = $ref ; - } - - 1; -} - -sub nest(&) { - return Test::Builder::Trace->nest(@_); -} - -sub make_provider { - my $class = shift; - my ($dest) = @_; - - my $meta = is_provider($dest); - - unless ($meta) { - $meta = {refs => {}, attrs => {}, export => []}; - no strict 'refs'; - *{"$dest\::TB_PROVIDER_META"} = sub { $meta }; - } - - return $meta; -} - -sub _build_provide { - my $class = shift; - my ($dest, $meta) = @_; - - $meta->{provide} ||= sub { - my ($name, $ref, %params) = @_; - - croak "$dest already provides or gives '$name'" - if $meta->{attrs}->{$name}; - - croak "The second argument to provide() must be a ref, got: $ref" - if $ref && !ref $ref; - - $ref ||= package_sub($dest, $name); - croak "$dest has no sub named '$name', and no ref was given" - unless $ref; - - my $attrs = {%params, package => $dest, name => $name}; - $meta->{attrs}->{$name} = $attrs; - - push @{$meta->{export}} => $name; - - # If this is just giving, or not a coderef - return $meta->{refs}->{$name} = $ref if $params{give} || reftype $ref ne 'CODE'; - - my $o_name = B::svref_2object($ref)->GV->NAME; - if ($o_name && $o_name ne '__ANON__') { #sub has a name - $meta->{refs}->{$name} = $ref; - $attrs->{named} = 1; - } - else { - $attrs->{named} = 0; - # Voodoo.... - # Insert an anonymous sub, and use a trick to make caller() think its - # name is this string, which tells us how to find the thing that was - # actually called. - my $globname = __PACKAGE__ . '::__ANON' . ($ID++) . '__'; - - my $code = sub { - no warnings 'once'; - local *__ANON__ = $globname; # Name the sub so we can find it for real. - $ref->(@_); - }; - - # The prototype on set_prototype blocks this usage, even though it - # is valid. This is why we use the old-school &func() call. - # Oh the irony. - my $proto = prototype($ref); - &set_prototype($code, $proto) if $proto; - - $meta->{refs}->{$name} = $code; - - no strict 'refs'; - *$globname = $code; - *$globname = $attrs; - } - }; - - return $meta->{provide}; -} - -sub _build_export { - my $class = shift; - my ($dest, $meta) = @_; - - return sub { - my $class = shift; - my ($caller, @args) = @_; - - my (%no, @list); - for my $thing (@args) { - if ($thing =~ m/^!(.*)$/) { - $no{$1}++; - } - else { - push @list => $thing; - } - } - - unless(@list) { - my %seen; - @list = grep { !($no{$_} || $seen{$_}++) } @{$meta->{export}}; - } - - for my $name (@list) { - if ($name =~ m/^(\$|\@|\%)(.*)$/) { - my ($sig, $sym) = ($1, $2); - - croak "$class does not export '$name'" - unless ($meta->{refs}->{$sym} && reftype $meta->{refs}->{$sym} eq $SIG_MAP{$sig}); - - no strict 'refs'; - *{"$caller\::$sym"} = $meta->{refs}->{$name} || *{"$class\::$sym"}{$SIG_MAP{$sig}} - || croak "'$class' has no symbol named '$name'"; - } - else { - croak "$class does not export '$name'" - unless $meta->{refs}->{$name}; - - no strict 'refs'; - *{"$caller\::$name"} = $meta->{refs}->{$name} || package_sub($class, $name) - || croak "'$class' has no sub named '$name'"; - } - } - }; -} - -sub provider_import { - my $class = shift; - my $caller = caller; - - $class->anoint($caller); - $class->before_import(\@_, $caller) if $class->can('before_import'); - $class->export($caller, @_); - $class->after_import(@_) if $class->can('after_import'); - - 1; -} - -sub anoint { Test::Builder::Trace->anoint($_[1], $_[0]) }; - -sub modernize { - my $target = shift; - - if (package_sub($target, 'TB_INSTANCE')) { - my $tb = $target->TB_INSTANCE; - $tb->stream->use_fork; - $tb->modern(1); - } - else { - my $tb = Test::Builder->create( - modern => 1, - shared_stream => 1, - no_reset_plan => 1, - ); - $tb->stream->use_fork; - no strict 'refs'; - *{"$target\::TB_INSTANCE"} = sub {$tb}; - } -} - -1; - -=head1 NAME - -Test::Builder::Provider - Helper for writing testing tools - -=head1 TEST COMPONENT MAP - - [Test Script] > [Test Tool] > [Test::Builder] > [Test::Bulder::Stream] > [Event Formatter] - ^ - You are here - -A test script uses a test tool such as L<Test::More>, which uses Test::Builder -to produce events. The events are sent to L<Test::Builder::Stream> which then -forwards them on to one or more formatters. The default formatter is -L<Test::Builder::Fromatter::TAP> which produces TAP output. - -=head1 DESCRIPTION - -This package provides you with tools to write testing tools. It makes your job -of integrating with L<Test::Builder> and other testing tools much easier. - -=head1 SYNOPSYS - -Instead of use L<Exporter> or other exporters, you can use convenience -functions to define exports on the fly. - - package My::Tester - use strict; - use warnings; - - use Test::Builder::Provider; - - sub before_import { - my $class = shift; - my ($import_args_ref) = @_; - - ... Modify $import_args_ref ... - # $import_args_ref should contain only what you want to pass as - # arguments into export(). - } - - sub after_import { - my $class = shift; - my @args = @_; - - ... - } - - # Provide (export) an 'ok' function (the anonymous function is the export) - provide ok => sub { builder()->ok(@_) }; - - # Provide some of our package functions as test functions. - provides qw/is is_deeply/; - sub is { ... } - sub is_deeply { ... }; - - # Provide a 'subtests' function. Functions that accept a block like this - # that may run other tests should be use nest() to run the codeblocks they - # recieve to mark them as nested providers. - provide subtests => sub(&) { - my $code = shift; - nest { $code->() }; # OR: nest(\&$code) OR: &nest($code); - }; - - # Provide a couple nested functions defined in our package - provide qw/subtests_alt subtests_xxx/; - sub subtests_alt(&) { ... } - sub subtests_xxx(&) { ... } - - # Export a helper function that does not produce any events (regular - # export). - give echo => sub { print @_ }; - - # Same for multiple functions in our package: - gives qw/echo_stdout echo_stderr/; - sub echo_stdout { ... } - sub echo_stderr { ... } - -=head2 IN A TEST FILE - - use Test::More; - use My::Tester; - - ok(1, "blah"); - - is(1, 1, "got 1"); - - subtests { - ok(1, "a subtest"); - ok(1, "another"); - }; - -=head2 USING EXTERNAL EXPORT LIBRARIES - -Maybe you like L<Exporter> or another export tool. In that case you still need -the 'provides' and 'nest' functions from here to mark testing tools as such. - -This is also a quick way to update an old library, but you also need to remove -any references to C<$Test::Builder::Level> which is now deprecated. - - package My::Tester - use strict; - use warnings; - - use base 'Exporter'; - use Test::Builder::Provider qw/provides nest/; - - our @EXPORT = qw{ - ok is is_deeply - subtests subtests_alt subtests_xxx - echo echo_stderr echo stdout - }; - - # *mark* the testing tools - provides qw/ok is is_deeply/; - sub ok { builder()->ok(@_) } - sub is { ... } - sub is_deeply { ... }; - - # Remember to use nest() - provide qw/subtests subtests_alt subtests_xxx/; - sub subtests(&) { ... } - sub subtests_alt(&) { ... } - sub subtests_xxx(&) { ... } - - # No special marking needed for these as they do not produce events. - sub echo { print @_ } - sub echo_stdout { ... } - sub echo_stderr { ... } - -=head2 SUPPORTING OLD VERSIONS - -See L<Test::Builder::Compat> which is a seperate dist that has no dependancies. -You can use it to write providers that make use of the new Test::Builder, while -also working fine on older versions of Test::Builder. - -=head1 META-DATA - -Importing this module will always mark your package as a test provider. It does -this by injecting a method into your package called 'TB_PROVIDER_META'. This -method simply returns the meta-data hash for your package. - -To avoid this you can use 'require' instead of 'use', or you can use () in your import: - - # Load the module, but do not make this package a provider. - require Test::Builder::Provider; - use Test::Builder::Provider(); - -=head1 EXPORTS - -All of these subs are injected into your package (unless you request a subset). - -=over 4 - -=item my $tb = TB() - -=item my $tb = builder() - -Get the correct instance of L<Test::Builder>. Usually this is the instance used -in the test file calling a tool in your package. If no such instance can be -found the default Test::Builder instance will be used. - -=item $class->anoint($target) - -Used to mark the $target package as a test package that consumes your test -package for tools. This is done automatically for you if you use the default -'import' sub below. - -=item $class->import() - -=item $class->import(@list) - -An import() function that exports your tools to any consumers of your class. - -=item $class->export($dest) - -=item $class->export($dest, @list) - -Export the packages tools into the $dest package. @list me be specified to -restrict what is exported. Prefix any item in the list with '!' to prevent -exporting it. - -=item provide $name - -=item provide $name => sub { ... } - -Provide a testing tool that will produce events. If no coderef is given it -will look for a coderef with $name in your package. - -You may also use this to export refs of any type. - -=item provides qw/sub1 sub2 .../ - -Like provide except you can specify multiple subs to export. - -=item nest { ... } - -=item nest(\&$code) - -=item &nest($code) - -Used as a tracing barrier, any events generated inside the nest will trace to -the nest as opposed to the call to your provided tool. - -=item give $name - -=item give $name => sub { ... } - -Export a helper function that does not produce events. - -=item gives qw/sub1 sub2 .../ - -Export helper functions. - -=back - -=head1 HOW DO I TEST MY TEST TOOLS? - -See L<Test::Tester2> - -=head1 AUTHORS - -=over 4 - -=item Chad Granum E<lt>exodist@cpan.orgE<gt> - -=back - -=head1 SOURCE - -The source code repository for Test::More can be found at -F<http://github.com/Test-More/test-more/>. - -=head1 COPYRIGHT - -Copyright 2014 Chad Granum E<lt>exodist7@gmail.comE<gt>. - -This program is free software; you can redistribute it and/or -modify it under the same terms as Perl itself. - -See F<http://www.perl.com/perl/misc/Artistic.html> diff --git a/cpan/Test-Simple/lib/Test/Builder/Stream.pm b/cpan/Test-Simple/lib/Test/Builder/Stream.pm deleted file mode 100644 index fdfeb9ef1e..0000000000 --- a/cpan/Test-Simple/lib/Test/Builder/Stream.pm +++ /dev/null @@ -1,684 +0,0 @@ -package Test::Builder::Stream; -use strict; -use warnings; - -use Carp qw/confess croak/; -use Scalar::Util qw/reftype blessed/; -use Test::Builder::Threads; -use Test::Builder::Util qw/accessors accessor atomic_deltas try protect/; - -accessors qw/plan bailed_out/; -atomic_deltas qw/tests_run tests_failed/; - -accessor no_ending => sub { 0 }; -accessor is_passing => sub { 1 }; -accessor _listeners => sub {{ }}; -accessor _mungers => sub {{ }}; -accessor _munge_order => sub {[ ]}; -accessor _follow_up => sub {{ }}; - -sub pid { shift->{pid} } - -{ - my ($root, @shared); - - sub root { $root }; - - sub shared { - $root ||= __PACKAGE__->new; - push @shared => $root unless @shared; - return $shared[-1]; - }; - - sub clear { $root = undef; @shared = () } - - sub intercept { - my $class = shift; - my ($code) = @_; - - confess "argument to intercept must be a coderef, got: $code" - unless reftype $code eq 'CODE'; - - my $orig = $class->intercept_start(); - my ($ok, $error) = try { $code->($shared[-1]) }; - - $class->intercept_stop($orig); - die $error unless $ok; - return $ok; - } - - sub intercept_start { - my $class = shift; - my $new = $_[0] || $class->new(no_follow => 1) || die "Internal error!"; - push @shared => $new; - return $new; - } - - sub intercept_stop { - my $class = shift; - my ($orig) = @_; - confess "intercept nesting inconsistancy!" - unless $shared[-1] == $orig; - return pop @shared; - } -} - -sub new { - my $class = shift; - my %params = @_; - my $self = bless { pid => $$ }, $class; - - share($self->{tests_run}); - share($self->{tests_failed}); - - $self->use_tap if $params{use_tap}; - $self->use_lresults if $params{use_lresults}; - $self->legacy_followup unless $params{no_follow}; - - return $self; -} - -sub follow_up { - my $self = shift; - my ($type, @action) = @_; - croak "'$type' is not an event type" - unless $type && $type->isa('Test::Builder::Event'); - - if (@action) { - my ($sub) = @action; - croak "The second argument to follow_up() must be a coderef, got: $sub" - if $sub && !(ref $sub && reftype $sub eq 'CODE'); - - $self->_follow_up->{$type} = $sub; - } - - return $self->_follow_up->{$type}; -} - -sub legacy_followup { - my $self = shift; - $self->_follow_up({ - 'Test::Builder::Event::Bail' => sub { exit 255 }, - 'Test::Builder::Event::Plan' => sub { - my ($plan) = @_; - return unless $plan->directive; - return unless $plan->directive eq 'SKIP'; - exit 0; - }, - }); -} - -sub exception_followup { - my $self = shift; - - $self->_follow_up({ - 'Test::Builder::Event::Bail' => sub {die $_[0]}, - 'Test::Builder::Event::Plan' => sub { - my $plan = shift; - return unless $plan->directive; - return unless $plan->directive eq 'SKIP'; - die $plan; - }, - }); -} - -sub expected_tests { - my $self = shift; - my $plan = $self->plan; - return undef unless $plan; - return $plan->max; -} - -sub listener { - my $self = shift; - my ($id) = @_; - confess("You must provide an ID for your listener") unless $id; - - confess("Listener ID's may not start with 'LEGACY_', those are reserved") - if $id =~ m/^LEGACY_/ && caller ne __PACKAGE__; - - return $self->_listeners->{$id}; -} - -sub listen { - my $self = shift; - my ($id, $listener) = @_; - - confess("You must provide an ID for your listener") unless $id; - - confess("Listener ID's may not start with 'LEGACY_', those are reserved") - if $id =~ m/^LEGACY_/ && caller ne __PACKAGE__; - - confess("Listeners must be code refs, or objects that implement handle(), got: $listener") - unless $listener && ( - (reftype $listener && reftype $listener eq 'CODE') - || - (blessed $listener && $listener->can('handle')) - ); - - my $listeners = $self->_listeners; - - confess("There is already a listener with ID: $id") - if $listeners->{$id}; - - $listeners->{$id} = $listener; - return sub { $self->unlisten($id) }; -} - -sub unlisten { - my $self = shift; - my ($id) = @_; - - confess("You must provide an ID for your listener") unless $id; - - confess("Listener ID's may not start with 'LEGACY_', those are reserved") - if $id =~ m/^LEGACY_/ && caller ne __PACKAGE__; - - my $listeners = $self->_listeners; - - confess("There is no listener with ID: $id") - unless $listeners->{$id}; - - delete $listeners->{$id}; -} - -sub munger { - my $self = shift; - my ($id) = @_; - confess("You must provide an ID for your munger") unless $id; - return $self->_mungers->{$id}; -} - -sub munge { - my $self = shift; - my ($id, $munger) = @_; - - confess("You must provide an ID for your munger") unless $id; - - confess("Mungers must be code refs, or objects that implement handle(), got: $munger") - unless $munger && ( - (reftype $munger && reftype $munger eq 'CODE') - || - (blessed $munger && $munger->can('handle')) - ); - - my $mungers = $self->_mungers; - - confess("There is already a munger with ID: $id") - if $mungers->{$id}; - - push @{$self->_munge_order} => $id; - $mungers->{$id} = $munger; - - return sub { $self->unmunge($id) }; -} - -sub unmunge { - my $self = shift; - my ($id) = @_; - my $mungers = $self->_mungers; - - confess("You must provide an ID for your munger") unless $id; - - confess("There is no munger with ID: $id") - unless $mungers->{$id}; - - $self->_munge_order([ grep { $_ ne $id } @{$self->_munge_order} ]); - delete $mungers->{$id}; -} - -sub send { - my $self = shift; - my ($item) = @_; - - # The redirect will return true if it intends to redirect, we should then return. - # If it returns false that means we do not need to redirect and should act normally. - if (my $redirect = $self->fork) { - return if $redirect->handle(@_); - } - - my $items = [$item]; - for my $munger_id (@{$self->_munge_order}) { - my $new_items = []; - my $munger = $self->munger($munger_id) || next; - - for my $item (@$items) { - push @$new_items => reftype $munger eq 'CODE' ? $munger->($item) : $munger->handle($item); - } - - $items = $new_items; - } - - for my $item (@$items) { - if ($item->isa('Test::Builder::Event::Plan')) { - $self->plan($item); - } - - if ($item->isa('Test::Builder::Event::Bail')) { - $self->bailed_out($item); - } - - if ($item->isa('Test::Builder::Event::Ok')) { - $self->tests_run(1); - $self->tests_failed(1) unless $item->bool; - } - - for my $listener (values %{$self->_listeners}) { - protect { - if (reftype $listener eq 'CODE') { - $listener->($item); - if ($item->can('diag') && $item->diag) { - $listener->($_) for grep {$_} @{$item->diag}; - } - } - else { - $listener->handle($item); - if ($item->can('diag') && $item->diag) { - $listener->handle($_) for grep {$_} @{$item->diag}; - } - } - }; - } - } - - for my $item (@$items) { - my $type = blessed $item; - my $follow = $self->follow_up($type) || next; - $follow->($item); - } -} - -sub tap { shift->listener('LEGACY_TAP') } - -sub use_tap { - my $self = shift; - return if $self->tap; - require Test::Builder::Formatter::TAP; - $self->listen(LEGACY_TAP => Test::Builder::Formatter::TAP->new()); -} - -sub no_tap { - my $self = shift; - $self->unlisten('LEGACY_TAP') if $self->tap; - return; -} - -sub lresults { shift->listener('LEGACY_RESULTS') } - -sub use_lresults { - my $self = shift; - return if $self->lresults; - require Test::Builder::Formatter::LegacyResults; - $self->listen(LEGACY_RESULTS => Test::Builder::Formatter::LegacyResults->new()); -} - -sub no_lresults { - my $self = shift; - $self->unlisten('LEGACY_RESULTS') if $self->lresults; - return; -} - -sub fork { shift->{'fork'} } - -sub use_fork { - my $self = shift; - - return if $self->{fork}; - - require Test::Builder::Fork; - $self->{fork} = Test::Builder::Fork->new; -} - -sub no_fork { - my $self = shift; - - return unless $self->{fork}; - - delete $self->{fork}; # Turn it off. -} - -sub spawn { - my $self = shift; - my (%params) = @_; - - my $new = blessed($self)->new(); - - $new->{fork} = $self->{fork}; - - my $refs = { - listeners => $self->_listeners, - mungers => $self->_mungers, - }; - - $new->_munge_order([@{$self->_munge_order}]); - - for my $type (keys %$refs) { - for my $key (keys %{$refs->{$type}}) { - next if $key eq 'LEGACY_TAP'; - next if $key eq 'LEGACY_RESULTS'; - $new->{"_$type"}->{$key} = sub { - my $item = $refs->{$type}->{$key} || return; - return $item->(@_) if reftype $item eq 'CODE'; - $item->handle(@_); - }; - } - } - - if ($self->tap && !$params{no_tap}) { - $new->use_tap; - $new->tap->io_sets({%{$self->tap->io_sets}}); - } - - $new->use_lresults if $self->lresults && !$params{no_lresults}; - - return $new; -} - -1; - -__END__ - -=head1 NAME - -Test::Bulder::Stream - The stream between Test::Builder and the formatters. - -=head1 TEST COMPONENT MAP - - [Test Script] > [Test Tool] > [Test::Builder] > [Test::Bulder::Stream] > [Event Formatter] - ^ - You are here - -A test script uses a test tool such as L<Test::More>, which uses Test::Builder -to produce events. The events are sent to L<Test::Builder::Stream> which then -forwards them on to one or more formatters. The default formatter is -L<Test::Builder::Fromatter::TAP> which produces TAP output. - -=head1 DESCRIPTION - -This module is responsible for taking event object from L<Test::Builder> and -forwarding them to the listeners/formatters. It also has facilities for -intercepting the events and munging them. Examples of this are forking support -and L<Test::Tester2>. - -=head1 METHODS - -=head2 CONSTRUCTION/FETCHING - -It is possible to construct an independant stream object using C<new()>. Most -of the time however you do not want an independant stream, you want the shared -stream. The shared stream is the stream to which all test output should be -sent. The shared stream is actually a stack, and the topmost stream should -always be used unless you I<really> know what you are doing. - -=over 4 - -=item $stream = $class->new(); - -=item $stream = $class->new(use_tap => 1); - -=item $stream = $class->new(use_lresults => 1); - -=item $stream = $class->new(no_follow => 1); - -Create a new/independant stream object. No listeners by default, but you can -specify 'use_tap' and/or 'use_lresults' to add those listeners. - -no_follow will disable the legacy behavior of exiting on bailout, or when a -skip_all plan is encountered. - -=item $stream = $class->shared() - -Get the topmost stream on the shared stream stack. - -=item $stream = $class->root() - -Get the bottom-most stream in the shared stack. - -=item $class->clear() - -Remove all streams from the shared stack. - -=item $stream->intercept(sub { ... }) - -Push a new stream onto the stack, run the specified code, then pop the new stream off of the stack. - -=item $stream->intercept_start() - -=item $stream->intercept_start($stream) - -Push a new stream onto the top of the shared stack. Returns the $stream that -was pushed. Optionally you can provide a stream to push instead of letting it -make a new one for you. - -=item $stream->intercept_stop($stream) - -Pop the topmost stream. You B<must> pass in the stream you expect to be popped. -If the stream you pass in does not match the one popped an exception will be -thrown. - -=item $child = $stream->spawn() - -=item $child = $stream->spawn(no_tap => 1) - -=item $child = $stream->spawn(no_lresults => 1) - -Spawn a cloned stream. The clone will have all the same listeners and mungers -as the parent. Removing a listener from the parent will be reflected in the -child, but the reverse is not true. - -TAP and legacy results are special, so they are also cloned instead of carrying -them over. Removing them from the parent will not remove them from the child. - -=back - -=head2 ACCESSORS - -=over 4 - -=item $plan = $stream->plan() - -=item $stream->plan($plan) - -=item $stream->plan(undef) - -Get/Set the plan, usually done for you when a plan object is encountered. - -=item $pid = $stream->pid() - -Get the original PID in which the stream object was built. - -=item $num = $stream->tests_run() - -=item $stream->tests_run($delta) - -Get the number of tests run. Optionally you can provide a delta, the number of -tests run will be adjusted by the delta. - -=item $stream->tests_failed($delta) - -Get the number of tests failed. Optionally you can provide a delta, the number of -tests failed will be adjusted by the delta. - -=item $bool = $stream->is_passing() - -=item $stream->is_padding($bool) - -Check if tests are passing, optinally you can pass in a $bool to reset this. - -=back - -=head2 BEHAVIOR CONTROL - -=over 4 - -=item $bool = $stream->no_ending() - -=item $stream->no_ending($bool) - -enable/disable endings. Defaults to false. - -=item $action = $stream->follow_up('Test::Builder::Event::...') - -=item $stream->follow_up('Test::Builder::Event::...' => sub { ($r) = @_; ... }) - -Fetch or Specify a followup behavior to run after all listeners have gotten an -event of the specified type. - -=item $stream->legacy_followup - -switch to legacy follow-up behavior. This means exiting for bailout or skip_all. - -=item $stream->exception_followup - -Switch to exception follow-up behavior. This means throwing an exception on -bailout or skip_all. This is necessary for intercepting events. - -=item $fork_handler = $stream->fork - -Get the fork handler. - -=item $stream->use_fork - -Enable forking - -=item $stream->no_fork - -Disable forking. - -=back - -=head2 PLANNING - -=over 4 - -=item $count = $stream->expected_tests - -Get the expected number of tests, if any. - -=back - -=head2 LISTENER CONTROL - -=head3 NORMAL LISTENERS - -=over 4 - -=item $L = $stream->listener($id) - -Get the listener with the given ID. - -=item $unlisten = $stream->listen($id, $listener) - -Add a listener with the given ID. The listener can either be a coderef that -takes a event object as an argument, or any object that implements a handle() -method. - -This method returns a coderef that can be used to remove the listener. It is -better to use this method over unlisten as it will remove the listener from the -original stream object and any child stream objects. - -=item $stream->unlisten($id) - -Remove a listener by id. - -=back - -=head3 LEGACY TAP LISTENER - -=over 4 - -=item $L = $stream->tap - -Get the tap listener object (if TAP is enabled) - -=item $stream->use_tap - -Enable the legacy tap listener. - -=item $stream->no_tap - -Disable the legacy tap listener. - -=back - -=head3 LEGACY EVENTS LISTENER - -=over 4 - -=item $L = $stream->lresults - -Get the Legacy Result lsitener object. - -=item $stream->use_lresults - -Enable legacy results - -=item $stream->no_lresults - -Disable legacy results - -=back - -=head2 MUNGING EVENTS - -Mungers are expected to take an event object and return 1 or more event -objects to replace the original. They are also allowed to simply modify the -original, or return nothing to remove it. - -Mungers are run in the order they are added, it is possible that the first -munger will remove an event in which case later mungers will never see it. -Listeners get the product of running all the mungers on the original event. - -=over 4 - -=item $M = $stream->munger($id) - -Get the munger with the specified ID. - -=item $unmunge = $stream->munge($id => $munger) - -Add a munger. The munger may be a coderef that takes a single event object as -an argument, or it can be any object that implements a handle() method. - -This method returns a coderef that can be used to remove the munger. It is -better to use this method over unmunge as it will remove the munger from the -original stream object and any child stream objects. - -=item $stream->unmunge($id) - -Remove a munger by id. - -=back - -=head2 PROVIDING EVENTS - -=over 4 - -=item $stream->send($event) - -Send a event to all listeners (also goes through munging and the form handler, -etc.) - -=back - -=head1 AUTHORS - -=over 4 - -=item Chad Granum E<lt>exodist@cpan.orgE<gt> - -=back - -=head1 SOURCE - -The source code repository for Test::More can be found at -F<http://github.com/Test-More/test-more/>. - -=head1 COPYRIGHT - -Copyright 2014 Chad Granum E<lt>exodist7@gmail.comE<gt>. - -This program is free software; you can redistribute it and/or -modify it under the same terms as Perl itself. - -See F<http://www.perl.com/perl/misc/Artistic.html> diff --git a/cpan/Test-Simple/lib/Test/Builder/Tester.pm b/cpan/Test-Simple/lib/Test/Builder/Tester.pm index cde3183685..5128be9d90 100644 --- a/cpan/Test-Simple/lib/Test/Builder/Tester.pm +++ b/cpan/Test-Simple/lib/Test/Builder/Tester.pm @@ -1,23 +1,17 @@ package Test::Builder::Tester; use strict; -our $VERSION = '1.301001_040'; -$VERSION = eval $VERSION; ## no critic (BuiltinFunctions::ProhibitStringyEval) +our $VERSION = "1.23_003"; -use Test::Builder 1.301001; +use Test::Builder 0.98; use Symbol; use Carp; =head1 NAME -Test::Builder::Tester - *DEPRECATED* test testsuites that have been built with +Test::Builder::Tester - test testsuites that have been built with Test::Builder -=head1 DEPRECATED - -B<This module is deprecated.> Please see L<Test::Tester2> for a -better alternative that does not involve dealing with TAP/string output. - =head1 SYNOPSIS use Test::Builder::Tester tests => 1; @@ -31,20 +25,20 @@ better alternative that does not involve dealing with TAP/string output. =head1 DESCRIPTION A module that helps you test testing modules that are built with -L<Test::Builder>. +B<Test::Builder>. The testing system is designed to be used by performing a three step process for each test you wish to test. This process starts with using C<test_out> and C<test_err> in advance to declare what the testsuite you -are testing will output with L<Test::Builder> to stdout and stderr. +are testing will output with B<Test::Builder> to stdout and stderr. You then can run the test(s) from your test suite that call -L<Test::Builder>. At this point the output of L<Test::Builder> is -safely captured by L<Test::Builder::Tester> rather than being +B<Test::Builder>. At this point the output of B<Test::Builder> is +safely captured by B<Test::Builder::Tester> rather than being interpreted as real test output. The final stage is to call C<test_test> that will simply compare what you -predeclared to what L<Test::Builder> actually outputted, and report the +predeclared to what B<Test::Builder> actually outputted, and report the results back with a "ok" or "not ok" (with debugging) to the normal output. @@ -54,36 +48,35 @@ output. # set up testing #### -#my $t = Test::Builder->new; +my $t = Test::Builder->new; ### # make us an exporter ### -use Test::Builder::Provider; +use Exporter; +our @ISA = qw(Exporter); -provides qw(test_out test_err test_fail test_diag test_test line_num); +our @EXPORT = qw(test_out test_err test_fail test_diag test_test line_num); -sub before_import { +sub import { my $class = shift; - my ($args) = @_; + my(@plan) = @_; my $caller = caller; - warn __PACKAGE__ . " is deprecated!\n" if builder()->modern; - - builder()->exported_to($caller); - builder()->plan(@$args); + $t->exported_to($caller); + $t->plan(@plan); my @imports = (); - foreach my $idx ( 0 .. @$args ) { - if( $args->[$idx] && $args->[$idx] eq 'import' ) { - @imports = @{ $args->[ $idx + 1 ] }; + foreach my $idx ( 0 .. $#plan ) { + if( $plan[$idx] eq 'import' ) { + @imports = @{ $plan[ $idx + 1 ] }; last; } } - @$args = @imports; + __PACKAGE__->export_to_level( 1, __PACKAGE__, @imports ); } ### @@ -107,8 +100,6 @@ my $testing = 0; my $testing_num; my $original_is_passing; -my $original_stream; - # remembering where the file handles were originally connected my $original_output_handle; my $original_failure_handle; @@ -124,14 +115,14 @@ sub _start_testing { $ENV{HARNESS_ACTIVE} = 0; # remember what the handles were set to - $original_output_handle = builder()->output(); - $original_failure_handle = builder()->failure_output(); - $original_todo_handle = builder()->todo_output(); + $original_output_handle = $t->output(); + $original_failure_handle = $t->failure_output(); + $original_todo_handle = $t->todo_output(); # switch out to our own handles - builder()->output($output_handle); - builder()->failure_output($error_handle); - builder()->todo_output($output_handle); + $t->output($output_handle); + $t->failure_output($error_handle); + $t->todo_output($output_handle); # clear the expected list $out->reset(); @@ -139,13 +130,13 @@ sub _start_testing { # remember that we're testing $testing = 1; - $testing_num = builder()->current_test; - builder()->current_test(0); - $original_is_passing = builder()->is_passing; - builder()->is_passing(1); + $testing_num = $t->current_test; + $t->current_test(0); + $original_is_passing = $t->is_passing; + $t->is_passing(1); # look, we shouldn't do the ending stuff - builder()->no_ending(1); + $t->no_ending(1); } =head2 Functions @@ -174,8 +165,8 @@ which is even the same as test_out("ok 2"); Once C<test_out> or C<test_err> (or C<test_fail> or C<test_diag>) have -been called, all further output from L<Test::Builder> will be -captured by L<Test::Builder::Tester>. This means that you will not +been called, all further output from B<Test::Builder> will be +captured by B<Test::Builder::Tester>. This means that you will not be able perform further tests to the normal output in the normal way until you call C<test_test> (well, unless you manually meddle with the output filehandles) @@ -198,7 +189,7 @@ sub test_err { =item test_fail -Because the standard failure message that L<Test::Builder> produces +Because the standard failure message that B<Test::Builder> produces whenever a test fails will be a common occurrence in your test error output, and because it has changed between Test::Builder versions, rather than forcing you to call C<test_err> with the string all the time like @@ -237,7 +228,7 @@ sub test_fail { =item test_diag As most of the remaining expected output to the error stream will be -created by L<Test::Builder>'s C<diag> function, L<Test::Builder::Tester> +created by Test::Builder's C<diag> function, B<Test::Builder::Tester> provides a convenience function C<test_diag> that you can use instead of C<test_err>. @@ -251,7 +242,7 @@ you can write test_diag("Couldn't open file"); -Remember that L<Test::Builder>'s diag function will not add newlines to +Remember that B<Test::Builder>'s diag function will not add newlines to the end of output and test_diag will. So to check Test::Builder->new->diag("foo\n","bar\n"); @@ -270,13 +261,13 @@ sub test_diag { # expect the same thing, but prepended with "# " local $_; - $err->expect( map { m/\S/ ? "# $_" : "" } @_ ); + $err->expect( map { "# $_" } @_ ); } =item test_test Actually performs the output check testing the tests, comparing the -data (with C<eq>) that we have captured from L<Test::Builder> against +data (with C<eq>) that we have captured from B<Test::Builder> against what was declared with C<test_out> and C<test_err>. This takes name/value pairs that effect how the test is run. @@ -306,9 +297,9 @@ As a convenience, if only one argument is passed then this argument is assumed to be the name of the test (as in the above examples.) Once C<test_test> has been run test output will be redirected back to -the original filehandles that L<Test::Builder> was connected to +the original filehandles that B<Test::Builder> was connected to (probably STDOUT and STDERR,) meaning any further tests you run -will function normally and cause success/errors for L<Test::Harness>. +will function normally and cause success/errors for B<Test::Harness>. =cut @@ -331,21 +322,21 @@ sub test_test { unless $testing; # okay, reconnect the test suite back to the saved handles - builder()->output($original_output_handle); - builder()->failure_output($original_failure_handle); - builder()->todo_output($original_todo_handle); + $t->output($original_output_handle); + $t->failure_output($original_failure_handle); + $t->todo_output($original_todo_handle); # restore the test no, etc, back to the original point - builder()->current_test($testing_num); + $t->current_test($testing_num); $testing = 0; - builder()->is_passing($original_is_passing); + $t->is_passing($original_is_passing); # re-enable the original setting of the harness $ENV{HARNESS_ACTIVE} = $original_harness_env; # check the output we've stashed - unless( builder()->ok( ( $args{skip_out} || $out->check ) && - ( $args{skip_err} || $err->check ), $mess ) + unless( $t->ok( ( $args{skip_out} || $out->check ) && + ( $args{skip_err} || $err->check ), $mess ) ) { # print out the diagnostic information about why this @@ -353,10 +344,10 @@ sub test_test { local $_; - builder()->diag( map { "$_\n" } $out->complaint ) + $t->diag( map { "$_\n" } $out->complaint ) unless $args{skip_out} || $out->check; - builder()->diag( map { "$_\n" } $err->complaint ) + $t->diag( map { "$_\n" } $err->complaint ) unless $args{skip_err} || $err->check; } } @@ -409,11 +400,11 @@ respectively, and the function called with no argument will return the current setting. To enable colouring from the command line, you can use the -L<Text::Builder::Tester::Color> module like so: +B<Text::Builder::Tester::Color> module like so: perl -Mlib=Text::Builder::Tester::Color test.t -Or by including the L<Test::Builder::Tester::Color> module directly in +Or by including the B<Test::Builder::Tester::Color> module directly in the PERL5LIB. =cut @@ -429,12 +420,12 @@ sub color { =head1 BUGS -Calls C<< Test::Builder->no_ending >> turning off the ending tests. +Calls C<<Test::Builder->no_ending>> turning off the ending tests. This is needed as otherwise it will trip out because we've run more tests than we strictly should have and it'll register any failures we had that we were testing for as real failures. -The color function doesn't work unless L<Term::ANSIColor> is +The color function doesn't work unless B<Term::ANSIColor> is compatible with your terminal. Bugs (and requests for new features) can be reported to the author @@ -445,7 +436,7 @@ L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-Builder-Tester> Copyright Mark Fowler E<lt>mark@twoshortplanks.comE<gt> 2002, 2004. -Some code taken from L<Test::More> and L<Test::Catch>, written by +Some code taken from B<Test::More> and B<Test::Catch>, written by Michael G Schwern E<lt>schwern@pobox.comE<gt>. Hence, those parts Copyright Micheal G Schwern 2001. Used and distributed with permission. @@ -496,9 +487,8 @@ sub expect { sub _account_for_subtest { my( $self, $check ) = @_; - my $builder = Test::Builder::Tester->builder(); # Since we ship with Test::Builder, calling a private method is safe...ish. - return ref($check) ? $check : ($builder->depth ? ' ' x $builder->depth : '') . $check; + return ref($check) ? $check : $t->_indent . $check; } sub _translate_Failed_check { diff --git a/cpan/Test-Simple/lib/Test/Builder/Tester/Color.pm b/cpan/Test-Simple/lib/Test/Builder/Tester/Color.pm index fdd1f5ce98..b269a2783d 100644 --- a/cpan/Test-Simple/lib/Test/Builder/Tester/Color.pm +++ b/cpan/Test-Simple/lib/Test/Builder/Tester/Color.pm @@ -1,8 +1,7 @@ package Test::Builder::Tester::Color; use strict; -our $VERSION = '1.301001_040'; -$VERSION = eval $VERSION; ## no critic (BuiltinFunctions::ProhibitStringyEval) +our $VERSION = "1.23_002"; require Test::Builder::Tester; diff --git a/cpan/Test-Simple/lib/Test/Builder/Threads.pm b/cpan/Test-Simple/lib/Test/Builder/Threads.pm deleted file mode 100644 index 93206ed41d..0000000000 --- a/cpan/Test-Simple/lib/Test/Builder/Threads.pm +++ /dev/null @@ -1,107 +0,0 @@ -package Test::Builder::Threads; -use strict; -use warnings; - -# Make Test::Builder thread-safe for ithreads. -BEGIN { - use Config; - # Load threads::shared when threads are turned on. - if( $Config{useithreads} && $INC{'threads.pm'} ) { - require threads::shared; - - # Hack around YET ANOTHER threads::shared bug. It would - # occasionally forget the contents of the variable when sharing it. - # So we first copy the data, then share, then put our copy back. - *share = sub (\[$@%]) { - my $type = ref $_[0]; - my $data; - - if( $type eq 'HASH' ) { - %$data = %{ $_[0] }; - } - elsif( $type eq 'ARRAY' ) { - @$data = @{ $_[0] }; - } - elsif( $type eq 'SCALAR' ) { - $$data = ${ $_[0] }; - } - else { - die( "Unknown type: " . $type ); - } - - $_[0] = &threads::shared::share( $_[0] ); - - if( $type eq 'HASH' ) { - } - elsif( $type eq 'ARRAY' ) { - @{ $_[0] } = @$data; - } - elsif( $type eq 'SCALAR' ) { - ${ $_[0] } = $$data; - } - else { - die( "Unknown type: " . $type ); - } - - return $_[0]; - }; - } - else { - *share = sub { return $_[0] }; - *lock = sub { 0 }; - } -} - -sub import { - my $class = shift; - my $caller = caller; - - no strict 'refs'; - *{"$caller\::share"} = $class->can('share') if $class->can('share'); - *{"$caller\::lock"} = $class->can('lock') if $class->can('lock'); -} - -1; - -__END__ - -=head1 NAME - -Test::Builder::Threads - Helper Test::Builder uses when threaded. - -=head1 DESCRIPTION - -Helper Test::Builder uses when threaded. - -=head1 SYNOPSYS - - use threads; - use Test::Builder::Threads; - - share(...); - lock(...); - -=head1 AUTHORS - -=over 4 - -=item Chad Granum E<lt>exodist@cpan.orgE<gt> - -=back - -=head1 SOURCE - -The source code repository for Test::More can be found at -F<http://github.com/Test-More/test-more/>. - -=head1 COPYRIGHT - -Copyright 2014 Chad Granum E<lt>exodist7@gmail.comE<gt>. - -Most of this code was pulled out ot L<Test::Builder>, written by Schwern and -others. - -This program is free software; you can redistribute it and/or -modify it under the same terms as Perl itself. - -See F<http://www.perl.com/perl/misc/Artistic.html> diff --git a/cpan/Test-Simple/lib/Test/Builder/Trace.pm b/cpan/Test-Simple/lib/Test/Builder/Trace.pm deleted file mode 100644 index 3f19222539..0000000000 --- a/cpan/Test-Simple/lib/Test/Builder/Trace.pm +++ /dev/null @@ -1,341 +0,0 @@ -package Test::Builder::Trace; -use strict; -use warnings; - -use Test::Builder::Util qw/accessor accessors is_tester try/; -use Test::Builder::Trace::Frame; -use List::Util qw/first/; -use Scalar::Util qw/blessed/; - -accessor _anointed => sub { [] }; -accessor _full => sub { [] }; -accessor _level => sub { [] }; -accessor _tools => sub { [] }; -accessor _transitions => sub { [] }; -accessor _stack => sub { [] }; -accessor _todo => sub { [] }; -accessor raw => sub { [] }; -accessor packages => sub { [] }; -accessor seek_level => sub { 0 }; -accessor todo_raw => sub { {} }; - -accessors qw/_report encoding _parent/; - -sub nest { - my $class = shift; - my ($code, @args) = @_; - $code->(@args); -} - -sub anoint { - my $class = shift; - my ($target, $oil) = @_; - - unless (is_tester($target)) { - my $meta = {anointed_by => {}}; - no strict 'refs'; - *{"$target\::TB_TESTER_META"} = sub {$meta}; - } - - return 1 unless $oil; - my $meta = $target->TB_TESTER_META; - $meta->{anointed_by}->{$oil} = 1; -} - -sub new { - my $class = shift; - my $self = bless {}, $class; - - my $seek_level = do { no warnings 'once'; $Test::Builder::Level - $Test::Builder::BLevel }; - $self->seek_level($seek_level); - - my %todo; - my %packages; - - my $raw = $self->raw; - my $plist = $self->packages; - - my $stack_level = 0; - while(my @call = CORE::caller($stack_level++)) { - unless(exists $todo{$call[0]}) { - no strict 'refs'; - $todo{$call[0]} = ${"$call[0]\::TODO"}; - } - - my $record = [@call[0 .. 4], $todo{$call[0]}]; - push @$raw => $record; - - next if $packages{$call[0]}++; - push @$plist => $call[0]; - next if $self->encoding; - next unless is_tester($call[0]); - next if $call[3] eq 'Test::Builder::subtest'; - $self->encoding($call[0]->TB_TESTER_META->{encoding}); - } - - $self->todo_raw(\%todo); - - return $self; -} - -accessor todo_reasons => sub { - my $self = shift; - my %seen; - return [grep { $_ && !$seen{$_} } values %{$self->todo_raw}]; -}; - -accessor todo_package => sub { - my $self = shift; - - # Do not force building, but if it is built use it. - if ($self->{_build}) { - return $self->report->package if $self->report && $self->report->todo; - return $self->todo->[-1]->package if @{$self->todo}; - return $self->anointed->[-1]->package if @{$self->anointed}; - return; - } - - my $raw = $self->todo_raw; - if (@{$self->todo_reasons}) { - for my $pkg (@{$self->packages}) { - next unless $raw->{$pkg}; - return $pkg; - } - } - - my $anointed; - for my $pkg (@{$self->packages}) { - no strict 'refs'; - no warnings 'once'; - - my $ref = *{$pkg . '::TODO'}{SCALAR}; - return $pkg if $ref == *Test::More::TODO{SCALAR}; - - $anointed ||= $pkg if is_tester($pkg); - } - - return $anointed; -}; - -sub _build { - my $self = shift; - my $class = blessed($self); - - return if $self->{_build}++; - - my $seek_level = $self->seek_level; - my $stack_level = 0; - my $notb_level = 0; - - my $current = $self; - for my $call (@{$self->raw}) { - my $depth = $stack_level++; - my $frame = Test::Builder::Trace::Frame->new($depth, @$call); - my ($pkg, $file, $line, $sub, $todo) = @$call; - - push @{$current->_full} => $frame; - - if ($frame->nest) { - $current->report; - $current->_parent( bless {}, $class ); - $current = $current->_parent; - next; - } - - next if $frame->builder; - - $notb_level++ unless $current->_is_transition($frame); - - if ($seek_level && $notb_level - 1 == $seek_level) { - $frame->level(1); - $current->_report($current->tools->[-1]) if $current->tools->[-1] && !($current->_report || $frame->anointed); - } - - next unless grep { $frame->$_ } qw/provider_tool anointed transition level todo/; - - push @{$current->_stack} => $frame; - push @{$current->_tools} => $frame if $frame->provider_tool; - push @{$current->_anointed} => $frame if $frame->anointed; - push @{$current->_transitions} => $frame if $frame->transition; - push @{$current->_level} => $frame if $frame->level; - push @{$current->_todo} => $frame if $frame->todo; - } -} - -sub report { - my $self = shift; - my ($report) = @_; - - if ($report) { - $report->report(1); - $self->_report($report); - } - elsif (!$self->_report) { - $self->_build; - my $level = $self->_level->[0]; - my $tool = $self->_tools->[-1]; - my $anointed = first { !$_->provider_tool } @{$self->_anointed}; - my $transition = $self->_transitions->[-1]; - - if ($tool && $level) { - ($report) = sort { $b->{depth} <=> $a->{depth} } $tool, $level; - } - - $report ||= $level || $tool || $anointed || $transition; - - if ($report) { - $report->report(1); - $self->_report($report); - } - } - - return $self->_report; -} - -sub _is_transition { - my $self = shift; - my ($frame) = @_; - - # Check if it already knows - return 1 if $frame->transition; - - return if $frame->builder; - return unless @{$self->full} > 1; - return unless $self->full->[-2]->builder || $self->full->[-2]->nest; - - $frame->transition(1); - - return 1; -} - -for my $name (qw/anointed full level tools transitions stack todo parent/) { - my $acc = "_$name"; - my $sub = sub { - my $self = shift; - $self->_build; - return $self->$acc; - }; - - no strict 'refs'; - *$name = $sub; -} - -1; - -__END__ - -=pod - -=head1 NAME - -Test::Builder::Trace - Module to represent a stack trace from a test event. - -=head1 DESCRIPTION - -When a test fails it will report the filename and line where the failure -occured. In order to do this it needs to look at the stack and figure out where -your tests stop, and the tools you are using begin. This object helps you find -the desired caller frame. - -=head1 CLASS METHODS - -=over 4 - -=item $trace = $class->new - -Create a new object tracing from itself to the deepest stack frame. - - my $trace = Test::Builder::Trace->new(); - -=item $class->nest(sub { ... }) - -Used as a tracing barrier. Events produced in the coderef will trace to that -coderef and no deeper. - -=item $class->anoint($TARGET_PACKAGE) - -=item $class->anoint($TARGET_PACKAGE, $ANOINTED_BY_PACKAGE) - -Used to anoint a package as a testing package. - -=back - -=head1 UTILITY METHODS - -=over 4 - -=item $frame = $trace->report - -Get the L<Test::Builder::Trace::Frame> object that should be used when -reporting errors. The 'report' is determined by examining the stack, -C<$Test::Builder::Level>, and provider/anointed metadata. - -=item $trace = $trace->parent - -A trace stops when it encounters a call to C<Test::Builder::Trace::nest> which -acts as a tracing barrier. When such a barrier is encountered the tracing -continues, but stores the frames in a new L<Test::Builder::Trace> object that -is set as the parent. You can use this to examine the stack beyond the main -trace. - -=back - -=head1 STACKS - -All stacks are arrayrefs containing L<Test::Builder::Trace::Frame> objects. - -=over 4 - -=item $arrayref = $trace->stack - -This stack contains all frames that are relevant to finding the report. Many -frames are kept out of this list. This will usually be the most helpful stack -to examine. - -=item $arrayref = $trace->full - -Absolutely every frame is kept in this stack. Examine this if you want to see -EVERYTHING. - -=item $arrayref = $trace->anointed - -This stack contains all the frames that come from an anointed package. - -=item $arrayref = $trace->level - -This stack contains all the frames that match the C<$Test::Builder::Level> -variable. - -=item $arrayref = $trace->tools - -This stack contains all the frames that are calls to provider tools. - -=item $arrayref = $trace->transitions - -This stack contains all the frames that act as transitions between external -code and L<Test::Builder> related code. - -=item $arrayref - $trace->todo - -This stack contains all the frames that seem to have a $TODO variable available -to them. See L<Test::Builder::Trace::Frame> for caveats. - -=back - -=head1 AUTHORS - -=over 4 - -=item Chad Granum E<lt>exodist@cpan.orgE<gt> - -=back - -=head1 COPYRIGHT - -Copyright 2014 by Chad Granum E<lt>exodist7@gmail.comE<gt> - -This program is free software; you can redistribute it and/or -modify it under the same terms as Perl itself. - -See F<http://www.perl.com/perl/misc/Artistic.html> - diff --git a/cpan/Test-Simple/lib/Test/Builder/Trace/Frame.pm b/cpan/Test-Simple/lib/Test/Builder/Trace/Frame.pm deleted file mode 100644 index 6d4a1daf37..0000000000 --- a/cpan/Test-Simple/lib/Test/Builder/Trace/Frame.pm +++ /dev/null @@ -1,240 +0,0 @@ -package Test::Builder::Trace::Frame; -use strict; -use warnings; - -use Test::Builder::Util qw/accessors accessor is_provider is_tester/; - -my %BUILDER_PACKAGES = ( - __PACKAGE__, 1, - 'Test::Builder' => 1, - 'Test::Builder::Event' => 1, - 'Test::Builder::Event::Bail' => 1, - 'Test::Builder::Event::Child' => 1, - 'Test::Builder::Event::Diag' => 1, - 'Test::Builder::Event::Note' => 1, - 'Test::Builder::Event::Ok' => 1, - 'Test::Builder::Event::Plan' => 1, - 'Test::Builder::Stream' => 1, - 'Test::Builder::Trace' => 1, - 'Test::Builder::Util' => 1, -); - -accessors qw{ - depth package file line subname todo - level report -}; - -sub new { - my $class = shift; - my ($depth, $pkg, $file, $line, $sub, $todo) = @_; - - return bless { - depth => $depth || 0, - package => $pkg || undef, - file => $file || undef, - line => $line || 0, - subname => $sub || undef, - todo => $todo || undef, - }, $class; -} - -sub call { - my $self = shift; - return ( - $self->package, - $self->file, - $self->line, - $self->subname, - ); -} - -accessor transition => sub { - my $self = shift; - - return 0 if $self->builder; - - my $subname = $self->subname; - return 0 unless $subname; - return 0 unless $subname =~ m/^(.*)::([^:]+)$/; - my ($pkg, $sub) = ($1, $2); - - return $BUILDER_PACKAGES{$pkg} || 0; -}; - -accessor nest => sub { - my $self = shift; - return 0 unless $self->subname eq 'Test::Builder::Trace::nest'; - return 1; -}; - -accessor builder => sub { - my $self = shift; - return 0 unless $BUILDER_PACKAGES{$self->package}; - return 1; -}; - -accessor anointed => sub { - my $self = shift; - return 0 unless is_tester($self->package); - return 0 if $self->subname eq 'Test::Builder::subtest'; - return 1; -}; - -accessor provider_tool => sub { - my $self = shift; - - my $subname = $self->subname; - return undef if $subname eq '(eval)'; - - my $attrs; - if ($subname =~ m/^Test\::Builder\::Provider\::__ANON(\d+)__/) { - no strict 'refs'; - return \%{$subname}; - } - else { - my ($pkg, $sub) = ($subname =~ m/^(.+)::([_\w][_\w0-9]*)/); - if (is_provider($pkg) && $sub && $sub ne '__ANON__') { - $attrs = $pkg->TB_PROVIDER_META->{attrs}->{$sub}; - return $attrs if $attrs->{named}; - } - } - - return undef; -}; - -1; - -=pod - -=head1 NAME - -Test::Builder::Trace::Frame - Module to represent a stack frame - -=head1 DESCRIPTION - -When a test fails it will report the filename and line where the failure -occured . In order to do this it needs to look at the stack and figure out -where your tests stop, and the tools you are using begin . This object -represents a single stack frame . - -=head1 CLASS METHODS - -=over 4 - -=item $frame = $class->new($depth, $package, $file, $line, $sub) - -Create a new instance. - - my $frame = $class->new(4, caller(4)); - -=back - -=head1 UTILITY METHODS - -=over 4 - -=item @call = $frame->call - -=item ($pkg, $file, $line, $subname) = $frame->call - -Returns a list similar to calling C<caller()>. - -=back - -=head1 ACCESSORS - -=over 4 - -=item $depth = $frame->depth - -Depth of the frame in the stack - -=item $package = $frame->package - -Package of the frame - -=item $file = $frame->file - -File of the frame - -=item $line = $frame->line - -Line of the frame - -=item $subname = $frame->subname - -Name of sub being called - -=item $attrs = $frame->provider_tool - -If the frame is a call to a provider tool this will contain the attribute -hashref for that tool. This returns undef when the call was not to a provider -tool. - -=back - -=head1 CALCULATED BOOLEAN ATTRIBUTES - -The state of these booleans will be determined the first time they are called. -They will be cached for future calls. - -=over 4 - -=item $todo = $frame->todo - -Returns the TODO message if $TODO is set in the package the frame is from. - -=item $bool = $frame->nest - -True if the frame is a call to L<Test::Builder::Trace::nest()>. - -=item $bool = $frame->builder - -True if the frame is inside Test::Builder code. - -=item $bool = $frame->transition - -True if the frame is a transition between Test::Builder and Non-Test::Builder -code. - -=item $bool = $frame->anointed - -True if the frame is a call from an annointed test package. - -=back - -=head1 BOOLEAN ATTRIBUTES - -B<Note> None of these are set automatically by the constructor or any other -calls. These get set by L<Test::Builder::Trace> when it scans the stack. It -will never be useful to check these on a frame object you created yourself. - -=over 4 - -=item $bool = $frame->level - -True if the frame is associated with C<$Test::Builder::Level>. - -=item $bool = $frame->report - -True if the frame has been chosen as the reporting frame. - -=back - -=head1 AUTHORS - -=over 4 - -=item Chad Granum E<lt>exodist@cpan.orgE<gt> - -=back - -=head1 COPYRIGHT - -Copyright 2014 by Chad Granum E<lt>exodist7@gmail.comE<gt> - -This program is free software; you can redistribute it and/or -modify it under the same terms as Perl itself. - -See F<http://www.perl.com/perl/misc/Artistic.html> - diff --git a/cpan/Test-Simple/lib/Test/Builder/Util.pm b/cpan/Test-Simple/lib/Test/Builder/Util.pm deleted file mode 100644 index 1a11387cc5..0000000000 --- a/cpan/Test-Simple/lib/Test/Builder/Util.pm +++ /dev/null @@ -1,450 +0,0 @@ -package Test::Builder::Util; -use strict; -use warnings; - -use Carp qw/croak/; -use Scalar::Util qw/reftype blessed/; -use Test::Builder::Threads; - -my $meta = {}; -sub TB_EXPORT_META { $meta }; - -exports(qw/ - import export exports accessor accessors delta deltas export_to transform - atomic_delta atomic_deltas try protect - package_sub is_tester is_provider find_builder -/); - -export(new => sub { - my $class = shift; - my %params = @_; - - my $self = bless {}, $class; - - $self->pre_init(\%params) if $self->can('pre_init'); - - my @attrs = keys %params; - @attrs = $self->init_order(@attrs) if @attrs && $self->can('init_order'); - - for my $attr (@attrs) { - croak "$class has no method named '$attr'" unless $self->can($attr); - $self->$attr($params{$attr}); - } - - $self->init(%params) if $self->can('init'); - - return $self; -}); - -sub import { - my $class = shift; - my $caller = caller; - - if (grep {$_ eq 'import'} @_) { - my $meta = {}; - no strict 'refs'; - *{"$caller\::TB_EXPORT_META"} = sub { $meta }; - } - - $class->export_to($caller, @_) if @_; - - 1; -} - -sub export_to { - my $from = shift; - my ($to, @subs) = @_; - - croak "package '$from' is not a TB exporter" - unless is_exporter($from); - - croak "No destination package specified." - unless $to; - - return unless @subs; - - my $meta = $from->TB_EXPORT_META; - - for my $name (@subs) { - my $ref = $meta->{$name} || croak "$from does not export '$name'"; - no strict 'refs'; - *{"$to\::$name"} = $ref; - } - - 1; -} - -sub exports { - my $caller = caller; - - my $meta = is_exporter($caller) - || croak "$caller is not an exporter!"; - - for my $name (@_) { - my $ref = $caller->can($name); - croak "$caller has no sub named '$name'" unless $ref; - - croak "Already exporting '$name'" - if $meta->{$name}; - - $meta->{$name} = $ref; - } -} - -sub export { - my ($name, $ref) = @_; - my $caller = caller; - - croak "The first argument to export() must be a symbol name" - unless $name; - - $ref ||= $caller->can($name); - croak "$caller has no sub named '$name', and no ref was provided" - unless $ref; - - # Allow any type of ref, people can export scalars, hashes, etc. - croak "The second argument to export() must be a reference" - unless ref $ref; - - my $meta = is_exporter($caller) - || croak "$caller is not an exporter!"; - - croak "Already exporting '$name'" - if $meta->{$name}; - - $meta->{$name} = $ref; -} - -sub accessor { - my ($name, $default) = @_; - my $caller = caller; - - croak "The second argument to accessor() must be a coderef, not '$default'" - if $default && !(ref $default && reftype $default eq 'CODE'); - - _accessor($caller, $name, $default); -} - -sub accessors { - my ($name) = @_; - my $caller = caller; - - _accessor($caller, "$_") for @_; -} - -sub _accessor { - my ($caller, $attr, $default) = @_; - my $name = lc $attr; - - my $sub; - if ($default) { - $sub = sub { - my $self = shift; - - $self->{$attr} = $self->$default unless exists $self->{$attr}; - ($self->{$attr}) = @_ if @_; - - return $self->{$attr}; - }; - } - else { - $sub = sub { - my $self = shift; - ($self->{$attr}) = @_ if @_; - return $self->{$attr}; - }; - } - - no strict 'refs'; - *{"$caller\::$name"} = $sub; -} - -sub transform { - my $name = shift; - my $code = pop; - my ($attr) = @_; - my $caller = caller; - - $attr ||= $name; - - croak "name is mandatory" unless $name; - croak "takes a minimum of 2 arguments" unless $code; - - my $sub = sub { - my $self = shift; - croak "$name\() must be called on a blessed instance, got: $self" - unless blessed $self; - - $self->{$attr} = $self->$code(@_) if @_ and defined $_[0]; - - return $self->{$attr}; - }; - - no strict 'refs'; - *{"$caller\::$name"} = $sub; -} - -sub delta { - my ($name, $initial) = @_; - my $caller = caller; - - _delta($caller, $name, $initial || 0, 0); -} - -sub deltas { - my $caller = caller; - _delta($caller, "$_", 0, 0) for @_; -} - -sub atomic_delta { - my ($name, $initial) = @_; - my $caller = caller; - - _delta($caller, $name, $initial || 0, 1); -} - -sub atomic_deltas { - my $caller = caller; - _delta($caller, "$_", 0, 1) for @_; -} - -sub _delta { - my ($caller, $attr, $initial, $atomic) = @_; - my $name = lc $attr; - - my $sub = sub { - my $self = shift; - - croak "$name\() must be called on a blessed instance, got: $self" - unless blessed $self; - - lock $self->{$attr} if $atomic; - $self->{$attr} = $initial unless defined $self->{$attr}; - $self->{$attr} += $_[0] if @_; - - return $self->{$attr}; - }; - - no strict 'refs'; - *{"$caller\::$name"} = $sub; -} - -sub protect(&) { - my $code = shift; - - my ($ok, $error); - { - local $@; - local $!; - $ok = eval { $code->(); 1 } || 0; - $error = $@ || "Error was squashed!\n"; - } - die $error unless $ok; - return $ok; -} - -sub try(&) { - my $code = shift; - my $error; - my $ok; - - { - local $@; - local $!; - local $SIG{__DIE__}; - - $ok = eval { $code->(); 1 } || 0; - unless($ok) { - $error = $@ || "Error was squashed!\n"; - } - } - - return wantarray ? ($ok, $error) : $ok; -} - -sub package_sub { - my ($pkg, $sub) = @_; - no warnings 'once'; - - my $globref = do { - no strict 'refs'; - \*{"$pkg\::$sub"}; - }; - - return *$globref{CODE} || undef; -} - -sub is_exporter { - my $pkg = shift; - return unless package_sub($pkg, 'TB_EXPORT_META'); - return $pkg->TB_EXPORT_META; -} - -sub is_tester { - my $pkg = shift; - return unless package_sub($pkg, 'TB_TESTER_META'); - return $pkg->TB_TESTER_META; -} - -sub is_provider { - my $pkg = shift; - return unless package_sub($pkg, 'TB_PROVIDER_META'); - return $pkg->TB_PROVIDER_META; -} - -sub find_builder { - my $level = 1; - while (my @call = caller($level++)) { - next unless package_sub($call[0], 'TB_INSTANCE'); - return $call[0]->TB_INSTANCE; - } - - return Test::Builder->new; -} - -1; - -__END__ - -=head1 NAME - -Test::Builder::Util - Internal tools for Test::Builder and friends - -=head1 DESCRIPTION - -Tools for generating accessors and other object bits and pieces. - -=head1 SYNOPSYS - - #Imports a sub named 'new' and all the other tools. - use Test::Builder::Util; - - # Define some exports - export 'foo'; # Export the 'foo' sub - export bar => sub { ... }; # export an anon sub named bar - - # Generate some accessors - accessors qw/yabba dabba doo/; - -=head1 EXPORTS - -=over 4 - -=item $class->new(...) - -Generic constructor method, can be used in almost any package. Takes key/value -pairs as arguments. Key is assumed to be the name of a method or accessor. The -method named for the key is called with the value as an argument. You can also -define an 'init' method which this will call for you on the newly created -object. - -=item $class->import(@list) - -Importing this method lets you define exports. - -=item $class->export_to($dest_package, @names) - -Export @names to the package $dest_package - -=item exports(@names) - -Export the subs named in @names. - -=item export($name) - -=item export($name => sub { ... }) - -Export a sub named $name. Optionally a coderef may be used. - -=item accessor($name) - -=item accessor($name, sub { return $DEFAULT }) - -Define an accessor. A default value can be specified via a coderef. - -=item accessors(qw/sub1 sub2 .../) - -Define several read/write accessors at once. - -=item transform($name, sub { ($self, @args) = @_; ... }) - -=item transform($name, $attr, sub { ($self, @args) = @_; ... }) - -Define a read/write accessor that transforms whatever you assign to it via the -given coderef. $attr is optional and defaults to $name. $attr is the key inside -the blessed object hash used to store the field. - -=item delta($name) - -=item delta($name => $default) - -=item deltas(qw/name1 name2 .../) - -=item atomic_delta($name) - -=item atomic_delta($name => $default) - -=item atomic_deltas(qw/name1 name2 .../) - -A delta accessor is an accessor that adds the numeric argument to the current -value. Optionally a default value can be specified, otherwise 0 is used. - -The atomic variations are thread-safe. - -=item $success = try { ... } - -=item ($success, $error) = try { ... } - -Eval the codeblock, return success or failure, and optionally the error -message. This code protects $@ and $!, they will be restored by the end of the -run. This code also temporarily blocks $SIG{DIE} handlers. - -=item protect { ... } - -Similar to try, except that it does not catch exceptions. The idea here is to -protect $@ and $! from changes. $@ and $! will be restored to whatever they -were before the run so long as it is successful. If the run fails $! will still -be restored, but $@ will contain the exception being thrown. - -=item $coderef = package_sub($package, $subname) - -Find a sub in a package, returns the coderef if it is present, otherwise it -returns undef. This is similar to C<< $package->can($subname) >> except that it -ignores inheritance. - -=item $meta = is_tester($package) - -Check if a package is a tester, return the metadata if it is. - -=item $meta = is_provider($package) - -Check if a package is a provider, return the metadata if it is. - -=item $TB = find_builder() - -Find the Test::Builder instance to use. - -=back - -=head1 AUTHORS - -=over 4 - -=item Chad Granum E<lt>exodist@cpan.orgE<gt> - -=back - -=head1 SOURCE - -The source code repository for Test::More can be found at -F<http://github.com/Test-More/test-more/>. - -=head1 COPYRIGHT - -Copyright 2014 Chad Granum E<lt>exodist7@gmail.comE<gt>. - -This program is free software; you can redistribute it and/or -modify it under the same terms as Perl itself. - -See F<http://www.perl.com/perl/misc/Artistic.html> - diff --git a/cpan/Test-Simple/lib/Test/FAQ.pod b/cpan/Test-Simple/lib/Test/FAQ.pod deleted file mode 100644 index a1bd641038..0000000000 --- a/cpan/Test-Simple/lib/Test/FAQ.pod +++ /dev/null @@ -1,379 +0,0 @@ -=pod - -=head1 NAME - -Test::FAQ - Frequently Asked Questions about testing with Perl - -=head1 DESCRIPTION - -Frequently Asked Questions about testing in general and specific -issues with Perl. - -=head2 Is there any tutorial on testing? - -L<Test::Tutorial> - -=head2 Are there any modules for testing? - -A whole bunch. Start with L<Test::Simple> then move onto Test::More. - -Then go onto L<http://search.cpan.org> and search for "Test". - -Also check out L<Fennec>. - -=head2 Are there any modules for testing web pages/CGI programs? - -L<Test::WWW::Mechanize>, L<Test::WWW::Selenium> - -=head2 Are there any modules for testing external programs? - -L<Test::Cmd> - -=head2 Can you do xUnit/JUnit style testing in Perl? - -Yes, L<Test::Class> allows you to write test methods while continuing to -use all the usual CPAN testing modules. It is the best and most -perlish way to do xUnit style testing. - -L<Test::Unit> is a more direct port of XUnit to Perl, but it does not use -the Perl conventions and does not play well with other CPAN testing -modules. As of this writing, it is abandoned. B<Do not use>. - -The L<Test::Inline> (aka L<Pod::Tests>) is worth mentioning as it allows you to -put tests into the POD in the same file as the code. - - -=head2 How do I test my module is backwards/forwards compatible? - -First, install a bunch of perls of commonly used versions. At the -moment, you could try these - - 5.7.2 - 5.6.1 - 5.005_03 - 5.004_05 - -if you're feeling brave, you might want to have on hand these - - bleadperl - 5.6.0 - 5.004_04 - 5.004 - -going back beyond 5.003 is probably beyond the call of duty. - -You can then add something like this to your F<Makefile.PL>. It -overrides the L<ExtUtils::MakeMaker> C<test_via_harness()> method to run the tests -against several different versions of Perl. - - # If PERL_TEST_ALL is set, run "make test" against - # other perls as well as the current perl. - { - package MY; - - sub test_via_harness { - my($self, $orig_perl, $tests) = @_; - - # names of your other perl binaries. - my @other_perls = qw(perl5.004_05 perl5.005_03 perl5.7.2); - - my @perls = ($orig_perl); - push @perls, @other_perls if $ENV{PERL_TEST_ALL}; - - my $out; - foreach my $perl (@perls) { - $out .= $self->SUPER::test_via_harness($perl, $tests); - } - - return $out; - } - } - -and re-run your F<Makefile.PL> with the C<PERL_TEST_ALL> environment -variable set - - PERL_TEST_ALL=1 perl Makefile.PL - -now C<make test> will run against each of your other perls. - - -=head2 If I'm testing Foo::Bar, where do I put tests for Foo::Bar::Baz? - -=head2 How do I know when my tests are good enough? - -A: Use tools for measuring the code coverage of your tests, e.g. how many of -your source code lines/subs/expressions/paths are executed (aka covered) by -the test suite. The more, the better, of course, although you may not -be able achieve 100%. If your testsuite covers under 100%, then -the rest of your code is, basically, untested. Which means it may work in -surprising ways (e.g. doesn't do things like they are intended or -documented), have bugs (e.g. return wrong results) or it may not work at -all. - -=head2 How do I measure the coverage of my test suite? - -L<Devel::Cover> - -=head2 How do I get tests to run in a certain order? - -Tests run in alphabetical order, so simply name your test files in the order -you want them to run. Numbering your test files works, too. - - t/00_compile.t - t/01_config.t - t/zz_teardown.t - -0 runs first, z runs last. - -To achieve a specific order, try L<Test::Manifest>. - -Typically you do B<not> want your tests to require being run in a -certain order, but it can be useful to do a compile check first or to -run the tests on a very basic module before everything else. This -gives you early information if a basic module fails which will bring -everything else down. - -Another use is if you have a suite wide setup/teardown, such as -creating and delete a large test database, which may be too -expensive to do for every test. - -We recommend B<against> numbering every test file. For most files -this ordering will be arbitrary and the leading number obscures the -real name of the file. See L<What should I name my test files?> for -more information. - - -=head2 What should I name my tests? - -=head2 What should I name my test files? - -A test filename serves three purposes: - -Most importantly, it serves to identify what is being tested. Each -test file should test a clear piece of functionality. This could be -at single class, a single method, even a single bug. - -The order in which tests are run is usually dictated by the filename. -See L<How do I get tests to run in a certain order?> for details. - -Finally, the grouping of tests into common bits of functionality can -be achieved by directory and filenames. For example, all the tests -for L<Test::Builder> are in the F<t/Builder/> directory. - -As an example, F<t/Builder/reset.t> contains the tests for -C<< Test::Builder->reset >>. F<t/00compile.t> checks that everything -compiles, and it will run first. F<t/dont_overwrite_die_handler.t> -checks that we don't overwrite the C<< $SIG{__DIE__} >> handler. - - -=head2 How do I deal with tests that sometimes pass and sometimes fail? - -=head2 How do I test with a database/network/server that the user may or may not have? - -=head2 What's a good way to test lists? - -C<is_deeply()> from L<Test::More> as well as L<Test::Deep>. - -=head2 Is there such a thing as untestable code? - -There's always compile/export checks. - -Code must be written with testability in mind. Separation of form and -functionality. - -=head2 What do I do when I can't make the code do the same thing twice? - -Force it to do the same thing twice. - -Even a random number generator can be tested. - -=head2 How do I test a GUI? - -=head2 How do I test an image generator? - -=head2 How do I test that my code handles failures gracefully? - -=head2 How do I check the right warnings are issued? - -L<Test::Warn> - -=head2 How do I test code that prints? - -L<Test::Output> - -=head2 I want to test that my code dies when I do X - -L<Test::Exception> - -=head2 I want to print out more diagnostic info on failure. - -C<ok(...) || diag "...";> - -=head2 How can I simulate failures to make sure that my code does the Right Thing in the face of them? - - -=head2 Why use an ok() function? - -On Tue, Aug 28, 2001 at 02:12:46PM +0100, Robin Houston wrote: -> Michael Schwern wrote: -> > Ah HA! I've been wondering why nobody ever thinks to write a simple -> > ok() function for their tests! perlhack has bad testing advice. -> -> Could you explain the advantage of having a "simple ok() function"? - -Because writing: - - print "not " unless some thing worked; - print "ok $test\n"; $test++; - -gets rapidly annoying. This is why we made up subroutines in the -first place. It also looks like hell and obscures the real purpose. - -Besides, that will cause problems on VMS. - - -> As somebody who has spent many painful hours debugging test failures, -> I'm intimately familiar with the _disadvantages_. When you run the -> test, you know that "test 113 failed". That's all you know, in general. - -Second advantage is you can easily upgrade the C<ok()> function to fix -this, either by slapping this line in: - - printf "# Failed test at line %d\n", (caller)[2]; - -or simply junking the whole thing and switching to L<Test::Simple> or -L<Test::More>, which does all sorts of nice diagnostics-on-failure for -you. Its C<ok()> function is backwards compatible with the above. - -There's some issues with using L<Test::Simple> to test really basic Perl -functionality, you have to choose on a per test basis. Since -L<Test::Simple> doesn't use C<pack()> it's safe for F<t/op/pack.t> to use -L<Test::Simple>. I just didn't want to make the perlhack patching -example too complicated. - - -=head2 Dummy Mode - -> One compromise would be to use a test-generating script, which allows -> the tests to be structured simply and _generates_ the actual test -> code. One could then grep the generated test script to locate the -> failing code. - -This is a very interesting, and very common, response to the problem. -I'm going to make some observations about reactions to testing, -they're not specific to you. - -If you've ever read the Bastard Operator From Hell series, you'll -recall the Dummy Mode. - - The words "power surging" and "drivers" have got her. People hear - words like that and go into Dummy Mode and do ANYTHING you say. I - could tell her to run naked across campus with a powercord rammed - up her backside and she'd probably do it... Hmmm... - -There seems to be a Dummy Mode WRT testing. An otherwise competent -person goes to write a test and they suddenly forget all basic -programming practice. - - -The reasons for using an C<ok()> function above are the same reasons to -use functions in general, we should all know them. We'd laugh our -heads off at code that repeated as much as your average test does. -These are newbie mistakes. - -And the normal 'can do' flair seems to disappear. I know Robin. I -*know* that in any other situation he would have come up with the -C<caller()> trick in about 15 seconds flat. Instead weird, elaborate, -inelegant hacks are thought up to solve the simplest problems. - - -I guess there are certain programming idioms that are foreign enough -to throw your brain into reverse if you're not ready for them. Like -trying to think in Lisp, for example. Or being presented with OO for -the first time. I guess writing test is one of those. - - -=head2 How do I use Test::More without depending on it? - -Install L<Test::More> into F<t/lib> under your source directory. Then in your tests -say C<use lib 't/lib'>. - -=head2 How do I deal with threads and forking? - - use Test::More qw/enable_forking/; - -or - - use Test::More qw/modern/; - -=head2 Why do I need more than ok? - -Since every test can be reduced to checking if a statement is true, -C<ok()> can test everything. But C<ok()> doesn't tell you why the test -failed. For that you need to tell the test more... which is why -you need L<Test::More>. - - ok $pirate->name eq "Roberts", "person's name"; - - not ok 1 - person's name - # Failed test at pirates.t line 23. - -If the above fails, you don't know what C<< $person->name >> returned. -You have to go in and add a C<diag> call. This is time consuming. If -it's a heisenbug, it might not fail again! If it's a user reporting a -test failure, they might not be bothered to hack the tests to give you -more information. - - is $person->name, "Roberts", "person's name"; - - not ok 1 - person's name - # Failed test at pirates.t line 23. - # got: 'Wesley' - # expected: 'Roberts' - -Using C<is> from L<Test::More> you now know what value you got and -what value you expected. - -The most useful functions in L<Test::More> are C<is()>, C<like()> and C<is_deeply()>. - - -=head2 What's wrong with C<print $test ? "ok" : "not ok">? - -=head2 How do I check for an infinite loop? - -On Mon, Mar 18, 2002 at 03:57:55AM -0500, Mark-Jason Dominus wrote: -> -> Michael The Schwern <schwern@pobox.com> says: -> > Use alarm and skip the test if $Config{d_alarm} is false (see -> > t/op/alarm.t for an example). If you think the infinite loop is due -> > to a programming glitch, as opposed to a cross-platform issue, this -> > will be enough. -> -> Thanks very much! -> - -=head2 How can I check that flock works? - -=head2 How do I use the comparison functions of a testing module without it being a test? - -Any testing function based on L<Test::Builder>, most are, can be quieted so it does -not do any testing. It simply returns true or false. Use the following code... - - use Test::More; # or any testing module - - use Test::Builder; - use File::Spec; - - # Get the internal Test::Builder object - my $tb = Test::Builder->new; - - $tb->plan("no_plan"); - - # Keep Test::Builder from displaying anything - $tb->no_diag(1); - $tb->no_ending(1); - $tb->no_header(1); - $tb->output( File::Spec->devnull ); - - # Now you can use the testing function. - print is_deeply( "foo", "bar" ) ? "Yes" : "No"; diff --git a/cpan/Test-Simple/lib/Test/More.pm b/cpan/Test-Simple/lib/Test/More.pm index 83f1be0c4c..217ad59ac5 100644 --- a/cpan/Test-Simple/lib/Test/More.pm +++ b/cpan/Test-Simple/lib/Test/More.pm @@ -1,18 +1,15 @@ package Test::More; -use 5.008001; +use 5.006; use strict; use warnings; -use Test::Builder::Util qw/is_tester try/; -use Encode(); - #---- perlcritic exemptions. ----# # We use a lot of subroutine prototypes ## no critic (Subroutines::ProhibitSubroutinePrototypes) -# Can't use Carp because it might cause C<use_ok()> to accidentally succeed +# Can't use Carp because it might cause use_ok() to accidentally succeed # even though the module being used forgot to use Carp. Yes, this # actually happened. sub _carp { @@ -20,834 +17,38 @@ sub _carp { return warn @_, " at $file line $line\n"; } -our $VERSION = '1.301001_040'; +our $VERSION = '1.001003'; $VERSION = eval $VERSION; ## no critic (BuiltinFunctions::ProhibitStringyEval) -our $TODO; -use Test::Builder::Provider; -*EXPORT = TB_PROVIDER_META()->{export}; - -provides qw( - ok use_ok require_ok +use Test::Builder::Module 0.99; +our @ISA = qw(Test::Builder::Module); +our @EXPORT = qw(ok use_ok require_ok is isnt like unlike is_deeply cmp_ok - skip todo_skip + skip todo todo_skip pass fail eq_array eq_hash eq_set + $TODO plan done_testing can_ok isa_ok new_ok diag note explain - BAIL_OUT subtest - nest - tap_encoding + BAIL_OUT ); -provide TODO => \$TODO; - -give cull => sub { - my $fork = Test::More->builder->stream->fork || return 0; - $fork->cull; -}; - -give helpers => sub { - my $caller = caller; - - # These both get cached, so they will be quick if called multiple times. - my $meta = Test::Builder::Provider->make_provider($caller); - my $provide = Test::Builder::Provider->_build_provide($caller, $meta); - - $provide->($_) for @_; -}; - -sub plan { - my $tb = Test::More->builder; - - return $tb->plan(@_); -} - -sub modern_default { 0 } - -sub before_import { - my $class = shift; - my ($list, $dest) = @_; - - _set_tap_encoding($dest, 'legacy'); - - my $encoding_set = 0; - my $other = []; - my $idx = 0; - my $modern = 0; - while ($idx <= $#{$list}) { - my $item = $list->[$idx++]; - next unless $item; - - if ($item eq 'no_diag') { - $class->builder->no_diag(1); - } - elsif ($item eq 'tests' || $item eq 'skip_all') { - $class->builder->plan($item => $list->[$idx++]); - return 0 if $item eq 'skip_all'; - } - elsif ($item eq 'no_plan') { - $class->builder->plan($item); - } - elsif ($item eq 'import') { - push @$other => @{$list->[$idx++]}; - } - elsif ($item eq 'enable_forking') { - builder->stream->use_fork; - } - elsif ($item eq 'modern') { - modernize($dest) unless $modern++; - } - elsif ($item eq 'utf8') { - modernize($dest) unless $modern++; - $encoding_set++; - _set_tap_encoding($dest, 'utf8'); - } - elsif ($item eq 'encoding') { - modernize($dest) unless $modern++; - $encoding_set++; - my $encoding = $list->[$idx++]; - _set_tap_encoding($dest, $encoding); - } - else { - Carp::carp("Unknown option: $item"); - } - } - - @$list = @$other; - - Test::Builder::Stream->shared->use_lresults unless $modern; - - return 1; -} - -sub _set_tap_encoding { - my ($test, $encoding, $run) = @_; - my $meta = is_tester($test); - require Carp; - Carp::croak "package '$test' is not a tester!" unless $meta; - - if ($encoding and $encoding ne 'legacy') { - Carp::croak "encoding '$encoding' is not valid, or not available" - unless Encode::find_encoding($encoding); - } - - if (defined $run) { - my $old = $meta->{encoding}; - $meta->{encoding} = $encoding; - - my ($ok, $error) = try { $run->() }; - - $meta->{encoding} = $old; - die $error unless $ok; - } - else { - $meta->{encoding} = $encoding if defined $encoding; - } - - return $meta->{encoding}; -} - -sub tap_encoding { - my $caller = caller; - _set_tap_encoding($caller, @_); -} - -sub done_testing { - my $tb = Test::More->builder; - $tb->done_testing(@_); -} - -sub ok ($;$) { - my( $test, $name ) = @_; - my $tb = Test::More->builder; - - return $tb->ok( $test, $name ); -} - -sub is ($$;$) { - my $tb = Test::More->builder; - - return $tb->is_eq(@_); -} - -sub isnt ($$;$) { - my $tb = Test::More->builder; - - return $tb->isnt_eq(@_); -} - -*isn't = \&isnt; -# ' to unconfuse syntax higlighters - -sub like ($$;$) { - my $tb = Test::More->builder; - - return $tb->like(@_); -} - -sub unlike ($$;$) { - my $tb = Test::More->builder; - - return $tb->unlike(@_); -} - -sub cmp_ok($$$;$) { - my $tb = Test::More->builder; - - return $tb->cmp_ok(@_); -} - -sub can_ok ($@) { - my( $proto, @methods ) = @_; - my $class = ref $proto || $proto; - my $tb = Test::More->builder; - - unless($class) { - my $ok = $tb->ok( 0, "->can(...)" ); - $tb->diag(' can_ok() called with empty class or reference'); - return $ok; - } - - unless(@methods) { - my $ok = $tb->ok( 0, "$class->can(...)" ); - $tb->diag(' can_ok() called with no methods'); - return $ok; - } - - my @nok = (); - foreach my $method (@methods) { - $tb->_try( sub { $proto->can($method) } ) or push @nok, $method; - } - - my $name = (@methods == 1) ? "$class->can('$methods[0]')" : - "$class->can(...)" ; - - my $ok = $tb->ok( !@nok, $name ); - - $tb->diag(" $class->can('$_') failed") for @nok; - - return $ok; -} - -sub isa_ok ($$;$) { - my( $thing, $class, $thing_name ) = @_; - my $tb = Test::More->builder; - - my $whatami; - if( !defined $thing ) { - $whatami = 'undef'; - } - elsif( ref $thing ) { - $whatami = 'reference'; - - local($@,$!); - require Scalar::Util; - if( Scalar::Util::blessed($thing) ) { - $whatami = 'object'; - } - } - else { - $whatami = 'class'; - } - - # We can't use UNIVERSAL::isa because we want to honor isa() overrides - my( $rslt, $error ) = $tb->_try( sub { $thing->isa($class) } ); - - if($error) { - die <<WHOA unless $error =~ /^Can't (locate|call) method "isa"/; -WHOA! I tried to call ->isa on your $whatami and got some weird error. -Here's the error. -$error -WHOA - } - - # Special case for isa_ok( [], "ARRAY" ) and like - if( $whatami eq 'reference' ) { - $rslt = UNIVERSAL::isa($thing, $class); - } - - my($diag, $name); - if( defined $thing_name ) { - $name = "'$thing_name' isa '$class'"; - $diag = defined $thing ? "'$thing_name' isn't a '$class'" : "'$thing_name' isn't defined"; - } - elsif( $whatami eq 'object' ) { - my $my_class = ref $thing; - $thing_name = qq[An object of class '$my_class']; - $name = "$thing_name isa '$class'"; - $diag = "The object of class '$my_class' isn't a '$class'"; - } - elsif( $whatami eq 'reference' ) { - my $type = ref $thing; - $thing_name = qq[A reference of type '$type']; - $name = "$thing_name isa '$class'"; - $diag = "The reference of type '$type' isn't a '$class'"; - } - elsif( $whatami eq 'undef' ) { - $thing_name = 'undef'; - $name = "$thing_name isa '$class'"; - $diag = "$thing_name isn't defined"; - } - elsif( $whatami eq 'class' ) { - $thing_name = qq[The class (or class-like) '$thing']; - $name = "$thing_name isa '$class'"; - $diag = "$thing_name isn't a '$class'"; - } - else { - die; - } - - my $ok; - if($rslt) { - $ok = $tb->ok( 1, $name ); - } - else { - $ok = $tb->ok( 0, $name ); - $tb->diag(" $diag\n"); - } - - return $ok; -} - -sub new_ok { - my $tb = Test::More->builder; - $tb->croak("new_ok() must be given at least a class") unless @_; - - my( $class, $args, $object_name ) = @_; - - $args ||= []; - - my $obj; - my( $success, $error ) = $tb->_try( sub { $obj = $class->new(@$args); 1 } ); - if($success) { - isa_ok $obj, $class, $object_name; - } - else { - $class = 'undef' if !defined $class; - $tb->ok( 0, "$class->new() died" ); - $tb->diag(" Error was: $error"); - } - - return $obj; -} - -sub subtest { - my ($name, $subtests) = @_; - - my $tb = Test::More->builder; - return $tb->subtest(@_); -} - -sub pass (;$) { - my $tb = Test::More->builder; - - return $tb->ok( 1, @_ ); -} - -sub fail (;$) { - my $tb = Test::More->builder; - - return $tb->ok( 0, @_ ); -} - -sub require_ok ($) { - my($module) = shift; - my $tb = Test::More->builder; - - my $pack = caller; - - # Try to determine if we've been given a module name or file. - # Module names must be barewords, files not. - $module = qq['$module'] unless _is_module_name($module); - - my $code = <<REQUIRE; -package $pack; -require $module; -1; -REQUIRE - - my( $eval_result, $eval_error ) = _eval($code); - my $ok = $tb->ok( $eval_result, "require $module;" ); - - unless($ok) { - chomp $eval_error; - $tb->diag(<<DIAGNOSTIC); - Tried to require '$module'. - Error: $eval_error -DIAGNOSTIC - - } - - return $ok; -} - -sub _is_module_name { - my $module = shift; - - # Module names start with a letter. - # End with an alphanumeric. - # The rest is an alphanumeric or :: - $module =~ s/\b::\b//g; - - return $module =~ /^[a-zA-Z]\w*$/ ? 1 : 0; -} - -sub use_ok ($;@) { - my( $module, @imports ) = @_; - @imports = () unless @imports; - my $tb = Test::More->builder; - - my( $pack, $filename, $line ) = caller; - $filename =~ y/\n\r/_/; # so it doesn't run off the "#line $line $f" line - - my $code; - if( @imports == 1 and $imports[0] =~ /^\d+(?:\.\d+)?$/ ) { - # probably a version check. Perl needs to see the bare number - # for it to work with non-Exporter based modules. - $code = <<USE; -package $pack; - -#line $line $filename -use $module $imports[0]; -1; -USE - } - else { - $code = <<USE; -package $pack; - -#line $line $filename -use $module \@{\$args[0]}; -1; -USE - } - - my( $eval_result, $eval_error ) = _eval( $code, \@imports ); - my $ok = $tb->ok( $eval_result, "use $module;" ); - - unless($ok) { - chomp $eval_error; - $@ =~ s{^BEGIN failed--compilation aborted at .*$} - {BEGIN failed--compilation aborted at $filename line $line.}m; - $tb->diag(<<DIAGNOSTIC); - Tried to use '$module'. - Error: $eval_error -DIAGNOSTIC - - } - - return $ok; -} - -sub _eval { - my( $code, @args ) = @_; - - # Work around oddities surrounding resetting of $@ by immediately - # storing it. - my( $sigdie, $eval_result, $eval_error ); - { - local( $@, $!, $SIG{__DIE__} ); # isolate eval - $eval_result = eval $code; ## no critic (BuiltinFunctions::ProhibitStringyEval) - $eval_error = $@; - $sigdie = $SIG{__DIE__} || undef; - } - # make sure that $code got a chance to set $SIG{__DIE__} - $SIG{__DIE__} = $sigdie if defined $sigdie; - - return( $eval_result, $eval_error ); -} - -our( @Data_Stack, %Refs_Seen ); -my $DNE = bless [], 'Does::Not::Exist'; - -sub _dne { - return ref $_[0] eq ref $DNE; -} - -## no critic (Subroutines::RequireArgUnpacking) -sub is_deeply { - my $tb = Test::More->builder; - - unless( @_ == 2 or @_ == 3 ) { - my $msg = <<'WARNING'; -is_deeply() takes two or three args, you gave %d. -This usually means you passed an array or hash instead -of a reference to it -WARNING - chop $msg; # clip off newline so carp() will put in line/file - - _carp sprintf $msg, scalar @_; - - return $tb->ok(0); - } - - my( $got, $expected, $name ) = @_; - - $tb->_unoverload_str( \$expected, \$got ); - - my $ok; - if( !ref $got and !ref $expected ) { # neither is a reference - $ok = $tb->is_eq( $got, $expected, $name ); - } - elsif( !ref $got xor !ref $expected ) { # one's a reference, one isn't - $ok = $tb->ok( 0, $name ); - $tb->diag( _format_stack({ vals => [ $got, $expected ] }) ); - } - else { # both references - local @Data_Stack = (); - if( _deep_check( $got, $expected ) ) { - $ok = $tb->ok( 1, $name ); - } - else { - $ok = $tb->ok( 0, $name ); - $tb->diag( _format_stack(@Data_Stack) ); - } - } - - return $ok; -} - -sub _format_stack { - my(@Stack) = @_; - - my $var = '$FOO'; - my $did_arrow = 0; - foreach my $entry (@Stack) { - my $type = $entry->{type} || ''; - my $idx = $entry->{'idx'}; - if( $type eq 'HASH' ) { - $var .= "->" unless $did_arrow++; - $var .= "{$idx}"; - } - elsif( $type eq 'ARRAY' ) { - $var .= "->" unless $did_arrow++; - $var .= "[$idx]"; - } - elsif( $type eq 'REF' ) { - $var = "\${$var}"; - } - } - - my @vals = @{ $Stack[-1]{vals} }[ 0, 1 ]; - my @vars = (); - ( $vars[0] = $var ) =~ s/\$FOO/ \$got/; - ( $vars[1] = $var ) =~ s/\$FOO/\$expected/; - - my $out = "Structures begin differing at:\n"; - foreach my $idx ( 0 .. $#vals ) { - my $val = $vals[$idx]; - $vals[$idx] - = !defined $val ? 'undef' - : _dne($val) ? "Does not exist" - : ref $val ? "$val" - : "'$val'"; - } - - $out .= "$vars[0] = $vals[0]\n"; - $out .= "$vars[1] = $vals[1]\n"; - - $out =~ s/^/ /msg; - return $out; -} - -sub _type { - my $thing = shift; - - return '' if !ref $thing; - - for my $type (qw(Regexp ARRAY HASH REF SCALAR GLOB CODE)) { - return $type if UNIVERSAL::isa( $thing, $type ); - } - - return ''; -} - -sub diag { - return Test::More->builder->diag(@_); -} - -sub note { - return Test::More->builder->note(@_); -} - -sub explain { - return Test::More->builder->explain(@_); -} - -## no critic (Subroutines::RequireFinalReturn) -sub skip { - my( $why, $how_many ) = @_; - my $tb = Test::More->builder; - - unless( defined $how_many ) { - # $how_many can only be avoided when no_plan is in use. - _carp "skip() needs to know \$how_many tests are in the block" - unless $tb->has_plan eq 'no_plan'; - $how_many = 1; - } - - if( defined $how_many and $how_many =~ /\D/ ) { - _carp - "skip() was passed a non-numeric number of tests. Did you get the arguments backwards?"; - $how_many = 1; - } - - for( 1 .. $how_many ) { - $tb->skip($why); - } - - no warnings 'exiting'; - last SKIP; -} - -sub todo_skip { - my( $why, $how_many ) = @_; - my $tb = Test::More->builder; - - unless( defined $how_many ) { - # $how_many can only be avoided when no_plan is in use. - _carp "todo_skip() needs to know \$how_many tests are in the block" - unless $tb->has_plan eq 'no_plan'; - $how_many = 1; - } - - for( 1 .. $how_many ) { - $tb->todo_skip($why); - } - - no warnings 'exiting'; - last TODO; -} - -sub BAIL_OUT { - my $reason = shift; - my $tb = Test::More->builder; - - $tb->BAIL_OUT($reason); -} - -#'# -sub eq_array { - local @Data_Stack = (); - _deep_check(@_); -} - -sub _eq_array { - my( $a1, $a2 ) = @_; - - if( grep _type($_) ne 'ARRAY', $a1, $a2 ) { - warn "eq_array passed a non-array ref"; - return 0; - } - - return 1 if $a1 eq $a2; - - my $ok = 1; - my $max = $#$a1 > $#$a2 ? $#$a1 : $#$a2; - for( 0 .. $max ) { - my $e1 = $_ > $#$a1 ? $DNE : $a1->[$_]; - my $e2 = $_ > $#$a2 ? $DNE : $a2->[$_]; - - next if _equal_nonrefs($e1, $e2); - - push @Data_Stack, { type => 'ARRAY', idx => $_, vals => [ $e1, $e2 ] }; - $ok = _deep_check( $e1, $e2 ); - pop @Data_Stack if $ok; - - last unless $ok; - } - - return $ok; -} - -sub _equal_nonrefs { - my( $e1, $e2 ) = @_; - - return if ref $e1 or ref $e2; - - if ( defined $e1 ) { - return 1 if defined $e2 and $e1 eq $e2; - } - else { - return 1 if !defined $e2; - } - - return; -} - -sub _deep_check { - my( $e1, $e2 ) = @_; - my $tb = Test::More->builder; - - my $ok = 0; - - # Effectively turn %Refs_Seen into a stack. This avoids picking up - # the same referenced used twice (such as [\$a, \$a]) to be considered - # circular. - local %Refs_Seen = %Refs_Seen; - - { - $tb->_unoverload_str( \$e1, \$e2 ); - - # Either they're both references or both not. - my $same_ref = !( !ref $e1 xor !ref $e2 ); - my $not_ref = ( !ref $e1 and !ref $e2 ); - - if( defined $e1 xor defined $e2 ) { - $ok = 0; - } - elsif( !defined $e1 and !defined $e2 ) { - # Shortcut if they're both undefined. - $ok = 1; - } - elsif( _dne($e1) xor _dne($e2) ) { - $ok = 0; - } - elsif( $same_ref and( $e1 eq $e2 ) ) { - $ok = 1; - } - elsif($not_ref) { - push @Data_Stack, { type => '', vals => [ $e1, $e2 ] }; - $ok = 0; - } - else { - if( $Refs_Seen{$e1} ) { - return $Refs_Seen{$e1} eq $e2; - } - else { - $Refs_Seen{$e1} = "$e2"; - } - - my $type = _type($e1); - $type = 'DIFFERENT' unless _type($e2) eq $type; - - if( $type eq 'DIFFERENT' ) { - push @Data_Stack, { type => $type, vals => [ $e1, $e2 ] }; - $ok = 0; - } - elsif( $type eq 'ARRAY' ) { - $ok = _eq_array( $e1, $e2 ); - } - elsif( $type eq 'HASH' ) { - $ok = _eq_hash( $e1, $e2 ); - } - elsif( $type eq 'REF' ) { - push @Data_Stack, { type => $type, vals => [ $e1, $e2 ] }; - $ok = _deep_check( $$e1, $$e2 ); - pop @Data_Stack if $ok; - } - elsif( $type eq 'SCALAR' ) { - push @Data_Stack, { type => 'REF', vals => [ $e1, $e2 ] }; - $ok = _deep_check( $$e1, $$e2 ); - pop @Data_Stack if $ok; - } - elsif($type) { - push @Data_Stack, { type => $type, vals => [ $e1, $e2 ] }; - $ok = 0; - } - else { - _whoa( 1, "No type in _deep_check" ); - } - } - } - - return $ok; -} - -sub _whoa { - my( $check, $desc ) = @_; - if($check) { - die <<"WHOA"; -WHOA! $desc -This should never happen! Please contact the author immediately! -WHOA - } -} - -sub eq_hash { - local @Data_Stack = (); - return _deep_check(@_); -} - -sub _eq_hash { - my( $a1, $a2 ) = @_; - - if( grep _type($_) ne 'HASH', $a1, $a2 ) { - warn "eq_hash passed a non-hash ref"; - return 0; - } - - return 1 if $a1 eq $a2; - - my $ok = 1; - my $bigger = keys %$a1 > keys %$a2 ? $a1 : $a2; - foreach my $k ( keys %$bigger ) { - my $e1 = exists $a1->{$k} ? $a1->{$k} : $DNE; - my $e2 = exists $a2->{$k} ? $a2->{$k} : $DNE; - - next if _equal_nonrefs($e1, $e2); - - push @Data_Stack, { type => 'HASH', idx => $k, vals => [ $e1, $e2 ] }; - $ok = _deep_check( $e1, $e2 ); - pop @Data_Stack if $ok; - - last unless $ok; - } - - return $ok; -} - -sub eq_set { - my( $a1, $a2 ) = @_; - return 0 unless @$a1 == @$a2; - - no warnings 'uninitialized'; - - # It really doesn't matter how we sort them, as long as both arrays are - # sorted with the same algorithm. - # - # Ensure that references are not accidentally treated the same as a - # string containing the reference. - # - # Have to inline the sort routine due to a threading/sort bug. - # See [rt.cpan.org 6782] - # - # I don't know how references would be sorted so we just don't sort - # them. This means eq_set doesn't really work with refs. - return eq_array( - [ grep( ref, @$a1 ), sort( grep( !ref, @$a1 ) ) ], - [ grep( ref, @$a2 ), sort( grep( !ref, @$a2 ) ) ], - ); -} - -1; - -__END__ - =head1 NAME Test::More - yet another framework for writing test scripts =head1 SYNOPSIS - use Test::More 'modern'; - # or - use Test::More; # see done_testing() - # or use Test::More tests => 23; # or use Test::More skip_all => $reason; # or + use Test::More; # see done_testing() - # Switch to utf8 for all TAP produced by THIS PACKAGE - tap_encoding 'utf8'; - - use ok 'Some::Module'; require_ok( 'Some::Module' ); # Various ways to say "ok" @@ -888,56 +89,9 @@ Test::More - yet another framework for writing test scripts BAIL_OUT($why); - helpers 'my_checker'; - sub my_checker { - ok(...); - ok(...); - } - - # Failures in the 'ok' calls above will report here instead of there. - my_checker(...); - my_checker(...); - my_checker(...); - - helpers 'my_check_wrapper'; - sub my_check_wrapper(&) { - my ($code) = @_; - ok( nest {$code->()}, "code ran" ); - } - - my_check_wrapper { - ok(...); # Failures report here - ok(...); # Failures report here - return $BOOL; - }; # Overall failure reported here - - done_testing; - # UNIMPLEMENTED!!! my @status = Test::More::status; -=head1 TEST COMPONENT MAP - - [Test Script] > [Test Tool] > [Test::Builder] > [Test::Bulder::Stream] > [Event Formatter] - ^ - You are here - -A test script uses a test tool such as L<Test::More>, which uses Test::Builder -to produce events. The events are sent to L<Test::Builder::Stream> which then -forwards them on to one or more formatters. The default formatter is -L<Test::Builder::Fromatter::TAP> which produces TAP output. - -=head1 NOTE ON DEPRECATIONS - -With version 1.301001 many old methods and practices have been deprecated. What -we mean when we say "deprecated" is that the practices or methods are not to be -used in any new code. Old code that uses them will still continue to work, -possibly forever, but new code should use the newer and better alternatives. - -In the future, if enough (read: pretty much everything) is updated and few if -any modules still use these old items, they will be removed completely. This is -not super likely to happen just because of the sheer number of modules that use -Test::More. =head1 DESCRIPTION @@ -990,7 +144,7 @@ but 'fail', you'd do: use Test::More tests => 23, import => ['!fail']; -Alternatively, you can use the C<plan()> function. Useful for when you +Alternatively, you can use the plan() function. Useful for when you have to calculate the number of tests. use Test::More; @@ -1006,139 +160,65 @@ or for deciding between running the tests at all: plan tests => 42; } -=over 4 - -=item B<done_testing> - - done_testing(); - done_testing($number_of_tests); +=cut -If you don't know how many tests you're going to run, you can issue -the plan when you're done running tests. - -$number_of_tests is the same as C<plan()>, it's the number of tests you -expected to run. You can omit this, in which case the number of tests -you ran doesn't matter, just the fact that your tests ran to -conclusion. - -This is safer than and replaces the "no_plan" plan. - -=back - -=head2 Other import options - -=over 4 +sub plan { + my $tb = Test::More->builder; -=item use Test::More 'enable_forking'; + return $tb->plan(@_); +} -Turn on forking support. This lets you fork and generate events from each -process. It is your job to call C<cull()> periodically in the original process -to collect the events from other processes. +# This implements "use Test::More 'no_diag'" but the behavior is +# deprecated. +sub import_extra { + my $class = shift; + my $list = shift; - use strict; - use warnings; - use Test::More tests => 2, qw/enable_forking/; + my @other = (); + my $idx = 0; + while( $idx <= $#{$list} ) { + my $item = $list->[$idx]; - ok(1, "Event in parent" ); + if( defined $item and $item eq 'no_diag' ) { + $class->builder->no_diag(1); + } + else { + push @other, $item; + } - if (my $pid = fork()) { - waitpid($pid, 0); - cull(); - } - else { - ok(1, "Event in child"); - exit 0; + $idx++; } -=item use Test::More 'modern'; - -enables forking, and issues warnings when using deprecated code. - -=item use Test::More 'utf8'; - -=item use Test::More encoding => 'utf8' - -These both work the same, they enable utf8 output in TAP. They also imply 'modern'. - -=item use Test::More encoding => ... + @$list = @other; -Switch TAP output to whatever encoding you want. - -B<Note>: This is effective only for the current package. Other packages can/may -select other encodings for their TAP output. For packages where none is -specified, the original STDOUT and STDERR settings are used, the results are -unpredictable. - -This implies the 'modern' flag. - -=back - -=head2 TAP Encoding + return; +} =over 4 -=item tap_encoding 'utf8'; - -=item tap_encoding 'YOUR_ENCODING'; - -=item tap_encoding 'xxx' => sub { ... }; - -The C<tap_encoding($encoding)> function will ensure that any B<FUTURE> TAP -output produced by I<This Package> will be output in the specified encoding. - -You may also provide a codeblock in which case the scope of the encoding change -will only apply to that codeblock. +=item B<done_testing> -B<Note>: This is effective only for the current package. Other packages can/may -select other encodings for their TAP output. For packages where none is -specified, the original STDOUT and STDERR settings are used, the results are -unpredictable. + done_testing(); + done_testing($number_of_tests); -B<Note>: Filenames are a touchy subject: +If you don't know how many tests you're going to run, you can issue +the plan when you're done running tests. -Different OS's and filesystems handle filenames differently. When you do not -specify an encoding, the filename will be unmodified, you get whatever perl -thinks it is. If you do specify an encoding, the filename will be assumed to be -in that encoding, and an attempt will be made to unscramble it. If the -unscrambling fails the original name will be used. +$number_of_tests is the same as plan(), it's the number of tests you +expected to run. You can omit this, in which case the number of tests +you ran doesn't matter, just the fact that your tests ran to +conclusion. -This filename unscrambling is necessary for example on linux systems when you -use utf8 encoding and a utf8 filename. Perl will read the bytes of the name, -and treat them as bytes. if you then try to print the name to a utf8 handle it -will treat each byte as a different character. Test::More attempts to fix this -scrambling for you. +This is safer than and replaces the "no_plan" plan. =back -=head2 Helpers - -Sometimes you want to write functions for things you do frequently that include -calling ok() or other test functions. Doing this can make it hard to debug -problems as failures will be reported in your sub, and not at the place where -you called your sub. Now there is a solution to this, we call these subs -helpers. You just need to mark such subs as special. - -B<Note:> If you are going to be doing complicated things, or intend to re-use -these helpers in other test files, consider making a L<Test::Builder::Provider> -library instead. - -=over 4 - -=item helpers(qw/sub1 sub2 .../) - -This will mark any sub listed as a helper. This means that any failures within -the sub will report to where you called the sub. - -=item nest { ... } - -=item &nest($coderef) - -=item nest(\&$coderef) - -Any test errors from inside the nested coderef will trace to that coderef -instead of to your tool, useful for testing utilities that accept a codeblock. +=cut -=back +sub done_testing { + my $tb = Test::More->builder; + $tb->done_testing(@_); +} =head2 Test names @@ -1197,13 +277,22 @@ out. It makes it very easy to find a test in your script when it fails and gives others an idea of your intentions. $test_name is optional, but we B<very> strongly encourage its use. -Should an C<ok()> fail, it will produce some diagnostics: +Should an ok() fail, it will produce some diagnostics: not ok 18 - sufficient mucus # Failed test 'sufficient mucus' # in foo.t at line 42. -This is the same as L<Test::Simple>'s C<ok()> routine. +This is the same as Test::Simple's ok() routine. + +=cut + +sub ok ($;$) { + my( $test, $name ) = @_; + my $tb = Test::More->builder; + + return $tb->ok( $test, $name ); +} =item B<is> @@ -1212,7 +301,7 @@ This is the same as L<Test::Simple>'s C<ok()> routine. is ( $got, $expected, $test_name ); isnt( $got, $expected, $test_name ); -Similar to C<ok()>, C<is()> and C<isnt()> compare their two arguments +Similar to ok(), is() and isnt() compare their two arguments with C<eq> and C<ne> respectively and use the result of that to determine if the test succeeded or failed. So these: @@ -1234,9 +323,9 @@ against C<undef> like this: (Mnemonic: "This is that." "This isn't that.") -So why use these? They produce better diagnostics on failure. C<ok()> -cannot know what you are testing for (beyond the name), but C<is()> and -C<isnt()> know what the test was and why it failed. For example this +So why use these? They produce better diagnostics on failure. ok() +cannot know what you are testing for (beyond the name), but is() and +isnt() know what the test was and why it failed. For example this test: my $foo = 'waffle'; my $bar = 'yarblokos'; @@ -1252,7 +341,7 @@ Will produce something like this: So you can figure out what went wrong without rerunning the test. -You are encouraged to use C<is()> and C<isnt()> over C<ok()> where possible, +You are encouraged to use is() and isnt() over ok() where possible, however do not be tempted to use them to find out if something is true or false! @@ -1261,11 +350,11 @@ true or false! This does not check if C<exists $brooklyn{tree}> is true, it checks if it returns 1. Very different. Similar caveats exist for false and 0. -In these cases, use C<ok()>. +In these cases, use ok(). ok( exists $brooklyn{tree}, 'A tree grows in Brooklyn' ); -A simple call to C<isnt()> usually does not provide a strong test but there +A simple call to isnt() usually does not provide a strong test but there are cases when you cannot say much more about a value than that it is different from some other value: @@ -1277,13 +366,29 @@ different from some other value: isnt $obj, $clone, "clone() produces a different object"; For those grammatical pedants out there, there's an C<isn't()> -function which is an alias of C<isnt()>. +function which is an alias of isnt(). + +=cut + +sub is ($$;$) { + my $tb = Test::More->builder; + + return $tb->is_eq(@_); +} + +sub isnt ($$;$) { + my $tb = Test::More->builder; + + return $tb->isnt_eq(@_); +} + +*isn't = \&isnt; =item B<like> like( $got, qr/expected/, $test_name ); -Similar to C<ok()>, C<like()> matches $got against the regex C<qr/expected/>. +Similar to ok(), like() matches $got against the regex C<qr/expected/>. So this: @@ -1304,16 +409,32 @@ currently not supported): Regex options may be placed on the end (C<'/expected/i'>). -Its advantages over C<ok()> are similar to that of C<is()> and C<isnt()>. Better +Its advantages over ok() are similar to that of is() and isnt(). Better diagnostics on failure. +=cut + +sub like ($$;$) { + my $tb = Test::More->builder; + + return $tb->like(@_); +} + =item B<unlike> unlike( $got, qr/expected/, $test_name ); -Works exactly as C<like()>, only it checks if $got B<does not> match the +Works exactly as like(), only it checks if $got B<does not> match the given pattern. +=cut + +sub unlike ($$;$) { + my $tb = Test::More->builder; + + return $tb->unlike(@_); +} + =item B<cmp_ok> cmp_ok( $got, $op, $expected, $test_name ); @@ -1332,7 +453,7 @@ passes if the comparison is true and fails otherwise. cmp_ok( $got, '&&', $expected, 'this && that' ); ...etc... -Its advantage over C<ok()> is when the test fails you'll know what $got +Its advantage over ok() is when the test fails you'll know what $got and $expected were: not ok 1 @@ -1342,15 +463,24 @@ and $expected were: # undef It's also useful in those cases where you are comparing numbers and -C<is()>'s use of C<eq> will interfere: +is()'s use of C<eq> will interfere: cmp_ok( $big_hairy_number, '==', $another_big_hairy_number ); -It's especially useful when comparing greater-than or smaller-than +It's especially useful when comparing greater-than or smaller-than relation between values: cmp_ok( $some_value, '<=', $upper_limit ); + +=cut + +sub cmp_ok($$$;$) { + my $tb = Test::More->builder; + + return $tb->cmp_ok(@_); +} + =item B<can_ok> can_ok($module, @methods); @@ -1363,21 +493,55 @@ Checks to make sure the $module or $object can do these @methods is almost exactly like saying: - ok( Foo->can('this') && - Foo->can('that') && - Foo->can('whatever') + ok( Foo->can('this') && + Foo->can('that') && + Foo->can('whatever') ); only without all the typing and with a better interface. Handy for quickly testing an interface. -No matter how many @methods you check, a single C<can_ok()> call counts +No matter how many @methods you check, a single can_ok() call counts as one test. If you desire otherwise, use: foreach my $meth (@methods) { can_ok('Foo', $meth); } +=cut + +sub can_ok ($@) { + my( $proto, @methods ) = @_; + my $class = ref $proto || $proto; + my $tb = Test::More->builder; + + unless($class) { + my $ok = $tb->ok( 0, "->can(...)" ); + $tb->diag(' can_ok() called with empty class or reference'); + return $ok; + } + + unless(@methods) { + my $ok = $tb->ok( 0, "$class->can(...)" ); + $tb->diag(' can_ok() called with no methods'); + return $ok; + } + + my @nok = (); + foreach my $method (@methods) { + $tb->_try( sub { $proto->can($method) } ) or push @nok, $method; + } + + my $name = (@methods == 1) ? "$class->can('$methods[0]')" : + "$class->can(...)" ; + + my $ok = $tb->ok( !@nok, $name ); + + $tb->diag( map " $class->can('$_') failed\n", @nok ); + + return $ok; +} + =item B<isa_ok> isa_ok($object, $class, $object_name); @@ -1410,6 +574,88 @@ The diagnostics of this test normally just refer to 'the object'. If you'd like them to be more specific, you can supply an $object_name (for example 'Test customer'). +=cut + +sub isa_ok ($$;$) { + my( $thing, $class, $thing_name ) = @_; + my $tb = Test::More->builder; + + my $whatami; + if( !defined $thing ) { + $whatami = 'undef'; + } + elsif( ref $thing ) { + $whatami = 'reference'; + + local($@,$!); + require Scalar::Util; + if( Scalar::Util::blessed($thing) ) { + $whatami = 'object'; + } + } + else { + $whatami = 'class'; + } + + # We can't use UNIVERSAL::isa because we want to honor isa() overrides + my( $rslt, $error ) = $tb->_try( sub { $thing->isa($class) } ); + + if($error) { + die <<WHOA unless $error =~ /^Can't (locate|call) method "isa"/; +WHOA! I tried to call ->isa on your $whatami and got some weird error. +Here's the error. +$error +WHOA + } + + # Special case for isa_ok( [], "ARRAY" ) and like + if( $whatami eq 'reference' ) { + $rslt = UNIVERSAL::isa($thing, $class); + } + + my($diag, $name); + if( defined $thing_name ) { + $name = "'$thing_name' isa '$class'"; + $diag = defined $thing ? "'$thing_name' isn't a '$class'" : "'$thing_name' isn't defined"; + } + elsif( $whatami eq 'object' ) { + my $my_class = ref $thing; + $thing_name = qq[An object of class '$my_class']; + $name = "$thing_name isa '$class'"; + $diag = "The object of class '$my_class' isn't a '$class'"; + } + elsif( $whatami eq 'reference' ) { + my $type = ref $thing; + $thing_name = qq[A reference of type '$type']; + $name = "$thing_name isa '$class'"; + $diag = "The reference of type '$type' isn't a '$class'"; + } + elsif( $whatami eq 'undef' ) { + $thing_name = 'undef'; + $name = "$thing_name isa '$class'"; + $diag = "$thing_name isn't defined"; + } + elsif( $whatami eq 'class' ) { + $thing_name = qq[The class (or class-like) '$thing']; + $name = "$thing_name isa '$class'"; + $diag = "$thing_name isn't a '$class'"; + } + else { + die; + } + + my $ok; + if($rslt) { + $ok = $tb->ok( 1, $name ); + } + else { + $ok = $tb->ok( 0, $name ); + $tb->diag(" $diag\n"); + } + + return $ok; +} + =item B<new_ok> my $obj = new_ok( $class ); @@ -1417,7 +663,7 @@ you'd like them to be more specific, you can supply an $object_name my $obj = new_ok( $class => \@args, $object_name ); A convenience function which combines creating an object and calling -C<isa_ok()> on that object. +isa_ok() on that object. It is basically equivalent to: @@ -1426,21 +672,46 @@ It is basically equivalent to: If @args is not given, an empty list will be used. -This function only works on C<new()> and it assumes C<new()> will return +This function only works on new() and it assumes new() will return just a single object which isa C<$class>. +=cut + +sub new_ok { + my $tb = Test::More->builder; + $tb->croak("new_ok() must be given at least a class") unless @_; + + my( $class, $args, $object_name ) = @_; + + $args ||= []; + + my $obj; + my( $success, $error ) = $tb->_try( sub { $obj = $class->new(@$args); 1 } ); + if($success) { + local $Test::Builder::Level = $Test::Builder::Level + 1; + isa_ok $obj, $class, $object_name; + } + else { + $class = 'undef' if !defined $class; + $tb->ok( 0, "$class->new() died" ); + $tb->diag(" Error was: $error"); + } + + return $obj; +} + =item B<subtest> subtest $name => \&code; -C<subtest()> runs the &code as its own little test with its own plan and +subtest() runs the &code as its own little test with its own plan and its own result. The main test counts this as a single test using the result of the whole subtest to determine if its ok or not ok. For example... use Test::More tests => 3; - + pass("First test"); subtest 'An example subtest' => sub { @@ -1463,7 +734,7 @@ This would produce. ok 2 - An example subtest ok 3 - Third test -A subtest may call C<skip_all>. No tests will be run, but the subtest is +A subtest may call "skip_all". No tests will be run, but the subtest is considered a skip. subtest 'skippy' => sub { @@ -1490,6 +761,15 @@ subtests are equivalent: done_testing(); }; +=cut + +sub subtest { + my ($name, $subtests) = @_; + + my $tb = Test::More->builder; + return $tb->subtest(@_); +} + =item B<pass> =item B<fail> @@ -1499,14 +779,29 @@ subtests are equivalent: Sometimes you just want to say that the tests have passed. Usually the case is you've got some complicated condition that is difficult to -wedge into an C<ok()>. In this case, you can simply use C<pass()> (to +wedge into an ok(). In this case, you can simply use pass() (to declare the test ok) or fail (for not ok). They are synonyms for -C<ok(1)> and C<ok(0)>. +ok(1) and ok(0). Use these very, very, very sparingly. +=cut + +sub pass (;$) { + my $tb = Test::More->builder; + + return $tb->ok( 1, @_ ); +} + +sub fail (;$) { + my $tb = Test::More->builder; + + return $tb->ok( 0, @_ ); +} + =back + =head2 Module tests Sometimes you want to test if a module, or a list of modules, can @@ -1514,8 +809,7 @@ successfully load. For example, you'll often want a first test which simply loads all the modules in the distribution to make sure they work before going on to do more complicated testing. -For such purposes we have C<require_ok>, and C<use ok 'module'>. C<use_ok> is -still around, but is considered deprecated in favor of C<use ok 'module'>. +For such purposes we have C<use_ok> and C<require_ok>. =over 4 @@ -1544,35 +838,52 @@ No exception will be thrown if the load fails. require_ok $module or BAIL_OUT "Can't load $module"; } -=item B<use ok 'module'> +=cut -=item B<use ok 'module', @args> +sub require_ok ($) { + my($module) = shift; + my $tb = Test::More->builder; - use ok 'Some::Module'; - use ok 'Another::Module', qw/import_a import_b/; + my $pack = caller; -This will load the specified module and pass through any extra arguments to -that module. This will also produce a test result. + # Try to determine if we've been given a module name or file. + # Module names must be barewords, files not. + $module = qq['$module'] unless _is_module_name($module); -B<Note - Do not do this:> + my $code = <<REQUIRE; +package $pack; +require $module; +1; +REQUIRE - my $class = 'My::Module'; - use ok $class; + my( $eval_result, $eval_error ) = _eval($code); + my $ok = $tb->ok( $eval_result, "require $module;" ); -The value 'My::Module' is not assigned to the C<$class> variable until -run-time, but the C<use ok $class> statement is run at compile time. The result -of this is that we try to load 'undef' as a module. This will generate an -exception: C<'use ok' called with an empty argument, did you try to use a package name from an uninitialized variable?> + unless($ok) { + chomp $eval_error; + $tb->diag(<<DIAGNOSTIC); + Tried to require '$module'. + Error: $eval_error +DIAGNOSTIC -If you must do something like this, here is a more-correct way: + } - my $class; - BEGIN { $class = 'My::Module' } - use ok $class; + return $ok; +} -=item B<use_ok> +sub _is_module_name { + my $module = shift; + + # Module names start with a letter. + # End with an alphanumeric. + # The rest is an alphanumeric or :: + $module =~ s/\b::\b//g; + + return $module =~ /^[a-zA-Z]\w*$/ ? 1 : 0; +} -B<Deprecated!> See C<use ok 'module'> + +=item B<use_ok> BEGIN { use_ok($module); } BEGIN { use_ok($module, @imports); } @@ -1585,7 +896,7 @@ If you just want to test a module can be loaded, use C<require_ok>. If you just want to load a module in a test, we recommend simply using C<use> directly. It will cause the test to stop. -It's recommended that you run C<use_ok()> inside a BEGIN block so its +It's recommended that you run use_ok() inside a BEGIN block so its functions are exported at compile-time and prototypes are properly honored. @@ -1621,8 +932,77 @@ import anything, use C<require_ok>. BEGIN { require_ok "Foo" } +=cut + +sub use_ok ($;@) { + my( $module, @imports ) = @_; + @imports = () unless @imports; + my $tb = Test::More->builder; + + my( $pack, $filename, $line ) = caller; + $filename =~ y/\n\r/_/; # so it doesn't run off the "#line $line $f" line + + my $code; + if( @imports == 1 and $imports[0] =~ /^\d+(?:\.\d+)?$/ ) { + # probably a version check. Perl needs to see the bare number + # for it to work with non-Exporter based modules. + $code = <<USE; +package $pack; + +#line $line $filename +use $module $imports[0]; +1; +USE + } + else { + $code = <<USE; +package $pack; + +#line $line $filename +use $module \@{\$args[0]}; +1; +USE + } + + my( $eval_result, $eval_error ) = _eval( $code, \@imports ); + my $ok = $tb->ok( $eval_result, "use $module;" ); + + unless($ok) { + chomp $eval_error; + $@ =~ s{^BEGIN failed--compilation aborted at .*$} + {BEGIN failed--compilation aborted at $filename line $line.}m; + $tb->diag(<<DIAGNOSTIC); + Tried to use '$module'. + Error: $eval_error +DIAGNOSTIC + + } + + return $ok; +} + +sub _eval { + my( $code, @args ) = @_; + + # Work around oddities surrounding resetting of $@ by immediately + # storing it. + my( $sigdie, $eval_result, $eval_error ); + { + local( $@, $!, $SIG{__DIE__} ); # isolate eval + $eval_result = eval $code; ## no critic (BuiltinFunctions::ProhibitStringyEval) + $eval_error = $@; + $sigdie = $SIG{__DIE__} || undef; + } + # make sure that $code got a chance to set $SIG{__DIE__} + $SIG{__DIE__} = $sigdie if defined $sigdie; + + return( $eval_result, $eval_error ); +} + + =back + =head2 Complex data structures Not everything is a simple eq check or regex. There are times you @@ -1637,22 +1017,128 @@ B<NOTE> I'm not quite sure what will happen with filehandles. is_deeply( $got, $expected, $test_name ); -Similar to C<is()>, except that if $got and $expected are references, it +Similar to is(), except that if $got and $expected are references, it does a deep comparison walking each data structure to see if they are equivalent. If the two structures are different, it will display the place where they start differing. -C<is_deeply()> compares the dereferenced values of references, the +is_deeply() compares the dereferenced values of references, the references themselves (except for their type) are ignored. This means aspects such as blessing and ties are not considered "different". -C<is_deeply()> currently has very limited handling of function reference +is_deeply() currently has very limited handling of function reference and globs. It merely checks if they have the same referent. This may improve in the future. L<Test::Differences> and L<Test::Deep> provide more in-depth functionality along these lines. +=cut + +our( @Data_Stack, %Refs_Seen ); +my $DNE = bless [], 'Does::Not::Exist'; + +sub _dne { + return ref $_[0] eq ref $DNE; +} + +## no critic (Subroutines::RequireArgUnpacking) +sub is_deeply { + my $tb = Test::More->builder; + + unless( @_ == 2 or @_ == 3 ) { + my $msg = <<'WARNING'; +is_deeply() takes two or three args, you gave %d. +This usually means you passed an array or hash instead +of a reference to it +WARNING + chop $msg; # clip off newline so carp() will put in line/file + + _carp sprintf $msg, scalar @_; + + return $tb->ok(0); + } + + my( $got, $expected, $name ) = @_; + + $tb->_unoverload_str( \$expected, \$got ); + + my $ok; + if( !ref $got and !ref $expected ) { # neither is a reference + $ok = $tb->is_eq( $got, $expected, $name ); + } + elsif( !ref $got xor !ref $expected ) { # one's a reference, one isn't + $ok = $tb->ok( 0, $name ); + $tb->diag( _format_stack({ vals => [ $got, $expected ] }) ); + } + else { # both references + local @Data_Stack = (); + if( _deep_check( $got, $expected ) ) { + $ok = $tb->ok( 1, $name ); + } + else { + $ok = $tb->ok( 0, $name ); + $tb->diag( _format_stack(@Data_Stack) ); + } + } + + return $ok; +} + +sub _format_stack { + my(@Stack) = @_; + + my $var = '$FOO'; + my $did_arrow = 0; + foreach my $entry (@Stack) { + my $type = $entry->{type} || ''; + my $idx = $entry->{'idx'}; + if( $type eq 'HASH' ) { + $var .= "->" unless $did_arrow++; + $var .= "{$idx}"; + } + elsif( $type eq 'ARRAY' ) { + $var .= "->" unless $did_arrow++; + $var .= "[$idx]"; + } + elsif( $type eq 'REF' ) { + $var = "\${$var}"; + } + } + + my @vals = @{ $Stack[-1]{vals} }[ 0, 1 ]; + my @vars = (); + ( $vars[0] = $var ) =~ s/\$FOO/ \$got/; + ( $vars[1] = $var ) =~ s/\$FOO/\$expected/; + + my $out = "Structures begin differing at:\n"; + foreach my $idx ( 0 .. $#vals ) { + my $val = $vals[$idx]; + $vals[$idx] + = !defined $val ? 'undef' + : _dne($val) ? "Does not exist" + : ref $val ? "$val" + : "'$val'"; + } + + $out .= "$vars[0] = $vals[0]\n"; + $out .= "$vars[1] = $vals[1]\n"; + + $out =~ s/^/ /msg; + return $out; +} + +sub _type { + my $thing = shift; + + return '' if !ref $thing; + + for my $type (qw(Regexp ARRAY HASH REF SCALAR GLOB CODE)) { + return $type if UNIVERSAL::isa( $thing, $type ); + } + + return ''; +} =back @@ -1699,7 +1185,7 @@ interfere with the test. note(@diagnostic_message); -Like C<diag()>, except the message will not be seen when the test is run +Like diag(), except the message will not be seen when the test is run in a harness. It will only be visible in the verbose TAP stream. Handy for putting in notes which might be useful for debugging, but @@ -1707,6 +1193,16 @@ don't indicate a problem. note("Tempfile is $tempfile"); +=cut + +sub diag { + return Test::More->builder->diag(@_); +} + +sub note { + return Test::More->builder->note(@_); +} + =item B<explain> my @dump = explain @diagnostic_message; @@ -1723,6 +1219,12 @@ or note explain \%args; Some::Class->method(%args); +=cut + +sub explain { + return Test::More->builder->explain(@_); +} + =back @@ -1730,7 +1232,7 @@ or Sometimes running a test under certain conditions will cause the test script to die. A certain function or method isn't implemented -(such as C<fork()> on MacOS), some resource isn't available (like a +(such as fork() on MacOS), some resource isn't available (like a net connection) or a module isn't available. In these cases it's necessary to skip tests, or declare that they are supposed to fail but will work in the future (a todo test). @@ -1783,6 +1285,34 @@ You don't skip tests which are failing because there's a bug in your program, or for which you don't yet have code written. For that you use TODO. Read on. +=cut + +## no critic (Subroutines::RequireFinalReturn) +sub skip { + my( $why, $how_many ) = @_; + my $tb = Test::More->builder; + + unless( defined $how_many ) { + # $how_many can only be avoided when no_plan is in use. + _carp "skip() needs to know \$how_many tests are in the block" + unless $tb->has_plan eq 'no_plan'; + $how_many = 1; + } + + if( defined $how_many and $how_many =~ /\D/ ) { + _carp + "skip() was passed a non-numeric number of tests. Did you get the arguments backwards?"; + $how_many = 1; + } + + for( 1 .. $how_many ) { + $tb->skip($why); + } + + no warnings 'exiting'; + last SKIP; +} + =item B<TODO: BLOCK> TODO: { @@ -1807,7 +1337,7 @@ because you haven't fixed a bug or haven't finished a new feature: With a todo block, the tests inside are expected to fail. Test::More will run the tests normally, but print out special flags indicating -they are "todo". L<Test::Harness> will interpret failures as being ok. +they are "todo". Test::Harness will interpret failures as being ok. Should anything succeed, it will report it as an unexpected success. You then know the thing you had todo is done and can remove the TODO flag. @@ -1836,15 +1366,35 @@ inside an C<eval BLOCK> with and using C<alarm>. In these extreme cases you have no choice but to skip over the broken tests entirely. The syntax and behavior is similar to a C<SKIP: BLOCK> except the -tests will be marked as failing but todo. L<Test::Harness> will +tests will be marked as failing but todo. Test::Harness will interpret them as passing. +=cut + +sub todo_skip { + my( $why, $how_many ) = @_; + my $tb = Test::More->builder; + + unless( defined $how_many ) { + # $how_many can only be avoided when no_plan is in use. + _carp "todo_skip() needs to know \$how_many tests are in the block" + unless $tb->has_plan eq 'no_plan'; + $how_many = 1; + } + + for( 1 .. $how_many ) { + $tb->todo_skip($why); + } + + no warnings 'exiting'; + last TODO; +} =item When do I use SKIP vs. TODO? B<If it's something the user might not be able to do>, use SKIP. This includes optional modules that aren't installed, running under -an OS that doesn't have some feature (like C<fork()> or symlinks), or maybe +an OS that doesn't have some feature (like fork() or symlinks), or maybe you need an Internet connection and one isn't available. B<If it's something the programmer hasn't done yet>, use TODO. This @@ -1874,21 +1424,31 @@ The test will exit with 255. For even better control look at L<Test::Most>. +=cut + +sub BAIL_OUT { + my $reason = shift; + my $tb = Test::More->builder; + + $tb->BAIL_OUT($reason); +} + =back + =head2 Discouraged comparison functions The use of the following functions is discouraged as they are not actually testing functions and produce no diagnostics to help figure -out what went wrong. They were written before C<is_deeply()> existed +out what went wrong. They were written before is_deeply() existed because I couldn't figure out how to display a useful diff of two arbitrary data structures. -These functions are usually used inside an C<ok()>. +These functions are usually used inside an ok(). ok( eq_array(\@got, \@expected) ); -C<is_deeply()> can do that better and with diagnostics. +C<is_deeply()> can do that better and with diagnostics. is_deeply( \@got, \@expected ); @@ -1903,6 +1463,146 @@ They may be deprecated in future versions. Checks if two arrays are equivalent. This is a deep check, so multi-level structures are handled correctly. +=cut + +#'# +sub eq_array { + local @Data_Stack = (); + _deep_check(@_); +} + +sub _eq_array { + my( $a1, $a2 ) = @_; + + if( grep _type($_) ne 'ARRAY', $a1, $a2 ) { + warn "eq_array passed a non-array ref"; + return 0; + } + + return 1 if $a1 eq $a2; + + my $ok = 1; + my $max = $#$a1 > $#$a2 ? $#$a1 : $#$a2; + for( 0 .. $max ) { + my $e1 = $_ > $#$a1 ? $DNE : $a1->[$_]; + my $e2 = $_ > $#$a2 ? $DNE : $a2->[$_]; + + next if _equal_nonrefs($e1, $e2); + + push @Data_Stack, { type => 'ARRAY', idx => $_, vals => [ $e1, $e2 ] }; + $ok = _deep_check( $e1, $e2 ); + pop @Data_Stack if $ok; + + last unless $ok; + } + + return $ok; +} + +sub _equal_nonrefs { + my( $e1, $e2 ) = @_; + + return if ref $e1 or ref $e2; + + if ( defined $e1 ) { + return 1 if defined $e2 and $e1 eq $e2; + } + else { + return 1 if !defined $e2; + } + + return; +} + +sub _deep_check { + my( $e1, $e2 ) = @_; + my $tb = Test::More->builder; + + my $ok = 0; + + # Effectively turn %Refs_Seen into a stack. This avoids picking up + # the same referenced used twice (such as [\$a, \$a]) to be considered + # circular. + local %Refs_Seen = %Refs_Seen; + + { + $tb->_unoverload_str( \$e1, \$e2 ); + + # Either they're both references or both not. + my $same_ref = !( !ref $e1 xor !ref $e2 ); + my $not_ref = ( !ref $e1 and !ref $e2 ); + + if( defined $e1 xor defined $e2 ) { + $ok = 0; + } + elsif( !defined $e1 and !defined $e2 ) { + # Shortcut if they're both undefined. + $ok = 1; + } + elsif( _dne($e1) xor _dne($e2) ) { + $ok = 0; + } + elsif( $same_ref and( $e1 eq $e2 ) ) { + $ok = 1; + } + elsif($not_ref) { + push @Data_Stack, { type => '', vals => [ $e1, $e2 ] }; + $ok = 0; + } + else { + if( $Refs_Seen{$e1} ) { + return $Refs_Seen{$e1} eq $e2; + } + else { + $Refs_Seen{$e1} = "$e2"; + } + + my $type = _type($e1); + $type = 'DIFFERENT' unless _type($e2) eq $type; + + if( $type eq 'DIFFERENT' ) { + push @Data_Stack, { type => $type, vals => [ $e1, $e2 ] }; + $ok = 0; + } + elsif( $type eq 'ARRAY' ) { + $ok = _eq_array( $e1, $e2 ); + } + elsif( $type eq 'HASH' ) { + $ok = _eq_hash( $e1, $e2 ); + } + elsif( $type eq 'REF' ) { + push @Data_Stack, { type => $type, vals => [ $e1, $e2 ] }; + $ok = _deep_check( $$e1, $$e2 ); + pop @Data_Stack if $ok; + } + elsif( $type eq 'SCALAR' ) { + push @Data_Stack, { type => 'REF', vals => [ $e1, $e2 ] }; + $ok = _deep_check( $$e1, $$e2 ); + pop @Data_Stack if $ok; + } + elsif($type) { + push @Data_Stack, { type => $type, vals => [ $e1, $e2 ] }; + $ok = 0; + } + else { + _whoa( 1, "No type in _deep_check" ); + } + } + } + + return $ok; +} + +sub _whoa { + my( $check, $desc ) = @_; + if($check) { + die <<"WHOA"; +WHOA! $desc +This should never happen! Please contact the author immediately! +WHOA + } +} + =item B<eq_hash> my $is_eq = eq_hash(\%got, \%expected); @@ -1910,12 +1610,46 @@ multi-level structures are handled correctly. Determines if the two hashes contain the same keys and values. This is a deep check. +=cut + +sub eq_hash { + local @Data_Stack = (); + return _deep_check(@_); +} + +sub _eq_hash { + my( $a1, $a2 ) = @_; + + if( grep _type($_) ne 'HASH', $a1, $a2 ) { + warn "eq_hash passed a non-hash ref"; + return 0; + } + + return 1 if $a1 eq $a2; + + my $ok = 1; + my $bigger = keys %$a1 > keys %$a2 ? $a1 : $a2; + foreach my $k ( keys %$bigger ) { + my $e1 = exists $a1->{$k} ? $a1->{$k} : $DNE; + my $e2 = exists $a2->{$k} ? $a2->{$k} : $DNE; + + next if _equal_nonrefs($e1, $e2); + + push @Data_Stack, { type => 'HASH', idx => $k, vals => [ $e1, $e2 ] }; + $ok = _deep_check( $e1, $e2 ); + pop @Data_Stack if $ok; + + last unless $ok; + } + + return $ok; +} =item B<eq_set> my $is_eq = eq_set(\@got, \@expected); -Similar to C<eq_array()>, except the order of the elements is B<not> +Similar to eq_array(), except the order of the elements is B<not> important. This is a deep check, but the irrelevancy of order only applies to the top level. @@ -1928,26 +1662,51 @@ Is better written: B<NOTE> By historical accident, this is not a true set comparison. While the order of elements does not matter, duplicate elements do. -B<NOTE> C<eq_set()> does not know how to deal with references at the top +B<NOTE> eq_set() does not know how to deal with references at the top level. The following is an example of a comparison which might not work: eq_set([\1, \2], [\2, \1]); L<Test::Deep> contains much better set comparison functions. +=cut + +sub eq_set { + my( $a1, $a2 ) = @_; + return 0 unless @$a1 == @$a2; + + no warnings 'uninitialized'; + + # It really doesn't matter how we sort them, as long as both arrays are + # sorted with the same algorithm. + # + # Ensure that references are not accidentally treated the same as a + # string containing the reference. + # + # Have to inline the sort routine due to a threading/sort bug. + # See [rt.cpan.org 6782] + # + # I don't know how references would be sorted so we just don't sort + # them. This means eq_set doesn't really work with refs. + return eq_array( + [ grep( ref, @$a1 ), sort( grep( !ref, @$a1 ) ) ], + [ grep( ref, @$a2 ), sort( grep( !ref, @$a2 ) ) ], + ); +} + =back =head2 Extending and Embedding Test::More Sometimes the Test::More interface isn't quite enough. Fortunately, -Test::More is built on top of L<Test::Builder> which provides a single, +Test::More is built on top of Test::Builder which provides a single, unified backend for any test library to use. This means two test -libraries which both use <Test::Builder> B<can> be used together in the +libraries which both use Test::Builder B<can be used together in the same program>. If you simply want to do a little tweaking of how the tests behave, -you can access the underlying L<Test::Builder> object like so: +you can access the underlying Test::Builder object like so: =over 4 @@ -1955,7 +1714,7 @@ you can access the underlying L<Test::Builder> object like so: my $test_builder = Test::More->builder; -Returns the L<Test::Builder> object underlying Test::More for you to play +Returns the Test::Builder object underlying Test::More for you to play with. @@ -1964,10 +1723,10 @@ with. =head1 EXIT CODES -If all your tests passed, L<Test::Builder> will exit with zero (which is +If all your tests passed, Test::Builder will exit with zero (which is normal). If anything failed it will exit with how many failed. If you run less (or more) tests than you planned, the missing (or extras) -will be considered failures. If no tests were ever run L<Test::Builder> +will be considered failures. If no tests were ever run Test::Builder will throw a warning and exit with 255. If the test died, even after having successfully completed all its tests, it will still be considered a failure and will exit with 255. @@ -1990,55 +1749,31 @@ Test::More works with Perls as old as 5.8.1. Thread support is not very reliable before 5.10.1, but that's because threads are not very reliable before 5.10.1. -Although Test::More has been a core module in versions of Perl since 5.6.2, -Test::More has evolved since then, and not all of the features you're used to -will be present in the shipped version of Test::More. If you are writing a -module, don't forget to indicate in your package metadata the minimum version -of Test::More that you require. For instance, if you want to use -C<done_testing()> but want your test script to run on Perl 5.10.0, you will -need to explicitly require Test::More > 0.88. +Although Test::More has been a core module in versions of Perl since 5.6.2, Test::More has evolved since then, and not all of the features you're used to will be present in the shipped version of Test::More. If you are writing a module, don't forget to indicate in your package metadata the minimum version of Test::More that you require. For instance, if you want to use C<done_testing()> but want your test script to run on Perl 5.10.0, you will need to explicitly require Test::More > 0.88. Key feature milestones include: =over 4 -=item event stream - -=item forking support - -=item test tracing - -=item tap encoding - -Test::Builder and Test::More version 1.301001 introduce these major -modernizations. - =item subtests -Subtests were released in Test::More 0.94, which came with Perl 5.12.0. -Subtests did not implicitly call C<done_testing()> until 0.96; the first Perl -with that fix was Perl 5.14.0 with 0.98. +Subtests were released in Test::More 0.94, which came with Perl 5.12.0. Subtests did not implicitly call C<done_testing()> until 0.96; the first Perl with that fix was Perl 5.14.0 with 0.98. =item C<done_testing()> -This was released in Test::More 0.88 and first shipped with Perl in 5.10.1 as -part of Test::More 0.92. +This was released in Test::More 0.88 and first shipped with Perl in 5.10.1 as part of Test::More 0.92. =item C<cmp_ok()> -Although C<cmp_ok()> was introduced in 0.40, 0.86 fixed an important bug to -make it safe for overloaded objects; the fixed first shipped with Perl in -5.10.1 as part of Test::More 0.92. +Although C<cmp_ok()> was introduced in 0.40, 0.86 fixed an important bug to make it safe for overloaded objects; the fixed first shipped with Perl in 5.10.1 as part of Test::More 0.92. =item C<new_ok()> C<note()> and C<explain()> -These were was released in Test::More 0.82, and first shipped with Perl in -5.10.1 as part of Test::More 0.92. +These were was released in Test::More 0.82, and first shipped with Perl in 5.10.1 as part of Test::More 0.92. =back -There is a full version history in the Changes file, and the Test::More -versions included as core can be found using L<Module::CoreList>: +There is a full version history in the Changes file, and the Test::More versions included as core can be found using L<Module::CoreList>: $ corelist -a Test::More @@ -2050,32 +1785,21 @@ versions included as core can be found using L<Module::CoreList>: =item utf8 / "Wide character in print" If you use utf8 or other non-ASCII characters with Test::More you -might get a "Wide character in print" warning. -Using C<< binmode STDOUT, ":utf8" >> will not fix it. - -Use the C<tap_encoding> function to configure the TAP stream encoding. - - use utf8; - use Test::More; - tap_encoding 'utf8'; - -L<Test::Builder> (which powers Test::More) duplicates STDOUT and STDERR. -So any changes to them, including changing their output disciplines, -will not be seen by Test::More. - -B<Note>:deprecated ways to use utf8 or other non-ASCII characters. +might get a "Wide character in print" warning. Using C<binmode +STDOUT, ":utf8"> will not fix it. Test::Builder (which powers +Test::More) duplicates STDOUT and STDERR. So any changes to them, +including changing their output disciplines, will not be seem by +Test::More. -In the past it was necessary to alter the filehandle encoding prior to loading -Test::More. This is no longer necessary thanks to C<tap_encoding()>. +One work around is to apply encodings to STDOUT and STDERR as early +as possible and before Test::More (or any other Test module) loads. - # *** DEPRECATED WAY *** use open ':std', ':encoding(utf8)'; use Test::More; A more direct work around is to change the filehandles used by -L<Test::Builder>. +Test::Builder. - # *** EVEN MORE DEPRECATED WAY *** my $builder = Test::More->builder; binmode $builder->output, ":encoding(utf8)"; binmode $builder->failure_output, ":encoding(utf8)"; @@ -2084,14 +1808,14 @@ L<Test::Builder>. =item Overloaded objects -String overloaded objects are compared B<as strings> (or in C<cmp_ok()>'s +String overloaded objects are compared B<as strings> (or in cmp_ok()'s case, strings or numbers as appropriate to the comparison op). This prevents Test::More from piercing an object's interface allowing better blackbox testing. So if a function starts returning overloaded objects instead of bare strings your tests won't notice the difference. This is good. -However, it does mean that functions like C<is_deeply()> cannot be used to +However, it does mean that functions like is_deeply() cannot be used to test the internals of string overloaded objects. In this case I would suggest L<Test::Deep> which contains more flexible testing functions for complex data structures. @@ -2099,7 +1823,7 @@ complex data structures. =item Threads -Test::More will only be aware of threads if C<use threads> has been done +Test::More will only be aware of threads if "use threads" has been done I<before> Test::More is loaded. This is ok: use threads; @@ -2117,9 +1841,9 @@ This may cause problems: =head1 HISTORY -This is a case of convergent evolution with Joshua Pritikin's L<Test> +This is a case of convergent evolution with Joshua Pritikin's Test module. I was largely unaware of its existence when I'd first -written my own C<ok()> routines. This module exists because I can't +written my own ok() routines. This module exists because I can't figure out how to easily wedge test names into Test's interface (along with a few other problems). @@ -2132,29 +1856,18 @@ magic side-effects are kept to a minimum. WYSIWYG. =head1 SEE ALSO -=head2 - -=head2 ALTERNATIVES - L<Test::Simple> if all this confuses you and you just want to write some tests. You can upgrade to Test::More later (it's forward compatible). +L<Test::Harness> is the test runner and output interpreter for Perl. +It's the thing that powers C<make test> and where the C<prove> utility +comes from. + L<Test::Legacy> tests written with Test.pm, the original testing module, do not play well with other testing libraries. Test::Legacy emulates the Test.pm interface and does play well with others. -=head2 TESTING FRAMEWORKS - -L<Fennec> The Fennec framework is a testers toolbox. It uses L<Test::Builder> -under the hood. It brings enhancements for forking, defining state, and -mocking. Fennec enhances several modules to work better together than they -would if you loaded them individually on your own. - -L<Fennec::Declare> Provides enhanced (L<Devel::Declare>) syntax for Fennec. - -=head2 ADDITIONAL LIBRARIES - L<Test::Differences> for more ways to test complex data structures. And it plays well with Test::More. @@ -2164,22 +1877,8 @@ L<Test::Deep> gives you more powerful complex data structure testing. L<Test::Inline> shows the idea of embedded testing. -L<Mock::Quick> The ultimate mocking library. Easily spawn objects defined on -the fly. Can also override, block, or reimplement packages as needed. - -L<Test::FixtureBuilder> Quickly define fixture data for unit tests. - -=head2 OTHER COMPONENTS - -L<Test::Harness> is the test runner and output interpreter for Perl. -It's the thing that powers C<make test> and where the C<prove> utility -comes from. - -=head2 BUNDLES - L<Bundle::Test> installs a whole bunch of useful test modules. -L<Test::Most> Most commonly needed test functions and features. =head1 AUTHORS @@ -2197,6 +1896,11 @@ the perl-qa gang. =back +=head1 BUGS + +See F<http://rt.cpan.org> to report and view bugs. + + =head1 SOURCE The source code repository for Test::More can be found at @@ -2207,10 +1911,11 @@ F<http://github.com/Test-More/test-more/>. Copyright 2001-2008 by Michael G Schwern E<lt>schwern@pobox.comE<gt>. -Copyright 2014 Chad Granum E<lt>exodist7@gmail.comE<gt>. - This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See F<http://www.perl.com/perl/misc/Artistic.html> +=cut + +1; diff --git a/cpan/Test-Simple/lib/Test/Simple.pm b/cpan/Test-Simple/lib/Test/Simple.pm index 9d98ecd286..8d123b46c7 100644 --- a/cpan/Test-Simple/lib/Test/Simple.pm +++ b/cpan/Test-Simple/lib/Test/Simple.pm @@ -1,76 +1,17 @@ package Test::Simple; -use 5.008001; +use 5.006; use strict; -our $VERSION = '1.301001_040'; +our $VERSION = '1.001003'; $VERSION = eval $VERSION; ## no critic (BuiltinFunctions::ProhibitStringyEval) -use Test::Builder::Provider; -require Test::More; - -provides qw/ok/; - -sub before_import { - my $class = shift; - my ($list, $dest) = @_; - - Test::More::_set_tap_encoding($dest, 'legacy'); - - my $encoding_set = 0; - my $other = []; - my $idx = 0; - my $modern = 0; - while ($idx <= $#{$list}) { - my $item = $list->[$idx++]; - - if (defined $item and $item eq 'no_diag') { - $class->builder->no_diag(1); - } - elsif ($item eq 'tests' || $item eq 'skip_all') { - $class->builder->plan($item => $list->[$idx++]); - } - elsif ($item eq 'no_plan') { - $class->builder->plan($item); - } - elsif ($item eq 'import') { - push @$other => @{$list->[$idx++]}; - } - elsif ($item eq 'modern') { - modernize($dest); - Test::More::_set_tap_encoding($dest, 'utf8') unless $encoding_set; - $modern++; - } - elsif ($item eq 'utf8') { - Test::More::_set_tap_encoding($dest, 'utf8'); - $encoding_set++; - } - elsif ($item eq 'encoding') { - my $encoding = $list->[$idx++]; - Test::More::_set_tap_encoding($dest, $encoding); - $encoding_set++; - } - - else { - Carp::croak("Unknown option: $item"); - } - } - - @$list = @$other; - - Test::Builder::Stream->shared->use_lresults unless $modern; - - return; -} - -sub ok ($;$) { ## no critic (Subroutines::ProhibitSubroutinePrototypes) - return builder()->ok(@_); -} +use Test::Builder::Module 0.99; +our @ISA = qw(Test::Builder::Module); +our @EXPORT = qw(ok); -1; - -__END__ +my $CLASS = __PACKAGE__; =head1 NAME @@ -82,20 +23,10 @@ Test::Simple - Basic utilities for writing tests. ok( $foo eq $bar, 'foo is bar' ); -=head1 TEST COMPONENT MAP - - [Test Script] > [Test Tool] > [Test::Builder] > [Test::Bulder::Stream] > [Event Formatter] - ^ - You are here - -A test script uses a test tool such as L<Test::More>, which uses Test::Builder -to produce events. The events are sent to L<Test::Builder::Stream> which then -forwards them on to one or more formatters. The default formatter is -L<Test::Builder::Fromatter::TAP> which produces TAP output. =head1 DESCRIPTION -** If you are unfamiliar with testing B<read L<Test::Tutorial> first!> ** +** If you are unfamiliar with testing B<read Test::Tutorial> first! ** This is an extremely simple, extremely basic module for writing tests suitable for CPAN modules and other pursuits. If you wish to do more @@ -104,7 +35,7 @@ for this one). The basic unit of Perl testing is the ok. For each thing you want to test your program will print out an "ok" or "not ok" to indicate pass -or fail. You do this with the C<ok()> function (see below). +or fail. You do this with the ok() function (see below). The only other constraint is you must pre-declare how many tests you plan to run. This is in case something goes horribly wrong during the @@ -123,10 +54,10 @@ You must have a plan. ok( $foo eq $bar, $name ); ok( $foo eq $bar ); -C<ok()> is given an expression (in this case C<$foo eq $bar>). If it's +ok() is given an expression (in this case C<$foo eq $bar>). If it's true, the test passed. If it's false, it didn't. That's about it. -C<ok()> prints out either "ok" or "not ok" along with a test number (it +ok() prints out either "ok" or "not ok" along with a test number (it keeps track of that for you). # This produces "ok 1 - Hell not yet frozen over" (or not ok) @@ -143,11 +74,17 @@ All tests are run in scalar context. So this: will do what you mean (fail if stuff is empty) +=cut + +sub ok ($;$) { ## no critic (Subroutines::ProhibitSubroutinePrototypes) + return $CLASS->builder->ok(@_); +} + =back Test::Simple will start by printing number of tests run in the form "1..M" (so "1..5" means you're going to run 5 tests). This strange -format lets L<Test::Harness> know how many tests you plan on running in +format lets Test::Harness know how many tests you plan on running in case something goes horribly wrong. If all your tests passed, Test::Simple will exit with zero (which is @@ -248,13 +185,13 @@ he wasn't in Tony's kitchen). This is it. =item L<Test::More> More testing functions! Once you outgrow Test::Simple, look at -L<Test::More>. Test::Simple is 100% forward compatible with L<Test::More> -(i.e. you can just use L<Test::More> instead of Test::Simple in your +Test::More. Test::Simple is 100% forward compatible with Test::More +(i.e. you can just use Test::More instead of Test::Simple in your programs and things will still work). =back -Look in L<Test::More>'s SEE ALSO for more testing modules. +Look in Test::More's SEE ALSO for more testing modules. =head1 AUTHORS @@ -274,9 +211,11 @@ E<lt>schwern@pobox.comE<gt>, wardrobe by Calvin Klein. Copyright 2001-2008 by Michael G Schwern E<lt>schwern@pobox.comE<gt>. -Copyright 2014 Chad Granum E<lt>exodist7@gmail.comE<gt>. - -This program is free software; you can redistribute it and/or +This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See F<http://www.perl.com/perl/misc/Artistic.html> + +=cut + +1; diff --git a/cpan/Test-Simple/lib/Test/Tester.pm b/cpan/Test-Simple/lib/Test/Tester.pm deleted file mode 100644 index 5eab16c08c..0000000000 --- a/cpan/Test-Simple/lib/Test/Tester.pm +++ /dev/null @@ -1,642 +0,0 @@ -use strict; - -package Test::Tester; - -# Turn this back on later -#warn "Test::Tester is deprecated, see Test::Tester2\n"; - -BEGIN { - if (*Test::Builder::new{CODE}) { - warn "You should load Test::Tester before Test::Builder (or anything that loads Test::Builder)"; - } -} - -use Test::Builder 1.301001; -BEGIN { Test::Builder::Stream->shared->use_lresults } -use Test::Tester::CaptureRunner; -use Test::Tester::Delegate; - -require Exporter; - -use vars qw( @ISA @EXPORT $VERSION ); - - -our $VERSION = '1.301001_040'; -$VERSION = eval $VERSION; ## no critic (BuiltinFunctions::ProhibitStringyEval) - -@EXPORT = qw( run_tests check_tests check_test cmp_results show_space ); -@ISA = qw( Exporter ); - -my $Test = Test::Builder->new; -my $Capture = Test::Tester::Capture->new; -my $Delegator = Test::Tester::Delegate->new; -$Delegator->{Object} = $Test; - -my $runner = Test::Tester::CaptureRunner->new; - -my $want_space = $ENV{TESTTESTERSPACE}; - -sub show_space { - $want_space = 1; -} - -my $colour = ''; -my $reset = ''; - -if (my $want_colour = $ENV{TESTTESTERCOLOUR} || $ENV{TESTTESTERCOLOUR}) { - if (eval "require Term::ANSIColor") { - my ($f, $b) = split(",", $want_colour); - $colour = Term::ANSIColor::color($f) . Term::ANSIColor::color("on_$b"); - $reset = Term::ANSIColor::color("reset"); - } - -} - -sub new_new { - return $Delegator; -} - -sub capture { - return Test::Tester::Capture->new; -} - -sub fh { - # experiment with capturing output, I don't like it - $runner = Test::Tester::FHRunner->new; - - return $Test; -} - -sub find_run_tests { - my $d = 1; - my $found = 0; - while ((not $found) and (my ($sub) = (caller($d))[3])) { - $found = ($sub eq "Test::Tester::run_tests"); - $d++; - } - - return $d; -} - -sub run_tests { - local ($Delegator->{Object}) = $Capture; - - $runner->run_tests(@_); - - return ($runner->get_premature, $runner->get_results); -} - -sub check_test { - my $test = shift; - my $expect = shift; - my $name = shift; - $name = "" unless defined($name); - - @_ = ($test, [$expect], $name); - goto &check_tests; -} - -sub check_tests { - my $test = shift; - my $expects = shift; - my $name = shift; - $name = "" unless defined($name); - - my ($prem, @results) = eval { run_tests($test, $name) }; - - $Test->ok(!$@, "Test '$name' completed") || $Test->diag($@); - $Test->ok(!length($prem), "Test '$name' no premature diagnostication") - || $Test->diag("Before any testing anything, your tests said\n$prem"); - - local $Test::Builder::Level = $Test::Builder::Level + 1; - cmp_results(\@results, $expects, $name); - return ($prem, @results); -} - -sub cmp_field { - my ($result, $expect, $field, $desc) = @_; - - if (defined $expect->{$field}) { - $Test->is_eq( - $result->{$field}, $expect->{$field}, - "$desc compare $field" - ); - } -} - -sub cmp_result { - my ($result, $expect, $name) = @_; - - my $sub_name = $result->{name}; - $sub_name = "" unless defined($name); - - my $desc = "subtest '$sub_name' of '$name'"; - - { - local $Test::Builder::Level = $Test::Builder::Level + 1; - - cmp_field($result, $expect, "ok", $desc); - - cmp_field($result, $expect, "actual_ok", $desc); - - cmp_field($result, $expect, "type", $desc); - - cmp_field($result, $expect, "reason", $desc); - - cmp_field($result, $expect, "name", $desc); - } - - # if we got no depth then default to 1 - my $depth = 1; - if (exists $expect->{depth}) { - $depth = $expect->{depth}; - } - - # if depth was explicitly undef then don't test it - if (defined $depth) { - $Test->ok(1, "depth checking is deprecated, dummy pass result..."); - } - - if (defined(my $exp = $expect->{diag})) { - # if there actually is some diag then put a \n on the end if it's not - # there already - - $exp .= "\n" if (length($exp) and $exp !~ /\n$/); - if ( - not $Test->ok( - $result->{diag} eq $exp, - "subtest '$sub_name' of '$name' compare diag" - ) - ) - { - my $got = $result->{diag}; - my $glen = length($got); - my $elen = length($exp); - for ($got, $exp) { - my @lines = split("\n", $_); - $_ = join( - "\n", - map { - if ($want_space) { - $_ = $colour . escape($_) . $reset; - } - else { - "'$colour$_$reset'"; - } - } @lines - ); - } - - $Test->diag(<<EOM); -Got diag ($glen bytes): -$got -Expected diag ($elen bytes): -$exp -EOM - - } - } -} - -sub escape { - my $str = shift; - my $res = ''; - for my $char (split("", $str)) { - my $c = ord($char); - if (($c > 32 and $c < 125) or $c == 10) { - $res .= $char; - } - else { - $res .= sprintf('\x{%x}', $c); - } - } - return $res; -} - -sub cmp_results { - my ($results, $expects, $name) = @_; - - $Test->is_num(scalar @$results, scalar @$expects, "Test '$name' result count"); - - for (my $i = 0; $i < @$expects; $i++) { - my $expect = $expects->[$i]; - my $result = $results->[$i]; - - local $Test::Builder::Level = $Test::Builder::Level + 1; - cmp_result($result, $expect, $name); - } -} - -######## nicked from Test::More -sub plan { - my (@plan) = @_; - - my $caller = caller; - - $Test->exported_to($caller); - - my @imports = (); - foreach my $idx (0 .. $#plan) { - if ($plan[$idx] eq 'import') { - my ($tag, $imports) = splice @plan, $idx, 2; - @imports = @$imports; - last; - } - } - - $Test->plan(@plan); - - __PACKAGE__->_export_to_level(1, __PACKAGE__, @imports); -} - -sub import { - my ($class) = shift; - { - no warnings 'redefine'; - *Test::Builder::new = \&new_new; - } - goto &plan; -} - -sub _export_to_level { - my $pkg = shift; - my $level = shift; - (undef) = shift; # redundant arg - my $callpkg = caller($level); - $pkg->export($callpkg, @_); -} - -############ - -1; - -__END__ - -=head1 NAME - -Test::Tester - *DEPRECATED* Ease testing test modules built with Test::Builder - -=head1 DEPRECATED - -See L<Test::Tester2> for a modern and maintained alternative. - -=head1 SYNOPSIS - - use Test::Tester tests => 6; - - use Test::MyStyle; - - check_test( - sub { - is_mystyle_eq("this", "that", "not eq"); - }, - { - ok => 0, # expect this to fail - name => "not eq", - diag => "Expected: 'this'\nGot: 'that'", - } - ); - -or - - use Test::Tester; - - use Test::More tests => 3; - use Test::MyStyle; - - my ($premature, @results) = run_tests( - sub { - is_database_alive("dbname"); - } - ); - - # now use Test::More::like to check the diagnostic output - - like($results[0]->{diag}, "/^Database ping took \\d+ seconds$"/, "diag"); - -=head1 DESCRIPTION - -If you have written a test module based on Test::Builder then Test::Tester -allows you to test it with the minimum of effort. - -=head1 HOW TO USE (THE EASY WAY) - -From version 0.08 Test::Tester no longer requires you to included anything -special in your test modules. All you need to do is - - use Test::Tester; - -in your test script B<before> any other Test::Builder based modules and away -you go. - -Other modules based on Test::Builder can be used to help with the -testing. In fact you can even use functions from your module to test -other functions from the same module (while this is possible it is -probably not a good idea, if your module has bugs, then -using it to test itself may give the wrong answers). - -The easiest way to test is to do something like - - check_test( - sub { is_mystyle_eq("this", "that", "not eq") }, - { - ok => 0, # we expect the test to fail - name => "not eq", - diag => "Expected: 'this'\nGot: 'that'", - } - ); - -this will execute the is_mystyle_eq test, capturing it's results and -checking that they are what was expected. - -You may need to examine the test results in a more flexible way, for -example, the diagnostic output may be quite long or complex or it may involve -something that you cannot predict in advance like a timestamp. In this case -you can get direct access to the test results: - - my ($premature, @results) = run_tests( - sub { - is_database_alive("dbname"); - } - ); - - like($result[0]->{diag}, "/^Database ping took \\d+ seconds$"/, "diag"); - - -We cannot predict how long the database ping will take so we use -Test::More's like() test to check that the diagnostic string is of the right -form. - -=head1 HOW TO USE (THE HARD WAY) - -I<This is here for backwards compatibility only> - -Make your module use the Test::Tester::Capture object instead of the -Test::Builder one. How to do this depends on your module but assuming that -your module holds the Test::Builder object in $Test and that all your test -routines access it through $Test then providing a function something like this - - sub set_builder - { - $Test = shift; - } - -should allow your test scripts to do - - Test::YourModule::set_builder(Test::Tester->capture); - -and after that any tests inside your module will captured. - -=head1 TEST EVENTS - -The result of each test is captured in a hash. These hashes are the same as -the hashes returned by Test::Builder->details but with a couple of extra -fields. - -These fields are documented in L<Test::Builder> in the details() function - -=over 2 - -=item ok - -Did the test pass? - -=item actual_ok - -Did the test really pass? That is, did the pass come from -Test::Builder->ok() or did it pass because it was a TODO test? - -=item name - -The name supplied for the test. - -=item type - -What kind of test? Possibilities include, skip, todo etc. See -L<Test::Builder> for more details. - -=item reason - -The reason for the skip, todo etc. See L<Test::Builder> for more details. - -=back - -These fields are exclusive to Test::Tester. - -=over 2 - -=item diag - -Any diagnostics that were output for the test. This only includes -diagnostics output B<after> the test result is declared. - -Note that Test::Builder ensures that any diagnostics end in a \n and -it in earlier versions of Test::Tester it was essential that you have -the final \n in your expected diagnostics. From version 0.10 onwards, -Test::Tester will add the \n if you forgot it. It will not add a \n if -you are expecting no diagnostics. See below for help tracking down -hard to find space and tab related problems. - -=item depth - -B<Note:> Depth checking is disabled on newer versions of Test::Builder which no -longer uses $Test::Builder::Level. In these versions this will simple produce a -dummy true result. - -This allows you to check that your test module is setting the correct value -for $Test::Builder::Level and thus giving the correct file and line number -when a test fails. It is calculated by looking at caller() and -$Test::Builder::Level. It should count how many subroutines there are before -jumping into the function you are testing. So for example in - - run_tests( sub { my_test_function("a", "b") } ); - -the depth should be 1 and in - - sub deeper { my_test_function("a", "b") } - - run_tests(sub { deeper() }); - -depth should be 2, that is 1 for the sub {} and one for deeper(). This -might seem a little complex but if your tests look like the simple -examples in this doc then you don't need to worry as the depth will -always be 1 and that's what Test::Tester expects by default. - -B<Note>: if you do not specify a value for depth in check_test() then it -automatically compares it against 1, if you really want to skip the depth -test then pass in undef. - -B<Note>: depth will not be correctly calculated for tests that run from a -signal handler or an END block or anywhere else that hides the call stack. - -=back - -Some of Test::Tester's functions return arrays of these hashes, just -like Test::Builder->details. That is, the hash for the first test will -be array element 1 (not 0). Element 0 will not be a hash it will be a -string which contains any diagnostic output that came before the first -test. This should usually be empty, if it's not, it means something -output diagnostics before any test results showed up. - -=head1 SPACES AND TABS - -Appearances can be deceptive, especially when it comes to emptiness. If you -are scratching your head trying to work out why Test::Tester is saying that -your diagnostics are wrong when they look perfectly right then the answer is -probably whitespace. From version 0.10 on, Test::Tester surrounds the -expected and got diag values with single quotes to make it easier to spot -trailing whitesapce. So in this example - - # Got diag (5 bytes): - # 'abcd ' - # Expected diag (4 bytes): - # 'abcd' - -it is quite clear that there is a space at the end of the first string. -Another way to solve this problem is to use colour and inverse video on an -ANSI terminal, see below COLOUR below if you want this. - -Unfortunately this is sometimes not enough, neither colour nor quotes will -help you with problems involving tabs, other non-printing characters and -certain kinds of problems inherent in Unicode. To deal with this, you can -switch Test::Tester into a mode whereby all "tricky" characters are shown as -\{xx}. Tricky characters are those with ASCII code less than 33 or higher -than 126. This makes the output more difficult to read but much easier to -find subtle differences between strings. To turn on this mode either call -show_space() in your test script or set the TESTTESTERSPACE environment -variable to be a true value. The example above would then look like - - # Got diag (5 bytes): - # abcd\x{20} - # Expected diag (4 bytes): - # abcd - -=head1 COLOUR - -If you prefer to use colour as a means of finding tricky whitespace -characters then you can set the TESTTESTCOLOUR environment variable to a -comma separated pair of colours, the first for the foreground, the second -for the background. For example "white,red" will print white text on a red -background. This requires the Term::ANSIColor module. You can specify any -colour that would be acceptable to the Term::ANSIColor::color function. - -If you spell colour differently, that's no problem. The TESTTESTERCOLOR -variable also works (if both are set then the British spelling wins out). - -=head1 EXPORTED FUNCTIONS - -=head3 ($premature, @results) = run_tests(\&test_sub) - -\&test_sub is a reference to a subroutine. - -run_tests runs the subroutine in $test_sub and captures the results of any -tests inside it. You can run more than 1 test inside this subroutine if you -like. - -$premature is a string containing any diagnostic output from before -the first test. - -@results is an array of test result hashes. - -=head3 cmp_result(\%result, \%expect, $name) - -\%result is a ref to a test result hash. - -\%expect is a ref to a hash of expected values for the test result. - -cmp_result compares the result with the expected values. If any differences -are found it outputs diagnostics. You may leave out any field from the -expected result and cmp_result will not do the comparison of that field. - -=head3 cmp_results(\@results, \@expects, $name) - -\@results is a ref to an array of test results. - -\@expects is a ref to an array of hash refs. - -cmp_results checks that the results match the expected results and if any -differences are found it outputs diagnostics. It first checks that the -number of elements in \@results and \@expects is the same. Then it goes -through each result checking it against the expected result as in -cmp_result() above. - -=head3 ($premature, @results) = check_tests(\&test_sub, \@expects, $name) - -\&test_sub is a reference to a subroutine. - -\@expect is a ref to an array of hash refs which are expected test results. - -check_tests combines run_tests and cmp_tests into a single call. It also -checks if the tests died at any stage. - -It returns the same values as run_tests, so you can further examine the test -results if you need to. - -=head3 ($premature, @results) = check_test(\&test_sub, \%expect, $name) - -\&test_sub is a reference to a subroutine. - -\%expect is a ref to an hash of expected values for the test result. - -check_test is a wrapper around check_tests. It combines run_tests and -cmp_tests into a single call, checking if the test died. It assumes -that only a single test is run inside \&test_sub and include a test to -make sure this is true. - -It returns the same values as run_tests, so you can further examine the test -results if you need to. - -=head3 show_space() - -Turn on the escaping of characters as described in the SPACES AND TABS -section. - -=head1 HOW IT WORKS - -Normally, a test module (let's call it Test:MyStyle) calls -Test::Builder->new to get the Test::Builder object. Test::MyStyle calls -methods on this object to record information about test results. When -Test::Tester is loaded, it replaces Test::Builder's new() method with one -which returns a Test::Tester::Delegate object. Most of the time this object -behaves as the real Test::Builder object. Any methods that are called are -delegated to the real Test::Builder object so everything works perfectly. -However once we go into test mode, the method calls are no longer passed to -the real Test::Builder object, instead they go to the Test::Tester::Capture -object. This object seems exactly like the real Test::Builder object, -except, instead of outputting test results and diagnostics, it just records -all the information for later analysis. - -=head1 CAVEATS - -Support for calling Test::Builder->note is minimal. It's implemented -as an empty stub, so modules that use it will not crash but the calls -are not recorded for testing purposes like the others. Patches -welcome. - -=head1 SEE ALSO - -L<Test::Builder> the source of testing goodness. L<Test::Builder::Tester> -for an alternative approach to the problem tackled by Test::Tester - -captures the strings output by Test::Builder. This means you cannot get -separate access to the individual pieces of information and you must predict -B<exactly> what your test will output. - -=head1 AUTHOR - -This module is copyright 2005 Fergal Daly <fergal@esatclear.ie>, some parts -are based on other people's work. - -Plan handling lifted from Test::More. written by Michael G Schwern -<schwern@pobox.com>. - -Test::Tester::Capture is a cut down and hacked up version of Test::Builder. -Test::Builder was written by chromatic <chromatic@wgz.org> and Michael G -Schwern <schwern@pobox.com>. - -=head1 LICENSE - -Under the same license as Perl itself - -See http://www.perl.com/perl/misc/Artistic.html - -=cut diff --git a/cpan/Test-Simple/lib/Test/Tester/Capture.pm b/cpan/Test-Simple/lib/Test/Tester/Capture.pm deleted file mode 100644 index 38df7d6b6e..0000000000 --- a/cpan/Test-Simple/lib/Test/Tester/Capture.pm +++ /dev/null @@ -1,233 +0,0 @@ -use strict; - -package Test::Tester::Capture; - -#warn "Test::Tester::Capture is deprecated, see Test::Tester2\n"; - -use Test::Builder; - -use vars qw( @ISA ); -@ISA = qw( Test::Builder ); - -# Make Test::Tester::Capture thread-safe for ithreads. -BEGIN { - use Config; - if ($Config{useithreads}) { - require threads::shared; - threads::shared->import; - } - else { - *share = sub { 0 }; - *lock = sub { 0 }; - } -} - -my $Curr_Test = 0; -share($Curr_Test); -my @Test_Results = (); -share(@Test_Results); -my $Prem_Diag = {diag => ""}; -share($Curr_Test); - -sub new { - # Test::Tester::Capgture::new used to just return __PACKAGE__ - # because Test::Builder::new enforced it's singleton nature by - # return __PACKAGE__. That has since changed, Test::Builder::new now - # returns a blessed has and around version 0.78, Test::Builder::todo - # started wanting to modify $self. To cope with this, we now return - # a blessed hash. This is a short-term hack, the correct thing to do - # is to detect which style of Test::Builder we're dealing with and - # act appropriately. - - my $class = shift; - return bless {}, $class; -} - -sub ok { - my ($self, $test, $name) = @_; - - # $test might contain an object which we don't want to accidentally - # store, so we turn it into a boolean. - $test = $test ? 1 : 0; - - lock $Curr_Test; - $Curr_Test++; - - my ($pack, $file, $line) = $self->caller; - - my $todo = $self->todo($pack); - - my $result = {}; - share($result); - - unless ($test) { - @$result{'ok', 'actual_ok'} = (($todo ? 1 : 0), 0); - } - else { - @$result{'ok', 'actual_ok'} = (1, $test); - } - - if (defined $name) { - $name =~ s|#|\\#|g; # # in a name can confuse Test::Harness. - $result->{name} = $name; - } - else { - $result->{name} = ''; - } - - if ($todo) { - my $what_todo = $todo; - $result->{reason} = $what_todo; - $result->{type} = 'todo'; - } - else { - $result->{reason} = ''; - $result->{type} = ''; - } - - $Test_Results[$Curr_Test - 1] = $result; - - unless ($test) { - my $msg = $todo ? "Failed (TODO)" : "Failed"; - $result->{fail_diag} = (" $msg test ($file at line $line)\n"); - } - - $result->{diag} = ""; - $result->{_level} = $Test::Builder::Level; - $result->{_depth} = Test::Tester::find_run_tests(); - - return $test ? 1 : 0; -} - -sub skip { - my ($self, $why) = @_; - $why ||= ''; - - lock($Curr_Test); - $Curr_Test++; - - my %result; - share(%result); - %result = ( - 'ok' => 1, - actual_ok => 1, - name => '', - type => 'skip', - reason => $why, - diag => "", - _level => $Test::Builder::Level, - _depth => Test::Tester::find_run_tests(), - ); - $Test_Results[$Curr_Test - 1] = \%result; - - return 1; -} - -sub todo_skip { - my ($self, $why) = @_; - $why ||= ''; - - lock($Curr_Test); - $Curr_Test++; - - my %result; - share(%result); - %result = ( - 'ok' => 1, - actual_ok => 0, - name => '', - type => 'todo_skip', - reason => $why, - diag => "", - _level => $Test::Builder::Level, - _depth => Test::Tester::find_run_tests(), - ); - - $Test_Results[$Curr_Test - 1] = \%result; - - return 1; -} - -sub diag { - my ($self, @msgs) = @_; - return unless @msgs; - - # Prevent printing headers when compiling (i.e. -c) - return if $^C; - - # Escape each line with a #. - foreach (@msgs) { - $_ = 'undef' unless defined; - } - - push @msgs, "\n" unless $msgs[-1] =~ /\n\Z/; - - my $result = $Curr_Test ? $Test_Results[$Curr_Test - 1] : $Prem_Diag; - - $result->{diag} .= join("", @msgs); - - return 0; -} - -sub details { - return @Test_Results; -} - -# Stub. Feel free to send me a patch to implement this. -sub note { -} - -sub explain { - return Test::Builder::explain(@_); -} - -sub premature { - return $Prem_Diag->{diag}; -} - -sub current_test { - if (@_ > 1) { - die "Don't try to change the test number!"; - } - else { - return $Curr_Test; - } -} - -sub reset { - $Curr_Test = 0; - @Test_Results = (); - $Prem_Diag = {diag => ""}; -} - -1; - -__END__ - -=head1 NAME - -Test::Tester::Capture - *DEPRECATED* Help testing test modules built with Test::Builder - -=head1 DEPRECATED - -See L<Test::Tester2> for a modern and maintained alternative. - -=head1 DESCRIPTION - -This is a subclass of Test::Builder that overrides many of the methods so -that they don't output anything. It also keeps track of it's own set of test -results so that you can use Test::Builder based modules to perform tests on -other Test::Builder based modules. - -=head1 AUTHOR - -Most of the code here was lifted straight from Test::Builder and then had -chunks removed by Fergal Daly <fergal@esatclear.ie>. - -=head1 LICENSE - -Under the same license as Perl itself - -See http://www.perl.com/perl/misc/Artistic.html - -=cut diff --git a/cpan/Test-Simple/lib/Test/Tester/CaptureRunner.pm b/cpan/Test-Simple/lib/Test/Tester/CaptureRunner.pm deleted file mode 100644 index 62bb7f2441..0000000000 --- a/cpan/Test-Simple/lib/Test/Tester/CaptureRunner.pm +++ /dev/null @@ -1,75 +0,0 @@ -# $Header: /home/fergal/my/cvs/Test-Tester/lib/Test/Tester/CaptureRunner.pm,v 1.3 2003/03/05 01:07:55 fergal Exp $ -use strict; - -#warn "Test::Tester::CaptureRunner is deprecated, see Test::Tester2\n"; - -package Test::Tester::CaptureRunner; - -use Test::Tester::Capture; -require Exporter; - -sub new { - my $pkg = shift; - my $self = bless {}, $pkg; - return $self; -} - -sub run_tests { - my $self = shift; - - my $test = shift; - - capture()->reset; - - $self->{StartLevel} = $Test::Builder::Level; - &$test(); -} - -sub get_results { - my $self = shift; - my @results = capture()->details; - - my $start = $self->{StartLevel}; - foreach my $res (@results) { - next if defined $res->{depth}; - my $depth = $res->{_depth} - $res->{_level} - $start - 3; - $res->{depth} = $depth; - } - - return @results; -} - -sub get_premature { - return capture()->premature; -} - -sub capture { - return Test::Tester::Capture->new; -} - -__END__ - -=head1 NAME - -Test::Tester::CaptureRunner - *DEPRECATED* Help testing test modules built with Test::Builder - -=head1 DEPRECATED - -See L<Test::Tester2> for a modern and maintained alternative. - -=head1 DESCRIPTION - -This stuff if needed to allow me to play with other ways of monitoring the -test results. - -=head1 AUTHOR - -Copyright 2003 by Fergal Daly <fergal@esatclear.ie>. - -=head1 LICENSE - -Under the same license as Perl itself - -See http://www.perl.com/perl/misc/Artistic.html - -=cut diff --git a/cpan/Test-Simple/lib/Test/Tester/Delegate.pm b/cpan/Test-Simple/lib/Test/Tester/Delegate.pm deleted file mode 100644 index 84691a2336..0000000000 --- a/cpan/Test-Simple/lib/Test/Tester/Delegate.pm +++ /dev/null @@ -1,32 +0,0 @@ -use strict; -use warnings; - -#warn "Test::Tester::Delegate is deprecated, see Test::Tester2\n"; - -package Test::Tester::Delegate; - -use vars '$AUTOLOAD'; - -sub new { - my $pkg = shift; - - my $obj = shift; - my $self = bless {}, $pkg; - - return $self; -} - -sub AUTOLOAD { - my ($sub) = $AUTOLOAD =~ /.*::(.*?)$/; - - return if $sub eq "DESTROY"; - - my $obj = $_[0]->{Object}; - - my $ref = $obj->can($sub); - shift(@_); - unshift(@_, $obj); - goto &$ref; -} - -1; diff --git a/cpan/Test-Simple/lib/Test/Tester2.pm b/cpan/Test-Simple/lib/Test/Tester2.pm deleted file mode 100644 index 3a1fe5f036..0000000000 --- a/cpan/Test-Simple/lib/Test/Tester2.pm +++ /dev/null @@ -1,883 +0,0 @@ -package Test::Tester2; -use strict; -use warnings; - -use Test::Builder 1.301001; -use Test::Builder::Stream; -use Test::Builder::Util qw/try/; - -use Scalar::Util qw/blessed reftype/; -use Carp qw/croak/; - -use Test::Builder::Provider; -gives qw/intercept display_events display_event render_event/; -provides qw/events_are/; - -sub intercept(&) { - my ($code) = @_; - - my @events; - - my ($ok, $error) = try { - Test::Builder::Stream->intercept( - sub { - my $stream = shift; - $stream->exception_followup; - - $stream->listen( - INTERCEPTOR => sub { - my ($item) = @_; - push @events => $item; - } - ); - $code->(); - } - ); - }; - - die $error unless $ok || (blessed($error) && $error->isa('Test::Builder::Event')); - - return \@events; -} - -sub events_are { - my ($events, @checks) = @_; - - my @res_list = @$events; - - my $overall_name; - my $seek = 0; - my $skip = 0; - my $ok = 1; - my $wnum = 0; - my @diag; - - while($ok && @checks) { - my $action = shift @checks; - - if ($action =~ m/^(!)?filter_providers?$/) { - @res_list = _filter_list( - $1 || 0, - shift(@checks), - sub { $_[0]->trace->report->provider_tool->{package} }, - @res_list - ); - next; - } - elsif ($action =~ m/^(!)?filter_types?$/) { - @res_list = _filter_list( - $1 || 0, - shift(@checks), - sub { $_[0]->type }, - @res_list - ); - next; - } - elsif ($action eq 'skip') { - $skip = shift @checks; - next if $skip eq '*'; - - shift(@res_list) while $skip--; - - next; - } - elsif ($action eq 'seek') { - $seek = shift @checks; - next; - } - elsif ($action eq 'end') { - if(@res_list) { - $ok = 0; - push @diag => "Expected end of events, but more events remain"; - } - $overall_name = shift @checks; - last; - } - elsif ($action eq 'name') { - $overall_name = shift @checks; - next; - } - - my $type = $action; - my $got = shift @res_list; - my $want = shift @checks; $wnum++; - my $id = "$type " . (delete $want->{id} || $wnum); - - $want ||= "(UNDEF)"; - croak "($id) '$type' must be paired with a hashref, but you gave: '$want'" - unless $want && ref $want && reftype $want eq 'HASH'; - - $got = shift(@res_list) while ($skip || $seek) && $got && $type ne $got->type; - $skip = 0; - - if (!$got) { - $ok = 0; - push @diag => "($id) Wanted event type '$type', But no more events left to check!"; - push @diag => "Full event found was: " . render_event($got); - last; - } - - if ($type ne $got->type) { - $ok = 0; - push @diag => "($id) Wanted event type '$type', But got: '" . $got->type . "'"; - push @diag => "Full event found was: " . render_event($got); - last; - } - - my $fields = _simplify_event($got); - - for my $key (keys %$want) { - my $wval = $want->{$key}; - my $rtype = reftype($wval) || ""; - $rtype = 'REGEXP' if $rtype eq 'SCALAR' && "$wval" =~ m/^\(\?[-xism]{5}:.*\)$/; - my $gval = $fields->{$key}; - - my $field_ok; - if ($rtype eq 'CODE') { - $field_ok = $wval->($gval); - $gval = "(UNDEF)" unless defined $gval; - push @diag => "($id) $key => '$gval' did not validate via coderef" unless $field_ok; - } - elsif ($rtype eq 'REGEXP') { - $field_ok = defined $gval && $gval =~ $wval; - $gval = "(UNDEF)" unless defined $gval; - push @diag => "($id) $key => '$gval' does not match $wval" unless $field_ok; - } - elsif(!exists $fields->{$key}) { - $field_ok = 0; - push @diag => "($id) Wanted $key => '$wval', but '$key' does not exist" unless $field_ok; - } - elsif(defined $wval && !defined $gval) { - $field_ok = 0; - push @diag => "($id) Wanted $key => '$wval', but '$key' is not defined" unless $field_ok; - } - elsif($wval =~ m/^\d+x?[\d\.e_]*$/i && $gval =~ m/^\d+x?[\d\.e_]*$/i) { - $field_ok = $wval == $gval; - push @diag => "($id) Wanted $key => '$wval', but got $key => '$gval'" unless $field_ok; - } - else { - $field_ok = "$wval" eq "$gval"; - push @diag => "($id) Wanted $key => '$wval', but got $key => '$gval'" unless $field_ok; - } - - $ok &&= $field_ok; - } - - unless ($ok) { - push @diag => "Full event found was: " . render_event($got); - last; - } - } - - # Find the test name - while(my $action = shift @checks) { - next unless $action eq 'end' || $action eq 'name'; - $overall_name = shift @checks; - } - - builder()->ok($ok, $overall_name || "Got expected events", @diag); - return $ok; -} - -sub display_events { - my ($events) = @_; - display_event($_) for @$events; -} - -sub display_event { - print STDERR render_event(@_); -} - -sub render_event { - my ($event) = @_; - - my @order = qw/ - name bool real_bool action max - directive reason in_todo - package file line pid - depth is_subtest source tests_failed tests_run - tool_name tool_package - message - tap - /; - - my $fields = _simplify_event($event); - - my %seen; - my $out = "$fields->{type} => {\n"; - for my $field (@order, keys %$fields) { - next if $field eq 'type'; - next if $seen{$field}++; - next unless defined $fields->{$field}; - if ($fields->{$field} =~ m/\n/sm) { - $out .= " $field:\n"; - for my $line (split /\n+/sm, $fields->{$field}) { - next unless $line; - next if $line eq "\n"; - $out .= " $line\n"; - } - } - else { - $out .= " $field: $fields->{$field}\n"; - } - } - $out .= "}\n"; - - return $out; -} - -sub _simplify_event { - my ($r) = @_; - - my $fields = {map { ref $r->{$_} ? () : ($_ => $r->{$_}) } keys %$r}; - $fields->{type} = $r->type; - - if ($r->trace && $r->trace->report) { - my $report = $r->trace->report; - @{$fields}{qw/line file package/} = map { $report->$_ } qw/line file package/; - @{$fields}{qw/tool_package tool_name/} = @{$report->provider_tool}{qw/package name/} if $report->provider_tool; - } - - $fields->{tap} = $r->to_tap if $r->can('to_tap'); - chomp($fields->{tap}) if $fields->{tap}; - - return $fields; -} - -sub _filter_list { - my ($negate, $args, $fetch, @items) = @_; - - my (@regex, @code, %name); - for my $arg (ref $args && reftype $args eq 'ARRAY' ? @$args : ($args)) { - my $reftype = reftype $arg || ""; - if ($reftype eq 'REGEXP') { - push @regex => $arg; - } - elsif($reftype eq 'CODE') { - push @code => $arg; - } - else { - $name{$arg}++; - } - } - - my @newlist; - for my $item (@items) { - my $val = $fetch->($item) || next; - - my $match = $name{$val} || (grep { $_->($val) } @code) || (grep { $val =~ $_ } @regex) || 0; - $match = !$match if $negate; - push @newlist => $item if $match; - } - return @newlist; -} - - -1; - -__END__ - -=head1 NAME - -Test::Tester2 - Tools for validating the events produced by your testing -tools. - -=head1 DESCRIPTION - -Unit tests are tools to validate your code. This library provides tools to -validate your tools! - -=head1 TEST COMPONENT MAP - - [Test Script] > [Test Tool] > [Test::Builder] > [Test::Bulder::Stream] > [Event Formatter] - -A test script uses a test tool such as L<Test::More>, which uses Test::Builder -to produce events. The events are sent to L<Test::Builder::Stream> which then -forwards them on to one or more formatters. The default formatter is -L<Test::Builder::Fromatter::TAP> which produces TAP output. - -=head1 SYNOPSIS - - use Test::More; - use Test::Tester2; - - # Intercept all the Test::Builder::Event objects produced in the block. - my $events = intercept { - ok(1, "pass"); - ok(0, "fail"); - diag("xxx"); - }; - - # By Hand - is($events->[0]->{bool}, 1, "First event passed"); - - # With help - events_are( - $events, - ok => { id => 'a', bool => 1, name => 'pass' }, - - ok => { id => 'b1', bool => 0, name => 'fail', line => 7, file => 'my_test.t' }, - diag => { id => 'b2', message => qr/Failed test 'fail'/, line => 7, file => 'my_test.t' }, - - diag => { id => 'c', message => qr/xxx/ }, - - end => 'Name of this test', - ); - - # You can combine the 2: - events_are( - intercept { ... }, - ok => { bool => 1 }, - ... - ); - - done_testing; - -=head1 EXPORTS - -=over 4 - -=item $events = intercept { ... } - -Capture the L<Test::Builder::Event> objects generated by tests inside the block. - -=item events_are($events, ...) - -Validate the given events. - -=item $dump = render_event($event) - -This will produce a simplified string of the event data for easy reading. This -is useful in debugging, in fact this is the same string that events_are will -print when there is a mismatch to show you the event. - -=item display_event($event) - -=item display_events($events) - -These will print the render_event string to STDERR. - -=back - -=head1 INTERCEPTING EVENTS - - my $events = intercept { - ok(1, "pass"); - ok(0, "fail"); - diag("xxx"); - }; - -Any events generated within the block will be intercepted and placed inside -the C<$events> array reference. - -=head2 EVENT TYPES - -All events will be subclasses of L<Test::Builder::Event> - -=over 4 - -=item L<Test::Builder::Event::Ok> - -=item L<Test::Builder::Event::Note> - -=item L<Test::Builder::Event::Diag> - -=item L<Test::Builder::Event::Plan> - -=item L<Test::Builder::Event::Finish> - -=item L<Test::Builder::Event::Bail> - -=item L<Test::Builder::Event::Child> - -=back - -=head1 VALIDATING EVENTS - - my $events = intercept { - ok(1, "pass"); - ok(0, "fail"); - diag("xxx"); - }; - - events_are( - $events, - name => 'Name of the test', # Name this overall test - ok => { id => 'a', bool => 1, name => 'pass' }, # check an 'ok' with ID 'a' - ok => { id => 'b', bool => 0, name => 'fail' }, # check an 'ok' with ID 'b' - diag => { message => qr/Failed test 'fail'/ }, # check a 'diag' no ID - diag => { message => qr/xxx/ }, # check a 'diag' no ID - 'end' # directive 'end' - ); - -The first argument to C<events_are()> must be an arrayref containing -L<Test::Builder::Event> objects. Such an arrayref can be produced by -C<intercept { ... }>. - -All additional arguments to C<events_are()> must be key value pairs (except -for 'end'). The key must either be a directive, or a event-type optionally -followed by a name. Values for directives are specific to the directives. -Values for event types must always be hashrefs with 0 or more fields to check. - -=head2 TYPES AND IDS - -Since you can provide many checks, it can be handy to ID them. If you do not -provide an ID then they will be assigned a number in sequence starting at 1. -You can specify an ID by passing in the 'id' parameter. - - ok => { id => 'foo', ... } - -This can be very helpful when tracking down the location of a failing check. - -=head2 VALIDATING FIELDS - -The hashref against which events are checked is composed of keys, and values. -The values may be regular values, which are checked for equality with the -corresponding property of the event object. Alternatively you can provide a -regex to match against, or a coderef that validates it for you. - -=over 4 - -=item field => 'exact_value', - -The specified field must exactly match the given value, be it number or string. - -=item field => qr/.../, - -The specified field must match the regular expression. - -=item field => sub { my $val = shift; return $val ? 1 : 0 }, - -The value from the event will be passed into your coderef as the only -argument. The coderef should return true for valid, false for invalid. - -=back - -=head2 FIELDS PRESENT FOR ALL EVENT TYPES - -=over 4 - -=item pid - -The process ID the event came from. - -=item depth - -Usually 0, but will be 1 for subtests, 2 for nested subtests, etc. - -=item source - -Usually $0, but in a subtest it will be the name of the subtest that generated -the event. - -=item in_todo - -True if the event was generated inside a todo. - -=item line - -Line number to which failures will be reported. - -(This is actually usually undefined for plan and finish) - -=item file - -File to which failures will be reported - -(This is actually usually undefined for plan and finish) - -=item package - -package to which errors will be reported - -(This is actually usually undefined for plan and finish) - -=item tool_package - -B<Note:> Only present if applicable. - -If the event was generated by an L<Test::Builder::Provider>, this will tell -you what package provided the tool. - -For example, if the event was provided by C<Test::More::ok()> this will -contain C<'Test::More'>. - -=item tool_name - -B<Note:> Only present if applicable. - -If the event was generated by an L<Test::Builder::Provider>, this will tell -you what the tool was called. - -For example, if the event was provided by C<Test::More::ok()> this will -contain C<'ok'>. - -=item tap - -B<Note:> Only present if applicable. - -The TAP string that would be printed by the TAP formatter. This is -particularily useful for diags since it translates filenames into the proper -encoding, the original message however will be untranslated. - -=back - -=head2 EVENT SPECIFIC FIELDS - -=head3 ok - -=over 4 - -=item bool - -True if the test passed (or failed but is in todo). - -=item real_bool - -The actual event of the test, not mangled by todo. - -=item name - -The name of the test. - -=item todo - -The todo reason. - -=item skip - -The reason the test was skipped. - -=back - -=head3 diag and note - -=over 4 - -=item message - -Message for the diag/note. - -=back - -=head3 plan - -=over 4 - -=item max - -Will be a number if a numeric plan was issued. - -=item directive - -Usually empty, but may be 'skip_all' or 'no_plan' - -=item reason - -Reason for the directive. - -=back - -=head3 finish - -=over 4 - -=item tests_run - -Number of tests that ran. - -=item tests_failed - -Number of tests that failed. - -=back - -=head3 bail - -=over 4 - -=item reason - -Reason the test bailed. - -=back - -=head3 child - -=over 4 - -=item name - -Name of the child - -=item is_subtest - -True if the child was created to start subtests - -=item action - -Always either 'push' or 'pop'. 'push' when a child is created, 'pop' when a -child is destroyed. - -=back - -=head2 VALIDATION DIRECTIVES - -These provide ways to filter or skip events. They apply as seen, and do not -effect checks before they are seen. - -=head3 filter_provider - -=over 4 - -=item filter_provider => ... - -=item filter_providers => [...] - -=item '!filter_provider' => ... - -=item '!filter_providers' => [...] - -Filter events so that you only see ones where the tool provider matches one or -more of the conditions specified. Conditions may be a value to match, a regex -to match, or a codref that takes the provider name and validates it returning -either true or false. - -Prefixing with '!' will negate the matching, that is only tool providers that -do not match will be checked. - -The filter will remove any events that do not match for the remainder of the -checks. Checks before the directive are used will see unfiltered events. - -example: - - my $events = intercept { - Test::More::ok(1, "foo"); - Test::More::ok(1, "bar"); - Test::More::ok(1, "baz"); - Test::Simple::ok(1, "bat"); - }; - - events_are( - $events, - ok => { name => "foo" }, - ok => { name => "bar" }, - - # From this point on, only more 'Test::Simple' events will be checked. - filter_provider => 'Test::Simple', - - # So it goes right to the Test::Simple event. - ok => { name => "bat" }, - ); - -=back - -=head3 filter_type - -=over 4 - -=item filter_type => ... - -=item filter_types => [...] - -=item '!filter_type' => ... - -=item '!filter_types' => [...] - -Filter events so that you only see ones where the type matches one or more of -the conditions specified. Conditions may be a value to match, a regex to match, -or a codref that takes the provider name and validates it returning either true -or false. - -Prefixing with '!' will negate the matching, that is only types that do not -match will be checked. - -The filter will remove any events that do not match for the remainder of the -checks. Checks before the directive are used will see unfiltered events. - -example: - - my $events = intercept { - ok(1, "foo"); - diag("XXX"); - - ok(1, "bar"); - diag("YYY"); - - ok(1, "baz"); - diag("ZZZ"); - }; - - events_are( - $events, - ok => { name => "foo" }, - diag => { message => 'XXX' }, - ok => { name => "bar" }, - diag => { message => 'YYY' }, - - # From this point on, only 'diag' types will be seen - filter_type => 'diag', - - # So it goes right to the next diag. - diag => { message => 'ZZZ' }, - ); - -=back - -=head3 skip - -=over 4 - -=item skip => # - -=item skip => '*' - -The numeric form will skip the next # events. - -example: - - my $events = intercept { - ok(1, "foo"); - diag("XXX"); - - ok(1, "bar"); - diag("YYY"); - - ok(1, "baz"); - diag("ZZZ"); - }; - - events_are( - $events, - ok => { name => "foo" }, - - skip => 1, # Skips the diag - - ok => { name => "bar" }, - - skip => 2, # Skips a diag and an ok - - diag => { message => 'ZZZ' }, - ); - -When '*' is used as an argument, the checker will skip until a event type -matching the next type to check is found. - -example: - - my $events = intercept { - ok(1, "foo"); - - diag("XXX"); - diag("YYY"); - diag("ZZZ"); - - ok(1, "bar"); - }; - - events_are( - $events, - ok => { name => "foo" }, - - skip => '*', # Skip until the next 'ok' is found since that is our next check. - - ok => { name => "bar" }, - ); - -=back - -=head3 seek - -=over 4 - -=item seek => $BOOL - -When turned on (true), any unexpected events will be skipped. You can turn -this on and off any time. - - my $events = intercept { - ok(1, "foo"); - - diag("XXX"); - diag("YYY"); - - ok(1, "bar"); - diag("ZZZ"); - - ok(1, "baz"); - }; - - events_are( - $events, - - seek => 1, - ok => { name => "foo" }, - # The diags are ignored, - ok => { name => "bar" }, - - seek => 0, - - # This will fail because the diag is not ignored anymore. - ok => { name => "baz" }, - ); - -=back - -=head3 name - -=over 4 - -=item name => "Name of test" - -Used to name the test when not using 'end'. - -=back - -=head3 end - -=over 4 - -=item 'end' - -=item end => 'Test Name' - -Used to say that there should not be any more events. Without this any events -after your last check are simply ignored. This will generate a failure if any -unchecked events remain. - -This is also how you can name the overall test. The default name is 'Got -expected events'. - -=back - -=head1 SEE ALSO - -=over 4 - -=item L<Test::Tester> *Deprecated* - -Deprecated predecessor to this module - -=item L<Test::Builder::Tester> *Deprecated* - -The original test tester, checks TAP output - -=back - -=head1 AUTHORS - -=over 4 - -=item Chad Granum E<lt>exodist@cpan.orgE<gt> - -=back - -=head1 COPYRIGHT - -Copyright 2014 by Chad Granum E<lt>exodist7@gmail.comE<gt> - -This program is free software; you can redistribute it and/or -modify it under the same terms as Perl itself. - -See F<http://www.perl.com/perl/misc/Artistic.html> - diff --git a/cpan/Test-Simple/lib/Test/Tutorial.pod b/cpan/Test-Simple/lib/Test/Tutorial.pod index a71a9c1b3f..8badf38e9f 100644 --- a/cpan/Test-Simple/lib/Test/Tutorial.pod +++ b/cpan/Test-Simple/lib/Test/Tutorial.pod @@ -90,7 +90,7 @@ along. [2] This is the hardest part of testing, where do you start? People often get overwhelmed at the apparent enormity of the task of testing a whole module. -The best place to start is at the beginning. L<Date::ICal> is an +The best place to start is at the beginning. C<Date::ICal> is an object-oriented module, and that means you start by making an object. Test C<new()>. @@ -176,18 +176,18 @@ Run that and you get: ok 8 - year() # Looks like you failed 1 tests of 8. -Whoops, a failure! [4] L<Test::Simple> helpfully lets us know on what line the +Whoops, a failure! [4] C<Test::Simple> helpfully lets us know on what line the failure occurred, but not much else. We were supposed to get 17, but we didn't. What did we get?? Dunno. You could re-run the test in the debugger or throw in some print statements to find out. -Instead, switch from L<Test::Simple> to L<Test::More>. L<Test::More> -does everything L<Test::Simple> does, and more! In fact, L<Test::More> does -things I<exactly> the way L<Test::Simple> does. You can literally swap -L<Test::Simple> out and put L<Test::More> in its place. That's just what +Instead, switch from L<Test::Simple> to L<Test::More>. C<Test::More> +does everything C<Test::Simple> does, and more! In fact, C<Test::More> does +things I<exactly> the way C<Test::Simple> does. You can literally swap +C<Test::Simple> out and put C<Test::More> in its place. That's just what we're going to do. -L<Test::More> does more than L<Test::Simple>. The most important difference at +C<Test::More> does more than C<Test::Simple>. The most important difference at this point is it provides more informative ways to say "ok". Although you can write almost any test with a generic C<ok()>, it can't tell you what went wrong. The C<is()> function lets us declare that something is supposed to be @@ -210,7 +210,7 @@ the same as something else: is( $ical->month, 10, ' month()' ); is( $ical->year, 1964, ' year()' ); -"Is C<< $ical->sec >> 47?" "Is C<< $ical->min >> 12?" With C<is()> in place, +"Is C<$ical-E<gt>sec> 47?" "Is C<$ical-E<gt>min> 12?" With C<is()> in place, you get more information: 1..8 @@ -227,7 +227,7 @@ you get more information: ok 8 - year() # Looks like you failed 1 tests of 8. -Aha. C<< $ical->day >> returned 16, but we expected 17. A +Aha. C<$ical-E<gt>day> returned 16, but we expected 17. A quick check shows that the code is working fine, we made a mistake when writing the tests. Change it to: @@ -297,7 +297,7 @@ Now we can test bunches of dates by just adding them to C<%ICal_Dates>. Now that it's less work to test with more dates, you'll be inclined to just throw more in as you think of them. Only problem is, every time we add to that we have to keep adjusting -the L<< use Test::More tests => ## >> line. That can rapidly get +the C<use Test::More tests =E<gt> ##> line. That can rapidly get annoying. There are ways to make this work better. First, we can calculate the plan dynamically using the C<plan()> @@ -324,10 +324,10 @@ running some tests, don't know how many. [6] done_testing(); # reached the end safely -If you don't specify a plan, L<Test::More> expects to see C<done_testing()> +If you don't specify a plan, C<Test::More> expects to see C<done_testing()> before your program exits. It will warn you if you forget it. You can give C<done_testing()> an optional number of tests you expected to run, and if the -number ran differs, L<Test::More> will give you another kind of warning. +number ran differs, C<Test::More> will give you another kind of warning. =head2 Informative names @@ -417,7 +417,7 @@ the test. A little bit of magic happens here. When running on anything but MacOS, all the tests run normally. But when on MacOS, C<skip()> causes the entire contents of the SKIP block to be jumped over. It never runs. Instead, -C<skip()> prints special output that tells L<Test::Harness> that the tests have +C<skip()> prints special output that tells C<Test::Harness> that the tests have been skipped. 1..7 @@ -446,7 +446,7 @@ The tests are wholly and completely skipped. [10] This will work. =head2 Todo tests -While thumbing through the L<Date::ICal> man page, I came across this: +While thumbing through the C<Date::ICal> man page, I came across this: ical @@ -497,12 +497,12 @@ Now when you run, it's a little different: # got: '20010822T201551Z' # expected: '20201231Z' -L<Test::More> doesn't say "Looks like you failed 1 tests of 1". That '# -TODO' tells L<Test::Harness> "this is supposed to fail" and it treats a +C<Test::More> doesn't say "Looks like you failed 1 tests of 1". That '# +TODO' tells C<Test::Harness> "this is supposed to fail" and it treats a failure as a successful test. You can write tests even before you've fixed the underlying code. -If a TODO test passes, L<Test::Harness> will report it "UNEXPECTEDLY +If a TODO test passes, C<Test::Harness> will report it "UNEXPECTEDLY SUCCEEDED". When that happens, remove the TODO block with C<local $TODO> and turn it into a real test. @@ -517,7 +517,7 @@ in mind, it's very important to ensure your module works under taint mode. It's very simple to have your tests run under taint mode. Just throw -a C<-T> into the C<#!> line. L<Test::Harness> will read the switches +a C<-T> into the C<#!> line. C<Test::Harness> will read the switches in C<#!> and use them to run your tests. #!/usr/bin/perl -Tw @@ -558,7 +558,7 @@ We'll get to testing the contents of lists later. But what happens if your test program dies halfway through?! Since we didn't say how many tests we're going to run, how can we know it -failed? No problem, L<Test::More> employs some magic to catch that death +failed? No problem, C<Test::More> employs some magic to catch that death and turn the test into a failure, even if every test passed up to that point. diff --git a/cpan/Test-Simple/lib/Test/use/ok.pm b/cpan/Test-Simple/lib/Test/use/ok.pm deleted file mode 100644 index e55e0902a5..0000000000 --- a/cpan/Test-Simple/lib/Test/use/ok.pm +++ /dev/null @@ -1,67 +0,0 @@ -package Test::use::ok; -use strict; -use warnings; -use 5.005; - -our $VERSION = '1.301001_040'; -$VERSION = eval $VERSION; ## no critic (BuiltinFunctions::ProhibitStringyEval) - -1; -__END__ - -=encoding utf8 - -=head1 NAME - -Test::use::ok - Alternative to Test::More::use_ok - -=head1 SYNOPSIS - - use ok 'Some::Module'; - -=head1 DESCRIPTION - -According to the B<Test::More> documentation, it used to be recommended to run -C<use_ok()> inside a C<BEGIN> block, so functions are exported at compile-time -and prototypes are properly honored. - -That is, instead of writing this: - - use_ok( 'Some::Module' ); - use_ok( 'Other::Module' ); - -One should write this: - - BEGIN { use_ok( 'Some::Module' ); } - BEGIN { use_ok( 'Other::Module' ); } - -However, people often either forget to add C<BEGIN>, or mistakenly group -C<use_ok> with other tests in a single C<BEGIN> block, which can create subtle -differences in execution order. - -With this module, simply change all C<use_ok> in test scripts to C<use ok>, -and they will be executed at C<BEGIN> time. The explicit space after C<use> -makes it clear that this is a single compile-time action. - -=head1 SEE ALSO - -L<Test::More> - -=head1 MAINTAINERS - -=over 4 - -=item Chad Granum E<lt>exodist@cpan.orgE<gt> - -=back - -=head1 CC0 1.0 Universal - -To the extent possible under law, 唐鳳 has waived all copyright and related -or neighboring rights to L<Test-use-ok>. - -This work is published from Taiwan. - -L<http://creativecommons.org/publicdomain/zero/1.0> - -=cut diff --git a/cpan/Test-Simple/lib/ok.pm b/cpan/Test-Simple/lib/ok.pm deleted file mode 100644 index 48c6a37f4f..0000000000 --- a/cpan/Test-Simple/lib/ok.pm +++ /dev/null @@ -1,61 +0,0 @@ -package ok; -use strict; -use warnings; - -use Test::More 1.301001 (); -use Carp qw/croak/; - -our $VERSION = '1.301001_040'; -$VERSION = eval $VERSION; ## no critic (BuiltinFunctions::ProhibitStringyEval) - -sub import { - shift; - - if (@_) { - croak "'use ok' called with an empty argument, did you try to use a package name from an uninitialized variable?" - unless defined $_[0]; - - goto &Test::More::pass if $_[0] eq 'ok'; - goto &Test::More::use_ok; - } -} - -1; - -__END__ - -=encoding utf8 - -=head1 NAME - -ok - Alternative to Test::More::use_ok - -=head1 SYNOPSIS - - use ok 'Some::Module'; - -=head1 DESCRIPTION - -With this module, simply change all C<use_ok> in test scripts to C<use ok>, -and they will be executed at C<BEGIN> time. - -Please see L<Test::use::ok> for the full description. - -=head1 MAINTAINERS - -=over 4 - -=item Chad Granum E<lt>exodist@cpan.orgE<gt> - -=back - -=head1 CC0 1.0 Universal - -To the extent possible under law, 唐鳳 has waived all copyright and related -or neighboring rights to L<Test-use-ok>. - -This work is published from Taiwan. - -L<http://creativecommons.org/publicdomain/zero/1.0> - -=cut diff --git a/cpan/Test-Simple/t/00test_harness_check.t b/cpan/Test-Simple/t/00test_harness_check.t new file mode 100644 index 0000000000..3ff4a13c63 --- /dev/null +++ b/cpan/Test-Simple/t/00test_harness_check.t @@ -0,0 +1,26 @@ +#!/usr/bin/perl -w + +# A test to make sure the new Test::Harness was installed properly. + +use Test::More; +plan tests => 1; + +my $TH_Version = 2.03; + +require Test::Harness; +unless( cmp_ok( eval $Test::Harness::VERSION, '>=', $TH_Version, "T::H version" ) ) { + diag <<INSTRUCTIONS; + +Test::Simple/More/Builder has features which depend on a version of +Test::Harness greater than $TH_Version. You have $Test::Harness::VERSION. +Please install a new version from CPAN. + +If you've already tried to upgrade Test::Harness and still get this +message, the new version may be "shadowed" by the old. Check the +output of Test::Harness's "make install" for "## Differing version" +messages. You can delete the old version by running +"make install UNINST=1". + +INSTRUCTIONS +} + diff --git a/cpan/Test-Simple/t/Builder/carp.t b/cpan/Test-Simple/t/Builder/carp.t index fb37c2f7f8..e89eeebfb9 100644 --- a/cpan/Test-Simple/t/Builder/carp.t +++ b/cpan/Test-Simple/t/Builder/carp.t @@ -1,6 +1,4 @@ #!/usr/bin/perl -use strict; -use warnings; BEGIN { if( $ENV{PERL_CORE} ) { @@ -12,16 +10,15 @@ BEGIN { use Test::More tests => 3; use Test::Builder; -use Test::Builder::Provider; -provides qw/foo bar/; -sub foo { builder()->croak("foo") } -sub bar { builder()->carp("bar") } +my $tb = Test::Builder->create; +sub foo { $tb->croak("foo") } +sub bar { $tb->carp("bar") } eval { foo() }; is $@, sprintf "foo at %s line %s.\n", $0, __LINE__ - 1; -eval { builder()->croak("this") }; +eval { $tb->croak("this") }; is $@, sprintf "this at %s line %s.\n", $0, __LINE__ - 1; { diff --git a/cpan/Test-Simple/t/Builder/done_testing_with_plan.t b/cpan/Test-Simple/t/Builder/done_testing_with_plan.t index 2d10322eea..c0a3d0f014 100644 --- a/cpan/Test-Simple/t/Builder/done_testing_with_plan.t +++ b/cpan/Test-Simple/t/Builder/done_testing_with_plan.t @@ -5,7 +5,7 @@ use strict; use Test::Builder; my $tb = Test::Builder->new; -$tb->plan(tests => 2); +$tb->plan( tests => 2 ); $tb->ok(1); $tb->ok(1); $tb->done_testing(2); diff --git a/cpan/Test-Simple/t/Builder/fork_with_new_stdout.t b/cpan/Test-Simple/t/Builder/fork_with_new_stdout.t index 1e0e97724e..e38c1d08cb 100644 --- a/cpan/Test-Simple/t/Builder/fork_with_new_stdout.t +++ b/cpan/Test-Simple/t/Builder/fork_with_new_stdout.t @@ -8,12 +8,13 @@ use Config; my $b = Test::Builder->new; $b->reset; -my $Can_Fork = $Config{d_fork} - || (($^O eq 'MSWin32' || $^O eq 'NetWare') - and $Config{useithreads} - and $Config{ccflags} =~ /-DPERL_IMPLICIT_SYS/); +my $Can_Fork = $Config{d_fork} || + (($^O eq 'MSWin32' || $^O eq 'NetWare') and + $Config{useithreads} and + $Config{ccflags} =~ /-DPERL_IMPLICIT_SYS/ + ); -if (!$Can_Fork) { +if( !$Can_Fork ) { $b->plan('skip_all' => "This system cannot fork"); } else { @@ -21,26 +22,23 @@ else { } my $pipe = IO::Pipe->new; -if (my $pid = fork) { - $pipe->reader; - my @output = <$pipe>; - $b->like($output[0], qr/ok 1/, "ok 1 from child"); - $b->like($output[1], qr/1\.\.1/, "1..1 from child"); - waitpid($pid, 0); +if ( my $pid = fork ) { + $pipe->reader; + $b->ok((<$pipe> =~ /FROM CHILD: ok 1/), "ok 1 from child"); + $b->ok((<$pipe> =~ /FROM CHILD: 1\.\.1/), "1..1 from child"); + waitpid($pid, 0); } else { - Test::Builder::Formatter::TAP->full_reset; - Test::Builder::Stream->clear; - $pipe->writer; - my $pipe_fd = $pipe->fileno; - close STDOUT; - open(STDOUT, ">&$pipe_fd"); - my $b = Test::Builder->create(shared_stream => 1); - $b->reset; - $b->no_plan; - $b->ok(1); - exit 0; -} + $pipe->writer; + my $pipe_fd = $pipe->fileno; + close STDOUT; + open(STDOUT, ">&$pipe_fd"); + my $b = Test::Builder->new; + $b->reset; + $b->no_plan; + $b->ok(1); +} + =pod #actual diff --git a/cpan/Test-Simple/t/Builder/is_fh.t b/cpan/Test-Simple/t/Builder/is_fh.t index f7a5f1a80d..0eb3ec0b15 100644 --- a/cpan/Test-Simple/t/Builder/is_fh.t +++ b/cpan/Test-Simple/t/Builder/is_fh.t @@ -41,7 +41,7 @@ package Lying::isa; sub isa { my $self = shift; my $parent = shift; - + return 1 if $parent eq 'IO::Handle'; } diff --git a/cpan/Test-Simple/t/Builder/maybe_regex.t b/cpan/Test-Simple/t/Builder/maybe_regex.t index fd8b8d06ed..d1927a56e5 100644 --- a/cpan/Test-Simple/t/Builder/maybe_regex.t +++ b/cpan/Test-Simple/t/Builder/maybe_regex.t @@ -23,7 +23,7 @@ ok(('bar' !~ /$r/), 'qr// bad match'); SKIP: { skip "blessed regex checker added in 5.10", 3 if $] < 5.010; - + my $obj = bless qr/foo/, 'Wibble'; my $re = $Test->maybe_regex($obj); ok( defined $re, "blessed regex detected" ); diff --git a/cpan/Test-Simple/t/Builder/reset.t b/cpan/Test-Simple/t/Builder/reset.t index 5d5be3b976..3bc44457fc 100644 --- a/cpan/Test-Simple/t/Builder/reset.t +++ b/cpan/Test-Simple/t/Builder/reset.t @@ -13,11 +13,10 @@ BEGIN { } chdir 't'; + use Test::Builder; -use Test::Builder::Formatter::LegacyResults; my $Test = Test::Builder->new; my $tb = Test::Builder->create; -$tb->stream->use_lresults; # We'll need this later to know the outputs were reset my %Original_Output; @@ -71,6 +70,7 @@ $Test->is_eq( fileno $tb->todo_output, # The reset Test::Builder will take over from here. $Test->no_ending(1); + $tb->current_test($Test->current_test); $tb->level(0); $tb->ok(1, 'final test to make sure output was reset'); diff --git a/cpan/Test-Simple/t/Builder/reset_outputs.t b/cpan/Test-Simple/t/Builder/reset_outputs.t deleted file mode 100644 index b199128ad3..0000000000 --- a/cpan/Test-Simple/t/Builder/reset_outputs.t +++ /dev/null @@ -1,35 +0,0 @@ -#!perl -w - -BEGIN { - if( $ENV{PERL_CORE} ) { - chdir 't'; - @INC = ('../lib', 'lib'); - } - else { - unshift @INC, 't/lib'; - } -} - -use Test::Builder; -use Test::More 'no_plan'; - -{ - my $tb = Test::Builder->create(); - - # Store the original output filehandles and change them all. - my %original_outputs; - - open my $fh, ">", "dummy_file.tmp"; - END { 1 while unlink "dummy_file.tmp"; } - for my $method (qw(output failure_output todo_output)) { - $original_outputs{$method} = $tb->$method(); - $tb->$method($fh); - is $tb->$method(), $fh; - } - - $tb->reset_outputs; - - for my $method (qw(output failure_output todo_output)) { - is $tb->$method(), $original_outputs{$method}, "reset_outputs() resets $method"; - } -} diff --git a/cpan/Test-Simple/t/Modern/Builder.t b/cpan/Test-Simple/t/Modern/Builder.t deleted file mode 100644 index 5558175efb..0000000000 --- a/cpan/Test-Simple/t/Modern/Builder.t +++ /dev/null @@ -1,8 +0,0 @@ -use strict; -use warnings; - -use Test::More; - -require_ok 'Test::Builder'; - -done_testing; diff --git a/cpan/Test-Simple/t/Modern/Builder_Event.t b/cpan/Test-Simple/t/Modern/Builder_Event.t deleted file mode 100644 index 94fc13bc4a..0000000000 --- a/cpan/Test-Simple/t/Modern/Builder_Event.t +++ /dev/null @@ -1,32 +0,0 @@ -use strict; -use warnings; - -use Test::More 'modern'; - -require_ok 'Test::Builder::Event'; - -can_ok('Test::Builder::Event', qw/trace pid depth in_todo source constructed/); - -my $one = Test::Builder::Event->new( - trace => {}, - depth => 1, - in_todo => 0, - source => 'foo.t', -); - -isa_ok($one, 'Test::Builder::Event'); -is($one->depth, 1, "Got depth"); -is($one->pid, $$, "Auto-populated pid"); -ok($one->constructed, "auto-populated constructed" ); - -is($one->type, 'event', "Got type"); - -is($one->indent, ' ', "Indent 4 spaces per depth"); - -no warnings 'once'; -@Test::Builder::Event::Fake::ISA = ('Test::Builder::Event'); -bless $one, 'Test::Builder::Event::Fake'; -is($one->type, 'fake', "Got type (subclass)"); - -done_testing; - diff --git a/cpan/Test-Simple/t/Modern/Builder_Event_Child.t b/cpan/Test-Simple/t/Modern/Builder_Event_Child.t deleted file mode 100644 index 3a43c01119..0000000000 --- a/cpan/Test-Simple/t/Modern/Builder_Event_Child.t +++ /dev/null @@ -1,22 +0,0 @@ -use strict; -use warnings; - -use Test::More 'modern'; - -require_ok 'Test::Builder::Event::Child'; - -my $one = Test::Builder::Event::Child->new(); - -isa_ok($one, 'Test::Builder::Event::Child'); -isa_ok($one, 'Test::Builder::Event'); - -can_ok($one, qw/name is_subtest action/); - -ok( eval { $one->action('push'); 1 }, "push is valid" ); -ok( eval { $one->action('pop'); 1 }, "pop is valid" ); -ok( !eval { $one->action('foo'); 1 }, "nothing else is valid" ); -like($@, qr/action must be one of 'push' or 'pop'/, "useful message"); - -ok(!$one->to_tap, "no real tap"); - -done_testing; diff --git a/cpan/Test-Simple/t/Modern/Builder_Event_Diag.t b/cpan/Test-Simple/t/Modern/Builder_Event_Diag.t deleted file mode 100644 index 548ac61cfe..0000000000 --- a/cpan/Test-Simple/t/Modern/Builder_Event_Diag.t +++ /dev/null @@ -1,37 +0,0 @@ -use strict; -use warnings; - -use Test::More 'modern'; -use Scalar::Util qw/isweak/; - -require_ok 'Test::Builder::Event::Diag'; - -can_ok('Test::Builder::Event::Diag', qw/message/); - -my $one = Test::Builder::Event::Diag->new(message => "\nFooo\nBar\nBaz\n"); - -isa_ok($one, 'Test::Builder::Event::Diag'); -isa_ok($one, 'Test::Builder::Event'); - -is($one->to_tap, "\n# Fooo\n# Bar\n# Baz\n", "Got tap output"); - -$one->message( "foo bar\n" ); -is($one->to_tap, "# foo bar\n", "simple tap"); - -is($one->linked, undef, "Not linked"); - -require Test::Builder::Event::Ok; -my $ok = Test::Builder::Event::Ok->new( - bool => 0, - real_bool => 0, - trace => Test::Builder::Trace->new -); - -$one->linked($ok); -is($one->linked, $ok, "Now linked"); -ok(isweak($one->{linked}), "Link reference is weak"); - -my $two = Test::Builder::Event::Diag->new(message => 'foo', linked => $ok); -ok(isweak($two->{linked}), "Link reference is weak even on construction"); - -done_testing; diff --git a/cpan/Test-Simple/t/Modern/Builder_Event_Finish.t b/cpan/Test-Simple/t/Modern/Builder_Event_Finish.t deleted file mode 100644 index ac9c7c3d0b..0000000000 --- a/cpan/Test-Simple/t/Modern/Builder_Event_Finish.t +++ /dev/null @@ -1,15 +0,0 @@ -use strict; -use warnings; - -use Test::More 'modern'; - -require_ok 'Test::Builder::Event::Finish'; - -my $one = Test::Builder::Event::Finish->new(); - -isa_ok($one, 'Test::Builder::Event::Finish'); -isa_ok($one, 'Test::Builder::Event'); - -can_ok($one, qw/tests_run tests_failed/); - -done_testing; diff --git a/cpan/Test-Simple/t/Modern/Builder_Event_Note.t b/cpan/Test-Simple/t/Modern/Builder_Event_Note.t deleted file mode 100644 index 8e71157cc4..0000000000 --- a/cpan/Test-Simple/t/Modern/Builder_Event_Note.t +++ /dev/null @@ -1,17 +0,0 @@ -use strict; -use warnings; - -use Test::More 'modern'; - -require_ok 'Test::Builder::Event::Note'; - -can_ok('Test::Builder::Event::Note', qw/message/); - -my $one = Test::Builder::Event::Note->new(message => "\nFooo\nBar\nBaz\n"); - -isa_ok($one, 'Test::Builder::Event::Note'); -isa_ok($one, 'Test::Builder::Event'); - -is($one->to_tap, "\n# Fooo\n# Bar\n# Baz\n", "Got tap output"); - -done_testing; diff --git a/cpan/Test-Simple/t/Modern/Builder_Event_Ok.t b/cpan/Test-Simple/t/Modern/Builder_Event_Ok.t deleted file mode 100644 index bf35a8d71d..0000000000 --- a/cpan/Test-Simple/t/Modern/Builder_Event_Ok.t +++ /dev/null @@ -1,107 +0,0 @@ -use strict; -use warnings; - -use Test::More 'modern'; - -require_ok 'Test::Builder::Event::Ok'; - -isa_ok('Test::Builder::Event::Ok', 'Test::Builder::Event'); - -can_ok('Test::Builder::Event::Ok', qw/bool real_bool name todo skip/); - -my $trace = bless { - _report => bless { - file => 'fake.t', - line => 42, - package => 'Fake::Fake', - }, 'Test::Builder::Trace::Frame' -}, 'Test::Builder::Trace'; - -my %init = ( - trace => $trace, - bool => 1, - real_bool => 1, - name => 'fake', - in_todo => 0, - todo => undef, - skip => undef, -); - -my $one = Test::Builder::Event::Ok->new(%init); - -is($one->to_tap(1), "ok 1 - fake\n", "TAP output, success"); - -$one->bool(0); -$one->real_bool(0); -is($one->to_tap(), "not ok - fake\n", "TAP output, fail"); - -$one->real_bool(1); -$one->in_todo(1); -$one->todo("Blah"); -is($one->to_tap(), "ok - fake # TODO Blah\n", "TAP output, todo"); - -$one->in_todo(0); -$one->todo(undef); -$one->skip("Don't do it!"); -is($one->to_tap(), "ok - fake # skip Don't do it!\n", "TAP output, skip"); - -$one->in_todo(1); -$one->todo("Don't do it!"); -$one->skip("Don't do it!"); -is($one->to_tap(), "ok - fake # TODO & SKIP Don't do it!\n", "TAP output, skip + todo"); - -$one->skip("Different"); -ok( !eval { $one->to_tap; 1}, "Different reasons dies" ); -like( $@, qr{^2 different reasons to skip/todo: \$VAR1}, "Useful message" ); - - -my $two = Test::Builder::Event::Ok->new(%init); - -is($two->diag, undef, "No diag on bool => true event"); - -$two = Test::Builder::Event::Ok->new(%init, in_todo => 1, todo => 'blah', skip => 'blah', real_bool => 1); -is($two->diag, undef, "No diag on todo+skip event"); - -$two = Test::Builder::Event::Ok->new(%init, skip => 'blah', real_bool => 0, bool => 0); -ok($two->diag, "added diag on skip event"); - -$two = Test::Builder::Event::Ok->new(%init, bool => 0, real_bool => 0); -ok($two->diag, "Have diag"); -$two->clear_diag; -is($two->diag, undef, "Removed diag"); - -my $diag_a = Test::Builder::Event::Diag->new(message => 'foo'); -my $diag_b = Test::Builder::Event::Diag->new(message => 'bar'); - -$two = Test::Builder::Event::Ok->new(%init); -$two->diag($diag_a); -is_deeply($two->diag, [$diag_a], "pushed diag"); -is($diag_a->linked, $two, "Added link"); - -$two->diag($diag_b); -is_deeply($two->diag, [$diag_a, $diag_b], "Both diags present"); -is($diag_b->linked, $two, "Added link"); - -my @out = $two->clear_diag; -is_deeply( \@out, [$diag_a, $diag_b], "Clear returned the diags" ); - -is($two->diag, undef, "Removed diag"); - -ok(!$diag_a->linked, "Removed link"); -ok(!$diag_b->linked, "Removed link"); - -$two = Test::Builder::Event::Ok->new(%init, in_todo => 1, todo => 'blah', real_bool => 0); -ok($two->diag->[0]->{in_todo}, "in_todo passed to the diag"); - -my $d = Test::Builder::Event::Ok->new( - bool => 0, - real_bool => 0, - name => 'blah', - trace => $trace, - diag => [ 'hello' ], -); - -is(@{$d->diag}, 2, "Normal Diag + the one we spec'd"); - -done_testing; - diff --git a/cpan/Test-Simple/t/Modern/Builder_Event_Plan.t b/cpan/Test-Simple/t/Modern/Builder_Event_Plan.t deleted file mode 100644 index ee70ce1299..0000000000 --- a/cpan/Test-Simple/t/Modern/Builder_Event_Plan.t +++ /dev/null @@ -1,24 +0,0 @@ -use strict; -use warnings; - -use Test::More 'modern'; - -require_ok 'Test::Builder::Event::Plan'; - -my $one = Test::Builder::Event::Plan->new; - -isa_ok($one, 'Test::Builder::Event::Plan'); -isa_ok($one, 'Test::Builder::Event'); - -can_ok($one, qw/max directive reason/); - -$one->max(5); -is($one->to_tap, "1..5\n", "Got plan"); - -$one->directive('SKIP'); -is($one->to_tap, "1..5 # SKIP\n", "Got plan with directive"); - -$one->reason('blah blah'); -is($one->to_tap, "1..5 # SKIP blah blah\n", "Got plan with directive"); - -done_testing; diff --git a/cpan/Test-Simple/t/Modern/Builder_Fork.t b/cpan/Test-Simple/t/Modern/Builder_Fork.t deleted file mode 100644 index 11dbb89799..0000000000 --- a/cpan/Test-Simple/t/Modern/Builder_Fork.t +++ /dev/null @@ -1,52 +0,0 @@ -use strict; -use warnings; -use Test::More; -use Test::Tester2; -use Test::Builder::Event::Ok; -use Config; - -my $Can_Fork = $Config{d_fork} || - (($^O eq 'MSWin32' || $^O eq 'NetWare') and - $Config{useithreads} and - $Config{ccflags} =~ /-DPERL_IMPLICIT_SYS/ - ); - -if( !$Can_Fork ) { - plan 'skip_all' => "This system cannot fork"; -} - -my $CLASS = 'Test::Builder::Fork'; -require_ok $CLASS; - -my $one = $CLASS->new; -isa_ok($one, $CLASS); -ok($one->tmpdir, "Got temp dir"); - -my $TB = Test::Builder->new; - -my $Ok = Test::Builder::Event::Ok->new( - bool => 1, - real_bool => 1, - name => 'fake', -); - -my $out = $one->handle($Ok); -ok(!$out, "Did not snatch event in parent process"); - -if (my $pid = fork()) { - waitpid($pid, 0); -} -else { - $one->handle($Ok); - exit 0; -} - -my $events = intercept { $one->cull() }; - -is_deeply( - $events, - [$Ok], - "got event after cull" -); - -done_testing; diff --git a/cpan/Test-Simple/t/Modern/Builder_Formatter.t b/cpan/Test-Simple/t/Modern/Builder_Formatter.t deleted file mode 100644 index ec9f896ab5..0000000000 --- a/cpan/Test-Simple/t/Modern/Builder_Formatter.t +++ /dev/null @@ -1,32 +0,0 @@ -use strict; -use warnings; - -use Test::More 'modern'; - -require_ok 'Test::Builder::Formatter'; - -can_ok('Test::Builder::Formatter', qw/new handle to_handler/); - -my $one = Test::Builder::Formatter->new; -isa_ok($one, 'Test::Builder::Formatter'); - -my $ref = ref $one->to_handler; -is($ref, 'CODE', 'handler returns a coderef'); - -{ - package My::Listener; - - use base 'Test::Builder::Formatter'; - - sub ok { $main::SEEN++ } -} - -My::Listener->listen; - -ok(1, "Just a result"); -is($main::SEEN, 1, "Listener saw the result"); - -ok(1, "Just a result"); -is($main::SEEN, 3, "Listener saw the other results too"); - -done_testing; diff --git a/cpan/Test-Simple/t/Modern/Builder_Formatter_TAP.t b/cpan/Test-Simple/t/Modern/Builder_Formatter_TAP.t deleted file mode 100644 index dcb92c8b26..0000000000 --- a/cpan/Test-Simple/t/Modern/Builder_Formatter_TAP.t +++ /dev/null @@ -1,20 +0,0 @@ -use strict; -use warnings; - -use Test::More; - -require_ok 'Test::Builder::Formatter::TAP'; - -isa_ok('Test::Builder::Formatter::TAP', 'Test::Builder::Formatter'); - -can_ok( - 'Test::Builder::Formatter::TAP', - qw{ - no_header no_diag depth use_numbers - output failure_output todo_output - bail nest child finish plan ok diag note - reset_outputs is_fh reset - } -); - -done_testing; diff --git a/cpan/Test-Simple/t/Modern/Builder_Module.t b/cpan/Test-Simple/t/Modern/Builder_Module.t deleted file mode 100644 index f08cba1438..0000000000 --- a/cpan/Test-Simple/t/Modern/Builder_Module.t +++ /dev/null @@ -1,15 +0,0 @@ -use strict; -use warnings; - -use Test::More 'modern'; - -my @warnings; -{ - local $SIG{__WARN__} = sub { push @warnings => @_ }; - require_ok 'Test::Builder::Module'; - Test::Builder::Module->import; -} - -is($warnings[0], "Test::Builder::Module is deprecated!\n", "'Test::Builder::Module' is deprecated"); - -done_testing; diff --git a/cpan/Test-Simple/t/Modern/Builder_Provider.t b/cpan/Test-Simple/t/Modern/Builder_Provider.t deleted file mode 100644 index 24956b32c4..0000000000 --- a/cpan/Test-Simple/t/Modern/Builder_Provider.t +++ /dev/null @@ -1,75 +0,0 @@ -use strict; -use warnings; - -use Scalar::Util qw/reftype/; - -{ - package My::Provider; - use Test::Builder::Provider; -} - -My::Provider->import(); -my $anointed = __PACKAGE__->can('TB_TESTER_META'); - -require Test::More; -Test::More->import; - -ok($anointed, "Importing our provider anointed us"); - -can_ok( - 'My::Provider', - qw{ - TB_PROVIDER_META builder TB anoint gives give provides provide export - import nest - } -); - -is(reftype(My::Provider->TB_PROVIDER_META), 'HASH', "Got Metadata"); - -isa_ok(My::Provider->builder, 'Test::Builder'); -isa_ok(My::Provider->TB, 'Test::Builder'); - -{ - package My::Provider; - - provide foo => sub { 'foo' }; - provide hsh => { a => 1 }; - - give xxx => sub { 'xxx' }; - give arr => [ 1 .. 5 ]; - - provide nestx => sub(&) { TB->ok(&nest($_[0]), "Internal") }; - - provides qw/bar baz/; - gives qw/aaa bbb/; - - provides qw/nesta nestb/; - - sub bar { 'bar' } - sub baz { 'baz' } - sub aaa { 'aaa' } - sub bbb { 'bbb' } - - sub nesta { &nest($_->[0]) } - sub nestb { &nest($_->[0]) } -} - -My::Provider->import(); - -can_ok( - __PACKAGE__, - qw{ foo xxx nestx bar baz aaa bbb nesta nestb } -); - -{ - no strict 'vars'; - no warnings 'once'; - is_deeply(\%hsh, { a => 1 }, "imported hash"); - is_deeply(\@arr, [ 1 .. 5 ], "imported array"); -} - -nestx( - sub { ok(1, "Foo") } -); - -done_testing(); diff --git a/cpan/Test-Simple/t/Modern/Builder_Stream.t b/cpan/Test-Simple/t/Modern/Builder_Stream.t deleted file mode 100644 index 7c2cc4951c..0000000000 --- a/cpan/Test-Simple/t/Modern/Builder_Stream.t +++ /dev/null @@ -1,8 +0,0 @@ -use strict; -use warnings; - -use Test::More; - -require_ok 'Test::Builder::Stream'; - -done_testing; diff --git a/cpan/Test-Simple/t/Modern/Builder_Tester.t b/cpan/Test-Simple/t/Modern/Builder_Tester.t deleted file mode 100644 index ad684c4046..0000000000 --- a/cpan/Test-Simple/t/Modern/Builder_Tester.t +++ /dev/null @@ -1,15 +0,0 @@ -use strict; -use warnings; - -use Test::More 'modern'; - -my @warnings; -{ - local $SIG{__WARN__} = sub { push @warnings => @_ }; - require_ok 'Test::Builder::Tester'; - Test::Builder::Tester->import; -} - -is($warnings[0], "Test::Builder::Tester is deprecated!\n", "'Test::Builder::Tester' is deprecated"); - -done_testing; diff --git a/cpan/Test-Simple/t/Modern/Builder_Trace.t b/cpan/Test-Simple/t/Modern/Builder_Trace.t deleted file mode 100644 index 4e433c4ace..0000000000 --- a/cpan/Test-Simple/t/Modern/Builder_Trace.t +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/perl -use strict; -use warnings; - -use Test::More 'modern'; - -my $CLASS = 'Test::Builder::Trace'; -require_ok $CLASS; - -my $one = bless {}, $CLASS; - -is_deeply($one->$_, [], "Default stack $_") for qw/anointed full level tools transitions stack/; - -# See t/Modern/tracing.t for most of the tests - -done_testing; diff --git a/cpan/Test-Simple/t/Modern/Builder_Trace_Frame.t b/cpan/Test-Simple/t/Modern/Builder_Trace_Frame.t deleted file mode 100644 index ee4fde5b4e..0000000000 --- a/cpan/Test-Simple/t/Modern/Builder_Trace_Frame.t +++ /dev/null @@ -1,88 +0,0 @@ -#!/usr/bin/perl -use strict; -use warnings; - -use Test::More 'modern'; - -my $CLASS = 'Test::Builder::Trace::Frame'; -require_ok $CLASS; - -my @BUILDERS = ( - 'Test::Builder::Trace', - 'Test::Builder', - 'Test::Builder::Event', - 'Test::Builder::Event::Bail', - 'Test::Builder::Event::Child', - 'Test::Builder::Event::Diag', - 'Test::Builder::Event::Note', - 'Test::Builder::Event::Ok', - 'Test::Builder::Event::Plan', - 'Test::Builder::Stream', - 'Test::Builder::Trace', - 'Test::Builder::Util', -); - -for my $pkg (@BUILDERS) { - my $frame = $CLASS->new(2, $pkg, __FILE__, 1, 'foo'); - ok($frame->builder, "Detected builder ($pkg)"); -} - -my $one = $CLASS->new(2, __PACKAGE__, __FILE__, 42, 'Foo::Bar::baz'); -is($one->depth, 2, "Got depth"); -is($one->package, __PACKAGE__, "got package"); -is($one->file, __FILE__, "Got file"); -is($one->line, 42, "Got line"); -is($one->subname, 'Foo::Bar::baz', "got subname"); - -is($one->level, undef, "Level boolean not set"); -is($one->report, undef, "Report boolean not set"); -is($one->level(1), 1, "Level boolean set"); -is($one->report(1), 1, "Report boolean set"); - -is_deeply( - [ $one->call ], - [ __PACKAGE__, __FILE__, 42, 'Foo::Bar::baz' ], - "Got call" -); - -ok(!$one->transition, "Not a transition"); -ok(!$one->nest, "Not a nest"); -ok($one->anointed, "Is annointed"); -is($one->provider_tool, undef, "not a provider tool"); - -my $two = $CLASS->new(2, 'Fake::McKaferson', 'Fake.t', 42, 'Test::Builder::Trace::nest'); -ok($two->transition, "This is a transition"); -ok($two->nest, "This is a nest"); -ok(!$two->anointed, "Not anointed"); -is($two->provider_tool, undef, "not a provider tool"); - -my $three = $CLASS->new(2, 'Fake::McKaferson', 'Fake.t', 42, 'Test::More::is'); -ok(!$three->transition, "This is not a transition"); -ok(!$three->nest, "This is not a nest"); -ok(!$three->anointed, "Not anointed"); -is_deeply( - $three->provider_tool, - Test::More->TB_PROVIDER_META->{attrs}->{'is'}, - "provider tool" -); - -{ - package My::Provider; - use Test::Builder::Provider; - - provide foo => sub { return caller(1) }; -} - -My::Provider->import; - -my @call = foo(); -my $anon_name = $call[3]; - -my $four = $CLASS->new(2, 'Fake::McKaferson', 'Fake.t', 42, $anon_name); -is_deeply( - $four->provider_tool, - My::Provider->TB_PROVIDER_META->{attrs}->{'foo'}, - "provider tool (anon)" -); - -done_testing; diff --git a/cpan/Test-Simple/t/Modern/Builder_Util.t b/cpan/Test-Simple/t/Modern/Builder_Util.t deleted file mode 100644 index f1fe359465..0000000000 --- a/cpan/Test-Simple/t/Modern/Builder_Util.t +++ /dev/null @@ -1,159 +0,0 @@ -use strict; -use warnings; - -use Test::More 'modern'; - -{ - package My::Example; - use Test::Builder::Util qw/ - import export exports accessor accessors delta deltas export_to transform - atomic_delta atomic_deltas new - /; - - export foo => sub { 'foo' }; - export 'bar'; - exports qw/baz bat/; - - sub bar { 'bar' } - sub baz { 'baz' } - sub bat { 'bat' } - - accessor apple => sub { 'fruit' }; - - accessors qw/x y z/; - - delta number => 5; - deltas qw/alpha omega/; - - transform add5 => sub { $_[1] + 5 }; - transform add6 => '_add6'; - - sub _add6 { $_[1] + 6 } - - atomic_delta a_number => 5; - atomic_deltas qw/a_alpha a_omega/; - - package My::Consumer; - My::Example->import(qw/foo bar baz bat/); -} - -can_ok( - 'My::Example', - qw/ - import export accessor accessors delta deltas export_to transform - atomic_delta atomic_deltas new - - bar baz bat - apple - x y z - number - alpha omega - add5 add6 - a_number - a_alpha a_omega - / -); - -can_ok('My::Consumer', qw/foo bar baz bat/); - -use Test::Builder::Util qw/try protect package_sub is_tester is_provider find_builder/; - -is(My::Consumer->$_, $_, "Simple sub $_") for qw/foo bar baz bat/; - -my $one = My::Example->new(x => 1, y => 2, z => 3); -isa_ok($one, 'My::Example'); -is($one->x, 1, "set at construction"); -is($one->y, 2, "set at construction"); -is($one->z, 3, "set at construction"); - -is($one->x(5), 5, "set value"); -is($one->x(), 5, "kept value"); - -is($one->number, 5, "default"); -is($one->number(2), 7, "Delta add the number"); -is($one->number(-2), 5, "Delta add the number"); - -is($one->alpha, 0, "default"); -is($one->alpha(2), 2, "Delta add the number"); -is($one->alpha(-2), 0, "Delta add the number"); - -is($one->add5(3), 8, "transformed"); -is($one->add6(3), 9, "transformed"); - -# XXX TODO: Test these in a threaded environment -is($one->a_number, 5, "default"); -is($one->a_number(2), 7, "Delta add the number"); -is($one->a_number(-2), 5, "Delta add the number"); - -is($one->a_alpha, 0, "default"); -is($one->a_alpha(2), 2, "Delta add the number"); -is($one->a_alpha(-2), 0, "Delta add the number"); - -can_ok( __PACKAGE__, 'try' ); - -{ - local $@ = "Blah"; - local $! = 23; - my ($ok, $error) = try { $! = 22; die "XXX"; 1 }; - ok(!$ok, "Exception in the try"); - ok($! == 23, '$! is preserved'); - is($@, "Blah", '$@ is preserved'); - like($error, qr/XXX/, "Got exception"); -} - -{ - local $@ = "Blah"; - local $! = 23; - my ($ok, $error) = try { $! = 22; $@ = 'XXX'; 1 }; - ok($ok, "No exception in the try"); - ok($! == 23, '$! is preserved'); - is($@, "Blah", '$@ is preserved'); -} - -{ - local $@ = "Blah"; - local $! = 23; - my $ok; - eval { $ok = protect { $! = 22; die "XXX"; 1 } }; - like($@, qr/XXX/, 'Threw exception'); - ok(!$ok, "Exception in the try"); - ok($! == 23, '$! is preserved'); -} - -{ - local $@ = "Blah"; - local $! = 23; - my $ok = protect { $! = 22; $@ = 'XXX'; 1 }; - ok($ok, "Success"); - ok($! == 23, '$! is preserved'); - is($@, "Blah", '$@ is preserved'); -} - -{ - package TestParent; - sub a { 'a' } - - package TestChildA; - our @ISA = ( 'TestParent' ); - - package TestChildB; - our @ISA = ( 'TestParent' ); - sub a { 'A' } -} - -is(package_sub(TestParent => 'a'), TestParent->can('a'), "Found sub in package"); -is(package_sub(TestChildA => 'a'), undef, "No sub in child package (Did not inherit)"); -is(package_sub(TestChildB => 'a'), TestChildB->can('a'), "Found sub in package"); - -ok(is_tester(__PACKAGE__), "We are a tester!"); -ok(!is_provider(__PACKAGE__), "We are not a provider!"); - -ok(!is_tester('TestParent'), "not a tester!"); -ok(!is_provider('TestParent'), "not a provider!"); - -ok(!is_tester('Test::More'), "not a tester!"); -ok(is_provider('Test::More'), "a provider!"); - -isa_ok(find_builder(), 'Test::Builder'); - -done_testing; diff --git a/cpan/Test-Simple/t/Modern/More.t b/cpan/Test-Simple/t/Modern/More.t deleted file mode 100644 index a4d6bb0600..0000000000 --- a/cpan/Test-Simple/t/Modern/More.t +++ /dev/null @@ -1,177 +0,0 @@ -use strict; -use warnings; -use Test::More qw/modern/; -use Test::Tester2; -use PerlIO; -use utf8; - -our $default_utf8 = grep { $_ eq 'utf8' } PerlIO::get_layers(\*STDOUT); - -helpers qw/my_ok/; -sub my_ok { Test::Builder->new->ok(@_) } - -helpers qw/my_nester/; -sub my_nester(&) { - my $code = shift; - Test::Builder->new->ok( - nest {$code->()}, - "my_nester exit" - ) -} - -my @lines; - -my $events = intercept { - my_ok( 1, "good" ); push @lines => __LINE__; - my_ok( 0, "bad" ); push @lines => __LINE__; - - my_nester { 1 }; push @lines => __LINE__; - - my_nester { - my_ok( 1, "good nested" ); push @lines => __LINE__; - my_ok( 0, "bad nested" ); push @lines => __LINE__; - 0; - }; push @lines => __LINE__; -}; - -events_are( - $events, - - ok => { line => $lines[0], bool => 1, name => "good" }, - ok => { line => $lines[1], bool => 0, name => "bad" }, - diag => { line => $lines[1], message => qr/failed test 'bad'/i }, - - ok => { line => $lines[2], bool => 1, name => "my_nester exit" }, - - ok => { line => $lines[3], bool => 1, name => "good nested" }, - ok => { line => $lines[4], bool => 0, name => "bad nested" }, - diag => { line => $lines[4], message => qr/failed test 'bad nested'/i }, - ok => { line => $lines[5], bool => 0, name => "my_nester exit" }, -); - -helpers 'helped'; - -my %place; -sub helped(&) { - my ($CODE) = @_; - - diag( 'setup' ); - ok( nest(\&$CODE), 'test ran' ); - diag( 'teardown' ); -}; - -$events = intercept { - helped { - ok(0 ,'helped test' ); $place{helped} = __LINE__; 0; - }; $place{inhelp} = __LINE__; -}; - -events_are( - $events, - - diag => { message => 'setup' }, - - ok => { bool => 0, line => $place{helped} }, - diag => { message => qr/failed test.*$place{helped}/ism, line => $place{helped} }, - - ok => { bool => 0, line => $place{inhelp} }, - diag => { message => qr/failed test.*$place{inhelp}/ism, line => $place{inhelp} }, - - diag => { message => 'teardown' }, -); - -my $ok = eval { Test::More->import(import => ['$TODO']) }; -ok($ok, "Can import \$TODO"); - -{ - package main_modern; - use Test::More 'utf8'; - use Test::Tester2; - - my $events = intercept { ok(1, "blah") }; - is($events->[0]->encoding, 'utf8', "utf8 encoding set for modern"); - - my @warnings; - { - local $SIG{__WARN__} = sub { push @warnings => @_ }; - ok(1, "Ճȴģȳф utf8 name"); - subtest 'Ճȴģȳф utf8 name - subtest name' => sub { - ok(1, "Ճȴģȳф utf8 name - in subtest"); - }; - ok(1, "Ճȴģȳф utf8 name - after subtest"); - } - ok(!@warnings, "no warnings"); -} - -SKIP: { - package main_old; - use Test::More; - use Test::Tester2; - - skip "UTF8 by default, skipping legacy" => 5 - if $main::default_utf8; - - my $events = intercept { ok(1, "blah") }; - is($events->[0]->encoding, 'legacy', "legacy encoding set for non-modern"); - - my @warnings; - { - local $SIG{__WARN__} = sub { push @warnings => @_ }; - ok(1, "Ճȴģȳф utf8 name"); - subtest 'Ճȴģȳф utf8 name - subtest name' => sub { - ok(1, "Ճȴģȳф utf8 name - in subtest"); - }; - ok(1, "Ճȴģȳф utf8 name - after subtest"); - } - - chomp(@warnings); - is_deeply( - [ map { s/ at.*$//; $_ } @warnings], - [ - 'Wide character in print', - 'Wide character in print', - 'Wide character in print', - 'Wide character in print', - 'Wide character in print', - ], - "utf8 is not on." - ); -} - -{ - package main_oblivious; - use Test::Tester2; - - my $events = intercept { Test::More::ok(1, "blah") }; - Test::More::is($events->[0]->encoding, undef, "no encoding set for non-consumer"); -} - -{ - package arg_encoding; - use Test::More encoding => 'utf8'; - use Test::Tester2; - - my $events = intercept { ok(1, "blah") }; - is($events->[0]->encoding, 'utf8', "utf8 encoding set by arg encoding"); - - my @warnings; - { - local $SIG{__WARN__} = sub { push @warnings => @_ }; - ok(1, "Ճȴģȳф utf8 name"); - } - ok(!@warnings, "no warnings - argument 'encoding'"); -} - - -require PerlIO; -my $legacy = Test::Builder->new->tap->io_set('legacy')->[0]; -my $modern = Test::Builder->new->tap->io_set('utf8')->[0]; -ok( (grep { $_ eq 'utf8' } PerlIO::get_layers($modern)), "Did add utf8 to UTF8 handle" ); -SKIP: { - skip "UTF8 by default, skipping legacy" => 2 - if $main::default_utf8; - ok( !(grep { $_ eq 'utf8' } PerlIO::get_layers(\*STDOUT)), "Did not add utf8 to STDOUT" ); - ok( !(grep { $_ eq 'utf8' } PerlIO::get_layers($legacy)), "Did not add utf8 to legacy" ); -} - -done_testing; diff --git a/cpan/Test-Simple/t/Modern/NotTB15.t b/cpan/Test-Simple/t/Modern/NotTB15.t deleted file mode 100644 index 55453976f0..0000000000 --- a/cpan/Test-Simple/t/Modern/NotTB15.t +++ /dev/null @@ -1,47 +0,0 @@ -#!/usr/bin/perl -use strict; -use warnings; - -use Test::More 'modern'; - -# This is just a list of method Test::Builder current does not have that Test::Builder 1.5 does. -my @TB15_METHODS = qw{ - _file_and_line _join_message _make_default _my_exit _reset_todo_state - _result_to_hash _results _todo_state formatter history in_subtest in_test - no_change_exit_code post_event post_result set_formatter set_plan test_end - test_exit_code test_start test_state -}; - -for my $method (qw/foo bar baz/) { - my $success = !eval { Test::Builder->$method; 1 }; my $line = __LINE__; - my $error = $@; - ok($success, "Threw an exception ($method)"); - is( - $error, - qq{Can't locate object method "$method" via package "Test::Builder" at } . __FILE__ . " line $line\n", - "Did not auto-create random sub ($method)" - ); -} - -my $file = __FILE__; -for my $method (@TB15_METHODS) { - my $success = !eval { Test::Builder->$method; 1 }; my $line = __LINE__; - my $error = $@; - - ok($success, "Threw an exception ($method)"); - - is($error, <<" EOT", "Got expected error ($method)"); -Can't locate object method "$method" via package "Test::Builder" at $file line $line - - ************************************************************************* - '$method' is a Test::Builder 1.5 method. Test::Builder 1.5 is a dead branch. - You need to update your code so that it no longer treats Test::Builders - over a specific version number as anything special. - - See: http://blogs.perl.org/users/chad_exodist_granum/2014/03/testmore---new-maintainer-also-stop-version-checking.html - ************************************************************************* - EOT -} - -done_testing; - diff --git a/cpan/Test-Simple/t/Modern/Simple.t b/cpan/Test-Simple/t/Modern/Simple.t deleted file mode 100644 index 7946f89f40..0000000000 --- a/cpan/Test-Simple/t/Modern/Simple.t +++ /dev/null @@ -1,18 +0,0 @@ -use strict; -use warnings; - -use Test::Simple tests => 4, 'modern'; -use Test::Tester2; - -ok(Test::Simple->can('TB_PROVIDER_META'), "Test::Simple is a provider"); - -my $events = intercept { - ok( 1, "A pass" ); - ok( 0, "A fail" ); -}; - -ok(@$events == 3, "found 3 events (2 oks, and 1 diag)"); - -ok($events->[0]->trace->report->line == 10, "Reported correct line event 1"); -ok($events->[2]->trace->report->line == 11, "Reported correct line event 2"); - diff --git a/cpan/Test-Simple/t/Modern/Tester2.t b/cpan/Test-Simple/t/Modern/Tester2.t deleted file mode 100644 index d0680ca9e8..0000000000 --- a/cpan/Test-Simple/t/Modern/Tester2.t +++ /dev/null @@ -1,258 +0,0 @@ -use strict; -use warnings; - -use Test::More 'modern'; -use Test::Tester2; - -can_ok( __PACKAGE__, 'intercept', 'events_are' ); - -my $events = intercept { - ok(1, "Woo!"); - ok(0, "Boo!"); -}; - -isa_ok($events->[0], 'Test::Builder::Event::Ok'); -is($events->[0]->bool, 1, "Got one success"); -is($events->[0]->name, "Woo!", "Got test name"); - -isa_ok($events->[1], 'Test::Builder::Event::Ok'); -is($events->[1]->bool, 0, "Got one fail"); -is($events->[1]->name, "Boo!", "Got test name"); - -$events = intercept { - ok(1, "Woo!"); - BAIL_OUT("Ooops"); - ok(0, "Should not see this"); -}; -is(@$events, 2, "Only got 2"); -isa_ok($events->[0], 'Test::Builder::Event::Ok'); -isa_ok($events->[1], 'Test::Builder::Event::Bail'); - -$events = intercept { - plan skip_all => 'All tests are skipped'; - - ok(1, "Woo!"); - BAIL_OUT("Ooops"); - ok(0, "Should not see this"); -}; -is(@$events, 1, "Only got 1"); -isa_ok($events->[0], 'Test::Builder::Event::Plan'); - -events_are( - intercept { - events_are( - intercept { ok(1, "foo") }, - ok => {id => 'blah', bool => 0}, - end => 'Lets name this test!', - ); - }, - - ok => {id => 'first', bool => 0}, - - diag => {message => qr{Failed test 'Lets name this test!'.*at (\./)?t/Modern/Tester2\.t line}s}, - diag => {message => q{(ok blah) Wanted bool => '0', but got bool => '1'}}, - diag => {message => <<" EOT"}, -Full event found was: ok => { - name: foo - bool: 1 - real_bool: 1 - in_todo: 0 - package: main - file: t/Modern/Tester2.t - line: 44 - pid: $$ - depth: 0 - source: t/Modern/Tester2.t - tool_name: ok - tool_package: Test::More - tap: ok - foo -} - EOT - end => 'Failure diag checking', -); - -events_are( - intercept { - events_are( - intercept { ok(1, "foo"); ok(1, "bar") }, - ok => {id => 'blah', bool => 1}, - 'end' - ); - }, - - ok => {id => 'first', bool => 0}, - - diag => {}, - diag => {message => q{Expected end of events, but more events remain}}, - - end => 'skipping a diag', -); - -DOCS_1: { - # Intercept all the Test::Builder::Event objects produced in the block. - my $events = intercept { - ok(1, "pass"); - ok(0, "fail"); - diag("xxx"); - }; - - # By Hand - is($events->[0]->{bool}, 1, "First event passed"); - - # With help - events_are( - $events, - ok => { id => 'a', bool => 1, name => 'pass' }, - ok => { id => 'b', bool => 0, name => 'fail' }, - diag => { message => qr/Failed test 'fail'/ }, - diag => { message => qr/xxx/ }, - end => 'docs 1', - ); -} - -DOCS_2: { - require Test::Simple; - my $events = intercept { - Test::More::ok(1, "foo"); - Test::More::ok(1, "bar"); - Test::More::ok(1, "baz"); - Test::Simple::ok(1, "bat"); - }; - - events_are( - $events, - ok => { name => "foo" }, - ok => { name => "bar" }, - - # From this point on, only more 'Test::Simple' events will be checked. - filter_provider => 'Test::Simple', - - # So it goes right to the Test::Simple event. - ok => { name => "bat" }, - - end => 'docs 2', - ); -} - -DOCS_3: { - my $events = intercept { - ok(1, "foo"); - diag("XXX"); - - ok(1, "bar"); - diag("YYY"); - - ok(1, "baz"); - diag("ZZZ"); - }; - - events_are( - $events, - ok => { name => "foo" }, - diag => { message => 'XXX' }, - ok => { name => "bar" }, - diag => { message => 'YYY' }, - - # From this point on, only 'diag' types will be seen - filter_type => 'diag', - - # So it goes right to the next diag. - diag => { message => 'ZZZ' }, - - end => 'docs 3', - ); -} - -DOCS_4: { - my $events = intercept { - ok(1, "foo"); - diag("XXX"); - - ok(1, "bar"); - diag("YYY"); - - ok(1, "baz"); - diag("ZZZ"); - }; - - events_are( - $events, - ok => { name => "foo" }, - - skip => 1, # Skips the diag - - ok => { name => "bar" }, - - skip => 2, # Skips a diag and an ok - - diag => { message => 'ZZZ' }, - - end => 'docs 4' - ); -} - -DOCS_5: { - my $events = intercept { - ok(1, "foo"); - - diag("XXX"); - diag("YYY"); - diag("ZZZ"); - - ok(1, "bar"); - }; - - events_are( - $events, - ok => { name => "foo" }, - - skip => '*', # Skip until the next 'ok' is found since that is our next check. - - ok => { name => "bar" }, - - end => 'docs 5', - ); -} - -DOCS_6: { - my $events = intercept { - ok(1, "foo"); - - diag("XXX"); - diag("YYY"); - - ok(1, "bar"); - diag("ZZZ"); - - ok(1, "baz"); - }; - - events_are( - intercept { - events_are( - $events, - - name => 'docs 6 inner', - - seek => 1, - ok => { name => "foo" }, - # The diags are ignored, - ok => { name => "bar" }, - - seek => 0, - - # This will fail because the diag is not ignored anymore. - ok => { name => "baz" }, - ); - }, - - ok => { bool => 0 }, - diag => { message => qr/Failed test 'docs 6 inner'/ }, - diag => { message => q{(ok 3) Wanted event type 'ok', But got: 'diag'} }, - diag => { message => qr/Full event found was:/ }, - - end => 'docs 6', - ); -} - -done_testing; diff --git a/cpan/Test-Simple/t/Modern/Tester2_subtest.t b/cpan/Test-Simple/t/Modern/Tester2_subtest.t deleted file mode 100644 index 236575fee5..0000000000 --- a/cpan/Test-Simple/t/Modern/Tester2_subtest.t +++ /dev/null @@ -1,66 +0,0 @@ -use strict; -use warnings; -use utf8; - -use Test::More qw/modern/; -use Test::Tester2; - -my $events = intercept { - ok(0, "test failure" ); - ok(1, "test success" ); - - subtest 'subtest' => sub { - ok(0, "subtest failure" ); - ok(1, "subtest success" ); - - subtest 'subtest_deeper' => sub { - ok(0, "deeper subtest failure" ); - ok(1, "deeper subtest success" ); - }; - }; - - ok(0, "another test failure" ); - ok(1, "another test success" ); -}; - -events_are( - $events, - - ok => {bool => 0}, - diag => {}, - ok => {bool => 1}, - - child => {action => 'push'}, - ok => {bool => 0}, - diag => {}, - ok => {bool => 1}, - - child => {action => 'push'}, - ok => {bool => 0}, - diag => {}, - ok => {bool => 1}, - - plan => {}, - finish => {}, - - diag => {tap => qr/Looks like you failed 1 test of 2/}, - ok => {bool => 0}, - diag => {}, - child => {action => 'pop'}, - - plan => {}, - finish => {}, - - diag => {tap => qr/Looks like you failed 2 tests of 3/}, - ok => {bool => 0}, - diag => {}, - child => {action => 'pop'}, - - ok => {bool => 0}, - diag => {}, - ok => {bool => 1}, - - end => "subtest events as expected", -); - -done_testing; diff --git a/cpan/Test-Simple/t/Modern/encoding_test.t b/cpan/Test-Simple/t/Modern/encoding_test.t deleted file mode 100644 index 83a0d49b4d..0000000000 --- a/cpan/Test-Simple/t/Modern/encoding_test.t +++ /dev/null @@ -1,66 +0,0 @@ -use strict; -use warnings; -no utf8; - -use Test::More qw/modern/; -use Test::Tester2; - -BEGIN { - my $norm = eval { require Unicode::Normalize; require Encode; 1 }; - plan skip_all => 'Unicode::Normalize is required for this test' unless $norm; -} - -my $filename = "encoding_tést.t"; -ok(!utf8::is_utf8($filename), "filename is not in utf8 already"); -my $utf8name = Unicode::Normalize::NFKC(Encode::decode('utf8', "$filename", Encode::FB_CROAK)); -ok( $filename ne $utf8name, "sanity check" ); - -tap_encoding 'utf8'; -my $trace_utf8 = Test::Builder::Trace->new(); -$trace_utf8->report->file($filename); - -tap_encoding 'legacy'; -my $trace_legacy = Test::Builder::Trace->new(); -$trace_legacy->report->file($filename); - -is($trace_utf8->encoding, 'utf8', "got a utf8 trace"); -is($trace_legacy->encoding, 'legacy', "got a legacy trace"); - -my $diag_utf8 = Test::Builder::Event::Diag->new( - message => "failed blah de blah\nFatal error in $filename line 42.\n", - trace => $trace_utf8, -); - -my $diag_legacy = Test::Builder::Event::Diag->new( - message => "failed blah de blah\nFatal error in $filename line 42.\n", - trace => $trace_legacy, -); - -ok( $diag_legacy->to_tap ne $diag_utf8->to_tap, "The utf8 diag has a different output" ); - -is( - $diag_legacy->to_tap, - "# failed blah de blah\n# Fatal error in $filename line 42.\n", - "Got unaltered filename in legacy" -); - -# Change encoding for the scope of the next test so that errors make more sense. -tap_encoding 'utf8' => sub { - is( - $diag_utf8->to_tap, - "# failed blah de blah\n# Fatal error in $utf8name line 42.\n", - "Got transcoded filename in utf8" - ); -}; - -{ - my $file = __FILE__; - my $success = eval { tap_encoding 'invalid_encoding'; 1 }; my $line = __LINE__; - chomp(my $error = $@); - ok(!$success, "Threw an exception when using invalid encoding"); - like($error, qr/^encoding 'invalid_encoding' is not valid, or not available at $file line $line/, 'validate encoding'); -}; - - - -done_testing; diff --git a/cpan/Test-Simple/t/Modern/tracing.t b/cpan/Test-Simple/t/Modern/tracing.t deleted file mode 100644 index e41ea14365..0000000000 --- a/cpan/Test-Simple/t/Modern/tracing.t +++ /dev/null @@ -1,223 +0,0 @@ -use strict; -use warnings; - -sub trace { - my $trace = Test::Builder->new->trace_test; - return $trace; -} - -BEGIN { - $INC{'XXX/Provider.pm'} = __FILE__; - $INC{'XXX/LegacyProvider.pm'} = __FILE__; - $INC{'XXX/Tester.pm'} = __FILE__; -} - -# line 1000 -{ - package XXX::Provider; - use Test::Builder::Provider; - - BEGIN { - provide explode => sub { - exploded(); - }; - } - - sub exploded { overkill() } - - sub overkill { - return main::trace(); - } - - sub nestit(&) { - my ($code) = @_; - nest{ $code->() }; - return main::trace(); - } - - sub nonest(&) { - my ($code) = @_; - $code->(); - return main::trace(); - } - - BEGIN { - provides qw/nestit/; - - provides qw/nonest/; - } -} - -# line 1500 -{ - package XXX::LegacyProvider; - use base 'Test::Builder::Module'; - - our @EXPORT; - BEGIN { @EXPORT = qw/do_it do_it_2 do_nestit do_nonest/ }; - -# line 1600 - sub do_it { - my $builder = __PACKAGE__->builder; - - my $trace = Test::Builder->new->trace_test; - return $trace; - } - -# line 1700 - sub do_it_2 { - local $Test::Builder::Level = $Test::Builder::Level + 1; - do_it(@_); - } - -# line 1800 - sub do_nestit(&) { - my ($code) = @_; - my $trace = Test::Builder->new->trace_test; - # TODO: I Think this is wrong... - local $Test::Builder::Level = $Test::Builder::Level + 3; - $code->(); - return $trace; - } -} - -# line 2000 -package XXX::Tester; -use XXX::Provider; -use XXX::LegacyProvider; -use Test::Builder::Provider; -use Data::Dumper; -use Test::More; - -provides 'explodable'; -# line 2100 -sub explodable { explode() }; -# line 2200 -sub explodadouble { explode() }; - -# line 2300 -my $trace = explodable(); -is($trace->report->line, 2300, "got correct line"); -is($trace->report->package, 'XXX::Tester', "got correct package"); -is_deeply( - $trace->report->provider_tool, - {package => 'XXX::Tester', name => 'explodable', named => 1}, - "got tool info" -); - -# line 2400 -$trace = explodadouble(); -is($trace->report->line, 2200, "got correct line"); -is($trace->report->package, 'XXX::Tester', "got correct package"); -is_deeply( - $trace->report->provider_tool, - {package => 'XXX::Provider', name => 'explode', named => 0}, - "got tool info" -); - -# line 2500 -$trace = explode(); -is($trace->report->line, 2500, "got correct line"); -is($trace->report->package, 'XXX::Tester', "got correct package"); -is_deeply( - $trace->report->provider_tool, - {package => 'XXX::Provider', name => 'explode', named => 0}, - "got tool info" -); - -# line 2600 -$trace = do_it(); -is($trace->report->line, 2600, "got correct line"); -is($trace->report->package, 'XXX::Tester', "got correct package"); -ok(!$trace->report->provider_tool, "No Tool"); - -# line 2700 -$trace = do_it_2(); -is($trace->report->line, 2700, "got correct line"); -is($trace->report->package, 'XXX::Tester', "got correct package"); -is($trace->report->level, 1, "Is level"); -ok(!$trace->report->provider_tool, "No Tool"); - -my @events; - -# Here we simulate subtests -# line 2800 -$trace = nestit { - push @events => explodable(); - push @events => explodadouble(); - push @events => explode(); - push @events => do_it(); - push @events => do_it_2(); -}; # Report line is here - -is($trace->report->line, 2806, "Nesting tool reported correct line"); - -is($events[0]->report->line, 2801, "Got nested line, our tool"); -is($events[1]->report->line, 2200, "Nested, but tool is not 'provided' so goes up to provided"); -is($events[2]->report->line, 2803, "Got nested line external tool"); -is($events[3]->report->line, 2804, "Got nested line legacy tool"); -is($events[4]->report->line, 2805, "Got nested line deeper legacy tool"); - -@events = (); -my $outer; -# line 2900 -$outer = nestit { - $trace = nestit { - push @events => explodable(); - push @events => explodadouble(); - push @events => explode(); - push @events => do_it(); - push @events => do_it_2(); - }; # Report line is here -}; - -# line 2920 -is($outer->report->line, 2908, "Nesting tool reported correct line"); -is($trace->report->line, 2907, "Nesting tool reported correct line"); - -# line 2930 -is($events[0]->report->line, 2902, "Got nested line, our tool"); -is($events[1]->report->line, 2200, "Nested, but tool is not 'provided' so goes up to provided"); -is($events[2]->report->line, 2904, "Got nested line external tool"); -is($events[3]->report->line, 2905, "Got nested line legacy tool"); -is($events[4]->report->line, 2906, "Got nested line deeper legacy tool"); - -@events = (); -# line 3000 -$trace = nonest { - push @events => explodable(); - push @events => explodadouble(); - push @events => explode(); - push @events => do_it(); - push @events => do_it_2(); -}; # Report line is here - -is($trace->report->line, 3006, "NoNesting tool reported correct line"); - -is($events[0]->report->line, 3006, "Lowest tool is nonest, so these get squashed (Which is why you use nesting)"); -is($events[1]->report->line, 3006, "Lowest tool is nonest, so these get squashed (Which is why you use nesting)"); -is($events[2]->report->line, 3006, "Lowest tool is nonest, so these get squashed (Which is why you use nesting)"); -is($events[3]->report->line, 3006, "Lowest tool is nonest, so these get squashed(Legacy) (Which is why you use nesting)"); -is($events[4]->report->line, 3006, "Lowest tool is nonest, so these get squashed(Legacy) (Which is why you use nesting)"); - -@events = (); - -# line 3100 -$trace = do_nestit { - push @events => explodable(); - push @events => explodadouble(); - push @events => explode(); - push @events => do_it(); - push @events => do_it_2(); -}; # Report line is here - -is($trace->report->line, 3106, "Nesting tool reported correct line"); - -is($events[0]->report->line, 3101, "Got nested line, our tool"); -is($events[1]->report->line, 2200, "Nested, but tool is not 'provided' so goes up to provided"); -is($events[2]->report->line, 3103, "Got nested line external tool"); -is($events[3]->report->line, 3104, "Got nested line legacy tool"); -is($events[4]->report->line, 3105, "Got nested line deeper legacy tool"); - -done_testing; - diff --git a/cpan/Test-Simple/t/More.t b/cpan/Test-Simple/t/More.t index d04d60ff4b..ce535e26d9 100644 --- a/cpan/Test-Simple/t/More.t +++ b/cpan/Test-Simple/t/More.t @@ -40,7 +40,7 @@ unlike(@foo, '/foo/'); can_ok('Test::More', qw(require_ok use_ok ok is isnt like skip can_ok pass fail eq_array eq_hash eq_set)); -can_ok(bless({}, "Test::More"), qw(require_ok use_ok ok is isnt like skip +can_ok(bless({}, "Test::More"), qw(require_ok use_ok ok is isnt like skip can_ok pass fail eq_array eq_hash eq_set)); @@ -54,7 +54,7 @@ isa_ok(\42, 'SCALAR'); } -# can_ok() & isa_ok should call can() & isa() on the given object, not +# can_ok() & isa_ok should call can() & isa() on the given object, not # just class, in case of custom can() { local *Foo::can; @@ -143,7 +143,7 @@ ok( !eq_hash(\%hash1, \%hash2), 'eq_hash with slightly different complicated hashes' ); is @Test::More::Data_Stack, 0; -is( Test::Builder->new, Test::More->builder, 'builder()' ); +is( Test::Builder->new, Test::More->builder, 'builder()' ); cmp_ok(42, '==', 42, 'cmp_ok =='); diff --git a/cpan/Test-Simple/t/PerlIO.t b/cpan/Test-Simple/t/PerlIO.t deleted file mode 100644 index d0e0b99517..0000000000 --- a/cpan/Test-Simple/t/PerlIO.t +++ /dev/null @@ -1,11 +0,0 @@ -use Test::More 'modern'; -require PerlIO; - -my $ok = 1; -my %counts; -for my $layer (PerlIO::get_layers(__PACKAGE__->TB_INSTANCE()->stream->tap->output)) { - my $dup = $counts{$layer}++; - ok(!$dup, "No IO layer duplication '$layer'"); -} - -done_testing; diff --git a/cpan/Test-Simple/t/TTLegacy/auto.t b/cpan/Test-Simple/t/TTLegacy/auto.t deleted file mode 100644 index c7a7fc04a5..0000000000 --- a/cpan/Test-Simple/t/TTLegacy/auto.t +++ /dev/null @@ -1,34 +0,0 @@ -use strict; -use warnings; - -BEGIN { - if ($ENV{PERL_CORE}) { - chdir 't'; - @INC = ('../lib', 'lib'); - } - else { - unshift @INC, 't/lib'; - } -} - -use Test::Tester tests => 5; - -use SmallTest; - -use MyTest; - -{ - my ($prem, @results) = run_tests(sub { MyTest::ok(1, "run pass") }); - - is_eq($results[0]->{name}, "run pass"); - is_num($results[0]->{ok}, 1); -} - -{ - my ($prem, @results) = run_tests(sub { MyTest::ok(0, "run fail") }); - - is_eq($results[0]->{name}, "run fail"); - is_num($results[0]->{ok}, 0); -} - -is_eq(ref(SmallTest::getTest()), "Test::Tester::Delegate"); diff --git a/cpan/Test-Simple/t/TTLegacy/capture.t b/cpan/Test-Simple/t/TTLegacy/capture.t deleted file mode 100644 index f9103bd6aa..0000000000 --- a/cpan/Test-Simple/t/TTLegacy/capture.t +++ /dev/null @@ -1,32 +0,0 @@ -use strict; - -use Test::Tester; - -my $Test = Test::Builder->new; -$Test->plan(tests => 3); - -my $cap; - -$cap = Test::Tester->capture; - -{ - no warnings 'redefine'; - sub Test::Tester::find_run_tests { return 0}; -} - -local $Test::Builder::Level = 0; -{ - my $cur = $cap->current_test; - $Test->is_num($cur, 0, "current test"); - - eval {$cap->current_test(2)}; - $Test->ok($@, "can't set test_num"); -} - -{ - $cap->ok(1, "a test"); - - my @res = $cap->details; - - $Test->is_num(scalar @res, 1, "res count"); -} diff --git a/cpan/Test-Simple/t/TTLegacy/check_tests.t b/cpan/Test-Simple/t/TTLegacy/check_tests.t deleted file mode 100644 index ec88e2d48c..0000000000 --- a/cpan/Test-Simple/t/TTLegacy/check_tests.t +++ /dev/null @@ -1,117 +0,0 @@ -use strict; - -use Test::Tester; - -use Data::Dumper qw(Dumper); - -my $test = Test::Builder->new; -$test->plan(tests => 105); - -my $cap; - -$cap = Test::Tester->capture; - -my @tests = ( - [ - 'pass', - '$cap->ok(1, "pass");', - { - name => "pass", - ok => 1, - actual_ok => 1, - reason => "", - type => "", - diag => "", - depth => 0, - }, - ], - [ - 'pass diag', - '$cap->ok(1, "pass diag"); - $cap->diag("pass diag1"); - $cap->diag("pass diag2");', - { - name => "pass diag", - ok => 1, - actual_ok => 1, - reason => "", - type => "", - diag => "pass diag1\npass diag2\n", - depth => 0, - }, - ], - [ - 'pass diag no \\n', - '$cap->ok(1, "pass diag"); - $cap->diag("pass diag1"); - $cap->diag("pass diag2");', - { - name => "pass diag", - ok => 1, - actual_ok => 1, - reason => "", - type => "", - diag => "pass diag1\npass diag2", - depth => 0, - }, - ], - [ - 'fail', - '$cap->ok(0, "fail"); - $cap->diag("fail diag");', - { - name => "fail", - ok => 0, - actual_ok => 0, - reason => "", - type => "", - diag => "fail diag\n", - depth => 0, - }, - ], - [ - 'skip', - '$cap->skip("just because");', - { - name => "", - ok => 1, - actual_ok => 1, - reason => "just because", - type => "skip", - diag => "", - depth => 0, - }, - ], - [ - 'todo_skip', - '$cap->todo_skip("why not");', - { - name => "", - ok => 1, - actual_ok => 0, - reason => "why not", - type => "todo_skip", - diag => "", - depth => 0, - }, - ], -); - -my $big_code = ""; -my @big_expect; - -foreach my $test (@tests) -{ - my ($name, $code, $expect) = @$test; - - $big_code .= "$code\n"; - push(@big_expect, $expect); - - my $test_sub = eval "sub {$code}"; - - check_test($test_sub, $expect, $name); -} - -my $big_test_sub = eval "sub {$big_code}"; - -check_tests($big_test_sub, \@big_expect, "run all"); diff --git a/cpan/Test-Simple/t/TTLegacy/depth.t b/cpan/Test-Simple/t/TTLegacy/depth.t deleted file mode 100644 index 53ba7e0779..0000000000 --- a/cpan/Test-Simple/t/TTLegacy/depth.t +++ /dev/null @@ -1,39 +0,0 @@ -use strict; -use warnings; - -BEGIN { - if ($ENV{PERL_CORE}) { - chdir 't'; - @INC = ('../lib', 'lib'); - } - else { - unshift @INC, 't/lib'; - } -} - -use Test::Tester; - -use MyTest; - -my $test = Test::Builder->new; -$test->plan(tests => 2); - -sub deeper -{ - MyTest::ok(1); -} - -{ - - my @results = run_tests( - sub { - MyTest::ok(1); - deeper(); - } - ); - - local $Test::Builder::Level = 0; - $test->is_num($results[1]->{depth}, 1, "depth 1"); - $test->is_num($results[2]->{depth}, 2, "deeper"); -} - diff --git a/cpan/Test-Simple/t/TTLegacy/run_test.t b/cpan/Test-Simple/t/TTLegacy/run_test.t deleted file mode 100644 index 8288f19ab8..0000000000 --- a/cpan/Test-Simple/t/TTLegacy/run_test.t +++ /dev/null @@ -1,145 +0,0 @@ -use strict; - -use Test::Tester; - -use Data::Dumper qw(Dumper); - -my $test = Test::Builder->new; -$test->plan(tests => 54); - -my $cap; - -{ - $cap = Test::Tester->capture; - my ($prem, @results) = run_tests( - sub {$cap->ok(1, "run pass")} - ); - - local $Test::Builder::Level = 0; - - $test->is_eq($prem, "", "run pass no prem"); - $test->is_num(scalar (@results), 1, "run pass result count"); - - my $res = $results[0]; - - $test->is_eq($res->{name}, "run pass", "run pass name"); - $test->is_eq($res->{ok}, 1, "run pass ok"); - $test->is_eq($res->{actual_ok}, 1, "run pass actual_ok"); - $test->is_eq($res->{reason}, "", "run pass reason"); - $test->is_eq($res->{type}, "", "run pass type"); - $test->is_eq($res->{diag}, "", "run pass diag"); - $test->is_num($res->{depth}, 0, "run pass depth"); -} - -{ - my ($prem, @results) = run_tests( - sub {$cap->ok(0, "run fail")} - ); - - local $Test::Builder::Level = 0; - - $test->is_eq($prem, "", "run fail no prem"); - $test->is_num(scalar (@results), 1, "run fail result count"); - - my $res = $results[0]; - - $test->is_eq($res->{name}, "run fail", "run fail name"); - $test->is_eq($res->{actual_ok}, 0, "run fail actual_ok"); - $test->is_eq($res->{ok}, 0, "run fail ok"); - $test->is_eq($res->{reason}, "", "run fail reason"); - $test->is_eq($res->{type}, "", "run fail type"); - $test->is_eq($res->{diag}, "", "run fail diag"); - $test->is_num($res->{depth}, 0, "run fail depth"); -} - -{ - my ($prem, @results) = run_tests( - sub {$cap->skip("just because")} - ); - - local $Test::Builder::Level = 0; - - $test->is_eq($prem, "", "skip no prem"); - $test->is_num(scalar (@results), 1, "skip result count"); - - my $res = $results[0]; - - $test->is_eq($res->{name}, "", "skip name"); - $test->is_eq($res->{actual_ok}, 1, "skip actual_ok"); - $test->is_eq($res->{ok}, 1, "skip ok"); - $test->is_eq($res->{reason}, "just because", "skip reason"); - $test->is_eq($res->{type}, "skip", "skip type"); - $test->is_eq($res->{diag}, "", "skip diag"); - $test->is_num($res->{depth}, 0, "skip depth"); -} - -{ - my ($prem, @results) = run_tests( - sub {$cap->todo_skip("just because")} - ); - - local $Test::Builder::Level = 0; - - $test->is_eq($prem, "", "todo_skip no prem"); - $test->is_num(scalar (@results), 1, "todo_skip result count"); - - my $res = $results[0]; - - $test->is_eq($res->{name}, "", "todo_skip name"); - $test->is_eq($res->{actual_ok}, 0, "todo_skip actual_ok"); - $test->is_eq($res->{ok}, 1, "todo_skip ok"); - $test->is_eq($res->{reason}, "just because", "todo_skip reason"); - $test->is_eq($res->{type}, "todo_skip", "todo_skip type"); - $test->is_eq($res->{diag}, "", "todo_skip diag"); - $test->is_num($res->{depth}, 0, "todo_skip depth"); -} - -{ - my ($prem, @results) = run_tests( - sub {$cap->diag("run diag")} - ); - - local $Test::Builder::Level = 0; - - $test->is_eq($prem, "run diag\n", "run diag prem"); - $test->is_num(scalar (@results), 0, "run diag result count"); -} - -{ - my ($prem, @results) = run_tests( - sub { - $cap->ok(1, "multi pass"); - $cap->diag("multi pass diag1"); - $cap->diag("multi pass diag2"); - $cap->ok(0, "multi fail"); - $cap->diag("multi fail diag"); - } - ); - - local $Test::Builder::Level = 0; - - $test->is_eq($prem, "", "run multi no prem"); - $test->is_num(scalar (@results), 2, "run multi result count"); - - my $res_pass = $results[0]; - - $test->is_eq($res_pass->{name}, "multi pass", "run multi pass name"); - $test->is_eq($res_pass->{actual_ok}, 1, "run multi pass actual_ok"); - $test->is_eq($res_pass->{ok}, 1, "run multi pass ok"); - $test->is_eq($res_pass->{reason}, "", "run multi pass reason"); - $test->is_eq($res_pass->{type}, "", "run multi pass type"); - $test->is_eq($res_pass->{diag}, "multi pass diag1\nmulti pass diag2\n", - "run multi pass diag"); - $test->is_num($res_pass->{depth}, 0, "run multi pass depth"); - - my $res_fail = $results[1]; - - $test->is_eq($res_fail->{name}, "multi fail", "run multi fail name"); - $test->is_eq($res_pass->{actual_ok}, 1, "run multi fail actual_ok"); - $test->is_eq($res_fail->{ok}, 0, "run multi fail ok"); - $test->is_eq($res_pass->{reason}, "", "run multi fail reason"); - $test->is_eq($res_pass->{type}, "", "run multi fail type"); - $test->is_eq($res_fail->{diag}, "multi fail diag\n", "run multi fail diag"); - $test->is_num($res_pass->{depth}, 0, "run multi fail depth"); -} - diff --git a/cpan/Test-Simple/t/Tester/tbt_01basic.t b/cpan/Test-Simple/t/Tester/tbt_01basic.t index 1b4b556d3f..62820741c2 100644 --- a/cpan/Test-Simple/t/Tester/tbt_01basic.t +++ b/cpan/Test-Simple/t/Tester/tbt_01basic.t @@ -51,7 +51,7 @@ test_test("testing failing on the same line with the same name"); test_out("not ok 1 - name # TODO Something"); test_out("# Failed (TODO) test ($0 at line 56)"); -TODO: { +TODO: { local $TODO = "Something"; fail("name"); } diff --git a/cpan/Test-Simple/t/Tester/tbt_02fhrestore.t b/cpan/Test-Simple/t/Tester/tbt_02fhrestore.t index c7826cdf1d..e37357171b 100644 --- a/cpan/Test-Simple/t/Tester/tbt_02fhrestore.t +++ b/cpan/Test-Simple/t/Tester/tbt_02fhrestore.t @@ -7,9 +7,9 @@ use Symbol; # create temporary file handles that still point indirectly # to the right place -my $orig_o = gensym; +my $orig_o = gensym; my $orig_t = gensym; -my $orig_f = gensym; +my $orig_f = gensym; tie *$orig_o, "My::Passthru", \*STDOUT; tie *$orig_t, "My::Passthru", \*STDERR; diff --git a/cpan/Test-Simple/t/Tester/tbt_06errormess.t b/cpan/Test-Simple/t/Tester/tbt_06errormess.t index f68cba4e42..b02b617293 100644 --- a/cpan/Test-Simple/t/Tester/tbt_06errormess.t +++ b/cpan/Test-Simple/t/Tester/tbt_06errormess.t @@ -64,7 +64,7 @@ sub my_test_test my $text = shift; local $^W = 0; - # reset the outputs + # reset the outputs $t->output($original_output_handle); $t->failure_output($original_failure_handle); $t->todo_output($original_todo_handle); diff --git a/cpan/Test-Simple/t/Tester/tbt_07args.t b/cpan/Test-Simple/t/Tester/tbt_07args.t index 0e322128dc..9542d755f4 100644 --- a/cpan/Test-Simple/t/Tester/tbt_07args.t +++ b/cpan/Test-Simple/t/Tester/tbt_07args.t @@ -64,7 +64,7 @@ sub my_test_test my $text = shift; local $^W = 0; - # reset the outputs + # reset the outputs $t->output($original_output_handle); $t->failure_output($original_failure_handle); $t->todo_output($original_todo_handle); diff --git a/cpan/Test-Simple/t/Tester/tbt_is_bug.t b/cpan/Test-Simple/t/Tester/tbt_is_bug.t deleted file mode 100644 index 64642fca2a..0000000000 --- a/cpan/Test-Simple/t/Tester/tbt_is_bug.t +++ /dev/null @@ -1,31 +0,0 @@ -use strict; -use warnings; -use Test::Tester; -use Test::More; - -check_test( - sub { is "Foo", "Foo" }, - {ok => 1}, -); - -check_test( - sub { is "Bar", "Bar" }, - {ok => 1}, -); - -check_test( - sub { is "Baz", "Quux" }, - {ok => 0}, -); - -check_test( - sub { like "Baz", qr/uhg/ }, - {ok => 0}, -); - -check_test( - sub { like "Baz", qr/a/ }, - {ok => 1}, -); - -done_testing(); diff --git a/cpan/Test-Simple/t/circular_data.t b/cpan/Test-Simple/t/circular_data.t index 15eb6d406f..2fd819e1f4 100644 --- a/cpan/Test-Simple/t/circular_data.t +++ b/cpan/Test-Simple/t/circular_data.t @@ -59,7 +59,7 @@ ok( eq_array ([$s], [$r]) ); { # rt.cpan.org 11623 - # Make sure the circular ref checks don't get confused by a reference + # Make sure the circular ref checks don't get confused by a reference # which is simply repeating. my $a = {}; my $b = {}; diff --git a/cpan/Test-Simple/t/cmp_ok.t b/cpan/Test-Simple/t/cmp_ok.t index 07ed1a9f0b..c9b9f1bf65 100644 --- a/cpan/Test-Simple/t/cmp_ok.t +++ b/cpan/Test-Simple/t/cmp_ok.t @@ -15,7 +15,7 @@ $TB->level(0); sub try_cmp_ok { my($left, $cmp, $right, $error) = @_; - + my %expect; if( $error ) { $expect{ok} = 0; @@ -33,7 +33,7 @@ sub try_cmp_ok { eval { $ok = cmp_ok($left, $cmp, $right, "cmp_ok"); }; $TB->is_num(!!$ok, !!$expect{ok}, " right return"); - + my $diag = $err->read; if ($@) { diff --git a/cpan/Test-Simple/t/died.t b/cpan/Test-Simple/t/died.t index 181289544b..b4ee2fbbff 100644 --- a/cpan/Test-Simple/t/died.t +++ b/cpan/Test-Simple/t/died.t @@ -14,7 +14,6 @@ package My::Test; # Test::Builder's own and the ending diagnostics don't come out right. require Test::Builder; my $TB = Test::Builder->create; -$TB->stream->use_lresults; $TB->plan(tests => 3); diff --git a/cpan/Test-Simple/t/dont_overwrite_die_handler.t b/cpan/Test-Simple/t/dont_overwrite_die_handler.t index 51f4d08d4e..0657a06ca3 100644 --- a/cpan/Test-Simple/t/dont_overwrite_die_handler.t +++ b/cpan/Test-Simple/t/dont_overwrite_die_handler.t @@ -1,5 +1,4 @@ #!/usr/bin/perl -w -use Config; # To prevent conflict with some strawberry-portable versions BEGIN { if( $ENV{PERL_CORE} ) { @@ -16,6 +15,5 @@ BEGIN { use Test::More tests => 2; -$handler_called = 0; ok !eval { die }; is $handler_called, 1, 'existing DIE handler not overridden'; diff --git a/cpan/Test-Simple/t/eq_set.t b/cpan/Test-Simple/t/eq_set.t index 202f3d3665..fbdc52db1f 100644 --- a/cpan/Test-Simple/t/eq_set.t +++ b/cpan/Test-Simple/t/eq_set.t @@ -23,7 +23,7 @@ ok( eq_set([1,2,[3]], [1,[3],2]) ); # bugs.perl.org 36354 my $ref = \2; ok( eq_set( [$ref, "$ref", "$ref", $ref], - ["$ref", $ref, $ref, "$ref"] + ["$ref", $ref, $ref, "$ref"] ) ); TODO: { diff --git a/cpan/Test-Simple/t/exit.t b/cpan/Test-Simple/t/exit.t index 8c9e16d162..2b17ce06a8 100644 --- a/cpan/Test-Simple/t/exit.t +++ b/cpan/Test-Simple/t/exit.t @@ -24,6 +24,9 @@ my $Orig_Dir = cwd; my $Perl = File::Spec->rel2abs($^X); if( $^O eq 'VMS' ) { + # VMS can't use its own $^X in a system call until almost 5.8 + $Perl = "MCR $^X" if $] < 5.007003; + # Quiet noisy 'SYS$ABORT' $Perl .= q{ -"I../lib"} if $ENV{PERL_CORE}; $Perl .= q{ -"Mvmsish=hushed"}; @@ -101,7 +104,7 @@ while( my($test_name, $exit_code) = each %Tests ) { "(expected non-zero)"); } else { - $TB->is_num( $actual_exit, $Exit_Map{$exit_code}, + $TB->is_num( $actual_exit, $Exit_Map{$exit_code}, "$test_name exited with $actual_exit ". "(expected $Exit_Map{$exit_code})"); } diff --git a/cpan/Test-Simple/t/fail-like.t b/cpan/Test-Simple/t/fail-like.t index 19e748f567..0383094913 100644 --- a/cpan/Test-Simple/t/fail-like.t +++ b/cpan/Test-Simple/t/fail-like.t @@ -22,7 +22,7 @@ package My::Test; # This has to be a require or else the END block below runs before # Test::Builder's own and the ending diagnostics don't come out right. require Test::Builder; -my $TB = Test::Builder->create(); +my $TB = Test::Builder->create; $TB->plan(tests => 4); @@ -71,5 +71,7 @@ OUT } -# Test::More thinks it failed. Override that. -Test::Builder->new->no_ending(1); +END { + # Test::More thinks it failed. Override that. + exit(scalar grep { !$_ } $TB->summary); +} diff --git a/cpan/Test-Simple/t/fork.t b/cpan/Test-Simple/t/fork.t index 13121bc2cc..55d7aec1f9 100644 --- a/cpan/Test-Simple/t/fork.t +++ b/cpan/Test-Simple/t/fork.t @@ -12,7 +12,7 @@ use Config; my $Can_Fork = $Config{d_fork} || (($^O eq 'MSWin32' || $^O eq 'NetWare') and - $Config{useithreads} and + $Config{useithreads} and $Config{ccflags} =~ /-DPERL_IMPLICIT_SYS/ ); diff --git a/cpan/Test-Simple/t/harness_active.t b/cpan/Test-Simple/t/harness_active.t index bda5dae318..7b027a7b40 100644 --- a/cpan/Test-Simple/t/harness_active.t +++ b/cpan/Test-Simple/t/harness_active.t @@ -66,7 +66,7 @@ ERR { local $ENV{HARNESS_ACTIVE} = 1; - + #line 71 fail( "this fails" ); err_ok( <<ERR ); diff --git a/cpan/Test-Simple/t/is_deeply_fail.t b/cpan/Test-Simple/t/is_deeply_fail.t index b955d290f4..26036fb960 100644 --- a/cpan/Test-Simple/t/is_deeply_fail.t +++ b/cpan/Test-Simple/t/is_deeply_fail.t @@ -83,7 +83,7 @@ ERR #line 88 ok !is_deeply({ this => 42 }, { this => 43 }, 'hashes with different values'); -is( $out, "not ok 3 - hashes with different values\n", +is( $out, "not ok 3 - hashes with different values\n", 'hashes with different values' ); is( $err, <<ERR, ' right diagnostic' ); # Failed test 'hashes with different values' @@ -223,7 +223,7 @@ foreach my $test (@tests) { local $SIG{__WARN__} = sub { $warning .= join '', @_; }; ok !is_deeply(@$test); - like \$warning, + like \$warning, "/^is_deeply\\(\\) takes two or three args, you gave $num_args\.\n/"; } diff --git a/cpan/Test-Simple/t/is_deeply_with_threads.t b/cpan/Test-Simple/t/is_deeply_with_threads.t index 66a6641fa7..9908ef6608 100644 --- a/cpan/Test-Simple/t/is_deeply_with_threads.t +++ b/cpan/Test-Simple/t/is_deeply_with_threads.t @@ -16,27 +16,18 @@ use strict; use Config; BEGIN { - if ($] == 5.010000) { - print "1..0 # Threads are broken on 5.10.0\n"; - exit 0; - } - - my $works = 1; - $works &&= $] >= 5.008001; - $works &&= $Config{'useithreads'}; - $works &&= eval { require threads; 'threads'->import; 1 }; - - unless ($works) { + unless ( $] >= 5.008001 && $Config{'useithreads'} && + eval { require threads; 'threads'->import; 1; }) + { print "1..0 # Skip no working threads\n"; exit 0; } - + unless ( $ENV{AUTHOR_TESTING} ) { print "1..0 # Skip many perls have broken threads. Enable with AUTHOR_TESTING.\n"; exit 0; } } - use Test::More; my $Num_Threads = 5; diff --git a/cpan/Test-Simple/t/lib/MyTest.pm b/cpan/Test-Simple/t/lib/MyTest.pm deleted file mode 100644 index e8ad8a3e53..0000000000 --- a/cpan/Test-Simple/t/lib/MyTest.pm +++ /dev/null @@ -1,15 +0,0 @@ -use strict; -use warnings; - -package MyTest; - -use Test::Builder; - -my $Test = Test::Builder->new; - -sub ok -{ - $Test->ok(@_); -} - -1; diff --git a/cpan/Test-Simple/t/lib/SmallTest.pm b/cpan/Test-Simple/t/lib/SmallTest.pm deleted file mode 100644 index c2a875855e..0000000000 --- a/cpan/Test-Simple/t/lib/SmallTest.pm +++ /dev/null @@ -1,35 +0,0 @@ -use strict; -use warnings; - -package SmallTest; - -require Exporter; - -use vars qw( @ISA @EXPORT ); -@ISA = qw( Exporter ); -@EXPORT = qw( ok is_eq is_num ); - -use Test::Builder; - -my $Test = Test::Builder->new; - -sub ok -{ - $Test->ok(@_); -} - -sub is_eq -{ - $Test->is_eq(@_); -} - -sub is_num -{ - $Test->is_num(@_); -} - -sub getTest -{ - return $Test; -} -1; diff --git a/cpan/Test-Simple/t/lib/Test/Builder/NoOutput.pm b/cpan/Test-Simple/t/lib/Test/Builder/NoOutput.pm index 024c4a8898..bbdf73268f 100644 --- a/cpan/Test-Simple/t/lib/Test/Builder/NoOutput.pm +++ b/cpan/Test-Simple/t/lib/Test/Builder/NoOutput.pm @@ -66,9 +66,9 @@ sub create { tie *$err, "Test::Builder::NoOutput::Tee", \$outputs{all}, \$outputs{err}; tie *$todo, "Test::Builder::NoOutput::Tee", \$outputs{all}, \$outputs{todo}; - $self->tap->output($out); - $self->tap->failure_output($err); - $self->tap->todo_output($todo); + $self->output($out); + $self->failure_output($err); + $self->todo_output($todo); return $self; } @@ -101,7 +101,7 @@ sub TIEHANDLE { my @fhs; for my $ref (@refs) { - my $fh = Test::Builder->new->tap->_new_fh($ref); + my $fh = Test::Builder->_new_fh($ref); push @fhs, $fh; } diff --git a/cpan/Test-Simple/t/no_tests.t b/cpan/Test-Simple/t/no_tests.t index 7b3f76d34b..eafa38cacc 100644 --- a/cpan/Test-Simple/t/no_tests.t +++ b/cpan/Test-Simple/t/no_tests.t @@ -14,7 +14,6 @@ package My::Test; # Test::Builder's own and the ending diagnostics don't come out right. require Test::Builder; my $TB = Test::Builder->create; -$TB->stream->use_lresults; $TB->plan(tests => 3); diff --git a/cpan/Test-Simple/t/overload.t b/cpan/Test-Simple/t/overload.t index fe9bc46e5a..a86103746b 100644 --- a/cpan/Test-Simple/t/overload.t +++ b/cpan/Test-Simple/t/overload.t @@ -69,7 +69,7 @@ Test::More->builder->is_eq ($obj, "foo"); package Foo; ::is_deeply(['TestPackage'], ['TestPackage']); - ::is_deeply({'TestPackage' => 'TestPackage'}, + ::is_deeply({'TestPackage' => 'TestPackage'}, {'TestPackage' => 'TestPackage'}); ::is_deeply('TestPackage', 'TestPackage'); } diff --git a/cpan/Test-Simple/t/plan_no_plan.t b/cpan/Test-Simple/t/plan_no_plan.t index 59fab4d21c..3111592e97 100644 --- a/cpan/Test-Simple/t/plan_no_plan.t +++ b/cpan/Test-Simple/t/plan_no_plan.t @@ -8,10 +8,6 @@ BEGIN { use Test::More; BEGIN { - require warnings; - if( eval "warnings->can('carp')" ) { - plan skip_all => 'Modern::Open is installed, which breaks this test'; - } if( !$ENV{HARNESS_ACTIVE} && $ENV{PERL_CORE} ) { plan skip_all => "Won't work with t/TEST"; } diff --git a/cpan/Test-Simple/t/pod.t b/cpan/Test-Simple/t/pod.t deleted file mode 100644 index ac55c162df..0000000000 --- a/cpan/Test-Simple/t/pod.t +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/perl -w - -use Test::More; -plan skip_all => "POD tests skipped unless AUTHOR_TESTING is set" unless $ENV{AUTHOR_TESTING}; -my $test_pod = eval "use Test::Pod 1.00; 1"; -plan skip_all => "Test::Pod 1.00 required for testing POD" unless $test_pod; -all_pod_files_ok(); diff --git a/cpan/Test-Simple/t/ribasushi_diag.t b/cpan/Test-Simple/t/ribasushi_diag.t deleted file mode 100644 index 23fa3d5384..0000000000 --- a/cpan/Test-Simple/t/ribasushi_diag.t +++ /dev/null @@ -1,54 +0,0 @@ -use strict; -use warnings; - -use Test::More; - -BEGIN { - my $has_module = eval { require SQL::Abstract::Test; 1 }; - my $required = $ENV{AUTHOR_TESTING}; - - if ($required && !$has_module) { - die "This test requires 'SQL::Abstract::Test' to be installed when AUTHOR_TESTING.\n"; - } - else { - plan skip_all => "Only run when AUTHOR_TESTING is set"; - } -} - -{ - package Worker; - - sub do_work { - local $Test::Builder::Level = $Test::Builder::Level + 2; - shift->(); - } -} - -use SQL::Abstract::Test; -use Test::Tester2; - -my $events = intercept { - local $TODO = "Not today"; - - Worker::do_work( - sub { - - SQL::Abstract::Test::is_same_sql_bind( - 'buh', [], - 'bah', [1], - ); - - } - ); -}; - -events_are( - $events, - ok => { in_todo => 1 }, - diag => { in_todo => 1 }, - note => { in_todo => 1 }, - note => { in_todo => 1 }, - end => "All events are TODO" -); - -done_testing; diff --git a/cpan/Test-Simple/t/ribasushi_threads.t b/cpan/Test-Simple/t/ribasushi_threads.t deleted file mode 100644 index 46a011ce86..0000000000 --- a/cpan/Test-Simple/t/ribasushi_threads.t +++ /dev/null @@ -1,75 +0,0 @@ -use Config; - -BEGIN { - if ($] == 5.010000) { - print "1..0 # Threads are broken on 5.10.0\n"; - exit 0; - } - - my $works = 1; - $works &&= $] >= 5.008001; - $works &&= $Config{'useithreads'}; - $works &&= eval { require threads; 'threads'->import; 1 }; - - unless ($works) { - print "1..0 # Skip no working threads\n"; - exit 0; - } - - unless ( $ENV{AUTHOR_TESTING} ) { - print "1..0 # Skip many perls have broken threads. Enable with AUTHOR_TESTING.\n"; - exit 0; - } - - if ($INC{'Devel/Cover.pm'}) { - print "1..0 # SKIP Devel::Cover does not work with threads yet\n"; - exit 0; - } -} - -use threads; - -use strict; -use warnings; - -use Test::More; - -# basic tests -{ - pass('Test starts'); - my $ct_num = Test::More->builder->current_test; - - my $newthread = async { - my $out = ''; - - #simulate a subtest to not confuse the parent TAP emission - my $tb = Test::More->builder; - $tb->reset; - Test::More->builder->current_test(0); - for (qw/output failure_output todo_output/) { - close $tb->$_; - open ($tb->$_, '>', \$out); - } - - pass("In-thread ok") for (1,2,3); - - done_testing; - - close $tb->$_ for (qw/output failure_output todo_output/); - sleep(1); # tasty crashes without this - - $out; - }; - die "Thread creation failed: $! $@" if !defined $newthread; - - my $out = $newthread->join; - $out =~ s/^/ /gm; - print $out; - - # workaround for older Test::More confusing the plan under threads - Test::More->builder->current_test($ct_num); - - pass("Made it to the end"); -} - -done_testing; diff --git a/cpan/Test-Simple/t/skip.t b/cpan/Test-Simple/t/skip.t index 424e083fb0..f2ea9fbf20 100644 --- a/cpan/Test-Simple/t/skip.t +++ b/cpan/Test-Simple/t/skip.t @@ -7,21 +7,14 @@ BEGIN { } } -use Test::More; - -BEGIN { - require warnings; - if( eval "warnings->can('carp')" ) { - plan skip_all => 'Modern::Open is installed, which breaks this test'; - } -} +use Test::More tests => 17; # If we skip with the same name, Test::Harness will report it back and # we won't get lots of false bug reports. my $Why = "Just testing the skip interface."; SKIP: { - skip $Why, 2 + skip $Why, 2 unless Pigs->can('fly'); my $pig = Pigs->new; @@ -103,5 +96,3 @@ SKIP: { like $warning, qr/^skip\(\) was passed a non-numeric number of tests/; } - -done_testing; diff --git a/cpan/Test-Simple/t/skipall.t b/cpan/Test-Simple/t/skipall.t index 08c8543be2..5491be126e 100644 --- a/cpan/Test-Simple/t/skipall.t +++ b/cpan/Test-Simple/t/skipall.t @@ -8,7 +8,7 @@ BEGIN { else { unshift @INC, 't/lib'; } -} +} use strict; diff --git a/cpan/Test-Simple/t/strays.t b/cpan/Test-Simple/t/strays.t deleted file mode 100644 index 02a99ab996..0000000000 --- a/cpan/Test-Simple/t/strays.t +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/perl -w - -# Check that stray newlines in test output are properly handed. - -BEGIN { - print "1..0 # Skip not completed\n"; - exit 0; -} - -BEGIN { - if( $ENV{PERL_CORE} ) { - chdir 't'; - @INC = ('../lib', 'lib'); - } - else { - unshift @INC, 't/lib'; - } -} -chdir 't'; - -use Test::Builder::NoOutput; -my $tb = Test::Builder::NoOutput->create; - -$tb->ok(1, "name\n"); -$tb->ok(0, "foo\nbar\nbaz"); -$tb->skip("\nmoofer"); -$tb->todo_skip("foo\n\n"); diff --git a/cpan/Test-Simple/t/subtest/args.t b/cpan/Test-Simple/t/subtest/args.t index 8ae26baa93..5271323e3e 100644 --- a/cpan/Test-Simple/t/subtest/args.t +++ b/cpan/Test-Simple/t/subtest/args.t @@ -3,17 +3,6 @@ use strict; use Test::Builder; -BEGIN { - if( $ENV{PERL_CORE} ) { - chdir 't'; - @INC = ( '../lib', 'lib' ); - } - else { - unshift @INC, 't/lib'; - } -} -use Test::Builder::NoOutput; - my $tb = Test::Builder->new; $tb->ok( !eval { $tb->subtest() } ); @@ -22,12 +11,4 @@ $tb->like( $@, qr/^\Qsubtest()'s second argument must be a code ref/ ); $tb->ok( !eval { $tb->subtest("foo") } ); $tb->like( $@, qr/^\Qsubtest()'s second argument must be a code ref/ ); -$tb->subtest('Arg passing', sub { - my $foo = shift; - my $child = Test::Builder->new; - $child->is_eq($foo, 'foo'); - $child->done_testing; - $child->finalize; -}, 'foo'); - $tb->done_testing(); diff --git a/cpan/Test-Simple/t/subtest/bail_out.t b/cpan/Test-Simple/t/subtest/bail_out.t index be7ec76eff..70dc9ac56f 100644 --- a/cpan/Test-Simple/t/subtest/bail_out.t +++ b/cpan/Test-Simple/t/subtest/bail_out.t @@ -46,10 +46,10 @@ subtest 'bar' => sub { $Test->is_eq( $output, <<'OUT' ); 1..4 ok 1 -# Subtest: bar + # Subtest: bar 1..3 ok 1 - # Subtest: sub_bar + # Subtest: sub_bar 1..3 ok 1 ok 2 diff --git a/cpan/Test-Simple/t/subtest/basic.t b/cpan/Test-Simple/t/subtest/basic.t index cccadf2fc4..93780a9da2 100644 --- a/cpan/Test-Simple/t/subtest/basic.t +++ b/cpan/Test-Simple/t/subtest/basic.t @@ -175,7 +175,7 @@ END plan skip_all => 'subtest with skip_all'; ok 0, 'This should never be run'; }; - is +Test::Builder->new->lresults->{Test_Results}[-1]{type}, 'skip', + is +Test::Builder->new->{Test_Results}[-1]{type}, 'skip', 'Subtests which "skip_all" are reported as skipped tests'; } diff --git a/cpan/Test-Simple/t/subtest/fork.t b/cpan/Test-Simple/t/subtest/fork.t index ccfeb1000b..e072a4813e 100644 --- a/cpan/Test-Simple/t/subtest/fork.t +++ b/cpan/Test-Simple/t/subtest/fork.t @@ -33,17 +33,17 @@ subtest 'fork within subtest' => sub { is $?, 0, 'child exit status'; like $child_output, qr/^[\s#]+Child Done\s*\z/, 'child output'; - } + } else { $pipe->writer; # Force all T::B output into the pipe, for the parent # builder as well as the current subtest builder. - my $builder = Test::Builder->new; - $builder->tap->output($pipe); - $builder->tap->failure_output($pipe); - $builder->tap->todo_output($pipe); - + no warnings 'redefine'; + *Test::Builder::output = sub { $pipe }; + *Test::Builder::failure_output = sub { $pipe }; + *Test::Builder::todo_output = sub { $pipe }; + diag 'Child Done'; exit 0; } diff --git a/cpan/Test-Simple/t/subtest/line_numbers.t b/cpan/Test-Simple/t/subtest/line_numbers.t index c1736d07d3..7a20a60ae6 100644 --- a/cpan/Test-Simple/t/subtest/line_numbers.t +++ b/cpan/Test-Simple/t/subtest/line_numbers.t @@ -26,7 +26,7 @@ $ENV{HARNESS_ACTIVE} = 0; our %line; { - test_out("# Subtest: namehere"); + test_out(" # Subtest: namehere"); test_out(" 1..3"); test_out(" ok 1"); test_out(" not ok 2"); @@ -43,11 +43,11 @@ our %line; ok 0; BEGIN{ $line{innerfail1} = __LINE__ } ok 1; }; BEGIN{ $line{outerfail1} = __LINE__ } - + test_test("un-named inner tests"); } { - test_out("# Subtest: namehere"); + test_out(" # Subtest: namehere"); test_out(" 1..3"); test_out(" ok 1 - first is good"); test_out(" not ok 2 - second is bad"); @@ -65,7 +65,7 @@ our %line; ok 0, "second is bad"; BEGIN{ $line{innerfail2} = __LINE__ } ok 1, "third is good"; }; BEGIN{ $line{outerfail2} = __LINE__ } - + test_test("named inner tests"); } @@ -78,7 +78,7 @@ sub run_the_subtest { }; BEGIN{ $line{outerfail3} = __LINE__ } } { - test_out("# Subtest: namehere"); + test_out(" # Subtest: namehere"); test_out(" 1..3"); test_out(" ok 1 - first is good"); test_out(" not ok 2 - second is bad"); @@ -91,11 +91,11 @@ sub run_the_subtest { test_err("# at $0 line $line{outerfail3}."); run_the_subtest(); - + test_test("subtest() called from a sub"); } { - test_out( "# Subtest: namehere"); + test_out( " # Subtest: namehere"); test_out( " 1..0"); test_err( " # No tests run!"); test_out( 'not ok 1 - No tests run for subtest "namehere"'); @@ -109,7 +109,7 @@ sub run_the_subtest { test_test("lineno in 'No tests run' diagnostic"); } { - test_out("# Subtest: namehere"); + test_out(" # Subtest: namehere"); test_out(" 1..1"); test_out(" not ok 1 - foo is bar"); test_err(" # Failed test 'foo is bar'"); diff --git a/cpan/Test-Simple/t/subtest/predicate.t b/cpan/Test-Simple/t/subtest/predicate.t index 73b9c81056..4e29a426b1 100644 --- a/cpan/Test-Simple/t/subtest/predicate.t +++ b/cpan/Test-Simple/t/subtest/predicate.t @@ -40,7 +40,7 @@ sub foobar_ok ($;$) { }; } { - test_out("# Subtest: namehere"); + test_out(" # Subtest: namehere"); test_out(" 1..2"); test_out(" ok 1 - foo"); test_out(" not ok 2 - bar"); @@ -65,7 +65,7 @@ sub foobar_ok_2 ($;$) { foobar_ok($value, $name); } { - test_out("# Subtest: namehere"); + test_out(" # Subtest: namehere"); test_out(" 1..2"); test_out(" ok 1 - foo"); test_out(" not ok 2 - bar"); @@ -95,7 +95,7 @@ sub barfoo_ok ($;$) { }); } { - test_out("# Subtest: namehere"); + test_out(" # Subtest: namehere"); test_out(" 1..2"); test_out(" ok 1 - foo"); test_out(" not ok 2 - bar"); @@ -120,7 +120,7 @@ sub barfoo_ok_2 ($;$) { barfoo_ok($value, $name); } { - test_out("# Subtest: namehere"); + test_out(" # Subtest: namehere"); test_out(" 1..2"); test_out(" ok 1 - foo"); test_out(" not ok 2 - bar"); @@ -138,10 +138,10 @@ sub barfoo_ok_2 ($;$) { # A subtest-based predicate called from within a subtest { - test_out("# Subtest: outergroup"); + test_out(" # Subtest: outergroup"); test_out(" 1..2"); test_out(" ok 1 - this passes"); - test_out(" # Subtest: namehere"); + test_out(" # Subtest: namehere"); test_out(" 1..2"); test_out(" ok 1 - foo"); test_out(" not ok 2 - bar"); diff --git a/cpan/Test-Simple/t/subtest/threads.t b/cpan/Test-Simple/t/subtest/threads.t index 5d053ca2db..0d70b1e6e5 100644 --- a/cpan/Test-Simple/t/subtest/threads.t +++ b/cpan/Test-Simple/t/subtest/threads.t @@ -5,8 +5,8 @@ use warnings; use Config; BEGIN { - unless ( $] >= 5.008001 && $Config{'useithreads'} && - eval { require threads; 'threads'->import; 1; }) + unless ( $] >= 5.008001 && $Config{'useithreads'} && + eval { require threads; 'threads'->import; 1; }) { print "1..0 # Skip: no working threads\n"; exit 0; diff --git a/cpan/Test-Simple/t/subtest/todo.t b/cpan/Test-Simple/t/subtest/todo.t index 5ed15c408f..7269da9b95 100644 --- a/cpan/Test-Simple/t/subtest/todo.t +++ b/cpan/Test-Simple/t/subtest/todo.t @@ -52,7 +52,7 @@ sub test_subtest_in_todo { my ($set_via, $todo_reason, $level) = @$combo; test_out( - "# Subtest: xxx", + " # Subtest: xxx", @outlines, "not ok 1 - $xxx # TODO $todo_reason", "# Failed (TODO) test '$xxx'", @@ -84,11 +84,12 @@ sub test_subtest_in_todo { package Foo; # If several stack frames are in package 'main' then $Level # could be wrong and $main::TODO might still be found. Using # another package makes the tests more sensitive. - + sub main::subtest_at_level { my ($name, $code, $level) = @_; if ($level > 1) { + local $Test::Builder::Level = $Test::Builder::Level + 1; main::subtest_at_level($name, $code, $level-1); } else { diff --git a/cpan/Test-Simple/t/test_use_ok.t b/cpan/Test-Simple/t/test_use_ok.t deleted file mode 100644 index 0b4b9a7d35..0000000000 --- a/cpan/Test-Simple/t/test_use_ok.t +++ /dev/null @@ -1,40 +0,0 @@ -use strict; -use Test::More; -use ok; -use ok 'strict'; -use ok 'Test::More'; -use ok 'ok'; - -my $class = 'Test::Builder'; -BEGIN { - ok(!$class, '$class is declared, but not yet set'); - - - my $success = eval 'use ok $class'; - my $error = $@; - - ok(!$success, "Threw an exception"); - like( - $error, - qr/^'use ok' called with an empty argument, did you try to use a package name from an uninitialized variable\?/, - "Threw expected exception" - ); - - - - $success = eval 'use ok $class, "xxx"'; - $error = $@; - - ok(!$success, "Threw an exception"); - like( - $error, - qr/^'use ok' called with an empty argument, did you try to use a package name from an uninitialized variable\?/, - "Threw expected exception when arguments are added" - ); -} - -my $class2; -BEGIN {$class2 = 'Test::Builder'}; -use ok $class2; - -done_testing; diff --git a/cpan/Test-Simple/t/threads.t b/cpan/Test-Simple/t/threads.t index 51b374d9f9..42ba8c269c 100644 --- a/cpan/Test-Simple/t/threads.t +++ b/cpan/Test-Simple/t/threads.t @@ -8,25 +8,11 @@ BEGIN { } use Config; - BEGIN { - if ($] == 5.010000) { - print "1..0 # Threads are broken on 5.10.0\n"; - exit 0; - } - - my $works = 1; - $works &&= $] >= 5.008001; - $works &&= $Config{'useithreads'}; - $works &&= eval { require threads; 'threads'->import; 1 }; - - unless ($works) { - print "1..0 # Skip no working threads\n"; - exit 0; - } - - unless ( $ENV{AUTHOR_TESTING} ) { - print "1..0 # Skip many perls have broken threads. Enable with AUTHOR_TESTING.\n"; + unless ( $] >= 5.008001 && $Config{'useithreads'} && + eval { require threads; 'threads'->import; 1; }) + { + print "1..0 # Skip: no working threads\n"; exit 0; } } @@ -39,8 +25,8 @@ $Test->exported_to('main'); $Test->plan(tests => 6); for(1..5) { - 'threads'->create(sub { - $Test->ok(1,"Each of these should app the test number") + 'threads'->create(sub { + $Test->ok(1,"Each of these should app the test number") })->join; } diff --git a/cpan/Test-Simple/t/todo.t b/cpan/Test-Simple/t/todo.t index 838f469281..91861be3cb 100644 --- a/cpan/Test-Simple/t/todo.t +++ b/cpan/Test-Simple/t/todo.t @@ -9,13 +9,6 @@ BEGIN { use Test::More; -BEGIN { - require warnings; - if( eval "warnings->can('carp')" ) { - plan skip_all => 'Modern::Open is installed, which breaks this test'; - } -} - plan tests => 36; @@ -89,9 +82,9 @@ my $builder = Test::More->builder; my $exported_to = $builder->exported_to; TODO: { $builder->exported_to("Wibble"); - + local $TODO = "testing \$TODO with an incorrect exported_to()"; - + fail("Just testing todo"); } @@ -144,7 +137,6 @@ is $is_todo, 'Nesting TODO', ok $in_todo, " but we're in_todo()"; } -# line 200 eval { $builder->todo_end; }; diff --git a/cpan/Test-Simple/t/undef.t b/cpan/Test-Simple/t/undef.t index d560f8231c..2c8cace491 100644 --- a/cpan/Test-Simple/t/undef.t +++ b/cpan/Test-Simple/t/undef.t @@ -11,14 +11,7 @@ BEGIN { } use strict; -use Test::More; - -BEGIN { - require warnings; - if( eval "warnings->can('carp')" ) { - plan skip_all => 'Modern::Open is installed, which breaks this test'; - } -} +use Test::More tests => 21; BEGIN { $^W = 1; } @@ -43,7 +36,7 @@ sub warnings_like { my $Filename = quotemeta $0; - + is( undef, undef, 'undef is undef'); no_warnings; @@ -103,5 +96,3 @@ no_warnings; is_deeply([ undef ], [ undef ]); no_warnings; } - -done_testing; diff --git a/cpan/Test-Simple/t/utf8.t b/cpan/Test-Simple/t/utf8.t index 2930226e3e..f68b2a7680 100644 --- a/cpan/Test-Simple/t/utf8.t +++ b/cpan/Test-Simple/t/utf8.t @@ -43,9 +43,9 @@ SKIP: { for my $method (keys %handles) { my $src = $handles{$method}; - + my $dest = Test::More->builder->$method; - + is_deeply { map { $_ => 1 } PerlIO::get_layers($dest) }, { map { $_ => 1 } PerlIO::get_layers($src) }, "layers copied to $method"; @@ -56,7 +56,7 @@ SKIP: { # Test utf8 is ok. { my $uni = "\x{11e}"; - + my @warnings; local $SIG{__WARN__} = sub { push @warnings, @_; diff --git a/cpan/Test-Simple/t/versions.t b/cpan/Test-Simple/t/versions.t index c5a62a52b0..cb83599364 100644 --- a/cpan/Test-Simple/t/versions.t +++ b/cpan/Test-Simple/t/versions.t @@ -7,34 +7,22 @@ use strict; use Test::More; -{ - local $SIG{__WARN__} = sub { 1 }; - require Test::Builder; - require Test::Builder::Module; - require Test::Simple; - require Test::Builder::Tester; - require Test::Tester2; - require Test::Tester; -} +require Test::Builder; +require Test::Builder::Module; +require Test::Simple; my $dist_version = Test::More->VERSION; -like( $dist_version, qr/^ \d+ \. \d+ $/x, "Version number is sane" ); +like( $dist_version, qr/^ \d+ \. \d+ $/x ); my @modules = qw( Test::Simple Test::Builder Test::Builder::Module - Test::Builder::Tester - Test::Tester2 - Test::Tester ); for my $module (@modules) { - my $file = $module; - $file =~ s{(::|')}{/}g; - $file .= ".pm"; - is( $module->VERSION, $module->VERSION, sprintf("%-22s %s", $module, $INC{$file}) ); + is( $dist_version, $module->VERSION, $module ); } -done_testing(); +done_testing(4); diff --git a/dist/Carp/t/Carp.t b/dist/Carp/t/Carp.t index 2e041841ec..b12c482ae8 100644 --- a/dist/Carp/t/Carp.t +++ b/dist/Carp/t/Carp.t @@ -310,13 +310,15 @@ cluck_undef( 0, "undef", 2, undef, 4 ); # check that Carp respects CORE::GLOBAL::caller override after Carp # has been compiled -require B; # For older Test::More versions that do not auto-load it for my $bodge_job ( 2, 1, 0 ) { SKIP: { skip "can't safely detect incomplete caller override on perl $]", 6 if $bodge_job && !Carp::CALLER_OVERRIDE_CHECK_OK; print '# ', ( $bodge_job ? 'Not ' : '' ), "setting \@DB::args in caller override\n"; - + if ( $bodge_job == 1 ) { + require B; + print "# required B\n"; + } my $accum = ''; local *CORE::GLOBAL::caller = sub { local *__ANON__ = "fakecaller"; @@ -332,22 +334,11 @@ for my $bodge_job ( 2, 1, 0 ) { SKIP: { return CORE::caller( ( $_[0] || 0 ) + 1 ); } }; - eval "scalar caller()"; like( $accum, qr/main::fakecaller/, "test CORE::GLOBAL::caller override in eval" ); - $accum = ''; - my $got; - { - # Test::Builder loads B now, so we have to pretend it is not loaded. - # Carp simply wraps a call to svref_2object in an eval, so if that - # method does not exist we emulate not having B. Localizing the glob - # temporarily removes the sub. - local *B::svref_2object unless $bodge_job == 1; - $got = XA::long(42); - } - + my $got = XA::long(42); like( $accum, qr/main::fakecaller/, "test CORE::GLOBAL::caller override in Carp" ); my $package = 'XA'; diff --git a/ext/DynaLoader/t/DynaLoader.t b/ext/DynaLoader/t/DynaLoader.t index caf2e507f9..ade1f8e52b 100644 --- a/ext/DynaLoader/t/DynaLoader.t +++ b/ext/DynaLoader/t/DynaLoader.t @@ -3,7 +3,7 @@ use strict; use Config; use Test::More; -my (%modules, %no_unload); +my %modules; my $db_file; BEGIN { @@ -24,16 +24,10 @@ BEGIN { $db_file => q| ::is( ref $db_file->can('TIEHASH'), 'CODE' ) |, # 5.0 'Socket' => q| ::is( ref Socket->can('inet_aton'),'CODE' ) |, # 5.0 'Time::HiRes'=> q| ::is( ref Time::HiRes->can('usleep'),'CODE' ) |, # 5.7.3 - 'B' => q| ::is( ref B->can('svref_2object'),'CODE' ) |, # Test::Builder loads this. - 'Encode' => q| ::is( ref Encode->can('decode'),'CODE' ) |, # Test::Builder loads this. ); -# These modules must not be unloaded since they are needed by Test::Builder -%no_unload = ( - 'B' => 1, - 'Encode' => 1, - 'List::Util' => 1, -); +plan tests => 26 + keys(%modules) * 3; + # Try to load the module use_ok( 'DynaLoader' ); @@ -143,6 +137,7 @@ for my $module (sort keys %modules) { } } +# checking internal consistency is( scalar @DynaLoader::dl_librefs, scalar keys %modules, "checking number of items in \@dl_librefs" ); is( scalar @DynaLoader::dl_modules, scalar keys %modules, "checking number of items in \@dl_modules" ); @@ -155,7 +150,6 @@ for my $libref (reverse @DynaLoader::dl_librefs) { skip "unloading unsupported on $^O", 2 if ($old_darwin || $^O eq 'VMS'); my $module = pop @loaded_modules; - next if $no_unload{$module}; skip "File::Glob sets PL_opfreehook", 2 if $module eq 'File::Glob'; my $r = eval { DynaLoader::dl_unload_file($libref) }; is( $@, '', "calling dl_unload_file() for $module" ); @@ -192,5 +186,3 @@ SKIP: { "mod2fname + libname_unique correctly truncates long names" ); } - -done_testing; diff --git a/lib/.gitignore b/lib/.gitignore index 1a378f0781..8d281cae43 100644 --- a/lib/.gitignore +++ b/lib/.gitignore @@ -202,7 +202,6 @@ /if.pm /lib.pm /mro.pm -/ok.pm /ops.pm /parent.pm /perlfaq.pm |