Skip to content
Snippets Groups Projects
Commit 61d96553 authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

git subrepo pull packages/Catch2

subrepo:
  subdir:   "packages/Catch2"
  merged:   "4902cd721"
upstream:
  origin:   "git@github.com:catchorg/Catch2.git"
  branch:   "master"
  commit:   "4902cd721"
git-subrepo:
  version:  "0.4.0"
  origin:   "git@github.com:ingydotnet/git-subrepo.git"
  commit:   "5d6aba9"
parent ee2eaf8a
No related branches found
No related tags found
No related merge requests found
Showing
with 437 additions and 55 deletions
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import re
from cpt.packager import ConanMultiPackager
from cpt.ci_manager import CIManager
from cpt.printer import Printer
class BuilderSettings(object):
@property
def username(self):
""" Set catchorg as package's owner
"""
return os.getenv("CONAN_USERNAME", "catchorg")
@property
def login_username(self):
""" Set Bintray login username
"""
return os.getenv("CONAN_LOGIN_USERNAME", "horenmar")
@property
def upload(self):
""" Set Catch2 repository to be used on upload.
The upload server address could be customized by env var
CONAN_UPLOAD. If not defined, the method will check the branch name.
Only master or CONAN_STABLE_BRANCH_PATTERN will be accepted.
The master branch will be pushed to testing channel, because it does
not match the stable pattern. Otherwise it will upload to stable
channel.
"""
return os.getenv("CONAN_UPLOAD", "https://api.bintray.com/conan/catchorg/Catch2")
@property
def upload_only_when_stable(self):
""" Force to upload when running over tag branch
"""
return os.getenv("CONAN_UPLOAD_ONLY_WHEN_STABLE", "True").lower() in ["true", "1", "yes"]
@property
def stable_branch_pattern(self):
""" Only upload the package the branch name is like a tag
"""
return os.getenv("CONAN_STABLE_BRANCH_PATTERN", r"v\d+\.\d+\.\d+")
@property
def reference(self):
""" Read project version from branch create Conan referece
"""
return os.getenv("CONAN_REFERENCE", "Catch2/{}".format(self._version))
@property
def channel(self):
""" Default Conan package channel when not stable
"""
return os.getenv("CONAN_CHANNEL", "testing")
@property
def _version(self):
""" Get version name from cmake file
"""
pattern = re.compile(r"project\(Catch2 LANGUAGES CXX VERSION (\d+\.\d+\.\d+)\)")
version = "latest"
with open("CMakeLists.txt") as file:
for line in file:
result = pattern.search(line)
if result:
version = result.group(1)
return version
@property
def _branch(self):
""" Get branch name from CI manager
"""
printer = Printer(None)
ci_manager = CIManager(printer)
return ci_manager.get_branch()
if __name__ == "__main__":
settings = BuilderSettings()
builder = ConanMultiPackager(
reference=settings.reference,
channel=settings.channel,
upload=settings.upload,
upload_only_when_stable=settings.upload_only_when_stable,
stable_branch_pattern=settings.stable_branch_pattern,
login_username=settings.login_username,
username=settings.username,
test_folder=os.path.join(".conan", "test_package"))
builder.add()
builder.run()
cmake_minimum_required(VERSION 3.2.0)
project(test_package CXX)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
find_package(Catch2 REQUIRED CONFIG)
add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} CONAN_PKG::Catch2)
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 11)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from conans import ConanFile, CMake
import os
class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake"
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
def test(self):
assert os.path.isfile(os.path.join(self.deps_cpp_info["Catch2"].rootpath, "licenses", "LICENSE.txt"))
bin_path = os.path.join("bin", "test_package")
self.run("%s -s" % bin_path, run_environment=True)
/*
* Created by Phil on 22/10/2010.
* Copyright 2010 Two Blue Cubes Ltd
*
* Distributed under the Boost Software License, Version 1.0. (See accompanying
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#define CATCH_CONFIG_MAIN #define CATCH_CONFIG_MAIN
#include <catch2/catch.hpp> #include <catch2/catch.hpp>
unsigned int Factorial( unsigned int number ) { int Factorial( int number ) {
return number > 1 ? Factorial(number-1)*number : 1; return number <= 1 ? 1 : Factorial( number - 1 ) * number;
} }
TEST_CASE( "Factorials are computed", "[factorial]" ) { TEST_CASE( "Factorial Tests", "[single-file]" ) {
REQUIRE( Factorial(0) == 1 ); REQUIRE( Factorial(0) == 1 );
REQUIRE( Factorial(1) == 1 ); REQUIRE( Factorial(1) == 1 );
REQUIRE( Factorial(2) == 2 ); REQUIRE( Factorial(2) == 2 );
......
...@@ -27,3 +27,4 @@ Build ...@@ -27,3 +27,4 @@ Build
.vs .vs
cmake-build-* cmake-build-*
benchmark-dir benchmark-dir
.conan/test_package/build
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
[subrepo] [subrepo]
remote = git@github.com:catchorg/Catch2.git remote = git@github.com:catchorg/Catch2.git
branch = master branch = master
commit = 489a41012e396868954a3e9ee39de26fa432ab44 commit = 4902cd721586822ded795afe0c418c553137306a
parent = f63d70305b7e15f11e33e2ac1b291e870f830bbc parent = ee2eaf8ae00c09a6eaa3de857f27d607a3e6511c
cmdver = 0.4.0 cmdver = 0.4.0
method = merge method = merge
language: cpp language: cpp
sudo: false
branches: branches:
except: except:
...@@ -271,6 +270,19 @@ matrix: ...@@ -271,6 +270,19 @@ matrix:
packages: ['clang-6.0', 'libstdc++-8-dev'] packages: ['clang-6.0', 'libstdc++-8-dev']
env: COMPILER='clang++-6.0' CPP17=1 EXAMPLES=1 COVERAGE=1 EXTRAS=1 env: COMPILER='clang++-6.0' CPP17=1 EXAMPLES=1 COVERAGE=1 EXTRAS=1
# 8/ Conan
- language: python
python:
- "3.7"
dist: xenial
install:
- pip install conan conan-package-tools
env:
- CONAN_GCC_VERSIONS=8
- CONAN_DOCKER_IMAGE=conanio/gcc8
script:
- python .conan/build.py
install: install:
- DEPS_DIR="${TRAVIS_BUILD_DIR}/deps" - DEPS_DIR="${TRAVIS_BUILD_DIR}/deps"
- mkdir -p ${DEPS_DIR} && cd ${DEPS_DIR} - mkdir -p ${DEPS_DIR} && cd ${DEPS_DIR}
......
...@@ -6,7 +6,7 @@ if(NOT DEFINED PROJECT_NAME) ...@@ -6,7 +6,7 @@ if(NOT DEFINED PROJECT_NAME)
set(NOT_SUBPROJECT ON) set(NOT_SUBPROJECT ON)
endif() endif()
project(Catch2 LANGUAGES CXX VERSION 2.4.2) project(Catch2 LANGUAGES CXX VERSION 2.5.0)
# Provide path for scripts # Provide path for scripts
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/CMake") list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/CMake")
......
...@@ -5,11 +5,11 @@ ...@@ -5,11 +5,11 @@
[![Build Status](https://travis-ci.org/catchorg/Catch2.svg?branch=master)](https://travis-ci.org/catchorg/Catch2) [![Build Status](https://travis-ci.org/catchorg/Catch2.svg?branch=master)](https://travis-ci.org/catchorg/Catch2)
[![Build status](https://ci.appveyor.com/api/projects/status/github/catchorg/Catch2?svg=true)](https://ci.appveyor.com/project/catchorg/catch2) [![Build status](https://ci.appveyor.com/api/projects/status/github/catchorg/Catch2?svg=true)](https://ci.appveyor.com/project/catchorg/catch2)
[![codecov](https://codecov.io/gh/catchorg/Catch2/branch/master/graph/badge.svg)](https://codecov.io/gh/catchorg/Catch2) [![codecov](https://codecov.io/gh/catchorg/Catch2/branch/master/graph/badge.svg)](https://codecov.io/gh/catchorg/Catch2)
[![Try online](https://img.shields.io/badge/try-online-blue.svg)](https://wandbox.org/permlink/rbkudthN4hBNJznk) [![Try online](https://img.shields.io/badge/try-online-blue.svg)](https://wandbox.org/permlink/7lDqHmzKQxA2eaM0)
[![Join the chat in Discord: https://discord.gg/4CWS9zD](https://img.shields.io/badge/Discord-Chat!-brightgreen.svg)](https://discord.gg/4CWS9zD) [![Join the chat in Discord: https://discord.gg/4CWS9zD](https://img.shields.io/badge/Discord-Chat!-brightgreen.svg)](https://discord.gg/4CWS9zD)
<a href="https://github.com/catchorg/Catch2/releases/download/v2.4.2/catch.hpp">The latest version of the single header can be downloaded directly using this link</a> <a href="https://github.com/catchorg/Catch2/releases/download/v2.5.0/catch.hpp">The latest version of the single header can be downloaded directly using this link</a>
## Catch2 is released! ## Catch2 is released!
......
...@@ -3,19 +3,15 @@ from conans import ConanFile, CMake ...@@ -3,19 +3,15 @@ from conans import ConanFile, CMake
class CatchConan(ConanFile): class CatchConan(ConanFile):
name = "Catch" name = "Catch2"
version = "2.4.2"
description = "A modern, C++-native, header-only, framework for unit-tests, TDD and BDD" description = "A modern, C++-native, header-only, framework for unit-tests, TDD and BDD"
author = "philsquared" topics = ("conan", "catch2", "header-only", "unit-test", "tdd", "bdd")
generators = "cmake"
# Only needed until conan 1.5 is released
settings = "compiler", "arch"
exports_sources = "single_include/*", "CMakeLists.txt", "CMake/catch2.pc.in", "LICENSE.txt"
url = "https://github.com/catchorg/Catch2" url = "https://github.com/catchorg/Catch2"
license = "Boost Software License - Version 1.0. http://www.boost.org/LICENSE_1_0.txt" homepage = url
license = "BSL-1.0"
def build(self): exports = "LICENSE.txt"
pass exports_sources = ("single_include/*", "CMakeLists.txt", "CMake/*", "contrib/*")
generators = "cmake"
def package(self): def package(self):
cmake = CMake(self) cmake = CMake(self)
......
...@@ -36,3 +36,4 @@ Other: ...@@ -36,3 +36,4 @@ Other:
* [Open Source Projects using Catch](opensource-users.md#top) * [Open Source Projects using Catch](opensource-users.md#top)
* [Contributing](contributing.md#top) * [Contributing](contributing.md#top)
* [Release Notes](release-notes.md#top) * [Release Notes](release-notes.md#top)
* [Deprecations and incoming changes](deprecations.md#top)
<a id="top"></a>
# Deprecations and incoming changes
This page documents current deprecations and upcoming planned changes
inside Catch2. The difference between these is that a deprecated feature
will be removed, while a planned change to a feature means that the
feature will behave differently, but will still be present. Obviously,
either of these is a breaking change, and thus will not happen until
at least the next major release.
## Deprecations
### `--list-*` return values
The return codes of the `--list-*` family of command line arguments
will no longer be equal to the number of tests/tags/etc found, instead
it will be 0 for success and non-zero for failure.
### `--list-test-names-only`
`--list-test-names-only` command line argument will be removed.
### `ANON_TEST_CASE`
`ANON_TEST_CASE` is scheduled for removal, as it can be fully replaced
by a `TEST_CASE` with no arguments.
### Secondary description amongst tags
Currently, the tags part of `TEST_CASE` (and others) macro can also
contain text that is not part of tags. This text is then separated into
a "description" of the test case, but the description is then never used
apart from writing it out for `--list-tests -v high`.
Because it isn't actually used nor documented, and brings complications
to Catch2's internals, description support will be removed.
## Planned changes
### Reporter verbosities
The current implementation of verbosities, where the reporter is checked
up-front whether it supports the requested verbosity, is fundamentally
misguided and will be changed. The new implementation will no longer check
whether the specified reporter supports the requested verbosity, instead
it will be up to the reporters to deal with verbosities as they see fit
(with an expectation that unsupported verbosities will be, at most,
warnings, but not errors).
### Output format of `--list-*` command line parameters
The various list operations will be piped through reporters. This means
that e.g. XML reporter will write the output as machine-parseable XML,
while the Console reporter will keep the current, human-oriented output.
### `CHECKED_IF` and `CHECKED_ELSE`
To make the `CHECKED_IF` and `CHECKED_ELSE` macros more useful, they will
be marked as "OK to fail" (`Catch::ResultDisposition::SuppressFail` flag
will be added), which means that their failure will not fail the test,
making the `else` actually useful.
### Change semantics of `[.]` and tag exclusion
Currently, given these 2 tests
```cpp
TEST_CASE("A", "[.][foo]") {}
TEST_CASE("B", "[.][bar]") {}
```
specifying `[foo]` as the testspec will run test "A" and specifying
`~[foo]` will run test "B", even though it is hidden. Also, specifying
`~[baz]` will run both tests. This behaviour is often surprising and will
be changed so that hidden tests are included in a run only if they
positively match a testspec.
---
[Home](Readme.md#top)
...@@ -57,20 +57,37 @@ The message is reported and the test case fails. ...@@ -57,20 +57,37 @@ 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
**CAPTURE(** _expression_ **)** **CAPTURE(** _expression1_, _expression2_, ... **)**
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. e.g. `CAPTURE( theAnswer );` will log message "theAnswer := 42", while
```c++ ```cpp
CAPTURE( theAnswer ); 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: 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}) );`
<pre>"theAnswer := 42"</pre>
--- ---
......
...@@ -32,6 +32,9 @@ A, single-header-only, type-safe, command line parser - which also prints format ...@@ -32,6 +32,9 @@ A, single-header-only, type-safe, command line parser - which also prints format
### [Couchbase-lite-core](https://github.com/couchbase/couchbase-lite-core) ### [Couchbase-lite-core](https://github.com/couchbase/couchbase-lite-core)
The next-generation core storage and query engine for Couchbase Lite The next-generation core storage and query engine for Couchbase Lite
### [cppcodec](https://github.com/tplgy/cppcodec)
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.
### [DtCraft](https://github.com/twhuang-uiuc/DtCraft) ### [DtCraft](https://github.com/twhuang-uiuc/DtCraft)
A High-performance Cluster Computing Engine A High-performance Cluster Computing Engine
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
# Release notes # Release notes
**Contents**<br> **Contents**<br>
[2.5.0](#250)<br>
[2.4.2](#242)<br> [2.4.2](#242)<br>
[2.4.1](#241)<br> [2.4.1](#241)<br>
[2.4.0](#240)<br> [2.4.0](#240)<br>
...@@ -17,6 +18,27 @@ ...@@ -17,6 +18,27 @@
[Older versions](#older-versions)<br> [Older versions](#older-versions)<br>
[Even Older versions](#even-older-versions)<br> [Even Older versions](#even-older-versions)<br>
## 2.5.0
### Improvements
* Added support for templated tests via `TEMPLATE_TEST_CASE` (#1437)
### Fixes
* Fixed compilation of `PredicateMatcher<const char*>` by removing partial specialization of `MatcherMethod<T*>`
* Listeners now implicitly support any verbosity (#1426)
* Fixed compilation with Embarcadero builder by introducing `Catch::isnan` polyfill (#1438)
* Fixed `CAPTURE` asserting for non-trivial captures (#1436, #1448)
### Miscellaneous
* We should now be providing first party Conan support via https://bintray.com/catchorg/Catch2 (#1443)
* Added new section "deprecations and planned changes" to the documentation
* It contains summary of what is deprecated and might change with next major version
* From this release forward, the released headers should be pgp signed (#430)
* KeyID `E29C 46F3 B8A7 5028 6079 3B7D ECC9 C20E 314B 2360`
* or https://codingnest.com/files/horenmar-publickey.asc
## 2.4.2 ## 2.4.2
......
...@@ -8,11 +8,11 @@ When enough changes have accumulated, it is time to release new version of Catch ...@@ -8,11 +8,11 @@ When enough changes have accumulated, it is time to release new version of Catch
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. 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>`. 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
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. proceed.
### Incrementing version number ### Incrementing version number
...@@ -27,7 +27,7 @@ version numbers everywhere and pushing the new version to Wandbox. ...@@ -27,7 +27,7 @@ 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
...@@ -43,11 +43,8 @@ description should contain the release notes for the current release. ...@@ -43,11 +43,8 @@ description should contain the release notes for the current release.
Single header version of `catch.hpp` *needs* to be attached as a binary, Single header version of `catch.hpp` *needs* to be attached as a binary,
as that is where the official download link links to. Preferably as that is where the official download link links to. Preferably
it should use linux line endings. All non-bundled reporters (Automake, it should use linux line endings. All non-bundled reporters (Automake,
TAP, TeamCity) should also be attached as binaries, as they are dependent TAP, TeamCity) should also be attached as binaries, as they might be
on a specific version of the single-include header. dependent on a specific version of the single-include header.
## Optional steps
Because Catch's [vcpkg](https://github.com/Microsoft/vcpkg) port updates Since 2.5.0, the release tag and the "binaries" (headers) should be PGP
itself automagically, there are no optional steps at this time. signed.
<a id="top"></a> <a id="top"></a>
# Test cases and sections # Test cases and sections
**Contents**<br>
[Tags](#tags)<br>
[Tag aliases](#tag-aliases)<br>
[BDD-style test cases](#bdd-style-test-cases)<br>
[Type parametrised test cases](#type-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).
...@@ -86,6 +92,65 @@ When any of these macros are used the console reporter recognises them and forma ...@@ -86,6 +92,65 @@ When any of these macros are used the console reporter recognises them and forma
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 type, in the form of `TEMPLATE_TEST_CASE`.
* **TEMPLATE_TEST_CASE(** _test name_ , _tags_, _type1_, _type2_, ..., _typen_ **)**
_test name_ and _tag_ are exactly the same as they are in `TEST_CASE`,
with the difference that the tag string must be provided (however, it
can be empty). _type1_ through _typen_ is the list of types for which
this test case should run, and, inside the test code, the current type
is available as the `TestType` type.
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>)`.
Example:
```cpp
TEMPLATE_TEST_CASE( "vectors can be sized and resized", "[vector][template]", int, std::string, (std::tuple<int,float>) ) {
std::vector<TestType> v( 5 );
REQUIRE( v.size() == 5 );
REQUIRE( v.capacity() >= 5 );
SECTION( "resizing bigger changes size and capacity" ) {
v.resize( 10 );
REQUIRE( v.size() == 10 );
REQUIRE( v.capacity() >= 10 );
}
SECTION( "resizing smaller changes size but not capacity" ) {
v.resize( 0 );
REQUIRE( v.size() == 0 );
REQUIRE( v.capacity() >= 5 );
SECTION( "We can use the 'swap trick' to reset the capacity" ) {
std::vector<TestType> empty;
empty.swap( v );
REQUIRE( v.capacity() == 0 );
}
}
SECTION( "reserving smaller does not change size or capacity" ) {
v.reserve( 0 );
REQUIRE( v.size() == 5 );
REQUIRE( v.capacity() >= 5 );
}
}
```
_While there is an upper limit on the number of types you can specify
in single `TEMPLATE_TEST_CASE`, the limit is very high and should not
be encountered in practice._
--- ---
[Home](Readme.md#top) [Home](Readme.md#top)
...@@ -30,6 +30,36 @@ class UniqueTestsFixture { ...@@ -30,6 +30,36 @@ 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` that can be used together
with templated fixtures to perform tests for multiple different types.
However, unlike `TEST_CASE_METHOD`, `TEMPLATE_TEST_CASE_METHOD` requires
the tag specification to be non-empty, as it is followed by further macros
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>)`.
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) {
REQUIRE( Template_Fixture<TestType>::m_a == 1 );
}
```
_While there is an upper limit on the number of types you can specify
in single `TEMPLATE_TEST_CASE`, the limit is very high and should not
be encountered in practice._
--- ---
[Home](Readme.md#top) [Home](Readme.md#top)
...@@ -23,7 +23,7 @@ std::ostream& operator << ( std::ostream& os, T const& value ) { ...@@ -23,7 +23,7 @@ std::ostream& operator << ( std::ostream& os, T const& value ) {
(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 have it declared before including Catch's header. 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.
## Catch::StringMaker specialisation ## 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>`: 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>`:
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
[Test cases and sections](#test-cases-and-sections)<br> [Test cases and sections](#test-cases-and-sections)<br>
[BDD-Style](#bdd-style)<br> [BDD-Style](#bdd-style)<br>
[Scaling up](#scaling-up)<br> [Scaling up](#scaling-up)<br>
[Type parametrised test cases](#type-parametrised-test-cases)<br>
[Next steps](#next-steps)<br> [Next steps](#next-steps)<br>
## Getting Catch2 ## Getting Catch2
...@@ -256,6 +257,16 @@ In fact it is usually a good idea to put the block with the ```#define``` [in it ...@@ -256,6 +257,16 @@ In fact it is usually a good idea to put the block with the ```#define``` [in it
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` macro, which behaves in the same way the `TEST_CASE`
macro, but is run for every type.
For more details, see our documentation on [test cases and
sections](test-cases-and-sections.md#type-parametrised-test-cases).
## Next steps ## Next steps
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.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment