18 | ```
19 |
20 |
21 | Copyright Endre Tamas SAJO (baja at inf dot elte dot hu),
22 | Abel Sinkovics (abel at elte dot hu), 2010.
23 | Distributed under the Boost Software License, Version 1.0.
24 | (See accompanying file LICENSE_1_0.txt or copy at
25 | [http://www.boost.org/LICENSE_1_0.txt](http://www.boost.org/LICENSE_1_0.txt)
26 |
27 |
28 | [[up]](index.html)
29 |
30 |
31 |
--------------------------------------------------------------------------------
/cmake/Files.cmake:
--------------------------------------------------------------------------------
1 | # Copyright Abel Sinkovics (abel@sinkovics.hu) 2012.
2 | # Distributed under the Boost Software License, Version 1.0.
3 | # (See accompanying file LICENSE_1_0.txt or copy at
4 | # http://www.boost.org/LICENSE_1_0.txt)
5 |
6 | macro(dir PATH)
7 | get_filename_component(P ${PATH} ABSOLUTE)
8 | add_custom_command(
9 | OUTPUT ${P}
10 | COMMAND mkdir -p ${P}
11 | )
12 | endmacro(dir)
13 |
14 | macro(copy_file SRC_PATH FILENAME DST_PATH)
15 | get_filename_component(P ${DST_PATH} ABSOLUTE)
16 | set(DST ${P}/${FILENAME})
17 | set(SRC ${SRC_PATH}/${FILENAME})
18 |
19 | add_custom_command(
20 | OUTPUT ${DST}
21 | COMMAND cp ${SRC} ${DST}
22 | DEPENDS ${SRC} ${P} ${ARGN}
23 | )
24 | endmacro(copy_file)
25 |
26 |
--------------------------------------------------------------------------------
/doc/plaintext_report.md:
--------------------------------------------------------------------------------
1 | # metatest::plaintext_report
2 |
3 | ## Synopsis
4 |
5 | ```cpp
6 | bool plaintext_report(std::ostream &os_)
7 | ```
8 |
9 | ## Description
10 |
11 | Displays the test results in a plain-text format. Returns `true` when there
12 | was no failed test case.
13 |
14 | ## Header
15 |
16 | ```cpp
17 | #include
18 | ```
19 |
20 |
21 | Copyright Endre Tamas SAJO (baja at inf dot elte dot hu),
22 | Abel Sinkovics (abel at elte dot hu), 2010.
23 | Distributed under the Boost Software License, Version 1.0.
24 | (See accompanying file LICENSE_1_0.txt or copy at
25 | [http://www.boost.org/LICENSE_1_0.txt](http://www.boost.org/LICENSE_1_0.txt)
26 |
27 |
28 | [[up]](index.html)
29 |
30 |
31 |
--------------------------------------------------------------------------------
/include/metatest/get_value.hpp:
--------------------------------------------------------------------------------
1 | #ifndef METATEST_GET_VALUE_HPP
2 | #define METATEST_GET_VALUE_HPP
3 |
4 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2010.
5 | // Distributed under the Boost Software License, Version 1.0.
6 | // (See accompanying file LICENSE_1_0.txt or copy at
7 | // http://www.boost.org/LICENSE_1_0.txt)
8 |
9 | #include
10 |
11 | #include
12 |
13 | #include
14 |
15 | namespace metatest
16 | {
17 | template
18 | struct get_value :
19 | boost::mpl::eval_if::type, T, Default>
20 | {};
21 | }
22 |
23 | METATEST_DEFINE_TO_STREAM_FOR_TEMPLATE(2, metatest::get_value, "get_value")
24 |
25 | #endif
26 |
27 |
--------------------------------------------------------------------------------
/doc/METATEST_HERE.md:
--------------------------------------------------------------------------------
1 | # METATEST_HERE
2 |
3 | ## Synopsis
4 |
5 | ```cpp
6 | #define METATEST_HERE \
7 | // unspecified
8 | ```
9 |
10 | ## Description
11 |
12 | Macro for constructing a [`location`](location.html) value, representing
13 | the source location that invokes `METATEST_HERE`.
14 |
15 | ## Header
16 |
17 | ```cpp
18 | #include
19 | ```
20 |
21 |
22 | Copyright Endre Tamas SAJO (baja at inf dot elte dot hu),
23 | Abel Sinkovics (abel at elte dot hu), 2010.
24 | Distributed under the Boost Software License, Version 1.0.
25 | (See accompanying file LICENSE_1_0.txt or copy at
26 | [http://www.boost.org/LICENSE_1_0.txt](http://www.boost.org/LICENSE_1_0.txt)
27 |
28 |
29 | [[up]](index.html)
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/include/metatest/has_type_value.hpp:
--------------------------------------------------------------------------------
1 | #ifndef METATEST_HAS_TYPE_VALUE_HPP
2 | #define METATEST_HAS_TYPE_VALUE_HPP
3 |
4 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2010.
5 | // Distributed under the Boost Software License, Version 1.0.
6 | // (See accompanying file LICENSE_1_0.txt or copy at
7 | // http://www.boost.org/LICENSE_1_0.txt)
8 |
9 | #include
10 | #include
11 | #include
12 |
13 | namespace metatest
14 | {
15 | template
16 | struct has_type_value :
17 | has_value::type, ValueType>
18 | {};
19 | }
20 |
21 | METATEST_DEFINE_TO_STREAM_FOR_TEMPLATE(
22 | 2,
23 | metatest::has_type_value,
24 | "has_type_value"
25 | )
26 |
27 | #endif
28 |
29 |
--------------------------------------------------------------------------------
/include/metatest/get_type.hpp:
--------------------------------------------------------------------------------
1 | #ifndef METATEST_GET_TYPE_HPP
2 | #define METATEST_GET_TYPE_HPP
3 |
4 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2010.
5 | // Distributed under the Boost Software License, Version 1.0.
6 | // (See accompanying file LICENSE_1_0.txt or copy at
7 | // http://www.boost.org/LICENSE_1_0.txt)
8 |
9 | #include
10 |
11 | #include
12 | #include
13 |
14 | #include
15 |
16 | namespace metatest
17 | {
18 | template
19 | struct get_type :
20 | boost::mpl::eval_if<
21 | typename has_type::type,
22 | T,
23 | boost::mpl::identity
24 | >
25 | {};
26 | }
27 |
28 | METATEST_DEFINE_TO_STREAM_FOR_TEMPLATE(2, metatest::get_type, "get_type")
29 |
30 | #endif
31 |
32 |
--------------------------------------------------------------------------------
/doc/html_report.md:
--------------------------------------------------------------------------------
1 | # metatest::html_report
2 |
3 | ## Synopsis
4 |
5 | ```cpp
6 | bool html_report(std::ostream &os_)
7 | ```
8 |
9 | ## Description
10 |
11 | Displays the test results as an HTML document. Returns `true` when there
12 | was no failed test case. The HTML document assumes that
13 | [`jquery.js`](http://jquery.com/) is in the same directory as the generated HTML
14 | document itself.
15 |
16 | ## Header
17 |
18 | ```cpp
19 | #include
20 | ```
21 |
22 |
23 | Copyright Endre Tamas SAJO (baja at inf dot elte dot hu),
24 | Abel Sinkovics (abel at elte dot hu), 2010.
25 | Distributed under the Boost Software License, Version 1.0.
26 | (See accompanying file LICENSE_1_0.txt or copy at
27 | [http://www.boost.org/LICENSE_1_0.txt](http://www.boost.org/LICENSE_1_0.txt)
28 |
29 |
30 | [[up]](index.html)
31 |
32 |
33 |
--------------------------------------------------------------------------------
/include/metatest/get_type_value.hpp:
--------------------------------------------------------------------------------
1 | #ifndef METATEST_GET_TYPE_VALUE_HPP
2 | #define METATEST_GET_TYPE_VALUE_HPP
3 |
4 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2010.
5 | // Distributed under the Boost Software License, Version 1.0.
6 | // (See accompanying file LICENSE_1_0.txt or copy at
7 | // http://www.boost.org/LICENSE_1_0.txt)
8 |
9 | #include
10 | #include
11 |
12 | #include
13 |
14 | #include
15 |
16 | namespace metatest
17 | {
18 | template
19 | struct get_type_value :
20 | get_value<
21 | typename get_type >::type,
22 | Default
23 | >
24 | {};
25 | }
26 |
27 | METATEST_DEFINE_TO_STREAM_FOR_TEMPLATE(
28 | 2,
29 | metatest::get_type_value,
30 | "get_type_value"
31 | )
32 |
33 | #endif
34 |
35 |
--------------------------------------------------------------------------------
/cmake/Pandoc.cmake:
--------------------------------------------------------------------------------
1 | # Copyright Abel Sinkovics (abel@sinkovics.hu) 2013.
2 | # Distributed under the Boost Software License, Version 1.0.
3 | # (See accompanying file LICENSE_1_0.txt or copy at
4 | # http://www.boost.org/LICENSE_1_0.txt)
5 |
6 | find_program(PANDOC pandoc)
7 | set(GEN_TOC ${PROJECT_SOURCE_DIR}/tools/gen_toc)
8 |
9 | macro(pandoc_build TARGET_NAME OUTDIR)
10 | set(OUTFILES)
11 | foreach(IT ${ARGN})
12 | get_filename_component(FILENAME ${IT} NAME_WE)
13 | set(OUTFILE ${OUTDIR}/${FILENAME}.html)
14 | set(OUTFILES ${OUTFILES} ${OUTFILE})
15 | add_custom_command(
16 | OUTPUT ${OUTFILE}
17 | COMMAND
18 | ${GEN_TOC} -i ${IT} -o - -t pandoc_html |
19 | ${PANDOC} --from markdown --to html -c style.css -o ${OUTFILE}
20 | DEPENDS ${IT}
21 | )
22 | endforeach(IT)
23 | add_custom_target(${TARGET_NAME} DEPENDS ${OUTFILES})
24 | endmacro(pandoc_build)
25 |
26 |
--------------------------------------------------------------------------------
/doc/METATEST_DEFINE_TO_STREAM_FOR_SIMPLE_TYPE.md:
--------------------------------------------------------------------------------
1 | # METATEST_DEFINE_TO_STREAM_FOR_SIMPLE_TYPE
2 |
3 | ## Synopsis
4 |
5 | ```cpp
6 | #define METATEST_DEFINE_TO_STREAM_FOR_SIMPLE_TYPE(name) \
7 | // unspecified
8 | ```
9 |
10 | ## Description
11 |
12 | Defines an overload of [`to_stream`](to_stream.html) for the type `name`.
13 |
14 | ## Header
15 |
16 | ```cpp
17 | #include
18 | ```
19 |
20 | ## Example
21 |
22 | ```cpp
23 | class custom_type;
24 |
25 | METATEST_DEFINE_TO_STREAM_FOR_SIMPLE_TYPE(custom_type)
26 | ```
27 |
28 |
29 | Copyright Endre Tamas SAJO (baja at inf dot elte dot hu),
30 | Abel Sinkovics (abel at elte dot hu), 2010.
31 | Distributed under the Boost Software License, Version 1.0.
32 | (See accompanying file LICENSE_1_0.txt or copy at
33 | [http://www.boost.org/LICENSE_1_0.txt](http://www.boost.org/LICENSE_1_0.txt)
34 |
35 |
36 | [[up]](index.html)
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/src/test_driver.cpp:
--------------------------------------------------------------------------------
1 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2010.-2011.
2 | // Distributed under the Boost Software License, Version 1.0.
3 | // (See accompanying file LICENSE_1_0.txt or copy at
4 | // http://www.boost.org/LICENSE_1_0.txt)
5 |
6 | #define METATEST_SOURCE
7 |
8 | #include
9 | #include
10 |
11 | #include
12 |
13 | using metatest::test_driver;
14 | using metatest::test_suite;
15 | using metatest::test_result;
16 | using metatest::suite_path;
17 |
18 | test_driver& test_driver::instance()
19 | {
20 | return boost::unit_test::singleton::instance();
21 | }
22 |
23 | void test_driver::add(const suite_path& suite_, const test_result& result_)
24 | {
25 | _suite.add(suite_.begin(), suite_.end(), result_);
26 | }
27 |
28 | const test_suite& test_driver::suite() const
29 | {
30 | return _suite;
31 | }
32 |
33 |
34 |
--------------------------------------------------------------------------------
/include/metatest/test_driver.hpp:
--------------------------------------------------------------------------------
1 | #ifndef METATEST_TEST_DRIVER_HPP
2 | #define METATEST_TEST_DRIVER_HPP
3 |
4 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2010.-2011.
5 | // Distributed under the Boost Software License, Version 1.0.
6 | // (See accompanying file LICENSE_1_0.txt or copy at
7 | // http://www.boost.org/LICENSE_1_0.txt)
8 |
9 | #include
10 | #include
11 | #include
12 |
13 | #include
14 |
15 | #include
16 |
17 | #include
18 |
19 | namespace metatest
20 | {
21 | class test_driver
22 | {
23 | public:
24 | METATEST_DECL static test_driver& instance();
25 |
26 | METATEST_DECL const test_suite& suite() const;
27 |
28 | METATEST_DECL void add(const suite_path& suite_,const test_result& result_);
29 | private:
30 | test_suite _suite;
31 | };
32 | }
33 |
34 | #endif
35 |
36 |
--------------------------------------------------------------------------------
/example/metatest_example/double.cpp:
--------------------------------------------------------------------------------
1 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2010.
2 | // Distributed under the Boost Software License, Version 1.0.
3 | // (See accompanying file LICENSE_1_0.txt or copy at
4 | // http://www.boost.org/LICENSE_1_0.txt)
5 |
6 | #include
7 |
8 | #include
9 |
10 | #include
11 | #include
12 | #include
13 |
14 | using metatest::suite_path;
15 |
16 | using boost::mpl::equal_to;
17 | using boost::mpl::int_;
18 |
19 | // Metafunction to test
20 | template
21 | struct double_ : boost::mpl::times > {};
22 |
23 | METATEST_DEFINE_TO_STREAM_FOR_TEMPLATE(1, double_, "double_")
24 |
25 | namespace
26 | {
27 | const suite_path suite("example");
28 |
29 | typedef equal_to >::type, int_<26> > test_success;
30 | }
31 |
32 | METATEST_ADD_TEST(suite, test_success)
33 |
34 |
35 |
--------------------------------------------------------------------------------
/example/ugly/ugly.cc:
--------------------------------------------------------------------------------
1 | // Copyright Endre Tamas SAJO (baja@inf.elte.hu) 2011.
2 | // Distributed under the Boost Software License, Version 1.0.
3 | // (See accompanying file LICENSE_2_0.txt or copy at
4 | // http://www.boost.org/LICENSE_1_0.txt)
5 |
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 |
12 | #include
13 |
14 | using namespace boost;
15 | using namespace mpl;
16 |
17 | MPL_TEST_CASE()
18 | {
19 | typedef front< vector > f;
20 |
21 | MPL_ASSERT(( is_same ));
22 | }
23 |
24 | MPL_TEST_CASE()
25 | {
26 | typedef size< vector > s;
27 |
28 | MPL_ASSERT_RELATION(s, ==, 3);
29 | }
30 |
31 | MPL_TEST_CASE()
32 | {
33 | typedef vector v1;
34 | typedef pop_front::type v2;
35 |
36 | MPL_ASSERT(( is_same< v2, vector > ));
37 | }
38 |
39 |
--------------------------------------------------------------------------------
/src/suite_path.cpp:
--------------------------------------------------------------------------------
1 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2011.
2 | // Distributed under the Boost Software License, Version 1.0.
3 | // (See accompanying file LICENSE_1_0.txt or copy at
4 | // http://www.boost.org/LICENSE_1_0.txt)
5 |
6 | #define METATEST_SOURCE
7 |
8 | #include
9 |
10 | using metatest::suite_path;
11 |
12 | using std::string;
13 |
14 | suite_path::suite_path()
15 | {}
16 |
17 | suite_path::suite_path(const std::string& p_) :
18 | _elements(1, p_)
19 | {}
20 |
21 | suite_path::suite_path(const std::list& p_) :
22 | _elements(p_)
23 | {}
24 |
25 | suite_path::iterator suite_path::begin() const
26 | {
27 | return _elements.begin();
28 | }
29 |
30 | suite_path::iterator suite_path::end() const
31 | {
32 | return _elements.end();
33 | }
34 |
35 | suite_path suite_path::operator()(const std::string& e_) const
36 | {
37 | suite_path result(*this);
38 | result._elements.push_back(e_);
39 | return result;
40 | }
41 |
42 |
--------------------------------------------------------------------------------
/example/boost_test_assertion/double.cpp:
--------------------------------------------------------------------------------
1 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2011.
2 | // Distributed under the Boost Software License, Version 1.0.
3 | // (See accompanying file LICENSE_1_0.txt or copy at
4 | // http://www.boost.org/LICENSE_1_0.txt)
5 |
6 | #define BOOST_TEST_DYN_LINK
7 |
8 | #include
9 | #include
10 |
11 | #include
12 |
13 | #include
14 | #include
15 | #include
16 |
17 | using metatest::meta_require;
18 |
19 | using boost::mpl::equal_to;
20 | using boost::mpl::int_;
21 |
22 | // Metafunction to test
23 | template
24 | struct double_ : boost::mpl::times > {};
25 |
26 | METATEST_DEFINE_TO_STREAM_FOR_TEMPLATE(1, double_, "double_")
27 |
28 | BOOST_AUTO_TEST_CASE(example)
29 | {
30 | meta_require<
31 | equal_to >::type, int_<26> >
32 | >(METATEST_HERE, "test_success");
33 | }
34 |
35 |
36 |
--------------------------------------------------------------------------------
/doc/METATEST_DEFINE_TO_STREAM_FOR_TYPE.md:
--------------------------------------------------------------------------------
1 | # METATEST_DEFINE_TO_STREAM_FOR_TYPE
2 |
3 | ## Synopsis
4 |
5 | ```cpp
6 | #define METATEST_DEFINE_TO_STREAM_FOR_TYPE(name, display_name) \
7 | // unspecified
8 | ```
9 |
10 | ## Description
11 |
12 | Defines an overload of [`to_stream`](to_stream.html) for the type `name`.
13 | `display_name` is a constant expression that can be displayed in a stream
14 | using `operator<<`.
15 |
16 | ## Header
17 |
18 | ```cpp
19 | #include
20 | ```
21 |
22 | ## Example
23 |
24 | ```cpp
25 | class custom_type;
26 |
27 | METATEST_DEFINE_TO_STREAM_FOR_TYPE(custom_type, "custom_type")
28 | ```
29 |
30 |
31 | Copyright Endre Tamas SAJO (baja at inf dot elte dot hu),
32 | Abel Sinkovics (abel at elte dot hu), 2010.
33 | Distributed under the Boost Software License, Version 1.0.
34 | (See accompanying file LICENSE_1_0.txt or copy at
35 | [http://www.boost.org/LICENSE_1_0.txt](http://www.boost.org/LICENSE_1_0.txt)
36 |
37 |
38 | [[up]](index.html)
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/include/metatest/suite_path.hpp:
--------------------------------------------------------------------------------
1 | #ifndef METATEST_SUITE_PATH_HPP
2 | #define METATEST_SUITE_PATH_HPP
3 |
4 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2011.
5 | // Distributed under the Boost Software License, Version 1.0.
6 | // (See accompanying file LICENSE_1_0.txt or copy at
7 | // http://www.boost.org/LICENSE_1_0.txt)
8 |
9 | #include
10 |
11 | #include
12 | #include
13 |
14 | namespace metatest
15 | {
16 | class suite_path
17 | {
18 | private:
19 | typedef std::list elements;
20 | public:
21 | typedef elements::const_iterator iterator;
22 |
23 | METATEST_DECL suite_path();
24 | METATEST_DECL suite_path(const std::string& p_);
25 | METATEST_DECL suite_path(const std::list& p_);
26 |
27 | METATEST_DECL iterator begin() const;
28 | METATEST_DECL iterator end() const;
29 |
30 | METATEST_DECL suite_path operator()(const std::string& e_) const;
31 | private:
32 | elements _elements;
33 | };
34 | }
35 |
36 | #endif
37 |
38 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | metatest
2 | ========
3 |
4 | [](http://travis-ci.org/sabel83/metatest)
5 |
6 | Introduction
7 | ------------
8 |
9 | Metatest is a unit testing framework for C++ template metaprograms. It can be
10 | integrated into other C++ unit testing frameworks and has its own reporting
11 | capabilities as well. There are no special steps in the compilation of unit
12 | tests compared to other C++ code.
13 |
14 | Documentation
15 | -------------
16 |
17 | The documentation of the library can be automatically generated by running the
18 | `website` target. It is also available [here](http://abel.web.elte.hu/metatest).
19 |
20 | Getting the library
21 | -------------------
22 |
23 | * Download the source code from [github](http://github.com/sabel83/metatest).
24 | * [build and install](http://abel.web.elte.hu/metatest/build.html) the library
25 |
26 | License
27 | -------
28 |
29 | The libraries are published under the
30 | [Boost Software License](http://www.boost.org/LICENSE_1_0.txt).
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/doc/to_stream.md:
--------------------------------------------------------------------------------
1 | # metatest::to_stream
2 |
3 | ## Synopsis
4 |
5 | ```cpp
6 | template
7 | struct to_stream
8 | {
9 | static std::ostream& run(std::ostream& o_);
10 | };
11 | ```
12 |
13 | ## Description
14 |
15 | Tool for pretty-printing types at runtime. It takes the type as a compile-time
16 | and the stream to print it to as a runtime argument. Pretty-printing support for
17 | new types can be added by specialising this template and providing the `run`
18 | method in the specialisation.
19 |
20 | ## Header
21 |
22 | ```cpp
23 | #include
24 | ```
25 |
26 | ## Example
27 |
28 | ```cpp
29 | int main()
30 | {
31 | to_stream::run(std::cout);
32 | }
33 | ```
34 |
35 |
36 | Copyright Endre Tamas SAJO (baja at inf dot elte dot hu),
37 | Abel Sinkovics (abel at elte dot hu), 2010.
38 | Distributed under the Boost Software License, Version 1.0.
39 | (See accompanying file LICENSE_1_0.txt or copy at
40 | [http://www.boost.org/LICENSE_1_0.txt](http://www.boost.org/LICENSE_1_0.txt)
41 |
42 |
43 | [[up]](index.html)
44 |
45 |
46 |
--------------------------------------------------------------------------------
/example/reverse/test.cc:
--------------------------------------------------------------------------------
1 | // Copyright Endre Tamas SAJO (baja@inf.elte.hu) 2011.
2 | // Abel Sinkovics (abel@sinkovics.hu) 2011.
3 | // Distributed under the Boost Software License, Version 1.0.
4 | // (See accompanying file LICENSE_2_0.txt or copy at
5 | // http://www.boost.org/LICENSE_1_0.txt)
6 |
7 | #include "my_reverse.hpp"
8 |
9 | #include
10 | #include
11 |
12 | #include
13 |
14 | MPL_TEST_CASE()
15 | {
16 | using namespace boost;
17 | using namespace mpl;
18 |
19 | typedef vector<> empty;
20 | typedef vector one;
21 | typedef vector four;
22 |
23 | typedef vector four_r;
24 |
25 | MPL_ASSERT((equal< my_reverse::type, empty >));
26 | MPL_ASSERT((equal< my_reverse::type, one >));
27 | MPL_ASSERT((equal< my_reverse::type, four_r >));
28 |
29 | MPL_ASSERT((equal< my_reverse::type, one >));
30 | MPL_ASSERT((equal< my_reverse::type, empty >));
31 | MPL_ASSERT((equal< my_reverse::type, four >));
32 | }
33 |
--------------------------------------------------------------------------------
/example/boost_mpl_unit_test/quote.cpp:
--------------------------------------------------------------------------------
1 | // Copyright Endre Tamas SAJO (baja@inf.elte.hu) 2011.
2 | // Distributed under the Boost Software License, Version 1.0.
3 | // (See accompanying file LICENSE_2_0.txt or copy at
4 | // http://www.boost.org/LICENSE_1_0.txt)
5 |
6 | #include
7 |
8 | #include
9 | #include
10 |
11 | namespace
12 | {
13 | const metatest::suite_path suite ("quote");
14 |
15 | using namespace boost::mpl;
16 | using boost::is_same;
17 |
18 | template
19 | struct f1
20 | {
21 | typedef T type;
22 | };
23 |
24 | template
25 | struct f5
26 | {
27 | #if defined(BOOST_MPL_CFG_NO_IMPLICIT_METAFUNCTIONS)
28 | typedef f5 type;
29 | #endif
30 | };
31 |
32 | typedef quote1::apply::type q1;
33 | typedef quote5::apply::type q5;
34 |
35 | typedef is_same t1;
36 | typedef is_same > t5;
37 | }
38 |
39 | METATEST_ADD_TEST (suite, t1)
40 | METATEST_ADD_TEST (suite, t5)
41 |
42 |
--------------------------------------------------------------------------------
/example/ugly/ugly.cpp:
--------------------------------------------------------------------------------
1 | // Copyright Endre Tamas SAJO (baja@inf.elte.hu) 2011.
2 | // Distributed under the Boost Software License, Version 1.0.
3 | // (See accompanying file LICENSE_2_0.txt or copy at
4 | // http://www.boost.org/LICENSE_1_0.txt)
5 |
6 | #include
7 |
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 |
14 | using namespace boost;
15 | using namespace mpl;
16 |
17 | namespace
18 | {
19 | const metatest::suite_path suite ("ugly");
20 |
21 | namespace testcase_1
22 | {
23 | typedef front< vector > f;
24 |
25 | typedef is_same test1;
26 | METATEST_ADD_TEST(suite, test1)
27 | }
28 |
29 | namespace testcase_2
30 | {
31 | typedef size< vector > s;
32 |
33 | typedef equal_to< s, int_<3> > test2;
34 | METATEST_ADD_TEST(suite, test2)
35 | }
36 |
37 | namespace testcase_3
38 | {
39 | typedef vector v1;
40 | typedef pop_front::type v2;
41 |
42 | typedef is_same< v2, vector > test3;
43 | METATEST_ADD_TEST(suite, test3)
44 | }
45 | }
46 |
47 |
--------------------------------------------------------------------------------
/include/metatest/test.hpp:
--------------------------------------------------------------------------------
1 | #ifndef METATEST_TEST_HPP
2 | #define METATEST_TEST_HPP
3 |
4 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2009 - 2011.
5 | // Distributed under the Boost Software License, Version 1.0.
6 | // (See accompanying file LICENSE_1_0.txt or copy at
7 | // http://www.boost.org/LICENSE_1_0.txt)
8 |
9 | #include
10 | #include
11 |
12 | #ifdef METATEST_ADD_TEST
13 | #error METATEST_ADD_TEST already defined
14 | #endif
15 | // We have to use a namespace not used anywhere else to avoid
16 | // test cases being replaced by other classes in the background
17 | #define METATEST_ADD_TEST(suite, name) \
18 | namespace metatest_test_cases \
19 | { \
20 | namespace \
21 | { \
22 | struct name##_executor \
23 | { \
24 | name##_executor() \
25 | { \
26 | metatest::test_driver::instance().add( \
27 | (suite), \
28 | metatest::test_result::build(METATEST_HERE, #name) \
29 | ); \
30 | } \
31 | \
32 | static name##_executor instance; \
33 | }; \
34 | \
35 | name##_executor name##_executor::instance; \
36 | } \
37 | }
38 |
39 | #endif
40 |
41 |
--------------------------------------------------------------------------------
/include/metatest/location.hpp:
--------------------------------------------------------------------------------
1 | #ifndef METATEST_LOCATION_HPP
2 | #define METATEST_LOCATION_HPP
3 |
4 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2010-2011.
5 | // Distributed under the Boost Software License, Version 1.0.
6 | // (See accompanying file LICENSE_1_0.txt or copy at
7 | // http://www.boost.org/LICENSE_1_0.txt)
8 |
9 | #include
10 | #include
11 |
12 | namespace metatest
13 | {
14 | #ifdef METATEST_HERE
15 | #error METATEST_HERE already defined
16 | #endif
17 | #define METATEST_HERE (metatest::location(__FILE__, __LINE__))
18 |
19 | class location
20 | {
21 | public:
22 | location(const std::string& filename_, int line_number_) :
23 | _filename(filename_),
24 | _line_number(line_number_)
25 | {}
26 |
27 | const std::string& filename() const
28 | {
29 | return _filename;
30 | }
31 |
32 | int line_number() const
33 | {
34 | return _line_number;
35 | }
36 | private:
37 | std::string _filename;
38 | int _line_number;
39 | };
40 |
41 | inline std::ostream& operator<<(std::ostream& out_, const location& l_)
42 | {
43 | return out_ << l_.filename() << ":" << l_.line_number();
44 | }
45 | }
46 |
47 | #endif
48 |
49 |
--------------------------------------------------------------------------------
/example/boost_mpl_unit_test/identity.cpp:
--------------------------------------------------------------------------------
1 | // Copyright Endre Tamas SAJO (baja@inf.elte.hu) 2011.
2 | // Distributed under the Boost Software License, Version 1.0.
3 | // (See accompanying file LICENSE_2_0.txt or copy at
4 | // http://www.boost.org/LICENSE_1_0.txt)
5 |
6 | #include
7 |
8 | #include
9 | #include
10 | #include
11 |
12 | namespace
13 | {
14 | const metatest::suite_path suite ("identity");
15 |
16 | using boost::is_same;
17 | using boost::mpl::_1;
18 | using boost::mpl::apply1;
19 | using boost::mpl::apply;
20 | using boost::mpl::identity;
21 | using boost::mpl::make_identity;
22 |
23 | typedef is_same< apply1, char>::type, char > t1;
24 | typedef is_same< apply1, int>::type, int > t2;
25 |
26 | typedef is_same<
27 | apply1< make_identity<>, char >::type
28 | , identity
29 | > t3;
30 |
31 | typedef is_same<
32 | apply1< make_identity<_1>, int >::type
33 | , identity
34 | > t4;
35 | }
36 |
37 | METATEST_ADD_TEST (suite, t1)
38 | METATEST_ADD_TEST (suite, t2)
39 | METATEST_ADD_TEST (suite, t3)
40 | METATEST_ADD_TEST (suite, t4)
41 |
42 |
--------------------------------------------------------------------------------
/example/boost_mpl_unit_test/if.cpp:
--------------------------------------------------------------------------------
1 | // Copyright Endre Tamas SAJO (baja@inf.elte.hu) 2011.
2 | // Distributed under the Boost Software License, Version 1.0.
3 | // (See accompanying file LICENSE_2_0.txt or copy at
4 | // http://www.boost.org/LICENSE_1_0.txt)
5 |
6 | #include
7 |
8 | #include
9 | #include
10 | #include
11 | #include
12 |
13 | namespace
14 | {
15 | const metatest::suite_path suite ("if");
16 |
17 | using namespace boost::mpl;
18 |
19 | typedef equal_to<
20 | if_, int_<2> >::type
21 | , int_<1>
22 | > test_if_true;
23 |
24 | typedef equal_to<
25 | if_c, int_<2> >::type
26 | , int_<1>
27 | > test_if_c_true;
28 |
29 | typedef equal_to<
30 | if_, int_<2> >::type
31 | , int_<2>
32 | > test_if_false;
33 |
34 | typedef equal_to<
35 | if_c, int_<2> >::type
36 | , int_<2>
37 | > test_if_c_false;
38 | }
39 |
40 | METATEST_ADD_TEST (suite, test_if_true)
41 | METATEST_ADD_TEST (suite, test_if_c_true)
42 | METATEST_ADD_TEST (suite, test_if_false)
43 | METATEST_ADD_TEST (suite, test_if_c_false)
44 |
45 |
--------------------------------------------------------------------------------
/example/misc/inline_test.cpp:
--------------------------------------------------------------------------------
1 | // Copyright Endre Tamas SAJO (baja@inf.elte.hu) 2011.
2 | // Distributed under the Boost Software License, Version 1.0.
3 | // (See accompanying file LICENSE_2_0.txt or copy at
4 | // http://www.boost.org/LICENSE_1_0.txt)
5 |
6 | #include
7 |
8 | #include
9 |
10 | template
11 | struct remove_parentheses_helper
12 | { typedef T type; };
13 |
14 | template
15 | struct remove_parentheses_helper
16 | { typedef T type; };
17 |
18 | #define REMOVE_PARENTHESES(t) \
19 | remove_parentheses_helper::type
20 |
21 | #define METATEST_TEST_IF_EQUAL(a, b, suite, test_name) \
22 | namespace \
23 | { \
24 | typedef boost::mpl::equal_to < \
25 | REMOVE_PARENTHESES(a) \
26 | , REMOVE_PARENTHESES(b) \
27 | > test_name; \
28 | } \
29 | METATEST_ADD_TEST(suite, test_name)
30 |
31 | #include
32 |
33 | namespace
34 | {
35 | const metatest::suite_path suite ("inline_test");
36 | using namespace boost::mpl;
37 | }
38 |
39 | METATEST_TEST_IF_EQUAL((int_<0>), (int_<0>), suite, test1)
40 |
41 | namespace
42 | {
43 | typedef equal_to, int_<0> > test2;
44 | }
45 |
46 | METATEST_ADD_TEST(suite, test2)
47 |
48 |
--------------------------------------------------------------------------------
/doc/location.md:
--------------------------------------------------------------------------------
1 | # metatest::location
2 |
3 | `location` instances represent locations in the source code. Instances are
4 | immutable, thus their state can not be changed after construction.
5 |
6 | A special macro, [`METATEST_HERE`](METATEST_HERE.html) represents the current
7 | location.
8 |
9 | ## Header
10 |
11 | ```cpp
12 | #include
13 | ```
14 |
15 | ## Constructors
16 |
17 | ```cpp
18 | location::location(const std::string& filename_, int line_number_)
19 | ```
20 |
21 | Creates a new instance with the specified properties.
22 |
23 | ## Methods
24 |
25 | None of the methods throws an exception.
26 |
27 | ```cpp
28 | const std::string& location::filename() const
29 | ```
30 |
31 | Name of the file, where the test case was registered.
32 |
33 | ```cpp
34 | int location::line_number() const
35 | ```
36 |
37 | Line number, where the test case was registered.
38 |
39 |
40 | Copyright Endre Tamas SAJO (baja at inf dot elte dot hu),
41 | Abel Sinkovics (abel at elte dot hu), 2010.
42 | Distributed under the Boost Software License, Version 1.0.
43 | (See accompanying file LICENSE_1_0.txt or copy at
44 | [http://www.boost.org/LICENSE_1_0.txt](http://www.boost.org/LICENSE_1_0.txt)
45 |
46 |
47 | [[up]](index.html)
48 |
49 |
50 |
--------------------------------------------------------------------------------
/example/boost_mpl_unit_test/eval_if.cpp:
--------------------------------------------------------------------------------
1 | // Copyright Endre Tamas SAJO (baja@inf.elte.hu) 2011.
2 | // Distributed under the Boost Software License, Version 1.0.
3 | // (See accompanying file LICENSE_2_0.txt or copy at
4 | // http://www.boost.org/LICENSE_1_0.txt)
5 |
6 | #include
7 |
8 | #include
9 | #include
10 | #include
11 | #include
12 |
13 | namespace
14 | {
15 | const metatest::suite_path suite ("eval_if");
16 |
17 | using namespace boost::mpl;
18 | using boost::is_same;
19 |
20 | typedef is_same<
21 | eval_if< true_, identity, identity >::type
22 | , char
23 | > t1;
24 |
25 | typedef is_same<
26 | eval_if_c< true, identity, identity >::type
27 | , char
28 | > t2;
29 |
30 | typedef is_same<
31 | eval_if< false_, identity, identity >::type
32 | , long
33 | > t3;
34 |
35 | typedef is_same<
36 | eval_if_c< false, identity, identity >::type
37 | , long
38 | > t4;
39 | }
40 |
41 | METATEST_ADD_TEST (suite, t1)
42 | METATEST_ADD_TEST (suite, t2)
43 | METATEST_ADD_TEST (suite, t3)
44 | METATEST_ADD_TEST (suite, t4)
45 |
46 |
--------------------------------------------------------------------------------
/doc/meta_warn.md:
--------------------------------------------------------------------------------
1 | # metatest::meta_warn
2 |
3 | ## Synopsis
4 |
5 | ```cpp
6 | template
7 | void meta_warn(const location& location_, const std::string& name_);
8 |
9 | template
10 | void meta_warn(const location& location_);
11 | ```
12 |
13 | This template function simplifies passing template metaprogrmaming assertions to
14 | Boost.Test. It creates a [`test_result`](test_result.html) from
15 | the `Pred` predicate using `location_` and `name_` when available. The
16 | success/failure flag and the reason string of the result is then passed to a
17 | Boost.Test `WARN` assertion.
18 |
19 | ## Header
20 |
21 | ```cpp
22 | #include
23 | ```
24 |
25 | ## Example
26 |
27 | ```cpp
28 | BOOST_AUTO_TEST_CASE(example)
29 | {
30 | meta_warn<
31 | boost::mpl::equal_to, function_to_test::type>
32 | >(METATEST_HERE);
33 | }
34 | ```
35 |
36 |
37 | Copyright Endre Tamas SAJO (baja at inf dot elte dot hu),
38 | Abel Sinkovics (abel at elte dot hu), 2010.
39 | Distributed under the Boost Software License, Version 1.0.
40 | (See accompanying file LICENSE_1_0.txt or copy at
41 | [http://www.boost.org/LICENSE_1_0.txt](http://www.boost.org/LICENSE_1_0.txt)
42 |
43 |
44 | [[up]](index.html)
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/doc/meta_check.md:
--------------------------------------------------------------------------------
1 | # metatest::meta_check
2 |
3 | ## Synopsis
4 |
5 | ```cpp
6 | template
7 | void meta_check(const location& location_, const std::string& name_);
8 |
9 | template
10 | void meta_check(const location& location_);
11 | ```
12 |
13 | This template function simplifies passing template metaprogrmaming assertions to
14 | Boost.Test. It creates a [`test_result`](test_result.html) from the `Pred`
15 | predicate using `location_` and `name_` when available. The success/failure flag
16 | and the reason string of the result is then passed to a Boost.Test `CHECK`
17 | assertion.
18 |
19 | ## Header
20 |
21 | ```cpp
22 | #include
23 | ```
24 |
25 | ## Example
26 |
27 | ```cpp
28 | BOOST_AUTO_TEST_CASE(example)
29 | {
30 | meta_check<
31 | boost::mpl::equal_to, function_to_test::type>
32 | >(METATEST_HERE);
33 | }
34 | ```
35 |
36 |
37 | Copyright Endre Tamas SAJO (baja at inf dot elte dot hu),
38 | Abel Sinkovics (abel at elte dot hu), 2010.
39 | Distributed under the Boost Software License, Version 1.0.
40 | (See accompanying file LICENSE_1_0.txt or copy at
41 | [http://www.boost.org/LICENSE_1_0.txt](http://www.boost.org/LICENSE_1_0.txt)
42 |
43 |
44 | [[up]](index.html)
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/include/metatest/test_suite.hpp:
--------------------------------------------------------------------------------
1 | #ifndef METATEST_TEST_FIXTURE_HPP
2 | #define METATEST_TEST_FIXTURE_HPP
3 |
4 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2011.
5 | // Distributed under the Boost Software License, Version 1.0.
6 | // (See accompanying file LICENSE_1_0.txt or copy at
7 | // http://www.boost.org/LICENSE_1_0.txt)
8 |
9 | #include
10 | #include
11 | #include
12 |
13 | #include
14 | #include