testu.pp 7.6 KB

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