cmake error when building Boost unit tests - c++

I'm working through this tutorial, using VS2012 on a c++ project generated by cmake 3.0.2.
http://help.exercism.io/getting-started-with-cpp.html
I have a series of boost unit tests that check whether the correct message is returned when given an input. Most of the tests work, but strangely, some cause a build error.
Error 1 error MSB3073: The command "setlocal
Debug\bob.exe
if %errorlevel% neq 0 goto :cmEnd
:cmEnd
endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone
:cmErrorLevel
exit /b %1
:cmDone
if %errorlevel% neq 0 goto :VCEnd
:VCEnd" exited with code 201. C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Microsoft.CppCommon.targets 134 5 bob
//bob.h
#ifndef BOB_H
#define BOB_H
#include <istream>
class bob
{
public:
static char* hey(char*);
};
#endif
//bob.cpp
#include "bob.h"
char* bob::hey(char * msg)
{
//if (!msg){return "";}
int msgLength = strlen(msg);
switch (msg[msgLength-1])
{
case '?':
return "Sure.";
break;
case '!':
return "Whoa, chill out!";
break;
case ' ':
case '\0':
return "Fine. Be that way!";
default:
break;
}
return "Whatever.";
}
//bob_test.cpp
#include "bob.h"
#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_CASE(stating_something)
{
BOOST_REQUIRE_EQUAL("Whatever.", bob::hey("Tom-ay-to, tom-aaaah-to."));
}
#if defined(EXERCISM_RUN_ALL_TESTS)
BOOST_AUTO_TEST_CASE(shouting)
{
BOOST_REQUIRE_EQUAL("Whoa, chill out!", bob::hey("WATCH OUT!"));
}
BOOST_AUTO_TEST_CASE(asking_a_question)
{
BOOST_REQUIRE_EQUAL("Sure.", bob::hey("Does this cryogenic chamber make me look fat?"));
}
/////////////This test causes the error
//BOOST_AUTO_TEST_CASE(talking_forcefully)
//{
// BOOST_REQUIRE_EQUAL("Whatever.", bob::hey("Let's go make out behind the gym!"));
//}

It looks like boost tests are working like they should. I needed to check the output window rather than look at build errors.
1>------ Build started: Project: bob, Configuration: Debug Win32 ------
1> bob_test.cpp
1> bob.vcxproj -> C:\exercism\cpp\build\Debug\bob.exe
1> Running 13 test cases...
1> C:/exercism/cpp/bob/bob_test.cpp(24): fatal error in "talking_forcefully": critical check "Whatever." == bob::hey("Let's go make out behind the gym!") failed [Whatever. != Whoa, chill out!]
1>
1> *** 1 failure detected in test suite "Master Test Suite"

Related

PerforceChangeList : error : No matching clients for root

