rj_schema 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (614) hide show
  1. checksums.yaml +4 -4
  2. data/ext/rj_schema/rapidjson/CHANGELOG.md +158 -0
  3. data/ext/rj_schema/rapidjson/CMakeLists.txt +226 -0
  4. data/ext/rj_schema/rapidjson/CMakeModules/FindGTestSrc.cmake +30 -0
  5. data/ext/rj_schema/rapidjson/RapidJSON.pc.in +7 -0
  6. data/ext/rj_schema/rapidjson/RapidJSONConfig.cmake.in +25 -0
  7. data/ext/rj_schema/rapidjson/RapidJSONConfigVersion.cmake.in +10 -0
  8. data/ext/rj_schema/rapidjson/appveyor.yml +54 -0
  9. data/ext/rj_schema/rapidjson/bin/data/abcde.txt +1 -0
  10. data/ext/rj_schema/rapidjson/bin/data/glossary.json +22 -0
  11. data/ext/rj_schema/rapidjson/bin/data/menu.json +27 -0
  12. data/ext/rj_schema/rapidjson/bin/data/readme.txt +1 -0
  13. data/ext/rj_schema/rapidjson/bin/data/sample.json +3315 -0
  14. data/ext/rj_schema/rapidjson/bin/data/webapp.json +88 -0
  15. data/ext/rj_schema/rapidjson/bin/data/widget.json +26 -0
  16. data/ext/rj_schema/rapidjson/bin/draft-04/schema +150 -0
  17. data/ext/rj_schema/rapidjson/bin/encodings/utf16be.json +0 -0
  18. data/ext/rj_schema/rapidjson/bin/encodings/utf16bebom.json +0 -0
  19. data/ext/rj_schema/rapidjson/bin/encodings/utf16le.json +0 -0
  20. data/ext/rj_schema/rapidjson/bin/encodings/utf16lebom.json +0 -0
  21. data/ext/rj_schema/rapidjson/bin/encodings/utf32be.json +0 -0
  22. data/ext/rj_schema/rapidjson/bin/encodings/utf32bebom.json +0 -0
  23. data/ext/rj_schema/rapidjson/bin/encodings/utf32le.json +0 -0
  24. data/ext/rj_schema/rapidjson/bin/encodings/utf32lebom.json +0 -0
  25. data/ext/rj_schema/rapidjson/bin/encodings/utf8.json +7 -0
  26. data/ext/rj_schema/rapidjson/bin/encodings/utf8bom.json +7 -0
  27. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail1.json +1 -0
  28. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail10.json +1 -0
  29. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail11.json +1 -0
  30. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail12.json +1 -0
  31. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail13.json +1 -0
  32. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail14.json +1 -0
  33. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail15.json +1 -0
  34. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail16.json +1 -0
  35. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail17.json +1 -0
  36. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail18.json +1 -0
  37. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail19.json +1 -0
  38. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail2.json +1 -0
  39. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail20.json +1 -0
  40. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail21.json +1 -0
  41. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail22.json +1 -0
  42. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail23.json +1 -0
  43. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail24.json +1 -0
  44. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail25.json +1 -0
  45. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail26.json +1 -0
  46. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail27.json +2 -0
  47. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail28.json +2 -0
  48. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail29.json +1 -0
  49. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail3.json +1 -0
  50. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail30.json +1 -0
  51. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail31.json +1 -0
  52. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail32.json +1 -0
  53. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail33.json +1 -0
  54. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail4.json +1 -0
  55. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail5.json +1 -0
  56. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail6.json +1 -0
  57. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail7.json +1 -0
  58. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail8.json +1 -0
  59. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail9.json +1 -0
  60. data/ext/rj_schema/rapidjson/bin/jsonchecker/pass1.json +58 -0
  61. data/ext/rj_schema/rapidjson/bin/jsonchecker/pass2.json +1 -0
  62. data/ext/rj_schema/rapidjson/bin/jsonchecker/pass3.json +6 -0
  63. data/ext/rj_schema/rapidjson/bin/jsonchecker/readme.txt +3 -0
  64. data/ext/rj_schema/rapidjson/bin/jsonschema/LICENSE +19 -0
  65. data/ext/rj_schema/rapidjson/bin/jsonschema/README.md +148 -0
  66. data/ext/rj_schema/rapidjson/bin/jsonschema/bin/jsonschema_suite +283 -0
  67. data/ext/rj_schema/rapidjson/bin/jsonschema/remotes/folder/folderInteger.json +3 -0
  68. data/ext/rj_schema/rapidjson/bin/jsonschema/remotes/integer.json +3 -0
  69. data/ext/rj_schema/rapidjson/bin/jsonschema/remotes/subSchemas.json +8 -0
  70. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/additionalItems.json +82 -0
  71. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/additionalProperties.json +88 -0
  72. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/default.json +49 -0
  73. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/dependencies.json +108 -0
  74. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/disallow.json +80 -0
  75. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/divisibleBy.json +60 -0
  76. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/enum.json +71 -0
  77. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/extends.json +94 -0
  78. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/items.json +46 -0
  79. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/maxItems.json +28 -0
  80. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/maxLength.json +33 -0
  81. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/maximum.json +42 -0
  82. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/minItems.json +28 -0
  83. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/minLength.json +33 -0
  84. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/minimum.json +42 -0
  85. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/optional/bignum.json +107 -0
  86. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/optional/format.json +222 -0
  87. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/optional/jsregex.json +18 -0
  88. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/optional/zeroTerminatedFloats.json +15 -0
  89. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/pattern.json +34 -0
  90. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/patternProperties.json +110 -0
  91. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/properties.json +92 -0
  92. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/ref.json +159 -0
  93. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/refRemote.json +74 -0
  94. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/required.json +53 -0
  95. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/type.json +474 -0
  96. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/uniqueItems.json +79 -0
  97. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/additionalItems.json +82 -0
  98. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/additionalProperties.json +88 -0
  99. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/allOf.json +112 -0
  100. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/anyOf.json +68 -0
  101. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/default.json +49 -0
  102. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/definitions.json +32 -0
  103. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/dependencies.json +113 -0
  104. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/enum.json +72 -0
  105. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/items.json +46 -0
  106. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/maxItems.json +28 -0
  107. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/maxLength.json +33 -0
  108. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/maxProperties.json +28 -0
  109. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/maximum.json +42 -0
  110. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/minItems.json +28 -0
  111. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/minLength.json +33 -0
  112. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/minProperties.json +28 -0
  113. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/minimum.json +42 -0
  114. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/multipleOf.json +60 -0
  115. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/not.json +96 -0
  116. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/oneOf.json +68 -0
  117. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/optional/bignum.json +107 -0
  118. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/optional/format.json +148 -0
  119. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/optional/zeroTerminatedFloats.json +15 -0
  120. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/pattern.json +34 -0
  121. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/patternProperties.json +110 -0
  122. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/properties.json +92 -0
  123. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/ref.json +159 -0
  124. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/refRemote.json +74 -0
  125. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/required.json +39 -0
  126. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/type.json +330 -0
  127. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/uniqueItems.json +79 -0
  128. data/ext/rj_schema/rapidjson/bin/jsonschema/tox.ini +8 -0
  129. data/ext/rj_schema/rapidjson/bin/types/booleans.json +102 -0
  130. data/ext/rj_schema/rapidjson/bin/types/floats.json +102 -0
  131. data/ext/rj_schema/rapidjson/bin/types/guids.json +102 -0
  132. data/ext/rj_schema/rapidjson/bin/types/integers.json +102 -0
  133. data/ext/rj_schema/rapidjson/bin/types/mixed.json +592 -0
  134. data/ext/rj_schema/rapidjson/bin/types/nulls.json +102 -0
  135. data/ext/rj_schema/rapidjson/bin/types/paragraphs.json +102 -0
  136. data/ext/rj_schema/rapidjson/bin/types/readme.txt +1 -0
  137. data/ext/rj_schema/rapidjson/contrib/natvis/LICENSE +45 -0
  138. data/ext/rj_schema/rapidjson/contrib/natvis/README.md +7 -0
  139. data/ext/rj_schema/rapidjson/contrib/natvis/rapidjson.natvis +38 -0
  140. data/ext/rj_schema/rapidjson/doc/CMakeLists.txt +27 -0
  141. data/ext/rj_schema/rapidjson/doc/Doxyfile.in +2369 -0
  142. data/ext/rj_schema/rapidjson/doc/Doxyfile.zh-cn.in +2369 -0
  143. data/ext/rj_schema/rapidjson/doc/diagram/architecture.dot +50 -0
  144. data/ext/rj_schema/rapidjson/doc/diagram/architecture.png +0 -0
  145. data/ext/rj_schema/rapidjson/doc/diagram/insituparsing.dot +65 -0
  146. data/ext/rj_schema/rapidjson/doc/diagram/insituparsing.png +0 -0
  147. data/ext/rj_schema/rapidjson/doc/diagram/iterative-parser-states-diagram.dot +62 -0
  148. data/ext/rj_schema/rapidjson/doc/diagram/iterative-parser-states-diagram.png +0 -0
  149. data/ext/rj_schema/rapidjson/doc/diagram/makefile +8 -0
  150. data/ext/rj_schema/rapidjson/doc/diagram/move1.dot +47 -0
  151. data/ext/rj_schema/rapidjson/doc/diagram/move1.png +0 -0
  152. data/ext/rj_schema/rapidjson/doc/diagram/move2.dot +62 -0
  153. data/ext/rj_schema/rapidjson/doc/diagram/move2.png +0 -0
  154. data/ext/rj_schema/rapidjson/doc/diagram/move3.dot +60 -0
  155. data/ext/rj_schema/rapidjson/doc/diagram/move3.png +0 -0
  156. data/ext/rj_schema/rapidjson/doc/diagram/normalparsing.dot +56 -0
  157. data/ext/rj_schema/rapidjson/doc/diagram/normalparsing.png +0 -0
  158. data/ext/rj_schema/rapidjson/doc/diagram/simpledom.dot +54 -0
  159. data/ext/rj_schema/rapidjson/doc/diagram/simpledom.png +0 -0
  160. data/ext/rj_schema/rapidjson/doc/diagram/tutorial.dot +58 -0
  161. data/ext/rj_schema/rapidjson/doc/diagram/tutorial.png +0 -0
  162. data/ext/rj_schema/rapidjson/doc/diagram/utilityclass.dot +73 -0
  163. data/ext/rj_schema/rapidjson/doc/diagram/utilityclass.png +0 -0
  164. data/ext/rj_schema/rapidjson/doc/dom.md +281 -0
  165. data/ext/rj_schema/rapidjson/doc/dom.zh-cn.md +285 -0
  166. data/ext/rj_schema/rapidjson/doc/encoding.md +146 -0
  167. data/ext/rj_schema/rapidjson/doc/encoding.zh-cn.md +152 -0
  168. data/ext/rj_schema/rapidjson/doc/faq.md +289 -0
  169. data/ext/rj_schema/rapidjson/doc/faq.zh-cn.md +290 -0
  170. data/ext/rj_schema/rapidjson/doc/features.md +104 -0
  171. data/ext/rj_schema/rapidjson/doc/features.zh-cn.md +103 -0
  172. data/ext/rj_schema/rapidjson/doc/internals.md +368 -0
  173. data/ext/rj_schema/rapidjson/doc/internals.zh-cn.md +363 -0
  174. data/ext/rj_schema/rapidjson/doc/logo/rapidjson.png +0 -0
  175. data/ext/rj_schema/rapidjson/doc/logo/rapidjson.svg +119 -0
  176. data/ext/rj_schema/rapidjson/doc/misc/DoxygenLayout.xml +194 -0
  177. data/ext/rj_schema/rapidjson/doc/misc/doxygenextra.css +274 -0
  178. data/ext/rj_schema/rapidjson/doc/misc/footer.html +11 -0
  179. data/ext/rj_schema/rapidjson/doc/misc/header.html +24 -0
  180. data/ext/rj_schema/rapidjson/doc/npm.md +31 -0
  181. data/ext/rj_schema/rapidjson/doc/performance.md +26 -0
  182. data/ext/rj_schema/rapidjson/doc/performance.zh-cn.md +26 -0
  183. data/ext/rj_schema/rapidjson/doc/pointer.md +234 -0
  184. data/ext/rj_schema/rapidjson/doc/pointer.zh-cn.md +234 -0
  185. data/ext/rj_schema/rapidjson/doc/sax.md +509 -0
  186. data/ext/rj_schema/rapidjson/doc/sax.zh-cn.md +487 -0
  187. data/ext/rj_schema/rapidjson/doc/schema.md +505 -0
  188. data/ext/rj_schema/rapidjson/doc/schema.zh-cn.md +237 -0
  189. data/ext/rj_schema/rapidjson/doc/stream.md +429 -0
  190. data/ext/rj_schema/rapidjson/doc/stream.zh-cn.md +429 -0
  191. data/ext/rj_schema/rapidjson/doc/tutorial.md +536 -0
  192. data/ext/rj_schema/rapidjson/doc/tutorial.zh-cn.md +535 -0
  193. data/ext/rj_schema/rapidjson/docker/debian/Dockerfile +8 -0
  194. data/ext/rj_schema/rapidjson/example/CMakeLists.txt +46 -0
  195. data/ext/rj_schema/rapidjson/example/archiver/archiver.cpp +292 -0
  196. data/ext/rj_schema/rapidjson/example/archiver/archiver.h +145 -0
  197. data/ext/rj_schema/rapidjson/example/archiver/archivertest.cpp +287 -0
  198. data/ext/rj_schema/rapidjson/example/capitalize/capitalize.cpp +67 -0
  199. data/ext/rj_schema/rapidjson/example/condense/condense.cpp +32 -0
  200. data/ext/rj_schema/rapidjson/example/filterkey/filterkey.cpp +135 -0
  201. data/ext/rj_schema/rapidjson/example/filterkeydom/filterkeydom.cpp +170 -0
  202. data/ext/rj_schema/rapidjson/example/jsonx/jsonx.cpp +207 -0
  203. data/ext/rj_schema/rapidjson/example/lookaheadparser/lookaheadparser.cpp +350 -0
  204. data/ext/rj_schema/rapidjson/example/messagereader/messagereader.cpp +105 -0
  205. data/ext/rj_schema/rapidjson/example/parsebyparts/parsebyparts.cpp +176 -0
  206. data/ext/rj_schema/rapidjson/example/pretty/pretty.cpp +30 -0
  207. data/ext/rj_schema/rapidjson/example/prettyauto/prettyauto.cpp +56 -0
  208. data/ext/rj_schema/rapidjson/example/schemavalidator/schemavalidator.cpp +78 -0
  209. data/ext/rj_schema/rapidjson/example/serialize/serialize.cpp +173 -0
  210. data/ext/rj_schema/rapidjson/example/simpledom/simpledom.cpp +29 -0
  211. data/ext/rj_schema/rapidjson/example/simplepullreader/simplepullreader.cpp +53 -0
  212. data/ext/rj_schema/rapidjson/example/simplereader/simplereader.cpp +42 -0
  213. data/ext/rj_schema/rapidjson/example/simplewriter/simplewriter.cpp +36 -0
  214. data/ext/rj_schema/rapidjson/example/sortkeys/sortkeys.cpp +62 -0
  215. data/ext/rj_schema/rapidjson/example/tutorial/tutorial.cpp +151 -0
  216. data/ext/rj_schema/rapidjson/include/rapidjson/allocators.h +284 -0
  217. data/ext/rj_schema/rapidjson/include/rapidjson/cursorstreamwrapper.h +78 -0
  218. data/ext/rj_schema/rapidjson/include/rapidjson/document.h +2732 -0
  219. data/ext/rj_schema/rapidjson/include/rapidjson/encodedstream.h +299 -0
  220. data/ext/rj_schema/rapidjson/include/rapidjson/encodings.h +716 -0
  221. data/ext/rj_schema/rapidjson/include/rapidjson/error/en.h +74 -0
  222. data/ext/rj_schema/rapidjson/include/rapidjson/error/error.h +161 -0
  223. data/ext/rj_schema/rapidjson/include/rapidjson/filereadstream.h +99 -0
  224. data/ext/rj_schema/rapidjson/include/rapidjson/filewritestream.h +104 -0
  225. data/ext/rj_schema/rapidjson/include/rapidjson/fwd.h +151 -0
  226. data/ext/rj_schema/rapidjson/include/rapidjson/internal/biginteger.h +290 -0
  227. data/ext/rj_schema/rapidjson/include/rapidjson/internal/clzll.h +71 -0
  228. data/ext/rj_schema/rapidjson/include/rapidjson/internal/diyfp.h +257 -0
  229. data/ext/rj_schema/rapidjson/include/rapidjson/internal/dtoa.h +245 -0
  230. data/ext/rj_schema/rapidjson/include/rapidjson/internal/ieee754.h +78 -0
  231. data/ext/rj_schema/rapidjson/include/rapidjson/internal/itoa.h +308 -0
  232. data/ext/rj_schema/rapidjson/include/rapidjson/internal/meta.h +186 -0
  233. data/ext/rj_schema/rapidjson/include/rapidjson/internal/pow10.h +55 -0
  234. data/ext/rj_schema/rapidjson/include/rapidjson/internal/regex.h +739 -0
  235. data/ext/rj_schema/rapidjson/include/rapidjson/internal/stack.h +232 -0
  236. data/ext/rj_schema/rapidjson/include/rapidjson/internal/strfunc.h +69 -0
  237. data/ext/rj_schema/rapidjson/include/rapidjson/internal/strtod.h +290 -0
  238. data/ext/rj_schema/rapidjson/include/rapidjson/internal/swap.h +46 -0
  239. data/ext/rj_schema/rapidjson/include/rapidjson/istreamwrapper.h +128 -0
  240. data/ext/rj_schema/rapidjson/include/rapidjson/memorybuffer.h +70 -0
  241. data/ext/rj_schema/rapidjson/include/rapidjson/memorystream.h +71 -0
  242. data/ext/rj_schema/rapidjson/include/rapidjson/msinttypes/inttypes.h +316 -0
  243. data/ext/rj_schema/rapidjson/include/rapidjson/msinttypes/stdint.h +300 -0
  244. data/ext/rj_schema/rapidjson/include/rapidjson/ostreamwrapper.h +81 -0
  245. data/ext/rj_schema/rapidjson/include/rapidjson/pointer.h +1415 -0
  246. data/ext/rj_schema/rapidjson/include/rapidjson/prettywriter.h +277 -0
  247. data/ext/rj_schema/rapidjson/include/rapidjson/rapidjson.h +676 -0
  248. data/ext/rj_schema/rapidjson/include/rapidjson/reader.h +2236 -0
  249. data/ext/rj_schema/rapidjson/include/rapidjson/schema.h +2496 -0
  250. data/ext/rj_schema/rapidjson/include/rapidjson/stream.h +223 -0
  251. data/ext/rj_schema/rapidjson/include/rapidjson/stringbuffer.h +121 -0
  252. data/ext/rj_schema/rapidjson/include/rapidjson/writer.h +710 -0
  253. data/ext/rj_schema/rapidjson/include_dirs.js +2 -0
  254. data/ext/rj_schema/rapidjson/library.json +15 -0
  255. data/ext/rj_schema/rapidjson/license.txt +57 -0
  256. data/ext/rj_schema/rapidjson/package.json +24 -0
  257. data/ext/rj_schema/rapidjson/rapidjson.autopkg +77 -0
  258. data/ext/rj_schema/rapidjson/readme.md +210 -0
  259. data/ext/rj_schema/rapidjson/readme.zh-cn.md +152 -0
  260. data/ext/rj_schema/rapidjson/test/CMakeLists.txt +20 -0
  261. data/ext/rj_schema/rapidjson/test/perftest/CMakeLists.txt +28 -0
  262. data/ext/rj_schema/rapidjson/test/perftest/misctest.cpp +974 -0
  263. data/ext/rj_schema/rapidjson/test/perftest/perftest.cpp +24 -0
  264. data/ext/rj_schema/rapidjson/test/perftest/perftest.h +185 -0
  265. data/ext/rj_schema/rapidjson/test/perftest/platformtest.cpp +166 -0
  266. data/ext/rj_schema/rapidjson/test/perftest/rapidjsontest.cpp +546 -0
  267. data/ext/rj_schema/rapidjson/test/perftest/schematest.cpp +223 -0
  268. data/ext/rj_schema/rapidjson/test/unittest/CMakeLists.txt +92 -0
  269. data/ext/rj_schema/rapidjson/test/unittest/allocatorstest.cpp +100 -0
  270. data/ext/rj_schema/rapidjson/test/unittest/bigintegertest.cpp +138 -0
  271. data/ext/rj_schema/rapidjson/test/unittest/cursorstreamwrappertest.cpp +115 -0
  272. data/ext/rj_schema/rapidjson/test/unittest/documenttest.cpp +672 -0
  273. data/ext/rj_schema/rapidjson/test/unittest/dtoatest.cpp +98 -0
  274. data/ext/rj_schema/rapidjson/test/unittest/encodedstreamtest.cpp +313 -0
  275. data/ext/rj_schema/rapidjson/test/unittest/encodingstest.cpp +451 -0
  276. data/ext/rj_schema/rapidjson/test/unittest/filestreamtest.cpp +155 -0
  277. data/ext/rj_schema/rapidjson/test/unittest/fwdtest.cpp +230 -0
  278. data/ext/rj_schema/rapidjson/test/unittest/istreamwrappertest.cpp +181 -0
  279. data/ext/rj_schema/rapidjson/test/unittest/itoatest.cpp +160 -0
  280. data/ext/rj_schema/rapidjson/test/unittest/jsoncheckertest.cpp +143 -0
  281. data/ext/rj_schema/rapidjson/test/unittest/namespacetest.cpp +70 -0
  282. data/ext/rj_schema/rapidjson/test/unittest/ostreamwrappertest.cpp +92 -0
  283. data/ext/rj_schema/rapidjson/test/unittest/pointertest.cpp +1638 -0
  284. data/ext/rj_schema/rapidjson/test/unittest/prettywritertest.cpp +373 -0
  285. data/ext/rj_schema/rapidjson/test/unittest/readertest.cpp +2225 -0
  286. data/ext/rj_schema/rapidjson/test/unittest/regextest.cpp +639 -0
  287. data/ext/rj_schema/rapidjson/test/unittest/schematest.cpp +2072 -0
  288. data/ext/rj_schema/rapidjson/test/unittest/simdtest.cpp +219 -0
  289. data/ext/rj_schema/rapidjson/test/unittest/strfunctest.cpp +30 -0
  290. data/ext/rj_schema/rapidjson/test/unittest/stringbuffertest.cpp +192 -0
  291. data/ext/rj_schema/rapidjson/test/unittest/strtodtest.cpp +132 -0
  292. data/ext/rj_schema/rapidjson/test/unittest/unittest.cpp +51 -0
  293. data/ext/rj_schema/rapidjson/test/unittest/unittest.h +143 -0
  294. data/ext/rj_schema/rapidjson/test/unittest/valuetest.cpp +1851 -0
  295. data/ext/rj_schema/rapidjson/test/unittest/writertest.cpp +598 -0
  296. data/ext/rj_schema/rapidjson/test/valgrind.supp +17 -0
  297. data/ext/rj_schema/rapidjson/thirdparty/gtest/BUILD.bazel +175 -0
  298. data/ext/rj_schema/rapidjson/thirdparty/gtest/CMakeLists.txt +33 -0
  299. data/ext/rj_schema/rapidjson/thirdparty/gtest/CONTRIBUTING.md +160 -0
  300. data/ext/rj_schema/rapidjson/thirdparty/gtest/LICENSE +28 -0
  301. data/ext/rj_schema/rapidjson/thirdparty/gtest/Makefile.am +14 -0
  302. data/ext/rj_schema/rapidjson/thirdparty/gtest/README.md +122 -0
  303. data/ext/rj_schema/rapidjson/thirdparty/gtest/WORKSPACE +8 -0
  304. data/ext/rj_schema/rapidjson/thirdparty/gtest/appveyor.yml +104 -0
  305. data/ext/rj_schema/rapidjson/thirdparty/gtest/ci/build-linux-autotools.sh +44 -0
  306. data/ext/rj_schema/rapidjson/thirdparty/gtest/ci/build-linux-bazel.sh +36 -0
  307. data/ext/rj_schema/rapidjson/thirdparty/gtest/ci/env-linux.sh +41 -0
  308. data/ext/rj_schema/rapidjson/thirdparty/gtest/ci/env-osx.sh +40 -0
  309. data/ext/rj_schema/rapidjson/thirdparty/gtest/ci/get-nprocessors.sh +48 -0
  310. data/ext/rj_schema/rapidjson/thirdparty/gtest/ci/install-linux.sh +49 -0
  311. data/ext/rj_schema/rapidjson/thirdparty/gtest/ci/install-osx.sh +39 -0
  312. data/ext/rj_schema/rapidjson/thirdparty/gtest/ci/log-config.sh +51 -0
  313. data/ext/rj_schema/rapidjson/thirdparty/gtest/ci/travis.sh +44 -0
  314. data/ext/rj_schema/rapidjson/thirdparty/gtest/configure.ac +16 -0
  315. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/CHANGES +126 -0
  316. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/CMakeLists.txt +242 -0
  317. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/CONTRIBUTORS +40 -0
  318. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/LICENSE +28 -0
  319. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/Makefile.am +224 -0
  320. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/README.md +344 -0
  321. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/cmake/gmock.pc.in +9 -0
  322. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/cmake/gmock_main.pc.in +9 -0
  323. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/configure.ac +146 -0
  324. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/docs/CheatSheet.md +564 -0
  325. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/docs/CookBook.md +3660 -0
  326. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/docs/DesignDoc.md +280 -0
  327. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/docs/Documentation.md +15 -0
  328. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/docs/ForDummies.md +447 -0
  329. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/docs/FrequentlyAskedQuestions.md +627 -0
  330. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/docs/KnownIssues.md +19 -0
  331. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/gmock-actions.h +1262 -0
  332. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/gmock-cardinalities.h +147 -0
  333. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/gmock-generated-actions.h +2571 -0
  334. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/gmock-generated-actions.h.pump +833 -0
  335. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/gmock-generated-function-mockers.h +1379 -0
  336. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/gmock-generated-function-mockers.h.pump +347 -0
  337. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/gmock-generated-matchers.h +2258 -0
  338. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/gmock-generated-matchers.h.pump +675 -0
  339. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/gmock-generated-nice-strict.h +458 -0
  340. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/gmock-generated-nice-strict.h.pump +178 -0
  341. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/gmock-matchers.h +5255 -0
  342. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/gmock-more-actions.h +246 -0
  343. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/gmock-more-matchers.h +91 -0
  344. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/gmock-spec-builders.h +1918 -0
  345. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/gmock.h +95 -0
  346. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/internal/custom/gmock-generated-actions.h +8 -0
  347. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/internal/custom/gmock-generated-actions.h.pump +10 -0
  348. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/internal/custom/gmock-matchers.h +38 -0
  349. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/internal/custom/gmock-port.h +46 -0
  350. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/internal/gmock-generated-internal-utils.h +286 -0
  351. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/internal/gmock-generated-internal-utils.h.pump +136 -0
  352. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/internal/gmock-internal-utils.h +574 -0
  353. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/internal/gmock-port.h +87 -0
  354. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/make/Makefile +101 -0
  355. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/msvc/2005/gmock.sln +32 -0
  356. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/msvc/2005/gmock.vcproj +191 -0
  357. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/msvc/2005/gmock_config.vsprops +15 -0
  358. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/msvc/2005/gmock_main.vcproj +187 -0
  359. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/msvc/2005/gmock_test.vcproj +201 -0
  360. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/msvc/2010/gmock.sln +46 -0
  361. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/msvc/2010/gmock.vcxproj +145 -0
  362. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/msvc/2010/gmock_config.props +19 -0
  363. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/msvc/2010/gmock_main.vcxproj +151 -0
  364. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/msvc/2010/gmock_test.vcxproj +176 -0
  365. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/msvc/2015/gmock.sln +46 -0
  366. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/msvc/2015/gmock.vcxproj +145 -0
  367. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/msvc/2015/gmock_config.props +19 -0
  368. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/msvc/2015/gmock_main.vcxproj +151 -0
  369. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/msvc/2015/gmock_test.vcxproj +176 -0
  370. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/scripts/fuse_gmock_files.py +240 -0
  371. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/scripts/generator/LICENSE +203 -0
  372. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/scripts/generator/README +34 -0
  373. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/scripts/generator/README.cppclean +115 -0
  374. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/scripts/generator/cpp/__init__.py +0 -0
  375. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/scripts/generator/cpp/ast.py +1733 -0
  376. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/scripts/generator/cpp/gmock_class.py +227 -0
  377. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/scripts/generator/cpp/gmock_class_test.py +448 -0
  378. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/scripts/generator/cpp/keywords.py +59 -0
  379. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/scripts/generator/cpp/tokenize.py +287 -0
  380. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/scripts/generator/cpp/utils.py +41 -0
  381. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/scripts/generator/gmock_gen.py +31 -0
  382. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/scripts/gmock-config.in +303 -0
  383. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/scripts/gmock_doctor.py +640 -0
  384. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/scripts/upload.py +1387 -0
  385. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/scripts/upload_gmock.py +78 -0
  386. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/src/gmock-all.cc +47 -0
  387. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/src/gmock-cardinalities.cc +156 -0
  388. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/src/gmock-internal-utils.cc +204 -0
  389. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/src/gmock-matchers.cc +573 -0
  390. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/src/gmock-spec-builders.cc +883 -0
  391. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/src/gmock.cc +205 -0
  392. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/src/gmock_main.cc +54 -0
  393. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/BUILD.bazel +123 -0
  394. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock-actions_test.cc +1575 -0
  395. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock-cardinalities_test.cc +428 -0
  396. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock-generated-actions_test.cc +1230 -0
  397. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock-generated-function-mockers_test.cc +647 -0
  398. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock-generated-internal-utils_test.cc +129 -0
  399. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock-generated-matchers_test.cc +1341 -0
  400. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock-internal-utils_test.cc +718 -0
  401. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock-matchers_test.cc +6767 -0
  402. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock-more-actions_test.cc +710 -0
  403. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock-nice-strict_test.cc +511 -0
  404. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock-port_test.cc +43 -0
  405. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock-spec-builders_test.cc +2771 -0
  406. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock_all_test.cc +51 -0
  407. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock_ex_test.cc +81 -0
  408. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock_leak_test.py +108 -0
  409. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock_leak_test_.cc +100 -0
  410. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock_link2_test.cc +40 -0
  411. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock_link_test.cc +40 -0
  412. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock_link_test.h +691 -0
  413. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock_output_test.py +183 -0
  414. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock_output_test_.cc +310 -0
  415. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock_output_test_golden.txt +317 -0
  416. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock_stress_test.cc +323 -0
  417. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock_test.cc +262 -0
  418. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock_test_utils.py +110 -0
  419. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/CHANGES +157 -0
  420. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/CMakeLists.txt +312 -0
  421. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/CONTRIBUTORS +37 -0
  422. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/LICENSE +28 -0
  423. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/Makefile.am +339 -0
  424. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/README.md +341 -0
  425. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/cmake/gtest.pc.in +9 -0
  426. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/cmake/gtest_main.pc.in +10 -0
  427. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/cmake/internal_utils.cmake +280 -0
  428. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/codegear/gtest.cbproj +138 -0
  429. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/codegear/gtest.groupproj +54 -0
  430. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/codegear/gtest_all.cc +38 -0
  431. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/codegear/gtest_link.cc +40 -0
  432. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/codegear/gtest_main.cbproj +82 -0
  433. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/codegear/gtest_unittest.cbproj +88 -0
  434. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/configure.ac +68 -0
  435. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/docs/Pkgconfig.md +146 -0
  436. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/docs/PumpManual.md +177 -0
  437. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/docs/XcodeGuide.md +93 -0
  438. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/docs/advanced.md +2416 -0
  439. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/docs/faq.md +1092 -0
  440. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/docs/primer.md +536 -0
  441. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/docs/samples.md +14 -0
  442. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/gtest-death-test.h +342 -0
  443. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/gtest-message.h +249 -0
  444. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/gtest-param-test.h +1438 -0
  445. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/gtest-param-test.h.pump +501 -0
  446. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/gtest-printers.h +1082 -0
  447. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/gtest-spi.h +231 -0
  448. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/gtest-test-part.h +179 -0
  449. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/gtest-typed-test.h +264 -0
  450. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/gtest.h +2332 -0
  451. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/gtest_pred_impl.h +357 -0
  452. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/gtest_prod.h +61 -0
  453. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/internal/custom/gtest-port.h +70 -0
  454. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/internal/custom/gtest-printers.h +42 -0
  455. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/internal/custom/gtest.h +45 -0
  456. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/internal/gtest-death-test-internal.h +275 -0
  457. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/internal/gtest-filepath.h +205 -0
  458. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/internal/gtest-internal.h +1277 -0
  459. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/internal/gtest-linked_ptr.h +243 -0
  460. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/internal/gtest-param-util-generated.h +5139 -0
  461. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/internal/gtest-param-util-generated.h.pump +279 -0
  462. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/internal/gtest-param-util.h +723 -0
  463. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/internal/gtest-port-arch.h +100 -0
  464. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/internal/gtest-port.h +2687 -0
  465. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/internal/gtest-string.h +167 -0
  466. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/internal/gtest-tuple.h +1020 -0
  467. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/internal/gtest-tuple.h.pump +347 -0
  468. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/internal/gtest-type-util.h +3347 -0
  469. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/internal/gtest-type-util.h.pump +313 -0
  470. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/m4/acx_pthread.m4 +363 -0
  471. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/m4/gtest.m4 +74 -0
  472. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/make/Makefile +82 -0
  473. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/2010/gtest-md.sln +55 -0
  474. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/2010/gtest-md.vcxproj +149 -0
  475. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/2010/gtest-md.vcxproj.filters +18 -0
  476. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/2010/gtest.sln +55 -0
  477. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/2010/gtest.vcxproj +149 -0
  478. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/2010/gtest.vcxproj.filters +18 -0
  479. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/2010/gtest_main-md.vcxproj +154 -0
  480. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/2010/gtest_main-md.vcxproj.filters +18 -0
  481. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/2010/gtest_main.vcxproj +162 -0
  482. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/2010/gtest_main.vcxproj.filters +18 -0
  483. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/2010/gtest_prod_test-md.vcxproj +199 -0
  484. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/2010/gtest_prod_test-md.vcxproj.filters +26 -0
  485. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/2010/gtest_prod_test.vcxproj +191 -0
  486. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/2010/gtest_prod_test.vcxproj.filters +26 -0
  487. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/2010/gtest_unittest-md.vcxproj +188 -0
  488. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/2010/gtest_unittest-md.vcxproj.filters +18 -0
  489. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/2010/gtest_unittest.vcxproj +180 -0
  490. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/2010/gtest_unittest.vcxproj.filters +18 -0
  491. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/samples/prime_tables.h +127 -0
  492. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/samples/sample1.cc +68 -0
  493. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/samples/sample1.h +43 -0
  494. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/samples/sample10_unittest.cc +140 -0
  495. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/samples/sample1_unittest.cc +154 -0
  496. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/samples/sample2.cc +56 -0
  497. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/samples/sample2.h +85 -0
  498. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/samples/sample2_unittest.cc +110 -0
  499. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/samples/sample3-inl.h +172 -0
  500. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/samples/sample3_unittest.cc +152 -0
  501. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/samples/sample4.cc +46 -0
  502. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/samples/sample4.h +53 -0
  503. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/samples/sample4_unittest.cc +49 -0
  504. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/samples/sample5_unittest.cc +199 -0
  505. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/samples/sample6_unittest.cc +225 -0
  506. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/samples/sample7_unittest.cc +118 -0
  507. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/samples/sample8_unittest.cc +174 -0
  508. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/samples/sample9_unittest.cc +157 -0
  509. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/scripts/common.py +83 -0
  510. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/scripts/fuse_gtest_files.py +253 -0
  511. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/scripts/gen_gtest_pred_impl.py +730 -0
  512. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/scripts/gtest-config.in +274 -0
  513. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/scripts/pump.py +855 -0
  514. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/scripts/release_docs.py +158 -0
  515. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/scripts/test/Makefile +59 -0
  516. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/scripts/upload.py +1387 -0
  517. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/scripts/upload_gtest.py +78 -0
  518. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/src/gtest-all.cc +48 -0
  519. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/src/gtest-death-test.cc +1536 -0
  520. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/src/gtest-filepath.cc +385 -0
  521. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/src/gtest-internal-inl.h +1175 -0
  522. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/src/gtest-port.cc +1277 -0
  523. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/src/gtest-printers.cc +458 -0
  524. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/src/gtest-test-part.cc +102 -0
  525. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/src/gtest-typed-test.cc +119 -0
  526. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/src/gtest.cc +5846 -0
  527. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/src/gtest_main.cc +38 -0
  528. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/BUILD.bazel +396 -0
  529. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest-death-test_ex_test.cc +93 -0
  530. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest-death-test_test.cc +1424 -0
  531. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest-filepath_test.cc +652 -0
  532. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest-linked_ptr_test.cc +154 -0
  533. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest-listener_test.cc +311 -0
  534. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest-message_test.cc +159 -0
  535. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest-options_test.cc +213 -0
  536. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest-param-test2_test.cc +61 -0
  537. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest-param-test_test.cc +1110 -0
  538. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest-param-test_test.h +53 -0
  539. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest-port_test.cc +1303 -0
  540. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest-printers_test.cc +1737 -0
  541. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest-test-part_test.cc +208 -0
  542. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest-tuple_test.cc +320 -0
  543. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest-typed-test2_test.cc +45 -0
  544. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest-typed-test_test.cc +380 -0
  545. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest-typed-test_test.h +66 -0
  546. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest-unittest-api_test.cc +341 -0
  547. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_all_test.cc +47 -0
  548. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_assert_by_exception_test.cc +119 -0
  549. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_break_on_failure_unittest.py +210 -0
  550. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_break_on_failure_unittest_.cc +87 -0
  551. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_catch_exceptions_test.py +235 -0
  552. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_catch_exceptions_test_.cc +311 -0
  553. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_color_test.py +129 -0
  554. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_color_test_.cc +63 -0
  555. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_env_var_test.py +119 -0
  556. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_env_var_test_.cc +124 -0
  557. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_environment_test.cc +189 -0
  558. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_filter_unittest.py +638 -0
  559. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_filter_unittest_.cc +138 -0
  560. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_help_test.py +172 -0
  561. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_help_test_.cc +46 -0
  562. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_json_outfiles_test.py +162 -0
  563. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_json_output_unittest.py +611 -0
  564. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_json_test_utils.py +60 -0
  565. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_list_tests_unittest.py +207 -0
  566. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_list_tests_unittest_.cc +157 -0
  567. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_main_unittest.cc +45 -0
  568. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_no_test_unittest.cc +56 -0
  569. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_output_test.py +344 -0
  570. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_output_test_.cc +1067 -0
  571. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_output_test_golden_lin.txt +781 -0
  572. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_pred_impl_unittest.cc +2427 -0
  573. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_premature_exit_test.cc +127 -0
  574. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_prod_test.cc +57 -0
  575. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_repeat_test.cc +236 -0
  576. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_shuffle_test.py +325 -0
  577. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_shuffle_test_.cc +103 -0
  578. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_sole_header_test.cc +57 -0
  579. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_stress_test.cc +250 -0
  580. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_test_utils.py +318 -0
  581. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_testbridge_test.py +65 -0
  582. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_testbridge_test_.cc +44 -0
  583. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_throw_on_failure_ex_test.cc +92 -0
  584. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_throw_on_failure_test.py +171 -0
  585. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_throw_on_failure_test_.cc +72 -0
  586. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_uninitialized_test.py +69 -0
  587. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_uninitialized_test_.cc +43 -0
  588. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_unittest.cc +7797 -0
  589. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_xml_outfile1_test_.cc +48 -0
  590. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_xml_outfile2_test_.cc +48 -0
  591. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_xml_outfiles_test.py +140 -0
  592. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_xml_output_unittest.py +378 -0
  593. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_xml_output_unittest_.cc +179 -0
  594. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_xml_test_utils.py +196 -0
  595. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/production.cc +36 -0
  596. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/production.h +55 -0
  597. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/xcode/Config/DebugProject.xcconfig +30 -0
  598. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/xcode/Config/FrameworkTarget.xcconfig +17 -0
  599. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/xcode/Config/General.xcconfig +41 -0
  600. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/xcode/Config/ReleaseProject.xcconfig +32 -0
  601. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/xcode/Config/StaticLibraryTarget.xcconfig +18 -0
  602. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/xcode/Config/TestTarget.xcconfig +8 -0
  603. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/xcode/Resources/Info.plist +30 -0
  604. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/xcode/Samples/FrameworkSample/Info.plist +28 -0
  605. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/xcode/Samples/FrameworkSample/WidgetFramework.xcodeproj/project.pbxproj +457 -0
  606. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/xcode/Samples/FrameworkSample/runtests.sh +62 -0
  607. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/xcode/Samples/FrameworkSample/widget.cc +63 -0
  608. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/xcode/Samples/FrameworkSample/widget.h +59 -0
  609. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/xcode/Samples/FrameworkSample/widget_test.cc +68 -0
  610. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/xcode/Scripts/runtests.sh +65 -0
  611. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/xcode/Scripts/versiongenerate.py +100 -0
  612. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/xcode/gtest.xcodeproj/project.pbxproj +1182 -0
  613. data/ext/rj_schema/rapidjson/travis-doxygen.sh +128 -0
  614. metadata +613 -1
