web-dev-qa-db-fra.com

Test Google dans Visual Studio 2012

J'essaie de commencer avec les tests unitaires. J'ai téléchargé la dernière version de gtest et l'ai extraite dans A:\gtest Comme indiqué dans les instructions, j'ai ouvert gtest.sln. Visual studio ne me permet d'ouvrir le sln que si j'accepte de le mettre à jour. Ensuite, quand j'essaye de construire, j'obtiens une pile d'erreurs:

1>------ Build started: Project: gtest, Configuration: Debug Win32 ------
1>  gtest-all.cc
1>a:\gtest\include\gtest\gtest-printers.h(550): error C2977: 'std::Tuple' : too many template arguments
1>          b:\program files (x86)\Microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::Tuple'
1>a:\gtest\include\gtest\gtest-printers.h(558): error C2977: 'std::Tuple' : too many template arguments
1>          b:\program files (x86)\Microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::Tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4017): error C2977: 'std::Tuple' : too many template arguments
1>          b:\program files (x86)\Microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::Tuple'
1>          a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4249) : see reference to class template instantiation 'testing::internal::CartesianProductGenerator9<T1,T2,T3,T4,T5,T6,T7,T8,T9>' being compiled
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4017): error C3203: 'Tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4017): error C2955: 'std::Tuple' : use of class template requires template argument list
1>          b:\program files (x86)\Microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::Tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4017): error C2955: 'testing::internal::ParamGeneratorInterface' : use of class template requires template argument list
1>          a:\gtest\include\gtest\internal\gtest-param-util.h(142) : see declaration of 'testing::internal::ParamGeneratorInterface'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4019): error C2977: 'std::Tuple' : too many template arguments
1>          b:\program files (x86)\Microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::Tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4030): error C3203: 'Tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4030): error C2955: 'std::Tuple' : use of class template requires template argument list
1>          b:\program files (x86)\Microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::Tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4035): error C3203: 'Tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4035): error C2955: 'std::Tuple' : use of class template requires template argument list
1>          b:\program files (x86)\Microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::Tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4042): error C3203: 'Tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
1>          a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4042) : see reference to class template instantiation 'testing::internal::CartesianProductGenerator9<T1,T2,T3,T4,T5,T6,T7,T8,T9>::Iterator' being compiled
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4042): error C2955: 'std::Tuple' : use of class template requires template argument list
1>          b:\program files (x86)\Microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::Tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4042): error C2955: 'testing::internal::ParamIteratorInterface' : use of class template requires template argument list
1>          a:\gtest\include\gtest\internal\gtest-param-util.h(69) : see declaration of 'testing::internal::ParamIteratorInterface'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4044): error C3203: 'Tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4044): error C2955: 'std::Tuple' : use of class template requires template argument list
1>          b:\program files (x86)\Microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::Tuple'
1>          b:\program files (x86)\Microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::Tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4077): error C3203: 'Tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4077): error C2955: 'std::Tuple' : use of class template requires template argument list
1>          b:\program files (x86)\Microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::Tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4119): error C3203: 'Tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4119): error C2955: 'std::Tuple' : use of class template requires template argument list
1>          b:\program files (x86)\Microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::Tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4123): error C3203: 'Tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4123): error C2955: 'std::Tuple' : use of class template requires template argument list
1>          b:\program files (x86)\Microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::Tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4204): error C3203: 'Tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4204): error C2955: 'std::Tuple' : use of class template requires template argument list
1>          b:\program files (x86)\Microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::Tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4256): error C2977: 'std::Tuple' : too many template arguments
1>          b:\program files (x86)\Microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::Tuple'
1>          a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4505) : see reference to class template instantiation 'testing::internal::CartesianProductGenerator10<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10>' being compiled
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4256): error C3203: 'Tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4256): error C2955: 'std::Tuple' : use of class template requires template argument list
1>          b:\program files (x86)\Microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::Tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4256): error C2955: 'testing::internal::ParamGeneratorInterface' : use of class template requires template argument list
1>          a:\gtest\include\gtest\internal\gtest-param-util.h(142) : see declaration of 'testing::internal::ParamGeneratorInterface'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4258): error C2977: 'std::Tuple' : too many template arguments
1>          b:\program files (x86)\Microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::Tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4270): error C3203: 'Tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4270): error C2955: 'std::Tuple' : use of class template requires template argument list
1>          b:\program files (x86)\Microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::Tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4275): error C3203: 'Tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4275): error C2955: 'std::Tuple' : use of class template requires template argument list
1>          b:\program files (x86)\Microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::Tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4282): error C3203: 'Tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
1>          a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4282) : see reference to class template instantiation 'testing::internal::CartesianProductGenerator10<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10>::Iterator' being compiled
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4282): error C2955: 'std::Tuple' : use of class template requires template argument list
1>          b:\program files (x86)\Microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::Tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4282): error C2955: 'testing::internal::ParamIteratorInterface' : use of class template requires template argument list
1>          a:\gtest\include\gtest\internal\gtest-param-util.h(69) : see declaration of 'testing::internal::ParamIteratorInterface'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4284): error C3203: 'Tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4284): error C2955: 'std::Tuple' : use of class template requires template argument list
1>          b:\program files (x86)\Microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::Tuple'
1>          b:\program files (x86)\Microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::Tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4320): error C3203: 'Tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4320): error C2955: 'std::Tuple' : use of class template requires template argument list
1>          b:\program files (x86)\Microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::Tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4366): error C3203: 'Tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4366): error C2955: 'std::Tuple' : use of class template requires template argument list
1>          b:\program files (x86)\Microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::Tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4370): error C3203: 'Tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4370): error C2955: 'std::Tuple' : use of class template requires template argument list
1>          b:\program files (x86)\Microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::Tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4456): error C3203: 'Tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4456): error C2955: 'std::Tuple' : use of class template requires template argument list
1>          b:\program files (x86)\Microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::Tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4738): error C2977: 'std::Tuple' : too many template arguments
1>          b:\program files (x86)\Microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::Tuple'
1>          a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4766) : see reference to class template instantiation 'testing::internal::CartesianProductHolder9<Generator1,Generator2,Generator3,Generator4,Generator5,Generator6,Generator7,Generator8,Generator9>' being compiled
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4738): error C3203: 'Tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4738): error C2955: 'std::Tuple' : use of class template requires template argument list
1>          b:\program files (x86)\Microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::Tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4782): error C2977: 'std::Tuple' : too many template arguments
1>          b:\program files (x86)\Microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::Tuple'
1>          a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4813) : see reference to class template instantiation 'testing::internal::CartesianProductHolder10<Generator1,Generator2,Generator3,Generator4,Generator5,Generator6,Generator7,Generator8,Generator9,Generator10>' being compiled
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4782): error C3203: 'Tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4782): error C2955: 'std::Tuple' : use of class template requires template argument list
1>          b:\program files (x86)\Microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::Tuple'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Suis-je en train de faire quelque chose de mal ou est-ce un problème avec VS2012? Je ne suis pas attaché au test google et ne suis pas opposé à l'utilisation d'un framework différent s'il fonctionne mieux avec VS, je venais d'entendre de très bonnes choses sur gtest.