I am syncing and building a project using jenkins with msbuild tool, but I keep getting this error everytime I run the build, either in VS or through Jenkins. I honestly have no idea what it means and I have not found any information on internet. I have another very similar project which runs fine. Any help or what to start checking it would be much appreciated as I have delete and set the job from scratch with the same result. This is the output I get from jenkins:
"C:\Users\User\.jenkins\workspace\Age_3_DE\Source\Age3DE.sln" (default target) (1) ->
"C:\Users\User\.jenkins\workspace\Age_3_DE\Source\age3\age3.vcxproj" (default target) (2) ->
(PreBuildEvent target) ->
PerforceChangeList : error : No matching clients for root=C:\Users\User\.jenkins\workspace\Age_3_DE\ [C:\Users\User\.jenkins\workspace\Age_3_DE\Source\age3\age3.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(128,5): error MSB3073: The command "C:\Users\User\.jenkins\workspace\Age_3_DE\Source\..\Scripts\PerforceChangeList.bat age3 "C:\Users\User\.jenkins\workspace\Age_3_DE\Source\age3\PerforceVersion.inc" "C:\Users\User\.jenkins\workspace\Age_3_DE\Source\age3\resource_version.h" [C:\Users\User\.jenkins\workspace\Age_3_DE\Source\age3\age3.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(128,5): error MSB3073: :VCEnd" exited with code -1. [C:\Users\User\.jenkins\workspace\Age_3_DE\Source\age3\age3.vcxproj]
27 Warning(s)
2 Error(s)
resource_version.h file:
#pragma once
#define VERSION_MAJOR 100
#define VERSION_MINOR 10
#define VERSION_BUILD 0
#define VERSION_STRING "100.10.0.0"
and PerforceVersion.inc:
#pragma once
namespace PerforceInfo {
const char* gChangeList = "00000";
const char* gVersionString = "100.10.0.0";
const char* gUserName = "";
const char* gClientName = "";
const char* gClientHost = "";
const char* gClientRoot = "";
const char* gClientStream = "";
}
Here is an image with the exactly error and the line where the error happens from VS Error

How to show Boost Test test case hierarchy in Visual Studio 2017's Test Explorer?

I have a unit test file using Boost Test, like so:
#include <boost/test/unit_test.hpp>
#include <cppx/auto/Cloner_.hpp>
#include <utility>
namespace {
struct S
{
static auto count() -> int& { static int c; return c; }
S(){ ++count(); }
S( const S& ) { ++count(); }
S( S&& ) { ++count(); }
~S() { --count(); }
};
}
BOOST_AUTO_TEST_SUITE( Cloner_ )
BOOST_AUTO_TEST_CASE( default_construction )
{
cppx::Cloner_<int> cloner1;
BOOST_TEST( cloner1.p() == nullptr );
}
BOOST_AUTO_TEST_CASE( auto_cleanup )
{
BOOST_REQUIRE( S::count() == 0 );
{
cppx::Cloner_<S> cloner1( new S );
BOOST_TEST( S::count() == 1 );
cppx::Cloner_<S> cloner2 = cloner1.clone();
BOOST_TEST( S::count() == 2 );
}
BOOST_TEST( S::count() == 0 );
}
BOOST_AUTO_TEST_SUITE_END()
My purpose with the test suite name Cloner_ is to collect all the test cases for the Cloner_ class, under a node in the Boost test cases hierarchy.
When I choose to run all tests in Visual Studio it detects this hierarchy:
[22.09.2018 06:18:37 Informational] ------ Run test started ------
[22.09.2018 06:18:39 Informational] Found test: Cloner_/auto_cleanup
[22.09.2018 06:18:39 Informational] Found test: Cloner_/default_construction
[22.09.2018 06:18:39 Informational] Executing: -> [Cloner_/auto_cleanup]
[22.09.2018 06:18:40 Informational] Executing: -> [Cloner_/default_construction]
[22.09.2018 06:18:40 Informational] ========== Run test finished: 2 run (0:00:03,1048741) ==========
However, it doesn't display the hierarchy, except that it uses the main Boost test module name cppx_tests (defined in a separate file) as root:
(Visual Studio's Test Explorer's presentation of the test cases is up to the right in the above screenshot.)
I'd like to avoid old-fashioned C style name prefixes since Boost Test does provide a means of defining a hierarchy, and since Test Explorer reports paths in that hierarchy when it searches for tests to execute, so that it apparently knows about it.
So, how can I make VS Test Explorer display the test case hierarchy for tests using Boost Test, so that I can readily identify e.g. default_construction testing of class X versus class Y or class Z, or is that not possible?

Google Test and SFML

I want to use SFML and Google test for my project. I tried to set both up in DLL mode. I was able to start the program with SFML and it works, also google test works, at least until I try to test a class from my actual project.
I use VS2013 and have structured my project(s) like that.
If I try to use a class from the "Pacman" project it fails with the following:
1>------ Rebuild All started: Project: Pacman, Configuration: Release Win32 ------
1> Main.cpp
1> TestMe.cpp
1> Generating Code...
1> .NETFramework,Version=v4.0.AssemblyAttributes.cpp
1> LINK : /LTCG specified but no code generation required; remove /LTCG from the link command line to improve linker performance
1> Pacman.vcxproj -> C:\Users\xxxx\Documents\Git\pacman\Pacman\Release\Pacman.exe
2>------ Rebuild All started: Project: Pacman_Test, Configuration: Release Win32 ------
2> Pacman_Test.cpp
2>Pacman_Test.obj : error LNK2001: unresolved external symbol "public: int __thiscall TestMe::TestMyValue(int)" (?TestMyValue#TestMe##QAEHH#Z)
2>Pacman_Test.obj : error LNK2001: unresolved external symbol "public: __thiscall TestMe::TestMe(void)" (??0TestMe##QAE#XZ)
2>C:\Users\xxx\Documents\Git\pacman\Pacman\Release\Pacman_Test.exe : fatal error LNK1120: 2 unresolved externals
========== Rebuild All: 1 succeeded, 1 failed, 0 skipped ==========
Can anyone help?
EDIT how should it help to mark it as a duplicate? I can't see where there would be duplicate declarations in my project.
EDIT2 Here is the code for the TestMe class and yes it works in the main.cpp.
#pragma once
class TestMe
{
public:
TestMe();
int TestMyValue(int val);
};
#include "TestMe.h"
TestMe::TestMe(){}
int TestMe::TestMyValue(int val){
return 0;
}
To complete the code here is the main.cpp too:
#include <iostream>
#include <SFML/Graphics.hpp>
#include "TestMe.h"
int main()
{
TestMe testMe;
std::cout << "Value:" << testMe.TestMyValue(3) << std::endl ;
sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
sf::CircleShape shape(100.f);
shape.setFillColor(sf::Color::Green);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(shape);
window.display();
}
return 0;
}

Code Analysis does not work in VS 2010 - Code Analysis Complete -- 0 error(s), 0 warning(s)

I'm trying to use Code Analysis in VS2010, but it's not working.
My sample appl:
#include "stdafx.h"
#include <malloc.h>
int getj() {
return 10;
}
int a(int *n) {
int b = *n;
int c = 1/b;
return c;
}
int _tmain(int argc, _TCHAR* argv[]) {
int *a;
a = (int *)malloc(10*sizeof(int));
if( a ) {
free( a );
a[0] = 12;
a[getj()] = 12;
}
return 0;
}
To start analysis, I using "Analyze-> Run Code Analysis on ...."
and logs :
1>------ Rebuild All started: Project: test1, Configuration: Debug Win32 ------
1>Build started 2013-07-01 17:45:40.
1>_PrepareForClean:
1> Deleting file "Debug\test1.lastbuildstate".
1>InitializeBuildStatus:
1> Creating "Debug\test1.unsuccessfulbuild" because "AlwaysCreate" was specified.
1>ClCompile:
1> stdafx.cpp
1> test1.cpp
1>Manifest:
1> Deleting file "Debug\test1.exe.embed.manifest".
1>LinkEmbedManifest:
1> test1.vcxproj -> D:\test1\Debug\test1.exe
1>RunCodeAnalysis:
1> Running Code Analysis...
1> **Code Analysis Complete -- 0 error(s), 0 warning(s)**
1>FinalizeBuildStatus:
1> Deleting file "Debug\test1.unsuccessfulbuild".
1> Touching "Debug\test1.lastbuildstate".
1>![enter image description here][1]
1>Build succeeded.
1>
1>Time Elapsed 00:00:03.40
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
Config:
On the "Property page", I have turned on:
-Enabled Code Analysis ob Build (defines....
-Enabled Code Analysis for C/C++ on Build
-Supress results from ...
-and Ruls Set ->AllRules
My question is what I'm doing wrong, or how to run code analysis in VS2010 ?
thanks

Boost tests in Visual Studio

I am trying to compile trivial unit test project in Visual Studio 2010. I have a testrunner.cpp:
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE "BaumWelch Unit Tests"
#include <boost/test/unit_test.hpp>
and exampletests.cpp
#include <boost/test/unit_test.hpp>
int add( int i, int j ) { return i+j; }
BOOST_AUTO_TEST_CASE( my_test )
{
// seven ways to detect and report the same error:
BOOST_CHECK( add( 2,2 ) == 4 ); // #1 continues on error
BOOST_REQUIRE( add( 2,2 ) == 4 ); // #2 throws on error
if( add( 2,2 ) != 4 )
BOOST_ERROR( "Ouch..." ); // #3 continues on error
if( add( 2,2 ) != 4 )
BOOST_FAIL( "Ouch..." ); // #4 throws on error
if( add( 2,2 ) != 4 ) throw "Ouch..."; // #5 throws on error
BOOST_CHECK_MESSAGE( add( 2,2 ) == 4, // #6 continues on error
"add(..) result: " << add( 2,2 ) );
BOOST_CHECK_EQUAL( add( 2,2 ), 4 ); // #7 continues on error
}
This example worked fine in Linux, however here it fails to compile:
1>------ Build started: Project: Test, Configuration: Release Win32 ------
1>Build started 30/01/2013 14:47:48.
1>InitializeBuildStatus:
1> Touching "Release\Test.unsuccessfulbuild".
1>ClCompile:
1> All outputs are up-to-date.
1>boost_unit_test_framework-vc100-mt-1_46_1.lib(boost_unit_test_framework-vc100-mt-1_46_1.dll) : error LNK2005: "class boost::unit_test::master_test_suite_t & __cdecl boost::unit_test::framework::master_test_suite(void)" (?master_test_suite#framework#unit_test#boost##YAAAVmaster_test_suite_t#23#XZ) already defined in libboost_unit_test_framework-vc100-mt-1_46_1.lib(framework.obj)
1>MSVCRT.lib(crtexew.obj) : error LNK2001: unresolved external symbol _WinMain#16
1>C:\Users\ga1009\Documents\dev\Oasis\Release\Test.exe : fatal error LNK1120: 1 unresolved externals
1>
1>Build FAILED.
What am I doing wrong and how can I fix it?
EDIT: After applying the answer from Arne Mertz, I get:
1>------ Build started: Project: Test, Configuration: Release Win32 ------
1>Build started 30/01/2013 15:09:54.
1>InitializeBuildStatus:
1> Touching "Release\Test.unsuccessfulbuild".
1>ClCompile:
1> All outputs are up-to-date.
1>boost_unit_test_framework-vc100-mt-1_46_1.lib(boost_unit_test_framework-vc100-mt-1_46_1.dll) : error LNK2005: "class boost::unit_test::master_test_suite_t & __cdecl boost::unit_test::framework::master_test_suite(void)" (?master_test_suite#framework#unit_test#boost##YAAAVmaster_test_suite_t#23#XZ) already defined in libboost_unit_test_framework-vc100-mt-1_46_1.lib(framework.obj)
1>C:\Users\ga1009\Documents\dev\Oasis\Release\Test.exe : fatal error LNK1169: one or more multiply defined symbols found
1>
1>Build FAILED.
Check your project's linker properties: There is a property System/SubSystem that should be set to /SUBSYSTEM:CONSOLE.
Edit:
For the multiple definition error it seems you have the following situation:
In your testrunner.cpp, you define BOOST_TEST_DYN_LINK wich leads to a dynamic linking of boost_unit_test_framework-vc100-mt-1_46_1.dll which contains a definition of the master_test_suite function. In the other .cpp, you do NOT define that symbol, so that one gets linked statically against boost_unit_test_framework-vc100-mt-1_46_1.lib which, together with the dll gives two definitions.
Solution: use the #define in every source before including the header.