Skip to content

Commit

Permalink
initial import
Browse files Browse the repository at this point in the history
  • Loading branch information
shalupov committed Dec 6, 2011
0 parents commit 55b88be
Show file tree
Hide file tree
Showing 17 changed files with 1,291 additions and 0 deletions.
52 changes: 52 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
TEAMCITY_PROJECT_NAME = test
export TEAMCITY_PROJECT_NAME

COMMON_FILES = common/teamcity_messages.cpp common/teamcity_messages.h
BOOST_FILES = $(COMMON_FILES) \
boost/teamcity_boost.cpp \
boost/boost_test.cpp
CPPUNIT_FILES = $(COMMON_FILES) \
cppunit/teamcity_cppunit.cpp cppunit/teamcity_cppunit.h \
cppunit/cppunit_test.cpp

.PHONY: all test dist

all: test

CXXFLAGS := -Icommon -g -O0

boost_test: $(BOOST_FILES)
g++ $(CXXFLAGS) -DBOOST_TEST_DYN_LINK -o \
$@ $(filter %.cpp, $(BOOST_FILES)) -lboost_unit_test_framework-mt

cppunit_test: $(CPPUNIT_FILES)
g++ $(CXXFLAGS) -o \
$@ $(filter %.cpp, $(CPPUNIT_FILES)) -lcppunit

BOOST_OUTPUT = boost/boost_test.output
CPPUNIT_OUTPUT = cppunit/cppunit_test.output

test: boost_test cppunit_test
./boost_test >$(BOOST_OUTPUT).tmp 2>&1 ||:
diff -Nru $(BOOST_OUTPUT).gold $(BOOST_OUTPUT).tmp && rm -f $(BOOST_OUTPUT).tmp

TEAMCITY_PROCESS_FLOW_ID=myFlowId ./boost_test >$(BOOST_OUTPUT).flowId.tmp 2>&1 ||:
diff -Nru $(BOOST_OUTPUT).flowId.gold $(BOOST_OUTPUT).flowId.tmp && rm -f $(BOOST_OUTPUT).flowId.tmp

./cppunit_test >$(CPPUNIT_OUTPUT).tmp 2>&1 ||:
diff -Nru $(CPPUNIT_OUTPUT).gold $(CPPUNIT_OUTPUT).tmp && rm -f $(CPPUNIT_OUTPUT).tmp

TEAMCITY_PROCESS_FLOW_ID=myFlowId ./cppunit_test >$(CPPUNIT_OUTPUT).flowId.tmp 2>&1 ||:
diff -Nru $(CPPUNIT_OUTPUT).flowId.gold $(CPPUNIT_OUTPUT).flowId.tmp && rm -f $(CPPUNIT_OUTPUT).flowId.tmp

@echo "<<< Tests OK >>>"

VERSION = $(shell cat VERSION)

dist:
rm -f teamcity-*-$(VERSION).zip
zip -rj9 teamcity-cppunit-$(VERSION).zip \
cppunit/teamcity_cppunit.* common/teamcity_messages.* \
cppunit/example.cpp cppunit/README.txt
zip -rj9 teamcity-boost-$(VERSION).zip \
boost/teamcity_boost.* common/teamcity_messages.* boost/README.txt
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.3
134 changes: 134 additions & 0 deletions boost/PARAM_TEST_CASES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
If you have tests with test parameters,
look at http://jetbrains.net/tracker/issue/TW-7043 for quick solution.

It's proposed to replace standard parameterized_test.hpp with modified one - it
creates a unique name for each test from the range if you use
BOOST_NAMED_PARAM_TEST_CASE macro.

