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