55
user1599559

VC++ 2012 ne prend pas (et ne prendra jamais) en charge les modèles variadic; par conséquent, son implémentation de bibliothèque standard tente de les simuler en utilisant des surcharges et des spécialisations générées par le préprocesseur. Comme ce billet de blog note, le nombre de paramètres de modèle de faux variadic est par défaut de 5 - le problème est que gtest essaie d'instancier std::Tuple<> avec jusqu'à 10 arguments de modèle.

Comme le blog le mentionne, vous pouvez définir le _VARIADIC_MAX macro à l'échelle du projet pour prendre en charge jusqu'à 10 paramètres; vous voudrez probablement le faire à l'aide du paramètre définitions du préprocesseur de votre projet, mais l'important est de vous assurer que chaque TU le définit avant d'inclure les en-têtes stdlib (directement ou indirectement).

78
ildjarn

Plutôt que de modifier l'implémentation du tuple VS2012 à l'aide de _VARIADIC_MAX macro, j'ai résolu ce problème en définissant les deux macros suivantes sur les projets gtest et les projets incluant les en-têtes gtest:

GTEST_HAS_TR1_Tuple=0
GTEST_USE_OWN_TR1_Tuple=1

Réglage GTEST_HAS_TR1_Tuple à 0 empêche gtest d'essayer d'utiliser la classe Tuple à partir des en-têtes STL et de définir GTEST_USE_OWN_TR1_Tuple to 1 indique à gtest d'utiliser sa propre implémentation de Tuple plutôt que d'omettre les fonctionnalités qui nécessitent la prise en charge de Tuple. Personnellement, j'ai préféré cette option à peaufiner l'implémentation STL, et cette solution devrait fonctionner sur tous les autres compilateurs qui ont des problèmes similaires.

8
Roger Sanders

Ceci est corrigé dans la version r675. Voir https://code.google.com/p/googletest/source/detail?r=675

6
Corey Kosak

De plus, jusqu'à ce que vous obteniez la dernière version, ajoutez GTEST_USE_OWN_TR1_Tuple=0 à vos définitions de pré-processeur.

1
Brad W