testfail.pp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. TestExe : string;
  42. begin
  43. TestExe:=ForceExtension(FailName,ExeExt);
  44. TestExe:=FExpand(TestExe);
  45. ExecuteRedir(TestExe,'','','','');
  46. if (DosError<>0) or (ExecuteResult<>1) then
  47. writeln('exit code not returned correctly');
  48. end;
  49. begin
  50. if (paramcount>0) and (paramstr(1)='-x') then
  51. UseComSpec:=false
  52. else
  53. UseComSpec:=true;
  54. RunFail;
  55. end.