Fix Some Pod Typos
[p5sagit/p5-mst-13.2.git] / lib / AutoSplit.t
index e4eb302..7723a53 100644 (file)
@@ -65,14 +65,29 @@ sub split_a_file {
   return $output;
 }
 
+# Brackets are valid in VMS filespecs and this test puts filespecs
+# into regexes a lot.
+
+sub _escape_brackets {
+  my $str = shift;
+  $str =~ s/\[/\\\[/g;   
+  $str =~ s/\]/\\\]/g;
+  return $str;
+}
+
 my $i = 0;
-my $dir = File::Spec->catfile($incdir, 'auto');
+my $dir = File::Spec->catdir($incdir, 'auto');
+if ($^O eq 'VMS') {
+  $dir = VMS::Filespec::unixify($dir);
+  $dir =~ s/\/$//;
+}
 foreach (@tests) {
   my $module = 'A' . $i . '_' . $$ . 'splittest';
   my $file = File::Spec->catfile($incdir,"$module.pm");
   s/\*INC\*/$incdir/gm;
   s/\*DIR\*/$dir/gm;
   s/\*MOD\*/$module/gm;
+  s#//#/#gm;
   # Build a hash for this test.
   my %args = /^\#\#\ ([^\n]*)\n        # Key is on a line starting ##
              ((?:[^\#]+                # Any number of characters not #
@@ -92,6 +107,17 @@ foreach (@tests) {
     $output = split_a_file (undef, $file, $dir, @extra_args);
   }
 
+  if ($^O eq 'VMS') {
+     my ($filespec, $replacement);
+     while ($output =~ m/(\[.+\])/) {
+       $filespec = $1;
+       $replacement =  VMS::Filespec::unixify($filespec);
+       $filespec = _escape_brackets($filespec);
+       $replacement =~ s/\/$//;
+       $output =~ s/$filespec/$replacement/;
+     }
+  }
+
   # test n+1
   is ($output, $args{Get}, "Output from autosplit()ing $args{Name}");
 
@@ -101,6 +127,7 @@ foreach (@tests) {
     find (sub {$got{$File::Find::name}++ unless -d $_}, $dir);
     foreach (split /\n/, $args{Files}) {
       next if /^#/;
+      $_ = lc($_) if $^O eq 'VMS';
       unless (delete $got{$_}) {
         $missing{$_}++;
       }
@@ -143,9 +170,27 @@ foreach (@tests) {
   if ($args{Tests}) {
     foreach my $code (split /\n/, $args{Tests}) {
       next if $code =~ /^\#/;
+      $code =~ s/\[(File::Spec->catfile\(.*\))\]/[_escape_brackets($1)]/ if $^O eq 'VMS';
       defined eval $code or fail(), print "# Code:  $code\n# Error: $@";
     }
   }
+  if (my $sleepfor = $args{Sleep}) {
+    # We need to sleep for a while
+    # Need the sleep hack else the next test is so fast that the timestamp
+    # compare routine in AutoSplit thinks that it shouldn't split the files.
+    my $time = time;
+    my $until = $time + $sleepfor;
+    my $attempts = 3;
+    do {
+      sleep ($sleepfor)
+    } while (time < $until && --$attempts > 0);
+    if ($attempts == 0) {
+      printf << "EOM", time;
+# Attempted to sleep for $sleepfor second(s), started at $time, now %d.
+# sleep attempt ppears to have failed; some tests may fail as a result.
+EOM
+    }
+  }
   unless ($args{SameAgain}) {
     $i++;
     rmtree($dir);
@@ -265,12 +310,10 @@ AutoSplitting *INC*/*MOD*.pm (*DIR*/*MOD*)
 ## Tests
 is (&*MOD*::obsolete, 0);
 is (&*MOD*::obsolete, 1);
-{my $time = time; print "# time is $time\n"; sleep (2); sleep (2) unless time > $time + 1}
-printf "# time is %d (hopefully >=2 seconds later)\n", time;
+## Sleep
+2
 ## SameAgain
 True, so don't scrub this directory.
-Need the sleep hack else the next test is so fast that the timestamp compare
-routine in AutoSplit thinks that it shouldn't split the files.
 IIRC DOS FAT filesystems have only 2 second granularity.
 ################################################################
 ## Name
@@ -298,8 +341,8 @@ AutoSplitting *INC*/*MOD*.pm (*DIR*/*MOD*)
 ## Tests
 is (&*MOD*::skeleton, "bones", "skeleton");
 eval {&*MOD*::gonner}; ok ($@ =~ m!^Can't locate auto/*MOD*/gonner.al in \@INC!, "Check &*MOD*::gonner is now a gonner") or print "# \$\@='$@'\n";
-{my $time = time; print "# time is $time\n"; sleep (2); sleep (2) unless time > $time + 1}
-printf "# time is %d (hopefully >=2 seconds later)\n", time;
+## Sleep
+2
 ## SameAgain
 True, so don't scrub this directory.
 ################################################################
@@ -328,8 +371,8 @@ AutoSplitting *INC*/*MOD*.pm (*DIR*/*MOD*)
 ## Tests
 is (&*MOD*::ghost, "bump");
 is (&*MOD*::zombie, "You didn't use fire.", "Are our zombies undead?");
-{my $time = time; print "# time is $time\n"; sleep (2); sleep (2) unless time > $time + 1}
-printf "# time is %d (hopefully >=2 seconds later)\n", time;
+## Sleep
+2
 ## SameAgain
 True, so don't scrub this directory.
 ################################################################
@@ -350,8 +393,8 @@ Without the the timestamp check make sure that nothing happens
 ## Tests
 is (&*MOD*::ghoul, "wail", "still haunted");
 is (&*MOD*::zombie, "You didn't use fire.", "Are our zombies still undead?");
-{my $time = time; print "# time is $time\n"; sleep (2); sleep (2) unless time > $time + 1}
-printf "# time is %d (hopefully >=2 seconds later)\n", time;
+## Sleep
+2
 ## SameAgain
 True, so don't scrub this directory.
 ################################################################