Skip to content

Commit

Permalink
Merge pull request #49 from banditcpp/prepare-v5.0.0
Browse files Browse the repository at this point in the history
Prepare v5.0.0
  • Loading branch information
sbeyer committed Mar 3, 2020
2 parents cd0761b + 23ed111 commit 3faaff8
Show file tree
Hide file tree
Showing 45 changed files with 248 additions and 317 deletions.
2 changes: 0 additions & 2 deletions .appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
environment:
matrix:
- CXX_STANDARD: 98
- CXX_STANDARD: 03
- CXX_STANDARD: 11
- CXX_STANDARD: 14

Expand Down
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# before committing your changes.
---
Language: Cpp
Standard: Cpp03
Standard: Cpp11

ColumnLimit: 0
IndentWidth: 2
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
image: docker://banditcpp/build-environments:debian-bullseye-compilers
strategy:
matrix:
cxx-standard: ["98", "03", "11", "14", "17"]
cxx-standard: ["11", "14", "17"]
compiler-env: ["CC=gcc-9 CXX=g++-9", "CC=clang-9 CXX=clang++-9"]
steps:
- name: Clone and checkout commit
Expand All @@ -22,7 +22,7 @@ jobs:
runs-on: windows-2019
strategy:
matrix:
# C++98, C++03 and C++11 is NOT supported by MSVC 2019
# C++11 is NOT supported by MSVC 2019
cxx-standard: ["14", "17"]
steps:
- name: Clone and checkout commit
Expand Down
13 changes: 0 additions & 13 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,6 @@ services:
- docker

env:
- DOCKER_TAG=snowhouse-minimum CXX_STANDARD=98 CC=gcc-4.4 CXX=g++-4.4
- DOCKER_TAG=snowhouse-minimum CXX_STANDARD=98 CC=gcc-4.6 CXX=g++-4.6
- DOCKER_TAG=snowhouse-minimum CXX_STANDARD=03 CC=gcc-4.6 CXX=g++-4.6
- DOCKER_TAG=snowhouse-minimum CXX_STANDARD=98 CC=clang CXX=clang++
- DOCKER_TAG=snowhouse-minimum CXX_STANDARD=03 CC=clang CXX=clang++
- DOCKER_TAG=snowhouse-minimum CXX_STANDARD=11 CC=clang CXX=clang++
- DOCKER_TAG=debian-jessie-compilers CXX_STANDARD=98 CC=gcc-4.8 CXX=g++-4.8
- DOCKER_TAG=debian-jessie-compilers CXX_STANDARD=03 CC=gcc-4.8 CXX=g++-4.8
- DOCKER_TAG=debian-jessie-compilers CXX_STANDARD=11 CC=gcc-4.8 CXX=g++-4.8
- DOCKER_TAG=debian-jessie-compilers CXX_STANDARD=98 CC=gcc-4.9 CXX=g++-4.9
- DOCKER_TAG=debian-jessie-compilers CXX_STANDARD=11 CC=gcc-4.9 CXX=g++-4.9
- DOCKER_TAG=debian-jessie-compilers CXX_STANDARD=98 CC=clang-3.5 CXX=clang++-3.5
- DOCKER_TAG=debian-jessie-compilers CXX_STANDARD=11 CC=clang-3.5 CXX=clang++-3.5
- DOCKER_TAG=debian-stretch-compilers CXX_STANDARD=11 CC=gcc-6 CXX=g++-6
- DOCKER_TAG=debian-stretch-compilers CXX_STANDARD=11 CC=clang-3.9 CXX=clang++-3.9

Expand Down
41 changes: 13 additions & 28 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 3.1)

project(snowhouse)

