This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
t/op/inc.t, t/op/hexfp.t, t/op/sprintf2.t: Add missing d_ prefixes for Config variabl...
[perl5.git] / t / win32 / crypt.t
1 #!./perl
2
3 BEGIN {
4     chdir 't' if -d 't';
5     @INC = '../lib';
6     require "./test.pl";
7     eval 'use Errno';
8     die $@ if $@ and !is_miniperl();
9 }
10
11 my @bad_salts =
12    (
13     [ '',   'zero-length' ],
14     [ 'a',  'length 1' ],
15     [ '!a', 'bad first character' ],
16     [ 'a!', 'bad second character' ],
17     [ '@a', 'fencepost before A' ],
18     [ '[a', 'fencepost after Z' ],
19     [ '`a', 'fencepost before a' ],
20     [ '{a', 'fencepost after z' ],
21     [ '-a', 'fencepost before .' ],
22     [ ':a', 'fencepost after 9' ],
23    );
24
25 my @good_salts = qw(aa zz AA ZZ .. 99);
26
27 plan tests => 2 * @bad_salts + 1 + @good_salts;
28
29 for my $bad_salt (@bad_salts) {
30     my ($salt, $what) = @$bad_salt;
31     $! = 0;
32     is(crypt("abc", $salt), undef, "bad salt ($what)");
33     is(0+$!, &Errno::EINVAL, "check errno ($what)");
34 }
35
36 is(crypt("abcdef", "ab"), "abDMWw5NL.afs", "sanity check result");
37
38 # just to check we're not rejecting any good salts
39 for my $good_salt (@good_salts) {
40     isnt(crypt("abcdef", $good_salt), undef, "good salt $good_salt");
41 }