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 je l’ai extraite dans A:\gtest Comme A:\gtest dans les instructions, j’ai ouvert gtest.sln. Visual Studio ne me permet d’ouvrir la sln que si j’accepte de le mettre à jour. Alors quand j’essaye de construire, je reçois un tas 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' being comstackd 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::Iterator' being comstackd 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' being comstackd 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::Iterator' being comstackd 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' being comstackd 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' being comstackd 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 ========== 

Est-ce que je fais quelque chose de mal ou s’agit-il d’un problème avec VS2012? Je ne suis pas attaché à google test et je ne suis pas opposé à l’utilisation d’un framework différent si cela fonctionne mieux avec VS, je venais d’entendre de très bonnes choses à propos de gtest.

VC ++ 2012 ne supporte pas (et ne supportera jamais) les modèles variadiques; 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 le note ce billet de blog , le nombre de parameters de modèle de variadic faux est 5 par défaut – le problème est que gtest tente d’instancier std::tuple<> avec jusqu’à 10 arguments de modèle.

Comme le _VARIADIC_MAX du blog continue, vous pouvez définir la macro _VARIADIC_MAX l’ _VARIADIC_MAX projet pour prendre en charge jusqu’à 10 parameters; Vous voudrez probablement le faire par le biais du paramètre de définitions de préprocesseur de votre projet, mais l’important est de vous assurer que chaque UT le définit avant d’inclure des en-têtes stdlib (directement ou indirectement).

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

 GTEST_HAS_TR1_TUPLE=0 GTEST_USE_OWN_TR1_TUPLE=1 

Définir GTEST_HAS_TR1_TUPLE sur 0 empêche gtest d’essayer d’utiliser la classe tuple à partir des en-têtes STL, et la définition de GTEST_USE_OWN_TR1_TUPLE sur 1 indique à gtest d’utiliser sa propre implémentation plutôt que d’omettre les fonctionnalités nécessitant le support 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.

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

En outre, jusqu’à ce que vous obteniez la dernière version, ajoutez GTEST_USE_OWN_TR1_TUPLE=0 à vos définitions de préprocesseur.