testfail.pp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. {
  2. This file is part of the Free Pascal test suite.
  3. Copyright (c) 1999-2002 by the Free Pascal development team.
  4. Check if redir can use COMSPEC environment variable.
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. program dotest;
  12. uses
  13. dos,
  14. redir;
  15. Const
  16. FailName = 'utils/fail';
  17. {$ifdef UNIX}
  18. ExeExt='';
  19. {$else UNIX}
  20. ExeExt='exe';
  21. {$endif UNIX}
  22. function ForceExtension(Const HStr,ext:String):String;
  23. {
  24. Return a filename which certainly has the extension ext
  25. }
  26. var
  27. j : longint;
  28. begin
  29. j:=length(Hstr);
  30. while (j>0) and (Hstr[j]<>'.') do
  31. dec(j);
  32. if j=0 then
  33. j:=255;
  34. if Ext<>'' then
  35. ForceExtension:=Copy(Hstr,1,j-1)+'.'+Ext
  36. else
  37. ForceExtension:=Copy(Hstr,1,j-1);
  38. end;
  39. procedure RunFail;
  40. var
  41. outname,
  42. TestExe : string;
  43. begin
  44. TestExe:=ForceExtension(FailName,ExeExt);
  45. TestExe:=FExpand(TestExe);
  46. ExecuteRedir(TestExe,'','','','');
  47. if (DosError<>0) or (ExecuteResult<>1) then
  48. writeln('exit code not returned correctly');
  49. end;
  50. begin
  51. if (paramcount>0) and (paramstr(1)='-x') then
  52. UseComSpec:=false
  53. else
  54. UseComSpec:=true;
  55. RunFail;
  56. end.