xref: /openbsd-src/gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/t/01version.t (revision 3d61058aa5c692477b6d18acfbbdb653a9930ff9)
1b39c5158SmillertBEGIN {
2b39c5158Smillert    if ($ENV{PERL_CORE}) {
3b39c5158Smillert	chdir 't' if -d 't';
4b39c5158Smillert	@INC = ("../lib", "lib/compress");
5b39c5158Smillert    }
6b39c5158Smillert}
7b39c5158Smillert
8b39c5158Smillertuse lib qw(t t/compress);
9b39c5158Smillertuse strict ;
10b39c5158Smillertuse warnings ;
11b39c5158Smillert
12b39c5158Smillertuse Test::More ;
13b39c5158Smillert
14b39c5158SmillertBEGIN
15b39c5158Smillert{
16b39c5158Smillert    # use Test::NoWarnings, if available
17b39c5158Smillert    my $extra = 0 ;
18b39c5158Smillert    $extra = 1
19b39c5158Smillert        if eval { require Test::NoWarnings ;  import Test::NoWarnings; 1 };
20b39c5158Smillert
21fdcd7346Safresh1    plan tests => 9 + $extra ;
22b39c5158Smillert
23b39c5158Smillert    use_ok('Compress::Raw::Zlib', 2) ;
24b39c5158Smillert}
25b39c5158Smillert
26fdcd7346Safresh1use CompTestUtils;
27256a93a4Safresh1
28256a93a4Safresh1
29b39c5158Smillert# Check zlib_version and ZLIB_VERSION are the same.
30fdcd7346Safresh1test_zlib_header_matches_library();
31b39c5158Smillert
32fdcd7346Safresh1SKIP:
33fdcd7346Safresh1{
34fdcd7346Safresh1    # If running a github workflow that tests upstream zlib/zlib-ng, check we have the version requested
35256a93a4Safresh1
36fdcd7346Safresh1    # Not github or not asking for explicit verson, so skip
37fdcd7346Safresh1    skip "Not github", 7
38fdcd7346Safresh1        if ! (defined $ENV{GITHUB_ACTION} && defined $ENV{ZLIB_VERSION}) ;
39b39c5158Smillert
40fdcd7346Safresh1    my $expected_version = $ENV{ZLIB_VERSION} ;
41fdcd7346Safresh1    # zlib prefixes tags with a "v", so remove
42fdcd7346Safresh1    $expected_version =~ s/^v//i;
43b39c5158Smillert
44fdcd7346Safresh1    skip "Skipping version tests for 'develop' branch", 7
45fdcd7346Safresh1        if ($expected_version eq 'develop') ;
46b39c5158Smillert
47fdcd7346Safresh1    if ($ENV{USE_ZLIB_NG})
48fdcd7346Safresh1    {
49fdcd7346Safresh1        # zlib-ng native
50fdcd7346Safresh1        my $zv = Compress::Raw::Zlib::zlibng_version();
51fdcd7346Safresh1        is substr($zv, 0, length($expected_version)), $expected_version, "Expected version is $expected_version";
52fdcd7346Safresh1        ok ! Compress::Raw::Zlib::is_zlib_native(), "! is_zlib_native";
53fdcd7346Safresh1        ok   Compress::Raw::Zlib::is_zlibng(), "is_zlibng";
54fdcd7346Safresh1        ok   Compress::Raw::Zlib::is_zlibng_native(), "is_zlibng_native";
55fdcd7346Safresh1        ok ! Compress::Raw::Zlib::is_zlibng_compat(), "! is_zlibng_compat";
56fdcd7346Safresh1        is   Compress::Raw::Zlib::zlib_version(), '', "zlib_version() should be empty";
57fdcd7346Safresh1        is   Compress::Raw::Zlib::ZLIB_VERSION, '', "ZLIB_VERSION should be empty";
58fdcd7346Safresh1    }
59fdcd7346Safresh1    elsif ($ENV{ZLIB_NG_PRESENT})
60fdcd7346Safresh1    {
61fdcd7346Safresh1        # zlib-ng compat
62fdcd7346Safresh1        my %zlibng2zlib = (
63fdcd7346Safresh1            '2.0.0' => '1.2.11.zlib-ng',
64fdcd7346Safresh1            '2.0.1' => '1.2.11.zlib-ng',
65fdcd7346Safresh1            '2.0.2' => '1.2.11.zlib-ng',
66fdcd7346Safresh1            '2.0.3' => '1.2.11.zlib-ng',
67fdcd7346Safresh1            '2.0.4' => '1.2.11.zlib-ng',
68fdcd7346Safresh1            '2.0.5' => '1.2.11.zlib-ng',
69fdcd7346Safresh1            '2.0.6' => '1.2.11.zlib-ng',
70*3d61058aSafresh1            '2.0.7' => '1.2.11.zlib-ng',
71*3d61058aSafresh1            '2.1.2' => '1.2.13.zlib-ng',
72*3d61058aSafresh1            '2.1.3' => '1.2.13.zlib-ng',
73*3d61058aSafresh1            '2.1.4' => '1.3.0.zlib-ng',
74*3d61058aSafresh1            '2.1.5' => '1.3.0.zlib-ng',
75*3d61058aSafresh1            '2.1.6' => '1.3.0.zlib-ng',
76fdcd7346Safresh1        );
77b39c5158Smillert
78fdcd7346Safresh1        my $zv = Compress::Raw::Zlib::zlibng_version();
79fdcd7346Safresh1
80fdcd7346Safresh1        my $compat_ver = $zlibng2zlib{$expected_version};
81fdcd7346Safresh1
82fdcd7346Safresh1        is substr($zv, 0, length($expected_version)), $expected_version, "Expected Version is $expected_version";
83fdcd7346Safresh1        ok ! Compress::Raw::Zlib::is_zlib_native(), "! is_zlib_native";
84fdcd7346Safresh1        ok   Compress::Raw::Zlib::is_zlibng(), "is_zlibng";
85fdcd7346Safresh1        ok ! Compress::Raw::Zlib::is_zlibng_native(), "! is_zlibng_native";
86fdcd7346Safresh1        ok   Compress::Raw::Zlib::is_zlibng_compat(), "is_zlibng_compat";
87fdcd7346Safresh1        is   Compress::Raw::Zlib::zlib_version(), $compat_ver, "zlib_version() should be $compat_ver";
88fdcd7346Safresh1        is   Compress::Raw::Zlib::ZLIB_VERSION, $compat_ver, "ZLIB_VERSION should be $compat_ver";
89fdcd7346Safresh1    }
90fdcd7346Safresh1    else
91fdcd7346Safresh1    {
92fdcd7346Safresh1        # zlib native
93fdcd7346Safresh1        my $zv = Compress::Raw::Zlib::zlib_version();
94fdcd7346Safresh1        is substr($zv, 0, length($expected_version)), $expected_version, "Expected Version is $expected_version";
95fdcd7346Safresh1        ok   Compress::Raw::Zlib::is_zlib_native(), "is_zlib_native";
96fdcd7346Safresh1        ok ! Compress::Raw::Zlib::is_zlibng(), "! is_zlibng";
97fdcd7346Safresh1        ok ! Compress::Raw::Zlib::is_zlibng_native(), "! is_zlibng_native";
98fdcd7346Safresh1        ok ! Compress::Raw::Zlib::is_zlibng_compat(), "! is_zlibng_compat";
99fdcd7346Safresh1        is   Compress::Raw::Zlib::zlibng_version(), '', "zlibng_version() should be empty";
100fdcd7346Safresh1        is   Compress::Raw::Zlib::ZLIBNG_VERSION, '', "ZLIBNG_VERSION should be empty";    }
101fdcd7346Safresh1
102898184e3Ssthen}
103