rugged 0.1.2 → 0.16.0b1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (277) hide show
  1. data/README.md +25 -36
  2. data/Rakefile +20 -98
  3. data/ext/rugged/extconf.rb +44 -4
  4. data/ext/rugged/remote.c +215 -0
  5. data/ext/rugged/rugged.c +171 -0
  6. data/ext/rugged/rugged.h +126 -0
  7. data/ext/rugged/rugged_blob.c +99 -0
  8. data/ext/rugged/rugged_commit.c +224 -0
  9. data/ext/rugged/rugged_config.c +238 -0
  10. data/ext/rugged/rugged_index.c +440 -0
  11. data/ext/rugged/rugged_object.c +203 -0
  12. data/ext/rugged/rugged_reference.c +401 -0
  13. data/ext/rugged/rugged_repo.c +482 -0
  14. data/ext/rugged/rugged_revwalk.c +138 -0
  15. data/ext/rugged/rugged_signature.c +80 -0
  16. data/ext/rugged/rugged_tag.c +216 -0
  17. data/ext/rugged/rugged_tree.c +322 -0
  18. data/ext/rugged/vendor/libgit2-dist.tar.gz +0 -0
  19. data/ext/rugged/vendor/libgit2-dist/deps/http-parser/http_parser.c +1778 -0
  20. data/ext/rugged/vendor/libgit2-dist/deps/http-parser/http_parser.h +267 -0
  21. data/ext/rugged/vendor/libgit2-dist/deps/zlib/adler32.c +169 -0
  22. data/ext/rugged/vendor/libgit2-dist/deps/zlib/crc32.c +442 -0
  23. data/ext/rugged/vendor/libgit2-dist/deps/zlib/crc32.h +441 -0
  24. data/ext/rugged/vendor/libgit2-dist/deps/zlib/deflate.c +1834 -0
  25. data/ext/rugged/vendor/libgit2-dist/deps/zlib/deflate.h +342 -0
  26. data/ext/rugged/vendor/libgit2-dist/deps/zlib/inffast.c +340 -0
  27. data/ext/rugged/vendor/libgit2-dist/deps/zlib/inffast.h +11 -0
  28. data/ext/rugged/vendor/libgit2-dist/deps/zlib/inffixed.h +94 -0
  29. data/ext/rugged/vendor/libgit2-dist/deps/zlib/inflate.c +1480 -0
  30. data/ext/rugged/vendor/libgit2-dist/deps/zlib/inflate.h +122 -0
  31. data/ext/rugged/vendor/libgit2-dist/deps/zlib/inftrees.c +330 -0
  32. data/ext/rugged/vendor/libgit2-dist/deps/zlib/inftrees.h +62 -0
  33. data/ext/rugged/vendor/libgit2-dist/deps/zlib/trees.c +1244 -0
  34. data/ext/rugged/vendor/libgit2-dist/deps/zlib/trees.h +128 -0
  35. data/ext/rugged/vendor/libgit2-dist/deps/zlib/zconf.h +54 -0
  36. data/ext/rugged/vendor/libgit2-dist/deps/zlib/zlib.h +1613 -0
  37. data/ext/rugged/vendor/libgit2-dist/deps/zlib/zutil.c +318 -0
  38. data/ext/rugged/vendor/libgit2-dist/deps/zlib/zutil.h +274 -0
  39. data/ext/rugged/vendor/libgit2-dist/examples/general.c +451 -0
  40. data/ext/rugged/vendor/libgit2-dist/examples/network/common.h +14 -0
  41. data/ext/rugged/vendor/libgit2-dist/examples/network/fetch.c +97 -0
  42. data/ext/rugged/vendor/libgit2-dist/examples/network/git2.c +58 -0
  43. data/ext/rugged/vendor/libgit2-dist/examples/network/index-pack.c +47 -0
  44. data/ext/rugged/vendor/libgit2-dist/examples/network/ls-remote.c +76 -0
  45. data/ext/rugged/vendor/libgit2-dist/examples/showindex.c +43 -0
  46. data/ext/rugged/vendor/libgit2-dist/include/git2.h +44 -0
  47. data/ext/rugged/vendor/libgit2-dist/include/git2/blob.h +120 -0
  48. data/ext/rugged/vendor/libgit2-dist/include/git2/branch.h +15 -0
  49. data/ext/rugged/vendor/libgit2-dist/include/git2/commit.h +263 -0
  50. data/ext/rugged/vendor/libgit2-dist/include/git2/common.h +103 -0
  51. data/ext/rugged/vendor/libgit2-dist/include/git2/config.h +278 -0
  52. data/ext/rugged/vendor/libgit2-dist/include/git2/errors.h +144 -0
  53. data/ext/rugged/vendor/libgit2-dist/include/git2/index.h +306 -0
  54. data/ext/rugged/vendor/libgit2-dist/include/git2/indexer.h +76 -0
  55. data/ext/rugged/vendor/libgit2-dist/include/git2/inttypes.h +305 -0
  56. data/ext/rugged/vendor/libgit2-dist/include/git2/net.h +51 -0
  57. data/ext/rugged/vendor/libgit2-dist/include/git2/object.h +173 -0
  58. data/ext/rugged/vendor/libgit2-dist/include/git2/odb.h +331 -0
  59. data/ext/rugged/vendor/libgit2-dist/include/git2/odb_backend.h +100 -0
  60. data/ext/rugged/vendor/libgit2-dist/include/git2/oid.h +218 -0
  61. data/ext/rugged/vendor/libgit2-dist/include/git2/reflog.h +128 -0
  62. data/ext/rugged/vendor/libgit2-dist/include/git2/refs.h +309 -0
  63. data/ext/rugged/vendor/libgit2-dist/include/git2/refspec.h +60 -0
  64. data/ext/rugged/vendor/libgit2-dist/include/git2/remote.h +176 -0
  65. data/ext/rugged/vendor/libgit2-dist/include/git2/repository.h +290 -0
  66. data/ext/rugged/vendor/libgit2-dist/include/git2/revwalk.h +169 -0
  67. data/ext/rugged/vendor/libgit2-dist/include/git2/signature.h +65 -0
  68. data/ext/rugged/vendor/libgit2-dist/include/git2/status.h +63 -0
  69. data/ext/rugged/vendor/libgit2-dist/include/git2/stdint.h +247 -0
  70. data/ext/rugged/vendor/libgit2-dist/include/git2/tag.h +279 -0
  71. data/ext/rugged/vendor/libgit2-dist/include/git2/threads.h +48 -0
  72. data/ext/rugged/vendor/libgit2-dist/include/git2/tree.h +318 -0
  73. data/ext/rugged/vendor/libgit2-dist/include/git2/types.h +169 -0
  74. data/ext/rugged/vendor/libgit2-dist/include/git2/version.h +15 -0
  75. data/ext/rugged/vendor/libgit2-dist/include/git2/windows.h +59 -0
  76. data/ext/rugged/vendor/libgit2-dist/include/git2/zlib.h +40 -0
  77. data/ext/rugged/vendor/libgit2-dist/src/blob.c +135 -0
  78. data/ext/rugged/vendor/libgit2-dist/src/blob.h +23 -0
  79. data/ext/rugged/vendor/libgit2-dist/src/bswap.h +97 -0
  80. data/ext/rugged/vendor/libgit2-dist/src/buffer.c +113 -0
  81. data/ext/rugged/vendor/libgit2-dist/src/buffer.h +32 -0
  82. data/ext/rugged/vendor/libgit2-dist/src/cache.c +111 -0
  83. data/ext/rugged/vendor/libgit2-dist/src/cache.h +64 -0
  84. data/ext/rugged/vendor/libgit2-dist/src/cc-compat.h +67 -0
  85. data/ext/rugged/vendor/libgit2-dist/src/commit.c +299 -0
  86. data/ext/rugged/vendor/libgit2-dist/src/commit.h +34 -0
  87. data/ext/rugged/vendor/libgit2-dist/src/common.h +64 -0
  88. data/ext/rugged/vendor/libgit2-dist/src/config.c +418 -0
  89. data/ext/rugged/vendor/libgit2-dist/src/config.h +24 -0
  90. data/ext/rugged/vendor/libgit2-dist/src/config_file.c +1210 -0
  91. data/ext/rugged/vendor/libgit2-dist/src/delta-apply.c +115 -0
  92. data/ext/rugged/vendor/libgit2-dist/src/delta-apply.h +33 -0
  93. data/ext/rugged/vendor/libgit2-dist/src/dir.h +47 -0
  94. data/ext/rugged/vendor/libgit2-dist/src/errors.c +104 -0
  95. data/ext/rugged/vendor/libgit2-dist/src/fetch.c +172 -0
  96. data/ext/rugged/vendor/libgit2-dist/src/fetch.h +18 -0
  97. data/ext/rugged/vendor/libgit2-dist/src/filebuf.c +400 -0
  98. data/ext/rugged/vendor/libgit2-dist/src/filebuf.h +72 -0
  99. data/ext/rugged/vendor/libgit2-dist/src/fileops.c +358 -0
  100. data/ext/rugged/vendor/libgit2-dist/src/fileops.h +151 -0
  101. data/ext/rugged/vendor/libgit2-dist/src/global.c +134 -0
  102. data/ext/rugged/vendor/libgit2-dist/src/global.h +24 -0
  103. data/ext/rugged/vendor/libgit2-dist/src/hash.c +74 -0
  104. data/ext/rugged/vendor/libgit2-dist/src/hash.h +29 -0
  105. data/ext/rugged/vendor/libgit2-dist/src/hashtable.c +243 -0
  106. data/ext/rugged/vendor/libgit2-dist/src/hashtable.h +80 -0
  107. data/ext/rugged/vendor/libgit2-dist/src/index.c +918 -0
  108. data/ext/rugged/vendor/libgit2-dist/src/index.h +34 -0
  109. data/ext/rugged/vendor/libgit2-dist/src/indexer.c +401 -0
  110. data/ext/rugged/vendor/libgit2-dist/src/map.h +37 -0
  111. data/ext/rugged/vendor/libgit2-dist/src/mwindow.c +272 -0
  112. data/ext/rugged/vendor/libgit2-dist/src/mwindow.h +45 -0
  113. data/ext/rugged/vendor/libgit2-dist/src/netops.c +198 -0
  114. data/ext/rugged/vendor/libgit2-dist/src/netops.h +36 -0
  115. data/ext/rugged/vendor/libgit2-dist/src/object.c +295 -0
  116. data/ext/rugged/vendor/libgit2-dist/src/odb.c +672 -0
  117. data/ext/rugged/vendor/libgit2-dist/src/odb.h +43 -0
  118. data/ext/rugged/vendor/libgit2-dist/src/odb_loose.c +855 -0
  119. data/ext/rugged/vendor/libgit2-dist/src/odb_pack.c +485 -0
  120. data/ext/rugged/vendor/libgit2-dist/src/oid.c +388 -0
  121. data/ext/rugged/vendor/libgit2-dist/src/pack.c +788 -0
  122. data/ext/rugged/vendor/libgit2-dist/src/pack.h +99 -0
  123. data/ext/rugged/vendor/libgit2-dist/src/path.c +270 -0
  124. data/ext/rugged/vendor/libgit2-dist/src/path.h +84 -0
  125. data/ext/rugged/vendor/libgit2-dist/src/pkt.c +426 -0
  126. data/ext/rugged/vendor/libgit2-dist/src/pkt.h +77 -0
  127. data/ext/rugged/vendor/libgit2-dist/src/posix.c +94 -0
  128. data/ext/rugged/vendor/libgit2-dist/src/posix.h +69 -0
  129. data/ext/rugged/vendor/libgit2-dist/src/ppc/sha1.c +70 -0
  130. data/ext/rugged/vendor/libgit2-dist/src/ppc/sha1.h +26 -0
  131. data/ext/rugged/vendor/libgit2-dist/src/pqueue.c +141 -0
  132. data/ext/rugged/vendor/libgit2-dist/src/pqueue.h +81 -0
  133. data/ext/rugged/vendor/libgit2-dist/src/protocol.c +50 -0
  134. data/ext/rugged/vendor/libgit2-dist/src/protocol.h +23 -0
  135. data/ext/rugged/vendor/libgit2-dist/src/reflog.c +318 -0
  136. data/ext/rugged/vendor/libgit2-dist/src/reflog.h +34 -0
  137. data/ext/rugged/vendor/libgit2-dist/src/refs.c +1693 -0
  138. data/ext/rugged/vendor/libgit2-dist/src/refs.h +58 -0
  139. data/ext/rugged/vendor/libgit2-dist/src/refspec.c +95 -0
  140. data/ext/rugged/vendor/libgit2-dist/src/refspec.h +23 -0
  141. data/ext/rugged/vendor/libgit2-dist/src/remote.c +339 -0
  142. data/ext/rugged/vendor/libgit2-dist/src/remote.h +25 -0
  143. data/ext/rugged/vendor/libgit2-dist/src/repository.c +849 -0
  144. data/ext/rugged/vendor/libgit2-dist/src/repository.h +60 -0
  145. data/ext/rugged/vendor/libgit2-dist/src/revwalk.c +569 -0
  146. data/ext/rugged/vendor/libgit2-dist/src/sha1.c +280 -0
  147. data/ext/rugged/vendor/libgit2-dist/src/sha1.h +21 -0
  148. data/ext/rugged/vendor/libgit2-dist/src/sha1_lookup.c +177 -0
  149. data/ext/rugged/vendor/libgit2-dist/src/sha1_lookup.h +18 -0
  150. data/ext/rugged/vendor/libgit2-dist/src/signature.c +335 -0
  151. data/ext/rugged/vendor/libgit2-dist/src/signature.h +18 -0
  152. data/ext/rugged/vendor/libgit2-dist/src/status.c +696 -0
  153. data/ext/rugged/vendor/libgit2-dist/src/tag.c +446 -0
  154. data/ext/rugged/vendor/libgit2-dist/src/tag.h +28 -0
  155. data/ext/rugged/vendor/libgit2-dist/src/thread-utils.c +55 -0
  156. data/ext/rugged/vendor/libgit2-dist/src/thread-utils.h +108 -0
  157. data/ext/rugged/vendor/libgit2-dist/src/transport.c +85 -0
  158. data/ext/rugged/vendor/libgit2-dist/src/transport.h +110 -0
  159. data/ext/rugged/vendor/libgit2-dist/src/transports/git.c +502 -0
  160. data/ext/rugged/vendor/libgit2-dist/src/transports/http.c +756 -0
  161. data/ext/rugged/vendor/libgit2-dist/src/transports/local.c +235 -0
  162. data/ext/rugged/vendor/libgit2-dist/src/tree-cache.c +201 -0
  163. data/ext/rugged/vendor/libgit2-dist/src/tree-cache.h +31 -0
  164. data/ext/rugged/vendor/libgit2-dist/src/tree.c +758 -0
  165. data/ext/rugged/vendor/libgit2-dist/src/tree.h +37 -0
  166. data/ext/rugged/vendor/libgit2-dist/src/tsort.c +365 -0
  167. data/ext/rugged/vendor/libgit2-dist/src/unix/map.c +70 -0
  168. data/ext/rugged/vendor/libgit2-dist/src/unix/posix.h +25 -0
  169. data/ext/rugged/vendor/libgit2-dist/src/util.c +381 -0
  170. data/ext/rugged/vendor/libgit2-dist/src/util.h +137 -0
  171. data/ext/rugged/vendor/libgit2-dist/src/vector.c +174 -0
  172. data/ext/rugged/vendor/libgit2-dist/src/vector.h +45 -0
  173. data/ext/rugged/vendor/libgit2-dist/src/win32/dir.c +115 -0
  174. data/ext/rugged/vendor/libgit2-dist/src/win32/fnmatch.c +180 -0
  175. data/ext/rugged/vendor/libgit2-dist/src/win32/fnmatch.h +27 -0
  176. data/ext/rugged/vendor/libgit2-dist/src/win32/map.c +131 -0
  177. data/ext/rugged/vendor/libgit2-dist/src/win32/mingw-compat.h +24 -0
  178. data/ext/rugged/vendor/libgit2-dist/src/win32/msvc-compat.h +38 -0
  179. data/ext/rugged/vendor/libgit2-dist/src/win32/posix.h +53 -0
  180. data/ext/rugged/vendor/libgit2-dist/src/win32/posix_w32.c +404 -0
  181. data/ext/rugged/vendor/libgit2-dist/src/win32/pthread.c +65 -0
  182. data/ext/rugged/vendor/libgit2-dist/src/win32/pthread.h +40 -0
  183. data/ext/rugged/vendor/libgit2-dist/src/win32/utf-conv.c +88 -0
  184. data/ext/rugged/vendor/libgit2-dist/src/win32/utf-conv.h +17 -0
  185. data/ext/rugged/vendor/libgit2-dist/tests-clay/buf/basic.c +29 -0
  186. data/ext/rugged/vendor/libgit2-dist/tests-clay/clay.h +187 -0
  187. data/ext/rugged/vendor/libgit2-dist/tests-clay/clay_libgit2.h +28 -0
  188. data/ext/rugged/vendor/libgit2-dist/tests-clay/clay_main.c +1073 -0
  189. data/ext/rugged/vendor/libgit2-dist/tests-clay/config/add.c +37 -0
  190. data/ext/rugged/vendor/libgit2-dist/tests-clay/config/new.c +36 -0
  191. data/ext/rugged/vendor/libgit2-dist/tests-clay/config/read.c +209 -0
  192. data/ext/rugged/vendor/libgit2-dist/tests-clay/config/stress.c +39 -0
  193. data/ext/rugged/vendor/libgit2-dist/tests-clay/config/write.c +77 -0
  194. data/ext/rugged/vendor/libgit2-dist/tests-clay/core/dirent.c +222 -0
  195. data/ext/rugged/vendor/libgit2-dist/tests-clay/core/filebuf.c +106 -0
  196. data/ext/rugged/vendor/libgit2-dist/tests-clay/core/oid.c +18 -0
  197. data/ext/rugged/vendor/libgit2-dist/tests-clay/core/path.c +139 -0
  198. data/ext/rugged/vendor/libgit2-dist/tests-clay/core/rmdir.c +50 -0
  199. data/ext/rugged/vendor/libgit2-dist/tests-clay/core/string.c +28 -0
  200. data/ext/rugged/vendor/libgit2-dist/tests-clay/core/strtol.c +37 -0
  201. data/ext/rugged/vendor/libgit2-dist/tests-clay/core/vector.c +66 -0
  202. data/ext/rugged/vendor/libgit2-dist/tests-clay/index/rename.c +60 -0
  203. data/ext/rugged/vendor/libgit2-dist/tests-clay/network/remotes.c +50 -0
  204. data/ext/rugged/vendor/libgit2-dist/tests-clay/object/raw/chars.c +52 -0
  205. data/ext/rugged/vendor/libgit2-dist/tests-clay/object/raw/compare.c +124 -0
  206. data/ext/rugged/vendor/libgit2-dist/tests-clay/object/raw/convert.c +75 -0
  207. data/ext/rugged/vendor/libgit2-dist/tests-clay/object/raw/data.h +323 -0
  208. data/ext/rugged/vendor/libgit2-dist/tests-clay/object/raw/fromstr.c +30 -0
  209. data/ext/rugged/vendor/libgit2-dist/tests-clay/object/raw/hash.c +162 -0
  210. data/ext/rugged/vendor/libgit2-dist/tests-clay/object/raw/short.c +94 -0
  211. data/ext/rugged/vendor/libgit2-dist/tests-clay/object/raw/size.c +13 -0
  212. data/ext/rugged/vendor/libgit2-dist/tests-clay/object/raw/type2string.c +54 -0
  213. data/ext/rugged/vendor/libgit2-dist/tests-clay/object/tree/frompath.c +75 -0
  214. data/ext/rugged/vendor/libgit2-dist/tests-clay/odb/loose.c +84 -0
  215. data/ext/rugged/vendor/libgit2-dist/tests-clay/odb/loose_data.h +522 -0
  216. data/ext/rugged/vendor/libgit2-dist/tests-clay/odb/pack_data.h +151 -0
  217. data/ext/rugged/vendor/libgit2-dist/tests-clay/odb/packed.c +78 -0
  218. data/ext/rugged/vendor/libgit2-dist/tests-clay/odb/sorting.c +71 -0
  219. data/ext/rugged/vendor/libgit2-dist/tests-clay/repo/getters.c +68 -0
  220. data/ext/rugged/vendor/libgit2-dist/tests-clay/repo/init.c +104 -0
  221. data/ext/rugged/vendor/libgit2-dist/tests-clay/repo/open.c +54 -0
  222. data/ext/rugged/vendor/libgit2-dist/tests-clay/status/single.c +38 -0
  223. data/ext/rugged/vendor/libgit2-dist/tests-clay/status/status_data.h +48 -0
  224. data/ext/rugged/vendor/libgit2-dist/tests-clay/status/worktree.c +124 -0
  225. data/ext/rugged/vendor/libgit2-dist/tests/t00-core.c +628 -0
  226. data/ext/rugged/vendor/libgit2-dist/tests/t01-data.h +322 -0
  227. data/ext/rugged/vendor/libgit2-dist/tests/t01-rawobj.c +638 -0
  228. data/ext/rugged/vendor/libgit2-dist/tests/t03-data.h +344 -0
  229. data/ext/rugged/vendor/libgit2-dist/tests/t03-objwrite.c +255 -0
  230. data/ext/rugged/vendor/libgit2-dist/tests/t04-commit.c +788 -0
  231. data/ext/rugged/vendor/libgit2-dist/tests/t05-revwalk.c +140 -0
  232. data/ext/rugged/vendor/libgit2-dist/tests/t06-index.c +219 -0
  233. data/ext/rugged/vendor/libgit2-dist/tests/t07-hashtable.c +192 -0
  234. data/ext/rugged/vendor/libgit2-dist/tests/t08-tag.c +357 -0
  235. data/ext/rugged/vendor/libgit2-dist/tests/t09-tree.c +221 -0
  236. data/ext/rugged/vendor/libgit2-dist/tests/t10-refs.c +1294 -0
  237. data/ext/rugged/vendor/libgit2-dist/tests/t12-repo.c +174 -0
  238. data/ext/rugged/vendor/libgit2-dist/tests/t13-threads.c +41 -0
  239. data/ext/rugged/vendor/libgit2-dist/tests/t17-bufs.c +61 -0
  240. data/ext/rugged/vendor/libgit2-dist/tests/t18-status.c +448 -0
  241. data/ext/rugged/vendor/libgit2-dist/tests/test_helpers.c +310 -0
  242. data/ext/rugged/vendor/libgit2-dist/tests/test_helpers.h +83 -0
  243. data/ext/rugged/vendor/libgit2-dist/tests/test_lib.c +198 -0
  244. data/ext/rugged/vendor/libgit2-dist/tests/test_lib.h +54 -0
  245. data/ext/rugged/vendor/libgit2-dist/tests/test_main.c +89 -0
  246. data/lib/rugged.rb +4 -3
  247. data/lib/rugged/index.rb +0 -8
  248. data/lib/rugged/objects.rb +45 -0
  249. data/lib/rugged/repository.rb +29 -0
  250. data/lib/rugged/tree.rb +16 -6
  251. data/lib/rugged/version.rb +1 -1
  252. data/lib/rugged/walker.rb +5 -0
  253. data/test/blob_test.rb +18 -14
  254. data/test/commit_test.rb +28 -26
  255. data/test/coverage/HEAD.json +1 -0
  256. data/test/coverage/cover.rb +106 -0
  257. data/test/fixtures/testrepo.git/refs/heads/new_name +1 -0
  258. data/test/index_test.rb +101 -78
  259. data/test/lib_test.rb +4 -4
  260. data/test/object_test.rb +3 -3
  261. data/test/reference_test.rb +75 -0
  262. data/test/remote_test.rb +19 -0
  263. data/test/repo_pack_test.rb +4 -4
  264. data/test/repo_test.rb +44 -15
  265. data/test/tag_test.rb +7 -17
  266. data/test/test_helper.rb +24 -5
  267. data/test/tree_test.rb +30 -12
  268. data/test/walker_test.rb +40 -31
  269. metadata +273 -50
  270. data/lib/rugged/person.rb +0 -20
  271. data/lib/rugged/tree_entry.rb +0 -9
  272. data/test/fixtures/testrepo.git/objects/1d/83f106355e4309a293e42ad2a2c4b8bdbe77ae +0 -0
  273. data/test/fixtures/testrepo.git/objects/2f/3321418db5b2a841375b8b70880a8ab5a4148f +0 -0
  274. data/test/fixtures/testrepo.git/objects/36/9b00a7700cca3a506d79e301d6ad8bf735d9ee +0 -3
  275. data/test/fixtures/testrepo.git/objects/3d/b1b5ceace59ff65279757003763046fd4cbbe6 +0 -0
  276. data/test/fixtures/testrepo.git/objects/4c/d1604907792e2c43e03dcec1216f99d63e68c4 +0 -3
  277. data/test/fixtures/testrepo.git/objects/e0/f46d77041c149296549b01ed4a18b02c4b7400 +0 -0
