perl Makefile.PL
make
make test
sudo make install
####
make test
PERL_DL_NONLAZY=1 "/usr/bin/perl" "-MExtUtils::Command::MM" "-MTest::Harness" "-e" "undef *Test::Harness::Switches; test_harness(0, 'blib/lib', '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
####
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
####
# Before 'make install' is performed this script should be runnable with
# 'make test'. After 'make install' it should work as 'perl Net-SNTP-Client.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 here
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.ntp.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.pool.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", "-RFC4330", "-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 Must be Defined' );
ok( defined( $hashInputModuleTest{-port} ) && $hashInputModuleTest{-port} =~ /\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.org' );
my @gotHashRefKeys = keys $hashRefOutput;
ok( eq_set(\@gotHashRefKeys, \@expectedHashKeys), 'Module Hash Keys are Identical' );
#is_deeply( [sort @gotHashRefKeys], [sort @expectedHashKeys], 'Module Hash Keys are Identical' );
cmp_deeply( $hashRefOutput, $hashRefExpected, 'Exptected Output From the Module Received' );
ok( my ( $errorForExtraHashKey , $hashRefOutputForExtraHashKey ) = getSNTPTime( %hashInputModuleTestExtraKeysInserted ), 'Faulty Test Extra Key' );
ok( $errorForExtraHashKey eq 'Not defined key(s)', 'Correct Output Error 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 Test Negative Port Number' );
ok( $errorNegativePortNumber eq 'Not correct port number', 'Correct Output Error for Negative Port Number' );
ok( my ( $errorOutOfRangePortNumber , $hashRefOutputOutOfRangePortNumber ) = getSNTPTime( %hashInputModuleTestOutOfRangePortNumber ), 'Faulty 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 so read
# its man page ( perldoc Test::More ) for help writing this test script.