option(SNOWHOUSE_BUILD_TESTS "Build the Snowhouse tests" OFF)
option(SNOWHOUSE_RUN_TESTS "Run the Snowhouse tests" OFF)
set(SNOWHOUSE_CXX_STANDARD "C++03" CACHE STRING "The C++ standard the examples are compiled with")
set_property(CACHE SNOWHOUSE_CXX_STANDARD PROPERTY STRINGS "C++98" "C++03" "C++11" "C++14" "C++17")
set(SNOWHOUSE_CXX_STANDARD "C++11" CACHE STRING "The C++ standard the examples are compiled with")
set_property(CACHE SNOWHOUSE_CXX_STANDARD PROPERTY STRINGS "C++11" "C++14" "C++17")

if (NOT ${CMAKE_VERSION} VERSION_LESS "3.0.0")
add_library(snowhouse INTERFACE)
target_include_directories(snowhouse INTERFACE include)
endif()
add_library(snowhouse INTERFACE)
target_include_directories(snowhouse INTERFACE include)

if(SNOWHOUSE_CXX_STANDARD STREQUAL "C++98")
set(std_name "c++98")
elseif(SNOWHOUSE_CXX_STANDARD STREQUAL "C++03")
set(std_name "c++03")
elseif(SNOWHOUSE_CXX_STANDARD STREQUAL "C++11")
set(std_name "c++11")
if(SNOWHOUSE_CXX_STANDARD STREQUAL "C++11")
set(CMAKE_CXX_STANDARD 11)
elseif(SNOWHOUSE_CXX_STANDARD STREQUAL "C++14")
set(std_name "c++14")
set(CMAKE_CXX_STANDARD 14)
elseif(SNOWHOUSE_CXX_STANDARD STREQUAL "C++17")
set(std_name "c++17")
set(CMAKE_CXX_STANDARD 17)
else()
message(WARNING "C++ standard \"${SNOWHOUSE_CXX_STANDARD}\" not known, falling back to default")
endif()
Expand All @@ -30,28 +24,19 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ./bin)

if (MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /MP ")
if(DEFINED std_name)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:${std_name}")
endif()
else()
# Assume GCC-style arguments
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wfatal-errors -Wall -Wextra -Werror -Wfloat-equal -Wundef -Wendif-labels -Wshadow -pedantic-errors")

if(DEFINED std_name)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=${std_name}")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \
-Wall -Wextra -pedantic -Wdeprecated -Wdeprecated-declarations -Wnon-virtual-dtor \
-Wshadow -Wfloat-equal -Wundef -Wendif-labels -Wno-error=unknown-pragmas")
endif()

message(STATUS "C++ compiler flags: ${CMAKE_CXX_FLAGS}")

