testu.pp 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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. NeedTarget,
  15. SkipTarget,
  16. MinVersion,
  17. MaxVersion,
  18. KnownRunNote,
  19. KnownCompileNote,
  20. KnownCompile10Note : string;
  21. ResultCode : longint;
  22. KnownRunError : longint;
  23. KnownCompileError,
  24. KnownCompile10Error : longint;
  25. NeedRecompile : boolean;
  26. NeedLibrary : boolean;
  27. IsInteractive : boolean;
  28. IsKnown : 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('VERSION') then
  166. r.MinVersion:=res
  167. else
  168. if GetEntry('MAXVERSION') then
  169. r.MaxVersion:=res
  170. else
  171. if GetEntry('RESULT') then
  172. Val(res,r.ResultCode,code)
  173. else
  174. if GetEntry('GRAPH') then
  175. r.UsesGraph:=true
  176. else
  177. if GetEntry('FAIL') then
  178. r.ShouldFail:=true
  179. else
  180. if GetEntry('RECOMPILE') then
  181. r.NeedRecompile:=true
  182. else
  183. if GetEntry('NORUN') then
  184. r.NoRun:=true
  185. else
  186. if GetEntry('NEEDLIBRARY') then
  187. r.NeedLibrary:=true
  188. else
  189. if GetEntry('KNOWNRUNERROR') then
  190. begin
  191. if res<>'' then
  192. begin
  193. val(res,l,code);
  194. if code>1 then
  195. begin
  196. part:=code;
  197. val(copy(res,1,code-1),l,code);
  198. delete(res,1,part);
  199. end;
  200. if code=0 then
  201. r.KnownRunError:=l;
  202. if res<>'' then
  203. r.KnownRunNote:=res;
  204. end;
  205. end
  206. else
  207. if GetEntry('KNOWNCOMPILEERROR') then
  208. begin
  209. if res<>'' then
  210. begin
  211. val(res,l,code);
  212. if code>1 then
  213. begin
  214. part:=code;
  215. val(copy(res,1,code-1),l,code);
  216. delete(res,1,part);
  217. end;
  218. if code=0 then
  219. r.KnownCompileError:=l;
  220. if res<>'' then
  221. r.KnownCompileNote:=res;
  222. end;
  223. end
  224. else
  225. if GetEntry('KNOWNCOMPILE10ERROR') then
  226. begin
  227. if res<>'' then
  228. begin
  229. val(res,l,code);
  230. if code>1 then
  231. begin
  232. part:=code;
  233. val(copy(res,1,code-1),l,code);
  234. delete(res,1,part);
  235. end;
  236. if code=0 then
  237. r.KnownCompile10Error:=l;
  238. if res<>'' then
  239. r.KnownCompile10Note:=res;
  240. end;
  241. end
  242. else
  243. if GetEntry('KNOWN') then
  244. r.IsKnown:=true
  245. else
  246. if GetEntry('INTERACTIVE') then
  247. r.IsInteractive:=true
  248. else
  249. if GetEntry('NOTE') then
  250. begin
  251. R.Note:='Note: '+res;
  252. Verbose(V_Normal,r.Note);
  253. end
  254. else
  255. Verbose(V_Error,'Unknown entry: '+s);
  256. end;
  257. end
  258. else
  259. break;
  260. end;
  261. end;
  262. close(t);
  263. GetConfig:=true;
  264. end;
  265. Function GetFileContents (FN : String) : String;
  266. Var
  267. F : Text;
  268. S : String;
  269. begin
  270. Result:='';
  271. Assign(F,FN);
  272. {$I-}
  273. Reset(F);
  274. If IOResult<>0 then
  275. Exit;
  276. {$I+}
  277. While Not(EOF(F)) do
  278. begin
  279. ReadLn(F,S);
  280. Result:=Result+S+LineEnding;
  281. end;
  282. Close(F);
  283. end;
  284. end.