1use strict; 2use warnings; 3 4use Test::More 0.88; 5 6use constant NON_EXISTENT_OS => 'titanix'; #the system they said could not go down... 7 8#--------------------------------------------------------------------------# 9# API tests 10#--------------------------------------------------------------------------# 11 12require_ok('Perl::OSType'); 13 14can_ok( 'Perl::OSType', 'os_type' ); 15 16my @functions = qw/os_type is_os_type/; 17for my $sub (@functions) { 18 ok( eval { Perl::OSType->import($sub); 1 }, "importing $sub()" ); 19 can_ok( 'main', $sub ); 20} 21 22my $test_pkg = "testpackage$$"; 23 24ok( eval "package $test_pkg; use Perl::OSType ':all'; 1", 25 "Testing 'use Perl::OSType qw/:all/'" ); 26 27can_ok( $test_pkg, @functions ); 28 29#--------------------------------------------------------------------------# 30# os_type 31#--------------------------------------------------------------------------# 32 33{ 34 my $fcn = 'os_type()'; 35 36 ok( my $current_type = os_type(), "$fcn: without arguments" ); 37 38 is( $current_type, os_type($^O), "... matches os_type($^O)" ); 39 40 is( os_type(NON_EXISTENT_OS), '', "$fcn: unknown OS returns empty string" ); 41 42 is( os_type(''), '', "$fcn: empty string returns empty string" ); 43 44 local $^O = 'linux'; 45 46 is( os_type(undef), 'Unix', "$fcn: explicit undef uses $^O" ); 47} 48 49#--------------------------------------------------------------------------# 50# is_os_type 51#--------------------------------------------------------------------------# 52 53{ 54 my $fcn = 'is_os_type()'; 55 56 is( is_os_type(NON_EXISTENT_OS), '', "$fcn: non-existent type is false" ); 57 58 is( is_os_type(''), undef, "$fcn: empty string type is false" ); 59 60 is( is_os_type( 'Unix', NON_EXISTENT_OS ), '', "$fcn: non-existent OS is false" ); 61 62 local $^O = 'vos'; 63 ok( !is_os_type('Unix'), "$fcn: false" ); 64 ok( is_os_type('VOS'), "$fcn: true" ); 65 ok( !is_os_type(), "$fcn: false if no type provided" ); 66} 67 68done_testing; 69 70