This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
better handle freeing of code blocks in /(?{...})/
[perl5.git] / t / op / crypt.t
index 47e546d..5e7183b 100644 (file)
@@ -2,22 +2,19 @@
 
 BEGIN {
     chdir 't' if -d 't';
-    @INC = qw(. ../lib);
-}
-
-BEGIN {
-    use Config;
-
     require "./test.pl";
+    set_up_inc( qw(. ../lib) );
+    use Config;
+}
 
-    if( !$Config{d_crypt} ) {
-        skip_all("crypt unimplemented");
-    }
-    else {
-        plan(tests => 6);
-    }
+if ( !$Config{d_crypt} ) {
+    skip_all("crypt unimplemented");
+}
+else {
+    plan(tests => 6);
 }
 
+
 # Can't assume too much about the string returned by crypt(),
 # and about how many bytes of the encrypted (really, hashed)
 # string matter.
@@ -33,14 +30,22 @@ BEGIN {
 # pointer, which Perl converts into undef. We assume for now that all
 # such platforms support glibc-style selection of a different hashing
 # algorithm.
+# glibc supports MD5, but OpenBSD only supports Blowfish.
 my $alg = '';       # Use default algorithm
-if ( !defined(crypt("ab", "cd")) ) {
-    $alg = '$5$';   # Use SHA-256
+if ( !defined(crypt("ab", $alg."cd")) ) {
+    $alg = '$5$';   # Try SHA-256
+}
+if ( !defined(crypt("ab", $alg."cd")) ) {
+    $alg = '$2b$12$FPWWO2RJ3CK4FINTw0Hi';  # Try Blowfish
+}
+if ( !defined(crypt("ab", $alg."cd")) ) {
+    $alg = ''; # Nothing worked.  Back to default
 }
 
 SKIP: {
     skip ("VOS crypt ignores salt.", 1) if ($^O eq 'vos');
-    ok(substr(crypt("ab", $alg."cd"), 2) ne substr(crypt("ab", $alg."ce"), 2),
+    ok(substr(crypt("ab", $alg."cd"), length($alg)+2) ne 
+       substr(crypt("ab", $alg."ce"), length($alg)+2),
        "salt makes a difference");
 }