@@ -0,0 +1,146 @@
1
+ ## Using GoogleTest from various build systems ##
2
+
3
+ GoogleTest comes with pkg-config files that can be used to determine all
4
+ necessary flags for compiling and linking to GoogleTest (and GoogleMock).
5
+ Pkg-config is a standardised plain-text format containing
6
+
7
+ * the includedir (-I) path
8
+ * necessary macro (-D) definitions
9
+ * further required flags (-pthread)
10
+ * the library (-L) path
11
+ * the library (-l) to link to
12
+
13
+ All current build systems support pkg-config in one way or another. For
14
+ all examples here we assume you want to compile the sample
15
+ `samples/sample3_unittest.cc`.
16
+
17
+
18
+ ### CMake ###
19
+
20
+ Using `pkg-config` in CMake is fairly easy:
21
+
22
+ ```
23
+ cmake_minimum_required(VERSION 3.0)
24
+
25
+ cmake_policy(SET CMP0048 NEW)
26
+ project(my_gtest_pkgconfig VERSION 0.0.1 LANGUAGES CXX)
27
+
28
+ find_package(PkgConfig)
29
+ pkg_search_module(GTEST REQUIRED gtest_main)
30
+
31
+ add_executable(testapp samples/sample3_unittest.cc)
32
+ target_link_libraries(testapp ${GTEST_LDFLAGS})
33
+ target_compile_options(testapp PUBLIC ${GTEST_CFLAGS})
34
+
35
+ include(CTest)
36
+ add_test(first_and_only_test testapp)
37
+ ```
38
+
39
+ It is generally recommended that you use `target_compile_options` + `_CFLAGS`
40
+ over `target_include_directories` + `_INCLUDE_DIRS` as the former includes not
41
+ just -I flags (GoogleTest might require a macro indicating to internal headers
42
+ that all libraries have been compiled with threading enabled. In addition,
43
+ GoogleTest might also require `-pthread` in the compiling step, and as such
44
+ splitting the pkg-config `Cflags` variable into include dirs and macros for
45
+ `target_compile_definitions()` might still miss this). The same recommendation
46
+ goes for using `_LDFLAGS` over the more commonplace `_LIBRARIES`, which
47
+ happens to discard `-L` flags and `-pthread`.
48
+
49
+
50
+ ### Autotools ###
51
+
52
+ Finding GoogleTest in Autoconf and using it from Automake is also fairly easy:
53
+
54
+ In your `configure.ac`:
55
+
56
+ ```
57
+ AC_PREREQ([2.69])
58
+ AC_INIT([my_gtest_pkgconfig], [0.0.1])
59
+ AC_CONFIG_SRCDIR([samples/sample3_unittest.cc])
60
+ AC_PROG_CXX
61
+
62
+ PKG_CHECK_MODULES([GTEST], [gtest_main])
63
+
64
+ AM_INIT_AUTOMAKE([foreign subdir-objects])
65
+ AC_CONFIG_FILES([Makefile])
66
+ AC_OUTPUT
67
+ ```
68
+
69
+ and in your `Makefile.am`:
70
+
71
+ ```
72
+ check_PROGRAMS = testapp
73
+ TESTS = $(check_PROGRAMS)
74
+
75
+ testapp_SOURCES = samples/sample3_unittest.cc
76
+ testapp_CXXFLAGS = $(GTEST_CFLAGS)
77
+ testapp_LDADD = $(GTEST_LIBS)
78
+ ```
79
+
80
+
81
+ ### Meson ###
82
+
83
+ Meson natively uses pkgconfig to query dependencies:
84
+
85
+ ```
86
+ project('my_gtest_pkgconfig', 'cpp', version : '0.0.1')
87
+
88
+ gtest_dep = dependency('gtest_main')
89
+
90
+ testapp = executable(
91
+ 'testapp',
92
+ files(['samples/sample3_unittest.cc']),
93
+ dependencies : gtest_dep,
94
+ install : false)
95
+
96
+ test('first_and_only_test', testapp)
97
+ ```
98
+
99
+
100
+ ### Plain Makefiles ###
101
+
102
+ Since `pkg-config` is a small Unix command-line utility, it can be used
103
+ in handwritten `Makefile`s too:
104
+
105
+ ```
106
+ GTEST_CFLAGS = `pkg-config --cflags gtest_main`
107
+ GTEST_LIBS = `pkg-config --libs gtest_main`
108
+
109
+ .PHONY: tests all
110
+
111
+ tests: all
112
+ ./testapp
113
+
114
+ all: testapp
115
+
116
+ testapp: testapp.o
117
+ $(CXX) $(CXXFLAGS) $(LDFLAGS) $< -o $@ $(GTEST_LIBS)
118
+
119
+ testapp.o: samples/sample3_unittest.cc
120
+ $(CXX) $(CPPFLAGS) $(CXXFLAGS) $< -c -o $@ $(GTEST_CFLAGS)
121
+ ```
122
+
123
+
124
+ ### Help! pkg-config can't find GoogleTest! ###
125
+
126
+ Let's say you have a `CMakeLists.txt` along the lines of the one in this
127
+ tutorial and you try to run `cmake`. It is very possible that you get a
128
+ failure along the lines of:
129
+
130
+ ```
131
+ -- Checking for one of the modules 'gtest_main'
132
+ CMake Error at /usr/share/cmake/Modules/FindPkgConfig.cmake:640 (message):
133
+ None of the required 'gtest_main' found
134
+ ```
135
+
136
+ These failures are common if you installed GoogleTest yourself and have not
137
+ sourced it from a distro or other package manager. If so, you need to tell
138
+ pkg-config where it can find the `.pc` files containing the information.
139
+ Say you installed GoogleTest to `/usr/local`, then it might be that the
140
+ `.pc` files are installed under `/usr/local/lib64/pkgconfig`. If you set
141
+
142
+ ```
143
+ export PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig
144
+ ```
145
+
146
+ pkg-config will also try to look in `PKG_CONFIG_PATH` to find `gtest_main.pc`.
@@ -0,0 +1,177 @@
1
+
2
+
3
+ <b>P</b>ump is <b>U</b>seful for <b>M</b>eta <b>P</b>rogramming.
4
+
5
+ # The Problem #
6
+
7
+ Template and macro libraries often need to define many classes,
8
+ functions, or macros that vary only (or almost only) in the number of
9
+ arguments they take. It's a lot of repetitive, mechanical, and
10
+ error-prone work.
11
+
12
+ Variadic templates and variadic macros can alleviate the problem.
13
+ However, while both are being considered by the C++ committee, neither
14
+ is in the standard yet or widely supported by compilers. Thus they
15
+ are often not a good choice, especially when your code needs to be
16
+ portable. And their capabilities are still limited.
17
+
18
+ As a result, authors of such libraries often have to write scripts to
19
+ generate their implementation. However, our experience is that it's
20
+ tedious to write such scripts, which tend to reflect the structure of
21
+ the generated code poorly and are often hard to read and edit. For
22
+ example, a small change needed in the generated code may require some
23
+ non-intuitive, non-trivial changes in the script. This is especially
24
+ painful when experimenting with the code.
25
+
26
+ # Our Solution #
27
+
28
+ Pump (for Pump is Useful for Meta Programming, Pretty Useful for Meta
29
+ Programming, or Practical Utility for Meta Programming, whichever you
30
+ prefer) is a simple meta-programming tool for C++. The idea is that a
31
+ programmer writes a `foo.pump` file which contains C++ code plus meta
32
+ code that manipulates the C++ code. The meta code can handle
33
+ iterations over a range, nested iterations, local meta variable
34
+ definitions, simple arithmetic, and conditional expressions. You can
35
+ view it as a small Domain-Specific Language. The meta language is
36
+ designed to be non-intrusive (s.t. it won't confuse Emacs' C++ mode,
37
+ for example) and concise, making Pump code intuitive and easy to
38
+ maintain.
39
+
40
+ ## Highlights ##
41
+
42
+ * The implementation is in a single Python script and thus ultra portable: no build or installation is needed and it works cross platforms.
43
+ * Pump tries to be smart with respect to [Google's style guide](https://github.com/google/styleguide): it breaks long lines (easy to have when they are generated) at acceptable places to fit within 80 columns and indent the continuation lines correctly.
44
+ * The format is human-readable and more concise than XML.
45
+ * The format works relatively well with Emacs' C++ mode.
46
+
47
+ ## Examples ##
48
+
49
+ The following Pump code (where meta keywords start with `$`, `[[` and `]]` are meta brackets, and `$$` starts a meta comment that ends with the line):
50
+
51
+ ```
52
+ $var n = 3 $$ Defines a meta variable n.
53
+ $range i 0..n $$ Declares the range of meta iterator i (inclusive).
54
+ $for i [[
55
+ $$ Meta loop.
56
+ // Foo$i does blah for $i-ary predicates.
57
+ $range j 1..i
58
+ template <size_t N $for j [[, typename A$j]]>
59
+ class Foo$i {
60
+ $if i == 0 [[
61
+ blah a;
62
+ ]] $elif i <= 2 [[
63
+ blah b;
64
+ ]] $else [[
65
+ blah c;
66
+ ]]
67
+ };
68
+
69
+ ]]
70
+ ```
71
+
72
+ will be translated by the Pump compiler to:
73
+
74
+ ```
75
+ // Foo0 does blah for 0-ary predicates.
76
+ template <size_t N>
77
+ class Foo0 {
78
+ blah a;
79
+ };
80
+
81
+ // Foo1 does blah for 1-ary predicates.
82
+ template <size_t N, typename A1>
83
+ class Foo1 {
84
+ blah b;
85
+ };
86
+
87
+ // Foo2 does blah for 2-ary predicates.
88
+ template <size_t N, typename A1, typename A2>
89
+ class Foo2 {
90
+ blah b;
91
+ };
92
+
93
+ // Foo3 does blah for 3-ary predicates.
94
+ template <size_t N, typename A1, typename A2, typename A3>
95
+ class Foo3 {
96
+ blah c;
97
+ };
98
+ ```
99
+
100
+ In another example,
101
+
102
+ ```
103
+ $range i 1..n
104
+ Func($for i + [[a$i]]);
105
+ $$ The text between i and [[ is the separator between iterations.
106
+ ```
107
+
108
+ will generate one of the following lines (without the comments), depending on the value of `n`:
109
+
110
+ ```
111
+ Func(); // If n is 0.
112
+ Func(a1); // If n is 1.
113
+ Func(a1 + a2); // If n is 2.
114
+ Func(a1 + a2 + a3); // If n is 3.
115
+ // And so on...
116
+ ```
117
+
118
+ ## Constructs ##
119
+
120
+ We support the following meta programming constructs:
121
+
122
+ | `$var id = exp` | Defines a named constant value. `$id` is valid util the end of the current meta lexical block. |
123
+ |:----------------|:-----------------------------------------------------------------------------------------------|
124
+ | `$range id exp..exp` | Sets the range of an iteration variable, which can be reused in multiple loops later. |
125
+ | `$for id sep [[ code ]]` | Iteration. The range of `id` must have been defined earlier. `$id` is valid in `code`. |
126
+ | `$($)` | Generates a single `$` character. |
127
+ | `$id` | Value of the named constant or iteration variable. |
128
+ | `$(exp)` | Value of the expression. |
129
+ | `$if exp [[ code ]] else_branch` | Conditional. |
130
+ | `[[ code ]]` | Meta lexical block. |
131
+ | `cpp_code` | Raw C++ code. |
132
+ | `$$ comment` | Meta comment. |
133
+
134
+ **Note:** To give the user some freedom in formatting the Pump source
135
+ code, Pump ignores a new-line character if it's right after `$for foo`
136
+ or next to `[[` or `]]`. Without this rule you'll often be forced to write
137
+ very long lines to get the desired output. Therefore sometimes you may
138
+ need to insert an extra new-line in such places for a new-line to show
139
+ up in your output.
140
+
141
+ ## Grammar ##
142
+
143
+ ```
144
+ code ::= atomic_code*
145
+ atomic_code ::= $var id = exp
146
+ | $var id = [[ code ]]
147
+ | $range id exp..exp
148
+ | $for id sep [[ code ]]
149
+ | $($)
150
+ | $id
151
+ | $(exp)
152
+ | $if exp [[ code ]] else_branch
153
+ | [[ code ]]
154
+ | cpp_code
155
+ sep ::= cpp_code | empty_string
156
+ else_branch ::= $else [[ code ]]
157
+ | $elif exp [[ code ]] else_branch
158
+ | empty_string
159
+ exp ::= simple_expression_in_Python_syntax
160
+ ```
161
+
162
+ ## Code ##
163
+
164
+ You can find the source code of Pump in [scripts/pump.py](../scripts/pump.py). It is still
165
+ very unpolished and lacks automated tests, although it has been
166
+ successfully used many times. If you find a chance to use it in your
167
+ project, please let us know what you think! We also welcome help on
168
+ improving Pump.
169
+
170
+ ## Real Examples ##
171
+
172
+ You can find real-world applications of Pump in [Google Test](https://github.com/google/googletest/tree/master/googletest) and [Google Mock](https://github.com/google/googletest/tree/master/googlemock). The source file `foo.h.pump` generates `foo.h`.
173
+
174
+ ## Tips ##
175
+
176
+ * If a meta variable is followed by a letter or digit, you can separate them using `[[]]`, which inserts an empty string. For example `Foo$j[[]]Helper` generate `Foo1Helper` when `j` is 1.
177
+ * To avoid extra-long Pump source lines, you can break a line anywhere you want by inserting `[[]]` followed by a new line. Since any new-line character next to `[[` or `]]` is ignored, the generated code won't contain this new line.
@@ -0,0 +1,93 @@
1
+
2
+
3
+ This guide will explain how to use the Google Testing Framework in your Xcode projects on Mac OS X. This tutorial begins by quickly explaining what to do for experienced users. After the quick start, the guide goes provides additional explanation about each step.
4
+
5
+ # Quick Start #
6
+
7
+ Here is the quick guide for using Google Test in your Xcode project.
8
+
9
+ 1. Download the source from the [website](http://code.google.com/p/googletest) using this command: `svn checkout http://googletest.googlecode.com/svn/trunk/ googletest-read-only`.
10
+ 1. Open up the `gtest.xcodeproj` in the `googletest-read-only/xcode/` directory and build the gtest.framework.
11
+ 1. Create a new "Shell Tool" target in your Xcode project called something like "UnitTests".
12
+ 1. Add the gtest.framework to your project and add it to the "Link Binary with Libraries" build phase of "UnitTests".
13
+ 1. Add your unit test source code to the "Compile Sources" build phase of "UnitTests".
14
+ 1. Edit the "UnitTests" executable and add an environment variable named "DYLD\_FRAMEWORK\_PATH" with a value equal to the path to the framework containing the gtest.framework relative to the compiled executable.
15
+ 1. Build and Go.
16
+
17
+ The following sections further explain each of the steps listed above in depth, describing in more detail how to complete it including some variations.
18
+
19
+ # Get the Source #
20
+
21
+ Currently, the gtest.framework discussed here isn't available in a tagged release of Google Test, it is only available in the trunk. As explained at the Google Test [site](http://code.google.com/p/googletest/source/checkout">svn), you can get the code from anonymous SVN with this command:
22
+
23
+ ```
24
+ svn checkout http://googletest.googlecode.com/svn/trunk/ googletest-read-only
25
+ ```
26
+
27
+ Alternatively, if you are working with Subversion in your own code base, you can add Google Test as an external dependency to your own Subversion repository. By following this approach, everyone that checks out your svn repository will also receive a copy of Google Test (a specific version, if you wish) without having to check it out explicitly. This makes the set up of your project simpler and reduces the copied code in the repository.
28
+
29
+ To use `svn:externals`, decide where you would like to have the external source reside. You might choose to put the external source inside the trunk, because you want it to be part of the branch when you make a release. However, keeping it outside the trunk in a version-tagged directory called something like `third-party/googletest/1.0.1`, is another option. Once the location is established, use `svn propedit svn:externals _directory_` to set the svn:externals property on a directory in your repository. This directory won't contain the code, but be its versioned parent directory.
30
+
31
+ The command `svn propedit` will bring up your Subversion editor, making editing the long, (potentially multi-line) property simpler. This same method can be used to check out a tagged branch, by using the appropriate URL (e.g. `http://googletest.googlecode.com/svn/tags/release-1.0.1`). Additionally, the svn:externals property allows the specification of a particular revision of the trunk with the `-r_##_` option (e.g. `externals/src/googletest -r60 http://googletest.googlecode.com/svn/trunk`).
32
+
33
+ Here is an example of using the svn:externals properties on a trunk (read via `svn propget`) of a project. This value checks out a copy of Google Test into the `trunk/externals/src/googletest/` directory.
34
+
35
+ ```
36
+ [Computer:svn] user$ svn propget svn:externals trunk
37
+ externals/src/googletest http://googletest.googlecode.com/svn/trunk
38
+ ```
39
+
40
+ # Add the Framework to Your Project #
41
+
42
+ The next step is to build and add the gtest.framework to your own project. This guide describes two common ways below.
43
+
44
+ * **Option 1** --- The simplest way to add Google Test to your own project, is to open gtest.xcodeproj (found in the xcode/ directory of the Google Test trunk) and build the framework manually. Then, add the built framework into your project using the "Add->Existing Framework..." from the context menu or "Project->Add..." from the main menu. The gtest.framework is relocatable and contains the headers and object code that you'll need to make tests. This method requires rebuilding every time you upgrade Google Test in your project.
45
+ * **Option 2** --- If you are going to be living off the trunk of Google Test, incorporating its latest features into your unit tests (or are a Google Test developer yourself). You'll want to rebuild the framework every time the source updates. to do this, you'll need to add the gtest.xcodeproj file, not the framework itself, to your own Xcode project. Then, from the build products that are revealed by the project's disclosure triangle, you can find the gtest.framework, which can be added to your targets (discussed below).
46
+
47
+ # Make a Test Target #
48
+
49
+ To start writing tests, make a new "Shell Tool" target. This target template is available under BSD, Cocoa, or Carbon. Add your unit test source code to the "Compile Sources" build phase of the target.
50
+
51
+ Next, you'll want to add gtest.framework in two different ways, depending upon which option you chose above.
52
+
53
+ * **Option 1** --- During compilation, Xcode will need to know that you are linking against the gtest.framework. Add the gtest.framework to the "Link Binary with Libraries" build phase of your test target. This will include the Google Test headers in your header search path, and will tell the linker where to find the library.
54
+ * **Option 2** --- If your working out of the trunk, you'll also want to add gtest.framework to your "Link Binary with Libraries" build phase of your test target. In addition, you'll want to add the gtest.framework as a dependency to your unit test target. This way, Xcode will make sure that gtest.framework is up to date, every time your build your target. Finally, if you don't share build directories with Google Test, you'll have to copy the gtest.framework into your own build products directory using a "Run Script" build phase.
55
+
56
+ # Set Up the Executable Run Environment #
57
+
58
+ Since the unit test executable is a shell tool, it doesn't have a bundle with a `Contents/Frameworks` directory, in which to place gtest.framework. Instead, the dynamic linker must be told at runtime to search for the framework in another location. This can be accomplished by setting the "DYLD\_FRAMEWORK\_PATH" environment variable in the "Edit Active Executable ..." Arguments tab, under "Variables to be set in the environment:". The path for this value is the path (relative or absolute) of the directory containing the gtest.framework.
59
+
60
+ If you haven't set up the DYLD\_FRAMEWORK\_PATH, correctly, you might get a message like this:
61
+
62
+ ```
63
+ [Session started at 2008-08-15 06:23:57 -0600.]
64
+ dyld: Library not loaded: @loader_path/../Frameworks/gtest.framework/Versions/A/gtest
65
+ Referenced from: /Users/username/Documents/Sandbox/gtestSample/build/Debug/WidgetFrameworkTest
66
+ Reason: image not found
67
+ ```
68
+
69
+ To correct this problem, go to to the directory containing the executable named in "Referenced from:" value in the error message above. Then, with the terminal in this location, find the relative path to the directory containing the gtest.framework. That is the value you'll need to set as the DYLD\_FRAMEWORK\_PATH.
70
+
71
+ # Build and Go #
72
+
73
+ Now, when you click "Build and Go", the test will be executed. Dumping out something like this:
74
+
75
+ ```
76
+ [Session started at 2008-08-06 06:36:13 -0600.]
77
+ [==========] Running 2 tests from 1 test case.
78
+ [----------] Global test environment set-up.
79
+ [----------] 2 tests from WidgetInitializerTest
80
+ [ RUN ] WidgetInitializerTest.TestConstructor
81
+ [ OK ] WidgetInitializerTest.TestConstructor
82
+ [ RUN ] WidgetInitializerTest.TestConversion
83
+ [ OK ] WidgetInitializerTest.TestConversion
84
+ [----------] Global test environment tear-down
85
+ [==========] 2 tests from 1 test case ran.
86
+ [ PASSED ] 2 tests.
87
+
88
+ The Debugger has exited with status 0.
89
+ ```
90
+
91
+ # Summary #
92
+
93
+ Unit testing is a valuable way to ensure your data model stays valid even during rapid development or refactoring. The Google Testing Framework is a great unit testing framework for C and C++ which integrates well with an Xcode development environment.
@@ -0,0 +1,2416 @@
1
+
2
+
3
+ Now that you have read [Primer](primer.md) and learned how to write tests
4
+ using Google Test, it's time to learn some new tricks. This document
5
+ will show you more assertions as well as how to construct complex
6
+ failure messages, propagate fatal failures, reuse and speed up your
7
+ test fixtures, and use various flags with your tests.
8
+
9
+ # More Assertions #
10
+
11
+ This section covers some less frequently used, but still significant,
12
+ assertions.
13
+
14
+ ## Explicit Success and Failure ##
15
+
16
+ These three assertions do not actually test a value or expression. Instead,
17
+ they generate a success or failure directly. Like the macros that actually
18
+ perform a test, you may stream a custom failure message into them.
19
+
20
+ | `SUCCEED();` |
21
+ |:-------------|
22
+
23
+ Generates a success. This does NOT make the overall test succeed. A test is
24
+ considered successful only if none of its assertions fail during its execution.
25
+
26
+ Note: `SUCCEED()` is purely documentary and currently doesn't generate any
27
+ user-visible output. However, we may add `SUCCEED()` messages to Google Test's
28
+ output in the future.
29
+
30
+ | `FAIL();` | `ADD_FAILURE();` | `ADD_FAILURE_AT("`_file\_path_`", `_line\_number_`);` |
31
+ |:-----------|:-----------------|:------------------------------------------------------|
32
+
33
+ `FAIL()` generates a fatal failure, while `ADD_FAILURE()` and `ADD_FAILURE_AT()` generate a nonfatal
34
+ failure. These are useful when control flow, rather than a Boolean expression,
35
+ determines the test's success or failure. For example, you might want to write
36
+ something like:
37
+
38
+ ```
39
+ switch(expression) {
40
+ case 1: ... some checks ...
41
+ case 2: ... some other checks
42
+ ...
43
+ default: FAIL() << "We shouldn't get here.";
44
+ }
45
+ ```
46
+
47
+ Note: you can only use `FAIL()` in functions that return `void`. See the [Assertion Placement section](#assertion-placement) for more information.
48
+
49
+ _Availability_: Linux, Windows, Mac.
50
+
51
+ ## Exception Assertions ##
52
+
53
+ These are for verifying that a piece of code throws (or does not
54
+ throw) an exception of the given type:
55
+
56
+ | **Fatal assertion** | **Nonfatal assertion** | **Verifies** |
57
+ |:--------------------|:-----------------------|:-------------|
58
+ | `ASSERT_THROW(`_statement_, _exception\_type_`);` | `EXPECT_THROW(`_statement_, _exception\_type_`);` | _statement_ throws an exception of the given type |
59
+ | `ASSERT_ANY_THROW(`_statement_`);` | `EXPECT_ANY_THROW(`_statement_`);` | _statement_ throws an exception of any type |
60
+ | `ASSERT_NO_THROW(`_statement_`);` | `EXPECT_NO_THROW(`_statement_`);` | _statement_ doesn't throw any exception |
61
+
62
+ Examples:
63
+
64
+ ```
65
+ ASSERT_THROW(Foo(5), bar_exception);
66
+
67
+ EXPECT_NO_THROW({
68
+ int n = 5;
69
+ Bar(&n);
70
+ });
71
+ ```
72
+
73
+ _Availability_: Linux, Windows, Mac; since version 1.1.0.
74
+
75
+ ## Predicate Assertions for Better Error Messages ##
76
+
77
+ Even though Google Test has a rich set of assertions, they can never be
78
+ complete, as it's impossible (nor a good idea) to anticipate all the scenarios
79
+ a user might run into. Therefore, sometimes a user has to use `EXPECT_TRUE()`
80
+ to check a complex expression, for lack of a better macro. This has the problem
81
+ of not showing you the values of the parts of the expression, making it hard to
82
+ understand what went wrong. As a workaround, some users choose to construct the
83
+ failure message by themselves, streaming it into `EXPECT_TRUE()`. However, this
84
+ is awkward especially when the expression has side-effects or is expensive to
85
+ evaluate.
86
+
87
+ Google Test gives you three different options to solve this problem:
88
+
89
+ ### Using an Existing Boolean Function ###
90
+
91
+ If you already have a function or a functor that returns `bool` (or a type
92
+ that can be implicitly converted to `bool`), you can use it in a _predicate
93
+ assertion_ to get the function arguments printed for free:
94
+
95
+ | **Fatal assertion** | **Nonfatal assertion** | **Verifies** |
96
+ |:--------------------|:-----------------------|:-------------|
97
+ | `ASSERT_PRED1(`_pred1, val1_`);` | `EXPECT_PRED1(`_pred1, val1_`);` | _pred1(val1)_ returns true |
98
+ | `ASSERT_PRED2(`_pred2, val1, val2_`);` | `EXPECT_PRED2(`_pred2, val1, val2_`);` | _pred2(val1, val2)_ returns true |
99
+ | ... | ... | ... |
100
+
101
+ In the above, _predn_ is an _n_-ary predicate function or functor, where
102
+ _val1_, _val2_, ..., and _valn_ are its arguments. The assertion succeeds
103
+ if the predicate returns `true` when applied to the given arguments, and fails
104
+ otherwise. When the assertion fails, it prints the value of each argument. In
105
+ either case, the arguments are evaluated exactly once.
106
+
107
+ Here's an example. Given
108
+
109
+ ```
110
+ // Returns true iff m and n have no common divisors except 1.
111
+ bool MutuallyPrime(int m, int n) { ... }
112
+ const int a = 3;
113
+ const int b = 4;
114
+ const int c = 10;
115
+ ```
116
+
117
+ the assertion `EXPECT_PRED2(MutuallyPrime, a, b);` will succeed, while the
118
+ assertion `EXPECT_PRED2(MutuallyPrime, b, c);` will fail with the message
119
+
120
+ <pre>
121
+ !MutuallyPrime(b, c) is false, where<br>
122
+ b is 4<br>
123
+ c is 10<br>
124
+ </pre>
125
+
126
+ **Notes:**
127
+
128
+ 1. If you see a compiler error "no matching function to call" when using `ASSERT_PRED*` or `EXPECT_PRED*`, please see [this FAQ](faq.md#the-compiler-complains-no-matching-function-to-call-when-i-use-assert_predn-how-do-i-fix-it) for how to resolve it.
129
+ 1. Currently we only provide predicate assertions of arity <= 5. If you need a higher-arity assertion, let us know.
130
+
131
+ _Availability_: Linux, Windows, Mac.
132
+
133
+ ### Using a Function That Returns an AssertionResult ###
134
+
135
+ While `EXPECT_PRED*()` and friends are handy for a quick job, the
136
+ syntax is not satisfactory: you have to use different macros for
137
+ different arities, and it feels more like Lisp than C++. The
138
+ `::testing::AssertionResult` class solves this problem.
139
+
140
+ An `AssertionResult` object represents the result of an assertion
141
+ (whether it's a success or a failure, and an associated message). You
142
+ can create an `AssertionResult` using one of these factory
143
+ functions:
144
+
145
+ ```
146
+ namespace testing {
147
+
148
+ // Returns an AssertionResult object to indicate that an assertion has
149
+ // succeeded.
150
+ AssertionResult AssertionSuccess();
151
+
152
+ // Returns an AssertionResult object to indicate that an assertion has
153
+ // failed.
154
+ AssertionResult AssertionFailure();
155
+
156
+ }
157
+ ```
158
+
159
+ You can then use the `<<` operator to stream messages to the
160
+ `AssertionResult` object.
161
+
162
+ To provide more readable messages in Boolean assertions
163
+ (e.g. `EXPECT_TRUE()`), write a predicate function that returns
164
+ `AssertionResult` instead of `bool`. For example, if you define
165
+ `IsEven()` as:
166
+
167
+ ```
168
+ ::testing::AssertionResult IsEven(int n) {
169
+ if ((n % 2) == 0)
170
+ return ::testing::AssertionSuccess();
171
+ else
172
+ return ::testing::AssertionFailure() << n << " is odd";
173
+ }
174
+ ```
175
+
176
+ instead of:
177
+
178
+ ```
179
+ bool IsEven(int n) {
180
+ return (n % 2) == 0;
181
+ }
182
+ ```
183
+
184
+ the failed assertion `EXPECT_TRUE(IsEven(Fib(4)))` will print:
185
+
186
+ <pre>
187
+ Value of: IsEven(Fib(4))<br>
188
+ Actual: false (*3 is odd*)<br>
189
+ Expected: true<br>
190
+ </pre>
191
+
192
+ instead of a more opaque
193
+
194
+ <pre>
195
+ Value of: IsEven(Fib(4))<br>
196
+ Actual: false<br>
197
+ Expected: true<br>
198
+ </pre>
199
+
200
+ If you want informative messages in `EXPECT_FALSE` and `ASSERT_FALSE`
201
+ as well, and are fine with making the predicate slower in the success
202
+ case, you can supply a success message:
203
+
204
+ ```
205
+ ::testing::AssertionResult IsEven(int n) {
206
+ if ((n % 2) == 0)
207
+ return ::testing::AssertionSuccess() << n << " is even";
208
+ else
209
+ return ::testing::AssertionFailure() << n << " is odd";
210
+ }
211
+ ```
212
+
213
+ Then the statement `EXPECT_FALSE(IsEven(Fib(6)))` will print
214
+
215
+ <pre>
216
+ Value of: IsEven(Fib(6))<br>
217
+ Actual: true (8 is even)<br>
218
+ Expected: false<br>
219
+ </pre>
220
+
221
+ _Availability_: Linux, Windows, Mac; since version 1.4.1.
222
+
223
+ ### Using a Predicate-Formatter ###
224
+
225
+ If you find the default message generated by `(ASSERT|EXPECT)_PRED*` and
226
+ `(ASSERT|EXPECT)_(TRUE|FALSE)` unsatisfactory, or some arguments to your
227
+ predicate do not support streaming to `ostream`, you can instead use the
228
+ following _predicate-formatter assertions_ to _fully_ customize how the
229
+ message is formatted:
230
+
231
+ | **Fatal assertion** | **Nonfatal assertion** | **Verifies** |
232
+ |:--------------------|:-----------------------|:-------------|
233
+ | `ASSERT_PRED_FORMAT1(`_pred\_format1, val1_`);` | `EXPECT_PRED_FORMAT1(`_pred\_format1, val1_`);` | _pred\_format1(val1)_ is successful |
234
+ | `ASSERT_PRED_FORMAT2(`_pred\_format2, val1, val2_`);` | `EXPECT_PRED_FORMAT2(`_pred\_format2, val1, val2_`);` | _pred\_format2(val1, val2)_ is successful |
235
+ | `...` | `...` | `...` |
236
+
237
+ The difference between this and the previous two groups of macros is that instead of
238
+ a predicate, `(ASSERT|EXPECT)_PRED_FORMAT*` take a _predicate-formatter_
239
+ (_pred\_formatn_), which is a function or functor with the signature:
240
+
241
+ `::testing::AssertionResult PredicateFormattern(const char* `_expr1_`, const char* `_expr2_`, ... const char* `_exprn_`, T1 `_val1_`, T2 `_val2_`, ... Tn `_valn_`);`
242
+
243
+ where _val1_, _val2_, ..., and _valn_ are the values of the predicate
244
+ arguments, and _expr1_, _expr2_, ..., and _exprn_ are the corresponding
245
+ expressions as they appear in the source code. The types `T1`, `T2`, ..., and
246
+ `Tn` can be either value types or reference types. For example, if an
247
+ argument has type `Foo`, you can declare it as either `Foo` or `const Foo&`,
248
+ whichever is appropriate.
249
+
250
+ A predicate-formatter returns a `::testing::AssertionResult` object to indicate
251
+ whether the assertion has succeeded or not. The only way to create such an
252
+ object is to call one of these factory functions:
253
+
254
+ As an example, let's improve the failure message in the previous example, which uses `EXPECT_PRED2()`:
255
+
256
+ ```
257
+ // Returns the smallest prime common divisor of m and n,
258
+ // or 1 when m and n are mutually prime.
259
+ int SmallestPrimeCommonDivisor(int m, int n) { ... }
260
+
261
+ // A predicate-formatter for asserting that two integers are mutually prime.
262
+ ::testing::AssertionResult AssertMutuallyPrime(const char* m_expr,
263
+ const char* n_expr,
264
+ int m,
265
+ int n) {
266
+ if (MutuallyPrime(m, n))
267
+ return ::testing::AssertionSuccess();
268
+
269
+ return ::testing::AssertionFailure()
270
+ << m_expr << " and " << n_expr << " (" << m << " and " << n
271
+ << ") are not mutually prime, " << "as they have a common divisor "
272
+ << SmallestPrimeCommonDivisor(m, n);
273
+ }
274
+ ```
275
+
276
+ With this predicate-formatter, we can use
277
+
278
+ ```
279
+ EXPECT_PRED_FORMAT2(AssertMutuallyPrime, b, c);
280
+ ```
281
+
282
+ to generate the message
283
+
284
+ <pre>
285
+ b and c (4 and 10) are not mutually prime, as they have a common divisor 2.<br>
286
+ </pre>
287
+
288
+ As you may have realized, many of the assertions we introduced earlier are
289
+ special cases of `(EXPECT|ASSERT)_PRED_FORMAT*`. In fact, most of them are
290
+ indeed defined using `(EXPECT|ASSERT)_PRED_FORMAT*`.
291
+
292
+ _Availability_: Linux, Windows, Mac.
293
+
294
+
295
+ ## Floating-Point Comparison ##
296
+
297
+ Comparing floating-point numbers is tricky. Due to round-off errors, it is
298
+ very unlikely that two floating-points will match exactly. Therefore,
299
+ `ASSERT_EQ` 's naive comparison usually doesn't work. And since floating-points
300
+ can have a wide value range, no single fixed error bound works. It's better to
301
+ compare by a fixed relative error bound, except for values close to 0 due to
302
+ the loss of precision there.
303
+
304
+ In general, for floating-point comparison to make sense, the user needs to
305
+ carefully choose the error bound. If they don't want or care to, comparing in
306
+ terms of Units in the Last Place (ULPs) is a good default, and Google Test
307
+ provides assertions to do this. Full details about ULPs are quite long; if you
308
+ want to learn more, see
309
+ [this article on float comparison](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/).
310
+
311
+ ### Floating-Point Macros ###
312
+
313
+ | **Fatal assertion** | **Nonfatal assertion** | **Verifies** |
314
+ |:--------------------|:-----------------------|:-------------|
315
+ | `ASSERT_FLOAT_EQ(`_val1, val2_`);` | `EXPECT_FLOAT_EQ(`_val1, val2_`);` | the two `float` values are almost equal |
316
+ | `ASSERT_DOUBLE_EQ(`_val1, val2_`);` | `EXPECT_DOUBLE_EQ(`_val1, val2_`);` | the two `double` values are almost equal |
317
+
318
+ By "almost equal", we mean the two values are within 4 ULP's from each
319
+ other.
320
+
321
+ The following assertions allow you to choose the acceptable error bound:
322
+
323
+ | **Fatal assertion** | **Nonfatal assertion** | **Verifies** |
324
+ |:--------------------|:-----------------------|:-------------|
325
+ | `ASSERT_NEAR(`_val1, val2, abs\_error_`);` | `EXPECT_NEAR`_(val1, val2, abs\_error_`);` | the difference between _val1_ and _val2_ doesn't exceed the given absolute error |
326
+
327
+ _Availability_: Linux, Windows, Mac.
328
+
329
+ ### Floating-Point Predicate-Format Functions ###
330
+
331
+ Some floating-point operations are useful, but not that often used. In order
332
+ to avoid an explosion of new macros, we provide them as predicate-format
333
+ functions that can be used in predicate assertion macros (e.g.
334
+ `EXPECT_PRED_FORMAT2`, etc).
335
+
336
+ ```
337
+ EXPECT_PRED_FORMAT2(::testing::FloatLE, val1, val2);
338
+ EXPECT_PRED_FORMAT2(::testing::DoubleLE, val1, val2);
339
+ ```
340
+
341
+ Verifies that _val1_ is less than, or almost equal to, _val2_. You can
342
+ replace `EXPECT_PRED_FORMAT2` in the above table with `ASSERT_PRED_FORMAT2`.
343
+
344
+ _Availability_: Linux, Windows, Mac.
345
+
346
+ ## Windows HRESULT assertions ##
347
+
348
+ These assertions test for `HRESULT` success or failure.
349
+
350
+ | **Fatal assertion** | **Nonfatal assertion** | **Verifies** |
351
+ |:--------------------|:-----------------------|:-------------|
352
+ | `ASSERT_HRESULT_SUCCEEDED(`_expression_`);` | `EXPECT_HRESULT_SUCCEEDED(`_expression_`);` | _expression_ is a success `HRESULT` |
353
+ | `ASSERT_HRESULT_FAILED(`_expression_`);` | `EXPECT_HRESULT_FAILED(`_expression_`);` | _expression_ is a failure `HRESULT` |
354
+
355
+ The generated output contains the human-readable error message
356
+ associated with the `HRESULT` code returned by _expression_.
357
+
358
+ You might use them like this:
359
+
360
+ ```
361
+ CComPtr shell;
362
+ ASSERT_HRESULT_SUCCEEDED(shell.CoCreateInstance(L"Shell.Application"));
363
+ CComVariant empty;
364
+ ASSERT_HRESULT_SUCCEEDED(shell->ShellExecute(CComBSTR(url), empty, empty, empty, empty));
365
+ ```
366
+
367
+ _Availability_: Windows.
368
+
369
+ ## Type Assertions ##
370
+
371
+ You can call the function
372
+ ```
373
+ ::testing::StaticAssertTypeEq<T1, T2>();
374
+ ```
375
+ to assert that types `T1` and `T2` are the same. The function does
376
+ nothing if the assertion is satisfied. If the types are different,
377
+ the function call will fail to compile, and the compiler error message
378
+ will likely (depending on the compiler) show you the actual values of
379
+ `T1` and `T2`. This is mainly useful inside template code.
380
+
381
+ _Caveat:_ When used inside a member function of a class template or a
382
+ function template, `StaticAssertTypeEq<T1, T2>()` is effective _only if_
383
+ the function is instantiated. For example, given:
384
+ ```
385
+ template <typename T> class Foo {
386
+ public:
387
+ void Bar() { ::testing::StaticAssertTypeEq<int, T>(); }
388
+ };
389
+ ```
390
+ the code:
391
+ ```
392
+ void Test1() { Foo<bool> foo; }
393
+ ```
394
+ will _not_ generate a compiler error, as `Foo<bool>::Bar()` is never
395
+ actually instantiated. Instead, you need:
396
+ ```
397
+ void Test2() { Foo<bool> foo; foo.Bar(); }
398
+ ```
399
+ to cause a compiler error.
400
+
401
+ _Availability:_ Linux, Windows, Mac; since version 1.3.0.
402
+
403
+ ## Assertion Placement ##
404
+
405
+ You can use assertions in any C++ function. In particular, it doesn't
406
+ have to be a method of the test fixture class. The one constraint is
407
+ that assertions that generate a fatal failure (`FAIL*` and `ASSERT_*`)
408
+ can only be used in void-returning functions. This is a consequence of
409
+ Google Test not using exceptions. By placing it in a non-void function
410
+ you'll get a confusing compile error like
411
+ `"error: void value not ignored as it ought to be"`.
412
+
413
+ If you need to use assertions in a function that returns non-void, one option
414
+ is to make the function return the value in an out parameter instead. For
415
+ example, you can rewrite `T2 Foo(T1 x)` to `void Foo(T1 x, T2* result)`. You
416
+ need to make sure that `*result` contains some sensible value even when the
417
+ function returns prematurely. As the function now returns `void`, you can use
418
+ any assertion inside of it.
419
+
420
+ If changing the function's type is not an option, you should just use
421
+ assertions that generate non-fatal failures, such as `ADD_FAILURE*` and
422
+ `EXPECT_*`.
423
+
424
+ _Note_: Constructors and destructors are not considered void-returning
425
+ functions, according to the C++ language specification, and so you may not use
426
+ fatal assertions in them. You'll get a compilation error if you try. A simple
427
+ workaround is to transfer the entire body of the constructor or destructor to a
428
+ private void-returning method. However, you should be aware that a fatal
429
+ assertion failure in a constructor does not terminate the current test, as your
430
+ intuition might suggest; it merely returns from the constructor early, possibly
431
+ leaving your object in a partially-constructed state. Likewise, a fatal
432
+ assertion failure in a destructor may leave your object in a
433
+ partially-destructed state. Use assertions carefully in these situations!
434
+
435
+ # Teaching Google Test How to Print Your Values #
436
+
437
+ When a test assertion such as `EXPECT_EQ` fails, Google Test prints the
438
+ argument values to help you debug. It does this using a
439
+ user-extensible value printer.
440
+
441
+ This printer knows how to print built-in C++ types, native arrays, STL
442
+ containers, and any type that supports the `<<` operator. For other
443
+ types, it prints the raw bytes in the value and hopes that you the
444
+ user can figure it out.
445
+
446
+ As mentioned earlier, the printer is _extensible_. That means
447
+ you can teach it to do a better job at printing your particular type
448
+ than to dump the bytes. To do that, define `<<` for your type:
449
+
450
+ ```
451
+ #include <iostream>
452
+
453
+ namespace foo {
454
+
455
+ class Bar { ... }; // We want Google Test to be able to print instances of this.
456
+
457
+ // It's important that the << operator is defined in the SAME
458
+ // namespace that defines Bar. C++'s look-up rules rely on that.
459
+ ::std::ostream& operator<<(::std::ostream& os, const Bar& bar) {
460
+ return os << bar.DebugString(); // whatever needed to print bar to os
461
+ }
462
+
463
+ } // namespace foo
464
+ ```
465
+
466
+ Sometimes, this might not be an option: your team may consider it bad
467
+ style to have a `<<` operator for `Bar`, or `Bar` may already have a
468
+ `<<` operator that doesn't do what you want (and you cannot change
469
+ it). If so, you can instead define a `PrintTo()` function like this:
470
+
471
+ ```
472
+ #include <iostream>
473
+
474
+ namespace foo {
475
+
476
+ class Bar { ... };
477
+
478
+ // It's important that PrintTo() is defined in the SAME
479
+ // namespace that defines Bar. C++'s look-up rules rely on that.
480
+ void PrintTo(const Bar& bar, ::std::ostream* os) {
481
+ *os << bar.DebugString(); // whatever needed to print bar to os
482
+ }
483
+
484
+ } // namespace foo
485
+ ```
486
+
487
+ If you have defined both `<<` and `PrintTo()`, the latter will be used
488
+ when Google Test is concerned. This allows you to customize how the value
489
+ appears in Google Test's output without affecting code that relies on the
490
+ behavior of its `<<` operator.
491
+
492
+ If you want to print a value `x` using Google Test's value printer
493
+ yourself, just call `::testing::PrintToString(`_x_`)`, which
494
+ returns an `std::string`:
495
+
496
+ ```
497
+ vector<pair<Bar, int> > bar_ints = GetBarIntVector();
498
+
499
+ EXPECT_TRUE(IsCorrectBarIntVector(bar_ints))
500
+ << "bar_ints = " << ::testing::PrintToString(bar_ints);
501
+ ```
502
+
503
+ # Death Tests #
504
+
505
+ In many applications, there are assertions that can cause application failure
506
+ if a condition is not met. These sanity checks, which ensure that the program
507
+ is in a known good state, are there to fail at the earliest possible time after
508
+ some program state is corrupted. If the assertion checks the wrong condition,
509
+ then the program may proceed in an erroneous state, which could lead to memory
510
+ corruption, security holes, or worse. Hence it is vitally important to test
511
+ that such assertion statements work as expected.
512
+
513
+ Since these precondition checks cause the processes to die, we call such tests
514
+ _death tests_. More generally, any test that checks that a program terminates
515
+ (except by throwing an exception) in an expected fashion is also a death test.
516
+
517
+ Note that if a piece of code throws an exception, we don't consider it "death"
518
+ for the purpose of death tests, as the caller of the code could catch the exception
519
+ and avoid the crash. If you want to verify exceptions thrown by your code,
520
+ see [Exception Assertions](#exception-assertions).
521
+
522
+ If you want to test `EXPECT_*()/ASSERT_*()` failures in your test code, see [Catching Failures](#catching-failures).
523
+
524
+ ## How to Write a Death Test ##
525
+
526
+ Google Test has the following macros to support death tests:
527
+
528
+ | **Fatal assertion** | **Nonfatal assertion** | **Verifies** |
529
+ |:--------------------|:-----------------------|:-------------|
530
+ | `ASSERT_DEATH(`_statement, regex_`);` | `EXPECT_DEATH(`_statement, regex_`);` | _statement_ crashes with the given error |
531
+ | `ASSERT_DEATH_IF_SUPPORTED(`_statement, regex_`);` | `EXPECT_DEATH_IF_SUPPORTED(`_statement, regex_`);` | if death tests are supported, verifies that _statement_ crashes with the given error; otherwise verifies nothing |
532
+ | `ASSERT_EXIT(`_statement, predicate, regex_`);` | `EXPECT_EXIT(`_statement, predicate, regex_`);` |_statement_ exits with the given error and its exit code matches _predicate_ |
533
+
534
+ where _statement_ is a statement that is expected to cause the process to
535
+ die, _predicate_ is a function or function object that evaluates an integer
536
+ exit status, and _regex_ is a regular expression that the stderr output of
537
+ _statement_ is expected to match. Note that _statement_ can be _any valid
538
+ statement_ (including _compound statement_) and doesn't have to be an
539
+ expression.
540
+
541
+ As usual, the `ASSERT` variants abort the current test function, while the
542
+ `EXPECT` variants do not.
543
+
544
+ **Note:** We use the word "crash" here to mean that the process
545
+ terminates with a _non-zero_ exit status code. There are two
546
+ possibilities: either the process has called `exit()` or `_exit()`
547
+ with a non-zero value, or it may be killed by a signal.
548
+
549
+ This means that if _statement_ terminates the process with a 0 exit
550
+ code, it is _not_ considered a crash by `EXPECT_DEATH`. Use
551
+ `EXPECT_EXIT` instead if this is the case, or if you want to restrict
552
+ the exit code more precisely.
553
+
554
+ A predicate here must accept an `int` and return a `bool`. The death test
555
+ succeeds only if the predicate returns `true`. Google Test defines a few
556
+ predicates that handle the most common cases:
557
+
558
+ ```
559
+ ::testing::ExitedWithCode(exit_code)
560
+ ```
561
+
562
+ This expression is `true` if the program exited normally with the given exit
563
+ code.
564
+
565
+ ```
566
+ ::testing::KilledBySignal(signal_number) // Not available on Windows.
567
+ ```
568
+
569
+ This expression is `true` if the program was killed by the given signal.
570
+
571
+ The `*_DEATH` macros are convenient wrappers for `*_EXIT` that use a predicate
572
+ that verifies the process' exit code is non-zero.
573
+
574
+ Note that a death test only cares about three things:
575
+
576
+ 1. does _statement_ abort or exit the process?
577
+ 1. (in the case of `ASSERT_EXIT` and `EXPECT_EXIT`) does the exit status satisfy _predicate_? Or (in the case of `ASSERT_DEATH` and `EXPECT_DEATH`) is the exit status non-zero? And
578
+ 1. does the stderr output match _regex_?
579
+
580
+ In particular, if _statement_ generates an `ASSERT_*` or `EXPECT_*` failure, it will **not** cause the death test to fail, as Google Test assertions don't abort the process.
581
+
582
+ To write a death test, simply use one of the above macros inside your test
583
+ function. For example,
584
+
585
+ ```
586
+ TEST(MyDeathTest, Foo) {
587
+ // This death test uses a compound statement.
588
+ ASSERT_DEATH({ int n = 5; Foo(&n); }, "Error on line .* of Foo()");
589
+ }
590
+ TEST(MyDeathTest, NormalExit) {
591
+ EXPECT_EXIT(NormalExit(), ::testing::ExitedWithCode(0), "Success");
592
+ }
593
+ TEST(MyDeathTest, KillMyself) {
594
+ EXPECT_EXIT(KillMyself(), ::testing::KilledBySignal(SIGKILL), "Sending myself unblockable signal");
595
+ }
596
+ ```
597
+
598
+ verifies that:
599
+
600
+ * calling `Foo(5)` causes the process to die with the given error message,
601
+ * calling `NormalExit()` causes the process to print `"Success"` to stderr and exit with exit code 0, and
602
+ * calling `KillMyself()` kills the process with signal `SIGKILL`.
603
+
604
+ The test function body may contain other assertions and statements as well, if
605
+ necessary.
606
+
607
+ _Important:_ We strongly recommend you to follow the convention of naming your
608
+ test case (not test) `*DeathTest` when it contains a death test, as
609
+ demonstrated in the above example. The `Death Tests And Threads` section below
610
+ explains why.
611
+
612
+ If a test fixture class is shared by normal tests and death tests, you
613
+ can use typedef to introduce an alias for the fixture class and avoid
614
+ duplicating its code:
615
+ ```
616
+ class FooTest : public ::testing::Test { ... };
617
+
618
+ typedef FooTest FooDeathTest;
619
+
620
+ TEST_F(FooTest, DoesThis) {
621
+ // normal test
622
+ }
623
+
624
+ TEST_F(FooDeathTest, DoesThat) {
625
+ // death test
626
+ }
627
+ ```
628
+
629
+ _Availability:_ Linux, Windows (requires MSVC 8.0 or above), Cygwin, and Mac (the latter three are supported since v1.3.0). `(ASSERT|EXPECT)_DEATH_IF_SUPPORTED` are new in v1.4.0.
630
+
631
+ ## Regular Expression Syntax ##
632
+
633
+ On POSIX systems (e.g. Linux, Cygwin, and Mac), Google Test uses the
634
+ [POSIX extended regular expression](http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap09.html#tag_09_04)
635
+ syntax in death tests. To learn about this syntax, you may want to read this [Wikipedia entry](http://en.wikipedia.org/wiki/Regular_expression#POSIX_Extended_Regular_Expressions).
636
+
637
+ On Windows, Google Test uses its own simple regular expression
638
+ implementation. It lacks many features you can find in POSIX extended
639
+ regular expressions. For example, we don't support union (`"x|y"`),
640
+ grouping (`"(xy)"`), brackets (`"[xy]"`), and repetition count
641
+ (`"x{5,7}"`), among others. Below is what we do support (Letter `A` denotes a
642
+ literal character, period (`.`), or a single `\\` escape sequence; `x`
643
+ and `y` denote regular expressions.):
644
+
645
+ | `c` | matches any literal character `c` |
646
+ |:----|:----------------------------------|
647
+ | `\\d` | matches any decimal digit |
648
+ | `\\D` | matches any character that's not a decimal digit |
649
+ | `\\f` | matches `\f` |
650
+ | `\\n` | matches `\n` |
651
+ | `\\r` | matches `\r` |
652
+ | `\\s` | matches any ASCII whitespace, including `\n` |
653
+ | `\\S` | matches any character that's not a whitespace |
654
+ | `\\t` | matches `\t` |
655
+ | `\\v` | matches `\v` |
656
+ | `\\w` | matches any letter, `_`, or decimal digit |
657
+ | `\\W` | matches any character that `\\w` doesn't match |
658
+ | `\\c` | matches any literal character `c`, which must be a punctuation |
659
+ | `\\.` | matches the `.` character |
660
+ | `.` | matches any single character except `\n` |
661
+ | `A?` | matches 0 or 1 occurrences of `A` |
662
+ | `A*` | matches 0 or many occurrences of `A` |
663
+ | `A+` | matches 1 or many occurrences of `A` |
664
+ | `^` | matches the beginning of a string (not that of each line) |
665
+ | `$` | matches the end of a string (not that of each line) |
666
+ | `xy` | matches `x` followed by `y` |
667
+
668
+ To help you determine which capability is available on your system,
669
+ Google Test defines macro `GTEST_USES_POSIX_RE=1` when it uses POSIX
670
+ extended regular expressions, or `GTEST_USES_SIMPLE_RE=1` when it uses
671
+ the simple version. If you want your death tests to work in both
672
+ cases, you can either `#if` on these macros or use the more limited
673
+ syntax only.
674
+
675
+ ## How It Works ##
676
+
677
+ Under the hood, `ASSERT_EXIT()` spawns a new process and executes the
678
+ death test statement in that process. The details of how precisely
679
+ that happens depend on the platform and the variable
680
+ `::testing::GTEST_FLAG(death_test_style)` (which is initialized from the
681
+ command-line flag `--gtest_death_test_style`).
682
+
683
+ * On POSIX systems, `fork()` (or `clone()` on Linux) is used to spawn the child, after which:
684
+ * If the variable's value is `"fast"`, the death test statement is immediately executed.
685
+ * If the variable's value is `"threadsafe"`, the child process re-executes the unit test binary just as it was originally invoked, but with some extra flags to cause just the single death test under consideration to be run.
686
+ * On Windows, the child is spawned using the `CreateProcess()` API, and re-executes the binary to cause just the single death test under consideration to be run - much like the `threadsafe` mode on POSIX.
687
+
688
+ Other values for the variable are illegal and will cause the death test to
689
+ fail. Currently, the flag's default value is `"fast"`. However, we reserve the
690
+ right to change it in the future. Therefore, your tests should not depend on
691
+ this.
692
+
693
+ In either case, the parent process waits for the child process to complete, and checks that
694
+
695
+ 1. the child's exit status satisfies the predicate, and
696
+ 1. the child's stderr matches the regular expression.
697
+
698
+ If the death test statement runs to completion without dying, the child
699
+ process will nonetheless terminate, and the assertion fails.
700
+
701
+ ## Death Tests And Threads ##
702
+
703
+ The reason for the two death test styles has to do with thread safety. Due to
704
+ well-known problems with forking in the presence of threads, death tests should
705
+ be run in a single-threaded context. Sometimes, however, it isn't feasible to
706
+ arrange that kind of environment. For example, statically-initialized modules
707
+ may start threads before main is ever reached. Once threads have been created,
708
+ it may be difficult or impossible to clean them up.
709
+
710
+ Google Test has three features intended to raise awareness of threading issues.
711
+
712
+ 1. A warning is emitted if multiple threads are running when a death test is encountered.
713
+ 1. Test cases with a name ending in "DeathTest" are run before all other tests.
714
+ 1. It uses `clone()` instead of `fork()` to spawn the child process on Linux (`clone()` is not available on Cygwin and Mac), as `fork()` is more likely to cause the child to hang when the parent process has multiple threads.
715
+
716
+ It's perfectly fine to create threads inside a death test statement; they are
717
+ executed in a separate process and cannot affect the parent.
718
+
719
+ ## Death Test Styles ##
720
+
721
+ The "threadsafe" death test style was introduced in order to help mitigate the
722
+ risks of testing in a possibly multithreaded environment. It trades increased
723
+ test execution time (potentially dramatically so) for improved thread safety.
724
+ We suggest using the faster, default "fast" style unless your test has specific
725
+ problems with it.
726
+
727
+ You can choose a particular style of death tests by setting the flag
728
+ programmatically:
729
+
730
+ ```
731
+ ::testing::FLAGS_gtest_death_test_style = "threadsafe";
732
+ ```
733
+
734
+ You can do this in `main()` to set the style for all death tests in the
735
+ binary, or in individual tests. Recall that flags are saved before running each
736
+ test and restored afterwards, so you need not do that yourself. For example:
737
+
738
+ ```
739
+ TEST(MyDeathTest, TestOne) {
740
+ ::testing::FLAGS_gtest_death_test_style = "threadsafe";
741
+ // This test is run in the "threadsafe" style:
742
+ ASSERT_DEATH(ThisShouldDie(), "");
743
+ }
744
+
745
+ TEST(MyDeathTest, TestTwo) {
746
+ // This test is run in the "fast" style:
747
+ ASSERT_DEATH(ThisShouldDie(), "");
748
+ }
749
+
750
+ int main(int argc, char** argv) {
751
+ ::testing::InitGoogleTest(&argc, argv);
752
+ ::testing::FLAGS_gtest_death_test_style = "fast";
753
+ return RUN_ALL_TESTS();
754
+ }
755
+ ```
756
+
757
+ ## Caveats ##
758
+
759
+ The _statement_ argument of `ASSERT_EXIT()` can be any valid C++ statement.
760
+ If it leaves the current function via a `return` statement or by throwing an exception,
761
+ the death test is considered to have failed. Some Google Test macros may return
762
+ from the current function (e.g. `ASSERT_TRUE()`), so be sure to avoid them in _statement_.
763
+
764
+ Since _statement_ runs in the child process, any in-memory side effect (e.g.
765
+ modifying a variable, releasing memory, etc) it causes will _not_ be observable
766
+ in the parent process. In particular, if you release memory in a death test,
767
+ your program will fail the heap check as the parent process will never see the
768
+ memory reclaimed. To solve this problem, you can
769
+
770
+ 1. try not to free memory in a death test;
771
+ 1. free the memory again in the parent process; or
772
+ 1. do not use the heap checker in your program.
773
+
774
+ Due to an implementation detail, you cannot place multiple death test
775
+ assertions on the same line; otherwise, compilation will fail with an unobvious
776
+ error message.
777
+
778
+ Despite the improved thread safety afforded by the "threadsafe" style of death
779
+ test, thread problems such as deadlock are still possible in the presence of
780
+ handlers registered with `pthread_atfork(3)`.
781
+
782
+ # Using Assertions in Sub-routines #
783
+
784
+ ## Adding Traces to Assertions ##
785
+
786
+ If a test sub-routine is called from several places, when an assertion
787
+ inside it fails, it can be hard to tell which invocation of the
788
+ sub-routine the failure is from. You can alleviate this problem using
789
+ extra logging or custom failure messages, but that usually clutters up
790
+ your tests. A better solution is to use the `SCOPED_TRACE` macro or
791
+ the `ScopedTrace` utility:
792
+
793
+ | `SCOPED_TRACE(`_message_`);` | `::testing::ScopedTrace trace(`_"file\_path"_`, `_line\_number_`, `_message_`);` |
794
+ |:-----------------------------|:---------------------------------------------------------------------------------|
795
+
796
+ where `message` can be anything streamable to `std::ostream`. `SCOPED_TRACE`
797
+ macro will cause the current file name, line number, and the given message to be
798
+ added in every failure message. `ScopedTrace` accepts explicit file name and
799
+ line number in arguments, which is useful for writing test helpers. The effect
800
+ will be undone when the control leaves the current lexical scope.
801
+
802
+ For example,
803
+
804
+ ```
805
+ 10: void Sub1(int n) {
806
+ 11: EXPECT_EQ(1, Bar(n));
807
+ 12: EXPECT_EQ(2, Bar(n + 1));
808
+ 13: }
809
+ 14:
810
+ 15: TEST(FooTest, Bar) {
811
+ 16: {
812
+ 17: SCOPED_TRACE("A"); // This trace point will be included in
813
+ 18: // every failure in this scope.
814
+ 19: Sub1(1);
815
+ 20: }
816
+ 21: // Now it won't.
817
+ 22: Sub1(9);
818
+ 23: }
819
+ ```
820
+
821
+ could result in messages like these:
822
+
823
+ ```
824
+ path/to/foo_test.cc:11: Failure
825
+ Value of: Bar(n)
826
+ Expected: 1
827
+ Actual: 2
828
+ Trace:
829
+ path/to/foo_test.cc:17: A
830
+
831
+ path/to/foo_test.cc:12: Failure
832
+ Value of: Bar(n + 1)
833
+ Expected: 2
834
+ Actual: 3
835
+ ```
836
+
837
+ Without the trace, it would've been difficult to know which invocation
838
+ of `Sub1()` the two failures come from respectively. (You could add an
839
+ extra message to each assertion in `Sub1()` to indicate the value of
840
+ `n`, but that's tedious.)
841
+
842
+ Some tips on using `SCOPED_TRACE`:
843
+
844
+ 1. With a suitable message, it's often enough to use `SCOPED_TRACE` at the beginning of a sub-routine, instead of at each call site.
845
+ 1. When calling sub-routines inside a loop, make the loop iterator part of the message in `SCOPED_TRACE` such that you can know which iteration the failure is from.
846
+ 1. Sometimes the line number of the trace point is enough for identifying the particular invocation of a sub-routine. In this case, you don't have to choose a unique message for `SCOPED_TRACE`. You can simply use `""`.
847
+ 1. You can use `SCOPED_TRACE` in an inner scope when there is one in the outer scope. In this case, all active trace points will be included in the failure messages, in reverse order they are encountered.
848
+ 1. The trace dump is clickable in Emacs' compilation buffer - hit return on a line number and you'll be taken to that line in the source file!
849
+
850
+ _Availability:_ Linux, Windows, Mac.
851
+
852
+ ## Propagating Fatal Failures ##
853
+
854
+ A common pitfall when using `ASSERT_*` and `FAIL*` is not understanding that
855
+ when they fail they only abort the _current function_, not the entire test. For
856
+ example, the following test will segfault:
857
+ ```
858
+ void Subroutine() {
859
+ // Generates a fatal failure and aborts the current function.
860
+ ASSERT_EQ(1, 2);
861
+ // The following won't be executed.
862
+ ...
863
+ }
864
+
865
+ TEST(FooTest, Bar) {
866
+ Subroutine();
867
+ // The intended behavior is for the fatal failure
868
+ // in Subroutine() to abort the entire test.
869
+ // The actual behavior: the function goes on after Subroutine() returns.
870
+ int* p = NULL;
871
+ *p = 3; // Segfault!
872
+ }
873
+ ```
874
+
875
+ To alleviate this, gUnit provides three different solutions. You could use
876
+ either exceptions, the `(ASSERT|EXPECT)_NO_FATAL_FAILURE` assertions or the
877
+ `HasFatalFailure()` function. They are described in the following two
878
+ subsections.
879
+
880
+ #### Asserting on Subroutines with an exception
881
+
882
+ The following code can turn ASSERT-failure into an exception:
883
+
884
+ ```c++
885
+ class ThrowListener : public testing::EmptyTestEventListener {
886
+ void OnTestPartResult(const testing::TestPartResult& result) override {
887
+ if (result.type() == testing::TestPartResult::kFatalFailure) {
888
+ throw testing::AssertionException(result);
889
+ }
890
+ }
891
+ };
892
+ int main(int argc, char** argv) {
893
+ ...
894
+ testing::UnitTest::GetInstance()->listeners().Append(new ThrowListener);
895
+ return RUN_ALL_TESTS();
896
+ }
897
+ ```
898
+
899
+ This listener should be added after other listeners if you have any, otherwise
900
+ they won't see failed `OnTestPartResult`.
901
+
902
+ ### Asserting on Subroutines ###
903
+
904
+ As shown above, if your test calls a subroutine that has an `ASSERT_*`
905
+ failure in it, the test will continue after the subroutine
906
+ returns. This may not be what you want.
907
+
908
+ Often people want fatal failures to propagate like exceptions. For
909
+ that Google Test offers the following macros:
910
+
911
+ | **Fatal assertion** | **Nonfatal assertion** | **Verifies** |
912
+ |:--------------------|:-----------------------|:-------------|
913
+ | `ASSERT_NO_FATAL_FAILURE(`_statement_`);` | `EXPECT_NO_FATAL_FAILURE(`_statement_`);` | _statement_ doesn't generate any new fatal failures in the current thread. |
914
+
915
+ Only failures in the thread that executes the assertion are checked to
916
+ determine the result of this type of assertions. If _statement_
917
+ creates new threads, failures in these threads are ignored.
918
+
919
+ Examples:
920
+
921
+ ```
922
+ ASSERT_NO_FATAL_FAILURE(Foo());
923
+
924
+ int i;
925
+ EXPECT_NO_FATAL_FAILURE({
926
+ i = Bar();
927
+ });
928
+ ```
929
+
930
+ _Availability:_ Linux, Windows, Mac. Assertions from multiple threads
931
+ are currently not supported.
932
+
933
+ ### Checking for Failures in the Current Test ###
934
+
935
+ `HasFatalFailure()` in the `::testing::Test` class returns `true` if an
936
+ assertion in the current test has suffered a fatal failure. This
937
+ allows functions to catch fatal failures in a sub-routine and return
938
+ early.
939
+
940
+ ```
941
+ class Test {
942
+ public:
943
+ ...
944
+ static bool HasFatalFailure();
945
+ };
946
+ ```
947
+
948
+ The typical usage, which basically simulates the behavior of a thrown
949
+ exception, is:
950
+
951
+ ```
952
+ TEST(FooTest, Bar) {
953
+ Subroutine();
954
+ // Aborts if Subroutine() had a fatal failure.
955
+ if (HasFatalFailure())
956
+ return;
957
+ // The following won't be executed.
958
+ ...
959
+ }
960
+ ```
961
+
962
+ If `HasFatalFailure()` is used outside of `TEST()` , `TEST_F()` , or a test
963
+ fixture, you must add the `::testing::Test::` prefix, as in:
964
+
965
+ ```
966
+ if (::testing::Test::HasFatalFailure())
967
+ return;
968
+ ```
969
+
970
+ Similarly, `HasNonfatalFailure()` returns `true` if the current test
971
+ has at least one non-fatal failure, and `HasFailure()` returns `true`
972
+ if the current test has at least one failure of either kind.
973
+
974
+ _Availability:_ Linux, Windows, Mac. `HasNonfatalFailure()` and
975
+ `HasFailure()` are available since version 1.4.0.
976
+
977
+ # Logging Additional Information #
978
+
979
+ In your test code, you can call `RecordProperty("key", value)` to log
980
+ additional information, where `value` can be either a string or an `int`. The _last_ value recorded for a key will be emitted to the XML output
981
+ if you specify one. For example, the test
982
+
983
+ ```
984
+ TEST_F(WidgetUsageTest, MinAndMaxWidgets) {
985
+ RecordProperty("MaximumWidgets", ComputeMaxUsage());
986
+ RecordProperty("MinimumWidgets", ComputeMinUsage());
987
+ }
988
+ ```
989
+
990
+ will output XML like this:
991
+
992
+ ```
993
+ ...
994
+ <testcase name="MinAndMaxWidgets" status="run" time="6" classname="WidgetUsageTest"
995
+ MaximumWidgets="12"
996
+ MinimumWidgets="9" />
997
+ ...
998
+ ```
999
+
1000
+ _Note_:
1001
+ * `RecordProperty()` is a static member of the `Test` class. Therefore it needs to be prefixed with `::testing::Test::` if used outside of the `TEST` body and the test fixture class.
1002
+ * `key` must be a valid XML attribute name, and cannot conflict with the ones already used by Google Test (`name`, `status`, `time`, `classname`, `type_param`, and `value_param`).
1003
+ * Calling `RecordProperty()` outside of the lifespan of a test is allowed. If it's called outside of a test but between a test case's `SetUpTestCase()` and `TearDownTestCase()` methods, it will be attributed to the XML element for the test case. If it's called outside of all test cases (e.g. in a test environment), it will be attributed to the top-level XML element.
1004
+
1005
+ _Availability_: Linux, Windows, Mac.
1006
+
1007
+ # Sharing Resources Between Tests in the Same Test Case #
1008
+
1009
+
1010
+
1011
+ Google Test creates a new test fixture object for each test in order to make
1012
+ tests independent and easier to debug. However, sometimes tests use resources
1013
+ that are expensive to set up, making the one-copy-per-test model prohibitively
1014
+ expensive.
1015
+
1016
+ If the tests don't change the resource, there's no harm in them sharing a
1017
+ single resource copy. So, in addition to per-test set-up/tear-down, Google Test
1018
+ also supports per-test-case set-up/tear-down. To use it:
1019
+
1020
+ 1. In your test fixture class (say `FooTest` ), define as `static` some member variables to hold the shared resources.
1021
+ 1. In the same test fixture class, define a `static void SetUpTestCase()` function (remember not to spell it as **`SetupTestCase`** with a small `u`!) to set up the shared resources and a `static void TearDownTestCase()` function to tear them down.
1022
+
1023
+ That's it! Google Test automatically calls `SetUpTestCase()` before running the
1024
+ _first test_ in the `FooTest` test case (i.e. before creating the first
1025
+ `FooTest` object), and calls `TearDownTestCase()` after running the _last test_
1026
+ in it (i.e. after deleting the last `FooTest` object). In between, the tests
1027
+ can use the shared resources.
1028
+
1029
+ Remember that the test order is undefined, so your code can't depend on a test
1030
+ preceding or following another. Also, the tests must either not modify the
1031
+ state of any shared resource, or, if they do modify the state, they must
1032
+ restore the state to its original value before passing control to the next
1033
+ test.
1034
+
1035
+ Here's an example of per-test-case set-up and tear-down:
1036
+ ```
1037
+ class FooTest : public ::testing::Test {
1038
+ protected:
1039
+ // Per-test-case set-up.
1040
+ // Called before the first test in this test case.
1041
+ // Can be omitted if not needed.
1042
+ static void SetUpTestCase() {
1043
+ shared_resource_ = new ...;
1044
+ }
1045
+
1046
+ // Per-test-case tear-down.
1047
+ // Called after the last test in this test case.
1048
+ // Can be omitted if not needed.
1049
+ static void TearDownTestCase() {
1050
+ delete shared_resource_;
1051
+ shared_resource_ = NULL;
1052
+ }
1053
+
1054
+ // You can define per-test set-up and tear-down logic as usual.
1055
+ virtual void SetUp() { ... }
1056
+ virtual void TearDown() { ... }
1057
+
1058
+ // Some expensive resource shared by all tests.
1059
+ static T* shared_resource_;
1060
+ };
1061
+
1062
+ T* FooTest::shared_resource_ = NULL;
1063
+
1064
+ TEST_F(FooTest, Test1) {
1065
+ ... you can refer to shared_resource here ...
1066
+ }
1067
+ TEST_F(FooTest, Test2) {
1068
+ ... you can refer to shared_resource here ...
1069
+ }
1070
+ ```
1071
+
1072
+ _Availability:_ Linux, Windows, Mac.
1073
+
1074
+ # Global Set-Up and Tear-Down #
1075
+
1076
+ Just as you can do set-up and tear-down at the test level and the test case
1077
+ level, you can also do it at the test program level. Here's how.
1078
+
1079
+ First, you subclass the `::testing::Environment` class to define a test
1080
+ environment, which knows how to set-up and tear-down:
1081
+
1082
+ ```
1083
+ class Environment {
1084
+ public:
1085
+ virtual ~Environment() {}
1086
+ // Override this to define how to set up the environment.
1087
+ virtual void SetUp() {}
1088
+ // Override this to define how to tear down the environment.
1089
+ virtual void TearDown() {}
1090
+ };
1091
+ ```
1092
+
1093
+ Then, you register an instance of your environment class with Google Test by
1094
+ calling the `::testing::AddGlobalTestEnvironment()` function:
1095
+
1096
+ ```
1097
+ Environment* AddGlobalTestEnvironment(Environment* env);
1098
+ ```
1099
+
1100
+ Now, when `RUN_ALL_TESTS()` is called, it first calls the `SetUp()` method of
1101
+ the environment object, then runs the tests if there was no fatal failures, and
1102
+ finally calls `TearDown()` of the environment object.
1103
+
1104
+ It's OK to register multiple environment objects. In this case, their `SetUp()`
1105
+ will be called in the order they are registered, and their `TearDown()` will be
1106
+ called in the reverse order.
1107
+
1108
+ Note that Google Test takes ownership of the registered environment objects.
1109
+ Therefore **do not delete them** by yourself.
1110
+
1111
+ You should call `AddGlobalTestEnvironment()` before `RUN_ALL_TESTS()` is
1112
+ called, probably in `main()`. If you use `gtest_main`, you need to call
1113
+ this before `main()` starts for it to take effect. One way to do this is to
1114
+ define a global variable like this:
1115
+
1116
+ ```
1117
+ ::testing::Environment* const foo_env = ::testing::AddGlobalTestEnvironment(new FooEnvironment);
1118
+ ```
1119
+
1120
+ However, we strongly recommend you to write your own `main()` and call
1121
+ `AddGlobalTestEnvironment()` there, as relying on initialization of global
1122
+ variables makes the code harder to read and may cause problems when you
1123
+ register multiple environments from different translation units and the
1124
+ environments have dependencies among them (remember that the compiler doesn't
1125
+ guarantee the order in which global variables from different translation units
1126
+ are initialized).
1127
+
1128
+ _Availability:_ Linux, Windows, Mac.
1129
+
1130
+
1131
+ # Value Parameterized Tests #
1132
+
1133
+ _Value-parameterized tests_ allow you to test your code with different
1134
+ parameters without writing multiple copies of the same test.
1135
+
1136
+ Suppose you write a test for your code and then realize that your code is affected by a presence of a Boolean command line flag.
1137
+
1138
+ ```
1139
+ TEST(MyCodeTest, TestFoo) {
1140
+ // A code to test foo().
1141
+ }
1142
+ ```
1143
+
1144
+ Usually people factor their test code into a function with a Boolean parameter in such situations. The function sets the flag, then executes the testing code.
1145
+
1146
+ ```
1147
+ void TestFooHelper(bool flag_value) {
1148
+ flag = flag_value;
1149
+ // A code to test foo().
1150
+ }
1151
+
1152
+ TEST(MyCodeTest, TestFoo) {
1153
+ TestFooHelper(false);
1154
+ TestFooHelper(true);
1155
+ }
1156
+ ```
1157
+
1158
+ But this setup has serious drawbacks. First, when a test assertion fails in your tests, it becomes unclear what value of the parameter caused it to fail. You can stream a clarifying message into your `EXPECT`/`ASSERT` statements, but it you'll have to do it with all of them. Second, you have to add one such helper function per test. What if you have ten tests? Twenty? A hundred?
1159
+
1160
+ Value-parameterized tests will let you write your test only once and then easily instantiate and run it with an arbitrary number of parameter values.
1161
+
1162
+ Here are some other situations when value-parameterized tests come handy:
1163
+
1164
+ * You want to test different implementations of an OO interface.
1165
+ * You want to test your code over various inputs (a.k.a. data-driven testing). This feature is easy to abuse, so please exercise your good sense when doing it!
1166
+
1167
+ ## How to Write Value-Parameterized Tests ##
1168
+
1169
+ To write value-parameterized tests, first you should define a fixture
1170
+ class. It must be derived from both `::testing::Test` and
1171
+ `::testing::WithParamInterface<T>` (the latter is a pure interface),
1172
+ where `T` is the type of your parameter values. For convenience, you
1173
+ can just derive the fixture class from `::testing::TestWithParam<T>`,
1174
+ which itself is derived from both `::testing::Test` and
1175
+ `::testing::WithParamInterface<T>`. `T` can be any copyable type. If
1176
+ it's a raw pointer, you are responsible for managing the lifespan of
1177
+ the pointed values.
1178
+
1179
+ ```
1180
+ class FooTest : public ::testing::TestWithParam<const char*> {
1181
+ // You can implement all the usual fixture class members here.
1182
+ // To access the test parameter, call GetParam() from class
1183
+ // TestWithParam<T>.
1184
+ };
1185
+
1186
+ // Or, when you want to add parameters to a pre-existing fixture class:
1187
+ class BaseTest : public ::testing::Test {
1188
+ ...
1189
+ };
1190
+ class BarTest : public BaseTest,
1191
+ public ::testing::WithParamInterface<const char*> {
1192
+ ...
1193
+ };
1194
+ ```
1195
+
1196
+ Then, use the `TEST_P` macro to define as many test patterns using
1197
+ this fixture as you want. The `_P` suffix is for "parameterized" or
1198
+ "pattern", whichever you prefer to think.
1199
+
1200
+ ```
1201
+ TEST_P(FooTest, DoesBlah) {
1202
+ // Inside a test, access the test parameter with the GetParam() method
1203
+ // of the TestWithParam<T> class:
1204
+ EXPECT_TRUE(foo.Blah(GetParam()));
1205
+ ...
1206
+ }
1207
+
1208
+ TEST_P(FooTest, HasBlahBlah) {
1209
+ ...
1210
+ }
1211
+ ```
1212
+
1213
+ Finally, you can use `INSTANTIATE_TEST_CASE_P` to instantiate the test
1214
+ case with any set of parameters you want. Google Test defines a number of
1215
+ functions for generating test parameters. They return what we call
1216
+ (surprise!) _parameter generators_. Here is a summary of them,
1217
+ which are all in the `testing` namespace:
1218
+
1219
+ | `Range(begin, end[, step])` | Yields values `{begin, begin+step, begin+step+step, ...}`. The values do not include `end`. `step` defaults to 1. |
1220
+ |:----------------------------|:------------------------------------------------------------------------------------------------------------------|
1221
+ | `Values(v1, v2, ..., vN)` | Yields values `{v1, v2, ..., vN}`. |
1222
+ | `ValuesIn(container)` and `ValuesIn(begin, end)` | Yields values from a C-style array, an STL-style container, or an iterator range `[begin, end)`. `container`, `begin`, and `end` can be expressions whose values are determined at run time. |
1223
+ | `Bool()` | Yields sequence `{false, true}`. |
1224
+ | `Combine(g1, g2, ..., gN)` | Yields all combinations (the Cartesian product for the math savvy) of the values generated by the `N` generators. This is only available if your system provides the `<tr1/tuple>` header. If you are sure your system does, and Google Test disagrees, you can override it by defining `GTEST_HAS_TR1_TUPLE=1`. See comments in [include/gtest/internal/gtest-port.h](../include/gtest/internal/gtest-port.h) for more information. |
1225
+
1226
+ For more details, see the comments at the definitions of these functions in the [source code](../include/gtest/gtest-param-test.h).
1227
+
1228
+ The following statement will instantiate tests from the `FooTest` test case
1229
+ each with parameter values `"meeny"`, `"miny"`, and `"moe"`.
1230
+
1231
+ ```
1232
+ INSTANTIATE_TEST_CASE_P(InstantiationName,
1233
+ FooTest,
1234
+ ::testing::Values("meeny", "miny", "moe"));
1235
+ ```
1236
+
1237
+ To distinguish different instances of the pattern (yes, you can
1238
+ instantiate it more than once), the first argument to
1239
+ `INSTANTIATE_TEST_CASE_P` is a prefix that will be added to the actual
1240
+ test case name. Remember to pick unique prefixes for different
1241
+ instantiations. The tests from the instantiation above will have these
1242
+ names:
1243
+
1244
+ * `InstantiationName/FooTest.DoesBlah/0` for `"meeny"`
1245
+ * `InstantiationName/FooTest.DoesBlah/1` for `"miny"`
1246
+ * `InstantiationName/FooTest.DoesBlah/2` for `"moe"`
1247
+ * `InstantiationName/FooTest.HasBlahBlah/0` for `"meeny"`
1248
+ * `InstantiationName/FooTest.HasBlahBlah/1` for `"miny"`
1249
+ * `InstantiationName/FooTest.HasBlahBlah/2` for `"moe"`
1250
+
1251
+ You can use these names in [--gtest\_filter](#running-a-subset-of-the-tests).
1252
+
1253
+ This statement will instantiate all tests from `FooTest` again, each
1254
+ with parameter values `"cat"` and `"dog"`:
1255
+
1256
+ ```
1257
+ const char* pets[] = {"cat", "dog"};
1258
+ INSTANTIATE_TEST_CASE_P(AnotherInstantiationName, FooTest,
1259
+ ::testing::ValuesIn(pets));
1260
+ ```
1261
+
1262
+ The tests from the instantiation above will have these names:
1263
+
1264
+ * `AnotherInstantiationName/FooTest.DoesBlah/0` for `"cat"`
1265
+ * `AnotherInstantiationName/FooTest.DoesBlah/1` for `"dog"`
1266
+ * `AnotherInstantiationName/FooTest.HasBlahBlah/0` for `"cat"`
1267
+ * `AnotherInstantiationName/FooTest.HasBlahBlah/1` for `"dog"`
1268
+
1269
+ Please note that `INSTANTIATE_TEST_CASE_P` will instantiate _all_
1270
+ tests in the given test case, whether their definitions come before or
1271
+ _after_ the `INSTANTIATE_TEST_CASE_P` statement.
1272
+
1273
+ You can see
1274
+ [these](../samples/sample7_unittest.cc)
1275
+ [files](../samples/sample8_unittest.cc) for more examples.
1276
+
1277
+ _Availability_: Linux, Windows (requires MSVC 8.0 or above), Mac; since version 1.2.0.
1278
+
1279
+ ## Creating Value-Parameterized Abstract Tests ##
1280
+
1281
+ In the above, we define and instantiate `FooTest` in the same source
1282
+ file. Sometimes you may want to define value-parameterized tests in a
1283
+ library and let other people instantiate them later. This pattern is
1284
+ known as <i>abstract tests</i>. As an example of its application, when you
1285
+ are designing an interface you can write a standard suite of abstract
1286
+ tests (perhaps using a factory function as the test parameter) that
1287
+ all implementations of the interface are expected to pass. When
1288
+ someone implements the interface, they can instantiate your suite to get
1289
+ all the interface-conformance tests for free.
1290
+
1291
+ To define abstract tests, you should organize your code like this:
1292
+
1293
+ 1. Put the definition of the parameterized test fixture class (e.g. `FooTest`) in a header file, say `foo_param_test.h`. Think of this as _declaring_ your abstract tests.
1294
+ 1. Put the `TEST_P` definitions in `foo_param_test.cc`, which includes `foo_param_test.h`. Think of this as _implementing_ your abstract tests.
1295
+
1296
+ Once they are defined, you can instantiate them by including
1297
+ `foo_param_test.h`, invoking `INSTANTIATE_TEST_CASE_P()`, and linking
1298
+ with `foo_param_test.cc`. You can instantiate the same abstract test
1299
+ case multiple times, possibly in different source files.
1300
+
1301
+ # Typed Tests #
1302
+
1303
+ Suppose you have multiple implementations of the same interface and
1304
+ want to make sure that all of them satisfy some common requirements.
1305
+ Or, you may have defined several types that are supposed to conform to
1306
+ the same "concept" and you want to verify it. In both cases, you want
1307
+ the same test logic repeated for different types.
1308
+
1309
+ While you can write one `TEST` or `TEST_F` for each type you want to
1310
+ test (and you may even factor the test logic into a function template
1311
+ that you invoke from the `TEST`), it's tedious and doesn't scale:
1312
+ if you want _m_ tests over _n_ types, you'll end up writing _m\*n_
1313
+ `TEST`s.
1314
+
1315
+ _Typed tests_ allow you to repeat the same test logic over a list of
1316
+ types. You only need to write the test logic once, although you must
1317
+ know the type list when writing typed tests. Here's how you do it:
1318
+
1319
+ First, define a fixture class template. It should be parameterized
1320
+ by a type. Remember to derive it from `::testing::Test`:
1321
+
1322
+ ```
1323
+ template <typename T>
1324
+ class FooTest : public ::testing::Test {
1325
+ public:
1326
+ ...
1327
+ typedef std::list<T> List;
1328
+ static T shared_;
1329
+ T value_;
1330
+ };
1331
+ ```
1332
+
1333
+ Next, associate a list of types with the test case, which will be
1334
+ repeated for each type in the list:
1335
+
1336
+ ```
1337
+ typedef ::testing::Types<char, int, unsigned int> MyTypes;
1338
+ TYPED_TEST_CASE(FooTest, MyTypes);
1339
+ ```
1340
+
1341
+ The `typedef` is necessary for the `TYPED_TEST_CASE` macro to parse
1342
+ correctly. Otherwise the compiler will think that each comma in the
1343
+ type list introduces a new macro argument.
1344
+
1345
+ Then, use `TYPED_TEST()` instead of `TEST_F()` to define a typed test
1346
+ for this test case. You can repeat this as many times as you want:
1347
+
1348
+ ```
1349
+ TYPED_TEST(FooTest, DoesBlah) {
1350
+ // Inside a test, refer to the special name TypeParam to get the type
1351
+ // parameter. Since we are inside a derived class template, C++ requires
1352
+ // us to visit the members of FooTest via 'this'.
1353
+ TypeParam n = this->value_;
1354
+
1355
+ // To visit static members of the fixture, add the 'TestFixture::'
1356
+ // prefix.
1357
+ n += TestFixture::shared_;
1358
+
1359
+ // To refer to typedefs in the fixture, add the 'typename TestFixture::'
1360
+ // prefix. The 'typename' is required to satisfy the compiler.
1361
+ typename TestFixture::List values;
1362
+ values.push_back(n);
1363
+ ...
1364
+ }
1365
+
1366
+ TYPED_TEST(FooTest, HasPropertyA) { ... }
1367
+ ```
1368
+
1369
+ You can see [`samples/sample6_unittest.cc`](../samples/sample6_unittest.cc) for a complete example.
1370
+
1371
+ _Availability:_ Linux, Windows (requires MSVC 8.0 or above), Mac;
1372
+ since version 1.1.0.
1373
+
1374
+ # Type-Parameterized Tests #
1375
+
1376
+ _Type-parameterized tests_ are like typed tests, except that they
1377
+ don't require you to know the list of types ahead of time. Instead,
1378
+ you can define the test logic first and instantiate it with different
1379
+ type lists later. You can even instantiate it more than once in the
1380
+ same program.
1381
+
1382
+ If you are designing an interface or concept, you can define a suite
1383
+ of type-parameterized tests to verify properties that any valid
1384
+ implementation of the interface/concept should have. Then, the author
1385
+ of each implementation can just instantiate the test suite with his
1386
+ type to verify that it conforms to the requirements, without having to
1387
+ write similar tests repeatedly. Here's an example:
1388
+
1389
+ First, define a fixture class template, as we did with typed tests:
1390
+
1391
+ ```
1392
+ template <typename T>
1393
+ class FooTest : public ::testing::Test {
1394
+ ...
1395
+ };
1396
+ ```
1397
+
1398
+ Next, declare that you will define a type-parameterized test case:
1399
+
1400
+ ```
1401
+ TYPED_TEST_CASE_P(FooTest);
1402
+ ```
1403
+
1404
+ The `_P` suffix is for "parameterized" or "pattern", whichever you
1405
+ prefer to think.
1406
+
1407
+ Then, use `TYPED_TEST_P()` to define a type-parameterized test. You
1408
+ can repeat this as many times as you want:
1409
+
1410
+ ```
1411
+ TYPED_TEST_P(FooTest, DoesBlah) {
1412
+ // Inside a test, refer to TypeParam to get the type parameter.
1413
+ TypeParam n = 0;
1414
+ ...
1415
+ }
1416
+
1417
+ TYPED_TEST_P(FooTest, HasPropertyA) { ... }
1418
+ ```
1419
+
1420
+ Now the tricky part: you need to register all test patterns using the
1421
+ `REGISTER_TYPED_TEST_CASE_P` macro before you can instantiate them.
1422
+ The first argument of the macro is the test case name; the rest are
1423
+ the names of the tests in this test case:
1424
+
1425
+ ```
1426
+ REGISTER_TYPED_TEST_CASE_P(FooTest,
1427
+ DoesBlah, HasPropertyA);
1428
+ ```
1429
+
1430
+ Finally, you are free to instantiate the pattern with the types you
1431
+ want. If you put the above code in a header file, you can `#include`
1432
+ it in multiple C++ source files and instantiate it multiple times.
1433
+
1434
+ ```
1435
+ typedef ::testing::Types<char, int, unsigned int> MyTypes;
1436
+ INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, MyTypes);
1437
+ ```
1438
+
1439
+ To distinguish different instances of the pattern, the first argument
1440
+ to the `INSTANTIATE_TYPED_TEST_CASE_P` macro is a prefix that will be
1441
+ added to the actual test case name. Remember to pick unique prefixes
1442
+ for different instances.
1443
+
1444
+ In the special case where the type list contains only one type, you
1445
+ can write that type directly without `::testing::Types<...>`, like this:
1446
+
1447
+ ```
1448
+ INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, int);
1449
+ ```
1450
+
1451
+ You can see `samples/sample6_unittest.cc` for a complete example.
1452
+
1453
+ _Availability:_ Linux, Windows (requires MSVC 8.0 or above), Mac;
1454
+ since version 1.1.0.
1455
+
1456
+ # Testing Private Code #
1457
+
1458
+ If you change your software's internal implementation, your tests should not
1459
+ break as long as the change is not observable by users. Therefore, per the
1460
+ _black-box testing principle_, most of the time you should test your code
1461
+ through its public interfaces.
1462
+
1463
+ If you still find yourself needing to test internal implementation code,
1464
+ consider if there's a better design that wouldn't require you to do so. If you
1465
+ absolutely have to test non-public interface code though, you can. There are
1466
+ two cases to consider:
1467
+
1468
+ * Static functions (_not_ the same as static member functions!) or unnamed namespaces, and
1469
+ * Private or protected class members.
1470
+
1471
+ ## Static Functions ##
1472
+
1473
+ Both static functions and definitions/declarations in an unnamed namespace are
1474
+ only visible within the same translation unit. To test them, you can `#include`
1475
+ the entire `.cc` file being tested in your `*_test.cc` file. (`#include`ing `.cc`
1476
+ files is not a good way to reuse code - you should not do this in production
1477
+ code!)
1478
+
1479
+ However, a better approach is to move the private code into the
1480
+ `foo::internal` namespace, where `foo` is the namespace your project normally
1481
+ uses, and put the private declarations in a `*-internal.h` file. Your
1482
+ production `.cc` files and your tests are allowed to include this internal
1483
+ header, but your clients are not. This way, you can fully test your internal
1484
+ implementation without leaking it to your clients.
1485
+
1486
+ ## Private Class Members ##
1487
+
1488
+ Private class members are only accessible from within the class or by friends.
1489
+ To access a class' private members, you can declare your test fixture as a
1490
+ friend to the class and define accessors in your fixture. Tests using the
1491
+ fixture can then access the private members of your production class via the
1492
+ accessors in the fixture. Note that even though your fixture is a friend to
1493
+ your production class, your tests are not automatically friends to it, as they
1494
+ are technically defined in sub-classes of the fixture.
1495
+
1496
+ Another way to test private members is to refactor them into an implementation
1497
+ class, which is then declared in a `*-internal.h` file. Your clients aren't
1498
+ allowed to include this header but your tests can. Such is called the Pimpl
1499
+ (Private Implementation) idiom.
1500
+
1501
+ Or, you can declare an individual test as a friend of your class by adding this
1502
+ line in the class body:
1503
+
1504
+ ```
1505
+ FRIEND_TEST(TestCaseName, TestName);
1506
+ ```
1507
+
1508
+ For example,
1509
+ ```
1510
+ // foo.h
1511
+ #include "gtest/gtest_prod.h"
1512
+
1513
+ // Defines FRIEND_TEST.
1514
+ class Foo {
1515
+ ...
1516
+ private:
1517
+ FRIEND_TEST(FooTest, BarReturnsZeroOnNull);
1518
+ int Bar(void* x);
1519
+ };
1520
+
1521
+ // foo_test.cc
1522
+ ...
1523
+ TEST(FooTest, BarReturnsZeroOnNull) {
1524
+ Foo foo;
1525
+ EXPECT_EQ(0, foo.Bar(NULL));
1526
+ // Uses Foo's private member Bar().
1527
+ }
1528
+ ```
1529
+
1530
+ Pay special attention when your class is defined in a namespace, as you should
1531
+ define your test fixtures and tests in the same namespace if you want them to
1532
+ be friends of your class. For example, if the code to be tested looks like:
1533
+
1534
+ ```
1535
+ namespace my_namespace {
1536
+
1537
+ class Foo {
1538
+ friend class FooTest;
1539
+ FRIEND_TEST(FooTest, Bar);
1540
+ FRIEND_TEST(FooTest, Baz);
1541
+ ...
1542
+ definition of the class Foo
1543
+ ...
1544
+ };
1545
+
1546
+ } // namespace my_namespace
1547
+ ```
1548
+
1549
+ Your test code should be something like:
1550
+
1551
+ ```
1552
+ namespace my_namespace {
1553
+ class FooTest : public ::testing::Test {
1554
+ protected:
1555
+ ...
1556
+ };
1557
+
1558
+ TEST_F(FooTest, Bar) { ... }
1559
+ TEST_F(FooTest, Baz) { ... }
1560
+
1561
+ } // namespace my_namespace
1562
+ ```
1563
+
1564
+ # Catching Failures #
1565
+
1566
+ If you are building a testing utility on top of Google Test, you'll
1567
+ want to test your utility. What framework would you use to test it?
1568
+ Google Test, of course.
1569
+
1570
+ The challenge is to verify that your testing utility reports failures
1571
+ correctly. In frameworks that report a failure by throwing an
1572
+ exception, you could catch the exception and assert on it. But Google
1573
+ Test doesn't use exceptions, so how do we test that a piece of code
1574
+ generates an expected failure?
1575
+
1576
+ `"gtest/gtest-spi.h"` contains some constructs to do this. After
1577
+ `#include`ing this header, you can use
1578
+
1579
+ | `EXPECT_FATAL_FAILURE(`_statement, substring_`);` |
1580
+ |:--------------------------------------------------|
1581
+
1582
+ to assert that _statement_ generates a fatal (e.g. `ASSERT_*`) failure
1583
+ whose message contains the given _substring_, or use
1584
+
1585
+ | `EXPECT_NONFATAL_FAILURE(`_statement, substring_`);` |
1586
+ |:-----------------------------------------------------|
1587
+
1588
+ if you are expecting a non-fatal (e.g. `EXPECT_*`) failure.
1589
+
1590
+ For technical reasons, there are some caveats:
1591
+
1592
+ 1. You cannot stream a failure message to either macro.
1593
+ 1. _statement_ in `EXPECT_FATAL_FAILURE()` cannot reference local non-static variables or non-static members of `this` object.
1594
+ 1. _statement_ in `EXPECT_FATAL_FAILURE()` cannot return a value.
1595
+
1596
+ _Note:_ Google Test is designed with threads in mind. Once the
1597
+ synchronization primitives in `"gtest/internal/gtest-port.h"` have
1598
+ been implemented, Google Test will become thread-safe, meaning that
1599
+ you can then use assertions in multiple threads concurrently. Before
1600
+ that, however, Google Test only supports single-threaded usage. Once
1601
+ thread-safe, `EXPECT_FATAL_FAILURE()` and `EXPECT_NONFATAL_FAILURE()`
1602
+ will capture failures in the current thread only. If _statement_
1603
+ creates new threads, failures in these threads will be ignored. If
1604
+ you want to capture failures from all threads instead, you should use
1605
+ the following macros:
1606
+
1607
+ | `EXPECT_FATAL_FAILURE_ON_ALL_THREADS(`_statement, substring_`);` |
1608
+ |:-----------------------------------------------------------------|
1609
+ | `EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS(`_statement, substring_`);` |
1610
+
1611
+ # Getting the Current Test's Name #
1612
+
1613
+ Sometimes a function may need to know the name of the currently running test.
1614
+ For example, you may be using the `SetUp()` method of your test fixture to set
1615
+ the golden file name based on which test is running. The `::testing::TestInfo`
1616
+ class has this information:
1617
+
1618
+ ```
1619
+ namespace testing {
1620
+
1621
+ class TestInfo {
1622
+ public:
1623
+ // Returns the test case name and the test name, respectively.
1624
+ //
1625
+ // Do NOT delete or free the return value - it's managed by the
1626
+ // TestInfo class.
1627
+ const char* test_case_name() const;
1628
+ const char* name() const;
1629
+ };
1630
+
1631
+ } // namespace testing
1632
+ ```
1633
+
1634
+
1635
+ > To obtain a `TestInfo` object for the currently running test, call
1636
+ `current_test_info()` on the `UnitTest` singleton object:
1637
+
1638
+ ```
1639
+ // Gets information about the currently running test.
1640
+ // Do NOT delete the returned object - it's managed by the UnitTest class.
1641
+ const ::testing::TestInfo* const test_info =
1642
+ ::testing::UnitTest::GetInstance()->current_test_info();
1643
+ printf("We are in test %s of test case %s.\n",
1644
+ test_info->name(), test_info->test_case_name());
1645
+ ```
1646
+
1647
+ `current_test_info()` returns a null pointer if no test is running. In
1648
+ particular, you cannot find the test case name in `SetUpTestCase()`,
1649
+ `TearDownTestCase()` (where you know the test case name implicitly), or
1650
+ functions called from them.
1651
+
1652
+ _Availability:_ Linux, Windows, Mac.
1653
+
1654
+ # Extending Google Test by Handling Test Events #
1655
+
1656
+ Google Test provides an <b>event listener API</b> to let you receive
1657
+ notifications about the progress of a test program and test
1658
+ failures. The events you can listen to include the start and end of
1659
+ the test program, a test case, or a test method, among others. You may
1660
+ use this API to augment or replace the standard console output,
1661
+ replace the XML output, or provide a completely different form of
1662
+ output, such as a GUI or a database. You can also use test events as
1663
+ checkpoints to implement a resource leak checker, for example.
1664
+
1665
+ _Availability:_ Linux, Windows, Mac; since v1.4.0.
1666
+
1667
+ ## Defining Event Listeners ##
1668
+
1669
+ To define a event listener, you subclass either
1670
+ [testing::TestEventListener](../include/gtest/gtest.h#L991)
1671
+ or [testing::EmptyTestEventListener](../include/gtest/gtest.h#L1044).
1672
+ The former is an (abstract) interface, where <i>each pure virtual method<br>
1673
+ can be overridden to handle a test event</i> (For example, when a test
1674
+ starts, the `OnTestStart()` method will be called.). The latter provides
1675
+ an empty implementation of all methods in the interface, such that a
1676
+ subclass only needs to override the methods it cares about.
1677
+
1678
+ When an event is fired, its context is passed to the handler function
1679
+ as an argument. The following argument types are used:
1680
+ * [UnitTest](../include/gtest/gtest.h#L1151) reflects the state of the entire test program,
1681
+ * [TestCase](../include/gtest/gtest.h#L778) has information about a test case, which can contain one or more tests,
1682
+ * [TestInfo](../include/gtest/gtest.h#L644) contains the state of a test, and
1683
+ * [TestPartResult](../include/gtest/gtest-test-part.h#L47) represents the result of a test assertion.
1684
+
1685
+ An event handler function can examine the argument it receives to find
1686
+ out interesting information about the event and the test program's
1687
+ state. Here's an example:
1688
+
1689
+ ```
1690
+ class MinimalistPrinter : public ::testing::EmptyTestEventListener {
1691
+ // Called before a test starts.
1692
+ virtual void OnTestStart(const ::testing::TestInfo& test_info) {
1693
+ printf("*** Test %s.%s starting.\n",
1694
+ test_info.test_case_name(), test_info.name());
1695
+ }
1696
+
1697
+ // Called after a failed assertion or a SUCCEED() invocation.
1698
+ virtual void OnTestPartResult(
1699
+ const ::testing::TestPartResult& test_part_result) {
1700
+ printf("%s in %s:%d\n%s\n",
1701
+ test_part_result.failed() ? "*** Failure" : "Success",
1702
+ test_part_result.file_name(),
1703
+ test_part_result.line_number(),
1704
+ test_part_result.summary());
1705
+ }
1706
+
1707
+ // Called after a test ends.
1708
+ virtual void OnTestEnd(const ::testing::TestInfo& test_info) {
1709
+ printf("*** Test %s.%s ending.\n",
1710
+ test_info.test_case_name(), test_info.name());
1711
+ }
1712
+ };
1713
+ ```
1714
+
1715
+ ## Using Event Listeners ##
1716
+
1717
+ To use the event listener you have defined, add an instance of it to
1718
+ the Google Test event listener list (represented by class
1719
+ [TestEventListeners](../include/gtest/gtest.h#L1064)
1720
+ - note the "s" at the end of the name) in your
1721
+ `main()` function, before calling `RUN_ALL_TESTS()`:
1722
+ ```
1723
+ int main(int argc, char** argv) {
1724
+ ::testing::InitGoogleTest(&argc, argv);
1725
+ // Gets hold of the event listener list.
1726
+ ::testing::TestEventListeners& listeners =
1727
+ ::testing::UnitTest::GetInstance()->listeners();
1728
+ // Adds a listener to the end. Google Test takes the ownership.
1729
+ listeners.Append(new MinimalistPrinter);
1730
+ return RUN_ALL_TESTS();
1731
+ }
1732
+ ```
1733
+
1734
+ There's only one problem: the default test result printer is still in
1735
+ effect, so its output will mingle with the output from your minimalist
1736
+ printer. To suppress the default printer, just release it from the
1737
+ event listener list and delete it. You can do so by adding one line:
1738
+ ```
1739
+ ...
1740
+ delete listeners.Release(listeners.default_result_printer());
1741
+ listeners.Append(new MinimalistPrinter);
1742
+ return RUN_ALL_TESTS();
1743
+ ```
1744
+
1745
+ Now, sit back and enjoy a completely different output from your
1746
+ tests. For more details, you can read this
1747
+ [sample](../samples/sample9_unittest.cc).
1748
+
1749
+ You may append more than one listener to the list. When an `On*Start()`
1750
+ or `OnTestPartResult()` event is fired, the listeners will receive it in
1751
+ the order they appear in the list (since new listeners are added to
1752
+ the end of the list, the default text printer and the default XML
1753
+ generator will receive the event first). An `On*End()` event will be
1754
+ received by the listeners in the _reverse_ order. This allows output by
1755
+ listeners added later to be framed by output from listeners added
1756
+ earlier.
1757
+
1758
+ ## Generating Failures in Listeners ##
1759
+
1760
+ You may use failure-raising macros (`EXPECT_*()`, `ASSERT_*()`,
1761
+ `FAIL()`, etc) when processing an event. There are some restrictions:
1762
+
1763
+ 1. You cannot generate any failure in `OnTestPartResult()` (otherwise it will cause `OnTestPartResult()` to be called recursively).
1764
+ 1. A listener that handles `OnTestPartResult()` is not allowed to generate any failure.
1765
+
1766
+ When you add listeners to the listener list, you should put listeners
1767
+ that handle `OnTestPartResult()` _before_ listeners that can generate
1768
+ failures. This ensures that failures generated by the latter are
1769
+ attributed to the right test by the former.
1770
+
1771
+ We have a sample of failure-raising listener
1772
+ [here](../samples/sample10_unittest.cc).
1773
+
1774
+ # Running Test Programs: Advanced Options #
1775
+
1776
+ Google Test test programs are ordinary executables. Once built, you can run
1777
+ them directly and affect their behavior via the following environment variables
1778
+ and/or command line flags. For the flags to work, your programs must call
1779
+ `::testing::InitGoogleTest()` before calling `RUN_ALL_TESTS()`.
1780
+
1781
+ To see a list of supported flags and their usage, please run your test
1782
+ program with the `--help` flag. You can also use `-h`, `-?`, or `/?`
1783
+ for short. This feature is added in version 1.3.0.
1784
+
1785
+ If an option is specified both by an environment variable and by a
1786
+ flag, the latter takes precedence. Most of the options can also be
1787
+ set/read in code: to access the value of command line flag
1788
+ `--gtest_foo`, write `::testing::GTEST_FLAG(foo)`. A common pattern is
1789
+ to set the value of a flag before calling `::testing::InitGoogleTest()`
1790
+ to change the default value of the flag:
1791
+ ```
1792
+ int main(int argc, char** argv) {
1793
+ // Disables elapsed time by default.
1794
+ ::testing::GTEST_FLAG(print_time) = false;
1795
+
1796
+ // This allows the user to override the flag on the command line.
1797
+ ::testing::InitGoogleTest(&argc, argv);
1798
+
1799
+ return RUN_ALL_TESTS();
1800
+ }
1801
+ ```
1802
+
1803
+ ## Selecting Tests ##
1804
+
1805
+ This section shows various options for choosing which tests to run.
1806
+
1807
+ ### Listing Test Names ###
1808
+
1809
+ Sometimes it is necessary to list the available tests in a program before
1810
+ running them so that a filter may be applied if needed. Including the flag
1811
+ `--gtest_list_tests` overrides all other flags and lists tests in the following
1812
+ format:
1813
+ ```
1814
+ TestCase1.
1815
+ TestName1
1816
+ TestName2
1817
+ TestCase2.
1818
+ TestName
1819
+ ```
1820
+
1821
+ None of the tests listed are actually run if the flag is provided. There is no
1822
+ corresponding environment variable for this flag.
1823
+
1824
+ _Availability:_ Linux, Windows, Mac.
1825
+
1826
+ ### Running a Subset of the Tests ###
1827
+
1828
+ By default, a Google Test program runs all tests the user has defined.
1829
+ Sometimes, you want to run only a subset of the tests (e.g. for debugging or
1830
+ quickly verifying a change). If you set the `GTEST_FILTER` environment variable
1831
+ or the `--gtest_filter` flag to a filter string, Google Test will only run the
1832
+ tests whose full names (in the form of `TestCaseName.TestName`) match the
1833
+ filter.
1834
+
1835
+ The format of a filter is a '`:`'-separated list of wildcard patterns (called
1836
+ the positive patterns) optionally followed by a '`-`' and another
1837
+ '`:`'-separated pattern list (called the negative patterns). A test matches the
1838
+ filter if and only if it matches any of the positive patterns but does not
1839
+ match any of the negative patterns.
1840
+
1841
+ A pattern may contain `'*'` (matches any string) or `'?'` (matches any single
1842
+ character). For convenience, the filter `'*-NegativePatterns'` can be also
1843
+ written as `'-NegativePatterns'`.
1844
+
1845
+ For example:
1846
+
1847
+ * `./foo_test` Has no flag, and thus runs all its tests.
1848
+ * `./foo_test --gtest_filter=*` Also runs everything, due to the single match-everything `*` value.
1849
+ * `./foo_test --gtest_filter=FooTest.*` Runs everything in test case `FooTest`.
1850
+ * `./foo_test --gtest_filter=*Null*:*Constructor*` Runs any test whose full name contains either `"Null"` or `"Constructor"`.
1851
+ * `./foo_test --gtest_filter=-*DeathTest.*` Runs all non-death tests.
1852
+ * `./foo_test --gtest_filter=FooTest.*-FooTest.Bar` Runs everything in test case `FooTest` except `FooTest.Bar`.
1853
+
1854
+ _Availability:_ Linux, Windows, Mac.
1855
+
1856
+ ### Temporarily Disabling Tests ###
1857
+
1858
+ If you have a broken test that you cannot fix right away, you can add the
1859
+ `DISABLED_` prefix to its name. This will exclude it from execution. This is
1860
+ better than commenting out the code or using `#if 0`, as disabled tests are
1861
+ still compiled (and thus won't rot).
1862
+
1863
+ If you need to disable all tests in a test case, you can either add `DISABLED_`
1864
+ to the front of the name of each test, or alternatively add it to the front of
1865
+ the test case name.
1866
+
1867
+ For example, the following tests won't be run by Google Test, even though they
1868
+ will still be compiled:
1869
+
1870
+ ```
1871
+ // Tests that Foo does Abc.
1872
+ TEST(FooTest, DISABLED_DoesAbc) { ... }
1873
+
1874
+ class DISABLED_BarTest : public ::testing::Test { ... };
1875
+
1876
+ // Tests that Bar does Xyz.
1877
+ TEST_F(DISABLED_BarTest, DoesXyz) { ... }
1878
+ ```
1879
+
1880
+ _Note:_ This feature should only be used for temporary pain-relief. You still
1881
+ have to fix the disabled tests at a later date. As a reminder, Google Test will
1882
+ print a banner warning you if a test program contains any disabled tests.
1883
+
1884
+ _Tip:_ You can easily count the number of disabled tests you have
1885
+ using `grep`. This number can be used as a metric for improving your
1886
+ test quality.
1887
+
1888
+ _Availability:_ Linux, Windows, Mac.
1889
+
1890
+ ### Temporarily Enabling Disabled Tests ###
1891
+
1892
+ To include [disabled tests](#temporarily-disabling-tests) in test
1893
+ execution, just invoke the test program with the
1894
+ `--gtest_also_run_disabled_tests` flag or set the
1895
+ `GTEST_ALSO_RUN_DISABLED_TESTS` environment variable to a value other
1896
+ than `0`. You can combine this with the
1897
+ [--gtest\_filter](#running-a-subset-of-the-tests) flag to further select
1898
+ which disabled tests to run.
1899
+
1900
+ _Availability:_ Linux, Windows, Mac; since version 1.3.0.
1901
+
1902
+ ## Repeating the Tests ##
1903
+
1904
+ Once in a while you'll run into a test whose result is hit-or-miss. Perhaps it
1905
+ will fail only 1% of the time, making it rather hard to reproduce the bug under
1906
+ a debugger. This can be a major source of frustration.
1907
+
1908
+ The `--gtest_repeat` flag allows you to repeat all (or selected) test methods
1909
+ in a program many times. Hopefully, a flaky test will eventually fail and give
1910
+ you a chance to debug. Here's how to use it:
1911
+
1912
+ | `$ foo_test --gtest_repeat=1000` | Repeat foo\_test 1000 times and don't stop at failures. |
1913
+ |:---------------------------------|:--------------------------------------------------------|
1914
+ | `$ foo_test --gtest_repeat=-1` | A negative count means repeating forever. |
1915
+ | `$ foo_test --gtest_repeat=1000 --gtest_break_on_failure` | Repeat foo\_test 1000 times, stopping at the first failure. This is especially useful when running under a debugger: when the testfails, it will drop into the debugger and you can then inspect variables and stacks. |
1916
+ | `$ foo_test --gtest_repeat=1000 --gtest_filter=FooBar` | Repeat the tests whose name matches the filter 1000 times. |
1917
+
1918
+ If your test program contains global set-up/tear-down code registered
1919
+ using `AddGlobalTestEnvironment()`, it will be repeated in each
1920
+ iteration as well, as the flakiness may be in it. You can also specify
1921
+ the repeat count by setting the `GTEST_REPEAT` environment variable.
1922
+
1923
+ _Availability:_ Linux, Windows, Mac.
1924
+
1925
+ ## Shuffling the Tests ##
1926
+
1927
+ You can specify the `--gtest_shuffle` flag (or set the `GTEST_SHUFFLE`
1928
+ environment variable to `1`) to run the tests in a program in a random
1929
+ order. This helps to reveal bad dependencies between tests.
1930
+
1931
+ By default, Google Test uses a random seed calculated from the current
1932
+ time. Therefore you'll get a different order every time. The console
1933
+ output includes the random seed value, such that you can reproduce an
1934
+ order-related test failure later. To specify the random seed
1935
+ explicitly, use the `--gtest_random_seed=SEED` flag (or set the
1936
+ `GTEST_RANDOM_SEED` environment variable), where `SEED` is an integer
1937
+ between 0 and 99999. The seed value 0 is special: it tells Google Test
1938
+ to do the default behavior of calculating the seed from the current
1939
+ time.
1940
+
1941
+ If you combine this with `--gtest_repeat=N`, Google Test will pick a
1942
+ different random seed and re-shuffle the tests in each iteration.
1943
+
1944
+ _Availability:_ Linux, Windows, Mac; since v1.4.0.
1945
+
1946
+ ## Controlling Test Output ##
1947
+
1948
+ This section teaches how to tweak the way test results are reported.
1949
+
1950
+ ### Colored Terminal Output ###
1951
+
1952
+ Google Test can use colors in its terminal output to make it easier to spot
1953
+ the separation between tests, and whether tests passed.
1954
+
1955
+ You can set the GTEST\_COLOR environment variable or set the `--gtest_color`
1956
+ command line flag to `yes`, `no`, or `auto` (the default) to enable colors,
1957
+ disable colors, or let Google Test decide. When the value is `auto`, Google
1958
+ Test will use colors if and only if the output goes to a terminal and (on
1959
+ non-Windows platforms) the `TERM` environment variable is set to `xterm` or
1960
+ `xterm-color`.
1961
+
1962
+ _Availability:_ Linux, Windows, Mac.
1963
+
1964
+ ### Suppressing the Elapsed Time ###
1965
+
1966
+ By default, Google Test prints the time it takes to run each test. To
1967
+ suppress that, run the test program with the `--gtest_print_time=0`
1968
+ command line flag. Setting the `GTEST_PRINT_TIME` environment
1969
+ variable to `0` has the same effect.
1970
+
1971
+ _Availability:_ Linux, Windows, Mac. (In Google Test 1.3.0 and lower,
1972
+ the default behavior is that the elapsed time is **not** printed.)
1973
+
1974
+ **Availability**: Linux, Windows, Mac.
1975
+
1976
+ #### Suppressing UTF-8 Text Output
1977
+
1978
+ In case of assertion failures, gUnit prints expected and actual values of type
1979
+ `string` both as hex-encoded strings as well as in readable UTF-8 text if they
1980
+ contain valid non-ASCII UTF-8 characters. If you want to suppress the UTF-8 text
1981
+ because, for example, you don't have an UTF-8 compatible output medium, run the
1982
+ test program with `--gunit_print_utf8=0` or set the `GUNIT_PRINT_UTF8`
1983
+ environment variable to `0`.
1984
+
1985
+ ### Generating an XML Report ###
1986
+
1987
+ Google Test can emit a detailed XML report to a file in addition to its normal
1988
+ textual output. The report contains the duration of each test, and thus can
1989
+ help you identify slow tests.
1990
+
1991
+ To generate the XML report, set the `GTEST_OUTPUT` environment variable or the
1992
+ `--gtest_output` flag to the string `"xml:_path_to_output_file_"`, which will
1993
+ create the file at the given location. You can also just use the string
1994
+ `"xml"`, in which case the output can be found in the `test_detail.xml` file in
1995
+ the current directory.
1996
+
1997
+ If you specify a directory (for example, `"xml:output/directory/"` on Linux or
1998
+ `"xml:output\directory\"` on Windows), Google Test will create the XML file in
1999
+ that directory, named after the test executable (e.g. `foo_test.xml` for test
2000
+ program `foo_test` or `foo_test.exe`). If the file already exists (perhaps left
2001
+ over from a previous run), Google Test will pick a different name (e.g.
2002
+ `foo_test_1.xml`) to avoid overwriting it.
2003
+
2004
+ The report uses the format described here. It is based on the
2005
+ `junitreport` Ant task and can be parsed by popular continuous build
2006
+ systems like [Hudson](https://hudson.dev.java.net/). Since that format
2007
+ was originally intended for Java, a little interpretation is required
2008
+ to make it apply to Google Test tests, as shown here:
2009
+
2010
+ ```
2011
+ <testsuites name="AllTests" ...>
2012
+ <testsuite name="test_case_name" ...>
2013
+ <testcase name="test_name" ...>
2014
+ <failure message="..."/>
2015
+ <failure message="..."/>
2016
+ <failure message="..."/>
2017
+ </testcase>
2018
+ </testsuite>
2019
+ </testsuites>
2020
+ ```
2021
+
2022
+ * The root `<testsuites>` element corresponds to the entire test program.
2023
+ * `<testsuite>` elements correspond to Google Test test cases.
2024
+ * `<testcase>` elements correspond to Google Test test functions.
2025
+
2026
+ For instance, the following program
2027
+
2028
+ ```
2029
+ TEST(MathTest, Addition) { ... }
2030
+ TEST(MathTest, Subtraction) { ... }
2031
+ TEST(LogicTest, NonContradiction) { ... }
2032
+ ```
2033
+
2034
+ could generate this report:
2035
+
2036
+ ```
2037
+ <?xml version="1.0" encoding="UTF-8"?>
2038
+ <testsuites tests="3" failures="1" errors="0" time="35" name="AllTests">
2039
+ <testsuite name="MathTest" tests="2" failures="1" errors="0" time="15">
2040
+ <testcase name="Addition" status="run" time="7" classname="">
2041
+ <failure message="Value of: add(1, 1)&#x0A; Actual: 3&#x0A;Expected: 2" type=""/>
2042
+ <failure message="Value of: add(1, -1)&#x0A; Actual: 1&#x0A;Expected: 0" type=""/>
2043
+ </testcase>
2044
+ <testcase name="Subtraction" status="run" time="5" classname="">
2045
+ </testcase>
2046
+ </testsuite>
2047
+ <testsuite name="LogicTest" tests="1" failures="0" errors="0" time="5">
2048
+ <testcase name="NonContradiction" status="run" time="5" classname="">
2049
+ </testcase>
2050
+ </testsuite>
2051
+ </testsuites>
2052
+ ```
2053
+
2054
+ Things to note:
2055
+
2056
+ * The `tests` attribute of a `<testsuites>` or `<testsuite>` element tells how many test functions the Google Test program or test case contains, while the `failures` attribute tells how many of them failed.
2057
+ * The `time` attribute expresses the duration of the test, test case, or entire test program in milliseconds.
2058
+ * Each `<failure>` element corresponds to a single failed Google Test assertion.
2059
+ * Some JUnit concepts don't apply to Google Test, yet we have to conform to the DTD. Therefore you'll see some dummy elements and attributes in the report. You can safely ignore these parts.
2060
+
2061
+ _Availability:_ Linux, Windows, Mac.
2062
+
2063
+ #### Generating an JSON Report {#JsonReport}
2064
+
2065
+ gUnit can also emit a JSON report as an alternative format to XML. To generate
2066
+ the JSON report, set the `GUNIT_OUTPUT` environment variable or the
2067
+ `--gunit_output` flag to the string `"json:path_to_output_file"`, which will
2068
+ create the file at the given location. You can also just use the string
2069
+ `"json"`, in which case the output can be found in the `test_detail.json` file
2070
+ in the current directory.
2071
+
2072
+ The report format conforms to the following JSON Schema:
2073
+
2074
+ ```json
2075
+ {
2076
+ "$schema": "http://json-schema.org/schema#",
2077
+ "type": "object",
2078
+ "definitions": {
2079
+ "TestCase": {
2080
+ "type": "object",
2081
+ "properties": {
2082
+ "name": { "type": "string" },
2083
+ "tests": { "type": "integer" },
2084
+ "failures": { "type": "integer" },
2085
+ "disabled": { "type": "integer" },
2086
+ "time": { "type": "string" },
2087
+ "testsuite": {
2088
+ "type": "array",
2089
+ "items": {
2090
+ "$ref": "#/definitions/TestInfo"
2091
+ }
2092
+ }
2093
+ }
2094
+ },
2095
+ "TestInfo": {
2096
+ "type": "object",
2097
+ "properties": {
2098
+ "name": { "type": "string" },
2099
+ "status": {
2100
+ "type": "string",
2101
+ "enum": ["RUN", "NOTRUN"]
2102
+ },
2103
+ "time": { "type": "string" },
2104
+ "classname": { "type": "string" },
2105
+ "failures": {
2106
+ "type": "array",
2107
+ "items": {
2108
+ "$ref": "#/definitions/Failure"
2109
+ }
2110
+ }
2111
+ }
2112
+ },
2113
+ "Failure": {
2114
+ "type": "object",
2115
+ "properties": {
2116
+ "failures": { "type": "string" },
2117
+ "type": { "type": "string" }
2118
+ }
2119
+ }
2120
+ },
2121
+ "properties": {
2122
+ "tests": { "type": "integer" },
2123
+ "failures": { "type": "integer" },
2124
+ "disabled": { "type": "integer" },
2125
+ "errors": { "type": "integer" },
2126
+ "timestamp": {
2127
+ "type": "string",
2128
+ "format": "date-time"
2129
+ },
2130
+ "time": { "type": "string" },
2131
+ "name": { "type": "string" },
2132
+ "testsuites": {
2133
+ "type": "array",
2134
+ "items": {
2135
+ "$ref": "#/definitions/TestCase"
2136
+ }
2137
+ }
2138
+ }
2139
+ }
2140
+ ```
2141
+
2142
+ The report uses the format that conforms to the following Proto3 using the
2143
+ [JSON encoding](https://developers.google.com/protocol-buffers/docs/proto3#json):
2144
+
2145
+ ```proto
2146
+ syntax = "proto3";
2147
+
2148
+ package googletest;
2149
+
2150
+ import "google/protobuf/timestamp.proto";
2151
+ import "google/protobuf/duration.proto";
2152
+
2153
+ message UnitTest {
2154
+ int32 tests = 1;
2155
+ int32 failures = 2;
2156
+ int32 disabled = 3;
2157
+ int32 errors = 4;
2158
+ google.protobuf.Timestamp timestamp = 5;
2159
+ google.protobuf.Duration time = 6;
2160
+ string name = 7;
2161
+ repeated TestCase testsuites = 8;
2162
+ }
2163
+
2164
+ message TestCase {
2165
+ string name = 1;
2166
+ int32 tests = 2;
2167
+ int32 failures = 3;
2168
+ int32 disabled = 4;
2169
+ int32 errors = 5;
2170
+ google.protobuf.Duration time = 6;
2171
+ repeated TestInfo testsuite = 7;
2172
+ }
2173
+
2174
+ message TestInfo {
2175
+ string name = 1;
2176
+ enum Status {
2177
+ RUN = 0;
2178
+ NOTRUN = 1;
2179
+ }
2180
+ Status status = 2;
2181
+ google.protobuf.Duration time = 3;
2182
+ string classname = 4;
2183
+ message Failure {
2184
+ string failures = 1;
2185
+ string type = 2;
2186
+ }
2187
+ repeated Failure failures = 5;
2188
+ }
2189
+ ```
2190
+
2191
+ For instance, the following program
2192
+
2193
+ ```c++
2194
+ TEST(MathTest, Addition) { ... }
2195
+ TEST(MathTest, Subtraction) { ... }
2196
+ TEST(LogicTest, NonContradiction) { ... }
2197
+ ```
2198
+
2199
+ could generate this report:
2200
+
2201
+ ```json
2202
+ {
2203
+ "tests": 3,
2204
+ "failures": 1,
2205
+ "errors": 0,
2206
+ "time": "0.035s",
2207
+ "timestamp": "2011-10-31T18:52:42Z"
2208
+ "name": "AllTests",
2209
+ "testsuites": [
2210
+ {
2211
+ "name": "MathTest",
2212
+ "tests": 2,
2213
+ "failures": 1,
2214
+ "errors": 0,
2215
+ "time": "0.015s",
2216
+ "testsuite": [
2217
+ {
2218
+ "name": "Addition",
2219
+ "status": "RUN",
2220
+ "time": "0.007s",
2221
+ "classname": "",
2222
+ "failures": [
2223
+ {
2224
+ "message": "Value of: add(1, 1)\x0A Actual: 3\x0AExpected: 2",
2225
+ "type": ""
2226
+ },
2227
+ {
2228
+ "message": "Value of: add(1, -1)\x0A Actual: 1\x0AExpected: 0",
2229
+ "type": ""
2230
+ }
2231
+ ]
2232
+ },
2233
+ {
2234
+ "name": "Subtraction",
2235
+ "status": "RUN",
2236
+ "time": "0.005s",
2237
+ "classname": ""
2238
+ }
2239
+ ]
2240
+ }
2241
+ {
2242
+ "name": "LogicTest",
2243
+ "tests": 1,
2244
+ "failures": 0,
2245
+ "errors": 0,
2246
+ "time": "0.005s",
2247
+ "testsuite": [
2248
+ {
2249
+ "name": "NonContradiction",
2250
+ "status": "RUN",
2251
+ "time": "0.005s",
2252
+ "classname": ""
2253
+ }
2254
+ ]
2255
+ }
2256
+ ]
2257
+ }
2258
+ ```
2259
+
2260
+ IMPORTANT: The exact format of the JSON document is subject to change.
2261
+
2262
+ **Availability**: Linux, Windows, Mac.
2263
+
2264
+ ## Controlling How Failures Are Reported ##
2265
+
2266
+ ### Turning Assertion Failures into Break-Points ###
2267
+
2268
+ When running test programs under a debugger, it's very convenient if the
2269
+ debugger can catch an assertion failure and automatically drop into interactive
2270
+ mode. Google Test's _break-on-failure_ mode supports this behavior.
2271
+
2272
+ To enable it, set the `GTEST_BREAK_ON_FAILURE` environment variable to a value
2273
+ other than `0` . Alternatively, you can use the `--gtest_break_on_failure`
2274
+ command line flag.
2275
+
2276
+ _Availability:_ Linux, Windows, Mac.
2277
+
2278
+ ### Disabling Catching Test-Thrown Exceptions ###
2279
+
2280
+ Google Test can be used either with or without exceptions enabled. If
2281
+ a test throws a C++ exception or (on Windows) a structured exception
2282
+ (SEH), by default Google Test catches it, reports it as a test
2283
+ failure, and continues with the next test method. This maximizes the
2284
+ coverage of a test run. Also, on Windows an uncaught exception will
2285
+ cause a pop-up window, so catching the exceptions allows you to run
2286
+ the tests automatically.
2287
+
2288
+ When debugging the test failures, however, you may instead want the
2289
+ exceptions to be handled by the debugger, such that you can examine
2290
+ the call stack when an exception is thrown. To achieve that, set the
2291
+ `GTEST_CATCH_EXCEPTIONS` environment variable to `0`, or use the
2292
+ `--gtest_catch_exceptions=0` flag when running the tests.
2293
+
2294
+ **Availability**: Linux, Windows, Mac.
2295
+
2296
+ ### Letting Another Testing Framework Drive ###
2297
+
2298
+ If you work on a project that has already been using another testing
2299
+ framework and is not ready to completely switch to Google Test yet,
2300
+ you can get much of Google Test's benefit by using its assertions in
2301
+ your existing tests. Just change your `main()` function to look
2302
+ like:
2303
+
2304
+ ```
2305
+ #include "gtest/gtest.h"
2306
+
2307
+ int main(int argc, char** argv) {
2308
+ ::testing::GTEST_FLAG(throw_on_failure) = true;
2309
+ // Important: Google Test must be initialized.
2310
+ ::testing::InitGoogleTest(&argc, argv);
2311
+
2312
+ ... whatever your existing testing framework requires ...
2313
+ }
2314
+ ```
2315
+
2316
+ With that, you can use Google Test assertions in addition to the
2317
+ native assertions your testing framework provides, for example:
2318
+
2319
+ ```
2320
+ void TestFooDoesBar() {
2321
+ Foo foo;
2322
+ EXPECT_LE(foo.Bar(1), 100); // A Google Test assertion.
2323
+ CPPUNIT_ASSERT(foo.IsEmpty()); // A native assertion.
2324
+ }
2325
+ ```
2326
+
2327
+ If a Google Test assertion fails, it will print an error message and
2328
+ throw an exception, which will be treated as a failure by your host
2329
+ testing framework. If you compile your code with exceptions disabled,
2330
+ a failed Google Test assertion will instead exit your program with a
2331
+ non-zero code, which will also signal a test failure to your test
2332
+ runner.
2333
+
2334
+ If you don't write `::testing::GTEST_FLAG(throw_on_failure) = true;` in
2335
+ your `main()`, you can alternatively enable this feature by specifying
2336
+ the `--gtest_throw_on_failure` flag on the command-line or setting the
2337
+ `GTEST_THROW_ON_FAILURE` environment variable to a non-zero value.
2338
+
2339
+ Death tests are _not_ supported when other test framework is used to organize tests.
2340
+
2341
+ _Availability:_ Linux, Windows, Mac; since v1.3.0.
2342
+
2343
+ ## Distributing Test Functions to Multiple Machines ##
2344
+
2345
+ If you have more than one machine you can use to run a test program,
2346
+ you might want to run the test functions in parallel and get the
2347
+ result faster. We call this technique _sharding_, where each machine
2348
+ is called a _shard_.
2349
+
2350
+ Google Test is compatible with test sharding. To take advantage of
2351
+ this feature, your test runner (not part of Google Test) needs to do
2352
+ the following:
2353
+
2354
+ 1. Allocate a number of machines (shards) to run the tests.
2355
+ 1. On each shard, set the `GTEST_TOTAL_SHARDS` environment variable to the total number of shards. It must be the same for all shards.
2356
+ 1. On each shard, set the `GTEST_SHARD_INDEX` environment variable to the index of the shard. Different shards must be assigned different indices, which must be in the range `[0, GTEST_TOTAL_SHARDS - 1]`.
2357
+ 1. Run the same test program on all shards. When Google Test sees the above two environment variables, it will select a subset of the test functions to run. Across all shards, each test function in the program will be run exactly once.
2358
+ 1. Wait for all shards to finish, then collect and report the results.
2359
+
2360
+ Your project may have tests that were written without Google Test and
2361
+ thus don't understand this protocol. In order for your test runner to
2362
+ figure out which test supports sharding, it can set the environment
2363
+ variable `GTEST_SHARD_STATUS_FILE` to a non-existent file path. If a
2364
+ test program supports sharding, it will create this file to
2365
+ acknowledge the fact (the actual contents of the file are not
2366
+ important at this time; although we may stick some useful information
2367
+ in it in the future.); otherwise it will not create it.
2368
+
2369
+ Here's an example to make it clear. Suppose you have a test program
2370
+ `foo_test` that contains the following 5 test functions:
2371
+ ```
2372
+ TEST(A, V)
2373
+ TEST(A, W)
2374
+ TEST(B, X)
2375
+ TEST(B, Y)
2376
+ TEST(B, Z)
2377
+ ```
2378
+ and you have 3 machines at your disposal. To run the test functions in
2379
+ parallel, you would set `GTEST_TOTAL_SHARDS` to 3 on all machines, and
2380
+ set `GTEST_SHARD_INDEX` to 0, 1, and 2 on the machines respectively.
2381
+ Then you would run the same `foo_test` on each machine.
2382
+
2383
+ Google Test reserves the right to change how the work is distributed
2384
+ across the shards, but here's one possible scenario:
2385
+
2386
+ * Machine #0 runs `A.V` and `B.X`.
2387
+ * Machine #1 runs `A.W` and `B.Y`.
2388
+ * Machine #2 runs `B.Z`.
2389
+
2390
+ _Availability:_ Linux, Windows, Mac; since version 1.3.0.
2391
+
2392
+ # Fusing Google Test Source Files #
2393
+
2394
+ Google Test's implementation consists of ~30 files (excluding its own
2395
+ tests). Sometimes you may want them to be packaged up in two files (a
2396
+ `.h` and a `.cc`) instead, such that you can easily copy them to a new
2397
+ machine and start hacking there. For this we provide an experimental
2398
+ Python script `fuse_gtest_files.py` in the `scripts/` directory (since release 1.3.0).
2399
+ Assuming you have Python 2.4 or above installed on your machine, just
2400
+ go to that directory and run
2401
+ ```
2402
+ python fuse_gtest_files.py OUTPUT_DIR
2403
+ ```
2404
+
2405
+ and you should see an `OUTPUT_DIR` directory being created with files
2406
+ `gtest/gtest.h` and `gtest/gtest-all.cc` in it. These files contain
2407
+ everything you need to use Google Test. Just copy them to anywhere
2408
+ you want and you are ready to write tests. You can use the
2409
+ [scripts/test/Makefile](../scripts/test/Makefile)
2410
+ file as an example on how to compile your tests against them.
2411
+
2412
+ # Where to Go from Here #
2413
+
2414
+ Congratulations! You've now learned more advanced Google Test tools and are
2415
+ ready to tackle more complex testing tasks. If you want to dive even deeper, you
2416
+ can read the [Frequently-Asked Questions](faq.md).