testu.pp 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. {$mode objfpc}
  2. {$h+}
  3. unit testu;
  4. Interface
  5. { ---------------------------------------------------------------------
  6. utility functions, shared by several programs of the test suite
  7. ---------------------------------------------------------------------}
  8. type
  9. TVerboseLevel=(V_Abort,V_Error,V_Warning,V_Normal,V_Debug);
  10. TConfig = record
  11. NeedOptions,
  12. NeedCPU,
  13. SkipCPU,
  14. SkipEmu,
  15. NeedTarget,
  16. SkipTarget,
  17. MinVersion,
  18. MaxVersion,
  19. KnownRunNote,
  20. KnownCompileNote : string;
  21. ResultCode : longint;
  22. KnownRunError : longint;
  23. KnownCompileError : longint;
  24. NeedRecompile : boolean;
  25. NeedLibrary : boolean;
  26. IsInteractive : boolean;
  27. IsKnownRunError,
  28. IsKnownCompileError : boolean;
  29. NoRun : boolean;
  30. UsesGraph : boolean;
  31. ShouldFail : boolean;
  32. Category : string;
  33. Note : string;
  34. end;
  35. Const
  36. DoVerbose : boolean = false;
  37. procedure TrimB(var s:string);
  38. procedure TrimE(var s:string);
  39. function upper(const s : string) : string;
  40. procedure Verbose(lvl:TVerboseLevel;const s:string);
  41. function GetConfig(const fn:string;var r:TConfig):boolean;
  42. Function GetFileContents (FN : String) : String;
  43. Implementation
  44. procedure Verbose(lvl:TVerboseLevel;const s:string);
  45. begin
  46. case lvl of
  47. V_Normal :
  48. writeln(s);
  49. V_Debug :
  50. if DoVerbose then
  51. writeln('Debug: ',s);
  52. V_Warning :
  53. writeln('Warning: ',s);
  54. V_Error :
  55. begin
  56. writeln('Error: ',s);
  57. halt(1);
  58. end;
  59. V_Abort :
  60. begin
  61. writeln('Abort: ',s);
  62. halt(0);
  63. end;
  64. end;
  65. end;
  66. procedure TrimB(var s:string);
  67. begin
  68. while (s<>'') and (s[1] in [' ',#9]) do
  69. delete(s,1,1);
  70. end;
  71. procedure TrimE(var s:string);
  72. begin
  73. while (s<>'') and (s[length(s)] in [' ',#9]) do
  74. delete(s,length(s),1);
  75. end;
  76. function upper(const s : string) : string;
  77. var
  78. i,l : longint;
  79. begin
  80. L:=Length(S);
  81. SetLength(upper,l);
  82. for i:=1 to l do
  83. if s[i] in ['a'..'z'] then
  84. upper[i]:=char(byte(s[i])-32)
  85. else
  86. upper[i]:=s[i];
  87. end;
  88. function GetConfig(const fn:string;var r:TConfig):boolean;
  89. var
  90. t : text;
  91. part,code : integer;
  92. l : longint;
  93. s,res : string;
  94. function GetEntry(const entry:string):boolean;
  95. var
  96. i : longint;
  97. begin
  98. Getentry:=false;
  99. Res:='';
  100. if Upper(Copy(s,1,length(entry)))=Upper(entry) then
  101. begin
  102. Delete(s,1,length(entry));
  103. TrimB(s);
  104. if (s<>'') then
  105. begin
  106. if (s[1]='=') then
  107. begin
  108. delete(s,1,1);
  109. i:=pos('}',s);
  110. if i=0 then
  111. i:=255
  112. else
  113. dec(i);
  114. res:=Copy(s,1,i);
  115. TrimB(res);
  116. TrimE(res);
  117. end;
  118. Verbose(V_Debug,'Config: '+Entry+' = "'+Res+'"');
  119. GetEntry:=true;
  120. end;
  121. end;
  122. end;
  123. begin
  124. FillChar(r,sizeof(r),0);
  125. GetConfig:=false;
  126. Verbose(V_Debug,'Reading '+fn);
  127. assign(t,fn);
  128. {$I-}
  129. reset(t);
  130. {$I+}
  131. if ioresult<>0 then
  132. begin
  133. Verbose(V_Error,'Can''t open '+fn);
  134. exit;
  135. end;
  136. r.Note:='';
  137. while not eof(t) do
  138. begin
  139. readln(t,s);
  140. if s<>'' then
  141. begin
  142. TrimB(s);
  143. if s[1]='{' then
  144. begin
  145. delete(s,1,1);
  146. TrimB(s);
  147. if (s<>'') and (s[1]='%') then
  148. begin
  149. delete(s,1,1);
  150. if GetEntry('OPT') then
  151. r.NeedOptions:=res
  152. else
  153. if GetEntry('TARGET') then
  154. r.NeedTarget:=res
  155. else
  156. if GetEntry('SKIPTARGET') then
  157. r.SkipTarget:=res
  158. else
  159. if GetEntry('CPU') then
  160. r.NeedCPU:=res
  161. else
  162. if GetEntry('SKIPCPU') then
  163. r.SkipCPU:=res
  164. else
  165. if GetEntry('SKIPEMU') then
  166. r.SkipEmu:=res
  167. else
  168. if GetEntry('VERSION') then
  169. r.MinVersion:=res
  170. else
  171. if GetEntry('MAXVERSION') then
  172. r.MaxVersion:=res
  173. else
  174. if GetEntry('RESULT') then
  175. Val(res,r.ResultCode,code)
  176. else
  177. if GetEntry('GRAPH') then
  178. r.UsesGraph:=true
  179. else
  180. if GetEntry('FAIL') then
  181. r.ShouldFail:=true
  182. else
  183. if GetEntry('RECOMPILE') then
  184. r.NeedRecompile:=true
  185. else
  186. if GetEntry('NORUN') then
  187. r.NoRun:=true
  188. else
  189. if GetEntry('NEEDLIBRARY') then
  190. r.NeedLibrary:=true
  191. else
  192. if GetEntry('KNOWNRUNERROR') then
  193. begin
  194. r.IsKnownRunError:=true;
  195. if res<>'' then
  196. begin
  197. val(res,l,code);
  198. if code>1 then
  199. begin
  200. part:=code;
  201. val(copy(res,1,code-1),l,code);
  202. delete(res,1,part);
  203. end;
  204. if code=0 then
  205. r.KnownRunError:=l;
  206. if res<>'' then
  207. r.KnownRunNote:=res;
  208. end;
  209. end
  210. else
  211. if GetEntry('KNOWNCOMPILEERROR') then
  212. begin
  213. r.IsKnownCompileError:=true;
  214. if res<>'' then
  215. begin
  216. val(res,l,code);
  217. if code>1 then
  218. begin
  219. part:=code;
  220. val(copy(res,1,code-1),l,code);
  221. delete(res,1,part);
  222. end;
  223. if code=0 then
  224. r.KnownCompileError:=l;
  225. if res<>'' then
  226. r.KnownCompileNote:=res;
  227. end;
  228. end
  229. else
  230. if GetEntry('INTERACTIVE') then
  231. r.IsInteractive:=true
  232. else
  233. if GetEntry('NOTE') then
  234. begin
  235. R.Note:='Note: '+res;
  236. Verbose(V_Normal,r.Note);
  237. end
  238. else
  239. Verbose(V_Error,'Unknown entry: '+s);
  240. end;
  241. end
  242. else
  243. break;
  244. end;
  245. end;
  246. close(t);
  247. GetConfig:=true;
  248. end;
  249. Function GetFileContents (FN : String) : String;
  250. Var
  251. F : Text;
  252. S : String;
  253. begin
  254. Result:='';
  255. Assign(F,FN);
  256. {$I-}
  257. Reset(F);
  258. If IOResult<>0 then
  259. Exit;
  260. {$I+}
  261. While Not(EOF(F)) do
  262. begin
  263. ReadLn(F,S);
  264. Result:=Result+S+LineEnding;
  265. end;
  266. Close(F);
  267. end;
  268. end.