+This version adjusts the secondary action to be a regular menu item action.
+
+
+## 3.0.8
+
+This version adjusts the secondary action signature to also provide the affected item. It's a breaking change, but a small one, so deal with it I guess ¯\_(ツ)_/¯
+
+This version also make sthe `ActionSheetItemHandler` protocol implementations `open` so they're possible to override.
+
+
+## 3.0.7
+
+This version adds a new `SecondaryActionItem` which lets you specify a secondary action for an item.
+
+It also adds a new `MenuCreator` protocol that can be implemented to postpone the creation of a menu, which may be good for prestanda when adding a context menu to every item in a large view collection.
+
+
+## 3.0.6
+
+This version solves an App Store submission rejection that occurred when an app pulled in Sheeeeeeeeet with Carthage.
+
+
+## 3.0.5
+
+This version changes `ContextMenuDelegateRetainer`'s `contextMenuDelegate` to an `Any` instead of its concrete type, to make it possible to use it on older iOS versions. This should not have any side-effects, since it's only used to retain the instance, never use it.
+
+
+## 3.0.4
+
+This version makes the `ActionSheet`'s `backgroundView` property public.
+
+
+## 3.0.3
+
+This version fixes some subtitle problems, where section titles and mutli select toggles didn't display their subtitles.
+
+It also fixes some behavior issues, where subtitles were incorrectly tinted.
+
+
+## 3.0.2
+
+This version adjusts the popover height calculations to include the height of a visible header. This solves the problem where the popover content would always scroll when a header was used.
+
+The version also adjusts the item height calculations, so that you no longer have to register a height for each item. This solves the problem with all items getting a zero size by default. Now, `height` is recursively resolved to the closest parent height if you haven't overridden `appearance().height` for your custom item.
+
+
+## 3.0.1
+
+This version adjusts the subtitle style to use `subtitle` instead of `value1`.
+
+It also adds a new `preferredActionSheetCellStyle` property to `MenuItem`, which you can override for your custom items.
+
+
+## 3.0.0
+
+Sheeeeeeeeet 3 contains many breaking changes, but once you understand the model changes, you will hopefully see the improvements it brings and be able to migrate your apps pretty easily. See [this migration guide][Migration-Guide] for help.
+
+This version separates the menu data model from the custom action sheet implementation, so that you can create menus without caring about how they will be presented.
+
+The new `Menu` type and all `MenuItem` types are decoupled from the presentation. This means that you can use them in more ways, for instance in custom and native action sheets, context menus etc.
+
+With these changes, you now create `ActionSheet`s with a `Menu` instead of `ActionSheetItem`s. Due to this, the `3.0` release of Sheeeeeeeeet has many breaking changes:
+
+ * All `ActionSheetItem` have been replaced by the new `MenuItem` types. Most of these items have the same name as the old ones, but without the `ActionSheet` prefix.
+ * `ActionSheetDangerButton` corresponds to the new `DestructiveButton` class.
+ * `ActionSheetCustomItemContentCell` has been moved and renamed to `CustomItemType`.
+ * `ActionSheetCollectionItemContentCell` has been moved and renamed to `CollectionItemType`.
+
+ There are also some breaking changes that involve how you work with action sheets:
+
+ * Item heights are no longer static, but an action sheet cell appearance proxy property.
+ * The action sheet header behavior is now specified in a `headerViewConfiguration` property.
+ * `CustomItem` (`ActionSheetCustomItem`) has been made non-generic.
+ * `isOkButton` and `isCancelButton` is gone. Use type checking instead, e.g. `is OkButton`.
+
+Bonus features:
+
+* The popover presenter now supports header views. It no longer hides the header by default.
+* `Menu` can be used to create action sheets, which you then present and configure like before.
+* `Menu` can be directly presented as a custom action sheet, without creating an `ActionSheet`.
+* `Menu` can be added as an iOS 13 context menu to any view.
+* `Menu` can be presented as a native `UIAlertController`.
+
+Some of the presentations above require that all items in the menu can be represented in that context.
+
+
+## 2.1.0
+
+This version adds Xcode 11 and iOS 13 support, including support for dark mode and high contrast color variants.
+
+There is a new `ActionSheetColor` enum with sheet-specific semantic colors. It uses the new, adaptive system colors in iOS 13 and falls back to older, non-adaptive colors in iOS 12 and below. You can either use the enum directly or use the static `UIColor` extension `.sheetColor(...)`.
+
+The appearance model has been extended with new a appearance type, which you can use to style your sheets. There is an `ActionSheetAppearance` base class as well as a standard `StandardActionSheetAppearance` appearance which applies a standard look, including dark mode support, high contrast color variants and SFSymbol icons on iOS 13.
+
+There are adjustments to how sheets can be dismissed. The `isDismissableWithTapOnBackground` has been renamed to `isDismissable`, since it also affects if the system can dismiss the action sheet.
+
+
## 2.0.2
## 2.0.2
-This version makes table view footer view sizes smaller to avoid a scroll offset
-issue that could occur when rotating devices that displayed sheets with a single
-custom item.
+This version makes table view footer view sizes smaller to avoid a scroll offset issue that could occur when rotating devices that displayed sheets with a single custom item.
## 2.0.1
## 2.0.1
-This version adjusts accessibility traits for selected select items and improves
-the overall accessibility experience when working with selectable items.
+This version adjusts accessibility traits for selected select items and improves the overall accessibility experience when working with selectable items.
## 2.0.0
## 2.0.0
-This version upgrades Sheeeeeeeeet and its unit test dependencies to Swift 5. The
-version contains no breaking changes.
+This version upgrades Sheeeeeeeeet and its unit test dependencies to Swift 5. It contains no breaking changes.
## 1.4.1
## 1.4.1
-This version makes `currentContext` the default presentation mode for the default
-presenter. This is due to accessibility issues with using `keyWindow` while being
-ina modal presentation. I will change how the default presenteras presents action
-sheets, but that is a future improvement.
+This version makes `currentContext` the default presentation mode for the default presenter. This is due to accessibility issues with using `keyWindow` while being ina modal presentation. I will change how the default presenteras presents action sheets, but that is a future improvement.
## 1.4.0
## 1.4.0
-This version removes the old deprecated appearance model, so if your app uses it,
-it's time to start using the appearance proxy model. Just follow the readme, and
-you'll be done in no time.
+This version removes the old deprecated appearance model, so if your app uses it, it's time to start using the appearance proxy model. Just follow the readme, and you'll be done in no time.
-This version also change which presenter to use, so that apps behaves correct on
-iPads in split screen. We still have to come up with a way to switch between the
-default and popover presenters when the split screen size changes, but that is a
-future improvement.
+This version also change which presenter to use, so that apps behaves correct on iPads in split screen. We still have to come up with a way to switch between the default and popover presenters when the split screen size changes, but that is a future improvement.
## 1.3.3
## 1.3.3
-This version adds a new `headerViewLandscapeMode` property to `ActionSheet`. You
-can set it to `.hidden` to let action sheets hide their header view in landscape
-orientation. This will free up more screen estate for the action sheet's options.
+This version adds a new `headerViewLandscapeMode` property to `ActionSheet`. You can set it to `.hidden` to let action sheets hide their header view in landscape orientation. This will free up more screen estate for the action sheet's options.
## 1.3.3
## 1.3.3
-This version adds a new `headerViewLandscapeMode` property to `ActionSheet`. You
-can set it to `.hidden` to let action sheets hide their header view in landscape
-orientation. This will free up more screen estate for the action sheet's options.
+This version adds a new `headerViewLandscapeMode` property to `ActionSheet`. You can set it to `.hidden` to let action sheets hide their header view in landscape orientation. This will free up more screen estate for the action sheet's options.
## 1.3.2
## 1.3.2
-This version makes the `ActionSheet` `backgroundView` outlet public, so that you
-can add your own custom effects to it. The other outlets are still internal.
+This version makes the `ActionSheet` `backgroundView` outlet public, so that you can add your own custom effects to it. The other outlets are still internal.
-The version also fixes a bug that caused action sheets to be misplaced when they
-were presented from a custom presentation controller. This fix also adds a brand
-new `presentationStyle` property to `StandardActionSheetPresenter`, which can be
-either `keyWindow` (default) or `currentContext`. Setting it to `keyWindow` will
-present the action sheet in the app's key window (full screen), while setting it
-to `currentContext` will present it in the presenting view controller's view (it
-looks straaange, but perhaps you can find a nice use case for it).
+The version also fixes a bug that caused action sheets to be misplaced when they were presented from a custom presentation controller. This fix also adds a brand new `presentationStyle` property to `StandardActionSheetPresenter`, which can be either `keyWindow` (default) or `currentContext`. Setting it to `keyWindow` will present the action sheet in the app's key window (full screen), while setting it to `currentContext` will present it in the presenting view controller's view (it looks straaange, but perhaps you can find a nice use case for it).
## 1.3.1
## 1.3.1
-This version fixes an iOS 9 bug that caused the popover to become square with no
-arrow. It was caused by the popover presenter, that set the background color for
-the popover after it had been presented, which is not supported in iOS 9. It now
-sets the bg color for all iOS versions before it presents the popover, then only
-refreshes it for iOS 10 and later.
+This version fixes an iOS 9 bug that caused the popover to become square with no arrow. It was caused by the popover presenter, that set the background color for the popover after it had been presented, which is not supported in iOS 9. It now sets the bg color for all iOS versions before it presents the popover, then only refreshes it for iOS 10 and later.
-This version fixes another iOS 9 bug that caused the item cell separator line to
-behave strangely and not honor the insets set using the appearance proxy. I have
-added a fix to the item cell class, that only runs for iOS 9.
+This version fixes another iOS 9 bug that caused the item cell separator line to behave strangely and not honor the insets set using the appearance proxy. I have added a fix to the item cell class, that only runs for iOS 9.
## 1.3.0
## 1.3.0
This version removes the last separator line from the item and button table view.
This version removes the last separator line from the item and button table view.
-This version also changes the default behavior of the popover presenter. It used
-to keep the popover presented as the device orientation changed, but this can be
-wrong in many cases. For instance, in collection or table views, the orientation
-change may cause cells to shuffle around as they are reused. If a reused cell is
-used as the popover source view, and the popover is still presented, the popover
-will point to the cell, but the cell model will have changed. In this case, your
-action sheet will appear to point to a specific object, but will be contextually
-bound to another one.
+This version also changes the default behavior of the popover presenter. It used to keep the popover presented as the device orientation changed, but this can be wrong in many cases. For instance, in collection or table views, the orientation change may cause cells to shuffle around as they are reused. If a reused cell is used as the popover source view, and the popover is still presented, the popover will point to the cell, but the cell model will have changed. In this case, your action sheet will appear to point to a specific object, but will be contextually bound to another one.
-Another way that orientation changes may mess with popovers are if a source view
-is removed from the view hierarchy when the orientation changes. If your popover
-is still presented, but the source view is removed, the popover arrow will point
-to a random point, e.g. the top-left part of the screen.
+Another way that orientation changes may mess with popovers are if a source view is removed from the view hierarchy when the orientation changes. If your popover is still presented, but the source view is removed, the popover arrow will point to a random point, e.g. the top-left part of the screen.
-To solve these bugs, I have added new orientation change handling in the popover
-presenter. It has a new `isListeningToOrientationChanges` property, as well as a
-`handleOrientationChange` and `setupOrientationChangeDetection` function. If you
-want to, you can override these functions to customize their behavior, otherwise
-just set `isListeningToOrientationChanges` to `false` to make the popover behave
-like before.
+To solve these bugs, I have added new orientation change handling in the popover presenter. It has a new `isListeningToOrientationChanges` property, as well as a `handleOrientationChange` and `setupOrientationChangeDetection` function. If you want to, you can override these functions to customize their behavior, otherwise just set `isListeningToOrientationChanges` to `false` to make the popover behave like before.
## 1.2.4
## 1.2.4
-This version fixes the https://github.com/danielsaidi/Sheeeeeeeeet/issues/64 bug,
-which caused an iPad popover to become a bottom action sheet on black background,
-if the idiom changes from pad to phone while the action sheet is open. I now let
-the popover remain as long as the action sheet is open.
+This version fixes the https://github.com/danielsaidi/Sheeeeeeeeet/issues/64 bug, which caused an iPad popover to become a bottom action sheet on black background, if the idiom changes from pad to phone while the action sheet is open. I now let the popover remain as long as the action sheet is open.
## 1.2.3
## 1.2.3
-This version reloads data when scrolling to row to solve a bug that could happen
-on some iPad devices.
+This version reloads data when scrolling to row to solve a bug that could happen on some iPad devices.
## 1.2.2
## 1.2.2
-This hotfix adds two new properties to `ActionSheetSelectItem`, that can be used
-to style the selected fonts: `selectedTitleFont` and `selectedSubtitleFont`.
+This hotfix adds two new properties to `ActionSheetSelectItem`, that can be used to style the selected fonts: `selectedTitleFont` and `selectedSubtitleFont`.
## 1.2.1
## 1.2.1
@@ -134,27 +184,17 @@ This hotfix fixes a font bug in the title item and color bugs in the select item
## 1.2.0
## 1.2.0
-This is a huge update, that completely rewrites how action sheet appearances are
-handled. Instead of the old appearance model, Sheeeeeeeeet now relies on the iOS
-appearance proxy model as much as possible.
+This is a huge update, that completely rewrites how action sheet appearances are handled. Instead of the old appearance model, Sheeeeeeeeet now relies on the iOS appearance proxy model as much as possible.
-The old appearance model is still around, but has been marked as deprecated, and
-will be removed in `1.4.0`. Make sure that you switch over to the new appearance
-model as soon as possible. Have a look at the example app and [here][Appearance]
-to see how you should customize the action sheet appearance from now on.
+The old appearance model is still around, but has been marked as deprecated, and will be removed in `1.4.0`. Make sure that you switch over to the new appearance model as soon as possible. Have a look at the example app and [here][Appearance] to see how you should customize the action sheet appearance from now on.
In short, item appearance customizations are handled in three different ways now:
In short, item appearance customizations are handled in three different ways now:
-* Item appearances such as colors and fonts, are customized with cell properties,
-* Item heights are now customized by setting the `height` property of every item
-type you want to customize, for instance: `ActionSheetTitle.height = 22`.
-* Action sheet margins, insets etc. are now customized by setting the properties
-of each `ActionSheet` instance. If you want to change the default values for all
-action sheets in your app, you have to subclass `ActionSheet`.
+* Item appearances such as colors and fonts, are customized with cell properties, for instance: `ActionSheetSelectItemCell.appearance().titleColor = .green`.
+* Item heights are now customized by setting the `height` property of every item type you want to customize, for instance: `ActionSheetTitle.height = 22`.
+* Action sheet margins, insets etc. are now customized by setting the properties of each `ActionSheet` instance. If you want to change the default values for all action sheets in your app, you have to subclass `ActionSheet`.
-All built-in action sheet items now have their own cells. Your custom items only
-have to use custom cells if you want to apply custom item appearances to them.
+All built-in action sheet items now have their own cells. Your custom items only have to use custom cells if you want to apply custom item appearances to them.
Sheeeeeeeeet now contains several new views, which are used by the action sheets:
Sheeeeeeeeet now contains several new views, which are used by the action sheets:
@@ -164,75 +204,54 @@ Sheeeeeeeeet now contains several new views, which are used by the action sheets
* `ActionSheetBackgroundView`
* `ActionSheetBackgroundView`
* `ActionSheetStackView`
* `ActionSheetStackView`
-The new classes make it easy to modify the appearance of these views, since they
-have appearance properties as well. For instance, to change the corner radius of
-the table views, just type: `ActionSheetTableView.appearance().cornerRadius = 8`.
+The new classes make it easy to modify the appearance of these views, since they have appearance properties as well. For instance, to change the corner radius of the table views, just type: `ActionSheetTableView.appearance().cornerRadius = 8`.
`ActionSheet` has two new extensions:
`ActionSheet` has two new extensions:
* `items<T>(ofType:)`
* `items<T>(ofType:)`
* `scrollToFirstSelectedItem(at:)`
* `scrollToFirstSelectedItem(at:)`
-This new version has also rebuilt all unit tests from scratch. They are now more
-robust and easier to maintain.
+This new version has also rebuilt all unit tests from scratch. They are now more robust and easier to maintain.
## 1.1.0
## 1.1.0
-This version increases the action sheet integrity by restricting what you can do
-with it. This involves some breaking changes, but they should not affect you. If
-you think any new rule is bad or affect you, please let me know.
+This version increases the action sheet integrity by restricting what you can do with it. This involves some breaking changes, but they should not affect you. If you think any new rule is bad or affect you, please let me know.
**New Features**
**New Features**
-@sebbo176 has added support for subtitles in the various select items, which now
-also changes the cell style of an item if the subtitle is set. He has also added
-an unselected icon to the select items, which means that you can now have images
-for unselected items as well (e.g. an unchecked checkbox).
+@sebbo176 has added support for subtitles in the various select items, which now also changes the cell style of an item if the subtitle is set. He has also added an unselected icon to the select items, which means that you can now have images for unselected items as well (e.g. an unchecked checkbox).
**Breaking Changes - ActionSheet:**
**Breaking Changes - ActionSheet:**
-* The `items` and `buttons` properties are now `internal(set)`, which means that
-they can only be set with `init(...)` or with `setup(items:)`. This protects the
-integrity of the item and button separation logic.
-
-* The code no longer contains any `didSet` events, since these events called the
-same functionality many times. Call `refresh` if you change any outlets manually
-from now on.
-
-* Since the `didSet` events have been removed, `refreshHeaderVisibility` is only
-called once and has therefore been moved into `refreshHeader`.
-
-* Since the `didSet` events have been removed, `refreshButtonsVisibility` is now
-only called once and has therefore been moved into `refreshButtons`.
-
+* The `items` and `buttons` properties are now `internal(set)`, which means that they can only be set with `init(...)` or with `setup(items:)`. This protects the integrity of the item and button separation logic.
+* The code no longer contains any `didSet` events, since these events called the same functionality many times. Call `refresh` if you change any outlets manually from now on.
+* Since the `didSet` events have been removed, `refreshHeaderVisibility` is only called once and has therefore been moved into `refreshHeader`.
+* Since the `didSet` events have been removed, `refreshButtonsVisibility` is now only called once and has therefore been moved into `refreshButtons`.
* A small delay in `handleTap(on:)`, that should not be needed, has been removed.
* A small delay in `handleTap(on:)`, that should not be needed, has been removed.
+
Let me know if it causes any side-effects.
Let me know if it causes any side-effects.
## 1.0.3
## 1.0.3
-This version removes a debug print that I used to ensure that action sheets were
-properly deinitialized after being dismissed.
+This version removes a debug print that I used to ensure that action sheets were properly deinitialized after being dismissed.
## 1.0.2
## 1.0.2
-This version adds new background color properties to the action sheet appearance
-class. They can be used to set the background color of an entire sheet.
+This version adds new background color properties to the action sheet appearance class. They can be used to set the background color of an entire sheet.
-This version fixes a bug, where the background color behind an action sheet went
-black when the action sheet was presented in a split view.
+This version fixes a bug, where the background color behind an action sheet went black when the action sheet was presented in a split view.
## 1.0.1
## 1.0.1
-This version fixes a bug, where the presenters incorrectly updated the scrolling
-behavior of the action sheet when rotating the device.
+This version fixes a bug, where the presenters incorrectly updated the scrolling behavior of the action sheet when rotating the device.
@@ -240,28 +259,15 @@ behavior of the action sheet when rotating the device.
Sheeeeeeeeet 1.0.0 is finally here, with many internal changes and some external.
Sheeeeeeeeet 1.0.0 is finally here, with many internal changes and some external.
-This version decouples action sheets from their presentation to great extent. An
-action sheet still styles its items and components, but the presenters now takes
-care of a lot more than before. The sheet setup is now also based on constraints
-instead of manual calculations, which means that popover scrolling etc. works by
-how the constraints are setup, instead of relying on manual calculations.
+This version decouples action sheets from their presentation to great extent. An action sheet still styles its items and components, but the presenters now takes care of a lot more than before. The sheet setup is now also based on constraints instead of manual calculations, which means that popover scrolling etc. works by how the constraints are setup, instead of relying on manual calculations.
-This should result in much more robust action sheets, but it requires testing on
-a wide range of devices and orientations, so please let me know if there are any
-issues with this approach.
+This should result in much more robust action sheets, but it requires testing on a wide range of devices and orientations, so please let me know if there are any issues with this approach.
-`IMPORTANT` The button item values have changed. Insted of `true` and `nil` they
-now have a strong `ButtonType` value. You can still create custom buttons with a
-custom value, though. You can also use the new `isOkButton` and `isCancelButton`
-extensions to quickly see if a user tapped "OK" or "Cancel".
+`IMPORTANT` The button item values have changed. Insted of `true` and `nil` they now have a strong `ButtonType` value. You can still create custom buttons with a custom value, though. You can also use the new `isOkButton` and `isCancelButton` extensions to quickly see if a user tapped "OK" or "Cancel".
### Breaking changes
### Breaking changes
-Since the presentation logic has been rewritten from scratch, you have to adjust
-your code to fit the new structure, if you have subclassed any presenter or made
-presentation tweaks in your sheets. The changes are too many and extensive to be
-listed here, so please have a look at the new structure. There is much less code,
-so changing your code to the new standard should be easy.
+Since the presentation logic has been rewritten from scratch, you have to adjust your code to fit the new structure, if you have subclassed any presenter or made presentation tweaks in your sheets. The changes are too many and extensive to be listed here, so please have a look at the new structure. There is much less code, so changing your code to the new standard should be easy.
* `ActionSheetButton` and its sublasses has new values.
* `ActionSheetButton` and its sublasses has new values.
* `ActionSheet.itemTapAction` has been removed
* `ActionSheet.itemTapAction` has been removed
@@ -274,30 +280,25 @@ so changing your code to the new standard should be easy.
### New features
### New features
* `ActionSheetAppearance` has new properties, which adds new way to style sheets.
* `ActionSheetAppearance` has new properties, which adds new way to style sheets.
-* `ActionSheetButton` adds `isOkButton` and `isCancelButton` extension functions
-to `ActionSheetItem`. They can be used to quickly check if a cancel or ok button
-was tapped, instead of having to check if the item can be cast to a button type.
+* `ActionSheetButton` adds `isOkButton` and `isCancelButton` extension functions to `ActionSheetItem`. They can be used to quickly check if a cancel or ok button was tapped, instead of having to check if the item can be cast to a button type.
### Bug fixes
### Bug fixes
-* The big presentation adjustments solves the scrolling issues that occured with
-popovers and many items.
-* The `hideSeparator()` function is adjusted to behave correctly when the device
-is rotated.
+* The big presentation adjustments solves the scrolling issues that occured with popovers and many items.
+* The `hideSeparator()` function is adjusted to behave correctly when the device is rotated.
### Deprecated logic
### Deprecated logic
-Instead of deprecating presentation-related properties and functions that are no
-longer used or available, I removed them completely. Let me know if you used any
-properties that are no longer available.
+Instead of deprecating presentation-related properties and functions that are no longer used or available, I removed them completely. Let me know if you used any properties that are no longer available.
* `ActionSheetItem.setupItemsAndButtons(with:)` is renamed to `setup(items:)`
* `ActionSheetItem.setupItemsAndButtons(with:)` is renamed to `setup(items:)`
* `ActionSheetItem.itemSelectAction` is renamed to `selectAction`
* `ActionSheetItem.itemSelectAction` is renamed to `selectAction`
-Perform the deprecation warnings, and you should be all good. Deprecated members
-will be removed in the next minor version.
+Perform the deprecation warnings, and you should be all good. Deprecated members will be removed in the next minor version.
+
+# Legacy versions
## 0.11.0
## 0.11.0
@@ -555,3 +556,4 @@ moving action sheets into their own separate classes.
+[Expressions with commas](#expressions-with-commas)<br>
+
Most test frameworks have a large collection of assertion macros to capture all possible conditional forms (```_EQUALS```, ```_NOTEQUALS```, ```_GREATER_THAN``` etc).
Most test frameworks have a large collection of assertion macros to capture all possible conditional forms (```_EQUALS```, ```_NOTEQUALS```, ```_GREATER_THAN``` etc).
-Catch is different. Because it decomposes natural C-style conditional expressions most of these forms are reduced to one or two that you will use all the time. That said there are a rich set of auxilliary macros as well. We'll describe all of these here.
+Catch is different. Because it decomposes natural C-style conditional expressions most of these forms are reduced to one or two that you will use all the time. That said there is a rich set of auxiliary macros as well. We'll describe all of these here.
Most of these macros come in two forms:
Most of these macros come in two forms:
@@ -14,7 +22,7 @@ The ```CHECK``` family are equivalent but execution continues in the same test c
* **REQUIRE(** _expression_ **)** and
* **REQUIRE(** _expression_ **)** and
* **CHECK(** _expression_ **)**
* **CHECK(** _expression_ **)**
-Evaluates the expression and records the result. If an exception is thrown it is caught, reported, and counted as a failure. These are the macros you will use most of the time
+Evaluates the expression and records the result. If an exception is thrown, it is caught, reported, and counted as a failure. These are the macros you will use most of the time.
Examples:
Examples:
```
```
@@ -47,37 +55,54 @@ This expression is too complex because of the `||` operator. If you want to chec
When comparing floating point numbers - especially if at least one of them has been computed - great care must be taken to allow for rounding errors and inexact representations.
When comparing floating point numbers - especially if at least one of them has been computed - great care must be taken to allow for rounding errors and inexact representations.
-Catch provides a way to perform tolerant comparisons of floating point values through use of a wrapper class called ```Approx```. ```Approx``` can be used on either side of a comparison expression. It overloads the comparisons operators to take a tolerance into account. Here's a simple example:
+Catch provides a way to perform tolerant comparisons of floating point values through use of a wrapper class called `Approx`. `Approx` can be used on either side of a comparison expression. It overloads the comparisons operators to take a tolerance into account. Here's a simple example:
-```
+```cpp
REQUIRE( performComputation() == Approx( 2.1 ) );
REQUIRE( performComputation() == Approx( 2.1 ) );
```
```
-This way `Approx` is constructed with reasonable defaults, covering most simple cases of rounding errors. If these are insufficient, each `Approx` instance has 3 tuning knobs, that can be used to customize it for your computation.
+Catch also provides a user-defined literal for `Approx`; `_a`. It resides in
+the `Catch::literals` namespace and can be used like so:
+```cpp
+using namespace Catch::literals;
+REQUIRE( performComputation() == 2.1_a );
+```
+
+`Approx` is constructed with defaults that should cover most simple cases.
+For the more complex cases, `Approx` provides 3 customization points:
-* __epsilon__ - epsilon serves to set the percentage by which a result can be erroneous, before it is rejected. By default set to `std::numeric_limits<float>::epsilon()*100`.
-* __margin__ - margin serves to set the the absolute value by which a result can be erroneous before it is rejected. By default set to `0.0`.
-* __scale__ - scale serves to adjust the base for comparison used by epsilon. By default set to `1.0`.
+* __epsilon__ - epsilon serves to set the coefficient by which a result
+can differ from `Approx`'s value before it is rejected.
+_By default set to `std::numeric_limits<float>::epsilon()*100`._
+* __margin__ - margin serves to set the the absolute value by which
+a result can differ from `Approx`'s value before it is rejected.
+_By default set to `0.0`._
+* __scale__ - scale is used to change the magnitude of `Approx` for relative check.
+_By default set to `0.0`._
#### epsilon example
#### epsilon example
```cpp
```cpp
Approx target = Approx(100).epsilon(0.01);
Approx target = Approx(100).epsilon(0.01);
100.0 == target; // Obviously true
100.0 == target; // Obviously true
200.0 == target; // Obviously still false
200.0 == target; // Obviously still false
-100.5 == target; // True, because we set target to allow up to 1% error
+100.5 == target; // True, because we set target to allow up to 1% difference
```
```
#### margin example
#### margin example
-_Margin check is used only if the relative (epsilon and scale based) check fails._
```cpp
```cpp
Approx target = Approx(100).margin(5);
Approx target = Approx(100).margin(5);
100.0 == target; // Obviously true
100.0 == target; // Obviously true
200.0 == target; // Obviously still false
200.0 == target; // Obviously still false
-104.0 == target; // True, because we set target to allow absolute error up to 5
+104.0 == target; // True, because we set target to allow absolute difference of at most 5
```
```
#### scale
#### scale
-Scale can be useful if the computation leading to the result worked on different scale, than is used by the results (and thus expected errors are on a different scale than would be expected based on the results alone), i.e. an additional not scaling difference will be accepted, because | current - target | < eps_rel + eps_abs (while eps_rel = max(current, target) * epsilon, eps_abs = epsilon * scale) will be checked.
+Scale can be useful if the computation leading to the result worked
+on different scale than is used by the results. Since allowed difference
+between Approx's value and compared value is based primarily on Approx's value
+(the allowed difference is computed as
+`(Approx::scale + Approx::value) * epsilon`), the resulting comparison could
+need rescaling to be correct.
## Exceptions
## Exceptions
@@ -95,7 +120,7 @@ Expects that an exception (of any type) is be thrown during evaluation of the ex
* **REQUIRE_THROWS_AS(** _expression_, _exception type_ **)** and
* **REQUIRE_THROWS_AS(** _expression_, _exception type_ **)** and
-Expects that an exception of the _specified type_ is thrown during evaluation of the expression. Note that the _exception type_ is used verbatim and you should include (const) reference.
+Expects that an exception of the _specified type_ is thrown during evaluation of the expression. Note that the _exception type_ is extended with `const&` and you should not include it yourself.
* **REQUIRE_THROWS_WITH(** _expression_, _string or string matcher_ **)** and
* **REQUIRE_THROWS_WITH(** _expression_, _string or string matcher_ **)** and
* **CHECK_THROWS_WITH(** _expression_, _string or string matcher_ **)**
* **CHECK_THROWS_WITH(** _expression_, _string or string matcher_ **)**
REQUIRE_THROWS_WITH( dismantleHal(), "My mind is going" );
REQUIRE_THROWS_WITH( dismantleHal(), "My mind is going" );
```
```
+* **REQUIRE_THROWS_MATCHES(** _expression_, _exception type_, _matcher for given exception type_ **)** and
+* **CHECK_THROWS_MATCHES(** _expression_, _exception type_, _matcher for given exception type_ **)**
+
+Expects that exception of _exception type_ is thrown and it matches provided matcher (see the [documentation for Matchers](matchers.md#top)).
+
-Please note that the `THROW` family of assertions expects to be passed a single expression, not a statement or series of statements. If you want to check a more complicated sequence of operations, you can use a C++11 lambda function.
+_Please note that the `THROW` family of assertions expects to be passed a single expression, not a statement or series of statements. If you want to check a more complicated sequence of operations, you can use a C++11 lambda function._
```cpp
```cpp
REQUIRE_NOTHROW([&](){
REQUIRE_NOTHROW([&](){
@@ -122,9 +152,11 @@ REQUIRE_NOTHROW([&](){
}());
}());
```
```
+
+
## Matcher expressions
## Matcher expressions
-To support Matchers a slightly different form is used. Matchers have [their own documentation](matchers.md).
+To support Matchers a slightly different form is used. Matchers have [their own documentation](matchers.md#top).
* **REQUIRE_THAT(** _lhs_, _matcher expression_ **)** and
* **REQUIRE_THAT(** _lhs_, _matcher expression_ **)** and
-Build Systems may refer to low-level tools, like CMake, or larger systems that run on servers, like Jenkins or TeamCity. This page will talk about both.
-
-# Continuous Integration systems
-
-Probably the most important aspect to using Catch with a build server is the use of different reporters. Catch comes bundled with three reporters that should cover the majority of build servers out there - although adding more for better integration with some is always a possibility (currently we also offer TeamCity, TAP and Automake reporters).
-
-Two of these reporters are built in (XML and JUnit) and the third (TeamCity) is included as a separate header. It's possible that the other two may be split out in the future too - as that would make the core of Catch smaller for those that don't need them.
-
-## XML Reporter
-```-r xml```
-
-The XML Reporter writes in an XML format that is specific to Catch.
-
-The advantage of this format is that it corresponds well to the way Catch works (especially the more unusual features, such as nested sections) and is a fully streaming format - that is it writes output as it goes, without having to store up all its results before it can start writing.
-
-The disadvantage is that, being specific to Catch, no existing build servers understand the format natively. It can be used as input to an XSLT transformation that could convert it to, say, HTML - although this loses the streaming advantage, of course.
-
-## JUnit Reporter
-```-r junit```
-
-The JUnit Reporter writes in an XML format that mimics the JUnit ANT schema.
-
-The advantage of this format is that the JUnit Ant schema is widely understood by most build servers and so can usually be consumed with no additional work.
-
-The disadvantage is that this schema was designed to correspond to how JUnit works - and there is a significant mismatch with how Catch works. Additionally the format is not streamable (because opening elements hold counts of failed and passing tests as attributes) - so the whole test run must complete before it can be written.
-
-## Other reporters
-Other reporters are not part of the single-header distribution and need to be downloaded and included separately. All reporters are stored in `include/reporters` directory in the git repository, and are named `catch_reporter_*.hpp`. For example, to use the TeamCity reporter you need to download `include/reporters/catch_reporter_teamcity.hpp` and include it after Catch itself.
-
-```
-#define CATCH_CONFIG_MAIN
-#include "catch.hpp"
-#include "catch_reporter_teamcity.hpp"
-```
-
-### TeamCity Reporter
-```-r teamcity```
-
-The TeamCity Reporter writes TeamCity service messages to stdout. In order to be able to use this reporter an additional header must also be included.
-
-Being specific to TeamCity this is the best reporter to use with it - but it is completely unsuitable for any other purpose. It is a streaming format (it writes as it goes) - although test results don't appear in the TeamCity interface until the completion of a suite (usually the whole test run).
-
-### Automake Reporter
-```-r automake```
-
-The Automake Reporter writes out the [meta tags](https://www.gnu.org/software/automake/manual/html_node/Log-files-generation-and-test-results-recording.html#Log-files-generation-and-test-results-recording) expected by automake via `make check`.
-
-### TAP (Test Anything Protocol) Reporter
-```-r tap```
-
-Because of the incremental nature of Catch's test suites and ability to run specific tests, our implementation of TAP reporter writes out the number of tests in a suite last.
-
-# Low-level tools
-
-## CMake
-
-In general we recommend "vendoring" Catch's single-include releases inside your own repository. If you do this, the following example shows a minimal CMake project:
-# Expose required variable (CATCH_INCLUDE_DIR) to parent scope
-ExternalProject_Get_Property(catch source_dir)
-set(CATCH_INCLUDE_DIR ${source_dir}/single_include CACHE INTERNAL "Path to include folder for Catch")
-```
-
-If you put it in, e.g., `${PROJECT_SRC_DIR}/${EXT_PROJECTS_DIR}/catch/`, you can use it in your project by adding the following to your root CMake file:
-The advantage of this approach is that you can always automatically update Catch to the latest release. The disadvantage is that it means bringing in lot more than you need.
-
-
-### Automatic test registration
-If you are also using ctest, `contrib/ParseAndAddCatchTests.cmake` is a CMake script that attempts to parse your test files and automatically register all test cases, using tags as labels. This means that these
-```cpp
-TEST_CASE("Test1", "[unit]") {
- int a = 1;
- int b = 2;
- REQUIRE(a == b);
-}
-
-TEST_CASE("Test2") {
- int a = 1;
- int b = 2;
- REQUIRE(a == b);
-}
-
-TEST_CASE("Test3", "[a][b][c]") {
- int a = 1;
- int b = 2;
- REQUIRE(a == b);
-}
-```
-would be registered as 3 tests, `Test1`, `Test2` and `Test3`, and ctest 4 labels would be created, `a`, `b`, `c` and `unit`.
-
-### CodeCoverage module (GCOV, LCOV...)
-
-If you are using GCOV tool to get testing coverage of your code, and are not sure how to integrate it with CMake and Catch, there should be an external example over at https://github.com/fkromer/catch_cmake_coverage
Catch works quite nicely without any command line options at all - but for those times when you want greater control the following options are available.
Catch works quite nicely without any command line options at all - but for those times when you want greater control the following options are available.
-Click one of the followings links to take you straight to that option - or scroll on to browse the available options.
+Click one of the following links to take you straight to that option - or scroll on to browse the available options.
@@ -50,7 +86,7 @@ Wildcards consist of the `*` character at the beginning and/or end of test case
Test specs are case insensitive.
Test specs are case insensitive.
-If a spec is prefixed with `exclude:` or the `~` character then the pattern matches an exclusion. This means that tests matching the pattern are excluded from the set - even if a prior inclusion spec included them. Subsequent inclusion specs will take precendence, however.
+If a spec is prefixed with `exclude:` or the `~` character then the pattern matches an exclusion. This means that tests matching the pattern are excluded from the set - even if a prior inclusion spec included them. Subsequent inclusion specs will take precedence, however.
Inclusions and exclusions are evaluated in left-to-right order.
Inclusions and exclusions are evaluated in left-to-right order.
Test case examples:
Test case examples:
@@ -66,7 +102,7 @@ a* ~ab* abc Matches all tests that start with 'a', except those that
</pre>
</pre>
Names within square brackets are interpreted as tags.
Names within square brackets are interpreted as tags.
-A series of tags form an AND expression wheras a comma-separated sequence forms an OR expression. e.g.:
+A series of tags form an AND expression whereas a comma-separated sequence forms an OR expression. e.g.:
<pre>[one][two],[three]</pre>
<pre>[one][two],[three]</pre>
This matches all tests tagged `[one]` and `[two]`, as well as all tests tagged `[three]`
This matches all tests tagged `[one]` and `[two]`, as well as all tests tagged `[three]`
@@ -94,7 +130,9 @@ The JUnit reporter is an xml format that follows the structure of the JUnit XML
## Breaking into the debugger
## Breaking into the debugger
<pre>-b, --break</pre>
<pre>-b, --break</pre>
-In some IDEs (currently XCode and Visual Studio) it is possible for Catch to break into the debugger on a test failure. This can be very helpful during debug sessions - especially when there is more than one path through a particular test.
+Under most debuggers Catch2 is capable of automatically breaking on a test
+failure. This allows the user to see the current state of the test during
+failure.
<a id="showing-results-for-successful-tests"></a>
<a id="showing-results-for-successful-tests"></a>
## Showing results for successful tests
## Showing results for successful tests
@@ -164,9 +202,16 @@ This option transforms tabs and newline characters into ```\t``` and ```\n``` re
## Warnings
## Warnings
<pre>-w, --warn <warning name></pre>
<pre>-w, --warn <warning name></pre>
-Enables reporting of warnings (only one, at time of this writing). If a warning is issued it fails the test.
+Enables reporting of suspicious test states. There are currently two
+available warnings
+
+```
+ NoAssertions // Fail test case / leaf section if no assertions
+ // (e.g. `REQUIRE`) is encountered.
+ NoTests // Return non-zero exit code when no test cases were run
+ // Also calls reporter's noMatchingTestCases method
+```
-The ony available warning, presently, is ```NoAssertions```. This warning fails a test case, or (leaf) section if no assertions (```REQUIRE```/ ```CHECK``` etc) are encountered.
<a id="reporting-timings"></a>
<a id="reporting-timings"></a>
## Reporting timings
## Reporting timings
@@ -197,7 +242,7 @@ Test cases are ordered one of three ways:
### decl
### decl
-Declaration order. The order the tests were originally declared in. Note that ordering between files is not guaranteed and is implementation dependent.
+Declaration order (this is the default order if no --order argument is provided). The order the tests were originally declared in. Note that ordering between files is not guaranteed and is implementation dependent.
### lex
### lex
Lexicographically sorted. Tests are sorted, alpha-numerically, by name.
Lexicographically sorted. Tests are sorted, alpha-numerically, by name.
@@ -211,7 +256,7 @@ Randomly sorted. Test names are sorted using ```std::random_shuffle()```. By def
Sets a seed for the random number generator using ```std::srand()```.
Sets a seed for the random number generator using ```std::srand()```.
If a number is provided this is used directly as the seed so the random pattern is repeatable.
If a number is provided this is used directly as the seed so the random pattern is repeatable.
-Alternatively if the keyword ```time``` is provided then the result of calling ```std::time(0)``` is used and so the pattern becomes unpredictable.
+Alternatively if the keyword ```time``` is provided then the result of calling ```std::time(0)``` is used and so the pattern becomes unpredictable. In some cases, you might need to pass the keyword ```time``` in double quotes instead of single quotes.
In either case the actual value for the seed is printed as part of Catch's output so if an issue is discovered that is sensitive to test ordering the ordering can be reproduced - even if it was originally seeded from ```std::time(0)```.
In either case the actual value for the seed is printed as part of Catch's output so if an issue is discovered that is sensitive to test ordering the ordering can be reproduced - even if it was originally seeded from ```std::time(0)```.
@@ -228,6 +273,48 @@ See [The LibIdentify repo for more information and examples](https://github.com/
Will cause the executable to print a message and wait until the return/ enter key is pressed before continuing -
Will cause the executable to print a message and wait until the return/ enter key is pressed before continuing -
either before running any tests, after running all tests - or both, depending on the argument.
either before running any tests, after running all tests - or both, depending on the argument.
+<a id="benchmark-samples"></a>
+## Specify the number of benchmark samples to collect
+<pre>--benchmark-samples <# of samples></pre>
+
+> [Introduced](https://github.com/catchorg/Catch2/issues/1616) in Catch 2.9.0.
+
+When running benchmarks a number of "samples" is collected. This is the base data for later statistical analysis.
+Per sample a clock resolution dependent number of iterations of the user code is run, which is independent of the number of samples. Defaults to 100.
+
+<a id="benchmark-resamples"></a>
+## Specify the number of resamples for bootstrapping
+<pre>--benchmark-resamples <# of resamples></pre>
+
+> [Introduced](https://github.com/catchorg/Catch2/issues/1616) in Catch 2.9.0.
+
+After the measurements are performed, statistical [bootstrapping] is performed
+on the samples. The number of resamples for that bootstrapping is configurable
+but defaults to 100000. Due to the bootstrapping it is possible to give
+estimates for the mean and standard deviation. The estimates come with a lower
+bound and an upper bound, and the confidence interval (which is configurable but
Catch is designed to "just work" as much as possible. For most people the only configuration needed is telling Catch which source file should host all the implementation code (```CATCH_CONFIG_MAIN```).
Catch is designed to "just work" as much as possible. For most people the only configuration needed is telling Catch which source file should host all the implementation code (```CATCH_CONFIG_MAIN```).
Nonetheless there are still some occasions where finer control is needed. For these occasions Catch exposes a set of macros for configuring how it is built.
Nonetheless there are still some occasions where finer control is needed. For these occasions Catch exposes a set of macros for configuring how it is built.
-# main()/ implementation
+## main()/ implementation
- CATCH_CONFIG_MAIN // Designates this as implementation file and defines main()
- CATCH_CONFIG_RUNNER // Designates this as implementation file
+ CATCH_CONFIG_MAIN // Designates this as implementation file and defines main()
+ CATCH_CONFIG_RUNNER // Designates this as implementation file
Although Catch is header only it still, internally, maintains a distinction between interface headers and headers that contain implementation. Only one source file in your test project should compile the implementation headers and this is controlled through the use of one of these macros - one of these identifiers should be defined before including Catch in *exactly one implementation file in your project*.
Although Catch is header only it still, internally, maintains a distinction between interface headers and headers that contain implementation. Only one source file in your test project should compile the implementation headers and this is controlled through the use of one of these macros - one of these identifiers should be defined before including Catch in *exactly one implementation file in your project*.
-# Prefixing Catch macros
+## Reporter / Listener interfaces
+
+ CATCH_CONFIG_EXTERNAL_INTERFACES // Brings in necessary headers for Reporter/Listener implementation
+
+Brings in various parts of Catch that are required for user defined Reporters and Listeners. This means that new Reporters and Listeners can be defined in this file as well as in the main file.
- CATCH_CONFIG_PREFIX_ALL
+Implied by both `CATCH_CONFIG_MAIN` and `CATCH_CONFIG_RUNNER`.
+
+## Prefixing Catch macros
+
+ CATCH_CONFIG_PREFIX_ALL
To keep test code clean and uncluttered Catch uses short macro names (e.g. ```TEST_CASE``` and ```REQUIRE```). Occasionally these may conflict with identifiers from platform headers or the system under test. In this case the above identifier can be defined. This will cause all the Catch user macros to be prefixed with ```CATCH_``` (e.g. ```CATCH_TEST_CASE``` and ```CATCH_REQUIRE```).
To keep test code clean and uncluttered Catch uses short macro names (e.g. ```TEST_CASE``` and ```REQUIRE```). Occasionally these may conflict with identifiers from platform headers or the system under test. In this case the above identifier can be defined. This will cause all the Catch user macros to be prefixed with ```CATCH_``` (e.g. ```CATCH_TEST_CASE``` and ```CATCH_REQUIRE```).
-# Terminal colour
+## Terminal colour
- CATCH_CONFIG_COLOUR_NONE // completely disables all text colouring
- CATCH_CONFIG_COLOUR_WINDOWS // forces the Win32 console API to be used
- CATCH_CONFIG_COLOUR_ANSI // forces ANSI colour codes to be used
+ CATCH_CONFIG_COLOUR_NONE // completely disables all text colouring
+ CATCH_CONFIG_COLOUR_WINDOWS // forces the Win32 console API to be used
+ CATCH_CONFIG_COLOUR_ANSI // forces ANSI colour codes to be used
Yes, I am English, so I will continue to spell "colour" with a 'u'.
Yes, I am English, so I will continue to spell "colour" with a 'u'.
@@ -32,82 +59,106 @@ Note that when ANSI colour codes are used "unistd.h" must be includable - along
Typically you should place the ```#define``` before #including "catch.hpp" in your main source file - but if you prefer you can define it for your whole project by whatever your IDE or build system provides for you to do so.
Typically you should place the ```#define``` before #including "catch.hpp" in your main source file - but if you prefer you can define it for your whole project by whatever your IDE or build system provides for you to do so.
-# Console width
+## Console width
-CATCH_CONFIG_CONSOLE_WIDTH = x // where x is a number
+CATCH_CONFIG_CONSOLE_WIDTH = x // where x is a number
Catch formats output intended for the console to fit within a fixed number of characters. This is especially important as indentation is used extensively and uncontrolled line wraps break this.
Catch formats output intended for the console to fit within a fixed number of characters. This is especially important as indentation is used extensively and uncontrolled line wraps break this.
By default a console width of 80 is assumed but this can be controlled by defining the above identifier to be a different value.
By default a console width of 80 is assumed but this can be controlled by defining the above identifier to be a different value.
-# stdout
+## stdout
-CATCH_CONFIG_NOSTDOUT
+CATCH_CONFIG_NOSTDOUT
-Catch does not use ```std::cout```, ```std::cerr``` and ```std::clog``` directly but gets them from ```Catch::cout()```, ```Catch::cerr()``` and ```Catch::clog``` respectively. If the above identifier is defined these functions are left unimplemented and you must implement them yourself. Their signatures are:
+To support platforms that do not provide `std::cout`, `std::cerr` and
+`std::clog`, Catch does not usem the directly, but rather calls
+`Catch::cout`, `Catch::cerr` and `Catch::clog`. You can replace their
+implementation by defining `CATCH_CONFIG_NOSTDOUT` and implementing
+them yourself, their signatures are:
std::ostream& cout();
std::ostream& cout();
std::ostream& cerr();
std::ostream& cerr();
std::ostream& clog();
std::ostream& clog();
-This can be useful on certain platforms that do not provide the standard iostreams, such as certain embedded systems.
+[You can see an example of replacing these functions here.](
+../examples/231-Cfg-OutputStreams.cpp)
-# Default reporter
- CATCH_CONFIG_DEFAULT_REPORTER <reporter>
+## Fallback stringifier
-The default reporter (reporter used when no reporters are explicitly specified) can be overriden during compilation time by using the above macro. Note that desired value of the macro is a C string and quotes have to be escaped during compilation: `clang++ test.cpp -DCATCH_CONFIG_DEFAULT_REPORTER=\"xml\"`.
+By default, when Catch's stringification machinery has to stringify
+a type that does not specialize `StringMaker`, does not overload `operator<<`,
+is not an enumeration and is not a range, it uses `"{?}"`. This can be
+overridden by defining `CATCH_CONFIG_FALLBACK_STRINGIFIER` to name of a
+function that should perform the stringification instead.
-# C++ conformance toggles
+All types that do not provide `StringMaker` specialization or `operator<<`
+overload will be sent to this function (this includes enums and ranges).
+The provided function must return `std::string` and must accept any type,
+e.g. via overloading.
- CATCH_CONFIG_CPP11_NULLPTR // nullptr is supported?
- CATCH_CONFIG_CPP11_NOEXCEPT // noexcept is supported?
- CATCH_CONFIG_CPP11_GENERATED_METHODS // delete and default keywords for methods
- CATCH_CONFIG_CPP11_IS_ENUM // std::is_enum is supported?
- CATCH_CONFIG_CPP11_TUPLE // std::tuple is supported
- CATCH_CONFIG_VARIADIC_MACROS // Usually pre-C++11 compiler extensions are sufficient
- CATCH_CONFIG_CPP11_LONG_LONG // generates overloads for the long long type
- CATCH_CONFIG_CPP11_OVERRIDE // CATCH_OVERRIDE expands to override (for virtual function implementations)
- CATCH_CONFIG_CPP11_UNIQUE_PTR // Use std::unique_ptr instead of std::auto_ptr
- CATCH_CONFIG_CPP11_SHUFFLE // Use std::shuffle instead of std::random_shuffle
- CATCH_CONFIG_CPP11_TYPE_TRAITS // Use std::enable_if and <type_traits>
- CATCH_CONFIG_CPP11_STREAM_INSERTABLE_CHECK // Use C++11 expression SFINAE to check if class can be inserted to std::ostream
+_Note that if the provided function does not handle a type and this type
+requires to be stringified, the compilation will fail._
-Catch has some basic compiler detection that will attempt to select the appropriate mix of these macros. However being incomplete - and often without access to the respective compilers - this detection tends to be conservative.
-So overriding control is given to the user. If a compiler supports a feature (and Catch does not already detect it) then one or more of these may be defined to enable it (or suppress it, in some cases). If you do do this please raise an issue, specifying your compiler version (ideally with an idea of how to detect it) and stating that it has such support.
-You may also suppress any of these features by using the `_NO_` form, e.g. `CATCH_CONFIG_CPP11_NO_NULLPTR`.
-All C++11 support can be disabled with `CATCH_CONFIG_NO_CPP11`
+## Default reporter
-## `CATCH_CONFIG_CPP11_STREAM_INSERTABLE_CHECK`
+Catch's default reporter can be changed by defining macro
+`CATCH_CONFIG_DEFAULT_REPORTER` to string literal naming the desired
+default reporter.
-This flag is off by default, but allows you to resolve problems caused by types with private base class that are streamable, but the classes themselves are not. Without it, the following code will cause a compilation error:
-```cpp
-#define CATCH_CONFIG_MAIN
-#include <catch.hpp>
-struct A {};
-std::ostream &operator<< (std::ostream &o, const A &v) { return o << 0; }
+This means that defining `CATCH_CONFIG_DEFAULT_REPORTER` to `"console"`
+is equivalent with the out-of-the-box experience.
-struct B : private A {
- bool operator==(int){ return true;}
-};
-B f ();
-std::ostream g ();
+## C++11 toggles
-TEST_CASE ("Error in streamable check") {
- B x;
- REQUIRE (x == 4);
-}
-```
+ CATCH_CONFIG_CPP11_TO_STRING // Use `std::to_string`
+
+Because we support platforms whose standard library does not contain
+`std::to_string`, it is possible to force Catch to use a workaround
+based on `std::stringstream`. On platforms other than Android,
+the default is to use `std::to_string`. On Android, the default is to
+use the `stringstream` workaround. As always, it is possible to override
+Catch's selection, by defining either `CATCH_CONFIG_CPP11_TO_STRING` or
+`CATCH_CONFIG_NO_CPP11_TO_STRING`.
+
+
+## C++17 toggles
-# Other toggles
+ CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS // Use std::uncaught_exceptions instead of std::uncaught_exception
+ CATCH_CONFIG_CPP17_STRING_VIEW // Override std::string_view support detection(Catch provides a StringMaker specialization by default)
+ CATCH_CONFIG_CPP17_VARIANT // Override std::variant support detection (checked by CATCH_CONFIG_ENABLE_VARIANT_STRINGMAKER)
+ CATCH_CONFIG_CPP17_OPTIONAL // Override std::optional support detection (checked by CATCH_CONFIG_ENABLE_OPTIONAL_STRINGMAKER)
+ CATCH_CONFIG_CPP17_BYTE // Override std::byte support detection (Catch provides a StringMaker specialization by default)
+
+> `CATCH_CONFIG_CPP17_STRING_VIEW` was [introduced](https://github.com/catchorg/Catch2/issues/1376) in Catch 2.4.1.
+
+Catch contains basic compiler/standard detection and attempts to use
+some C++17 features whenever appropriate. This automatic detection
+can be manually overridden in both directions, that is, a feature
+can be enabled by defining the macro in the table above, and disabled
+by using `_NO_` in the macro, e.g. `CATCH_CONFIG_NO_CPP17_UNCAUGHT_EXCEPTIONS`.
+
+
+## Other toggles
CATCH_CONFIG_COUNTER // Use __COUNTER__ to generate unique names for test cases
CATCH_CONFIG_COUNTER // Use __COUNTER__ to generate unique names for test cases
CATCH_CONFIG_WINDOWS_SEH // Enable SEH handling on Windows
CATCH_CONFIG_WINDOWS_SEH // Enable SEH handling on Windows
CATCH_CONFIG_FAST_COMPILE // Sacrifices some (rather minor) features for compilation speed
CATCH_CONFIG_FAST_COMPILE // Sacrifices some (rather minor) features for compilation speed
+ CATCH_CONFIG_DISABLE_MATCHERS // Do not compile Matchers in this compilation unit
CATCH_CONFIG_WINDOWS_CRTDBG // Enable leak checking using Windows's CRT Debug Heap
CATCH_CONFIG_WINDOWS_CRTDBG // Enable leak checking using Windows's CRT Debug Heap
CATCH_CONFIG_DISABLE_STRINGIFICATION // Disable stringifying the original expression
CATCH_CONFIG_DISABLE_STRINGIFICATION // Disable stringifying the original expression
+ CATCH_CONFIG_DISABLE // Disables assertions and test case registration
+ CATCH_CONFIG_WCHAR // Enables use of wchart_t
+ CATCH_CONFIG_EXPERIMENTAL_REDIRECT // Enables the new (experimental) way of capturing stdout/stderr
+ CATCH_CONFIG_ENABLE_BENCHMARKING // Enables the integrated benchmarking features (has a significant effect on compilation speed)
+ CATCH_CONFIG_USE_ASYNC // Force parallel statistical processing of samples during benchmarking
+ CATCH_CONFIG_ANDROID_LOGWRITE // Use android's logging system for debug output
+ CATCH_CONFIG_GLOBAL_NEXTAFTER // Use nextafter{,f,l} instead of std::nextafter
+
+> [`CATCH_CONFIG_ANDROID_LOGWRITE`](https://github.com/catchorg/Catch2/issues/1743) and [`CATCH_CONFIG_GLOBAL_NEXTAFTER`](https://github.com/catchorg/Catch2/pull/1739) were introduced in Catch 2.10.0
Currently Catch enables `CATCH_CONFIG_WINDOWS_SEH` only when compiled with MSVC, because some versions of MinGW do not have the necessary Win32 API support.
Currently Catch enables `CATCH_CONFIG_WINDOWS_SEH` only when compiled with MSVC, because some versions of MinGW do not have the necessary Win32 API support.
@@ -115,26 +166,97 @@ Currently Catch enables `CATCH_CONFIG_WINDOWS_SEH` only when compiled with MSVC,
`CATCH_CONFIG_WINDOWS_CRTDBG` is off by default. If enabled, Windows's CRT is used to check for memory leaks, and displays them after the tests finish running.
`CATCH_CONFIG_WINDOWS_CRTDBG` is off by default. If enabled, Windows's CRT is used to check for memory leaks, and displays them after the tests finish running.
-Just as with the C++11 conformance toggles, these toggles can be disabled by using `_NO_` form of the toggle, e.g. `CATCH_CONFIG_NO_WINDOWS_SEH`.
+`CATCH_CONFIG_WCHAR` is on by default, but can be disabled. Currently
+it is only used in support for DJGPP cross-compiler.
+
+With the exception of `CATCH_CONFIG_EXPERIMENTAL_REDIRECT`,
+these toggles can be disabled by using `_NO_` form of the toggle,
+e.g. `CATCH_CONFIG_NO_WINDOWS_SEH`.
+
+### `CATCH_CONFIG_FAST_COMPILE`
+This compile-time flag speeds up compilation of assertion macros by ~20%,
+by disabling the generation of assertion-local try-catch blocks for
+non-exception family of assertion macros ({`REQUIRE`,`CHECK`}{``,`_FALSE`, `_THAT`}).
+This disables translation of exceptions thrown under these assertions, but
+should not lead to false negatives.
+
+`CATCH_CONFIG_FAST_COMPILE` has to be either defined, or not defined,
+in all translation units that are linked into single test binary.
+
+### `CATCH_CONFIG_DISABLE_MATCHERS`
+When `CATCH_CONFIG_DISABLE_MATCHERS` is defined, all mentions of Catch's Matchers are ifdef-ed away from the translation unit. Doing so will speed up compilation of that TU.
+
+_Note: If you define `CATCH_CONFIG_DISABLE_MATCHERS` in the same file as Catch's main is implemented, your test executable will fail to link if you use Matchers anywhere._
-## `CATCH_CONFIG_FAST_COMPILE`
-Defining this flag speeds up compilation of test files by ~20%, by making 2 changes:
-* The `-b` (`--break`) flag no longer makes Catch break into debugger in the same stack frame as the failed test, but rather in a stack frame *below*.
-* The `REQUIRE` family of macros (`REQUIRE`, `REQUIRE_FALSE` and `REQUIRE_THAT`) no longer uses local try-catch block. This disables exception translation, but should not lead to false negatives.
+### `CATCH_CONFIG_DISABLE_STRINGIFICATION`
+This toggle enables a workaround for VS 2017 bug. For details see [known limitations](limitations.md#visual-studio-2017----raw-string-literal-in-assert-fails-to-compile).
-`CATCH_CONFIG_FAST_COMPILE` has to be either defined, or not defined, in all translation units that are linked into single test binary, or the behaviour of setting `-b` flag and throwing unexpected exceptions will be unpredictable.
+### `CATCH_CONFIG_DISABLE`
+This toggle removes most of Catch from given file. This means that `TEST_CASE`s are not registered and assertions are turned into no-ops. Useful for keeping tests within implementation files (ie for functions with internal linkage), instead of in external files.
-## `CATCH_CONFIG_DISABLE_STRINGIFICATION`
-This toggle enables a workaround for VS 2017 bug. For details see
+This feature is considered experimental and might change at any point.
-# Windows header clutter
+_Inspired by Doctest's `DOCTEST_CONFIG_DISABLE`_
+
+## Windows header clutter
On Windows Catch includes `windows.h`. To minimize global namespace clutter in the implementation file, it defines `NOMINMAX` and `WIN32_LEAN_AND_MEAN` before including it. You can control this behaviour via two macros:
On Windows Catch includes `windows.h`. To minimize global namespace clutter in the implementation file, it defines `NOMINMAX` and `WIN32_LEAN_AND_MEAN` before including it. You can control this behaviour via two macros:
CATCH_CONFIG_NO_NOMINMAX // Stops Catch from using NOMINMAX macro
CATCH_CONFIG_NO_NOMINMAX // Stops Catch from using NOMINMAX macro
CATCH_CONFIG_NO_WIN32_LEAN_AND_MEAN // Stops Catch from using WIN32_LEAN_AND_MEAN macro
CATCH_CONFIG_NO_WIN32_LEAN_AND_MEAN // Stops Catch from using WIN32_LEAN_AND_MEAN macro
+
+## Enabling stringification
+
+By default, Catch does not stringify some types from the standard library. This is done to avoid dragging in various standard library headers by default. However, Catch does contain these and can be configured to provide them, using these macros:
+
+ CATCH_CONFIG_ENABLE_PAIR_STRINGMAKER // Provide StringMaker specialization for std::pair
+ CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER // Provide StringMaker specialization for std::tuple
+ CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER // Provide StringMaker specialization for std::chrono::duration, std::chrono::timepoint
+ CATCH_CONFIG_ENABLE_VARIANT_STRINGMAKER // Provide StringMaker specialization for std::variant, std::monostate (on C++17)
+ CATCH_CONFIG_ENABLE_OPTIONAL_STRINGMAKER // Provide StringMaker specialization for std::optional (on C++17)
+ CATCH_CONFIG_ENABLE_ALL_STRINGMAKERS // Defines all of the above
+
+> `CATCH_CONFIG_ENABLE_VARIANT_STRINGMAKER` was [introduced](https://github.com/catchorg/Catch2/issues/1380) in Catch 2.4.1.
+
+> `CATCH_CONFIG_ENABLE_OPTIONAL_STRINGMAKER` was [introduced](https://github.com/catchorg/Catch2/issues/1510) in Catch 2.6.0.
+
+## Disabling exceptions
+
+> Introduced in Catch 2.4.0.
+
+By default, Catch2 uses exceptions to signal errors and to abort tests
+when an assertion from the `REQUIRE` family of assertions fails. We also
+provide an experimental support for disabling exceptions. Catch2 should
+automatically detect when it is compiled with exceptions disabled, but
+it can be forced to compile without exceptions by defining
+
+ CATCH_CONFIG_DISABLE_EXCEPTIONS
+
+Note that when using Catch2 without exceptions, there are 2 major
+limitations:
+
+1) If there is an error that would normally be signalled by an exception,
+the exception's message will instead be written to `Catch::cerr` and
+`std::terminate` will be called.
+2) If an assertion from the `REQUIRE` family of macros fails,
+`std::terminate` will be called after the active reporter returns.
+
+
+There is also a customization point for the exact behaviour of what
+happens instead of exception being thrown. To use it, define
-Catch has some known limitations, that we are not planning to change. Some of these are caused by our desire to support C++98 compilers, some of these are caused by our desire to keep Catch crossplatform, some exist because their priority is seen as low compared to the development effort they would need and some other yet are compiler/runtime bugs.
+Over time, some limitations of Catch2 emerged. Some of these are due
+to implementation details that cannot be easily changed, some of these
+are due to lack of development resources on our part, and some of these
+are due to plain old 3rd party bugs.
+
+
+## Implementation limits
+### Sections nested in loops
+
+If you are using `SECTION`s inside loops, you have to create them with
+different name per loop's iteration. The recommended way to do so is to
+incorporate the loop's counter into section's name, like so:
+
+```cpp
+TEST_CASE( "Looped section" ) {
+ for (char i = '0'; i < '5'; ++i) {
+ SECTION(std::string("Looped section ") + i) {
+ SUCCEED( "Everything is OK" );
+ }
+ }
+}
+```
+
+or with a `DYNAMIC_SECTION` macro (that was made for exactly this purpose):
+
+```cpp
+TEST_CASE( "Looped section" ) {
+ for (char i = '0'; i < '5'; ++i) {
+ DYNAMIC_SECTION( "Looped section " << i) {
+ SUCCEED( "Everything is OK" );
+ }
+ }
+}
+```
+
+### Tests might be run again if last section fails
+
+If the last section in a test fails, it might be run again. This is because
+Catch2 discovers `SECTION`s dynamically, as they are about to run, and
+if the last section in test case is aborted during execution (e.g. via
+the `REQUIRE` family of macros), Catch2 does not know that there are no
+more sections in that test case and must run the test case again.
+
## Features
## Features
This section outlines some missing features, what is their status and their possible workarounds.
This section outlines some missing features, what is their status and their possible workarounds.
### Thread safe assertions
### Thread safe assertions
-Because threading support in standard C++98 is limited (well, non-existent), assertion macros in Catch are not thread safe. This does not mean that you cannot use threads inside Catch's test, but that only single thread can interact with Catch's assertions and other macros.
+Catch2's assertion macros are not thread safe. This does not mean that
+you cannot use threads inside Catch's test, but that only single thread
+can interact with Catch's assertions and other macros.
This means that this is ok
This means that this is ok
```cpp
```cpp
@@ -34,8 +79,8 @@ because only one thread passes the `REQUIRE` macro and this is not
REQUIRE(cnt == 16);
REQUIRE(cnt == 16);
```
```
-
-_This limitation is highly unlikely to be lifted before Catch 2 is released._
+Because C++11 provides the necessary tools to do this, we are planning
+to remove this limitation in the future.
### Process isolation in a test
### Process isolation in a test
Catch does not support running tests in isolated (forked) processes. While this might in the future, the fact that Windows does not support forking and only allows full-on process creation and the desire to keep code as similar as possible across platforms, mean that this is likely to take significant development time, that is not currently available.
Catch does not support running tests in isolated (forked) processes. While this might in the future, the fact that Windows does not support forking and only allows full-on process creation and the desire to keep code as similar as possible across platforms, mean that this is likely to take significant development time, that is not currently available.
@@ -81,34 +126,20 @@ with expansion:
""\" == ""\"
""\" == ""\"
```
```
+### Visual Studio 2015 -- Alignment compilation error (C2718)
-### Visual Studio 2013 -- do-while loop withing range based for fails to compile (C2059)
-There is a known bug in Visual Studio 2013 (VC 12), that causes compilation error if range based for is followed by an assertion macro, without enclosing the block in braces. This snippet is sufficient to trigger the error
-```cpp
-#define CATCH_CONFIG_MAIN
-#include "catch.hpp"
+VS 2015 has a known bug, where `declval<T>` can cause compilation error
+if `T` has alignment requirements that it cannot meet.
-TEST_CASE("Syntax error with VC12") {
- for ( auto x : { 1 , 2, 3 } )
- REQUIRE( x < 3.14 );
-}
-```
-An easy workaround is possible, use braces:
-```cpp
-#define CATCH_CONFIG_MAIN
-#include "catch.hpp"
-TEST_CASE("No longer a syntax error with VC12") {
- for ( auto x : { 1 , 2, 3 } ) {
- REQUIRE( x < 3.14 );
- }
-}
-```
+A workaround is to explicitly specialize `Catch::is_range` for given
+type (this avoids code path that uses `declval<T>` in a SFINAE context).
+
-### Visual Studio 2003 -- Syntax error caused by improperly expanded `__LINE__` macro
-Older version of Visual Studio can have trouble compiling Catch, not expanding the `__LINE__` macro properly when recompiling the test binary. This is caused by Edit and Continue being on.
+### Visual Studio 2015 -- Wrong line number reported in debug mode
+VS 2015 has a known bug where `__LINE__` macro can be improperly expanded under certain circumstances, while compiling multi-file project in Debug mode.
-A workaround is to turn off Edit and Continue when compiling the test binary.
+A workaround is to compile the binary in Release mode.
### Clang/G++ -- skipping leaf sections after an exception
### Clang/G++ -- skipping leaf sections after an exception
Some versions of `libc++` and `libstdc++` (or their runtimes) have a bug with `std::uncaught_exception()` getting stuck returning `true` after rethrow, even if there are no active exceptions. One such case is this snippet, which skipped the sections "a" and "b", when compiled against `libcxxrt` from master
Some versions of `libc++` and `libstdc++` (or their runtimes) have a bug with `std::uncaught_exception()` getting stuck returning `true` after rethrow, even if there are no active exceptions. One such case is this snippet, which skipped the sections "a" and "b", when compiled against `libcxxrt` from master
@@ -129,3 +160,19 @@ TEST_CASE("b") {
```
```
If you are seeing a problem like this, i.e. a weird test paths that trigger only under Clang with `libc++`, or only under very specific version of `libstdc++`, it is very likely you are seeing this. The only known workaround is to use a fixed version of your standard library.
If you are seeing a problem like this, i.e. a weird test paths that trigger only under Clang with `libc++`, or only under very specific version of `libstdc++`, it is very likely you are seeing this. The only known workaround is to use a fixed version of your standard library.
+This is a bug in `libstdc++-4.8`, where all matching methods from `<regex>` return false. Since `Matches` uses `<regex>` internally, if the underlying implementation does not work, it doesn't work either.
+
+Workaround: Use newer version of `libstdc++`.
+
+
+### libstdc++, `_GLIBCXX_DEBUG` macro and random ordering of tests
+
+Running a Catch2 binary compiled against libstdc++ with `_GLIBCXX_DEBUG`
+macro defined with `--order rand` will cause a debug check to trigger and
+abort the run due to self-assignment.
+[This is a known bug inside libstdc++](https://stackoverflow.com/questions/22915325/avoiding-self-assignment-in-stdshuffle/23691322)
+
+Workaround: Don't use `--order rand` when compiling against debug-enabled
-Additional messages can be logged during a test case. Note that the messages are scoped and thus will not be reported if failure occurs in scope preceding the message declaration. An example:
+Additional messages can be logged during a test case. Note that the messages logged with `INFO` are scoped and thus will not be reported if failure occurs in scope preceding the message declaration. An example:
```cpp
```cpp
TEST_CASE("Foo") {
TEST_CASE("Foo") {
@@ -27,10 +28,66 @@ The number is 1
```
```
When the last `CHECK` fails in the "Bar" test case, then only one message will be printed: `Test case start`.
When the last `CHECK` fails in the "Bar" test case, then only one message will be printed: `Test case start`.
+## Logging without local scope
+
+> [Introduced](https://github.com/catchorg/Catch2/issues/1522) in Catch 2.7.0.
+
+`UNSCOPED_INFO` is similar to `INFO` with two key differences:
+
+- Lifetime of an unscoped message is not tied to its own scope.
+- An unscoped message can be reported by the first following assertion only, regardless of the result of that assertion.
+
+In other words, lifetime of `UNSCOPED_INFO` is limited by the following assertion (or by the end of test case/section, whichever comes first) whereas lifetime of `INFO` is limited by its own scope.
+
+These differences make this macro useful for reporting information from helper functions or inner scopes. An example:
+
+```cpp
+void print_some_info() {
+ UNSCOPED_INFO("Info from helper");
+}
+
+TEST_CASE("Baz") {
+ print_some_info();
+ for (int i = 0; i < 2; ++i) {
+ UNSCOPED_INFO("The number is " << i);
+ }
+ CHECK(false);
+}
+
+TEST_CASE("Qux") {
+ INFO("First info");
+ UNSCOPED_INFO("First unscoped info");
+ CHECK(false);
+
+ INFO("Second info");
+ UNSCOPED_INFO("Second unscoped info");
+ CHECK(false);
+}
+```
+
+"Baz" test case prints:
+```
+Info from helper
+The number is 0
+The number is 1
+```
+
+With "Qux" test case, two messages will be printed when the first `CHECK` fails:
+```
+First info
+First unscoped info
+```
+
+"First unscoped info" message will be cleared after the first `CHECK`, while "First info" message will persist until the end of the test case. Therefore, when the second `CHECK` fails, three messages will be printed:
+```
+First info
+Second info
+Second unscoped info
+```
## Streaming macros
## Streaming macros
-All these macros allow heterogenous sequences of values to be streaming using the insertion operator (```<<```) in the same way that std::ostream, std::cout, etc support it.
+All these macros allow heterogeneous sequences of values to be streaming using the insertion operator (```<<```) in the same way that std::ostream, std::cout, etc support it.
E.g.:
E.g.:
```c++
```c++
@@ -42,7 +99,16 @@ These macros come in three forms:
**INFO(** _message expression_ **)**
**INFO(** _message expression_ **)**
-The message is logged to a buffer, but only reported with the next assertion that is logged. This allows you to log contextual information in case of failures which is not shown during a successful test run (for the console reporter, without -s). Messages are removed from the buffer at the end of their scope, so may be used, for example, in loops.
+The message is logged to a buffer, but only reported with next assertions that are logged. This allows you to log contextual information in case of failures which is not shown during a successful test run (for the console reporter, without -s). Messages are removed from the buffer at the end of their scope, so may be used, for example, in loops.
+
+_Note that in Catch2 2.x.x `INFO` can be used without a trailing semicolon as there is a trailing semicolon inside macro.
+This semicolon will be removed with next major version. It is highly advised to use a trailing semicolon after `INFO` macro._
+
+**UNSCOPED_INFO(** _message expression_ **)**
+
+> [Introduced](https://github.com/catchorg/Catch2/issues/1522) in Catch 2.7.0.
+
+Similar to `INFO`, but messages are not limited to their own scope: They are removed from the buffer after each assertion, section or test case, whichever comes first.
**WARN(** _message expression_ **)**
**WARN(** _message expression_ **)**
@@ -56,27 +122,38 @@ The message is reported and the test case fails.
AS `FAIL`, but does not abort the test
AS `FAIL`, but does not abort the test
-## Quickly capture a variable value
+## Quickly capture value of variables or expressions
-Sometimes you just want to log the name and value of a variable. While you can easily do this with the INFO macro, above, as a convenience the CAPTURE macro handles the stringising of the variable name for you (actually it works with any expression, not just variables).
+Sometimes you just want to log a value of variable, or expression. For
+convenience, we provide the `CAPTURE` macro, that can take a variable,
+or an expression, and prints out that variable/expression and its value
+at the time of capture.
-E.g.
-```c++
-CAPTURE( theAnswer );
+e.g. `CAPTURE( theAnswer );` will log message "theAnswer := 42", while
+```cpp
+int a = 1, b = 2, c = 3;
+CAPTURE( a, b, c, a + b, c > b, a == 1);
+```
+will log a total of 6 messages:
+```
+a := 1
+b := 2
+c := 3
+a + b := 3
+c > b := true
+a == 1 := true
```
```
-This would log something like:
-
-<pre>"theAnswer := 42"</pre>
-
-## Deprecated macros
-
-**SCOPED_INFO and SCOPED_CAPTURE**
+You can also capture expressions that use commas inside parentheses
+(e.g. function calls), brackets, or braces (e.g. initializers). To
+properly capture expression that contains template parameters list
+(in other words, it contains commas between angle brackets), you need
+to enclose the expression inside parentheses:
+`CAPTURE( (std::pair<int, int>{1, 2}) );`
-These macros are now deprecated and are just aliases for INFO and CAPTURE (which were not previously scoped).
-Currently Catch has some string matchers and some vector matchers. They are in the `Catch::Matchers` and `Catch` namespaces.
-The string matchers are `StartsWith`, `EndsWith`, `Contains` and `Equals`. Each of them also takes an optional second argument, that decides case sensitivity (by-default, they are case sensitive).
-The vector matchers are `Contains`, `VectorContains` and `Equals`. `VectorContains` looks for a single element in the matched vector, `Contains` looks for a set (vector) of elements inside the matched vector.
+Catch2 provides some matchers by default. They can be found in the
+`Catch::Matchers::foo` namespace and are imported into the `Catch`
+namespace as well.
+
+There are two parts to each of the built-in matchers, the matcher
+type itself and a helper function that provides template argument
+deduction when creating templated matchers. As an example, the matcher
+for checking that two instances of `std::vector` are identical is
+`EqualsMatcher<T>`, but the user is expected to use the `Equals`
+helper function instead.
+
+
+### String matchers
+The string matchers are `StartsWith`, `EndsWith`, `Contains`, `Equals` and `Matches`. The first four match a literal (sub)string against a result, while `Matches` takes and matches an ECMAScript regex. Do note that `Matches` matches the string as a whole, meaning that "abc" will not match against "abcd", but "abc.*" will.
+
+Each of the provided `std::string` matchers also takes an optional second argument, that decides case sensitivity (by-default, they are case sensitive).
+
+
+### Vector matchers
+Catch2 currently provides 5 built-in matchers that work on `std::vector`.
+These are
+
+ * `Contains` which checks whether a specified vector is present in the result
+ * `VectorContains` which checks whether a specified element is present in the result
+ * `Equals` which checks whether the result is exactly equal (order matters) to a specific vector
+ * `UnorderedEquals` which checks whether the result is equal to a specific vector under a permutation
+ * `Approx` which checks whether the result is "approx-equal" (order matters, but comparison is done via `Approx`) to a specific vector
+> Approx matcher was [introduced](https://github.com/catchorg/Catch2/issues/1499) in Catch 2.7.2.
+
+
+### Floating point matchers
+Catch2 provides 3 matchers for working with floating point numbers. These
+are `WithinAbsMatcher`, `WithinUlpsMatcher` and `WithinRelMatcher`.
+
+The `WithinAbsMatcher` matcher accepts floating point numbers that are
+within a certain distance of target. It should be constructed with the
-Catch is great for open source. With its [liberal license](../LICENSE.txt) and single-header, dependency-free, distribution
+Catch is great for open source. With its [liberal license](../LICENSE.txt) and single-header, dependency-free, distribution
it's easy to just drop the header into your project and start writing tests - what's not to like?
it's easy to just drop the header into your project and start writing tests - what's not to like?
As a result Catch is now being used in many Open Source projects, including some quite well known ones.
As a result Catch is now being used in many Open Source projects, including some quite well known ones.
This page is an attempt to track those projects. Obviously it can never be complete.
This page is an attempt to track those projects. Obviously it can never be complete.
This effort largely relies on the maintainers of the projects themselves updating this page and submitting a PR
This effort largely relies on the maintainers of the projects themselves updating this page and submitting a PR
-(or, if you prefer contact one of the maintainers of Catch directly, use the
+(or, if you prefer contact one of the maintainers of Catch directly, use the
[forums](https://groups.google.com/forum/?fromgroups#!forum/catch-forum)), or raise an [issue](https://github.com/philsquared/Catch/issues) to let us know).
[forums](https://groups.google.com/forum/?fromgroups#!forum/catch-forum)), or raise an [issue](https://github.com/philsquared/Catch/issues) to let us know).
Of course users of those projects might want to update this page too. That's fine - as long you're confident the project maintainers won't mind.
Of course users of those projects might want to update this page too. That's fine - as long you're confident the project maintainers won't mind.
-If you're an Open Source project maintainer and see your project listed here but would rather it wasn't -
+If you're an Open Source project maintainer and see your project listed here but would rather it wasn't -
just let us know via any of the previously mentioned means - although I'm sure there won't be many who feel that way.
just let us know via any of the previously mentioned means - although I'm sure there won't be many who feel that way.
-
+
Listing a project here does not imply endorsement and the plan is to keep these ordered alphabetically to avoid an implication of relative importance.
Listing a project here does not imply endorsement and the plan is to keep these ordered alphabetically to avoid an implication of relative importance.
-A, header-only, embedded scripting language designed from the ground up to directly target C++ and take advantage of modern C++ development techniques
+A, header-only, embedded scripting language designed from the ground up to directly target C++ and take advantage of modern C++ development techniques.
### [Clara](https://github.com/philsquared/Clara)
### [Clara](https://github.com/philsquared/Clara)
A, single-header-only, type-safe, command line parser - which also prints formatted usage strings.
A, single-header-only, type-safe, command line parser - which also prints formatted usage strings.
+Header-only C++11 library to encode/decode base64, base64url, base32, base32hex and hex (a.k.a. base16) as specified in RFC 4648, plus Crockford's base32.
+[Let Catch take full control of args and config](#let-catch-take-full-control-of-args-and-config)<br>
+[Amending the config](#amending-the-config)<br>
+[Adding your own command line options](#adding-your-own-command-line-options)<br>
+[Version detection](#version-detection)<br>
+
The easiest way to use Catch is to let it supply ```main()``` for you and handle configuring itself from the command line.
The easiest way to use Catch is to let it supply ```main()``` for you and handle configuring itself from the command line.
This is achieved by writing ```#define CATCH_CONFIG_MAIN``` before the ```#include "catch.hpp"``` in *exactly one* source file.
This is achieved by writing ```#define CATCH_CONFIG_MAIN``` before the ```#include "catch.hpp"``` in *exactly one* source file.
@@ -16,21 +23,20 @@ If you just need to have code that executes before and/ or after Catch this is t
#define CATCH_CONFIG_RUNNER
#define CATCH_CONFIG_RUNNER
#include "catch.hpp"
#include "catch.hpp"
-int main( int argc, char* argv[] )
-{
+int main( int argc, char* argv[] ) {
// global setup...
// global setup...
int result = Catch::Session().run( argc, argv );
int result = Catch::Session().run( argc, argv );
// global clean-up...
// global clean-up...
- return ( result < 0xff ? result : 0xff );
+ return result;
}
}
```
```
## Amending the config
## Amending the config
-If you still want Catch to process the command line, but you want to programatically tweak the config, you can do so in one of two ways:
+If you still want Catch to process the command line, but you want to programmatically tweak the config, you can do so in one of two ways:
```c++
```c++
#define CATCH_CONFIG_RUNNER
#define CATCH_CONFIG_RUNNER
@@ -39,23 +45,24 @@ If you still want Catch to process the command line, but you want to programatic
int main( int argc, char* argv[] )
int main( int argc, char* argv[] )
{
{
Catch::Session session; // There must be exactly one instance
Catch::Session session; // There must be exactly one instance
-
+
// writing to session.configData() here sets defaults
// writing to session.configData() here sets defaults
// this is the preferred way to set them
// this is the preferred way to set them
-
+
int returnCode = session.applyCommandLine( argc, argv );
int returnCode = session.applyCommandLine( argc, argv );
if( returnCode != 0 ) // Indicates a command line error
if( returnCode != 0 ) // Indicates a command line error
- return returnCode;
-
+ return returnCode;
+
// writing to session.configData() or session.Config() here
// writing to session.configData() or session.Config() here
// overrides command line args
// overrides command line args
// only do this if you know you need to
// only do this if you know you need to
int numFailed = session.run();
int numFailed = session.run();
- // Note that on unices only the lower 8 bits are usually used, clamping
- // the return value to 255 prevents false negative when some multiple
- // of 256 tests has failed
- return ( numFailed < 0xff ? numFailed : 0xff );
+
+ // numFailed is clamped to 255 as some unices only use the lower 8 bits.
+ // This clamping has already been applied, so just return it here
+ // You can also do any post run clean-up here
+ return numFailed;
}
}
```
```
@@ -65,8 +72,60 @@ To take full control of the config simply omit the call to ```applyCommandLine()
## Adding your own command line options
## Adding your own command line options
-Catch embeds a powerful command line parser which you can also use to parse your own options out. This capability is still in active development but will be documented here when it is ready.
+Catch embeds a powerful command line parser called [Clara](https://github.com/philsquared/Clara).
+As of Catch2 (and Clara 1.0) Clara allows you to write _composable_ option and argument parsers,
+so extending Catch's own command line options is now easy.
+
+```c++
+#define CATCH_CONFIG_RUNNER
+#include "catch.hpp"
+
+int main( int argc, char* argv[] )
+{
+ Catch::Session session; // There must be exactly one instance
+
+ int height = 0; // Some user variable you want to be able to set
+
+ // Build a new parser on top of Catch's
+ using namespace Catch::clara;
+ auto cli
+ = session.cli() // Get Catch's composite command line parser
+ | Opt( height, "height" ) // bind variable to a new option, with a hint string
+ ["-g"]["--height"] // the option names it will respond to
+ ("how high?"); // description string for the help output
+
+ // Now pass the new composite back to Catch so it uses that
+ session.cli( cli );
+
+ // Let Catch (using Clara) parse the command line
+ int returnCode = session.applyCommandLine( argc, argv );
+ if( returnCode != 0 ) // Indicates a command line error
+ return returnCode;
+
+ // if set on the command line then 'height' is now set at this point
+ if( height > 0 )
+ std::cout << "height: " << height << std::endl;
+
+ return session.run();
+}
+```
+
+See the [Clara documentation](https://github.com/philsquared/Clara/blob/master/README.md) for more details.
+
+
+## Version detection
+
+Catch provides a triplet of macros providing the header's version,
+
+* `CATCH_VERSION_MAJOR`
+* `CATCH_VERSION_MINOR`
+* `CATCH_VERSION_PATCH`
+
+these macros expand into a single number, that corresponds to the appropriate
+part of the version. As an example, given single header version v2.3.4,
+the macros would expand into `2`, `3`, and `4` respectively.
+* `TEMPLATE_LIST_TEST_CASE` now properly handles non-copyable and non-movable types (#1729)
+* Fixed compilation error on Solaris caused by a system header defining macro `TT` (#1722, #1723)
+* `REGISTER_ENUM` will now fail at compilation time if the registered enum is too large
+* Removed use of `std::is_same_v` in C++17 mode (#1757)
+* Fixed parsing of escaped special characters when reading test specs from a file (#1767, #1769)
+
-# 1.12.1
+### Improvements
+* Trailing and leading whitespace in test/section specs are now ignored.
+* Writing to Android debug log now uses `__android_log_write` instead of `__android_log_print`
+* Android logging support can now be turned on/off at compile time (#1743)
+ * The toggle is `CATCH_CONFIG_ANDROID_LOGWRITE`
+* Added a generator that returns elements of a range
+ * Use via `from_range(from, to)` or `from_range(container)`
+* Added support for CRTs that do not provide `std::nextafter` (#1739)
+ * They must still provide global `nextafter{f,l,}`
+ * Enabled via `CATCH_CONFIG_GLOBAL_NEXTAFTER`
+* Special cased `Approx(inf)` not to match non-infinite values
+ * Very strictly speaking this might be a breaking change, but it should match user expectations better
+* The output of benchmarking through the Console reporter when `--benchmark-no-analysis` is set is now much simpler (#1768)
+* Added a matcher that can be used for checking an exceptions message (#1649, #1728)
+ * The matcher helper function is called `Message`
+ * The exception must publicly derive from `std::exception`
+ * The matching is done exactly, including case and whitespace
+* Added a matcher that can be used for checking relative equality of floating point numbers (#1746)
+ * Unlike `Approx`, it considers both sides when determining the allowed margin
+ * Special cases `NaN` and `INFINITY` to match user expectations
+ * The matcher helper function is called `WithinRel`
+* The ULP matcher now allows for any possible distance between the two numbers
+* The random number generators now use Catch-global instance of RNG (#1734, #1736)
+ * This means that nested random number generators actually generate different numbers
+
+
+### Miscellaneous
+* In-repo PNGs have been optimized to lower overhead of using Catch2 via git clone
+* Catch2 now uses its own implementation of the URBG concept
+ * In the future we also plan to use our own implementation of the distributions from `<random>` to provide cross-platform repeatability of random results
+
+
+
+## 2.9.2
### Fixes
### Fixes
-* Fixed deprecation warning in `ScopedMessage::~ScopedMessage`
-* All uses of `min` or `max` identifiers are now wrapped in parentheses
- * This avoids problems when Windows headers define `min` and `max` macros
+* `ChunkGenerator` can now be used with chunks of size 0 (#1671)
+* Nested subsections are now run properly when specific section is run via the `-c` argument (#1670, #1673)
+* Catch2 now consistently uses `_WIN32` to detect Windows platform (#1676)
+* `TEMPLATE_LIST_TEST_CASE` now support non-default constructible type lists (#1697)
+* Fixed a crash in the XMLReporter when a benchmark throws exception during warmup (#1706)
+* Fixed a possible infinite loop in CompactReporter (#1715)
+* Fixed `-w NoTests` returning 0 even when no tests were matched (#1449, #1683, #1684)
+* Fixed matcher compilation under Obj-C++ (#1661)
+
+### Improvements
+* `RepeatGenerator` and `FixedValuesGenerator` now fail to compile when used with `bool` (#1692)
+ * Previously they would fail at runtime.
+* Catch2 now supports Android's debug logging for its debug output (#1710)
+* Catch2 now detects and configures itself for the RTX platform (#1693)
+ * You still need to pass `--benchmark-no-analysis` if you are using benchmarking under RTX
+* Removed a "storage class is not first" warning when compiling Catch2 with PGI compiler (#1717)
+
+### Miscellaneous
+* Documentation now contains indication when a specific feature was introduced (#1695)
+ * These start with Catch2 v2.3.0, (a bit over a year ago).
+ * `docs/contributing.md` has been updated to provide contributors guidance on how to add these to newly written documentation
+* Various other documentation improvements
+ * ToC fixes
+ * Documented `--order` and `--rng-seed` command line options
+ * Benchmarking documentation now clearly states that it requires opt-in
+ * Documented `CATCH_CONFIG_CPP17_OPTIONAL` and `CATCH_CONFIG_CPP17_BYTE` macros
+ * Properly documented built-in vector matchers
+ * Improved `*_THROWS_MATCHES` documentation a bit
+* CMake config file is now arch-independent even if `CMAKE_SIZEOF_VOID_P` is in CMake cache (#1660)
+* `CatchAddTests` now properly escapes `[` and `]` in test names (#1634, #1698)
+* Reverted `CatchAddTests` adding tags as CTest labels (#1658)
+ * The script broke when test names were too long
+ * Overwriting `LABELS` caused trouble for users who set them manually
+ * CMake does not let users append to `LABELS` if the test name has spaces
+
+
+## 2.9.1
+
+### Fixes
+* Fix benchmarking compilation failure in files without `CATCH_CONFIG_EXTERNAL_INTERFACES` (or implementation)
+
+## 2.9.0
+
+### Improvements
+* The experimental benchmarking support has been replaced by integrating Nonius code (#1616)
+ * This provides a much more featurefull micro-benchmarking support.
+ * Due to the compilation cost, it is disabled by default. See the documentation for details.
+ * As far as backwards compatibility is concerned, this feature is still considered experimental in that we might change the interface based on user feedback.
+* `WithinULP` matcher now shows the acceptable range (#1581)
+* Template test cases now support type lists (#1627)
+
+
+## 2.8.0
+
+### Improvements
+* Templated test cases no longer check whether the provided types are unique (#1628)
+ * This allows you to e.g. test over `uint32_t`, `uint64_t`, and `size_t` without compilation failing
+* The precision of floating point stringification can be modified by user (#1612, #1614)
+* We now provide `REGISTER_ENUM` convenience macro for generating `StringMaker` specializations for enums
+ * See the "String conversion" documentation for details
+* Added new set of macros for template test cases that enables the use of NTTPs (#1531, #1609)
+ * See "Test cases and sections" documentation for details
+
+### Fixes
+* `UNSCOPED_INFO` macro now has a prefixed/disabled/prefixed+disabled versions (#1611)
+* Reporting errors at startup should no longer cause a segfault under certain circumstances (#1626)
+
+
+### Miscellaneous
+* CMake will now prevent you from attempting in-tree build (#1636, #1638)
+ * Previously it would break with an obscure error message during the build step
+
+
+## 2.7.2
+
+### Improvements
+* Added an approximate vector matcher (#1499)
+
+### Fixes
+* Filters will no longer be shown if there were none
+* Fixed compilation error when using Homebrew GCC on OS X (#1588, #1589)
+* Fixed the console reporter not showing messages that start with a newline (#1455, #1470)
+* Modified JUnit reporter's output so that rng seed and filters are reported according to the JUnit schema (#1598)
+* Fixed some obscure warnings and static analysis passes
+
+### Miscellaneous
+* Various improvements to `ParseAndAddCatchTests` (#1559, #1601)
+ * When a target is parsed, it receives `ParseAndAddCatchTests_TESTS` property which summarizes found tests
+ * Fixed problem with tests not being found if the `OptionalCatchTestLauncher` variables is used
+ * Including the script will no longer forcefully modify `CMAKE_MINIMUM_REQUIRED_VERSION`
+ * CMake object libraries are ignored when parsing to avoid needless warnings
+* `CatchAddTests` now adds test's tags to their CTest labels (#1600)
+* Added basic CPack support to our build
+
+## 2.7.1
+
+### Improvements
+* Reporters now print out the filters applied to test cases (#1550, #1585)
+* Added `GENERATE_COPY` and `GENERATE_REF` macros that can use variables inside the generator expression
+ * Because of the significant danger of lifetime issues, the default `GENERATE` macro still does not allow variables
+* The `map` generator helper now deduces the mapped return type (#1576)
+
+### Fixes
+* Fixed ObjC++ compilation (#1571)
+* Fixed test tag parsing so that `[.foo]` is now parsed as `[.][foo]`.
+* Suppressed warning caused by the Windows headers defining SE codes in different manners (#1575)
+
+## 2.7.0
+
+### Improvements
+* `TEMPLATE_PRODUCT_TEST_CASE` now uses the resulting type in the name, instead of the serial number (#1544)
+* Catch2's single header is now strictly ASCII (#1542)
+* Added generator for random integral/floating point types
+ * The types are inferred within the `random` helper
+* Added back RangeGenerator (#1526)
+ * RangeGenerator returns elements within a certain range
+* Added ChunkGenerator generic transform (#1538)
+ * A ChunkGenerator returns the elements from different generator in chunks of n elements
+* Added `UNSCOPED_INFO` (#415, #983, #1522)
+ * This is a variant of `INFO` that lives until next assertion/end of the test case.
+
+
+### Fixes
+* All calls to C stdlib functions are now `std::` qualified (#1541)
+ * Code brought in from Clara was also updated.
+* Running tests will no longer open the specified output file twice (#1545)
+ * This would cause trouble when the file was not a file, but rather a named pipe
+ * Fixes the CLion/Resharper integration with Catch
+* Fixed `-Wunreachable-code` occurring with (old) ccache+cmake+clang combination (#1540)
+* Fixed `-Wdefaulted-function-deleted` warning with Clang 8 (#1537)
+* Catch2's type traits and helpers are now properly namespaced inside `Catch::` (#1548)
+* Fixed std{out,err} redirection for failing test (#1514, #1525)
+ * Somehow, this bug has been present for well over a year before it was reported
+
+
+### Contrib
+* `ParseAndAddCatchTests` now properly escapes commas in the test name
+
+
+
+## 2.6.1
+
+### Improvements
+* The JUnit reporter now also reports random seed (#1520, #1521)
+
+### Fixes
+* The TAP reporter now formats comments with test name properly (#1529)
+* `CATCH_REQUIRE_THROWS`'s internals were unified with `REQUIRE_THROWS` (#1536)
+ * This fixes a potential `-Wunused-value` warning when used
+* Fixed a potential segfault when using any of the `--list-*` options (#1533, #1534)
+
+
+## 2.6.0
+
+**With this release the data generator feature is now fully supported.**
+ * or https://codingnest.com/files/horenmar-publickey.asc
+
+
+## 2.4.2
+
+### Improvements
+* XmlReporter now also outputs the RNG seed that was used in a run (#1404)
+* `Catch::Session::applyCommandLine` now also accepts `wchar_t` arguments.
+ * However, Catch2 still does not support unicode.
+* Added `STATIC_REQUIRE` macro (#1356, #1362)
+* Catch2's singleton's are now cleaned up even if tests are run (#1411)
+ * This is mostly useful as a FP prevention for users who define their own main.
+* Specifying an invalid reporter via `-r` is now reported sooner (#1351, #1422)
+
+
+### Fixes
+* Stringification no longer assumes that `char` is signed (#1399, #1407)
+ * This caused a `Wtautological-compare` warning.
+* SFINAE for `operator<<` no longer sees different overload set than the actual insertion (#1403)
+
+
+### Contrib
+* `catch_discover_tests` correctly adds tests with comma in name (#1327, #1409)
+* Added a new customization point in how the tests are launched to `catch_discover_tests`
+
+
+## 2.4.1
+
+### Improvements
+* Added a StringMaker for `std::(w)string_view` (#1375, #1376)
+* Added a StringMaker for `std::variant` (#1380)
+ * This one is disabled by default to avoid increased compile-time drag
+* Added detection for cygwin environment without `std::to_string` (#1396, #1397)
+
+### Fixes
+* `UnorderedEqualsMatcher` will no longer accept erroneously accept
+vectors that share suffix, but are not permutation of the desired vector
+* Abort after (`-x N`) can no longer be overshot by nested `REQUIRES` and
+subsequently ignored (#1391, #1392)
+
+
+## 2.4.0
+
+**This release brings two new experimental features, generator support
+and a `-fno-exceptions` support. Being experimental means that they
+will not be subject to the usual stability guarantees provided by semver.**
+
+### Improvements
+* Various small runtime performance improvements
+* `CAPTURE` macro is now variadic
+* Added `AND_GIVEN` macro (#1360)
+* Added experimental support for data generators
+ * See [their documentation](generators.md) for details
+* Added support for compiling and running Catch without exceptions
+ * Doing so limits the functionality somewhat
+ * Look [into the documentation](configuration.md#disablingexceptions) for details
+
+### Fixes
+* Suppressed `-Wnon-virtual-dtor` warnings in Matchers (#1357)
+* Suppressed `-Wunreachable-code` warnings in floating point matchers (#1350)
+
+### CMake
+* It is now possible to override which Python is used to run Catch's tests (#1365)
+* Catch now provides infrastructure for adding tests that check compile-time configuration
+* Catch no longer tries to install itself when used as a subproject (#1373)
+* Catch2ConfigVersion.cmake is now generated as arch-independent (#1368)
+ * This means that installing Catch from 32-bit machine and copying it to 64-bit one works
+ * This fixes conan installation of Catch
+
+
+## 2.3.0
+**This release changes the include paths provided by our CMake and
+pkg-config integration. The proper include path for the single-header
+when using one of the above is now `<catch2/catch.hpp>`. This change
+also necessitated changes to paths inside the repository, so that the
+single-header version is now at `single_include/catch2/catch.hpp`, rather
+than `single_include/catch.hpp`.**
-# 1.12.0
### Fixes
### Fixes
+* Fixed Objective-C++ build
+* `-Wunused-variable` suppression no longer leaks from Catch's header under Clang
+* Implementation of the experimental new output capture can now be disabled (#1335)
+ * This allows building Catch2 on platforms that do not provide things like `dup` or `tmpfile`.
+* The JUnit and XML reporters will no longer skip over successful tests when running without `-s` (#1264, #1267, #1310)
+ * See improvements for more details
+
+### Improvements
+* pkg-config and CMake integration has been rewritten
+ * If you use them, the new include path is `#include <catch2/catch.hpp>`
+ * CMake installation now also installs scripts from `contrib/`
+ * For details see the [new documentation](cmake-integration.md#top)
+* Reporters now have a new customization point, `ReporterPreferences::shouldReportAllAssertions`
+ * When this is set to `false` and the tests are run without `-s`, passing assertions are not sent to the reporter.
+ * Defaults to `false`.
+* Added `DYNAMIC_SECTION`, a section variant that constructs its name using stream
+ * This means that you can do `DYNAMIC_SECTION("For X := " << x)`.
+
+
+## 2.2.3
+
+**To fix some of the bugs, some behavior had to change in potentially breaking manner.**
+**This means that even though this is a patch release, it might not be a drop-in replacement.**
+
+### Fixes
+* Listeners are now called before reporter
+ * This was always documented to be the case, now it actually works that way
+* Catch's commandline will no longer accept multiple reporters
+ * This was done because multiple reporters never worked properly and broke things in non-obvious ways
+ * **This has potential to be a breaking change**
+* MinGW is now detected as Windows platform w/o SEH support (#1257)
+ * This means that Catch2 no longer tries to use POSIX signal handling when compiled with MinGW
+* Fixed potential UB in parsing tags using non-ASCII characters (#1266)
+ * Note that Catch2 still supports only ASCII test names/tags/etc
+* `TEST_CASE_METHOD` can now be used on classnames containing commas (#1245)
+ * You have to enclose the classname in extra set of parentheses
+* Fixed insufficient alt stack size for POSIX signal handling (#1225)
+* Fixed compilation error on Android due to missing `std::to_string` in C++11 mode (#1280)
+* Fixed the order of user-provided `FALLBACK_STRINGIFIER` in stringification machinery (#1024)
+ * It was intended to be replacement for built-in fallbacks, but it was used _after_ them.
+ * **This has potential to be a breaking change**
+* Fixed compilation error when a type has an `operator<<` with templated lhs (#1285, #1306)
+
+### Improvements
+* Added a new, experimental, output capture (#1243)
+ * This capture can also redirect output written via C apis, e.g. `printf`
+ * To opt-in, define `CATCH_CONFIG_EXPERIMENTAL_REDIRECT` in the implementation file
+* Added a new fallback stringifier for classes derived from `std::exception`
+ * Both `StringMaker` specialization and `operator<<` overload are given priority
+
+### Miscellaneous
+* `contrib/` now contains dbg scripts that skip over Catch's internals (#904, #1283)
+ * `gdbinit` for gdb `lldbinit` for lldb
+* `CatchAddTests.cmake` no longer strips whitespace from tests (#1265, #1281)
+* Online documentation now describes `--use-colour` option (#1263)
+
+
+## 2.2.2
+
+### Fixes
+* Fixed bug in `WithinAbs::match()` failing spuriously (#1228)
+* Fixed clang-tidy diagnostic about virtual call in destructor (#1226)
+* Reduced the number of GCC warnings suppression leaking out of the header (#1090, #1091)
+ * Only `-Wparentheses` should be leaking now
+* Added upper bound on the time benchmark timer calibration is allowed to take (#1237)
+ * On platforms where `std::chrono::high_resolution_clock`'s resolution is low, the calibration would appear stuck
+* Fixed compilation error when stringifying static arrays of `unsigned char`s (#1238)
+
+### Improvements
+* XML encoder now hex-encodes invalid UTF-8 sequences (#1207)
+ * This affects xml and junit reporters
+ * Some invalid UTF-8 parts are left as is, e.g. surrogate pairs. This is because certain extensions of UTF-8 allow them, such as WTF-8.
+* CLR objects (`T^`) can now be stringified (#1216)
+ * This affects code compiled as C++/CLI
+* Added `PredicateMatcher`, a matcher that takes an arbitrary predicate function (#1236)
+ * See [documentation for details](https://github.com/catchorg/Catch2/blob/master/docs/matchers.md)
+
+### Others
+* Modified CMake-installed pkg-config to allow `#include <catch.hpp>`(#1239)
+ * The plans to standardize on `#include <catch2/catch.hpp>` are still in effect
+
+
+## 2.2.1
+
+### Fixes
+* Fixed compilation error when compiling Catch2 with `std=c++17` against libc++ (#1214)
+ * Clara (Catch2's CLI parsing library) used `std::optional` without including it explicitly
+* Fixed Catch2 return code always being 0 (#1215)
+ * In the words of STL, "We feel superbad about letting this in"
+
+
+## 2.2.0
+
+### Fixes
+* Hidden tests are not listed by default when listing tests (#1175)
+ * This makes `catch_discover_tests` CMake script work better
+* Fixed regression that meant `<windows.h>` could potentially not be included properly (#1197)
+* Fixed installing `Catch2ConfigVersion.cmake` when Catch2 is a subproject.
+
+### Improvements
+* Added an option to warn (+ exit with error) when no tests were ran (#1158)
+ * Use as `-w NoTests`
+* Added provisional support for Emscripten (#1114)
+* [Added a way to override the fallback stringifier](https://github.com/catchorg/Catch2/blob/master/docs/configuration.md#fallback-stringifier) (#1024)
+ * This allows project's own stringification machinery to be easily reused for Catch
+* `Catch::Session::run()` now accepts `char const * const *`, allowing it to accept array of string literals (#1031, #1178)
+ * The embedded version of Clara was bumped to v1.1.3
+* Various minor performance improvements
+* Added support for DJGPP DOS crosscompiler (#1206)
+
+
+## 2.1.2
+
+### Fixes
+* Fixed compilation error with `-fno-rtti` (#1165)
+* Fixed NoAssertion warnings
+* `operator<<` is used before range-based stringification (#1172)
+* Fixed `-Wpedantic` warnings (extra semicolons and binary literals) (#1173)
+ * Set-equal matcher for vectors, `UnorderedEquals`
+ * Floating point matchers, `WithinAbs` and `WithinULP`.
+* Stringification now attempts to decompose all containers (#606)
+ * Containers are objects that respond to ADL `begin(T)` and `end(T)`.
+
+
+### Other changes
+* Reporters will now be versioned in the `single_include` folder to ensure their compatibility with the last released version
+
+
+
+
+## 2.0.1
+
+### Breaking changes
+* Removed C++98 support
+* Removed legacy reporter support
+* Removed legacy generator support
+ * Generator support will come back later, reworked
+* Removed `Catch::toString` support
+ * The new stringification machinery uses `Catch::StringMaker` specializations first and `operator<<` overloads second.
+* Removed legacy `SCOPED_MSG` and `SCOPED_INFO` macros
+* Removed `INTERNAL_CATCH_REGISTER_REPORTER`
+ * `CATCH_REGISTER_REPORTER` should be used to register reporters
+* Removed legacy `[hide]` tag
+ * `[.]`, `[.foo]` and `[!hide]` are still supported
+* Output into debugger is now colourized
+* `*_THROWS_AS(expr, exception_type)` now unconditionally appends `const&` to the exception type.
+* `CATCH_CONFIG_FAST_COMPILE` now affects the `CHECK_` family of assertions as well as `REQUIRE_` family of assertions
+ * This is most noticeable in `CHECK(throws())`, which would previously report failure, properly stringify the exception and continue. Now it will report failure and stop executing current section.
+* Removed deprecated matcher utility functions `Not`, `AllOf` and `AnyOf`.
+ * They are superseded by operators `!`, `&&` and `||`, which are natural and do not have limited arity
+* Removed support for non-const comparison operators
+ * Non-const comparison operators are an abomination that should not exist
+ * They were breaking support for comparing function to function pointer
+* `std::pair` and `std::tuple` are no longer stringified by default
+ * This is done to avoid dragging in `<tuple>` and `<utility>` headers in common path
+ * Their stringification can be enabled per-file via new configuration macros
+* `Approx` is subtly different and hopefully behaves more as users would expect
+ * `Approx::scale` defaults to `0.0`
+ * `Approx::epsilon` no longer applies to the larger of the two compared values, but only to the `Approx`'s value
+ * `INFINITY == Approx(INFINITY)` returns true
+
+
+### Improvements
+* Reporters and Listeners can be defined in files different from the main file
+ * The file has to define `CATCH_CONFIG_EXTERNAL_INTERFACES` before including catch.hpp.
+* Errors that happen during set up before main are now caught and properly reported once main is entered
+ * If you are providing your own main, you can access and use these as well.
+* New assertion macros, *_THROWS_MATCHES(expr, exception_type, matcher) are provided
+ * As the arguments suggest, these allow you to assert that an expression throws desired type of exception and pass the exception to a matcher.
+* JUnit reporter no longer has significantly different output for test cases with and without sections
+* Most assertions now support expressions containing commas (ie `REQUIRE(foo() == std::vector<int>{1, 2, 3});`)
+* Catch now contains experimental micro benchmarking support
+ * See `projects/SelfTest/Benchmark.tests.cpp` for examples
+ * The support being experiment means that it can be changed without prior notice
+* Catch uses new CLI parsing library (Clara)
+ * Users can now easily add new command line options to the final executable
+ * This also leads to some changes in `Catch::Session` interface
+* All parts of matchers can be removed from a TU by defining `CATCH_CONFIG_DISABLE_MATCHERS`
+ * This can be used to somewhat speed up compilation times
+* An experimental implementation of `CATCH_CONFIG_DISABLE` has been added
+ * Inspired by Doctest's `DOCTEST_CONFIG_DISABLE`
+ * Useful for implementing tests in source files
+ * ie for functions in anonymous namespaces
+ * Removes all assertions
+ * Prevents `TEST_CASE` registrations
+ * Exception translators are not registered
+ * Reporters are not registered
+ * Listeners are not registered
+* Reporters/Listeners are now notified of fatal errors
+ * This means specific signals or structured exceptions
+ * The Reporter/Listener interface provides default, empty, implementation to preserve backward compatibility
+* Stringification of `std::chrono::duration` and `std::chrono::time_point` is now supported
+ * Needs to be enabled by a per-file compile time configuration option
+* Add `pkg-config` support to CMake install command
+
+
+### Fixes
+* Don't use console colour if running in XCode
+* Explicit constructor in reporter base class
+* Swept out `-Wweak-vtables`, `-Wexit-time-destructors`, `-Wglobal-constructors` warnings
+* Compilation for Universal Windows Platform (UWP) is supported
+ * SEH handling and colorized output are disabled when compiling for UWP
+* Implemented a workaround for `std::uncaught_exception` issues in libcxxrt
+ * These issues caused incorrect section traversals
+ * The workaround is only partial, user's test can still trigger the issue by using `throw;` to rethrow an exception
+* Suppressed C4061 warning under MSVC
+
+
+### Internal changes
+* The development version now uses .cpp files instead of header files containing implementation.
+ * This makes partial rebuilds much faster during development
+* The expression decomposition layer has been rewritten
+* The evaluation layer has been rewritten
+* New library (TextFlow) is used for formatting text to output
+
+
+## Older versions
+
+### 1.12.x
+
+#### 1.12.2
+##### Fixes
+* Fixed missing <cassert> include
+
+#### 1.12.1
+
+##### Fixes
+* Fixed deprecation warning in `ScopedMessage::~ScopedMessage`
+* All uses of `min` or `max` identifiers are now wrapped in parentheses
+ * This avoids problems when Windows headers define `min` and `max` macros
+
+#### 1.12.0
+
+##### Fixes
* Fixed compilation for strict C++98 mode (ie not gnu++98) and older compilers (#1103)
* Fixed compilation for strict C++98 mode (ie not gnu++98) and older compilers (#1103)
* `INFO` messages are included in the `xml` reporter output even without `-s` specified.
* `INFO` messages are included in the `xml` reporter output even without `-s` specified.
+### 1.11.x
-# 1.11.0
+#### 1.11.0
-### Fixes
+##### Fixes
* The original expression in `REQUIRE_FALSE( expr )` is now reporter properly as `!( expr )` (#1051)
* The original expression in `REQUIRE_FALSE( expr )` is now reporter properly as `!( expr )` (#1051)
* Previously the parentheses were missing and `x != y` would be expanded as `!x != x`
* Previously the parentheses were missing and `x != y` would be expanded as `!x != x`
* `Approx::Margin` is now inclusive (#952)
* `Approx::Margin` is now inclusive (#952)
@@ -29,7 +684,7 @@
* This means that `REQUIRE( 0.25f == Approx( 0.0f ).margin( 0.25f ) )` passes, instead of fails
* This means that `REQUIRE( 0.25f == Approx( 0.0f ).margin( 0.25f ) )` passes, instead of fails
* `RandomNumberGenerator::result_type` is now unsigned (#1050)
* `RandomNumberGenerator::result_type` is now unsigned (#1050)
-### Improvements
+##### Improvements
* `__JETBRAINS_IDE__` macro handling is now CLion version specific (#1017)
* `__JETBRAINS_IDE__` macro handling is now CLion version specific (#1017)
* When CLion 2017.3 or newer is detected, `__COUNTER__` is used instead of
* When CLion 2017.3 or newer is detected, `__COUNTER__` is used instead of
* TeamCity reporter now explicitly flushes output stream after each report (#1057)
* TeamCity reporter now explicitly flushes output stream after each report (#1057)
@@ -37,55 +692,35 @@
* `ParseAndAddCatchTests` now can add test files as dependency to CMake configuration
* `ParseAndAddCatchTests` now can add test files as dependency to CMake configuration
* This means you do not have to manually rerun CMake configuration step to detect new tests
* This means you do not have to manually rerun CMake configuration step to detect new tests
+### 1.10.x
-# 1.10.0
+#### 1.10.0
-### Fixes
+##### Fixes
* Evaluation layer has been rewritten (backported from Catch 2)
* Evaluation layer has been rewritten (backported from Catch 2)
* The new layer is much simpler and fixes some issues (#981)
* The new layer is much simpler and fixes some issues (#981)
* Implemented workaround for VS 2017 raw string literal stringification bug (#995)
* Implemented workaround for VS 2017 raw string literal stringification bug (#995)
* Fixed interaction between `[!shouldfail]` and `[!mayfail]` tags and sections
* Fixed interaction between `[!shouldfail]` and `[!mayfail]` tags and sections
* Previously sections with failing assertions would be marked as failed, not failed-but-ok
* Previously sections with failing assertions would be marked as failed, not failed-but-ok
-### Improvements
+##### Improvements
* Added [libidentify](https://github.com/janwilmans/LibIdentify) support
* Added [libidentify](https://github.com/janwilmans/LibIdentify) support
* Added "wait-for-keypress" option
* Added "wait-for-keypress" option
+### 1.9.x
-# 1.9.7
-
-### Fixes
-* Various warnings from clang-tidy, Resharper-C++ and PVS Studio have been addressed (#957)
-* Dynamically generated sections are now properly reported (#963)
-* Writes to `std::clog` are redirected for reporters (#989)
- * Previously only `std::cerr` writes were redirected
- * Interleaved writes to `std::cerr` and `std::clog` are combined properly
-* Assertions failed before signals/structured exceptions fails test case are properly reported as failed (#990)
-
-### Improvements
-* Catch's runtime overhead has been decreased further (#940)
-* Added support for IBM i ILE c++ compiler (#976)
- * This means that AS/400 is now supported.
-* The default reporter can be configured at compile time (#978)
- * That is, the reporter used if no reporter is explicitly specified
-
-### Other
-* `ParseAndAddCatchTests` cmake script has couple new customization options
-
+#### 1.9.6
-
-# 1.9.6
-
-### Improvements
+##### Improvements
* Catch's runtime overhead has been significantly decreased (#937, #939)
* Catch's runtime overhead has been significantly decreased (#937, #939)
* Added `--list-extra-info` cli option (#934).
* Added `--list-extra-info` cli option (#934).
* It lists all tests together with extra information, ie filename, line number and description.
* It lists all tests together with extra information, ie filename, line number and description.
-# 1.9.5
+#### 1.9.5
-### Fixes
+##### Fixes
* Truthy expressions are now reconstructed properly, not as booleans (#914)
* Truthy expressions are now reconstructed properly, not as booleans (#914)
* Various warnings are no longer erroneously suppressed in test files (files that include `catch.hpp`, but do not define `CATCH_CONFIG_MAIN` or `CATCH_CONFIG_RUNNER`) (#871)
* Various warnings are no longer erroneously suppressed in test files (files that include `catch.hpp`, but do not define `CATCH_CONFIG_MAIN` or `CATCH_CONFIG_RUNNER`) (#871)
* Catch no longer fails to link when main is compiled as C++, but linked against Objective-C (#855)
* Catch no longer fails to link when main is compiled as C++, but linked against Objective-C (#855)
@@ -93,35 +728,35 @@
* Previously any GCC with minor version less than 3 would be incorrectly classified as not supporting `__COUNTER__`.
* Previously any GCC with minor version less than 3 would be incorrectly classified as not supporting `__COUNTER__`.
* Suppressed C4996 warning caused by upcoming updated to MSVC 2017, marking `std::uncaught_exception` as deprecated. (#927)
* Suppressed C4996 warning caused by upcoming updated to MSVC 2017, marking `std::uncaught_exception` as deprecated. (#927)
-### Improvements
+##### Improvements
* CMake integration script now incorporates debug messages and registers tests in an improved way (#911)
* CMake integration script now incorporates debug messages and registers tests in an improved way (#911)
* Various documentation improvements
* Various documentation improvements
-# 1.9.4
+#### 1.9.4
-### Fixes
+##### Fixes
* `CATCH_FAIL` macro no longer causes compilation error without variadic macro support
* `CATCH_FAIL` macro no longer causes compilation error without variadic macro support
* `INFO` messages are no longer cleared after being reported once
* `INFO` messages are no longer cleared after being reported once
-### Improvements and minor changes
+##### Improvements and minor changes
* Catch now uses `wmain` when compiled under Windows and `UNICODE` is defined.
* Catch now uses `wmain` when compiled under Windows and `UNICODE` is defined.
* Note that Catch still officially supports only ASCII
* Note that Catch still officially supports only ASCII
-# 1.9.3
+#### 1.9.3
-### Fixes
+##### Fixes
* Completed the fix for (lack of) uint64_t in earlier Visual Studios
* Completed the fix for (lack of) uint64_t in earlier Visual Studios
-# 1.9.2
+#### 1.9.2
-### Improvements and minor changes
+##### Improvements and minor changes
* All of `Approx`'s member functions now accept strong typedefs in C++11 mode (#888)
* All of `Approx`'s member functions now accept strong typedefs in C++11 mode (#888)
* Previously `Approx::scale`, `Approx::epsilon`, `Approx::margin` and `Approx::operator()` didn't.
* Previously `Approx::scale`, `Approx::epsilon`, `Approx::margin` and `Approx::operator()` didn't.
-### Fixes
+##### Fixes
* POSIX signals are now disabled by default under QNX (#889)
* POSIX signals are now disabled by default under QNX (#889)
* QNX does not support current enough (2001) POSIX specification
* QNX does not support current enough (2001) POSIX specification
* JUnit no longer counts exceptions as failures if given test case is marked as ok to fail.
* JUnit no longer counts exceptions as failures if given test case is marked as ok to fail.
@@ -129,22 +764,22 @@
* Catch no longer attempts to define `uint64_t` on windows (#862)
* Catch no longer attempts to define `uint64_t` on windows (#862)
* This was causing trouble when compiled under Cygwin
* This was causing trouble when compiled under Cygwin
-### Other
+##### Other
* Catch is now compiled under MSVC 2017 using `std:c++latest` (C++17 mode) in CI
* Catch is now compiled under MSVC 2017 using `std:c++latest` (C++17 mode) in CI
* We now provide cmake script that autoregisters Catch tests into ctest.
* We now provide cmake script that autoregisters Catch tests into ctest.
* See `contrib` folder.
* See `contrib` folder.
-# 1.9.1
+#### 1.9.1
-### Fixes
+##### Fixes
* Unexpected exceptions are no longer ignored by default (#885, #887)
* Unexpected exceptions are no longer ignored by default (#885, #887)
-# 1.9.0
+#### 1.9.0
-### Improvements and minor changes
+##### Improvements and minor changes
* Catch no longer attempts to ensure the exception type passed by user in `REQUIRE_THROWS_AS` is a constant reference.
* Catch no longer attempts to ensure the exception type passed by user in `REQUIRE_THROWS_AS` is a constant reference.
* It was causing trouble when `REQUIRE_THROWS_AS` was used inside templated functions
* It was causing trouble when `REQUIRE_THROWS_AS` was used inside templated functions
* This actually reverts changes made in v1.7.2
* This actually reverts changes made in v1.7.2
@@ -158,7 +793,7 @@
* When Catch is compiled using C++11, `Approx` is now constructible with anything that can be explicitly converted to `double`.
* When Catch is compiled using C++11, `Approx` is now constructible with anything that can be explicitly converted to `double`.
* Captured messages are now printed on unexpected exceptions
* Captured messages are now printed on unexpected exceptions
-### Fixes:
+##### Fixes:
* Clang's `-Wexit-time-destructors` should be suppressed for Catch's internals
* Clang's `-Wexit-time-destructors` should be suppressed for Catch's internals
* GCC's `-Wparentheses` is now suppressed for all TU's that include `catch.hpp`.
* GCC's `-Wparentheses` is now suppressed for all TU's that include `catch.hpp`.
* This is functionally a revert of changes made in 1.8.0, where we tried using `_Pragma` based suppression. This should have kept the suppression local to Catch's assertions, but bugs in GCC's handling of `_Pragma`s in C++ mode meant that it did not always work.
* This is functionally a revert of changes made in 1.8.0, where we tried using `_Pragma` based suppression. This should have kept the suppression local to Catch's assertions, but bugs in GCC's handling of `_Pragma`s in C++ mode meant that it did not always work.
@@ -167,16 +802,18 @@
* [Details can be found in documentation](configuration.md#catch_config_cpp11_stream_insertable_check)
* [Details can be found in documentation](configuration.md#catch_config_cpp11_stream_insertable_check)
-### Other notes:
+##### Other notes:
* We have added VS 2017 to our CI
* We have added VS 2017 to our CI
* Work on Catch 2 should start soon
* Work on Catch 2 should start soon
-# 1.8.2
+### 1.8.x
+#### 1.8.2
-### Improvements and minor changes
+
+##### Improvements and minor changes
* TAP reporter now behaves as if `-s` was always set
* TAP reporter now behaves as if `-s` was always set
* This should be more consistent with the protocol desired behaviour.
* This should be more consistent with the protocol desired behaviour.
* Compact reporter now obeys `-d yes` argument (#780)
* Compact reporter now obeys `-d yes` argument (#780)
@@ -186,11 +823,11 @@
* This means it reports `INFO` messages on success, if output on success (`-s`) is enabled.
* This means it reports `INFO` messages on success, if output on success (`-s`) is enabled.
* Previously it only reported `INFO` messages on failure.
* Previously it only reported `INFO` messages on failure.
* `CAPTURE(expr)` now stringifies `expr` in the same way assertion macros do (#639)
* `CAPTURE(expr)` now stringifies `expr` in the same way assertion macros do (#639)
-* Listeners are now finally [documented](event-listeners.md).
+* Listeners are now finally [documented](event-listeners.md#top).
* Listeners provide a way to hook into events generated by running your tests, including start and end of run, every test case, every section and every assertion.
* Listeners provide a way to hook into events generated by running your tests, including start and end of run, every test case, every section and every assertion.
-### Fixes:
+##### Fixes:
* Catch no longer attempts to reconstruct expression that led to a fatal error (#810)
* Catch no longer attempts to reconstruct expression that led to a fatal error (#810)
* This fixes possible signal/SEH loop when processing expressions, where the signal was triggered by expression decomposition.
* This fixes possible signal/SEH loop when processing expressions, where the signal was triggered by expression decomposition.
* Fixed (C4265) missing virtual destructor warning in Matchers (#844)
* Fixed (C4265) missing virtual destructor warning in Matchers (#844)
@@ -207,25 +844,25 @@
* Regression in Objective-C bindings (Matchers) fixed (#854)
* Regression in Objective-C bindings (Matchers) fixed (#854)
-### Other notes:
+##### Other notes:
* We have added VS 2013 and 2015 to our CI
* We have added VS 2013 and 2015 to our CI
* Catch Classic (1.x.x) now contains its own, forked, version of Clara (the argument parser).
* Catch Classic (1.x.x) now contains its own, forked, version of Clara (the argument parser).
-# 1.8.1
+#### 1.8.1
-### Fixes
+##### Fixes
Cygwin issue with `gettimeofday` - `#define` was not early enough
Cygwin issue with `gettimeofday` - `#define` was not early enough
-# 1.8.0
+#### 1.8.0
-### New features/ minor changes
+##### New features/ minor changes
* Matchers have new, simpler (and documented) interface.
* Matchers have new, simpler (and documented) interface.
* Catch provides string and vector matchers.
* Catch provides string and vector matchers.
- * For details see [Matchers documentation](matchers.md).
+ * For details see [Matchers documentation](matchers.md#top).
* Changed console reporter test duration reporting format (#322)
* Changed console reporter test duration reporting format (#322)
* Old format: `Some simple comparisons between doubles completed in 0.000123s`
* Old format: `Some simple comparisons between doubles completed in 0.000123s`
* New format: `xxx.123s: Some simple comparisons between doubles` _(There will always be exactly 3 decimal places)_
* New format: `xxx.123s: Some simple comparisons between doubles` _(There will always be exactly 3 decimal places)_
@@ -236,36 +873,38 @@ Cygwin issue with `gettimeofday` - `#define` was not early enough
* _More changes are coming_
* _More changes are coming_
* Added [TAP (Test Anything Protocol)](https://testanything.org/) and [Automake](https://www.gnu.org/software/automake/manual/html_node/Log-files-generation-and-test-results-recording.html#Log-files-generation-and-test-results-recording) reporters.
* Added [TAP (Test Anything Protocol)](https://testanything.org/) and [Automake](https://www.gnu.org/software/automake/manual/html_node/Log-files-generation-and-test-results-recording.html#Log-files-generation-and-test-results-recording) reporters.
* These are not present in the default single-include header and need to be downloaded from GitHub separately.
* These are not present in the default single-include header and need to be downloaded from GitHub separately.
- * For details see [documentation about integrating with build systems](build-systems.md).
+ * For details see [documentation about integrating with build systems](build-systems.md#top).
* XML reporter now reports filename as part of the `Section` and `TestCase` tags.
* XML reporter now reports filename as part of the `Section` and `TestCase` tags.
* `Approx` now supports an optional margin of absolute error
* `Approx` now supports an optional margin of absolute error
- * It has also received [new documentation](assertions.md).
+ * It has also received [new documentation](assertions.md#top).
-### Fixes
+##### Fixes
* Silenced C4312 ("conversion from int to 'ClassName *") warnings in the evaluate layer.
* Silenced C4312 ("conversion from int to 'ClassName *") warnings in the evaluate layer.
* Fixed C4512 ("assignment operator could not be generated") warnings under VS2013.
* Fixed C4512 ("assignment operator could not be generated") warnings under VS2013.
* Cygwin compatibility fixes
* Cygwin compatibility fixes
* Signal handling is no longer compiled by default.
* Signal handling is no longer compiled by default.
* Usage of `gettimeofday` inside Catch should no longer cause compilation errors.
* Usage of `gettimeofday` inside Catch should no longer cause compilation errors.
-* Improved `-Wparentheses` supression for gcc (#674)
- * When compiled with gcc 4.8 or newer, the supression is localized to assertions only
- * Otherwise it is supressed for the whole TU
+* Improved `-Wparentheses` suppression for gcc (#674)
+ * When compiled with gcc 4.8 or newer, the suppression is localized to assertions only
+ * Otherwise it is suppressed for the whole TU
* Fixed test spec parser issue (with escapes in multiple names)
* Fixed test spec parser issue (with escapes in multiple names)
-### Other
+##### Other
* Various documentation fixes and improvements
* Various documentation fixes and improvements
-# 1.7.2
+### 1.7.x
-### Fixes and minor improvements
+#### 1.7.2
+
+##### Fixes and minor improvements
Xml:
Xml:
(technically the first two are breaking changes but are also fixes and arguably break few if any people)
(technically the first two are breaking changes but are also fixes and arguably break few if any people)
* C-escape control characters instead of XML encoding them (which requires XML 1.1)
* C-escape control characters instead of XML encoding them (which requires XML 1.1)
* Revert XML output to XML 1.0
* Revert XML output to XML 1.0
* Can provide stylesheet references by extending the XML reporter
* Can provide stylesheet references by extending the XML reporter
-* Added description and tags attribites to XML Reporter
+* Added description and tags attributes to XML Reporter
* Tags are closed and the stream flushed more eagerly to avoid stdout interpolation
* Tags are closed and the stream flushed more eagerly to avoid stdout interpolation
@@ -277,26 +916,26 @@ Other:
* Silenced a few more warnings in different circumstances
* Silenced a few more warnings in different circumstances
* Travis improvements
* Travis improvements
-# 1.7.1
+#### 1.7.1
-### Fixes:
+##### Fixes:
* Fixed inconsistency in defining `NOMINMAX` and `WIN32_LEAN_AND_MEAN` inside `catch.hpp`.
* Fixed inconsistency in defining `NOMINMAX` and `WIN32_LEAN_AND_MEAN` inside `catch.hpp`.
* Fixed SEH-related compilation error under older MinGW compilers, by making Windows SEH handling opt-in for compilers other than MSVC.
* Fixed SEH-related compilation error under older MinGW compilers, by making Windows SEH handling opt-in for compilers other than MSVC.
- * For specifics, look into the [documentation](configuration.md).
+ * For specifics, look into the [documentation](configuration.md#top).
* Fixed compilation error under MinGW caused by improper compiler detection.
* Fixed compilation error under MinGW caused by improper compiler detection.
* Fixed XML reporter sometimes leaving an empty output file when a test ends with signal/structured exception.
* Fixed XML reporter sometimes leaving an empty output file when a test ends with signal/structured exception.
* Fixed XML reporter not reporting captured stdout/stderr.
* Fixed XML reporter not reporting captured stdout/stderr.
* Fixed possible infinite recursion in Windows SEH.
* Fixed possible infinite recursion in Windows SEH.
* Fixed possible compilation error caused by Catch's operator overloads being ambiguous in regards to user-defined templated operators.
* Fixed possible compilation error caused by Catch's operator overloads being ambiguous in regards to user-defined templated operators.
-## 1.7.0
+#### 1.7.0
-### Features/ Changes:
+##### Features/ Changes:
* Catch now runs significantly faster for passing tests
* Catch now runs significantly faster for passing tests
* Microbenchmark focused on Catch's overhead went from ~3.4s to ~0.7s.
* Microbenchmark focused on Catch's overhead went from ~3.4s to ~0.7s.
* Real world test using [JSON for Modern C++](https://github.com/nlohmann/json)'s test suite went from ~6m 25s to ~4m 14s.
* Real world test using [JSON for Modern C++](https://github.com/nlohmann/json)'s test suite went from ~6m 25s to ~4m 14s.
* Catch can now run specific sections within test cases.
* Catch can now run specific sections within test cases.
- * For now the support is only basic (no wildcards or tags), for details see the [documentation](command-line.md).
+ * For now the support is only basic (no wildcards or tags), for details see the [documentation](command-line.md#top).
* Catch now supports SEH on Windows as well as signals on Linux.
* Catch now supports SEH on Windows as well as signals on Linux.
* After receiving a signal, Catch reports failing assertion and then passes the signal onto the previous handler.
* After receiving a signal, Catch reports failing assertion and then passes the signal onto the previous handler.
* Approx can be used to compare values against strong typedefs (available in C++11 mode only).
* Approx can be used to compare values against strong typedefs (available in C++11 mode only).
@@ -305,61 +944,63 @@ Other:
* Certain characters (space, tab, etc) are now pretty printed.
* Certain characters (space, tab, etc) are now pretty printed.
* This means that a `char c = ' '; REQUIRE(c == '\t');` would be printed as `' ' == '\t'`, instead of ` == 9`.
* This means that a `char c = ' '; REQUIRE(c == '\t');` would be printed as `' ' == '\t'`, instead of ` == 9`.
-### Fixes:
+##### Fixes:
* Text formatting no longer attempts to access out-of-bounds characters under certain conditions.
* Text formatting no longer attempts to access out-of-bounds characters under certain conditions.
* THROW family of assertions no longer trigger `-Wunused-value` on expressions containing explicit cast.
* THROW family of assertions no longer trigger `-Wunused-value` on expressions containing explicit cast.
* Breaking into debugger under OS X works again and no longer required `DEBUG` to be defined.
* Breaking into debugger under OS X works again and no longer required `DEBUG` to be defined.
* Compilation no longer breaks under certain compiler if a lambda is used inside assertion macro.
* Compilation no longer breaks under certain compiler if a lambda is used inside assertion macro.
-### Other:
+##### Other:
* Catch's CMakeLists now defines install command.
* Catch's CMakeLists now defines install command.
* Catch's CMakeLists now generates projects with warnings enabled.
* Catch's CMakeLists now generates projects with warnings enabled.
-## 1.6.1
+### 1.6.x
+
+#### 1.6.1
-### Features/ Changes:
+##### Features/ Changes:
* Catch now supports breaking into debugger on Linux
* Catch now supports breaking into debugger on Linux
-### Fixes:
+##### Fixes:
* Generators no longer leak memory (generators are still unsupported in general)
* Generators no longer leak memory (generators are still unsupported in general)
* JUnit reporter now reports UTC timestamps, instead of "tbd"
* JUnit reporter now reports UTC timestamps, instead of "tbd"
* `CHECK_THAT` macro is now properly defined as `CATCH_CHECK_THAT` when using `CATCH_` prefixed macros
* `CHECK_THAT` macro is now properly defined as `CATCH_CHECK_THAT` when using `CATCH_` prefixed macros
-### Other:
+##### Other:
* Types with overloaded `&&` operator are no longer evaluated twice when used in an assertion macro.
* Types with overloaded `&&` operator are no longer evaluated twice when used in an assertion macro.
-* The use of `__COUNTER__` is supressed when Catch is parsed by CLion
+* The use of `__COUNTER__` is suppressed when Catch is parsed by CLion
* This change is not active when compiling a binary
* This change is not active when compiling a binary
* Approval tests can now be run on Windows
* Approval tests can now be run on Windows
* CMake will now warn if a file is present in the `include` folder but not is not enumerated as part of the project
* CMake will now warn if a file is present in the `include` folder but not is not enumerated as part of the project
* Catch now defines `NOMINMAX` and `WIN32_LEAN_AND_MEAN` before including `windows.h`
* Catch now defines `NOMINMAX` and `WIN32_LEAN_AND_MEAN` before including `windows.h`
- * This can be disabled if needed, see [documentation](configuration.md) for details.
+ * This can be disabled if needed, see [documentation](configuration.md#top) for details.
-## 1.6.0
+#### 1.6.0
-### Cmake/ projects:
+##### Cmake/ projects:
* Moved CMakeLists.txt to root, made it friendlier for CLion and generating XCode and VS projects, and removed the manually maintained XCode and VS projects.
* Moved CMakeLists.txt to root, made it friendlier for CLion and generating XCode and VS projects, and removed the manually maintained XCode and VS projects.
-### Features/ Changes:
+##### Features/ Changes:
* Approx now supports `>=` and `<=`
* Approx now supports `>=` and `<=`
* Can now use `\` to escape chars in test names on command line
* Can now use `\` to escape chars in test names on command line
* Standardize C++11 feature toggles
* Standardize C++11 feature toggles
-### Fixes:
+##### Fixes:
* Blue shell colour
* Blue shell colour
* Missing argument to `CATCH_CHECK_THROWS`
* Missing argument to `CATCH_CHECK_THROWS`
* Don't encode extended ASCII in XML
* Don't encode extended ASCII in XML
* use `std::shuffle` on more compilers (fixes deprecation warning/error)
* use `std::shuffle` on more compilers (fixes deprecation warning/error)
* Use `__COUNTER__` more consistently (where available)
* Use `__COUNTER__` more consistently (where available)
-### Other:
+##### Other:
* Tweaks and changes to scripts - particularly for Approval test - to make them more portable
* Tweaks and changes to scripts - particularly for Approval test - to make them more portable
-# Older versions
+## Even Older versions
Release notes were not maintained prior to v1.6.0, but you should be able to work them out from the Git history
Release notes were not maintained prior to v1.6.0, but you should be able to work them out from the Git history
-When enough changes have accumulated, it is time to release new version of Catch. This document describes the proces in doing so, that no steps are forgotten. Note that all referenced scripts can be found in the `scripts/` directory.
+When enough changes have accumulated, it is time to release new version of Catch. This document describes the process in doing so, that no steps are forgotten. Note that all referenced scripts can be found in the `scripts/` directory.
-## Neccessary steps
+## Necessary steps
-These steps are neccessary and have to be performed before each new release. They serve to make sure that the new release is correct and linked-to from the standard places.
+These steps are necessary and have to be performed before each new release. They serve to make sure that the new release is correct and linked-to from the standard places.
-### Approval testing
+### Testing
-Catch's releases are primarily validated against output from previous release, stored in `projects/SelfTest/Baselines`. To validate current sources, build the SelfTest binary and pass it to the `approvalTests.py` script: `approvalTests.py <path/to/SelfTest>`.
-
-There should be no differences, as Approval tests should be updated when changes to Catch are made, but if there are, then they need to be manually reviewed and either approved (using `approve.py`) or Catch requires other fixes.
+All of the tests are currently run in our CI setup based on TravisCI and
+AppVeyor. As long as the last commit tested green, the release can
+proceed.
### Incrementing version number
### Incrementing version number
-Catch uses a variant of [semantic versioning](http://semver.org/), with breaking API changes (and thus major version increments) being very rare. Thus, the release will usually increment the patch version, when it only contains couple of bugfixes, or minor version, when it contains new functionality, or larger changes in implementation of current functionality.
+Catch uses a variant of [semantic versioning](http://semver.org/), with breaking API changes (and thus major version increments) being very rare. Thus, the release will usually increment the patch version, when it only contains couple of bugfixes, or minor version, when it contains new functionality, or larger changes in implementation of current functionality.
After deciding which part of version number should be incremented, you can use one of the `*Release.py` scripts to perform the required changes to Catch.
After deciding which part of version number should be incremented, you can use one of the `*Release.py` scripts to perform the required changes to Catch.
-
-### Generate updated single-include header
-
-After updating version number, regenerate single-include header using `generateSingleHeader.py`.
+This will take care of generating the single include header, updating
+version numbers everywhere and pushing the new version to Wandbox.
### Release notes
### Release notes
-Once a release is ready, release notes need to be written. They should summarize changes done since last release. For rough idea of expected notes see previous releases. Once written, release notes should be placed in `docs/release-notes.md`.
+Once a release is ready, release notes need to be written. They should summarize changes done since last release. For rough idea of expected notes see previous releases. Once written, release notes should be added to `docs/release-notes.md`.
### Commit and push update to GitHub
### Commit and push update to GitHub
-After version number is incremented, single-include header is regenerated and release notes are updated, changes should be commited and pushed to GitHub.
+After version number is incremented, single-include header is regenerated and release notes are updated, changes should be committed and pushed to GitHub.
### Release on GitHub
### Release on GitHub
-After pushing changes to GitHub, GitHub release *needs* to be created. Tag version and release title should be same as the new version, description should contain the release notes for the current release. Single header version of `catch.hpp` *needs* to be attached as a binary, as that is where the official download link links to. Preferably it should use linux line endings.
+After pushing changes to GitHub, GitHub release *needs* to be created.
+Tag version and release title should be same as the new version,
+description should contain the release notes for the current release.
+Single header version of `catch.hpp` *needs* to be attached as a binary,
+as that is where the official download link links to. Preferably
+it should use linux line endings. All non-bundled reporters (Automake,
+TAP, TeamCity) should also be attached as binaries, as they might be
+dependent on a specific version of the single-include header.
+
+Since 2.5.0, the release tag and the "binaries" (headers) should be PGP
+signed.
-## Optional steps
+#### Signing a tag
-The following steps are optional, and do not have to be performed when releasing new version of Catch. However, they are *should* happen, but they can happen the next day without losing anything significant.
+To create a signed tag, use `git tag -s <VERSION>`, where `<VERSION>`
+is the version being released, e.g. `git tag -s v2.6.0`.
+Use the version name as the short message and the release notes as
+the body (long) message.
-### vcpkg update
+#### Signing the headers
-Catch is maintaining its own port in Microsoft's package manager [vcpkg](https://github.com/Microsoft/vcpkg). This means that when new version of Catch is released, it should be posted there as well. `updateVcpkgPackage.py` can do a lot of neccessary work for you, it creates a branch and commits neccessary changes. You should review these changes, push and open a PR against vcpkg's upstream.
+This will create ASCII-armored signatures for the headers that are
+uploaded to the GitHub release:
-Note that the script assumes you have your fork of vcpkg checked out in a directory next to the directory where you have checked out Catch, like so:
-Recently we also included a link to wandbox with preloaded Catch on the main page. Strictly speaking it is unneccessary to update this after every release, Catch usually does not change that much between versions, but it should be kept up to date anyway.
-
+_GPG does not support signing multiple files in single invocation._
Catch has a modular reporting system and comes bundled with a handful of useful reporters built in.
Catch has a modular reporting system and comes bundled with a handful of useful reporters built in.
@@ -17,15 +18,15 @@ There are four reporters built in to the single include:
* `console` writes as lines of text, formatted to a typical terminal width, with colours if a capable terminal is detected.
* `console` writes as lines of text, formatted to a typical terminal width, with colours if a capable terminal is detected.
* `compact` similar to `console` but optimised for minimal output - each entry on one line
* `compact` similar to `console` but optimised for minimal output - each entry on one line
-* `junit` writes xml that corresponds to Ant's [junitreport](http://help.catchsoftware.com/display/ET/JUnit+Format) target. Useful for build systems that understand Junit. If you are using Jenkins with Catch 1.x, you can improve quality of output by applying changes in [#923](https://github.com/philsquared/Catch/pull/923).
+* `junit` writes xml that corresponds to Ant's [junitreport](http://help.catchsoftware.com/display/ET/JUnit+Format) target. Useful for build systems that understand Junit.
Because of the way the junit format is structured the run must complete before anything is written.
Because of the way the junit format is structured the run must complete before anything is written.
* `xml` writes an xml format tailored to Catch. Unlike `junit` this is a streaming format so results are delivered progressively.
* `xml` writes an xml format tailored to Catch. Unlike `junit` this is a streaming format so results are delivered progressively.
There are a few additional reporters, for specific build systems, in the Catch repository (in `include\reporters`) which you can `#include` in your project if you would like to make use of them.
There are a few additional reporters, for specific build systems, in the Catch repository (in `include\reporters`) which you can `#include` in your project if you would like to make use of them.
-Do this in one source file - typically the same one you have `CATCH_CONFIG_MAIN` or `CATCH_CONFIG_RUNNER`.
+Do this in one source file - the same one you have `CATCH_CONFIG_MAIN` or `CATCH_CONFIG_RUNNER`.
-* `teamcity` writes the native, streaming, format that [TeamCity](https://www.jetbrains.com/teamcity/) understands.
-Use this when building as part of a TeamCity build to see results as they happen.
+* `teamcity` writes the native, streaming, format that [TeamCity](https://www.jetbrains.com/teamcity/) understands.
+Use this when building as part of a TeamCity build to see results as they happen ([code example](../examples/207-Rpt-TeamCityReporter.cpp)).
* `tap` writes in the TAP ([Test Anything Protocol](https://en.wikipedia.org/wiki/Test_Anything_Protocol)) format.
* `tap` writes in the TAP ([Test Anything Protocol](https://en.wikipedia.org/wiki/Test_Anything_Protocol)) format.
* `automake` writes in a format that correspond to [automake .trs](https://www.gnu.org/software/automake/manual/html_node/Log-files-generation-and-test-results-recording.html) files
* `automake` writes in a format that correspond to [automake .trs](https://www.gnu.org/software/automake/manual/html_node/Log-files-generation-and-test-results-recording.html) files
@@ -42,4 +43,4 @@ but do keep in mind upcoming changes (these will be minor, simplifying, changes
+[Other possible solutions](#other-possible-solutions)<br>
+
Several people have reported that test code written with Catch takes much longer to compile than they would expect. Why is that?
Several people have reported that test code written with Catch takes much longer to compile than they would expect. Why is that?
Catch is implemented entirely in headers. There is a little overhead due to this - but not as much as you might think - and you can minimise it simply by organising your test code as follows:
Catch is implemented entirely in headers. There is a little overhead due to this - but not as much as you might think - and you can minimise it simply by organising your test code as follows:
@@ -18,7 +25,7 @@ Because Catch is implemented *entirely* in headers you might think that the whol
As a result the main source file *does* compile the whole of Catch every time! So it makes sense to dedicate this file to *only* ```#define```-ing the identifier and ```#include```-ing Catch (and implementing the runner code, if you're doing that). Keep all your test cases in other files. This way you won't pay the recompilation cost for the whole of Catch
As a result the main source file *does* compile the whole of Catch every time! So it makes sense to dedicate this file to *only* ```#define```-ing the identifier and ```#include```-ing Catch (and implementing the runner code, if you're doing that). Keep all your test cases in other files. This way you won't pay the recompilation cost for the whole of Catch
## Practical example
## Practical example
-Assume you have the `Factorial` function from the [tutorial](tutorial.md) in `factorial.cpp` (with forward declaration in `factorial.h`) and want to test it and keep the compile times down when adding new tests. Then you should have 2 files, `tests-main.cpp` and `tests-factorial.cpp`:
+Assume you have the `Factorial` function from the [tutorial](tutorial.md#top) in `factorial.cpp` (with forward declaration in `factorial.h`) and want to test it and keep the compile times down when adding new tests. Then you should have 2 files, `tests-main.cpp` and `tests-factorial.cpp`:
```cpp
```cpp
// tests-main.cpp
// tests-main.cpp
@@ -44,14 +51,15 @@ After compiling `tests-main.cpp` once, it is enough to link it with separately c
Now, the next time we change the file `tests-factorial.cpp` (say we add `REQUIRE( Factorial(0) == 1)`), it is enough to recompile the tests instead of recompiling main as well:
Now, the next time we change the file `tests-factorial.cpp` (say we add `REQUIRE( Factorial(0) == 1)`), it is enough to recompile the tests instead of recompiling main as well:
+[BDD-style test cases](#bdd-style-test-cases)<br>
+[Type parametrised test cases](#type-parametrised-test-cases)<br>
+[Signature based parametrised test cases](#signature-based-parametrised-test-cases)<br>
+
While Catch fully supports the traditional, xUnit, style of class-based fixtures containing test case methods this is not the preferred style.
While Catch fully supports the traditional, xUnit, style of class-based fixtures containing test case methods this is not the preferred style.
Instead Catch provides a powerful mechanism for nesting test case sections within a test case. For a more detailed discussion see the [tutorial](tutorial.md#test-cases-and-sections).
Instead Catch provides a powerful mechanism for nesting test case sections within a test case. For a more detailed discussion see the [tutorial](tutorial.md#test-cases-and-sections).
@@ -11,7 +19,7 @@ Test cases and sections are very easy to use in practice:
_test name_ and _section name_ are free form, quoted, strings. The optional _tags_ argument is a quoted string containing one or more tags enclosed in square brackets. Tags are discussed below. Test names must be unique within the Catch executable.
_test name_ and _section name_ are free form, quoted, strings. The optional _tags_ argument is a quoted string containing one or more tags enclosed in square brackets. Tags are discussed below. Test names must be unique within the Catch executable.
-For examples see the [Tutorial](tutorial.md)
+For examples see the [Tutorial](tutorial.md#top)
## Tags
## Tags
@@ -19,10 +27,10 @@ Tags allow an arbitrary number of additional strings to be associated with a tes
The tag expression, ```"[widget]"``` selects A, B & D. ```"[gadget]"``` selects C & D. ```"[widget][gadget]"``` selects just D and ```"[widget],[gadget]"``` selects all four test cases.
The tag expression, ```"[widget]"``` selects A, B & D. ```"[gadget]"``` selects C & D. ```"[widget][gadget]"``` selects just D and ```"[widget],[gadget]"``` selects all four test cases.
@@ -34,9 +42,9 @@ Tag names are not case sensitive and can contain any ASCII characters. This mean
All tag names beginning with non-alphanumeric characters are reserved by Catch. Catch defines a number of "special" tags, which have meaning to the test runner itself. These special tags all begin with a symbol character. Following is a list of currently defined special tags and their meanings.
All tag names beginning with non-alphanumeric characters are reserved by Catch. Catch defines a number of "special" tags, which have meaning to the test runner itself. These special tags all begin with a symbol character. Following is a list of currently defined special tags and their meanings.
-* `[!hide]` or `[.]` (or, for legacy reasons, `[hide]`) - causes test cases to be skipped from the default list (i.e. when no test cases have been explicitly selected through tag expressions or name wildcards). The hide tag is often combined with another, user, tag (for example `[.][integration]` - so all integration tests are excluded from the default run but can be run by passing `[integration]` on the command line). As a short-cut you can combine these by simply prefixing your user tag with a `.` - e.g. `[.integration]`. Because the hide tag has evolved to have several forms, all forms are added as tags if you use one of them.
+* `[!hide]` or `[.]` - causes test cases to be skipped from the default list (i.e. when no test cases have been explicitly selected through tag expressions or name wildcards). The hide tag is often combined with another, user, tag (for example `[.][integration]` - so all integration tests are excluded from the default run but can be run by passing `[integration]` on the command line). As a short-cut you can combine these by simply prefixing your user tag with a `.` - e.g. `[.integration]`. Because the hide tag has evolved to have several forms, all forms are added as tags if you use one of them.
-* `[!throws]`- lets Catch know that this test is likely to throw an exception even if successful. This causes the test to be excluded when running with `-e` or `--nothrow`.
+* `[!throws]`- lets Catch know that this test is likely to throw an exception even if successful. This causes the test to be excluded when running with `-e` or `--nothrow`.
* `[!mayfail]` - doesn't fail the test if any given assertion fails (but still reports it). This can be useful to flag a work-in-progress, or a known issue that you don't want to immediately fix but still want to track in your tests.
* `[!mayfail]` - doesn't fail the test if any given assertion fails (but still reports it). This can be useful to flag a work-in-progress, or a known issue that you don't want to immediately fix but still want to track in your tests.
@@ -48,15 +56,17 @@ All tag names beginning with non-alphanumeric characters are reserved by Catch.
* `[@<alias>]` - tag aliases all begin with `@` (see below).
* `[@<alias>]` - tag aliases all begin with `@` (see below).
+* `[!benchmark]` - this test case is actually a benchmark. This is an experimental feature, and currently has no documentation. If you want to try it out, look at `projects/SelfTest/Benchmark.tests.cpp` for details.
+
## Tag aliases
## Tag aliases
Between tag expressions and wildcarded test names (as well as combinations of the two) quite complex patterns can be constructed to direct which test cases are run. If a complex pattern is used often it is convenient to be able to create an alias for the expression. This can be done, in code, using the following form:
Between tag expressions and wildcarded test names (as well as combinations of the two) quite complex patterns can be constructed to direct which test cases are run. If a complex pattern is used often it is convenient to be able to create an alias for the expression. This can be done, in code, using the following form:
Now when `[@nhf]` is used on the command line this matches all tests that are tagged `[failing]`, but which are not also hidden.
Now when `[@nhf]` is used on the command line this matches all tests that are tagged `[failing]`, but which are not also hidden.
@@ -74,15 +84,192 @@ This macro maps onto ```TEST_CASE``` and works in the same way, except that the
These macros map onto ```SECTION```s except that the section names are the _something_s prefixed by "given: ", "when: " or "then: " respectively.
These macros map onto ```SECTION```s except that the section names are the _something_s prefixed by "given: ", "when: " or "then: " respectively.
+* **AND_GIVEN(** _something_ **)**
* **AND_WHEN(** _something_ **)**
* **AND_WHEN(** _something_ **)**
* **AND_THEN(** _something_ **)**
* **AND_THEN(** _something_ **)**
-Similar to ```WHEN``` and ```THEN``` except that the prefixes start with "and ". These are used to chain ```WHEN```s and ```THEN```s together.
+Similar to ```GIVEN```, ```WHEN``` and ```THEN``` except that the prefixes start with "and ". These are used to chain ```GIVEN```s, ```WHEN```s and ```THEN```s together.
+
+> `AND_GIVEN` was [introduced](https://github.com/catchorg/Catch2/issues/1360) in Catch 2.4.0.
When any of these macros are used the console reporter recognises them and formats the test case header such that the Givens, Whens and Thens are aligned to aid readability.
When any of these macros are used the console reporter recognises them and formats the test case header such that the Givens, Whens and Thens are aligned to aid readability.
Other than the additional prefixes and the formatting in the console reporter these macros behave exactly as ```TEST_CASE```s and ```SECTION```s. As such there is nothing enforcing the correct sequencing of these macros - that's up to the programmer!
Other than the additional prefixes and the formatting in the console reporter these macros behave exactly as ```TEST_CASE```s and ```SECTION```s. As such there is nothing enforcing the correct sequencing of these macros - that's up to the programmer!
+## Type parametrised test cases
+
+In addition to `TEST_CASE`s, Catch2 also supports test cases parametrised
+by types, in the form of `TEMPLATE_TEST_CASE`,
+`TEMPLATE_PRODUCT_TEST_CASE` and `TEMPLATE_LIST_TEST_CASE`.
Although Catch allows you to group tests together as sections within a test case, it can still be convenient, sometimes, to group them using a more traditional test fixture. Catch fully supports this too. You define the test fixture as a simple structure:
Although Catch allows you to group tests together as sections within a test case, it can still be convenient, sometimes, to group them using a more traditional test fixture. Catch fully supports this too. You define the test fixture as a simple structure:
```c++
```c++
@@ -27,6 +32,112 @@ class UniqueTestsFixture {
The two test cases here will create uniquely-named derived classes of UniqueTestsFixture and thus can access the `getID()` protected method and `conn` member variables. This ensures that both the test cases are able to create a DBConnection using the same method (DRY principle) and that any ID's created are unique such that the order that tests are executed does not matter.
The two test cases here will create uniquely-named derived classes of UniqueTestsFixture and thus can access the `getID()` protected method and `conn` member variables. This ensures that both the test cases are able to create a DBConnection using the same method (DRY principle) and that any ID's created are unique such that the order that tests are executed does not matter.
+
+Catch2 also provides `TEMPLATE_TEST_CASE_METHOD` and
+`TEMPLATE_PRODUCT_TEST_CASE_METHOD` that can be used together
+with templated fixtures and templated template fixtures to perform
+tests for multiple different types. Unlike `TEST_CASE_METHOD`,
+`TEMPLATE_TEST_CASE_METHOD` and `TEMPLATE_PRODUCT_TEST_CASE_METHOD` do
+require the tag specification to be non-empty, as it is followed by
+further macro arguments.
+
+Also note that, because of limitations of the C++ preprocessor, if you
+want to specify a type with multiple template parameters, you need to
+enclose it in parentheses, e.g. `std::map<int, std::string>` needs to be
+passed as `(std::map<int, std::string>)`.
+In the case of `TEMPLATE_PRODUCT_TEST_CASE_METHOD`, if a member of the
+type list should consist of more than single type, it needs to be enclosed
+in another pair of parentheses, e.g. `(std::map, std::pair)` and
+`((int, float), (char, double))`.
+
+Example:
+```cpp
+template< typename T >
+struct Template_Fixture {
+ Template_Fixture(): m_a(1) {}
+
+ T m_a;
+};
+
+TEMPLATE_TEST_CASE_METHOD(Template_Fixture,"A TEMPLATE_TEST_CASE_METHOD based test run that succeeds", "[class][template]", int, float, double) {
+TEMPLATE_PRODUCT_TEST_CASE_METHOD(Template_Template_Fixture, "A TEMPLATE_PRODUCT_TEST_CASE_METHOD based test succeeds", "[class][template]", (Foo_class, std::vector), int) {
+_While there is an upper limit on the number of types you can specify
+in single `TEMPLATE_TEST_CASE_METHOD` or `TEMPLATE_PRODUCT_TEST_CASE_METHOD`,
+the limit is very high and should not be encountered in practice._
+
+## Signature-based parametrised test fixtures
+
+> [Introduced](https://github.com/catchorg/Catch2/issues/1609) in Catch 2.8.0.
+
+Catch2 also provides `TEMPLATE_TEST_CASE_METHOD_SIG` and `TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG` to support
+fixtures using non-type template parameters. These test cases work similar to `TEMPLATE_TEST_CASE_METHOD` and `TEMPLATE_PRODUCT_TEST_CASE_METHOD`,
+with additional positional argument for [signature](test-cases-and-sections.md#signature-based-parametrised-test-cases).
+
+Example:
+```cpp
+template <int V>
+struct Nttp_Fixture{
+ int value = V;
+};
+
+TEMPLATE_TEST_CASE_METHOD_SIG(Nttp_Fixture, "A TEMPLATE_TEST_CASE_METHOD_SIG based test run that succeeds", "[class][template][nttp]",((int V), V), 1, 3, 6) {
+ REQUIRE(Nttp_Fixture<V>::value > 0);
+}
+
+template<typename T>
+struct Template_Fixture_2 {
+ Template_Fixture_2() {}
+
+ T m_a;
+};
+
+template< typename T, size_t V>
+struct Template_Foo_2 {
+ size_t size() { return V; }
+};
+
+TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG(Template_Fixture_2, "A TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG based test run that succeeds", "[class][template][product][nttp]", ((typename T, size_t S), T, S),(std::array, Template_Foo_2), ((int,2), (float,6)))
+## Template fixtures with types specified in template type lists
+
+Catch2 also provides `TEMPLATE_LIST_TEST_CASE_METHOD` to support template fixtures with types specified in
+template type lists like `std::tuple`, `boost::mpl::list` or `boost::mp11::mp_list`. This test case works the same as `TEMPLATE_TEST_CASE_METHOD`,
+only difference is the source of types. This allows you to reuse the template type list in multiple test cases.
+
+Example:
+```cpp
+using MyTypes = std::tuple<int, char, double>;
+TEMPLATE_LIST_TEST_CASE_METHOD(Template_Fixture, "Template test case method with test types specified inside std::tuple", "[class][template][list]", MyTypes)
+[Floating point precision](#floating-point-precision)<br>
+
+
Catch needs to be able to convert types you use in assertions and logging expressions into strings (for logging and reporting purposes).
Catch needs to be able to convert types you use in assertions and logging expressions into strings (for logging and reporting purposes).
-Most built-in or std types are supported out of the box but there are three ways that you can tell Catch how to convert your own types (or other, third-party types) into strings.
+Most built-in or std types are supported out of the box but there are two ways that you can tell Catch how to convert your own types (or other, third-party types) into strings.
## operator << overload for std::ostream
## operator << overload for std::ostream
This is the standard way of providing string conversions in C++ - and the chances are you may already provide this for your own purposes. If you're not familiar with this idiom it involves writing a free function of the form:
This is the standard way of providing string conversions in C++ - and the chances are you may already provide this for your own purposes. If you're not familiar with this idiom it involves writing a free function of the form:
-```
+```cpp
std::ostream& operator << ( std::ostream& os, T const& value ) {
std::ostream& operator << ( std::ostream& os, T const& value ) {
-os << convertMyTypeToString( value );
-return os;
+os << convertMyTypeToString( value );
+return os;
}
}
```
```
(where ```T``` is your type and ```convertMyTypeToString``` is where you'll write whatever code is necessary to make your type printable - it doesn't have to be in another function).
(where ```T``` is your type and ```convertMyTypeToString``` is where you'll write whatever code is necessary to make your type printable - it doesn't have to be in another function).
-You should put this function in the same namespace as your type and it has to be declared before including Catch's header.
-
-## Catch::toString overload
+You should put this function in the same namespace as your type, or the global namespace, and have it declared before including Catch's header.
-If you don't want to provide an ```operator <<``` overload, or you want to convert your type differently for testing purposes, you can provide an overload for ```Catch::toString()``` for your type.
+## Catch::StringMaker specialisation
+If you don't want to provide an ```operator <<``` overload, or you want to convert your type differently for testing purposes, you can provide a specialization for `Catch::StringMaker<T>`:
-```
+```cpp
namespace Catch {
namespace Catch {
- std::string toString( T const& value ) {
- return convertMyTypeToString( value );
- }
+ template<>
+ struct StringMaker<T> {
+ static std::string convert( T const& value ) {
+ return convertMyTypeToString( value );
+ }
+ };
}
}
```
```
-Again ```T``` is your type and ```convertMyTypeToString``` is where you'll write whatever code is necessary to make your type printable. Note that the function must be in the Catch namespace, which itself must be in the global namespace and must be declared _before_ Catch's header is included.
-
-**Please note that overloading `Catch::toString` is currently considered legacy and will not be supported in the next major version of Catch.**
+## Catch::is_range specialisation
+As a fallback, Catch attempts to detect if the type can be iterated
+(`begin(T)` and `end(T)` are valid) and if it can be, it is stringified
+as a range. For certain types this can lead to infinite recursion, so
+it can be disabled by specializing `Catch::is_range` like so:
-## Catch::StringMaker<T> specialisation
-Another way of telling Catch how to convert a type to string is specialising `Catch::StringMaker` template. This allows you to have separate way of stringifying types for Catch, than you have for writing it to a stream and also doesn't require you to declare it before including Catch's header.
-
-```
+```cpp
namespace Catch {
namespace Catch {
- template<> struct StringMaker<T> {
- static std::string convert( T const& value ) {
- return convertMyTypeToString( value );
- }
- };
+ template<>
+ struct is_range<T> {
+ static const bool value = false;
+ };
}
}
+
```
```
+
## Exceptions
## Exceptions
By default all exceptions deriving from `std::exception` will be translated to strings by calling the `what()` method. For exception types that do not derive from `std::exception` - or if `what()` does not return a suitable string - use `CATCH_TRANSLATE_EXCEPTION`. This defines a function that takes your exception type, by reference, and returns a string. It can appear anywhere in the code - it doesn't have to be in the same translation unit. For example:
By default all exceptions deriving from `std::exception` will be translated to strings by calling the `what()` method. For exception types that do not derive from `std::exception` - or if `what()` does not return a suitable string - use `CATCH_TRANSLATE_EXCEPTION`. This defines a function that takes your exception type, by reference, and returns a string. It can appear anywhere in the code - it doesn't have to be in the same translation unit. For example:
-```
+```cpp
CATCH_TRANSLATE_EXCEPTION( MyType& ex ) {
CATCH_TRANSLATE_EXCEPTION( MyType& ex ) {
- return ex.message();
+ return ex.message();
+}
+```
+
+## Enums
+
+> Introduced in Catch 2.8.0.
+
+Enums that already have a `<<` overload for `std::ostream` will convert to strings as expected.
+If you only need to convert enums to strings for test reporting purposes you can provide a `StringMaker` specialisations as any other type.
+However, as a convenience, Catch provides the `REGISTER_ENUM` helper macro that will generate the `StringMaker` specialiation for you with minimal code.
+Simply provide it the (qualified) enum name, followed by all the enum values, and you're done!
-The simplest way to get Catch is to download the latest [single header version](https://raw.githubusercontent.com/philsquared/Catch/master/single_include/catch.hpp). The single header is generated by merging a set of individual headers but it is still just normal source code in a header file.
+**Contents**<br>
+[Getting Catch2](#getting-catch2)<br>
+[Where to put it?](#where-to-put-it)<br>
+[Writing tests](#writing-tests)<br>
+[Test cases and sections](#test-cases-and-sections)<br>
+[BDD-Style](#bdd-style)<br>
+[Scaling up](#scaling-up)<br>
+[Type parametrised test cases](#type-parametrised-test-cases)<br>
+[Next steps](#next-steps)<br>
-The full source for Catch, including test projects, documentation, and other things, is hosted on GitHub. [http://catch-lib.net](http://catch-lib.net) will redirect you there.
+## Getting Catch2
+
+The simplest way to get Catch2 is to download the latest [single header version](https://raw.githubusercontent.com/catchorg/Catch2/master/single_include/catch2/catch.hpp). The single header is generated by merging a set of individual headers but it is still just normal source code in a header file.
+
+Alternative ways of getting Catch2 include using your system package
+manager, or installing it using [its CMake package](cmake-integration.md#installing-catch2-from-git-repository).
+
+The full source for Catch2, including test projects, documentation, and other things, is hosted on GitHub. [http://catch-lib.net](http://catch-lib.net) will redirect you there.
## Where to put it?
## Where to put it?
-Catch is header only. All you need to do is drop the file(s) somewhere reachable from your project - either in some central location you can set your header search path to find, or directly into your project tree itself! This is a particularly good option for other Open-Source projects that want to use Catch for their test suite. See [this blog entry for more on that](http://www.levelofindirection.com/journal/2011/5/27/unit-testing-in-c-and-objective-c-just-got-ridiculously-easi.html).
+Catch2 is header only. All you need to do is drop the file somewhere reachable from your project - either in some central location you can set your header search path to find, or directly into your project tree itself! This is a particularly good option for other Open-Source projects that want to use Catch for their test suite. See [this blog entry for more on that](https://levelofindirection.com/blog/unit-testing-in-cpp-and-objective-c-just-got-ridiculously-easier-still.html).
-The rest of this tutorial will assume that the Catch single-include header (or the include folder) is available unqualified - but you may need to prefix it with a folder name if necessary.
+The rest of this tutorial will assume that the Catch2 single-include header (or the include folder) is available unqualified - but you may need to prefix it with a folder name if necessary.
-# Writing tests
+_If you have installed Catch2 from system package manager, or CMake
+package, you need to include the header as `#include <catch2/catch.hpp>`_
-Let's start with a really simple example. Say you have written a function to calculate factorials and now you want to test it (let's leave aside TDD for now).
+## Writing tests
+
+Let's start with a really simple example ([code](../examples/010-TestCase.cpp)). Say you have written a function to calculate factorials and now you want to test it (let's leave aside TDD for now).
```c++
```c++
unsigned int Factorial( unsigned int number ) {
unsigned int Factorial( unsigned int number ) {
@@ -21,7 +40,7 @@ unsigned int Factorial( unsigned int number ) {
}
}
```
```
-To keep things simple we'll put everything in a single file (<a href="#scaling-up">see later for more on how to structure your test files</a>)
+To keep things simple we'll put everything in a single file (<a href="#scaling-up">see later for more on how to structure your test files</a>).
```c++
```c++
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
-This will compile to a complete executable which responds to [command line arguments](command-line.md). If you just run it with no arguments it will execute all test cases (in this case there is just one), report any failures, report a summary of how many tests passed and failed and return the number of failed tests (useful for if you just want a yes/ no answer to: "did it work").
+This will compile to a complete executable which responds to [command line arguments](command-line.md#top). If you just run it with no arguments it will execute all test cases (in this case there is just one), report any failures, report a summary of how many tests passed and failed and return the number of failed tests (useful for if you just want a yes/ no answer to: "did it work").
If you run this as written it will pass. Everything is good. Right?
If you run this as written it will pass. Everything is good. Right?
Well, there is still a bug here. In fact the first version of this tutorial I posted here genuinely had the bug in! So it's not completely contrived (thanks to Daryle Walker (```@CTMacUser```) for pointing this out).
Well, there is still a bug here. In fact the first version of this tutorial I posted here genuinely had the bug in! So it's not completely contrived (thanks to Daryle Walker (```@CTMacUser```) for pointing this out).
@@ -82,12 +101,12 @@ Now all the tests pass.
Of course there are still more issues to deal with. For example we'll hit problems when the return value starts to exceed the range of an unsigned int. With factorials that can happen quite quickly. You might want to add tests for such cases and decide how to handle them. We'll stop short of doing that here.
Of course there are still more issues to deal with. For example we'll hit problems when the return value starts to exceed the range of an unsigned int. With factorials that can happen quite quickly. You might want to add tests for such cases and decide how to handle them. We'll stop short of doing that here.
-## What did we do here?
+### What did we do here?
-Although this was a simple test it's been enough to demonstrate a few things about how Catch is used. Let's take moment to consider those before we move on.
+Although this was a simple test it's been enough to demonstrate a few things about how Catch is used. Let's take a moment to consider those before we move on.
-1. All we did was ```#define``` one identifier and ```#include``` one header and we got everything - even an implementation of ```main()``` that will [respond to command line arguments](command-line.md). You can only use that ```#define``` in one implementation file, for (hopefully) obvious reasons. Once you have more than one file with unit tests in you'll just ```#include "catch.hpp"``` and go. Usually it's a good idea to have a dedicated implementation file that just has ```#define CATCH_CONFIG_MAIN``` and ```#include "catch.hpp"```. You can also provide your own implementation of main and drive Catch yourself (see [Supplying-your-own-main()](own-main.md)).
-2. We introduce test cases with the ```TEST_CASE``` macro. This macro takes one or two arguments - a free form test name and, optionally, one or more tags (for more see <a href="#test-cases-and-sections">Test cases and Sections</a>, ). The test name must be unique. You can run sets of tests by specifying a wildcarded test name or a tag expression. See the [command line docs](command-line.md) for more information on running tests.
+1. All we did was ```#define``` one identifier and ```#include``` one header and we got everything - even an implementation of ```main()``` that will [respond to command line arguments](command-line.md#top). You can only use that ```#define``` in one implementation file, for (hopefully) obvious reasons. Once you have more than one file with unit tests in you'll just ```#include "catch.hpp"``` and go. Usually it's a good idea to have a dedicated implementation file that just has ```#define CATCH_CONFIG_MAIN``` and ```#include "catch.hpp"```. You can also provide your own implementation of main and drive Catch yourself (see [Supplying-your-own-main()](own-main.md#top)).
+2. We introduce test cases with the ```TEST_CASE``` macro. This macro takes one or two arguments - a free form test name and, optionally, one or more tags (for more see <a href="#test-cases-and-sections">Test cases and Sections</a>, ). The test name must be unique. You can run sets of tests by specifying a wildcarded test name or a tag expression. See the [command line docs](command-line.md#top) for more information on running tests.
3. The name and tags arguments are just strings. We haven't had to declare a function or method - or explicitly register the test case anywhere. Behind the scenes a function with a generated name is defined for you, and automatically registered using static registry classes. By abstracting the function name away we can name our tests without the constraints of identifier names.
3. The name and tags arguments are just strings. We haven't had to declare a function or method - or explicitly register the test case anywhere. Behind the scenes a function with a generated name is defined for you, and automatically registered using static registry classes. By abstracting the function name away we can name our tests without the constraints of identifier names.
4. We write our individual test assertions using the ```REQUIRE``` macro. Rather than a separate macro for each type of condition we express the condition naturally using C/C++ syntax. Behind the scenes a simple set of expression templates captures the left-hand-side and right-hand-side of the expression so we can display the values in our test report. As we'll see later there _are_ other assertion macros - but because of this technique the number of them is drastically reduced.
4. We write our individual test assertions using the ```REQUIRE``` macro. Rather than a separate macro for each type of condition we express the condition naturally using C/C++ syntax. Behind the scenes a simple set of expression templates captures the left-hand-side and right-hand-side of the expression so we can display the values in our test report. As we'll see later there _are_ other assertion macros - but because of this technique the number of them is drastically reduced.
@@ -98,37 +117,37 @@ Most test frameworks have a class-based fixture mechanism. That is, test cases m
While Catch fully supports this way of working there are a few problems with the approach. In particular the way your code must be split up, and the blunt granularity of it, may cause problems. You can only have one setup/ teardown pair across a set of methods, but sometimes you want slightly different setup in each method, or you may even want several levels of setup (a concept which we will clarify later on in this tutorial). It was <a href="http://jamesnewkirk.typepad.com/posts/2007/09/why-you-should-.html">problems like these</a> that led James Newkirk, who led the team that built NUnit, to start again from scratch and <a href="http://jamesnewkirk.typepad.com/posts/2007/09/announcing-xuni.html">build xUnit</a>).
While Catch fully supports this way of working there are a few problems with the approach. In particular the way your code must be split up, and the blunt granularity of it, may cause problems. You can only have one setup/ teardown pair across a set of methods, but sometimes you want slightly different setup in each method, or you may even want several levels of setup (a concept which we will clarify later on in this tutorial). It was <a href="http://jamesnewkirk.typepad.com/posts/2007/09/why-you-should-.html">problems like these</a> that led James Newkirk, who led the team that built NUnit, to start again from scratch and <a href="http://jamesnewkirk.typepad.com/posts/2007/09/announcing-xuni.html">build xUnit</a>).
-Catch takes a different approach (to both NUnit and xUnit) that is a more natural fit for C++ and the C family of languages. This is best explained through an example:
+Catch takes a different approach (to both NUnit and xUnit) that is a more natural fit for C++ and the C family of languages. This is best explained through an example ([code](../examples/100-Fix-Section.cpp)):
```c++
```c++
TEST_CASE( "vectors can be sized and resized", "[vector]" ) {
TEST_CASE( "vectors can be sized and resized", "[vector]" ) {
std::vector<int> v( 5 );
std::vector<int> v( 5 );
-
+
REQUIRE( v.size() == 5 );
REQUIRE( v.size() == 5 );
REQUIRE( v.capacity() >= 5 );
REQUIRE( v.capacity() >= 5 );
-
+
SECTION( "resizing bigger changes size and capacity" ) {
SECTION( "resizing bigger changes size and capacity" ) {
v.resize( 10 );
v.resize( 10 );
-
+
REQUIRE( v.size() == 10 );
REQUIRE( v.size() == 10 );
REQUIRE( v.capacity() >= 10 );
REQUIRE( v.capacity() >= 10 );
}
}
SECTION( "resizing smaller changes size but not capacity" ) {
SECTION( "resizing smaller changes size but not capacity" ) {
v.resize( 0 );
v.resize( 0 );
-
+
REQUIRE( v.size() == 0 );
REQUIRE( v.size() == 0 );
REQUIRE( v.capacity() >= 5 );
REQUIRE( v.capacity() >= 5 );
}
}
SECTION( "reserving bigger changes capacity but not size" ) {
SECTION( "reserving bigger changes capacity but not size" ) {
v.reserve( 10 );
v.reserve( 10 );
-
+
REQUIRE( v.size() == 5 );
REQUIRE( v.size() == 5 );
REQUIRE( v.capacity() >= 10 );
REQUIRE( v.capacity() >= 10 );
}
}
SECTION( "reserving smaller does not change size or capacity" ) {
SECTION( "reserving smaller does not change size or capacity" ) {
v.reserve( 0 );
v.reserve( 0 );
-
+
REQUIRE( v.size() == 5 );
REQUIRE( v.size() == 5 );
REQUIRE( v.capacity() >= 5 );
REQUIRE( v.capacity() >= 5 );
}
}
@@ -140,18 +159,18 @@ This works because the ```SECTION``` macro contains an if statement that calls b
So far so good - this is already an improvement on the setup/teardown approach because now we see our setup code inline and use the stack.
So far so good - this is already an improvement on the setup/teardown approach because now we see our setup code inline and use the stack.
-The power of sections really shows, however, when we need to execute a sequence of, checked, operations. Continuing the vector example, we might want to verify that attempting to reserve a capacity smaller than the current capacity of the vector changes nothing. We can do that, naturally, like so:
+The power of sections really shows, however, when we need to execute a sequence of checked operations. Continuing the vector example, we might want to verify that attempting to reserve a capacity smaller than the current capacity of the vector changes nothing. We can do that, naturally, like so:
```c++
```c++
SECTION( "reserving bigger changes capacity but not size" ) {
SECTION( "reserving bigger changes capacity but not size" ) {
v.reserve( 10 );
v.reserve( 10 );
-
+
REQUIRE( v.size() == 5 );
REQUIRE( v.size() == 5 );
REQUIRE( v.capacity() >= 10 );
REQUIRE( v.capacity() >= 10 );
-
+
SECTION( "reserving smaller again does not change capacity" ) {
SECTION( "reserving smaller again does not change capacity" ) {
v.reserve( 7 );
v.reserve( 7 );
-
+
REQUIRE( v.capacity() >= 10 );
REQUIRE( v.capacity() >= 10 );
}
}
}
}
@@ -161,22 +180,22 @@ Sections can be nested to an arbitrary depth (limited only by your stack size).
## BDD-Style
## BDD-Style
-If you name your test cases and sections appropriately you can achieve a BDD-style specification structure. This became such a useful way of working that first class support has been added to Catch. Scenarios can be specified using ```SCENARIO```, ```GIVEN```, ```WHEN``` and ```THEN``` macros, which map on to ```TEST_CASE```s and ```SECTION```s, respectively. For more details see [Test cases and sections](test-cases-and-sections.md).
+If you name your test cases and sections appropriately you can achieve a BDD-style specification structure. This became such a useful way of working that first class support has been added to Catch. Scenarios can be specified using ```SCENARIO```, ```GIVEN```, ```WHEN``` and ```THEN``` macros, which map on to ```TEST_CASE```s and ```SECTION```s, respectively. For more details see [Test cases and sections](test-cases-and-sections.md#top).
-The vector example can be adjusted to use these macros like so:
+The vector example can be adjusted to use these macros like so ([example code](../examples/120-Bdd-ScenarioGivenWhenThen.cpp)):
```c++
```c++
SCENARIO( "vectors can be sized and resized", "[vector]" ) {
SCENARIO( "vectors can be sized and resized", "[vector]" ) {
GIVEN( "A vector with some items" ) {
GIVEN( "A vector with some items" ) {
std::vector<int> v( 5 );
std::vector<int> v( 5 );
-
+
REQUIRE( v.size() == 5 );
REQUIRE( v.size() == 5 );
REQUIRE( v.capacity() >= 5 );
REQUIRE( v.capacity() >= 5 );
-
+
WHEN( "the size is increased" ) {
WHEN( "the size is increased" ) {
v.resize( 10 );
v.resize( 10 );
-
+
THEN( "the size and capacity change" ) {
THEN( "the size and capacity change" ) {
REQUIRE( v.size() == 10 );
REQUIRE( v.size() == 10 );
REQUIRE( v.capacity() >= 10 );
REQUIRE( v.capacity() >= 10 );
@@ -184,7 +203,7 @@ SCENARIO( "vectors can be sized and resized", "[vector]" ) {
}
}
WHEN( "the size is reduced" ) {
WHEN( "the size is reduced" ) {
v.resize( 0 );
v.resize( 0 );
-
+
THEN( "the size changes but not capacity" ) {
THEN( "the size changes but not capacity" ) {
REQUIRE( v.size() == 0 );
REQUIRE( v.size() == 0 );
REQUIRE( v.capacity() >= 5 );
REQUIRE( v.capacity() >= 5 );
@@ -192,7 +211,7 @@ SCENARIO( "vectors can be sized and resized", "[vector]" ) {
}
}
WHEN( "more capacity is reserved" ) {
WHEN( "more capacity is reserved" ) {
v.reserve( 10 );
v.reserve( 10 );
-
+
THEN( "the capacity changes but not the size" ) {
THEN( "the capacity changes but not the size" ) {
REQUIRE( v.size() == 5 );
REQUIRE( v.size() == 5 );
REQUIRE( v.capacity() >= 10 );
REQUIRE( v.capacity() >= 10 );
@@ -200,7 +219,7 @@ SCENARIO( "vectors can be sized and resized", "[vector]" ) {
}
}
WHEN( "less capacity is reserved" ) {
WHEN( "less capacity is reserved" ) {
v.reserve( 0 );
v.reserve( 0 );
-
+
THEN( "neither size nor capacity are changed" ) {
THEN( "neither size nor capacity are changed" ) {
REQUIRE( v.size() == 5 );
REQUIRE( v.size() == 5 );
REQUIRE( v.capacity() >= 5 );
REQUIRE( v.capacity() >= 5 );
@@ -224,7 +243,7 @@ Scenario: vectors can be sized and resized
To keep the tutorial simple we put all our code in a single file. This is fine to get started - and makes jumping into Catch even quicker and easier. As you write more real-world tests, though, this is not really the best approach.
To keep the tutorial simple we put all our code in a single file. This is fine to get started - and makes jumping into Catch even quicker and easier. As you write more real-world tests, though, this is not really the best approach.
-The requirement is that the following block of code ([or equivalent](own-main.md)):
+The requirement is that the following block of code ([or equivalent](own-main.md#top)):
```c++
```c++
#define CATCH_CONFIG_MAIN
#define CATCH_CONFIG_MAIN
@@ -233,17 +252,28 @@ The requirement is that the following block of code ([or equivalent](own-main.md
appears in _exactly one_ source file. Use as many additional cpp files (or whatever you call your implementation files) as you need for your tests, partitioned however makes most sense for your way of working. Each additional file need only ```#include "catch.hpp"``` - do not repeat the ```#define```!
appears in _exactly one_ source file. Use as many additional cpp files (or whatever you call your implementation files) as you need for your tests, partitioned however makes most sense for your way of working. Each additional file need only ```#include "catch.hpp"``` - do not repeat the ```#define```!
-In fact it is usually a good idea to put the block with the ```#define``` [in its own source file](slow-compiles.md).
+In fact it is usually a good idea to put the block with the ```#define``` [in its own source file](slow-compiles.md#top) (code example [main](../examples/020-TestCase-1.cpp), [tests](../examples/020-TestCase-2.cpp)).
Do not write your tests in header files!
Do not write your tests in header files!
+## Type parametrised test cases
+
+Test cases in Catch2 can be also parametrised by type, via the
+`TEMPLATE_TEST_CASE` and `TEMPLATE_PRODUCT_TEST_CASE` macros,
+which behave in the same way the `TEST_CASE` macro, but are run for
+every type or type combination.
+
+For more details, see our documentation on [test cases and
This has been a brief introduction to get you up and running with Catch, and to point out some of the key differences between Catch and other frameworks you may already be familiar with. This will get you going quite far already and you are now in a position to dive in and write some tests.
This has been a brief introduction to get you up and running with Catch, and to point out some of the key differences between Catch and other frameworks you may already be familiar with. This will get you going quite far already and you are now in a position to dive in and write some tests.
-Of course there is more to learn - most of which you should be able to page-fault in as you go. Please see the ever-growing [Reference section](Readme.md) for what's available.
+Of course there is more to learn - most of which you should be able to page-fault in as you go. Please see the ever-growing [Reference section](Readme.md#top) for what's available.
-Good question. For C++ there are quite a number of established frameworks, including (but not limited to), [CppUnit](http://sourceforge.net/apps/mediawiki/cppunit/index.php?title=Main_Page), [Google Test](http://code.google.com/p/googletest/), [Boost.Test](http://www.boost.org/doc/libs/1_49_0/libs/test/doc/html/index.html), [Aeryn](https://launchpad.net/aeryn), [Cute](http://r2.ifs.hsr.ch/cute), [Fructose](http://fructose.sourceforge.net/) and [many, many more](http://en.wikipedia.org/wiki/List_of_unit_testing_frameworks#C.2B.2B). Even for Objective-C there are a few, including OCUnit - which now comes bundled with XCode.
+Good question. For C++ there are quite a number of established frameworks,
+[many, many more](http://en.wikipedia.org/wiki/List_of_unit_testing_frameworks#C.2B.2B).
So what does Catch bring to the party that differentiates it from these? Apart from a Catchy name, of course.
So what does Catch bring to the party that differentiates it from these? Apart from a Catchy name, of course.
## Key Features
## Key Features
-* Really easy to get started. Just download catch.hpp, #include it and you're away.
-* No external dependencies. As long as you can compile C++98 and have a C++ standard library available.
-* Write test cases as, self-registering, functions or methods.
-* Divide test cases into sections, each of which is run in isolation (eliminates the need for fixtures!)
+* Quick and Really easy to get started. Just download catch.hpp, `#include` it and you're away.
+* No external dependencies. As long as you can compile C++11 and have a C++ standard library available.
+* Write test cases as, self-registering, functions (or methods, if you prefer).
+* Divide test cases into sections, each of which is run in isolation (eliminates the need for fixtures).
* Use BDD-style Given-When-Then sections as well as traditional unit test cases.
* Use BDD-style Given-When-Then sections as well as traditional unit test cases.
* Only one core assertion macro for comparisons. Standard C/C++ operators are used for the comparison - yet the full expression is decomposed and lhs and rhs values are logged.
* Only one core assertion macro for comparisons. Standard C/C++ operators are used for the comparison - yet the full expression is decomposed and lhs and rhs values are logged.
+* Tests are named using free-form strings - no more couching names in legal identifiers.
## Other core features
## Other core features
-* Tests are named using free-form strings - no more couching names in legal identifiers.
* Tests can be tagged for easily running ad-hoc groups of tests.
* Tests can be tagged for easily running ad-hoc groups of tests.
* Failures can (optionally) break into the debugger on Windows and Mac.
* Failures can (optionally) break into the debugger on Windows and Mac.
* Output is through modular reporter objects. Basic textual and XML reporters are included. Custom reporters can easily be added.
* Output is through modular reporter objects. Basic textual and XML reporters are included. Custom reporters can easily be added.
* JUnit xml output is supported for integration with third-party tools, such as CI servers.
* JUnit xml output is supported for integration with third-party tools, such as CI servers.
-* A default main() function is provided (in a header), but you can supply your own for complete control (e.g. integration into your own test runner GUI).
+* A default main() function is provided, but you can supply your own for complete control (e.g. integration into your own test runner GUI).
* A command line parser is provided and can still be used if you choose to provided your own main() function.
* A command line parser is provided and can still be used if you choose to provided your own main() function.
* Catch can test itself.
* Catch can test itself.
* Alternative assertion macro(s) report failures but don't abort the test case
* Alternative assertion macro(s) report failures but don't abort the test case
* Floating point tolerance comparisons are built in using an expressive Approx() syntax.
* Floating point tolerance comparisons are built in using an expressive Approx() syntax.
* Internal and friendly macros are isolated so name clashes can be managed
* Internal and friendly macros are isolated so name clashes can be managed
-* Support for Matchers (early stages)
-
-## Objective-C-specific features
-
-* Automatically detects if you are using it from an Objective-C project
-* Works with and without ARC with no additional configuration
-* Implement test fixtures using Obj-C classes too (like OCUnit)
-* Additional built in matchers that work with Obj-C types (e.g. string matchers)
+* Matchers
## Who else is using Catch?
## Who else is using Catch?
-See the list of [open source projects using Catch](opensource-users.md).
+See the list of [open source projects using Catch](opensource-users.md#top).
-See the [tutorial](tutorial.md) to get more of a taste of using CATCH in practice
+See the [tutorial](tutorial.md#top) to get more of a taste of using Catch in practice
- } while( Catch::isTrue( false && static_cast<bool>( !!(expr) ) ) ) // expr here is never evaluated at runtime but it forces the compiler to give it a look
-// The double negation silences MSVC's C4800 warning, the static_cast forces short-circuit evaluation if the type has overloaded &&.
- } while( Catch::isTrue( false && static_cast<bool>( !!(expr) ) ) ) // expr here is never evaluated at runtime but it forces the compiler to give it a look
+ } while( (void)0, (false) && static_cast<bool>( !!(__VA_ARGS__) ) ) // the expression here is never evaluated at runtime but it forces the compiler to give it a look
// The double negation silences MSVC's C4800 warning, the static_cast forces short-circuit evaluation if the type has overloaded &&.
// The double negation silences MSVC's C4800 warning, the static_cast forces short-circuit evaluation if the type has overloaded &&.