@@ -0,0 +1,1073 @@
1
+ #include <assert.h>
2
+ #include <setjmp.h>
3
+ #include <stdlib.h>
4
+ #include <stdio.h>
5
+ #include <string.h>
6
+ #include <math.h>
7
+ #include <stdarg.h>
8
+
9
+ /* required for sandboxing */
10
+ #include <sys/types.h>
11
+ #include <sys/stat.h>
12
+
13
+ #ifdef _WIN32
14
+ # include <windows.h>
15
+ # include <io.h>
16
+ # include <shellapi.h>
17
+ # include <direct.h>
18
+
19
+ # define _MAIN_CC __cdecl
20
+
21
+ # define stat(path, st) _stat(path, st)
22
+ # define mkdir(path, mode) _mkdir(path)
23
+ # define chdir(path) _chdir(path)
24
+ # define access(path, mode) _access(path, mode)
25
+ # define strdup(str) _strdup(str)
26
+
27
+ # ifndef __MINGW32__
28
+ # pragma comment(lib, "shell32")
29
+ # define strncpy(to, from, to_size) strncpy_s(to, to_size, from, _TRUNCATE)
30
+ # define W_OK 02
31
+ # define S_ISDIR(x) ((x & _S_IFDIR) != 0)
32
+ # define mktemp_s(path, len) _mktemp_s(path, len)
33
+ # endif
34
+ typedef struct _stat STAT_T;
35
+ #else
36
+ # include <sys/wait.h> /* waitpid(2) */
37
+ # include <unistd.h>
38
+ # define _MAIN_CC
39
+ typedef struct stat STAT_T;
40
+ #endif
41
+
42
+ #include "clay.h"
43
+
44
+ static void fs_rm(const char *_source);
45
+ static void fs_copy(const char *_source, const char *dest);
46
+
47
+ static const char *
48
+ fixture_path(const char *base, const char *fixture_name);
49
+
50
+ struct clay_error {
51
+ const char *test;
52
+ int test_number;
53
+ const char *suite;
54
+ const char *file;
55
+ int line_number;
56
+ const char *error_msg;
57
+ char *description;
58
+
59
+ struct clay_error *next;
60
+ };
61
+
62
+ static struct {
63
+ const char *active_test;
64
+ const char *active_suite;
65
+
66
+ int suite_errors;
67
+ int total_errors;
68
+
69
+ int test_count;
70
+
71
+ struct clay_error *errors;
72
+ struct clay_error *last_error;
73
+
74
+ void (*local_cleanup)(void *);
75
+ void *local_cleanup_payload;
76
+
77
+ jmp_buf trampoline;
78
+ int trampoline_enabled;
79
+ } _clay;
80
+
81
+ struct clay_func {
82
+ const char *name;
83
+ void (*ptr)(void);
84
+ };
85
+
86
+ struct clay_suite {
87
+ const char *name;
88
+ struct clay_func initialize;
89
+ struct clay_func cleanup;
90
+ const struct clay_func *tests;
91
+ size_t test_count;
92
+ };
93
+
94
+ /* From clay_print_*.c */
95
+ static void clay_print_init(int test_count, int suite_count, const char *suite_names);
96
+ static void clay_print_shutdown(int test_count, int suite_count, int error_count);
97
+ static void clay_print_error(int num, const struct clay_error *error);
98
+ static void clay_print_ontest(const char *test_name, int test_number, int failed);
99
+ static void clay_print_onsuite(const char *suite_name);
100
+ static void clay_print_onabort(const char *msg, ...);
101
+
102
+ /* From clay_sandbox.c */
103
+ static void clay_unsandbox(void);
104
+ static int clay_sandbox(void);
105
+
106
+ /* Autogenerated test data by clay */
107
+ static const struct clay_func _clay_cb_buf_basic[] = {
108
+ {"printf", &test_buf_basic__printf},
109
+ {"resize", &test_buf_basic__resize}
110
+ };
111
+ static const struct clay_func _clay_cb_config_add[] = {
112
+ {"to_existing_section", &test_config_add__to_existing_section},
113
+ {"to_new_section", &test_config_add__to_new_section}
114
+ };
115
+ static const struct clay_func _clay_cb_config_new[] = {
116
+ {"write_new_config", &test_config_new__write_new_config}
117
+ };
118
+ static const struct clay_func _clay_cb_config_read[] = {
119
+ {"blank_lines", &test_config_read__blank_lines},
120
+ {"case_sensitive", &test_config_read__case_sensitive},
121
+ {"empty_files", &test_config_read__empty_files},
122
+ {"header_in_last_line", &test_config_read__header_in_last_line},
123
+ {"invalid_ext_headers", &test_config_read__invalid_ext_headers},
124
+ {"lone_variable", &test_config_read__lone_variable},
125
+ {"multiline_value", &test_config_read__multiline_value},
126
+ {"number_suffixes", &test_config_read__number_suffixes},
127
+ {"prefixes", &test_config_read__prefixes},
128
+ {"simple_read", &test_config_read__simple_read},
129
+ {"subsection_header", &test_config_read__subsection_header}
130
+ };
131
+ static const struct clay_func _clay_cb_config_stress[] = {
132
+ {"dont_break_on_invalid_input", &test_config_stress__dont_break_on_invalid_input}
133
+ };
134
+ static const struct clay_func _clay_cb_config_write[] = {
135
+ {"delete_inexistent", &test_config_write__delete_inexistent},
136
+ {"delete_value", &test_config_write__delete_value},
137
+ {"replace_value", &test_config_write__replace_value}
138
+ };
139
+ static const struct clay_func _clay_cb_core_dirent[] = {
140
+ {"dont_traverse_dot", &test_core_dirent__dont_traverse_dot},
141
+ {"dont_traverse_empty_folders", &test_core_dirent__dont_traverse_empty_folders},
142
+ {"traverse_slash_terminated_folder", &test_core_dirent__traverse_slash_terminated_folder},
143
+ {"traverse_subfolder", &test_core_dirent__traverse_subfolder},
144
+ {"traverse_weird_filenames", &test_core_dirent__traverse_weird_filenames}
145
+ };
146
+ static const struct clay_func _clay_cb_core_filebuf[] = {
147
+ {"0", &test_core_filebuf__0},
148
+ {"1", &test_core_filebuf__1},
149
+ {"2", &test_core_filebuf__2},
150
+ {"3", &test_core_filebuf__3},
151
+ {"4", &test_core_filebuf__4},
152
+ {"5", &test_core_filebuf__5}
153
+ };
154
+ static const struct clay_func _clay_cb_core_oid[] = {
155
+ {"streq", &test_core_oid__streq}
156
+ };
157
+ static const struct clay_func _clay_cb_core_path[] = {
158
+ {"0", &test_core_path__0},
159
+ {"1", &test_core_path__1},
160
+ {"2", &test_core_path__2},
161
+ {"5", &test_core_path__5},
162
+ {"6", &test_core_path__6}
163
+ };
164
+ static const struct clay_func _clay_cb_core_rmdir[] = {
165
+ {"delete_recursive", &test_core_rmdir__delete_recursive},
166
+ {"fail_to_delete_non_empty_dir", &test_core_rmdir__fail_to_delete_non_empty_dir}
167
+ };
168
+ static const struct clay_func _clay_cb_core_string[] = {
169
+ {"0", &test_core_string__0},
170
+ {"1", &test_core_string__1}
171
+ };
172
+ static const struct clay_func _clay_cb_core_strtol[] = {
173
+ {"int32", &test_core_strtol__int32},
174
+ {"int64", &test_core_strtol__int64}
175
+ };
176
+ static const struct clay_func _clay_cb_core_vector[] = {
177
+ {"0", &test_core_vector__0},
178
+ {"1", &test_core_vector__1},
179
+ {"2", &test_core_vector__2}
180
+ };
181
+ static const struct clay_func _clay_cb_index_rename[] = {
182
+ {"single_file", &test_index_rename__single_file}
183
+ };
184
+ static const struct clay_func _clay_cb_network_remotes[] = {
185
+ {"fnmatch", &test_network_remotes__fnmatch},
186
+ {"parsing", &test_network_remotes__parsing},
187
+ {"refspec_parsing", &test_network_remotes__refspec_parsing},
188
+ {"transform", &test_network_remotes__transform}
189
+ };
190
+ static const struct clay_func _clay_cb_object_raw_chars[] = {
191
+ {"build_valid_oid_from_raw_bytes", &test_object_raw_chars__build_valid_oid_from_raw_bytes},
192
+ {"find_invalid_chars_in_oid", &test_object_raw_chars__find_invalid_chars_in_oid}
193
+ };
194
+ static const struct clay_func _clay_cb_object_raw_compare[] = {
195
+ {"compare_allocfmt_oids", &test_object_raw_compare__compare_allocfmt_oids},
196
+ {"compare_fmt_oids", &test_object_raw_compare__compare_fmt_oids},
197
+ {"compare_pathfmt_oids", &test_object_raw_compare__compare_pathfmt_oids},
198
+ {"succeed_on_copy_oid", &test_object_raw_compare__succeed_on_copy_oid},
199
+ {"succeed_on_oid_comparison_equal", &test_object_raw_compare__succeed_on_oid_comparison_equal},
200
+ {"succeed_on_oid_comparison_greater", &test_object_raw_compare__succeed_on_oid_comparison_greater},
201
+ {"succeed_on_oid_comparison_lesser", &test_object_raw_compare__succeed_on_oid_comparison_lesser}
202
+ };
203
+ static const struct clay_func _clay_cb_object_raw_convert[] = {
204
+ {"succeed_on_oid_to_string_conversion", &test_object_raw_convert__succeed_on_oid_to_string_conversion},
205
+ {"succeed_on_oid_to_string_conversion_big", &test_object_raw_convert__succeed_on_oid_to_string_conversion_big}
206
+ };
207
+ static const struct clay_func _clay_cb_object_raw_fromstr[] = {
208
+ {"fail_on_invalid_oid_string", &test_object_raw_fromstr__fail_on_invalid_oid_string},
209
+ {"succeed_on_valid_oid_string", &test_object_raw_fromstr__succeed_on_valid_oid_string}
210
+ };
211
+ static const struct clay_func _clay_cb_object_raw_hash[] = {
212
+ {"hash_buffer_in_single_call", &test_object_raw_hash__hash_buffer_in_single_call},
213
+ {"hash_by_blocks", &test_object_raw_hash__hash_by_blocks},
214
+ {"hash_commit_object", &test_object_raw_hash__hash_commit_object},
215
+ {"hash_junk_data", &test_object_raw_hash__hash_junk_data},
216
+ {"hash_multi_byte_object", &test_object_raw_hash__hash_multi_byte_object},
217
+ {"hash_one_byte_object", &test_object_raw_hash__hash_one_byte_object},
218
+ {"hash_tag_object", &test_object_raw_hash__hash_tag_object},
219
+ {"hash_tree_object", &test_object_raw_hash__hash_tree_object},
220
+ {"hash_two_byte_object", &test_object_raw_hash__hash_two_byte_object},
221
+ {"hash_vector", &test_object_raw_hash__hash_vector},
222
+ {"hash_zero_length_object", &test_object_raw_hash__hash_zero_length_object}
223
+ };
224
+ static const struct clay_func _clay_cb_object_raw_short[] = {
225
+ {"oid_shortener_no_duplicates", &test_object_raw_short__oid_shortener_no_duplicates},
226
+ {"oid_shortener_stresstest_git_oid_shorten", &test_object_raw_short__oid_shortener_stresstest_git_oid_shorten}
227
+ };
228
+ static const struct clay_func _clay_cb_object_raw_size[] = {
229
+ {"validate_oid_size", &test_object_raw_size__validate_oid_size}
230
+ };
231
+ static const struct clay_func _clay_cb_object_raw_type2string[] = {
232
+ {"check_type_is_loose", &test_object_raw_type2string__check_type_is_loose},
233
+ {"convert_string_to_type", &test_object_raw_type2string__convert_string_to_type},
234
+ {"convert_type_to_string", &test_object_raw_type2string__convert_type_to_string}
235
+ };
236
+ static const struct clay_func _clay_cb_object_tree_frompath[] = {
237
+ {"fail_when_processing_an_invalid_path", &test_object_tree_frompath__fail_when_processing_an_invalid_path},
238
+ {"fail_when_processing_an_unknown_tree_segment", &test_object_tree_frompath__fail_when_processing_an_unknown_tree_segment},
239
+ {"retrieve_tree_from_path_to_treeentry", &test_object_tree_frompath__retrieve_tree_from_path_to_treeentry}
240
+ };
241
+ static const struct clay_func _clay_cb_odb_loose[] = {
242
+ {"exists", &test_odb_loose__exists},
243
+ {"simple_reads", &test_odb_loose__simple_reads}
244
+ };
245
+ static const struct clay_func _clay_cb_odb_packed[] = {
246
+ {"mass_read", &test_odb_packed__mass_read},
247
+ {"read_header_0", &test_odb_packed__read_header_0},
248
+ {"read_header_1", &test_odb_packed__read_header_1}
249
+ };
250
+ static const struct clay_func _clay_cb_odb_sorting[] = {
251
+ {"alternate_backends_sorting", &test_odb_sorting__alternate_backends_sorting},
252
+ {"basic_backends_sorting", &test_odb_sorting__basic_backends_sorting}
253
+ };
254
+ static const struct clay_func _clay_cb_repo_getters[] = {
255
+ {"empty", &test_repo_getters__empty},
256
+ {"head_detached", &test_repo_getters__head_detached},
257
+ {"head_orphan", &test_repo_getters__head_orphan}
258
+ };
259
+ static const struct clay_func _clay_cb_repo_init[] = {
260
+ {"bare_repo", &test_repo_init__bare_repo},
261
+ {"bare_repo_noslash", &test_repo_init__bare_repo_noslash},
262
+ {"standard_repo", &test_repo_init__standard_repo},
263
+ {"standard_repo_noslash", &test_repo_init__standard_repo_noslash}
264
+ };
265
+ static const struct clay_func _clay_cb_repo_open[] = {
266
+ {"bare_empty_repo", &test_repo_open__bare_empty_repo},
267
+ {"standard_empty_repo", &test_repo_open__standard_empty_repo}
268
+ };
269
+ static const struct clay_func _clay_cb_status_single[] = {
270
+ {"hash_single_file", &test_status_single__hash_single_file}
271
+ };
272
+ static const struct clay_func _clay_cb_status_worktree[] = {
273
+ {"empty_repository", &test_status_worktree__empty_repository},
274
+ {"whole_repository", &test_status_worktree__whole_repository}
275
+ };
276
+
277
+ static const struct clay_suite _clay_suites[] = {
278
+ {
279
+ "buf::basic",
280
+ {NULL, NULL},
281
+ {NULL, NULL},
282
+ _clay_cb_buf_basic, 2
283
+ },
284
+ {
285
+ "config::add",
286
+ {"initialize", &test_config_add__initialize},
287
+ {"cleanup", &test_config_add__cleanup},
288
+ _clay_cb_config_add, 2
289
+ },
290
+ {
291
+ "config::new",
292
+ {NULL, NULL},
293
+ {NULL, NULL},
294
+ _clay_cb_config_new, 1
295
+ },
296
+ {
297
+ "config::read",
298
+ {NULL, NULL},
299
+ {NULL, NULL},
300
+ _clay_cb_config_read, 11
301
+ },
302
+ {
303
+ "config::stress",
304
+ {"initialize", &test_config_stress__initialize},
305
+ {"cleanup", &test_config_stress__cleanup},
306
+ _clay_cb_config_stress, 1
307
+ },
308
+ {
309
+ "config::write",
310
+ {"initialize", &test_config_write__initialize},
311
+ {"cleanup", &test_config_write__cleanup},
312
+ _clay_cb_config_write, 3
313
+ },
314
+ {
315
+ "core::dirent",
316
+ {NULL, NULL},
317
+ {NULL, NULL},
318
+ _clay_cb_core_dirent, 5
319
+ },
320
+ {
321
+ "core::filebuf",
322
+ {NULL, NULL},
323
+ {NULL, NULL},
324
+ _clay_cb_core_filebuf, 6
325
+ },
326
+ {
327
+ "core::oid",
328
+ {"initialize", &test_core_oid__initialize},
329
+ {NULL, NULL},
330
+ _clay_cb_core_oid, 1
331
+ },
332
+ {
333
+ "core::path",
334
+ {NULL, NULL},
335
+ {NULL, NULL},
336
+ _clay_cb_core_path, 5
337
+ },
338
+ {
339
+ "core::rmdir",
340
+ {"initialize", &test_core_rmdir__initialize},
341
+ {NULL, NULL},
342
+ _clay_cb_core_rmdir, 2
343
+ },
344
+ {
345
+ "core::string",
346
+ {NULL, NULL},
347
+ {NULL, NULL},
348
+ _clay_cb_core_string, 2
349
+ },
350
+ {
351
+ "core::strtol",
352
+ {NULL, NULL},
353
+ {NULL, NULL},
354
+ _clay_cb_core_strtol, 2
355
+ },
356
+ {
357
+ "core::vector",
358
+ {NULL, NULL},
359
+ {NULL, NULL},
360
+ _clay_cb_core_vector, 3
361
+ },
362
+ {
363
+ "index::rename",
364
+ {NULL, NULL},
365
+ {NULL, NULL},
366
+ _clay_cb_index_rename, 1
367
+ },
368
+ {
369
+ "network::remotes",
370
+ {"initialize", &test_network_remotes__initialize},
371
+ {"cleanup", &test_network_remotes__cleanup},
372
+ _clay_cb_network_remotes, 4
373
+ },
374
+ {
375
+ "object::raw::chars",
376
+ {NULL, NULL},
377
+ {NULL, NULL},
378
+ _clay_cb_object_raw_chars, 2
379
+ },
380
+ {
381
+ "object::raw::compare",
382
+ {NULL, NULL},
383
+ {NULL, NULL},
384
+ _clay_cb_object_raw_compare, 7
385
+ },
386
+ {
387
+ "object::raw::convert",
388
+ {NULL, NULL},
389
+ {NULL, NULL},
390
+ _clay_cb_object_raw_convert, 2
391
+ },
392
+ {
393
+ "object::raw::fromstr",
394
+ {NULL, NULL},
395
+ {NULL, NULL},
396
+ _clay_cb_object_raw_fromstr, 2
397
+ },
398
+ {
399
+ "object::raw::hash",
400
+ {NULL, NULL},
401
+ {NULL, NULL},
402
+ _clay_cb_object_raw_hash, 11
403
+ },
404
+ {
405
+ "object::raw::short",
406
+ {NULL, NULL},
407
+ {NULL, NULL},
408
+ _clay_cb_object_raw_short, 2
409
+ },
410
+ {
411
+ "object::raw::size",
412
+ {NULL, NULL},
413
+ {NULL, NULL},
414
+ _clay_cb_object_raw_size, 1
415
+ },
416
+ {
417
+ "object::raw::type2string",
418
+ {NULL, NULL},
419
+ {NULL, NULL},
420
+ _clay_cb_object_raw_type2string, 3
421
+ },
422
+ {
423
+ "object::tree::frompath",
424
+ {"initialize", &test_object_tree_frompath__initialize},
425
+ {"cleanup", &test_object_tree_frompath__cleanup},
426
+ _clay_cb_object_tree_frompath, 3
427
+ },
428
+ {
429
+ "odb::loose",
430
+ {"initialize", &test_odb_loose__initialize},
431
+ {"cleanup", &test_odb_loose__cleanup},
432
+ _clay_cb_odb_loose, 2
433
+ },
434
+ {
435
+ "odb::packed",
436
+ {"initialize", &test_odb_packed__initialize},
437
+ {"cleanup", &test_odb_packed__cleanup},
438
+ _clay_cb_odb_packed, 3
439
+ },
440
+ {
441
+ "odb::sorting",
442
+ {"initialize", &test_odb_sorting__initialize},
443
+ {"cleanup", &test_odb_sorting__cleanup},
444
+ _clay_cb_odb_sorting, 2
445
+ },
446
+ {
447
+ "repo::getters",
448
+ {"initialize", &test_repo_getters__initialize},
449
+ {"cleanup", &test_repo_getters__cleanup},
450
+ _clay_cb_repo_getters, 3
451
+ },
452
+ {
453
+ "repo::init",
454
+ {"initialize", &test_repo_init__initialize},
455
+ {NULL, NULL},
456
+ _clay_cb_repo_init, 4
457
+ },
458
+ {
459
+ "repo::open",
460
+ {NULL, NULL},
461
+ {NULL, NULL},
462
+ _clay_cb_repo_open, 2
463
+ },
464
+ {
465
+ "status::single",
466
+ {NULL, NULL},
467
+ {NULL, NULL},
468
+ _clay_cb_status_single, 1
469
+ },
470
+ {
471
+ "status::worktree",
472
+ {"initialize", &test_status_worktree__initialize},
473
+ {"cleanup", &test_status_worktree__cleanup},
474
+ _clay_cb_status_worktree, 2
475
+ }
476
+ };
477
+
478
+ static size_t _clay_suite_count = 33;
479
+ static size_t _clay_callback_count = 103;
480
+
481
+ /* Core test functions */
482
+ static void
483
+ clay_run_test(
484
+ const struct clay_func *test,
485
+ const struct clay_func *initialize,
486
+ const struct clay_func *cleanup)
487
+ {
488
+ int error_st = _clay.suite_errors;
489
+
490
+ _clay.trampoline_enabled = 1;
491
+
492
+ if (setjmp(_clay.trampoline) == 0) {
493
+ if (initialize->ptr != NULL)
494
+ initialize->ptr();
495
+
496
+ test->ptr();
497
+ }
498
+
499
+ _clay.trampoline_enabled = 0;
500
+
501
+ if (_clay.local_cleanup != NULL)
502
+ _clay.local_cleanup(_clay.local_cleanup_payload);
503
+
504
+ if (cleanup->ptr != NULL)
505
+ cleanup->ptr();
506
+
507
+ _clay.test_count++;
508
+
509
+ /* remove any local-set cleanup methods */
510
+ _clay.local_cleanup = NULL;
511
+ _clay.local_cleanup_payload = NULL;
512
+
513
+ clay_print_ontest(
514
+ test->name,
515
+ _clay.test_count,
516
+ (_clay.suite_errors > error_st)
517
+ );
518
+ }
519
+
520
+ static void
521
+ clay_report_errors(void)
522
+ {
523
+ int i = 1;
524
+ struct clay_error *error, *next;
525
+
526
+ error = _clay.errors;
527
+ while (error != NULL) {
528
+ next = error->next;
529
+ clay_print_error(i++, error);
530
+ free(error->description);
531
+ free(error);
532
+ error = next;
533
+ }
534
+
535
+ _clay.errors = _clay.last_error = NULL;
536
+ }
537
+
538
+ static void
539
+ clay_run_suite(const struct clay_suite *suite)
540
+ {
541
+ const struct clay_func *test = suite->tests;
542
+ size_t i;
543
+
544
+ clay_print_onsuite(suite->name);
545
+
546
+ _clay.active_suite = suite->name;
547
+ _clay.suite_errors = 0;
548
+
549
+ for (i = 0; i < suite->test_count; ++i) {
550
+ _clay.active_test = test[i].name;
551
+ clay_run_test(&test[i], &suite->initialize, &suite->cleanup);
552
+ }
553
+ }
554
+
555
+ #if 0 /* temporarily disabled */
556
+ static void
557
+ clay_run_single(const struct clay_func *test,
558
+ const struct clay_suite *suite)
559
+ {
560
+ _clay.suite_errors = 0;
561
+ _clay.active_suite = suite->name;
562
+ _clay.active_test = test->name;
563
+
564
+ clay_run_test(test, &suite->initialize, &suite->cleanup);
565
+ }
566
+ #endif
567
+
568
+ static void
569
+ clay_usage(const char *arg)
570
+ {
571
+ printf("Usage: %s [options]\n\n", arg);
572
+ printf("Options:\n");
573
+ // printf(" -tXX\t\tRun only the test number XX\n");
574
+ printf(" -sXX\t\tRun only the suite number XX\n");
575
+ exit(-1);
576
+ }
577
+
578
+ static void
579
+ clay_parse_args(int argc, char **argv)
580
+ {
581
+ int i;
582
+
583
+ for (i = 1; i < argc; ++i) {
584
+ char *argument = argv[i];
585
+ char action;
586
+ int num;
587
+
588
+ if (argument[0] != '-')
589
+ clay_usage(argv[0]);
590
+
591
+ action = argument[1];
592
+ num = strtol(argument + 2, &argument, 10);
593
+
594
+ if (*argument != '\0' || num < 0)
595
+ clay_usage(argv[0]);
596
+
597
+ switch (action) {
598
+ case 's':
599
+ if ((size_t)num >= _clay_suite_count) {
600
+ clay_print_onabort("Suite number %d does not exist.\n", num);
601
+ exit(-1);
602
+ }
603
+
604
+ clay_run_suite(&_clay_suites[num]);
605
+ break;
606
+
607
+ default:
608
+ clay_usage(argv[0]);
609
+ }
610
+ }
611
+ }
612
+
613
+ static int
614
+ clay_test(int argc, char **argv)
615
+ {
616
+ clay_print_init(
617
+ (int)_clay_callback_count,
618
+ (int)_clay_suite_count,
619
+ ""
620
+ );
621
+
622
+ if (clay_sandbox() < 0) {
623
+ fprintf(stderr,
624
+ "Failed to sandbox the test runner.\n"
625
+ "Testing will proceed without sandboxing.\n");
626
+ }
627
+
628
+ if (argc > 1) {
629
+ clay_parse_args(argc, argv);
630
+ } else {
631
+ size_t i;
632
+ for (i = 0; i < _clay_suite_count; ++i)
633
+ clay_run_suite(&_clay_suites[i]);
634
+ }
635
+
636
+ clay_print_shutdown(
637
+ (int)_clay_callback_count,
638
+ (int)_clay_suite_count,
639
+ _clay.total_errors
640
+ );
641
+
642
+ clay_unsandbox();
643
+ return _clay.total_errors;
644
+ }
645
+
646
+ void
647
+ clay__assert(
648
+ int condition,
649
+ const char *file,
650
+ int line,
651
+ const char *error_msg,
652
+ const char *description,
653
+ int should_abort)
654
+ {
655
+ struct clay_error *error;
656
+
657
+ if (condition)
658
+ return;
659
+
660
+ error = calloc(1, sizeof(struct clay_error));
661
+
662
+ if (_clay.errors == NULL)
663
+ _clay.errors = error;
664
+
665
+ if (_clay.last_error != NULL)
666
+ _clay.last_error->next = error;
667
+
668
+ _clay.last_error = error;
669
+
670
+ error->test = _clay.active_test;
671
+ error->test_number = _clay.test_count;
672
+ error->suite = _clay.active_suite;
673
+ error->file = file;
674
+ error->line_number = line;
675
+ error->error_msg = error_msg;
676
+
677
+ if (description != NULL)
678
+ error->description = strdup(description);
679
+
680
+ _clay.suite_errors++;
681
+ _clay.total_errors++;
682
+
683
+ if (should_abort) {
684
+ if (!_clay.trampoline_enabled) {
685
+ clay_print_onabort(
686
+ "Fatal error: a cleanup method raised an exception.");
687
+ exit(-1);
688
+ }
689
+
690
+ longjmp(_clay.trampoline, -1);
691
+ }
692
+ }
693
+
694
+ void cl_set_cleanup(void (*cleanup)(void *), void *opaque)
695
+ {
696
+ _clay.local_cleanup = cleanup;
697
+ _clay.local_cleanup_payload = opaque;
698
+ }
699
+
700
+ static char _clay_path[4096];
701
+
702
+ static int
703
+ is_valid_tmp_path(const char *path)
704
+ {
705
+ STAT_T st;
706
+
707
+ if (stat(path, &st) != 0)
708
+ return 0;
709
+
710
+ if (!S_ISDIR(st.st_mode))
711
+ return 0;
712
+
713
+ return (access(path, W_OK) == 0);
714
+ }
715
+
716
+ static int
717
+ find_tmp_path(char *buffer, size_t length)
718
+ {
719
+ #ifndef _WIN32
720
+ static const size_t var_count = 4;
721
+ static const char *env_vars[] = {
722
+ "TMPDIR", "TMP", "TEMP", "USERPROFILE"
723
+ };
724
+
725
+ size_t i;
726
+
727
+ for (i = 0; i < var_count; ++i) {
728
+ const char *env = getenv(env_vars[i]);
729
+ if (!env)
730
+ continue;
731
+
732
+ if (is_valid_tmp_path(env)) {
733
+ strncpy(buffer, env, length);
734
+ return 0;
735
+ }
736
+ }
737
+
738
+ /* If the environment doesn't say anything, try to use /tmp */
739
+ if (is_valid_tmp_path("/tmp")) {
740
+ strncpy(buffer, "/tmp", length);
741
+ return 0;
742
+ }
743
+
744
+ #else
745
+ if (GetTempPath((DWORD)length, buffer))
746
+ return 0;
747
+ #endif
748
+
749
+ /* This system doesn't like us, try to use the current directory */
750
+ if (is_valid_tmp_path(".")) {
751
+ strncpy(buffer, ".", length);
752
+ return 0;
753
+ }
754
+
755
+ return -1;
756
+ }
757
+
758
+ static void clay_unsandbox(void)
759
+ {
760
+ if (_clay_path[0] == '\0')
761
+ return;
762
+
763
+ #ifdef _WIN32
764
+ chdir("..");
765
+ #endif
766
+
767
+ fs_rm(_clay_path);
768
+ }
769
+
770
+ static int build_sandbox_path(void)
771
+ {
772
+ const char path_tail[] = "clay_tmp_XXXXXX";
773
+ size_t len;
774
+
775
+ if (find_tmp_path(_clay_path, sizeof(_clay_path)) < 0)
776
+ return -1;
777
+
778
+ len = strlen(_clay_path);
779
+
780
+ #ifdef _WIN32
781
+ { /* normalize path to POSIX forward slashes */
782
+ size_t i;
783
+ for (i = 0; i < len; ++i) {
784
+ if (_clay_path[i] == '\\')
785
+ _clay_path[i] = '/';
786
+ }
787
+ }
788
+ #endif
789
+
790
+ if (_clay_path[len - 1] != '/') {
791
+ _clay_path[len++] = '/';
792
+ }
793
+
794
+ strncpy(_clay_path + len, path_tail, sizeof(_clay_path) - len);
795
+
796
+ #ifdef _WIN32
797
+ if (mktemp_s(_clay_path, sizeof(_clay_path)) != 0)
798
+ return -1;
799
+
800
+ if (mkdir(_clay_path, 0700) != 0)
801
+ return -1;
802
+ #else
803
+ if (mkdtemp(_clay_path) == NULL)
804
+ return -1;
805
+ #endif
806
+
807
+ return 0;
808
+ }
809
+
810
+ static int clay_sandbox(void)
811
+ {
812
+ if (_clay_path[0] == '\0' && build_sandbox_path() < 0)
813
+ return -1;
814
+
815
+ if (chdir(_clay_path) != 0)
816
+ return -1;
817
+
818
+ return 0;
819
+ }
820
+
821
+
822
+ static const char *
823
+ fixture_path(const char *base, const char *fixture_name)
824
+ {
825
+ static char _path[4096];
826
+ size_t root_len;
827
+
828
+ root_len = strlen(base);
829
+ strncpy(_path, base, sizeof(_path));
830
+
831
+ if (_path[root_len - 1] != '/')
832
+ _path[root_len++] = '/';
833
+
834
+ if (fixture_name[0] == '/')
835
+ fixture_name++;
836
+
837
+ strncpy(_path + root_len,
838
+ fixture_name,
839
+ sizeof(_path) - root_len);
840
+
841
+ return _path;
842
+ }
843
+
844
+ #ifdef CLAY_FIXTURE_PATH
845
+ const char *cl_fixture(const char *fixture_name)
846
+ {
847
+ return fixture_path(CLAY_FIXTURE_PATH, fixture_name);
848
+ }
849
+
850
+ void cl_fixture_sandbox(const char *fixture_name)
851
+ {
852
+ fs_copy(cl_fixture(fixture_name), _clay_path);
853
+ }
854
+
855
+ void cl_fixture_cleanup(const char *fixture_name)
856
+ {
857
+ fs_rm(fixture_path(_clay_path, fixture_name));
858
+ }
859
+ #endif
860
+
861
+ #ifdef _WIN32
862
+
863
+ #define FOF_FLAGS (FOF_SILENT | FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_NOCONFIRMMKDIR)
864
+
865
+ static char *
866
+ fileops_path(const char *_path)
867
+ {
868
+ char *path = NULL;
869
+ size_t length, i;
870
+
871
+ if (_path == NULL)
872
+ return NULL;
873
+
874
+ length = strlen(_path);
875
+ path = malloc(length + 2);
876
+
877
+ if (path == NULL)
878
+ return NULL;
879
+
880
+ memcpy(path, _path, length);
881
+ path[length] = 0;
882
+ path[length + 1] = 0;
883
+
884
+ for (i = 0; i < length; ++i) {
885
+ if (path[i] == '/')
886
+ path[i] = '\\';
887
+ }
888
+
889
+ return path;
890
+ }
891
+
892
+ static void
893
+ fileops(int mode, const char *_source, const char *_dest)
894
+ {
895
+ SHFILEOPSTRUCT fops;
896
+
897
+ char *source = fileops_path(_source);
898
+ char *dest = fileops_path(_dest);
899
+
900
+ ZeroMemory(&fops, sizeof(SHFILEOPSTRUCT));
901
+
902
+ fops.wFunc = mode;
903
+ fops.pFrom = source;
904
+ fops.pTo = dest;
905
+ fops.fFlags = FOF_FLAGS;
906
+
907
+ cl_assert_(
908
+ SHFileOperation(&fops) == 0,
909
+ "Windows SHFileOperation failed"
910
+ );
911
+
912
+ free(source);
913
+ free(dest);
914
+ }
915
+
916
+ static void
917
+ fs_rm(const char *_source)
918
+ {
919
+ fileops(FO_DELETE, _source, NULL);
920
+ }
921
+
922
+ static void
923
+ fs_copy(const char *_source, const char *_dest)
924
+ {
925
+ fileops(FO_COPY, _source, _dest);
926
+ }
927
+
928
+ void
929
+ cl_fs_cleanup(void)
930
+ {
931
+ fs_rm(fixture_path(_clay_path, "*"));
932
+ }
933
+
934
+ #else
935
+ static int
936
+ shell_out(char * const argv[])
937
+ {
938
+ int status;
939
+ pid_t pid;
940
+
941
+ pid = fork();
942
+
943
+ if (pid < 0) {
944
+ fprintf(stderr,
945
+ "System error: `fork()` call failed.\n");
946
+ exit(-1);
947
+ }
948
+
949
+ if (pid == 0) {
950
+ execv(argv[0], argv);
951
+ }
952
+
953
+ waitpid(pid, &status, 0);
954
+ return WEXITSTATUS(status);
955
+ }
956
+
957
+ static void
958
+ fs_copy(const char *_source, const char *dest)
959
+ {
960
+ char *argv[5];
961
+ char *source;
962
+ size_t source_len;
963
+
964
+ source = strdup(_source);
965
+ source_len = strlen(source);
966
+
967
+ if (source[source_len - 1] == '/')
968
+ source[source_len - 1] = 0;
969
+
970
+ argv[0] = "/bin/cp";
971
+ argv[1] = "-R";
972
+ argv[2] = source;
973
+ argv[3] = (char *)dest;
974
+ argv[4] = NULL;
975
+
976
+ cl_must_pass_(
977
+ shell_out(argv),
978
+ "Failed to copy test fixtures to sandbox"
979
+ );
980
+
981
+ free(source);
982
+ }
983
+
984
+ static void
985
+ fs_rm(const char *source)
986
+ {
987
+ char *argv[4];
988
+
989
+ argv[0] = "/bin/rm";
990
+ argv[1] = "-Rf";
991
+ argv[2] = (char *)source;
992
+ argv[3] = NULL;
993
+
994
+ cl_must_pass_(
995
+ shell_out(argv),
996
+ "Failed to cleanup the sandbox"
997
+ );
998
+ }
999
+
1000
+ void
1001
+ cl_fs_cleanup(void)
1002
+ {
1003
+ clay_unsandbox();
1004
+ clay_sandbox();
1005
+ }
1006
+ #endif
1007
+
1008
+
1009
+ static void clay_print_init(int test_count, int suite_count, const char *suite_names)
1010
+ {
1011
+ (void)suite_names;
1012
+ (void)suite_count;
1013
+ printf("TAP version 13\n");
1014
+ printf("1..%d\n", test_count);
1015
+ }
1016
+
1017
+ static void clay_print_shutdown(int test_count, int suite_count, int error_count)
1018
+ {
1019
+ (void)test_count;
1020
+ (void)suite_count;
1021
+ (void)error_count;
1022
+
1023
+ printf("\n");
1024
+ }
1025
+
1026
+ static void clay_print_error(int num, const struct clay_error *error)
1027
+ {
1028
+ (void)num;
1029
+
1030
+ printf(" ---\n");
1031
+ printf(" message : %s\n", error->error_msg);
1032
+ printf(" severity: fail\n");
1033
+ printf(" suite : %s\n", error->suite);
1034
+ printf(" test : %s\n", error->test);
1035
+ printf(" file : %s\n", error->file);
1036
+ printf(" line : %d\n", error->line_number);
1037
+
1038
+ if (error->description != NULL)
1039
+ printf(" description: %s\n", error->description);
1040
+
1041
+ printf(" ...\n");
1042
+ }
1043
+
1044
+ static void clay_print_ontest(const char *test_name, int test_number, int failed)
1045
+ {
1046
+ printf("%s %d - %s\n",
1047
+ failed ? "not ok" : "ok",
1048
+ test_number,
1049
+ test_name
1050
+ );
1051
+
1052
+ clay_report_errors();
1053
+ }
1054
+
1055
+ static void clay_print_onsuite(const char *suite_name)
1056
+ {
1057
+ printf("# *** %s ***\n", suite_name);
1058
+ }
1059
+
1060
+ static void clay_print_onabort(const char *msg, ...)
1061
+ {
1062
+ va_list argp;
1063
+ va_start(argp, msg);
1064
+ fprintf(stdout, "Bail out! ");
1065
+ vfprintf(stdout, msg, argp);
1066
+ va_end(argp);
1067
+ }
1068
+
1069
+
1070
+ int _MAIN_CC main(int argc, char *argv[])
1071
+ {
1072
+ return clay_test(argc, argv);
1073
+ }