Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 42 additions & 35 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,35 +1,42 @@
cmake_minimum_required (VERSION 2.6)
project(UNITTEST11 CXX)

option(ENABLE_GCOV "Adds the --coverage flag to compilation" OFF)

if (ENABLE_GCOV)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
set(CMAKE_EXE_LINKER_FLAGS="${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
endif()

if (MSVC)
set(CMAKE_CXX_FLAGS "/MP ${CMAKE_CXX_FLAGS}")

elseif(CMAKE_COMPILER_IS_GNUCXX)
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GXX_VERSION)
if (GXX_VERSION VERSION_LESS 4.8)
if (GXX_VERSION VERSION_LESS 4.7)
set(CMAKE_CXX_FLAGS "-std=c++0x ${CMAKE_CXX_FLAGS}")
else()
set(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")
endif()
else()
set (CMAKE_CXX_FLAGS "-std=c++1y ${CMAKE_CXX_FLAGS}")
endif()

elseif ("${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1}" MATCHES ".*clang")
set(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")
endif()



add_subdirectory(src)

enable_testing()
add_subdirectory(tests)
cmake_minimum_required (VERSION 2.6)
project(UNITTEST11 CXX)

option(ENABLE_GCOV "Adds the --coverage flag to compilation" OFF)

if (BIICODE)
include(${CMAKE_HOME_DIRECTORY}/biicode.cmake)
init_biicode_block()
endif()

if (ENABLE_GCOV)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
set(CMAKE_EXE_LINKER_FLAGS="${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
endif()

if (MSVC)
set(CMAKE_CXX_FLAGS "/MP ${CMAKE_CXX_FLAGS}")

elseif(CMAKE_COMPILER_IS_GNUCXX)
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GXX_VERSION)
if (GXX_VERSION VERSION_LESS 4.8)
if (GXX_VERSION VERSION_LESS 4.7)
set(CMAKE_CXX_FLAGS "-std=c++0x ${CMAKE_CXX_FLAGS}")
else()
set(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")
endif()
else()
set (CMAKE_CXX_FLAGS "-std=c++1y ${CMAKE_CXX_FLAGS}")
endif()

elseif ("${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1}" MATCHES ".*clang")
set(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")
endif()

add_subdirectory(src)

if (BIICODE)
add_biicode_targets()
else()
enable_testing()
add_subdirectory(tests)
endif()
14 changes: 7 additions & 7 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
UnitTest11 Copyright (C) 2013 Jason Morley (http://www.morleydev.co.uk)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
UnitTest11 Copyright (C) 2013 Jason Morley (http://www.morleydev.co.uk)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
48 changes: 24 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
UnitTest11
==========

**Please note this library is still in early-stage active development and not yet finished. Breaking changes will be avoided when possible, but this cannot be guaranteed.**

A unit testing and mocking library written in C++, for C++, taking advantage of the new C++11 features to write human-readable unit tests in a given-when-then-finally (arrange-act-assert-cleanup) format.

Useful Links
------------

* Wiki Documentation: https://github.com/MorleyDev/UnitTest11/wiki
* Issue Tracker: https://github.com/MorleyDev/UnitTest11/issues?state=open

Build Status
------------

* [![Build Status](https://api.travis-ci.org/MorleyDev/UnitTest11.png)](https://api.travis-ci.org/MorleyDev/UnitTest11) on **GNU G++ 4.6 (Debug, Linux)**
* [![Build Status](https://drone.io/github.com/MorleyDev/UnitTest11/status.png)](https://drone.io/github.com/MorleyDev/UnitTest11/latest) on **GNU G++ 4.8 (Release, Linux)**
* [![Build status](https://ci.appveyor.com/api/projects/status/0m779tplb2ceem86)](https://ci.appveyor.com/project/MorleyDev/unittest11) on **Visual Studio 2013 (Release, Windows)**

Code Coverage
-------------

[![Coverage Status](https://coveralls.io/repos/MorleyDev/UnitTest11/badge.png)](https://coveralls.io/r/MorleyDev/UnitTest11)
UnitTest11
==========
**Please note this library is still in early-stage active development and not yet finished. Breaking changes will be avoided when possible, but this cannot be guaranteed.**
A unit testing and mocking library written in C++, for C++, taking advantage of the new C++11 features to write human-readable unit tests in a given-when-then-finally (arrange-act-assert-cleanup) format.
Useful Links
------------
* Wiki Documentation: https://github.com/MorleyDev/UnitTest11/wiki
* Issue Tracker: https://github.com/MorleyDev/UnitTest11/issues?state=open
Build Status
------------
* [![Build Status](https://api.travis-ci.org/MorleyDev/UnitTest11.png)](https://api.travis-ci.org/MorleyDev/UnitTest11) on **GNU G++ 4.6 (Debug, Linux)**
* [![Build Status](https://drone.io/github.com/MorleyDev/UnitTest11/status.png)](https://drone.io/github.com/MorleyDev/UnitTest11/latest) on **GNU G++ 4.8 (Release, Linux)**
* [![Build status](https://ci.appveyor.com/api/projects/status/0m779tplb2ceem86)](https://ci.appveyor.com/project/MorleyDev/unittest11) on **Visual Studio 2013 (Release, Windows)**
Code Coverage
-------------
[![Coverage Status](https://coveralls.io/repos/MorleyDev/UnitTest11/badge.png)](https://coveralls.io/r/MorleyDev/UnitTest11)
33 changes: 33 additions & 0 deletions UnitTest11.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#ifndef UNITTEST11_HPP
#define UNITTEST11_HPP

#include "UnitTest11/Core.hpp"
#include "UnitTest11/Run.hpp"

#include "UnitTest11/Is/EqualTo.hpp"
#include "UnitTest11/Is/Empty.hpp"
#include "UnitTest11/Is/Any.hpp"
#include "UnitTest11/Is/True.hpp"
#include "UnitTest11/Is/False.hpp"
#include "UnitTest11/Is/Zero.hpp"
#include "UnitTest11/Is/NaN.hpp"
#include "UnitTest11/Is/Infinity.hpp"
#include "UnitTest11/Is/Null.hpp"
#include "UnitTest11/Is/Between.hpp"
#include "UnitTest11/Is/GreaterThan.hpp"
#include "UnitTest11/Is/LessThan.hpp"

#include "UnitTest11/Is/String/Containing.hpp"
#include "UnitTest11/Is/String/BeginningWith.hpp"
#include "UnitTest11/Is/String/EndingWith.hpp"

#include "UnitTest11/Is/Iterable/Of.hpp"
#include "UnitTest11/Is/Iterable/EquivalentTo.hpp"
#include "UnitTest11/Is/Iterable/Containing/Item.hpp"
#include "UnitTest11/Is/Iterable/Containing/Subset.hpp"

#include "UnitTest11/Will/Throw.hpp"
#include "UnitTest11/Will/Pass.hpp"


#endif // UNITTEST11_HPP
14 changes: 14 additions & 0 deletions UnitTest11/Assert/Fail.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef UNITTEST11_ASSERT_FAIL_HPP
#define UNITTEST11_ASSERT_FAIL_HPP

#include <string>

namespace ut11
{
namespace Assert
{
extern void Fail(std::size_t line, std::string file, std::string message);
}
}

#endif // UNITTEST11_ASSERT_FAIL_HPP
29 changes: 29 additions & 0 deletions UnitTest11/Assert/That.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifndef UNITTEST11_ASSERT_THAT_HPP
#define UNITTEST11_ASSERT_THAT_HPP

#include "Fail.hpp"
#include <string>

namespace ut11
{
namespace Assert
{
template<typename Expected, typename Operand>
inline void That(std::size_t line, std::string file, const Expected& expected, const Operand& operand)
{
if ( operand(expected) )
return;
Fail(line, file, operand.GetErrorMessage(expected));
}

template<typename Expected, typename Operand>
inline void That(std::size_t line, std::string file, std::string message, const Expected& expected, const Operand& operand)
{
if ( operand(expected) )
return;
Fail(line, file, message);
}
}
}

#endif // UNITTEST11_ASSERT_THAT_HPP
48 changes: 48 additions & 0 deletions UnitTest11/Category.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Category.hpp
*
* Created on: 10 Jun 2013
* Author: Jason
*/

#ifndef UT11_CATEGORY_HPP_INCLUDED
#define UT11_CATEGORY_HPP_INCLUDED

#include <string>

namespace ut11
{
/*! \brief A category used when declaring a fixture to record what categories that fixture belongs to
*
* DeclareFixture(TestFixtureName)(Category("the_category"));
* DeclareFixture(TestFixtureName)({ Category("the_category"), Category("the_other_category") });
*/
struct Category
{
public:
Category(std::string category)
: m_category(category)
{
}

const std::string& GetName() const
{
return m_category;
}

bool operator==(const Category& other) const
{
return m_category == other.m_category;
}

bool operator<(const Category& other) const
{
return m_category < other.m_category;
}

private:
std::string m_category;
};
}

#endif /* UT11_CATEGORY_HPP_INCLUDED */
12 changes: 12 additions & 0 deletions UnitTest11/Core.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef UT11_CORE_HPP_INCLUDED
#define UT11_CORE_HPP_INCLUDED

#include "TestFixture.hpp"
#include "Assert/That.hpp"
#include "Macros.hpp"

#include "detail/DeclareFixture.hpp"
#include "detail/MockTimesVerify.hpp"
#include "detail/MockVerify.hpp"

#endif // UT11_CORE_HPP_INCLUDED
54 changes: 54 additions & 0 deletions UnitTest11/Is/Any.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#ifndef UNITTEST11_IS_ANY_HPP
#define UNITTEST11_IS_ANY_HPP

#include "../detail/BaseOperand.hpp"
#include <type_traits>
#include <typeinfo>
#include <sstream>

namespace ut11
{
namespace Operands
{
template<typename T>
struct IsAny : public ut11::detail::BaseOperand<IsAny<T>>
{
bool operator()(const T&) const
{
return true;
}

template<typename U> bool operator()(const U&) const
{
return std::is_base_of<T,U>::value || std::is_convertible<U,T>::value;
}

template<typename U> inline std::string GetErrorMessage(const U&) const
{
std::stringstream errorMessage;
errorMessage << "Expected any of class " << (typeid(T).name()) << " or derived but was " << (typeid(U).name());
return errorMessage.str();
}
};
}

namespace Is
{
/*! \brief Operand returns true if Actual is of type U, or is a base of or convertible to type U, otherwise false */
template<typename U> inline Operands::IsAny<U> Any()
{
return Operands::IsAny<U>();
}

namespace Not
{
/*! \brief Operand returns true if Actual is not of type U and it is not a base of or convertible to type U, otherwise false */
template<typename U> inline detail::NotOperand< Operands::IsAny<U> > Any()
{
return !Operands::IsAny<U>();
}
}
}
}

#endif // UNITTEST11_IS_ANY_HPP
57 changes: 57 additions & 0 deletions UnitTest11/Is/Between.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#ifndef UNITTEST11_IS_BETWEEN_HPP
#define UNITTEST11_IS_BETWEEN_HPP

#include "../detail/BaseOperand.hpp"
#include "../utility/ToString.hpp"
#include <sstream>

namespace ut11
{
namespace Operands
{
template<typename U, typename V>
struct IsBetween : public detail::BaseOperand<IsBetween<U,V>>
{
const U& low;
const V& high;

IsBetween(const U& low, const V& high)
: low(low),
high(high)
{
}

template<typename T> inline bool operator()(const T& value) const
{
return low < value && value <= high;
}

template<typename Q> inline std::string GetErrorMessage(const Q& actual) const
{
std::stringstream errorMessage;
errorMessage << "Expected between " << ut11::utility::ToString(low) << " and " << ut11::utility::ToString(high) << " but was " << ut11::utility::ToString(actual);
return errorMessage.str();
}
};
}

namespace Is
{
/*! \brief Operand returns true if Actual is greater than or equal to low, and Actual is less than or equal to high, otherwise false */
template<typename U, typename V> inline Operands::IsBetween<U,V> Between(const U& low, const V& high)
{
return Operands::IsBetween<U,V>(low, high);
}

namespace Not
{
/*! \brief Operand returns true if Actual is less than low, or Actual is greater than high, otherwise false */
template<typename U, typename V> inline detail::NotOperand< Operands::IsBetween<U,V> > Between(const U& low, const V& high)
{
return !Operands::IsBetween<U,V>(low, high);
}
}
}
}

#endif // UNITTEST11_IS_BETWEEN_HPP
Loading