Branch: Tag:

1998-02-24

1998-02-24 22:48:13 by Fredrik Hübinette (Hubbe) <hubbe@hubbe.net>

some changes

Rev: bin/export.pike:1.14
Rev: bin/mktestsuite:1.8
Rev: bin/test_pike.pike:1.6

1:   #!/usr/local/bin/pike    - /* $Id: test_pike.pike,v 1.5 1998/01/03 07:11:24 hubbe Exp $ */ + /* $Id: test_pike.pike,v 1.6 1998/02/24 22:48:13 hubbe Exp $ */      #include <simulate.h>   
8:   #define _verify_internals()   #endif    -  + int foo(string opt) + { +  if(opt=="" || !opt) return 1; +  return (int)opt; + }   int main(int argc, string *argv)   {    int e, verbose, successes, errors, t, check;
17:    int start, fail, mem;    int loop=1;    -  for(e=1;e<argc;e++) +  foreach(Getopt.find_all_options(argv,aggregate( +  ({"help",Getopt.NO_ARG,({"-h","--help"})}), +  ({"verbose",Getopt.NO_ARG,({"-v","--verbose"})}), +  ({"start",Getopt.HAS_ARG,({"-s","--start-test"})}), +  ({"fail",Getopt.MAY_HAVE_ARG,({"-f","--fail"})}), +  ({"loop",Getopt.MAY_HAVE_ARG,({"-l","--loop"})}), +  ({"trace",Getopt.MAY_HAVE_ARG,({"-t","--trace"})}), +  ({"check",Getopt.MAY_HAVE_ARG,({"-c","--check"})}), +  ({"mem",Getopt.MAY_HAVE_ARG,({"-m","--mem","--memory"})}), +  )),array opt)    { -  string opt; -  int arg; -  arg=1; -  if(sscanf(argv[e],"--%s=%d",opt,arg)==2) -  opt="--"+opt; -  else if(sscanf(argv[e],"-%s%d",opt,arg)==2) -  opt="-"+opt; -  else -  opt=argv[e]; -  -  switch(opt) +  switch(opt[0])    { -  case "-h": -  case "--help": -  perror("Usage: "+argv[e]+" [-v | --verbose] [-h | --help] [-t <testno>] <testfile>\n"); +  case "help": +  werror("Usage: "+argv[e]+" [-v | --verbose] [-h | --help] [-t <testno>] <testfile>\n");    return 0;    -  case "-v": -  case "--verbose": -  verbose+=arg; -  break; +  case "verbose": verbose+=foo(opt[1]); break; +  case "start": start=foo(opt[1]); start--; break; +  case "fail": fail+=foo(opt[1]); break; +  case "loop": loop+=foo(opt[1]); break; +  case "trace": t+=foo(opt[1]); break; +  case "check": check+=foo(opt[1]); break; +  case "mem": mem+=foo(opt[1]); break; +  } +  }    -  case "-s": -  case "--start-test": -  start=arg; -  start--; -  break; -  -  case "-f": -  case "--fail": -  fail+=arg; -  break; -  -  -  case "-l": -  case "--loop": -  loop+=arg; -  break; -  -  case "-t": -  case "--trace": -  t+=arg; -  break; -  -  case "-c": -  case "--check": -  check++; -  break; -  -  -  case "-m": -  case "--mem": -  case "--memory": -  mem++; -  break; -  -  default: -  if(tests) +  argv=Getopt.get_args(argv,1); +  if(sizeof(argv)<1)    { -  perror("Unknown argument: "+opt+".\n"); -  exit(1); -  } -  tmp=read_bytes(argv[e]); +     if(!tmp)    { -  perror("Failed to read test file, errno="+errno()+".\n"); +  werror("No tests?\n");    exit(1);    }    } -  } +     -  if(!tmp) +  while(loop--)    { -  tmp=Stdio.stdin->read(0x7fffffff); +  successes=errors=0; +  for(int f=1;f<sizeof(argv);f++) +  { +  tmp=read_bytes(argv[f]);    if(!tmp)    { -  perror("Failed to read test file, errno="+errno()+".\n"); +  werror("Failed to read test file, errno="+errno()+".\n");    exit(1);    } -  } +     -  +     tests=tmp/"\n....\n"; -  +  tmp=0;    tests=tests[0..sizeof(tests)-2];    -  while(loop--) -  { -  successes=errors=0; +  werror("Doing tests in %s (%d tests)\n",argv[f],sizeof(tests));    -  +     for(e=start;e<sizeof(tests);e++)    {    string test,condition;
123:    if(!clone(compile_string("mixed c() { return "+condition+"; }","Cond "+(e+1)))->c())    {    if(verbose) -  perror("Not doing test "+(e+1)+"\n"); +  werror("Not doing test "+(e+1)+"\n");    successes++;    continue;    }
134:       if(verbose)    { -  perror("Doing test "+(e+1)+"\n"); +  werror("Doing test "+(e+1)+"\n");    if(verbose>1) -  perror(test+"\n"); +  werror(test+"\n");    }       if(check > 1) _verify_internals();
149:    {    successes++;    }else{ -  perror("Test "+(e+1)+" failed.\n"); -  perror(test+"\n"); +  werror("Test "+(e+1)+" failed.\n"); +  werror(test+"\n");    errors++;    }    master()->set_inhibit_compile_errors(0);
162:    {    successes++;    }else{ -  perror("Test "+(e+1)+" failed.\n"); -  perror(test+"\n"); +  werror("Test "+(e+1)+" failed.\n"); +  werror(test+"\n");    errors++;    }    master()->set_inhibit_compile_errors(0);
190:    case "TRUE":    if(!a)    { -  perror("Test "+(e+1)+" failed.\n"); -  perror(test+"\n"); +  werror("Test "+(e+1)+" failed.\n"); +  werror(test+"\n");    errors++;    }else{    successes++;
205:    case "EQ":    if(a!=b)    { -  perror("Test "+(e+1)+" failed.\n"); -  perror(test+"\n"); -  perror(sprintf("o->a(): %O\n",a)); -  perror(sprintf("o->b(): %O\n",b)); +  werror("Test "+(e+1)+" failed.\n"); +  werror(test+"\n"); +  werror(sprintf("o->a(): %O\n",a)); +  werror(sprintf("o->b(): %O\n",b));    errors++;    }else{    successes++;
218:    case "EQUAL":    if(!equal(a,b))    { -  perror("Test "+(e+1)+" failed.\n"); -  perror(test+"\n"); -  perror(sprintf("o->a(): %O\n",a)); -  perror(sprintf("o->b(): %O\n",b)); +  werror("Test "+(e+1)+" failed.\n"); +  werror(test+"\n"); +  werror(sprintf("o->a(): %O\n",a)); +  werror(sprintf("o->b(): %O\n",b));    errors++;    }else{    successes++;
229:    break;       default: -  perror(sprintf("Unknown test type (%O).\n",type)); +  werror(sprintf("Unknown test type (%O).\n",type));    errors++;    }    }
242:    a=b=0;    }    -  if(errors + successes != sizeof(tests)) -  { -  perror("Errors + Successes != number of tests!\n"); -  errors++; -  } -  +     if(errors || verbose)    { -  perror("Failed tests: "+errors+".\n"); +  werror("Failed tests: "+errors+".\n");    }       }
277:    "",    total));    } +  } +  if(verbose) +  { +  werror("Total tests: %d\n",successes+errors); +  }       return errors;   }