testamenthtml.templ 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. #? stdtmpl(subsChar = '%', metaChar = '#', emit = "outfile.write")
  2. #import strutils
  3. #
  4. #proc htmlQuote*(raw: string): string =
  5. # result = raw.multiReplace(
  6. # ("&", "&"),
  7. # ("\"", """),
  8. # ("'", "'"),
  9. # ("<", "&lt;"),
  10. # (">", "&gt;")
  11. # )
  12. #
  13. #end proc
  14. #proc generateHtmlBegin*(outfile: File) =
  15. <!DOCTYPE html>
  16. <html>
  17. <head>
  18. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  19. <title>Testament Test Results</title>
  20. <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.0/jquery.min.js" integrity="sha256-ihAoc6M/JPfrIiIeayPE9xjin4UWjsx2mjW/rtmxLM4=" crossorigin="anonymous"></script>
  21. <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha256-U5ZEeKfGNOja007MMD3YBI0A3OSZOQbeG6z2f2Y0hu8=" crossorigin="anonymous"></script>
  22. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha256-916EbMg70RQy9LHiGkXzG8hSg9EdNy97GazNG/aiY1w=" crossorigin="anonymous" />
  23. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha256-ZT4HPpdCOt2lvDkXokHuhJfdOKSPFLzeAJik5U/Q+l4=" crossorigin="anonymous" />
  24. <script>
  25. /**
  26. * Callback function that is executed for each Element in an array.
  27. * @callback executeForElement
  28. * @param {Element} elem Element to operate on
  29. */
  30. /**
  31. *
  32. * @param {number} index
  33. * @param {Element[]} elemArray
  34. * @param {executeForElement} executeOnItem
  35. */
  36. function executeAllAsync(elemArray, index, executeOnItem) {
  37. for (var i = 0; index < elemArray.length && i < 100; i++ , index++) {
  38. var item = elemArray[index];
  39. executeOnItem(item);
  40. }
  41. if (index < elemArray.length) {
  42. setTimeout(executeAllAsync, 0, elemArray, index, executeOnItem);
  43. }
  44. }
  45. /** @param {Element} elem */
  46. function executeShowOnElement(elem) {
  47. while (elem.classList.contains("hidden")) {
  48. elem.classList.remove("hidden");
  49. }
  50. }
  51. /** @param {Element} elem */
  52. function executeHideOnElement(elem) {
  53. if (!elem.classList.contains("hidden")) {
  54. elem.classList.add("hidden");
  55. }
  56. }
  57. /** @param {Element} elem */
  58. function executeExpandOnElement(elem) {
  59. $(elem).collapse("show");
  60. }
  61. /** @param {Element} elem */
  62. function executeCollapseOnElement(elem) {
  63. $(elem).collapse("hide");
  64. }
  65. /**
  66. * @param {string} [category] Optional bootstrap panel context class (danger, warning, info, success)
  67. * @param {executeForElement} executeOnEachPanel
  68. */
  69. function wholePanelAll(category, executeOnEachPanel) {
  70. var selector = "div.panel";
  71. if (typeof category === "string" && category) {
  72. selector += "-" + category;
  73. }
  74. var jqPanels = $(selector);
  75. /** @type {Element[]} */
  76. var elemArray = jqPanels.toArray();
  77. setTimeout(executeAllAsync, 0, elemArray, 0, executeOnEachPanel);
  78. }
  79. /**
  80. * @param {string} [category] Optional bootstrap panel context class (danger, warning, info, success)
  81. * @param {executeForElement} executeOnEachPanel
  82. */
  83. function panelBodyAll(category, executeOnEachPanelBody) {
  84. var selector = "div.panel";
  85. if (typeof category === "string" && category) {
  86. selector += "-" + category;
  87. }
  88. var jqPanels = $(selector);
  89. var jqPanelBodies = $("div.panel-body", jqPanels);
  90. /** @type {Element[]} */
  91. var elemArray = jqPanelBodies.toArray();
  92. setTimeout(executeAllAsync, 0, elemArray, 0, executeOnEachPanelBody);
  93. }
  94. /**
  95. * @param {string} [category] Optional bootstrap panel context class (danger, warning, info, success)
  96. */
  97. function showAll(category) {
  98. wholePanelAll(category, executeShowOnElement);
  99. }
  100. /**
  101. * @param {string} [category] Optional bootstrap panel context class (danger, warning, info, success)
  102. */
  103. function hideAll(category) {
  104. wholePanelAll(category, executeHideOnElement);
  105. }
  106. /**
  107. * @param {string} [category] Optional bootstrap panel context class (danger, warning, info, success)
  108. */
  109. function expandAll(category) {
  110. panelBodyAll(category, executeExpandOnElement);
  111. }
  112. /**
  113. * @param {string} [category] Optional bootstrap panel context class (danger, warning, info, success)
  114. */
  115. function collapseAll(category) {
  116. panelBodyAll(category, executeCollapseOnElement);
  117. }
  118. </script>
  119. </head>
  120. <body>
  121. <div class="container">
  122. <h1>Testament Test Results <small>Nim Tester</small></h1>
  123. #end proc
  124. #proc generateHtmlAllTestsBegin*(outfile: File, machine, commit, branch: string,
  125. # totalCount: BiggestInt,
  126. # successCount: BiggestInt, successPercentage: string,
  127. # ignoredCount: BiggestInt, ignoredPercentage: string,
  128. # failedCount: BiggestInt, failedPercentage: string, onlyFailing = false) =
  129. <dl class="dl-horizontal">
  130. <dt>Hostname</dt>
  131. <dd>%machine</dd>
  132. <dt>Git Commit</dt>
  133. <dd><code>%commit</code></dd>
  134. <dt title="Git Branch reference">Branch ref.</dt>
  135. <dd>%branch</dd>
  136. </dl>
  137. <dl class="dl-horizontal">
  138. <dt>All Tests</dt>
  139. <dd>
  140. <span class="glyphicon glyphicon-th-list"></span>
  141. %totalCount
  142. </dd>
  143. <dt>Successful Tests</dt>
  144. <dd>
  145. <span class="glyphicon glyphicon-ok-sign"></span>
  146. %successCount (%successPercentage)
  147. </dd>
  148. <dt>Skipped Tests</dt>
  149. <dd>
  150. <span class="glyphicon glyphicon-question-sign"></span>
  151. %ignoredCount (%ignoredPercentage)
  152. </dd>
  153. <dt>Failed Tests</dt>
  154. <dd>
  155. <span class="glyphicon glyphicon-exclamation-sign"></span>
  156. %failedCount (%failedPercentage)
  157. </dd>
  158. </dl>
  159. <div class="table-responsive">
  160. <table class="table table-condensed">
  161. # if not onlyFailing:
  162. <tr>
  163. <th class="text-right" style="vertical-align:middle">All Tests</th>
  164. <td>
  165. <div class="btn-group">
  166. <button class="btn btn-default" type="button" onclick="showAll();">Show All</button>
  167. <button class="btn btn-default" type="button" onclick="hideAll();">Hide All</button>
  168. <button class="btn btn-default" type="button" onclick="expandAll();">Expand All</button>
  169. <button class="btn btn-default" type="button" onclick="collapseAll();">Collapse All</button>
  170. </div>
  171. </td>
  172. </tr>
  173. <tr>
  174. <th class="text-right" style="vertical-align:middle">Successful Tests</th>
  175. <td>
  176. <div class="btn-group">
  177. <button class="btn btn-default" type="button" onclick="showAll('success');">Show All</button>
  178. <button class="btn btn-default" type="button" onclick="hideAll('success');">Hide All</button>
  179. <button class="btn btn-default" type="button" onclick="expandAll('success');">Expand All</button>
  180. <button class="btn btn-default" type="button" onclick="collapseAll('success');">Collapse All</button>
  181. </div>
  182. </td>
  183. </tr>
  184. # end if
  185. <tr>
  186. <th class="text-right" style="vertical-align:middle">Skipped Tests</th>
  187. <td>
  188. <div class="btn-group">
  189. <button class="btn btn-default" type="button" onclick="showAll('info');">Show All</button>
  190. <button class="btn btn-default" type="button" onclick="hideAll('info');">Hide All</button>
  191. <button class="btn btn-default" type="button" onclick="expandAll('info');">Expand All</button>
  192. <button class="btn btn-default" type="button" onclick="collapseAll('info');">Collapse All</button>
  193. </div>
  194. </td>
  195. </tr>
  196. <tr>
  197. <th class="text-right" style="vertical-align:middle">Failed Tests</th>
  198. <td>
  199. <div class="btn-group">
  200. <button class="btn btn-default" type="button" onclick="showAll('danger');">Show All</button>
  201. <button class="btn btn-default" type="button" onclick="hideAll('danger');">Hide All</button>
  202. <button class="btn btn-default" type="button" onclick="expandAll('danger');">Expand All</button>
  203. <button class="btn btn-default" type="button" onclick="collapseAll('danger');">Collapse All</button>
  204. </div>
  205. </td>
  206. </tr>
  207. </table>
  208. </div>
  209. <div class="panel-group">
  210. #end proc
  211. #proc generateHtmlTestresultPanelBegin*(outfile: File, trId, name, target, category,
  212. # action, resultDescription, timestamp, result, resultSign,
  213. # panelCtxClass, textCtxClass, bgCtxClass: string) =
  214. <div id="panel-testResult-%trId" class="panel panel-%panelCtxClass">
  215. <div class="panel-heading" style="cursor:pointer" data-toggle="collapse" data-target="#panel-body-testResult-%trId" aria-controls="panel-body-testResult-%trId" aria-expanded="false">
  216. <div class="row">
  217. <h4 class="col-xs-3 col-sm-1 panel-title">
  218. <span class="glyphicon glyphicon-%resultSign-sign"></span>
  219. <strong>%resultDescription</strong>
  220. </h4>
  221. <h4 class="col-xs-1 panel-title"><span class="badge">%target</span></h4>
  222. <h4 class="col-xs-5 col-sm-7 panel-title" title="%name"><code class="text-%textCtxClass">%name</code></h4>
  223. <h4 class="col-xs-3 col-sm-3 panel-title text-right"><span class="badge">%category</span></h4>
  224. </div>
  225. </div>
  226. <div id="panel-body-testResult-%trId" class="panel-body collapse bg-%bgCtxClass">
  227. <dl class="dl-horizontal">
  228. <dt>Name</dt>
  229. <dd><code class="text-%textCtxClass">%name</code></dd>
  230. <dt>Category</dt>
  231. <dd><span class="badge">%category</span></dd>
  232. <dt>Timestamp</dt>
  233. <dd>%timestamp</dd>
  234. <dt>Nim Action</dt>
  235. <dd><code class="text-%textCtxClass">%action</code></dd>
  236. <dt>Nim Backend Target</dt>
  237. <dd><span class="badge">%target</span></dd>
  238. <dt>Code</dt>
  239. <dd><code class="text-%textCtxClass">%result</code></dd>
  240. </dl>
  241. #end proc
  242. #proc generateHtmlTestresultOutputDetails*(outfile: File, expected, gotten: string) =
  243. <div class="table-responsive">
  244. <table class="table table-condensed">
  245. <thead>
  246. <tr>
  247. <th>Expected</th>
  248. <th>Actual</th>
  249. </tr>
  250. </thead>
  251. <tbody>
  252. <tr>
  253. <td><pre>%expected</pre></td>
  254. <td><pre>%gotten</pre></td>
  255. </tr>
  256. </tbody>
  257. </table>
  258. </div>
  259. #end proc
  260. #proc generateHtmlTestresultOutputNone*(outfile: File) =
  261. <p class="sr-only">No output details</p>
  262. #end proc
  263. #proc generateHtmlTestresultPanelEnd*(outfile: File) =
  264. </div>
  265. </div>
  266. #end proc
  267. #proc generateHtmlAllTestsEnd*(outfile: File) =
  268. </div>
  269. #end proc
  270. #proc generateHtmlEnd*(outfile: File, timestamp: string) =
  271. <hr />
  272. <footer>
  273. <p>
  274. Report generated by: <code>testament</code> &ndash; Nim Tester
  275. <br />
  276. Made with Nim. Generated on: %timestamp
  277. </p>
  278. </footer>
  279. </div>
  280. </body>
  281. </html>