source: git/Tst/regress.cmd @ d5e119

spielwiese
Last change on this file since d5e119 was d5e119, checked in by Olaf Bachmann <obachman@…>, 26 years ago
* added -e to singularoptions in regress.cmd * winnt port of regress.cmd * regress.cmd does not use uudecode -o any more * added MP check to regress.cmd * lst files may now contain entires like subdir/file.tst * lst files in subdirs can be given to regress.cmd git-svn-id: file:///usr/local/Singular/svn/trunk@2121 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100755
File size: 8.4 KB
Line 
1#!/usr/bin/perl
2
3#################################################################
4# $Id: regress.cmd,v 1.12 1998-06-10 15:18:29 obachman Exp $
5# FILE:    regress.cmd
6# PURPOSE: Script which runs regress test of Singular
7# CREATED: 2/16/98
8# AUTHOR:  obachman@mathematik.uni-kl.de
9
10#################################################################
11#
12# usage
13#
14sub Usage
15{
16  print <<_EOM_
17Usage:
18regress.cmd    -- regress test of Singular
19  [-s <Singular>]  -- use <Singular> as executable to test
20  [-h]             -- print out help and exit
21  [-k]             -- keep result (*.res) files, do not zip original res file
22  [-v num]         -- set verbosity to num (used range 0..3, default: 1)
23  [-g]             -- generate result (*.res.gz.uu) files, only
24  [file.lst]       -- read tst files from file.lst
25  [file.tst]       -- test Singular script file.tst
26_EOM_
27}
28
29#################################################################
30#
31# the default settings
32#
33$singularOptions = "-teqr12345678";
34$keep = "no";
35$verbosity = 1;
36$generate = "no";
37$exit_code = 0;
38chop($curr_dir=`pwd`);
39# singular -- use the one in curr directory or the one found above
40$singular = "$curr_dir/Singular";
41if ( (! (-e $singular)) || (! (-x $singular)))
42{
43  $singular = $curr_dir."/../Singular";
44}
45# sed scripts which are applied to res files before they are diff'ed
46$sed_scripts = "-e '/^\\/\\/.*used time:/d' -e '/^\\/\\/.*ignore:/d' -e '/error occured in/d'";
47
48
49#################################################################
50#
51# used programs
52#
53$diff = "diff";
54$gunzip = "gunzip";
55$gzip = "gzip";
56$rm = "rm";
57$mv = "mv";
58$cp = "cp";
59$tr = "tr";
60$sed = "sed";
61$cat = "cat";
62$tee = "tee";
63$WINNT = 1 if (system("uname -a | grep CYGWIN") == 0);;
64if ($WINNT)
65{
66  $uudecode = "uudeview.exe -i";
67}
68else
69{
70  $uuencode = "uuencode";
71  $uudecode = "uudecode";
72}
73
74
75#################################################################
76#
77# auxiallary routines
78#
79sub mysystem
80{
81  local($call) = $_[0];
82  local($exit_status);
83 
84  print "$call\n" if ($verbosity > 1);
85  return (system $call);
86}
87
88sub Set_withMP
89{
90  if (! $withMP)
91  {
92    $withMP = "no";
93    &mysystem("$singular -qt -c 'system(\"with\", \"MP\");\$' > withMPtest");
94    if (open(MP_TEST, "<withMPtest"))
95    {
96      $_ = <MP_TEST>;
97      $withMP = "yes" if (/^1/);
98      close(MP_TEST);
99    }
100    &mysystem("$rm -f withMPtest");
101  }
102}
103   
104   
105sub MPok
106{
107  local($root) = $_[0];
108 
109  if (! open(TST_FILE, "<$root.tst"))
110  {
111    print (STDERR "Can not open $root.tst for reading\n");
112    return (0);
113  }
114  while (<TST_FILE>)
115  {
116    if (/\"MP.+:.*\"/)
117    {
118      &Set_withMP;
119      return (0) if ($withMP eq "no");
120    }
121  }
122  return (1);
123}
124 
125sub Diff
126{
127  local($root) = $_[0];
128  local($exit_status);
129 
130  # prepare the result files:
131  &mysystem("$cat $root.res | $tr \"\\r\" \" \" | $sed $sed_scripts > $root.res.cleaned");
132  &mysystem("$cat $root.new.res | $tr \"\\r\" \" \" | $sed $sed_scripts > $root.new.res.cleaned");
133
134  # doo the diff call
135  if ($verbosity > 0 && ! $WINNT)
136  {
137    $exit_status = &mysystem("$diff -w $root.res.cleaned $root.new.res.cleaned | $tee $root.diff");
138  }
139  else
140  {
141    $exit_status = &mysystem("$diff -w $root.res.cleaned $root.new.res.cleaned > $root.diff 2>&1");
142  }
143 
144  # clean up time
145  &mysystem("$rm -f $root.res.cleaned $root.new.res.cleaned");
146 
147  # there seems to be a bug here somewhere: even if diff reported
148  # differenceses and exited with status != 0, then system still
149  # returns exit status 0. Hence we manually need to find out whether
150  # or not differences were reported:
151  # iff diff-file exists and has non-zero size
152  $exit_status = $exit_status || (-e "$root.diff" && -s "$root.diff");
153
154  return($exit_status);
155}
156 
157sub tst_check
158{
159  local($root) = $_[0];
160  local($system_call, $exit_status, $ignore_pattern);
161
162  print "--- $root\n" unless ($verbosity == 0);
163  # check for existence/readablity of tst and res file
164  if (! (-r "$root.tst"))
165  {
166    print (STDERR "Can not read $root.tst\n");
167    return (1);
168  }
169
170  # ignore MP stuff, if this singular does not have MP
171  if (! &MPok($root))
172  {
173    print "Warning: $root not tested: needs MP\n";
174    return (0);
175  }
176
177  # generate $root.res
178  if ($generate ne "yes")
179  {
180    if ((-r "$root.res.gz.uu") && ! ( -z "$root.res.gz.uu"))
181    {
182      $exit_status = &mysystem("$uudecode $root.res.gz.uu; $gunzip -f $root.res.gz");
183      if ($exit_status)
184      {
185        print (STDERR "Can not decode $root.res.gz.uu\n");
186        return ($exit_status);
187      }
188    }
189    elsif (! (-r "$root.res") || ( -z "$root.res"))
190    {
191      print (STDERR "Can not read $root.res[.gz.uu]\n");
192      return (1);
193    }
194  }
195 
196   
197  # prepare Singular run
198  if ($verbosity > 2 && !$WINNT)
199  {
200    $system_call = "$cat $root.tst | $singular $singularOptions | $tee $root.new.res";
201  }
202  else
203  {
204    $system_call = "$cat $root.tst | $singular $singularOptions > $root.new.res 2>&1";
205  }
206  # Go Singular, Go!
207  $exit_status = &mysystem($system_call);
208 
209  # prepare diff call
210  &mysystem("$rm -f $root.diff");
211  if ($generate eq "yes")
212  {
213    if ($exit_status == 0)
214    {
215      &mysystem("$cp $root.new.res $root.res");
216    }
217  }
218  else
219  {
220    # call Diff
221    $exit_status = &Diff($root) || $exit_status;
222  }
223 
224  # complain even if verbosity == 0
225  if ($exit_status && $verbosity == 0)
226  {
227    print (STDERR "!!! $root\n");
228  }
229
230  #time to clean up
231  if ($keep eq "no" && $exit_status == 0 && $generate ne "yes")
232  {
233    &mysystem("$rm -rf $root.new.res $root.diff");
234    &mysystem("$rm -rf $root.res") if (-r "$root.res.gz.uu")
235  }
236  elsif ($generate eq "yes" && $exit_status == 0)
237  {
238    if (! $WINNT)
239    {
240      &mysystem("$gzip -f $root.res; $uuencode $root.res.gz $root.res.gz > $root.res.gz.uu; $rm -rf $root.res.gz $root.diff");
241    }
242    else
243    {
244      # uuencode is broken under windows
245      print "Warning: Can not generate $root.res.gz.uu under Windows\n";
246    }
247    if ($keep eq "yes")
248    {
249      &mysystem("$mv $root.new.res $root.res");
250    }
251    else
252    {
253      &mysystem("$rm -f $root.new.res");
254    }
255  }
256 
257  # und tschuess
258  return ($exit_status);
259}
260
261
262#################################################################
263#
264# Main program
265#
266
267# process switches
268while ($ARGV[0] =~ /^-/)
269{
270  $_ = shift;
271  if (/^-s$/)
272  {
273    $singular = shift;
274  }
275  elsif (/^-h$/)
276  {
277    &Usage && exit (0);
278  }
279  elsif (/^-k$/)
280  {
281    $keep = "yes";
282  }
283  elsif (/^-g$/)
284  {
285    $generate = "yes";
286  }
287  elsif(/^-v$/)
288  {
289    $verbosity = shift;
290  }
291  else
292  {
293    print (STDERR "Unrecognised option: $_\n") && &Usage && die;
294  }
295}
296
297# if no command line arguments are left, use regress.lst
298if ($#ARGV == -1)
299{
300  $ARGV[0] = "regress.lst";
301}
302
303# make sure $singular exists and is executable
304$singular = "$curr_dir/$singular" unless ($singular =~ /\/.*/);
305
306if ( ! (-e $singular))
307{
308  print (STDERR "Can not find $singular \n") && &Usage && die;
309}
310if (! (-x $singular))
311{
312  print (STDERR "Can not execute $singular \n") && &Usage && die;
313}
314if (-d $singular)
315{
316  print (STDERR "$singular is a directory\n") && &Usage && die;
317}
318
319
320# now do the work
321foreach (@ARGV)
322{
323
324  if ( /^(.*)\.([^\.\/]*)$/ )
325  {
326    $_ = $1;
327    $extension = $2;
328  }
329
330  if ( /^(.*)\/([^\/]*)$/ )
331  {
332    $path = $1;
333    $base = $2;
334    chdir($path);
335    print "cd $path\n" if ($verbosity > 1);
336  }
337  else
338  {
339    $path = "";
340    $base = $_;
341  }
342  $file = "$base.$extension";
343  chop ($tst_curr_dir = `pwd`);
344 
345  if ($extension eq "tst")
346  {
347    $exit_code = &tst_check($base) || $exit_code;
348  }
349  elsif ($extension eq "lst")
350  {
351    if (! open(LST_FILE, "<$file"))
352    {
353      print (STDERR "Can not open $path/$file for reading\n");
354      $exit_code = 1;
355      next;
356    }
357    while (<LST_FILE>)
358    {
359      if (/^;/)          # ignore lines starting with ;
360      {
361        print unless ($verbosity == 0);
362        next;
363      }
364      next if (/^\s*$/); #ignore whitespaced lines
365      chop if (/\n$/);   #chop of \n
366     
367      $_ = $1 if (/^(.*)\.([^\.\/]*)$/ ); # chop of extension
368      if ( /^(.*)\/([^\/]*)$/ )
369      {
370        $tst_path = $1;
371        $tst_base = $2;
372        chdir($tst_path);
373        print "cd $tst_path\n" if ($verbosity > 1);
374      }
375      else
376      {
377        $tst_path = "";
378        $tst_base = $_;
379      }
380
381      $exit_code = &tst_check($tst_base) || $exit_code;
382
383      if ($tst_path ne "")
384      {
385        chdir($tst_curr_dir);
386        print "cd $tst_curr_dir\n" if ($verbosity > 1);
387      }
388    }
389    close (LST_FILE);
390  }
391  else
392  {
393    print (STDERR "Unknown extension of $_: Need extension lst or tst\n");
394    $exit_code = 1;
395  }
396  if ($path ne "")
397  {
398    chdir($curr_dir);
399    print "cd $curr_dir\n" if ($verbosity > 1);   
400  }
401}
402
403# Und Tschuess
404exit $exit_code;
405
406
Note: See TracBrowser for help on using the repository browser.