if (SNOWHOUSE_BUILD_TESTS)
FILE(GLOB SnowhouseSpecSourceFiles example/*.cpp)
add_executable(snowhouse-tests ${SnowhouseSpecSourceFiles})
if (NOT ${CMAKE_VERSION} VERSION_LESS "3.0.0")
target_link_libraries(snowhouse-tests PRIVATE snowhouse)
else()
include_directories("${PROJECT_SOURCE_DIR}/include")
endif()
target_link_libraries(snowhouse-tests PRIVATE snowhouse)
endif()

if (SNOWHOUSE_BUILD_TESTS AND SNOWHOUSE_RUN_TESTS)
Expand Down
30 changes: 21 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,26 @@ snowhouse
An assertion library for C++

Snowhouse is a stand-alone assertion framework for C++.

It is a header-only library.
You can simply use the `headers-only` branch as a submodule:

Snowhouse requires a C++11-compatible compiler since version 5.0.0.
Feel free to use Snowhouse with major version 4 if you want to use it
in a pre-C++11 setting.
Major version 4 is still maintained in the `maint-v4` branch (bug fixes, etc.).

For inclusion in your projects, you have several options:

a) You can copy the code and just use it as the license allows.

b) You can use the `headers-only` branch as a submodule:

```sh
git submodule add -b headers-only https://github.com/banditcpp/snowhouse snowhouse
git submodule update --init --recursive
```

As an alternative, CMake >= 3.0 users can use Snowhouse with the provided library target.
c) If you use CMake >= 3.1 in your project,
you can use Snowhouse with the provided library target.
Assuming you have cloned the `master` branch into a `snowhouse` subdirectory,
your `CMakeLists.txt` might contain lines like the following:

Expand All @@ -43,10 +53,10 @@ int main()
{
AssertThat(12, Is().LessThan(11).And().GreaterThan(99));
}
catch(const AssertionException& ex)
catch (const AssertionException& ex)
{
std::cout << "Apparently this failed:" << std::endl;
std::cout << ex.GetMessage() << std::endl;
std::cout << ex.what() << std::endl;
}

return 0;
Expand Down Expand Up @@ -166,9 +176,6 @@ AssertThat(x, IsNull());
AssertThat(x, Is().Null());
```

Note that this feature is only available for C++11-compliant compilers.
In this case, the `SNOWHOUSE_HAS_NULLPTR` macro is defined.

### String Constraints

String assertions in Snowhouse are used to verify the values of
Expand Down Expand Up @@ -518,6 +525,11 @@ Compatibility-breaking changes since version 3.0.0:
Booleans are now displayed as `true` or `false`.
Strings are put into quotation marks for improved readability.

* Since version 5.0.0, the support for C++ versions prior to C++11 are dropped.
The definition of the macro `SNOWHOUSE_HAS_NULLPTR` is removed.
Our exceptions are now derived from the `std::exception` hierarchy,
thus their method names changed.

## Contributing

The development of Snowhouse takes place on [GitHub](//github.com/banditcpp/snowhouse).
Expand All @@ -533,7 +545,7 @@ Please make sure to be consistent with the project's coding style.
The `.clang-format` file allows easy checking and implementation of the
coding style.

C++ code should comply to C++98, C++03- and C++11.
C++ code should comply to C++11.
Please use `__cplusplus` guards if you want to use language features of
a certain C++ version.

Expand Down
6 changes: 2 additions & 4 deletions example/basic_assertions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ void BasicAssertions()
}
catch (const AssertionException& e)
{
line = e.GetLineNumber();
file = e.GetFilename();
line = e.line();
file = e.file();
}

AssertThat(line, Equals(32));
Expand Down Expand Up @@ -180,7 +180,6 @@ void BasicAssertions()
"Expected: less than or equal to 5\nActual: 6\n");
}

#ifdef SNOWHOUSE_HAS_NULLPTR
it("handles IsNull()");
{
AssertThat(nullptr, IsNull());
Expand Down Expand Up @@ -220,5 +219,4 @@ void BasicAssertions()

AssertTestFails(AssertThat(nullptr, !IsNull()), message.str());
}
#endif
}
15 changes: 14 additions & 1 deletion example/exceptions_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ struct ClassWithExceptions
}
};

struct ExpectedException : public std::exception
{
const char* what() const noexcept override
{
return "Description of the exception we expected";
}
};

void ExceptionTests()
{
ClassWithExceptions objectUnderTest;
Expand Down Expand Up @@ -87,6 +95,11 @@ void ExceptionTests()
AssertThrows(std::logic_error, objectUnderTest.LogicError());
}
AssertThrows(AssertionException, LastException<std::logic_error>());
AssertThat(LastException<AssertionException>().GetMessage(), Contains("No exception was stored"));
AssertThat(LastException<AssertionException>().what(), Contains("No exception was stored"));
}

it("prints description of unwanted exception");
{
AssertTestFails(AssertThrows(ExpectedException, objectUnderTest.LogicError()), "Expected ExpectedException. Wrong exception was thrown. Description of unwanted exception: not logical!");
}
}
2 changes: 1 addition & 1 deletion example/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ int main()
catch (const AssertionException& e)
{
std::cout << "Tests failed!" << std::endl;
std::cout << e.GetMessage() << std::endl;
std::cout << e.what() << std::endl;
return 1;
}

Expand Down
2 changes: 1 addition & 1 deletion example/operator_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void OperatorTests()
it("yields error on malformed expression");
{
AssertTestFails(AssertThat(4, Is().Not()),
"The expression contains a not operator without any operand");
"The expression contains a \"not\" operator without any operand");
}

it("handles failing EqualsWithDelta() when larger than delta");
Expand Down
31 changes: 10 additions & 21 deletions example/sequence_container_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include <deque>
#include <list>
#include <set>
#include <array>
#include <forward_list>

#include "tests.h"

Expand Down Expand Up @@ -38,10 +40,6 @@ void insert_numbers(std::set<int>& container)
container.insert(8);
}

#if __cplusplus >= 201103L
#include <array>
#include <forward_list>

template<>
void insert_numbers(std::array<int, 5>& container)
{
Expand All @@ -61,7 +59,6 @@ void insert_numbers(std::forward_list<int>& container)
container.push_front(2);
container.push_front(1);
}
#endif

template<typename T>
static void TestHasAll(const T& container)
Expand All @@ -78,7 +75,7 @@ static void TestHasAll(const T& container)

it("handles invalid expression after All()");
{
AssertTestFails(AssertThat(container, Has().All().Not()), "The expression contains a not operator without any operand");
AssertTestFails(AssertThat(container, Has().All().Not()), "The expression contains a \"not\" operator without any operand");
}

it("handles no expression after All()");
Expand All @@ -87,13 +84,11 @@ static void TestHasAll(const T& container)
}
}

#if __cplusplus >= 201103L
template<>
void TestHasAll(const std::forward_list<int>&)
{
// The constraint is size-based but there is no size() method available
}
#endif

template<typename T>
static void TestLength(const T& container)
Expand All @@ -119,13 +114,11 @@ static void TestLength(const T& container)
}
}

#if __cplusplus >= 201103L
template<>
void TestLength(const std::forward_list<int>&)
{
// There is no size() method available
}
#endif

template<typename T, typename TEmpty>
static void TestEmpty(const T& container, const TEmpty& is_empty)
Expand Down Expand Up @@ -158,14 +151,12 @@ void TestEmpty(const T& container)
TestEmpty(container, is_empty);
}

#if __cplusplus >= 201103L
template<>
void TestEmpty(const std::array<int, 5>& container)
{
std::array<int, 0> is_empty;
TestEmpty(container, is_empty);
}
#endif

template<typename T>
static void SequenceContainerActual()
Expand Down Expand Up @@ -275,25 +266,23 @@ static void SequenceContainerActual()
void SequenceContainerTests()
{
describe("Sequence containers (std::vector)");
SequenceContainerActual<std::vector<int> >();
SequenceContainerActual<std::vector<int>>();

describe("Sequence containers (std::list)");
SequenceContainerActual<std::list<int> >();
SequenceContainerActual<std::list<int>>();

describe("Sequence containers (std::deque)");
SequenceContainerActual<std::deque<int> >();
SequenceContainerActual<std::deque<int>>();

describe("Sequence containers (std::set)");
SequenceContainerActual<std::set<int> >();
SequenceContainerActual<std::set<int>>();

describe("Sequence containers (std::multiset)");
SequenceContainerActual<std::multiset<int> >();
SequenceContainerActual<std::multiset<int>>();

#if __cplusplus >= 201103L
describe("Sequence containers (std::array)");
SequenceContainerActual<std::array<int, 5> >();
SequenceContainerActual<std::array<int, 5>>();

describe("Sequence containers (std::forward_list)");
SequenceContainerActual<std::forward_list<int> >();
#endif
SequenceContainerActual<std::forward_list<int>>();
}
2 changes: 1 addition & 1 deletion example/tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
} \
catch (const AssertionException& exception_from_snowhouse_assertion) \
{ \
SNOWHOUSE_INTERNAL_expected_error = exception_from_snowhouse_assertion.GetMessage(); \
SNOWHOUSE_INTERNAL_expected_error = exception_from_snowhouse_assertion.what(); \
} \
AssertThat(SNOWHOUSE_INTERNAL_expected_error, Is().Containing(expected_error_text));
// clang-format on
Expand Down
Loading

0 comments on commit 3faaff8

Please sign in to comment.