By default a per-param type sequence is used to create name,
e.g. test(#1), test(#2), ... but you can alter name generation by
providing your our compose_test_case_name() function, or by providing
to_string overloads. Note that any of your custom overloads should reside
in the boost::unit_test namespace.

Thanks Kirill Kovalenko for the workaround.

parameterized_test.hpp
----------------------

#pragma once

#include <sstream>
#include <boost/test/parameterized_test.hpp>

#define BOOST_NAMED_PARAM_TEST_CASE( function, begin, end ) \
boost::unit_test::make_named_test_case( function, \
BOOST_TEST_STRINGIZE( function ), \
(begin), (end) ) \

namespace boost {

namespace unit_test {

template<typename ParamType>
inline std::string to_string(const ParamType& t)
{
static unsigned int counter = 0;
std::stringstream ss;
ss << "#" << ++counter;
return ss.str();
}

template<typename ParamType>
inline std::string compose_test_case_name(boost::unit_test::const_string name, const ParamType& t)
{
std::stringstream ss;
ss << name << "(\"" << to_string(t) << "\")";
return ss.str();
}

namespace ut_detail {

template<typename ParamType, typename ParamIter>
class named_param_test_case_generator : public test_unit_generator {
public:
named_param_test_case_generator(
callback1<ParamType> const& test_func,
const_string tc_name,
ParamIter par_begin,
ParamIter par_end )
: m_test_func( test_func )
, m_tc_name( ut_detail::normalize_test_case_name( tc_name ) )
, m_par_begin( par_begin )
, m_par_end( par_end )
{}

boost::unit_test::test_unit* next() const
{
if( m_par_begin == m_par_end )
return (test_unit*)0;

boost::unit_test::ut_detail::test_func_with_bound_param<ParamType> bound_test_func( m_test_func, *m_par_begin );
test_unit* res = new test_case( compose_test_case_name(m_tc_name, *m_par_begin), bound_test_func );

++m_par_begin;

return res;
}

private:
// Data members
callback1<ParamType> m_test_func;
std::string m_tc_name;
mutable ParamIter m_par_begin;
ParamIter m_par_end;
};

} // ut_detail

template<typename ParamType, typename ParamIter>
inline ut_detail::named_param_test_case_generator<ParamType,ParamIter>
make_named_test_case( callback1<ParamType> const& test_func,
const_string tc_name,
ParamIter par_begin,
ParamIter par_end )
{
return ut_detail::named_param_test_case_generator<ParamType,ParamIter>( test_func, tc_name, par_begin, par_end );
}

//____________________________________________________________________________//

template<typename ParamType, typename ParamIter>
inline ut_detail::named_param_test_case_generator<
BOOST_DEDUCED_TYPENAME remove_const<BOOST_DEDUCED_TYPENAME remove_reference<ParamType>::type>::type,ParamIter>
make_named_test_case( void (*test_func)( ParamType ),
const_string tc_name,
ParamIter par_begin,
ParamIter par_end )
{
typedef BOOST_DEDUCED_TYPENAME remove_const<BOOST_DEDUCED_TYPENAME remove_reference<ParamType>::type>::type param_value_type;
return ut_detail::named_param_test_case_generator<param_value_type,ParamIter>( test_func, tc_name, par_begin, par_end );
}

//____________________________________________________________________________//

template<typename UserTestCase,typename ParamType, typename ParamIter>
inline ut_detail::named_param_test_case_generator<
BOOST_DEDUCED_TYPENAME remove_const<BOOST_DEDUCED_TYPENAME remove_reference<ParamType>::type>::type,ParamIter>
make_named_test_case( void (UserTestCase::*test_method )( ParamType ),
const_string tc_name,
boost::shared_ptr<UserTestCase> const& user_test_case,
ParamIter par_begin,
ParamIter par_end )
{
typedef BOOST_DEDUCED_TYPENAME remove_const<BOOST_DEDUCED_TYPENAME remove_reference<ParamType>::type>::type param_value_type;
return ut_detail::named_param_test_case_generator<param_value_type,ParamIter>(
ut_detail::user_param_tc_method_invoker<UserTestCase,ParamType>( user_test_case, test_method ),
tc_name,
par_begin,
par_end );
}

} // namespace unit_test

} // boost
32 changes: 32 additions & 0 deletions boost/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Boost listener for TeamCity
---------------------------

To report your tests result to TeamCity server
just include teamcity_messages.* teamcity_boost.cpp
to your project.

That code will register global fixture
( http://www.boost.org/doc/libs/1_38_0/libs/test/doc/html/utf/user-guide/fixture/global.html )
to replace output formatter if run under TeamCity.

If you have tests with test parameters, see PARAM_TEST_CASES.txt for quick solution.

Technical details
-----------------

Reporting implemented as writing TeamCity service messages to stdout.

See
http://www.jetbrains.net/confluence/display/TCD3/Build+Script+Interaction+with+TeamCity
for more details.

Contact information
-------------------

See http://www.jetbrains.com/support/teamcity

License
-------

Apache, version 2.0
http://www.apache.org/licenses/LICENSE-2.0
84 changes: 84 additions & 0 deletions boost/boost_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#define BOOST_TEST_MAIN

#include <iostream>

#include <boost/test/unit_test.hpp>

using namespace std;

/* Suite tree tests */
BOOST_AUTO_TEST_SUITE(my_suite1)

BOOST_AUTO_TEST_CASE(my_test1) {
BOOST_CHECK(2 == 1);
}

BOOST_AUTO_TEST_CASE(my_test2) {
int i = 0;

BOOST_CHECK_EQUAL(i, 2);
BOOST_CHECK_EQUAL(i, 0);
}

BOOST_AUTO_TEST_SUITE_END()

BOOST_AUTO_TEST_CASE(my_test3) {
int i = 0;

BOOST_CHECK_EQUAL(i, 0);
}

BOOST_AUTO_TEST_SUITE(my_suite2)

BOOST_AUTO_TEST_CASE(my_test4) {
int i = 0;

BOOST_CHECK_EQUAL(i, 1);
}

BOOST_AUTO_TEST_SUITE(internal_suite)

BOOST_AUTO_TEST_CASE(my_test5) {
int i = 0;

BOOST_CHECK_EQUAL( i, 1 );
}

BOOST_AUTO_TEST_SUITE_END()

BOOST_AUTO_TEST_SUITE_END()

/* Other */
BOOST_AUTO_TEST_CASE(testCerr) {
cerr << "Hello from cerr" << endl;
}

BOOST_AUTO_TEST_CASE(testCout) {
cerr << "Hello from cout" << endl;
}

static void ThrowRuntimeError() {
throw runtime_error("runtime exception text");
}

BOOST_AUTO_TEST_CASE(testException) {
ThrowRuntimeError();
}

BOOST_AUTO_TEST_CASE(testAssertExceptionGood) {
BOOST_CHECK_THROW(ThrowRuntimeError(), runtime_error);
}

BOOST_AUTO_TEST_CASE(testAssertExceptionFail) {
BOOST_CHECK_THROW(ThrowRuntimeError(), logic_error);
}

BOOST_AUTO_TEST_CASE(testFatal) {
BOOST_FAIL("bfail");
}

BOOST_AUTO_TEST_CASE(testError) {
BOOST_ERROR("berror");
}

BOOST_AUTO_TEST_CASE(testNothing) {}
Loading

0 comments on commit 55b88be

Please sign in to comment.