testu.pp 7.8 KB

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