Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8451587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:16:52+00:00 2026-06-10T11:16:52+00:00

I am practicing to make a new module using Module::Starter. I have written a

  • 0

I am practicing to make a new module using Module::Starter. I have written a few test cases for a package, and they run OK sometimes.

However I noticed there are two problems:

  • When the test cases fail, I want put some print statements in the function being tested. I ran make test and it only tells me that my test cases failed, it does not show my printed output, despite that I am really sure that the print statements are reached.

  • Say I have three test cases to test one function, I put a print statement inside the function, when the test cases run, it reports that only 1 out of the three test cases were run. If I remove the print statement, all three test cases will run. Why is that?

Here’s my code:

# package declaration and stuff...
sub get_in {
  my ( $hash, @path ) = @_;
  my $ref = $hash;
  print 'lol'; # This is the troublesome print statement. Remove this statement and all three test cases will run and pass
  foreach (@path) {
    if ( ref($ref) eq 'HASH' && exists $ref->{$_} ) {
      $ref = $ref->{$_};
    } else {
      return undef;
    }
  }
  return $ref;
}

This is the test cases:

use Test::More tests => 3;
use strict;
use warnings;
use diagnostics;
require_ok('Foo::Doc');
ok( Foo::Doc::get_in( { 'a' => { 'b' => { 'c' => 101 } } }, 'a', 'b', 'c' ) == 101 );
ok( @{ Foo::Doc::get_in( { 'a' => { 'b' => { 'c' => [ 1, 2, 3 ] } } }, 'a', 'b', 'c' ) } == @{ [ 1, 2, 3 ] } );
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T11:16:54+00:00Added an answer on June 10, 2026 at 11:16 am

    There are a few problems with you tests that need to be addressed as well as your question itself. First your question:

    If you want output to show up in tests, you need to explicitly print to standard error. As a best practice, you also need your output prefaced with #. The Test::More module provides tools you can use to do this easily.

    my $got = Foo::Doc::get_in( { 'a' => { 'b' => { 'c' => 101 } } }, 'a', 'b', 'c' );
    ok($got == 101); # you probably want is() instead, see below
    diag("GOT $got"); # outputs "# GOT 101" or whatever to STDERR
    

    If you don’t want to print that output every time, but only when verbose logging is requested, you can use note:

    note("GOT $got");
    

    This is useful when you use prove -v to run your tests:

    prove -l -v t/test.t
    

    There’s also an explain function that will dump out complex output for viewing:

    diag explain $got;
    # OR
    note explain $got;
    

    As for your other problems. It’s generally preferable to use is() to ok():

    is($got, 101); # gives slightly more readable output on error
    

    Also, when testing complex data structures you need to use is_deeply() to make a complete comparison:

    is_deeply($got, [1, 2, 3]);
    

    You should definitely take a look at the documentation of Test::More because there’s a great deal of useful information in there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been practicing TDD and (some) XP for a few years now and
while practicing recursive functions, I have written this code for fibonacci series and (factorial)
I have started practicing TDD approach. I am pretty much new to unit testing.
I have been practicing some old C++ problems to prepare for a few job
I am practicing using pointers. I have a pointer to an array of 3
I am new to TCL and have been practicing a bit on my own.
I'm practicing using mulitple files and header files etc. So I have this project
I'm practicing recursion using Java and I've hit a problem. I'm trying to make
Practicing what is written here: ScalaForms , I have created the following form: val
I have been practicing writing a number of Ruby scrapers using Mechanize and Nokogiri.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.