]> git.pond.sub.org Git - empserver/blobdiff - tests/normalize.pl
ship: Unbreak MOB_ACCESS real-time mobility update for ships
[empserver] / tests / normalize.pl
index 7297d7873ff1d03f5ba191556c268e9a4e2b3b3f..01c4b274d8340cfa630fa95abd624ed50da90f62 100755 (executable)
@@ -13,7 +13,15 @@ getopts('js')
 die "$0: either -j or -s, not both\n"
     if $opt_j && $opt_s;
 
-my $ctime_re = qr/(Sun|Mon|Tue|Wed|Thu|Fri|Sat) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) [ 123][0-9] [0-2][0-9]:[0-5][0-9]:[0-6][0-9] [0-9][0-9][0-9][0-9]/;
+my $dow_re = qr/(Sun|Mon|Tue|Wed|Thu|Fri|Sat)/;
+my $mon_re = qr/(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)/;
+my $hm_re = qr/[0-2][0-9]:[0-5][0-9]/;
+my $hms_re = qr/$hm_re:[0-6][0-9]/;
+my $year_re = qr/[0-9][0-9][0-9][0-9]/;
+my $ctime16_re = qr/$dow_re $mon_re [ 123][0-9] $hm_re/;
+my $ctime19_re = qr/$dow_re $mon_re [ 123][0-9] $hms_re/;
+my $ctime_re = qr/$dow_re $mon_re [ 123][0-9] $hms_re $year_re/;
+my $fmttime2822_re = qr/$dow_re, [0123][0-9] $mon_re $year_re $hms_re [-+][0-9][0-9][0-9][0-9]/;
 my $xdfld_re = qr/\([^)]*\)|[^ (][^ ]*/;
 
 # Current dump, if any
@@ -25,23 +33,32 @@ my $dump = "";
 sub norm_ctime {
     my ($s) = @_;
     $s =~ s/$ctime_re/Thu Jan  1 00:00:00 1970/g;
+    $s =~ s/$ctime19_re/Thu Jan  1 00:00:00/g;
+    $s =~ s/$ctime16_re/Thu Jan  1 00:00/g;
+    $s =~ s/$fmttime2822_re/Thu, 01 Jan 1970 00:00:00 +0000/g;
     return $s;
 }
 
 while (<>) {
     chomp;
 
-    my $pfx = '';
-
+    # Strip log timestamp
     if ($opt_j || $opt_s) {
-       die "$0: malformed line" unless substr($_, 24, 1) eq ' ';
-       $pfx .= norm_ctime(substr($_, 0, 25));
+       die "$0: malformed line" unless /^$ctime_re /;
        $_ = substr($_, 25);
     }
 
+    # Strip trailing white space
+    # We don't really care for it in test output, and git's pre-commit
+    # hook flags it, which is annoying.
+    s/\s+$//;
+
+    # Split off prefix that is not to be normalized
+    my $pfx = '';
     if ($opt_j) {
        die "$0: malformed line" unless substr($_, 10, 1) eq ' ';
        $pfx .= substr($_, 0, 11);
+       # Normalize only player output
        $_ = substr($_, 11);
        if (/(^output [^ ]* 1 )(.*)/) {
            $pfx .= $1;
@@ -56,9 +73,9 @@ while (<>) {
        $_ = norm_ctime($_);
        ### Host environment in logs
        # getrusage() results in server.log
-       s/(End update|done assembling paths) .* user .* system/$1 0.0 user 0.0 system/g;
+       s/(End update|done assembling paths) .* user .* system/$1 0.0 user 0.0 system/;
        # PID in server.log
-       s/(Empire server \(pid) [0-9]+(\) started)/$1 42$2/g;
+       s/(Empire server \(pid) [0-9]+(\) started)/$1 42$2/;
        ### Harmless races
        # shutdown wins race with logout
        next if /Waiting for player threads to terminate/;
@@ -73,15 +90,19 @@ while (<>) {
            and (/\: No (sector|ship|plane|unit|nuke)\(s\)|\: Nothing lost/
                 or /^[0-9]+ (sector|ship|plane|unit|nuke|lost item)/));
 
+    ### Version
+    s/(Wolfpack( |\\\\040)Empire( |\\\\040))(UNKNOWN-|[0-9])[^ "]*/${1}4.4.0/;
     ### Formatted time
     # nat_timeused in prompt
-    s/^\[[0-9]+(:[0-9]+\] Command \:)/[0$1/g;
+    s/^\[[0-9]+(:[0-9]+\] Command \:)/[0$1/;
+    $pfx =~ s/( output [^ ]* 6) [0-9]+ ([0-9]+$)/$1 0 $2/
+       if $opt_j;
     # TODO command play column time
     # result of ctime() in many commands
     $_ = norm_ctime($_)
        unless $dump;
     ### Time values in legacy dumps
-    s/(DUMP (SECTOR|SHIPS|PLANES|LAND UNITS|NUKES|LOST ITEMS)) [0-9]+$/$1 0/g;
+    s/(DUMP (SECTOR|SHIPS|PLANES|LAND UNITS|NUKES|LOST ITEMS)) [0-9]+$/$1 0/;
     s/ [0-9]+$/ 0/
        if $dump eq 'LOST ITEMS';
     ### Time values in xdump
@@ -91,19 +112,15 @@ while (<>) {
     # TODO don't do that, use xdump meta instead
     s/(^| )[0-9]{10,}/${1}0/g
        if $dump =~ /^[a-z]/;
-    # timeused in xdump country (column 9)
-    s/^(($xdfld_re ){9})([0-9]+) /${1}255 /
+    # timeused in xdump country timeused (column 10)
+    s/^(($xdfld_re ){10})([0-9]+) /${1}255 /
        if $dump eq 'country';
-    # timeused in xdump nat (column 14)
-    s/^(($xdfld_re ){14})([0-9]+) /${1}255 /
+    # timeused in xdump nat (column 15)
+    s/^(($xdfld_re ){15})([0-9]+) /${1}255 /
        if $dump eq 'nat';
     # duration in xdump news (column 4)
     s/^(($xdfld_re ){4})([0-9]+) /${1}0 /
        if $dump eq 'news';
-    ### nsc_type values in xdump
-    # Can vary between systems, because the width of enumeration types
-    # is implementation-defined.
-    # TODO type in xdump meta
     ### nrndx values in xdump
     # Encoding depends on the host, see resources[].  Too clever by half;
     # perhaps we should change it.