QCKDSL.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. #import <Foundation/Foundation.h>
  2. @class ExampleMetadata;
  3. /**
  4. Provides a hook for Quick to be configured before any examples are run.
  5. Within this scope, override the +[QuickConfiguration configure:] method
  6. to set properties on a configuration object to customize Quick behavior.
  7. For details, see the documentation for Configuraiton.swift.
  8. @param name The name of the configuration class. Like any Objective-C
  9. class name, this must be unique to the current runtime
  10. environment.
  11. */
  12. #define QuickConfigurationBegin(name) \
  13. @interface name : QuickConfiguration; @end \
  14. @implementation name \
  15. /**
  16. Marks the end of a Quick configuration.
  17. Make sure you put this after `QuickConfigurationBegin`.
  18. */
  19. #define QuickConfigurationEnd \
  20. @end \
  21. /**
  22. Defines a new QuickSpec. Define examples and example groups within the space
  23. between this and `QuickSpecEnd`.
  24. @param name The name of the spec class. Like any Objective-C class name, this
  25. must be unique to the current runtime environment.
  26. */
  27. #define QuickSpecBegin(name) \
  28. @interface name : QuickSpec; @end \
  29. @implementation name \
  30. - (void)spec { \
  31. /**
  32. Marks the end of a QuickSpec. Make sure you put this after `QuickSpecBegin`.
  33. */
  34. #define QuickSpecEnd \
  35. } \
  36. @end \
  37. typedef NSDictionary *(^QCKDSLSharedExampleContext)(void);
  38. typedef void (^QCKDSLSharedExampleBlock)(QCKDSLSharedExampleContext);
  39. typedef void (^QCKDSLEmptyBlock)(void);
  40. typedef void (^QCKDSLExampleMetadataBlock)(ExampleMetadata *exampleMetadata);
  41. #define QUICK_EXPORT FOUNDATION_EXPORT
  42. QUICK_EXPORT void qck_beforeSuite(QCKDSLEmptyBlock closure);
  43. QUICK_EXPORT void qck_afterSuite(QCKDSLEmptyBlock closure);
  44. QUICK_EXPORT void qck_sharedExamples(NSString *name, QCKDSLSharedExampleBlock closure);
  45. QUICK_EXPORT void qck_describe(NSString *description, QCKDSLEmptyBlock closure);
  46. QUICK_EXPORT void qck_context(NSString *description, QCKDSLEmptyBlock closure);
  47. QUICK_EXPORT void qck_beforeEach(QCKDSLEmptyBlock closure);
  48. QUICK_EXPORT void qck_beforeEachWithMetadata(QCKDSLExampleMetadataBlock closure);
  49. QUICK_EXPORT void qck_afterEach(QCKDSLEmptyBlock closure);
  50. QUICK_EXPORT void qck_afterEachWithMetadata(QCKDSLExampleMetadataBlock closure);
  51. QUICK_EXPORT void qck_pending(NSString *description, QCKDSLEmptyBlock closure);
  52. QUICK_EXPORT void qck_xdescribe(NSString *description, QCKDSLEmptyBlock closure);
  53. QUICK_EXPORT void qck_xcontext(NSString *description, QCKDSLEmptyBlock closure);
  54. QUICK_EXPORT void qck_fdescribe(NSString *description, QCKDSLEmptyBlock closure);
  55. QUICK_EXPORT void qck_fcontext(NSString *description, QCKDSLEmptyBlock closure);
  56. #ifndef QUICK_DISABLE_SHORT_SYNTAX
  57. /**
  58. Defines a closure to be run prior to any examples in the test suite.
  59. You may define an unlimited number of these closures, but there is no
  60. guarantee as to the order in which they're run.
  61. If the test suite crashes before the first example is run, this closure
  62. will not be executed.
  63. @param closure The closure to be run prior to any examples in the test suite.
  64. */
  65. static inline void beforeSuite(QCKDSLEmptyBlock closure) {
  66. qck_beforeSuite(closure);
  67. }
  68. /**
  69. Defines a closure to be run after all of the examples in the test suite.
  70. You may define an unlimited number of these closures, but there is no
  71. guarantee as to the order in which they're run.
  72. If the test suite crashes before all examples are run, this closure
  73. will not be executed.
  74. @param closure The closure to be run after all of the examples in the test suite.
  75. */
  76. static inline void afterSuite(QCKDSLEmptyBlock closure) {
  77. qck_afterSuite(closure);
  78. }
  79. /**
  80. Defines a group of shared examples. These examples can be re-used in several locations
  81. by using the `itBehavesLike` function.
  82. @param name The name of the shared example group. This must be unique across all shared example
  83. groups defined in a test suite.
  84. @param closure A closure containing the examples. This behaves just like an example group defined
  85. using `describe` or `context`--the closure may contain any number of `beforeEach`
  86. and `afterEach` closures, as well as any number of examples (defined using `it`).
  87. */
  88. static inline void sharedExamples(NSString *name, QCKDSLSharedExampleBlock closure) {
  89. qck_sharedExamples(name, closure);
  90. }
  91. /**
  92. Defines an example group. Example groups are logical groupings of examples.
  93. Example groups can share setup and teardown code.
  94. @param description An arbitrary string describing the example group.
  95. @param closure A closure that can contain other examples.
  96. */
  97. static inline void describe(NSString *description, QCKDSLEmptyBlock closure) {
  98. qck_describe(description, closure);
  99. }
  100. /**
  101. Defines an example group. Equivalent to `describe`.
  102. */
  103. static inline void context(NSString *description, QCKDSLEmptyBlock closure) {
  104. qck_context(description, closure);
  105. }
  106. /**
  107. Defines a closure to be run prior to each example in the current example
  108. group. This closure is not run for pending or otherwise disabled examples.
  109. An example group may contain an unlimited number of beforeEach. They'll be
  110. run in the order they're defined, but you shouldn't rely on that behavior.
  111. @param closure The closure to be run prior to each example.
  112. */
  113. static inline void beforeEach(QCKDSLEmptyBlock closure) {
  114. qck_beforeEach(closure);
  115. }
  116. /**
  117. Identical to QCKDSL.beforeEach, except the closure is provided with
  118. metadata on the example that the closure is being run prior to.
  119. */
  120. static inline void beforeEachWithMetadata(QCKDSLExampleMetadataBlock closure) {
  121. qck_beforeEachWithMetadata(closure);
  122. }
  123. /**
  124. Defines a closure to be run after each example in the current example
  125. group. This closure is not run for pending or otherwise disabled examples.
  126. An example group may contain an unlimited number of afterEach. They'll be
  127. run in the order they're defined, but you shouldn't rely on that behavior.
  128. @param closure The closure to be run after each example.
  129. */
  130. static inline void afterEach(QCKDSLEmptyBlock closure) {
  131. qck_afterEach(closure);
  132. }
  133. /**
  134. Identical to QCKDSL.afterEach, except the closure is provided with
  135. metadata on the example that the closure is being run after.
  136. */
  137. static inline void afterEachWithMetadata(QCKDSLExampleMetadataBlock closure) {
  138. qck_afterEachWithMetadata(closure);
  139. }
  140. /**
  141. Defines an example or example group that should not be executed. Use `pending` to temporarily disable
  142. examples or groups that should not be run yet.
  143. @param description An arbitrary string describing the example or example group.
  144. @param closure A closure that will not be evaluated.
  145. */
  146. static inline void pending(NSString *description, QCKDSLEmptyBlock closure) {
  147. qck_pending(description, closure);
  148. }
  149. /**
  150. Use this to quickly mark a `describe` block as pending.
  151. This disables all examples within the block.
  152. */
  153. static inline void xdescribe(NSString *description, QCKDSLEmptyBlock closure) {
  154. qck_xdescribe(description, closure);
  155. }
  156. /**
  157. Use this to quickly mark a `context` block as pending.
  158. This disables all examples within the block.
  159. */
  160. static inline void xcontext(NSString *description, QCKDSLEmptyBlock closure) {
  161. qck_xcontext(description, closure);
  162. }
  163. /**
  164. Use this to quickly focus a `describe` block, focusing the examples in the block.
  165. If any examples in the test suite are focused, only those examples are executed.
  166. This trumps any explicitly focused or unfocused examples within the block--they are all treated as focused.
  167. */
  168. static inline void fdescribe(NSString *description, QCKDSLEmptyBlock closure) {
  169. qck_fdescribe(description, closure);
  170. }
  171. /**
  172. Use this to quickly focus a `context` block. Equivalent to `fdescribe`.
  173. */
  174. static inline void fcontext(NSString *description, QCKDSLEmptyBlock closure) {
  175. qck_fcontext(description, closure);
  176. }
  177. #define it qck_it
  178. #define xit qck_xit
  179. #define fit qck_fit
  180. #define itBehavesLike qck_itBehavesLike
  181. #define xitBehavesLike qck_xitBehavesLike
  182. #define fitBehavesLike qck_fitBehavesLike
  183. #endif
  184. #define qck_it qck_it_builder(@{}, @(__FILE__), __LINE__)
  185. #define qck_xit qck_it_builder(@{Filter.pending: @YES}, @(__FILE__), __LINE__)
  186. #define qck_fit qck_it_builder(@{Filter.focused: @YES}, @(__FILE__), __LINE__)
  187. #define qck_itBehavesLike qck_itBehavesLike_builder(@{}, @(__FILE__), __LINE__)
  188. #define qck_xitBehavesLike qck_itBehavesLike_builder(@{Filter.pending: @YES}, @(__FILE__), __LINE__)
  189. #define qck_fitBehavesLike qck_itBehavesLike_builder(@{Filter.focused: @YES}, @(__FILE__), __LINE__)
  190. typedef void (^QCKItBlock)(NSString *description, QCKDSLEmptyBlock closure);
  191. typedef void (^QCKItBehavesLikeBlock)(NSString *description, QCKDSLSharedExampleContext context);
  192. QUICK_EXPORT QCKItBlock qck_it_builder(NSDictionary *flags, NSString *file, NSUInteger line);
  193. QUICK_EXPORT QCKItBehavesLikeBlock qck_itBehavesLike_builder(NSDictionary *flags, NSString *file, NSUInteger line);