testu.pp 7.7 KB

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