{
  From the old testsuite. Since many of the errors can be detected
  at compile time, they're commented out. What's actually checked is
  a nil pointer dereference. GPC doesn't do this yet -- and if it
  does, this test will have to be changed to detect this as "OK" ...
}

program errs(input,output,junk,locked);

label   99;

type
etype = (ECHR, EHALT, ENILPTR, ECASE, EOUTOFMEM, ECTSNG,
ESTLIM, EARGV, EPACK, EUNPACK, EASRT, ELLIMIT, ETRASHHEAP, EPASTEOF,
EREFINAF, ENOFILE, ENAMESIZE, EBADINUM, EBADFNUM, ENUMNTFD, ENAMRNG,
EFMTSIZE, ESEEK, ECREATE, EREMOVE, EOPEN, EREADIT, EWRITEIT, ESQRT,
ELN, ERANGE, ESUBSC, EGOTO, ECLOSE, EWRITE, ECTLWR, ECTUPR, xxx);
biggie = array[1..15000] of integer;

var
ch :char;
chs :packed array [1..10] of char;
ch1 :array[1..10] of char;
ptr, ptr1 :^char;
ptr2 :^biggie;
junk, locked, other :file of char;
variant :record
        case boolean of
        true:(val :1..100);
        false:(name :etype)
        end;
s :set of 1..4;
i :integer;
r :real;
err :etype;

begin
{writeln('Want a list of error names?');readln(ch);}
ch:='n';
if ch = 'y' then begin
        for err:=ECHR to pred(xxx) do begin
                write(ord(err):15);
                if ord(err) mod 5 = 4 then
                        writeln;
                end;
        writeln;
        end;
{writeln('enter an error name');readln(err);}
err:=ENILPTR;
case err of
ESEEK, EGOTO, ECLOSE, EWRITE, xxx: begin
        writeln(ord(err), ': error cannot be simulated');
        goto 99;
        end;
ECHR: ch:=chr(128);
EHALT: halt;
ENILPTR: begin ptr:=nil; write (ptr^); writeln ('failed') end;
ECASE: case 4 of 1:; end;
EOUTOFMEM: while true do begin
                new(ptr2);
                writeln('alloc successful');
                end;
ECTLWR: begin
        i:=0;
        s:=[i..2];
        end;
ECTUPR: begin
        i:=5;
        s:=[1..i];
        end;
ECTSNG: begin
        i:=0;
        s:=[i];
        end;
ESTLIM: {stlimit(0)};
EARGV: {argv(100,chs)};
EPACK: {pack(ch1,2,chs)};
EUNPACK: {unpack(chs,ch1,2)};
EASRT: {assert(false)};
ELLIMIT: begin
         {linelimit(output,1);}
         writeln('This only should print');
         writeln;
         writeln('ERROR');
         end;
ETRASHHEAP: begin
            new(ptr);
            ptr1:=ptr;
            dispose(ptr1);
            dispose(ptr);
            end;
EPASTEOF: begin
          rewrite(junk);
          reset(junk);
          get(junk);
          get(junk);
          write(junk^);
          end;
EREFINAF: ch:=junk^;
ENOFILE: ch:=other^;
ENAMESIZE: rewrite(junk,
'thisisaverylongandconvolutedfilenamewhichexceedsalllimitsofreasonablenessandgoodtaste');  { Hardly so. Frank }
EBADINUM: begin
          writeln('Enter a letter');
          read(i);
          end;
EBADFNUM: begin
          writeln('Enter a letter');
          read(r);
          end;
ENUMNTFD: begin
          writeln('Enter your name');
          {read(err);}
          end;
ENAMRNG:  begin
          variant.val:=100;
          {writeln(variant.name);}
          end;
EFMTSIZE: begin
          i:=-1;
          writeln(1.0:i);
          end;
ECREATE: rewrite(locked);
EREMOVE: {remove('none')};
EOPEN: reset(locked);
EREADIT: read(output,ch);
EWRITEIT: write(input,ch);
ESQRT: r:=sqrt(-1.0);
ELN: r:=ln(0);
ERANGE: ch:=succ(chr(127));
ESUBSC: {ch:=ch1[127 + 1]};
end;
writeln('*** ERROR NOT DETECTED ***');
99:end.
