Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type parametrised test cases v2 #1437

Merged
merged 2 commits into from
Nov 16, 2018
Merged

Type parametrised test cases v2 #1437

merged 2 commits into from
Nov 16, 2018

Conversation

JoeyGrajciar
Copy link
Contributor

@JoeyGrajciar JoeyGrajciar commented Nov 8, 2018

Description

This PR adds the support, docs and some unit tests for type parametrised test cases. This implementation supports arbitrary count of types.

Introduces TEMPLATE_TEST_CASE and TEMPLATE_TEST_CASE_METHOD macros. Usage of these macros is very similar to TEST_CASE and TEST_CASE_METHOD. Difference is that name and description (even empty string) is required as types for test are specified at the end.

Example:

struct Bar {}; 

TEMPLATE_TEST_CASE("Templated test","",int,float, std::string, Bar)
{
    std::vector<TestType> v( 5 );
    REQUIRE( v.size() == 5 );
    REQUIRE( v.capacity() >= 5 );
}

template<typename T>
struct TemplateFixture
{
    TemplateFixture() : m_a( 1 ) {}

    int m_a;
}

TEMPLATE_TEST_CASE_METHOD(TemplateFixture,
    "A TEMPLATE_TEST_CASE_METHOD based test run that fails", 
    "[.][class][template][failing]", int, float, double)
{
        REQUIRE( TemplateFixture<TestType>::m_a == 2 );
}

Difference to #1425 is that now there will test invoker registered for each type specified. Former PR added one test invoker with multiple sections for each type, calling the templated test function with type.

Implementation of these test cases was heavily inspired by Doctest.

GitHub Issues

#46 #357 #850 ...

@codecov
Copy link

codecov bot commented Nov 9, 2018

Codecov Report

Merging #1437 into master will decrease coverage by 0.03%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##           master    #1437      +/-   ##
==========================================
- Coverage   80.31%   80.28%   -0.03%     
==========================================
  Files         120      120              
  Lines        3403     3403              
==========================================
- Hits         2733     2732       -1     
- Misses        670      671       +1

@myrgy
Copy link

myrgy commented Nov 13, 2018

Is there any progress with that PR?
Is it going to be merged?
Thanks

@JoeyGrajciar
Copy link
Contributor Author

@myrgy after some minor improvements it is now waiting on review :) please be patient :) feel free to pull locally these changes and do some tests with it and share your opinions about it :)

Copy link
Member

@horenmar horenmar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is first set of notes, I still have to dive into the macro hell.

docs/test-cases-and-sections.md Outdated Show resolved Hide resolved
docs/tutorial.md Outdated Show resolved Hide resolved
docs/tutorial.md Outdated Show resolved Hide resolved
include/internal/catch_compiler_capabilities.h Outdated Show resolved Hide resolved
include/internal/catch_test_registry.h Outdated Show resolved Hide resolved
Copy link
Member

@horenmar horenmar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found only two, small, nitpicks in the implementation itself. Not sure if it means that I don't understand the preprocessor enough, or that there were only these two. 😃

I'll check the modified documentation tomorrow.

include/internal/catch_test_registry.h Show resolved Hide resolved
include/internal/catch_test_registry.h Outdated Show resolved Hide resolved
JoeyGrajciar and others added 2 commits November 16, 2018 21:21
This adds support for templated tests and test methods via
`TEMPLATE_TEST_CASE` and `TEMPLATE_TEST_CASE_METHOD` macros. These
work mostly just like their regular counterparts*, but take an
unlimited** number of types as their last arguments.

* Unlike the plain `TEST_CASE*` macros, the `TEMPLATE*` variants
require a tag string.

** In practice there is limit of about 300 types.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants