thanos1983 has asked for the wisdom of the Perl Monks concerning the following question:
Dear Monks,
I am trying to write my first Perl module (Net::SNTP::Client). I have post several questions over and over trying to get some help from the experts. So unfortunately now I got stack again, with the testing and verification of the module.
So first thing first. The module code if someone want to test it can be found here RFC: Net::SNTP::Client v1.
So as a next step I should explain what I am doing.
I was following the instructions from How to make a CPAN Module Distribution where I completed all steps even the testing part. Now I am trying to verify my module before I uploaded on CPAN and I got stack.
I am trying to install the module manually by applying the following commands:
perl Makefile.PL make make test sudo make install
Everything seems to be fine up to the point of make test. I am getting the following error:
make test PERL_DL_NONLAZY=1 "/usr/bin/perl" "-MExtUtils::Command::MM" "-MTest::H +arness" "-e" "undef *Test::Harness::Switches; test_harness(0, 'blib/l +ib', 'blib/arch')" t/*.t t/Net-SNTP-Client.t .. 1/15 # Failed test 'Module Hash Keys are Identical' # at t/Net-SNTP-Client.t line 94. # Failed test 'Exptected Output From the Module Received' # at t/Net-SNTP-Client.t line 98. # Comparing hash keys of $data # Missing: 'Net-SNTP-Client.t' # Extra: 't/Net-SNTP-Client.t' # Looks like you failed 2 tests of 15. t/Net-SNTP-Client.t .. Dubious, test returned 2 (wstat 512, 0x200) Failed 2/15 subtests Test Summary Report ------------------- t/Net-SNTP-Client.t (Wstat: 512 Tests: 15 Failed: 2) Failed tests: 6-7 Non-zero exit status: 2 Files=1, Tests=15, 1 wallclock secs ( 0.04 usr 0.00 sys + 0.11 cusr + 0.02 csys = 0.17 CPU) Result: FAIL Failed 1/1 test programs. 2/15 subtests failed. make: *** [test_dynamic] Error 2
The strange part is that I am executing the test manually inside the /t directory through the command: perl Net-SNTP-Client.t everything compiles and executes just fine.
Sample of output:
1..15 ok 1 - use Net::SNTP::Client; ok 2 - Module Hash Input Works ok 3 - Hostname Must be Defined ok 4 - Port Has to be Defined and Integer ok 5 - Got Hash Output ok 6 - Module Hash Keys are Identical ok 7 - Exptected Output From the Module Received ok 8 - Faulty Test Extra Key ok 9 - Correct Output Error Extra Hash Key ok 10 - Faulty Test no Hostname ok 11 - Correct Output Error No Hostname ok 12 - Faulty Test Negative Port Number ok 13 - Correct Output Error for Negative Port Number ok 14 - Faulty Test Out of Range Port Number ok 15 - Correct Output Error Out of Range Port Number
So the question is why is it failing, when manually is not? What I am missing?
Bellow is the test cases code in case that someone would like to replicate the error.
# Before 'make install' is performed this script should be runnable wi +th # 'make test'. After 'make install' it should work as 'perl Net-SNTP-C +lient.t' ######################### # change 'tests => 1' to 'tests => last_test_to_print'; use strict; use warnings; use lib '/home/username/Desktop/Net-SNTP-Client-0.01/lib/'; # note her +e use Test::More tests => 15; use Test::Deep; my %hashInputModuleHostnameTest = ( -hostname => undef ); my %hashInputModuleTest = ( -hostname => "0.pool.ntp.org", -port => 123 ); my %hashInputModuleTestExtraKeysInserted = ( -hostname => "0.pool.n +tp.org", -port => 123, -RFC4330 => 1, -clearScreen => 1, -extraKey => "Test" ); my %hashInputModuleTestNoHostName = ( -port => 123, -RFC4330 => 1, -clearScreen => 1 ); my %hashInputModuleTestNegativePortNumber = ( -hostname => "0.pool. +ntp.org", -port => -123, -RFC4330 => 1, -clearScreen => 1 ); my %hashInputModuleTestOutOfRangePortNumber = ( -hostname => "0.poo +l.ntp.org", -port => 65536, -RFC4330 => 1, -clearScreen => 1 ); my %hashInputModuleTestNotCorrectNtpPortNumber = ( -hostname => "0. +pool.ntp.org", -port => 12345, -RFC4330 => 1, -clearScreen => 1 ); my @hashInputModuleTestOriginalKeys = ( "-hostname" , "-port", "-RFC43 +30", "-clearScreen" ); my $hashRefExpected = { 'Net-SNTP-Client.t' => { 'VN' => 4, 'Originate Timestamp' => '00', 'Root Delay' => '0', 'Stratum' => '0', 'Receive Timestamp' => ignore(), 'Transmit Timestamp' => ignore(), 'Reference Timestamp' => '00', 'Precision' => '0', 'LI' => 0, 'Root Dispersion' => '0', 'Poll' => '0', 'Reference Identifier' => '0', 'Mode' => 3 }, 'RFC4330' => { 'Round Trip Delay' => ignore(), 'Clock Offset' => ignore() }, '0.pool.ntp.org' => { 'LI' => ignore(), 'Transmit Timestamp' => ignore(), 'Receive Timestamp' => ignore(), 'Reference Timestamp' => ignore(), 'Precision' => ignore(), 'Root Delay' => ignore(), 'Stratum' => ignore(), 'VN' => 4, 'Originate Timestamp' => ignore(), 'Mode' => 4, 'Poll' => ignore(), 'Reference Identifier' => ignore(), 'Root Dispersion' => ignore() } }; BEGIN { use_ok('Net::SNTP::Client', qw(getSNTPTime) ) }; ok( getSNTPTime( %hashInputModuleTest ), 'Module Hash Input Works' ); ok( !defined( $hashInputModuleHostnameTest{-hostname} ), 'Hostname Mus +t be Defined' ); ok( defined( $hashInputModuleTest{-port} ) && $hashInputModuleTest{-po +rt} =~ /\A (\d+) \z/xms , 'Port Has to be Defined and Integer' ); ok( my ( $error , $hashRefOutput ) = getSNTPTime( %hashInputModuleTest + ), 'Got Hash Output' ); my @expectedHashKeys = ( 'Net-SNTP-Client.t', 'RFC4330', '0.pool.ntp.o +rg' ); my @gotHashRefKeys = keys $hashRefOutput; ok( eq_set(\@gotHashRefKeys, \@expectedHashKeys), 'Module Hash Keys ar +e Identical' ); #is_deeply( [sort @gotHashRefKeys], [sort @expectedHashKeys], 'Module +Hash Keys are Identical' ); cmp_deeply( $hashRefOutput, $hashRefExpected, 'Exptected Output From t +he Module Received' ); ok( my ( $errorForExtraHashKey , $hashRefOutputForExtraHashKey ) = get +SNTPTime( %hashInputModuleTestExtraKeysInserted ), 'Faulty Test Extra + Key' ); ok( $errorForExtraHashKey eq 'Not defined key(s)', 'Correct Output Err +or Extra Hash Key' ); ok( my ( $errorNoHostname , $hashRefOutputNoHostName ) = getSNTPTime( +%hashInputModuleTestNoHostName ), 'Faulty Test no Hostname' ); ok( $errorNoHostname eq 'Not defined Hostname', 'Correct Output Error +No Hostname' ); ok( my ( $errorNegativePortNumber , $hashRefOutputNegativePortNumber ) + = getSNTPTime( %hashInputModuleTestNegativePortNumber ), 'Faulty Tes +t Negative Port Number' ); ok( $errorNegativePortNumber eq 'Not correct port number', 'Correct Ou +tput Error for Negative Port Number' ); ok( my ( $errorOutOfRangePortNumber , $hashRefOutputOutOfRangePortNumb +er ) = getSNTPTime( %hashInputModuleTestOutOfRangePortNumber ), 'Faul +ty Test Out of Range Port Number' ); ok( $errorOutOfRangePortNumber eq 'Not correct port number', 'Correct +Output Error Out of Range Port Number' ); use Data::Dumper; #print Dumper $hashRefOutputNegativePortNumber; #print "Error: " . $errorNegativePortNumber . "\n"; ######################### # Insert your test code below, the Test::More module is use()ed here s +o read # its man page ( perldoc Test::More ) for help writing this test scrip +t.
Although the test cases that are failing are 2 out of 15 I tried to fix them because the error is really simple. I have commended the fix, but still the error is not stopping to appear. Where I am going so wrong?
Thank you in advance for your time and effort to assist me.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Failed test of Net::SNTP::Client module
by Corion (Patriarch) on Jul 06, 2015 at 07:05 UTC | |
by thanos1983 (Parson) on Jul 06, 2015 at 14:47 UTC | |
|
Re: Failed test of Net::SNTP::Client module
by stevieb (Canon) on Jul 05, 2015 at 23:22 UTC | |
by thanos1983 (Parson) on Jul 06, 2015 at 14:36 UTC | |
by stevieb (Canon) on Jul 06, 2015 at 14:42 UTC | |
by thanos1983 (Parson) on Jul 06, 2015 at 14:53 UTC | |
|
Re: Failed test of Net::SNTP::Client module
by kcott (Archbishop) on Jul 06, 2015 at 11:02 UTC | |
by thanos1983 (Parson) on Jul 06, 2015 at 23:19 UTC |