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

Add an example of using GENERATE(table()) #1963

Merged
merged 1 commit into from
Jun 23, 2020

Conversation

richardash1981
Copy link

Description

There are some examples on issue #850 of using this feature, but they are not easily found from the documentation. Adding them here as an example makes them more findable and ensures they keep working if the API changes.

GitHub Issues

@richardash1981
Copy link
Author

That's weird. It failed on the AMD 64 / Linux / Xenial COMPILER='clang++-3.8' EXAMPLES=1 COVERAGE=1 EXTRAS=1 run in Travis.
That's fair enough in that my tests were AMD 64 / Linux / GCC 9.3.0.
Clang versions are confusing me, because the one I have available is clang++ 9.0.1. Clang 3.8 is a really old version by now?

This is the error compiling the example

[ 26%] Building CXX object examples/CMakeFiles/302-Gen-Table.dir/302-Gen-Table.cpp.o
/home/travis/build/catchorg/Catch2/examples/302-Gen-Table.cpp:31:59: error: no
      matching function for call to 'table'
  ...expected_output) = GENERATE( table<std::string, size_t>({
                                  ^~~~~~~~~~~~~~~~~~~~~~~~~~
/home/travis/build/catchorg/Catch2/single_include/catch2/catch.hpp:4107:97: note: 
      expanded from macro 'GENERATE'
  ...namespace Catch::Generators; return makeGenerators( __VA_ARGS__ ); } ) /...
                                                         ^~~~~~~~~~~
/home/travis/build/catchorg/Catch2/single_include/catch2/catch.hpp:4058:41: note: 
      candidate function [with Ts = <std::__cxx11::basic_string<char>, unsigned
      long>] not viable: cannot convert initializer list argument to
      'std::tuple<std::__cxx11::basic_string<char>, unsigned long>'
    GeneratorWrapper<std::tuple<Ts...>> table( std::initializer_list<std...
                                        ^
/home/travis/build/catchorg/Catch2/examples/302-Gen-Table.cpp:31:49: error: no
      matching function for call to 'generate'
  ...expected_output) = GENERATE( table<std::string, size_t>({
                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/travis/build/catchorg/Catch2/single_include/catch2/catch.hpp:4105:5: note: 
      expanded from macro 'GENERATE'
    Catch::Generators::generate( INTERNAL_CATCH_STRINGIZE(INTERNAL_CATCH...
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/travis/build/catchorg/Catch2/single_include/catch2/catch.hpp:4089:10: note: 
      candidate template ignored: substitution failure [with L = (lambda at
      /home/travis/build/catchorg/Catch2/examples/302-Gen-Table.cpp:31:49)]:
      member reference base type 'typename add_rvalue_reference<void>::type'
      (aka 'void') is not a structure or union
  ...generate( StringRef generatorName, SourceLineInfo const& lineInfo, L const& generatorExpression ) -> decltype(std::declval<decltype(generatorExpression())>()....
     ^                                                                                                                                                            ~
2 errors generated.

I'm guessing that "cannot convert initializer list argument to 'std::tuple<std::__cxx11::basic_string<char>, unsigned long>'" is the important error here, the rest will go away if that did not occur. However I can't find any other configuration of { which will compile with my current compilers ...

@horenmar
Copy link
Member

At a glance, this is likely the same problem as described in Generators.tests.cpp line 34 and below.

Also please avoid tabs (CMakeLists.txt for examples)

@richardash1981
Copy link
Author

Thanks for the pointers. Hopefully this version will build on all targets ...

@codecov
Copy link

codecov bot commented Jun 22, 2020

Codecov Report

Merging #1963 into master will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##           master    #1963   +/-   ##
=======================================
  Coverage   88.59%   88.59%           
=======================================
  Files         138      138           
  Lines        5619     5619           
=======================================
  Hits         4978     4978           
  Misses        641      641           

There are some examples on issue catchorg#850 of using this feature, but they
are not easily found from the documentation. Adding them here as an
example makes them more findable and ensures they keep working if the
API changes.
@horenmar horenmar merged commit ad1940f into catchorg:master Jun 23, 2020
@richardash1981
Copy link
Author

Thank you for the merge!
Was the re-format done by an automated tool or manually? In other words is there something I should have done to the code before pushing, or a coding standard I should have followed? Ah, #1182. I need to learn about using clang-tidy ...

@horenmar
Copy link
Member

Both. Clang-format was just introduced, and I am still experimenting with the settings, so I sometimes override it manually.

I also updated the contributing docs to mention clang-format.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants