Skip to content

Commit

Permalink
Merge branch 'release/0.1.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
griwes committed Aug 27, 2017
2 parents b2f0d31 + 32e8082 commit d1ad3f0
Show file tree
Hide file tree
Showing 15 changed files with 367 additions and 216 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ mayfly-test
*.kate-swp
*.d
*.so
tags
tests/test
2 changes: 1 addition & 1 deletion LICENCE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Mayfly License

Copyright © 2013-2014 Michał "Griwes" Dominiak
Copyright © 2013-2015 Michał "Griwes" Dominiak

This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CXX = g++
LD = g++
CXXFLAGS += -Os -Wall -std=c++1y -MD -fPIC -Wno-unused-parameter
CXX = c++
LD = c++
CXXFLAGS += -O0 -Wall -std=c++1z -MD -fPIC -Wno-unused-parameter -fno-omit-frame-pointer -Wno-error=unused-variable -g
SOFLAGS += -shared
LDFLAGS +=
LIBRARIES +=
Expand Down Expand Up @@ -34,7 +34,7 @@ INCLUDEDIR ?= $(PREFIX)/include
test: ./tests/test

./tests/test: $(TESTOBJ) $(LIBRARY)
$(LD) $(CXXFLAGS) $(LDFLAGS) $(TESTOBJ) -o $@ $(LIBRARIES) -lboost_system -lboost_iostreams -lboost_program_options -lboost_filesystem -ldl -pthread
$(LD) $(CXXFLAGS) $(LDFLAGS) $(TESTOBJ) -o $@ $(LIBRARIES) -lboost_system -lboost_program_options -lboost_filesystem -ldl -pthread

install: $(LIBRARY) # $(EXECUTABLE)
# @cp $(EXECUTABLE) $(DESTDIR)$(BINDIR)/$(EXECUTABLE)
Expand Down
14 changes: 5 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
# Mayfly

[![Join the chat at https://gitter.im/reaver-project/Mayfly](https://badges.gitter.im/reaver-project/Mayfly.svg)](https://gitter.im/reaver-project/Mayfly?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

Mayfly is the Reaver Project's testing framework. It's meant to be lightweight and
benefit from as many modern C++ features as possible. Primary goals for Mayfly are
to be fast, generate readable outputs (and TeamCity-ready results) and later get
closely integrated with Despayre, the Reaver Project's build system.

## Supported compilers

Currently supported compilers include GCC 4.9+ and Clang 3.5+, both with libstdc++
and libc++.

CI status:

* Clang: <a href="http://ci.reaver-project.org/viewType.html?buildTypeId=mayfly_TestBuildWithClang&guest=1">
<img src="http://ci.reaver-project.org/app/rest/builds/buildType:(id:mayfly_TestBuildWithClang)/statusIcon"></a>
* GCC: <a href="http://ci.reaver-project.org/viewType.html?buildTypeId=mayfly_TestBuildWithGcc&guest=1">
<img src="http://ci.reaver-project.org/app/rest/builds/buildType:(id:mayfly_TestBuildWithGcc)/statusIcon"></a>
Currently supported compilers include GCC 6.1+ and Clang 3.9+, both with libstdc++
and libc++, and with Boost 1.64.0+.

CI status can be checked on [Reaver Project's TeamCity server](http://ci.reaver-project.org/viewType.html?buildTypeId=mayfly_Tests&guest=1).
10 changes: 5 additions & 5 deletions VERSIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
## Release #1

* 0.0.x dev - early development; not versioned
* 0.1.x alpha:
* 0.1.x:
* 0.1.0 - initial release; console reporter, subprocess runner and basic checking macros done at least partially - *finished on 09.06.2014*
* 0.1.1 - nested suites; negative tests; TeamCity reporter; duration measurement for the tests - *finished on 06.09.2014*
* 0.1.2 - refactor subprocess runner to allow printing (almost?) arbitrary output from tests; print files and lines in assertions - *finished on 02.10.2014*
* 0.1.3 - add support for sanitizers: leak, address, memory, thread, ub
* 0.1.3 - align to an officially released Boost.Process - *finished on 27.08.2017*
* 0.1.4 - print values of operands in `MAYFLY_CHECK` and `MAYFLY_REQUIRE`; print info from exceptions thrown in tests
* 0.1.5 - test annotations
* 0.2.x beta:
* 0.1.5 - test tags
* 0.1.6 - add support for sanitizers: leak, address, memory, thread, ub; augment reporters with a function to log standard output from tests in a custom way
* 0.2.x:
* 0.2.0 - support for fixtures
* 0.3.x stable
30 changes: 30 additions & 0 deletions ci
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash

set -xe

if [[ -f /proc/cpuinfo ]]
then
core_number=$(cat /proc/cpuinfo | grep -c ^processor)
else
core_number=2
fi

# this section to be made smarter in the future
# will kinda get automatically smarter once reaverlib itself uses develop and master for stable
function install_package() {
local package=$1
local branch=$2

wget https://github.com/reaver-project/${package}/archive/${branch}.zip
unzip ${branch}.zip
cd ${package}-${branch}
make install # no sudo needed; to be executed in docker as sudo
cd ..
rm -rf ${package}-${branch} ${branch}.zip
}

install_package reaverlib master
install_package mayfly develop

make test -j${core_number} -l${core_number}
./tests/test -j ${core_number} -l 3 -r teamcity
2 changes: 1 addition & 1 deletion doc/licence-cpp-formatted
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Mayfly License
*
* Copyright © 2014 Michał "Griwes" Dominiak
* Copyright © 2015 Michał "Griwes" Dominiak
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
Expand Down
44 changes: 40 additions & 4 deletions include/reaver/mayfly/asserts.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Mayfly License
*
* Copyright © 2014 Michał "Griwes" Dominiak
* Copyright © 2014-2015 Michał "Griwes" Dominiak
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
Expand Down Expand Up @@ -138,11 +138,35 @@ namespace reaver
std::size_t _assertions_to_fail;
};

inline boost::optional<_assertions_logger> & _local_assertions_logger()
inline boost::optional<_assertions_logger> & _local_assertions_logger(std::thread::id id)
{
static std::unordered_map<std::thread::id, boost::optional<_assertions_logger>> loggers;

return loggers[std::this_thread::get_id()];
return loggers[id];
}

inline auto _main_test_thread(boost::optional<std::thread::id> set = {})
{
static std::unordered_map<std::thread::id, std::thread::id> map;

auto id = std::this_thread::get_id();

if (set)
{
map[id] = *set;
}

if (map.find(id) == map.end())
{
map[id] = id;
}

return map[id];
}

inline auto & _local_assertions_logger()
{
return _local_assertions_logger(_main_test_thread());
}
}

Expand Down Expand Up @@ -186,7 +210,9 @@ namespace reaver

#define MAYFLY_REQUIRE_THROWS(...) \
try { __VA_ARGS__; ::reaver::mayfly::log_assertion(::std::string{ #__VA_ARGS__ " should have thrown, but didn't" } \
+ " (in " + __FILE__ + " at line " + ::std::to_string(__LINE__) + ")", true); } catch (...) {}
+ " (in " + __FILE__ + " at line " + ::std::to_string(__LINE__) + ")", true); } \
catch (::reaver::mayfly::assertions_failed & ex) { throw; } \
catch (...) {}

#define MAYFLY_CHECK_THROWS(...) \
try { __VA_ARGS__; ::reaver::mayfly::log_assertion(::std::string{ #__VA_ARGS__ " should have thrown, but didn't"} \
Expand All @@ -196,6 +222,7 @@ namespace reaver
try { __VA_ARGS__; ::reaver::mayfly::log_assertion(::std::string{ #__VA_ARGS__ " should have thrown " #type ", but didn't throw anything" } \
+ " (in " + __FILE__ + " at line " + ::std::to_string(__LINE__) + ")", true); } \
catch (type & e) {} \
catch (::reaver::mayfly::assertions_failed & ex) { throw; } \
catch (...) { ::reaver::mayfly::log_assertion(::std::string{ #__VA_ARGS__ " should have thrown " #type ", but has thrown something else" } \
+ " (in " + __FILE__ + " at line " + ::std::to_string(__LINE__) + ")", true); }

Expand All @@ -213,3 +240,12 @@ namespace reaver
#define MAYFLY_CHECK_NOTHROW(...) \
try { __VA_ARGS__; } catch (...) { ::reaver::mayfly::log_assertion(::std::string{ #__VA_ARGS__ " shouldn't have thrown" } \
+ " (in " + __FILE__ + " at line " + ::std::to_string(__LINE__) + ")"); }

// multithreaded checks support

#define MAYFLY_MAIN_THREAD \
auto _mayfly_main_thread_logger = std::this_thread::get_id()

#define MAYFLY_THREAD \
::reaver::mayfly::_detail::_main_test_thread(_mayfly_main_thread_logger)

30 changes: 16 additions & 14 deletions include/reaver/mayfly/console.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Mayfly License
*
* Copyright © 2014 Michał "Griwes" Dominiak
* Copyright © 2014-2015 Michał "Griwes" Dominiak
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
Expand Down Expand Up @@ -81,7 +81,7 @@ namespace reaver
}
}

virtual void summary(const std::vector<std::pair<testcase_status, std::string>> & summary, std::uintmax_t passed, std::uintmax_t total) const override
virtual void summary(const tests_summary & summary) const override
{
auto && white = style::style(style::colors::bgray, style::colors::def, style::styles::bold);
auto && red = style::style(style::colors::bred, style::colors::def, style::styles::bold);
Expand All @@ -91,12 +91,12 @@ namespace reaver
std::uintmax_t crashed = 0;
std::uintmax_t timed_out = 0;

if (summary.size())
if (summary.failed_tests.size())
{
reaver::logger::dlog() << white << "\nSummary:";
}

for (const auto & elem : summary)
for (const auto & elem : summary.failed_tests)
{
switch (elem.first)
{
Expand All @@ -119,43 +119,45 @@ namespace reaver
}
}

if (summary.size())
if (summary.failed_tests.size())
{
reaver::logger::dlog();
}

if (!total)
if (!summary.total)
{
reaver::logger::dlog() << white << "No tests found.";
return;
}

if (passed == total)
if (summary.passed == summary.total)
{
reaver::logger::dlog() << green << "All tests passed!";
}

auto width = std::to_string(total).size();
auto width = std::to_string(summary.total).size();

if (passed)
if (summary.passed)
{
reaver::logger::dlog() << green << "Passed" << white << ": " << to_string_width(passed, width) << " / " << total;
reaver::logger::dlog() << green << "Passed" << white << ": " << to_string_width(summary.passed, width) << " / " << summary.total;
}

if (total - passed - crashed - timed_out)
if (summary.total - summary.passed - crashed - timed_out)
{
reaver::logger::dlog() << red << "Failed" << white << ": " << to_string_width(total - passed - crashed - timed_out, width) << " / " << total;
reaver::logger::dlog() << red << "Failed" << white << ": " << to_string_width(summary.total - summary.passed - crashed - timed_out, width) << " / " << summary.total;
}

if (crashed)
{
reaver::logger::dlog() << red << "Crashed" << white << ": " << to_string_width(crashed, width) << " / " << total;
reaver::logger::dlog() << red << "Crashed" << white << ": " << to_string_width(crashed, width) << " / " << summary.total;
}

if (timed_out)
{
reaver::logger::dlog() << yellow << "Timed out" << white << ": " << to_string_width(timed_out, width) << " / " << total;
reaver::logger::dlog() << yellow << "Timed out" << white << ": " << to_string_width(timed_out, width) << " / " << summary.total;
}

reaver::logger::dlog() << green << "Clock time taken" << white << ": " << summary.actual_time.count() << "ms.";
}
};

Expand Down
18 changes: 14 additions & 4 deletions include/reaver/mayfly/reporter.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Mayfly License
*
* Copyright © 2014 Michał "Griwes" Dominiak
* Copyright © 2014-2015 Michał "Griwes" Dominiak
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
Expand Down Expand Up @@ -43,6 +43,14 @@ namespace reaver

enum class testcase_status;

struct tests_summary
{
const std::vector<std::pair<testcase_status, std::string>> & failed_tests;
std::uintmax_t passed;
std::uintmax_t total;
std::chrono::milliseconds actual_time{ 0 };
};

class invalid_testcase_status : public exception
{
public:
Expand All @@ -55,12 +63,14 @@ namespace reaver
class reporter
{
public:
virtual ~reporter() = default;

virtual void suite_started(const suite &) const = 0;
virtual void suite_finished(const suite &) const = 0;
virtual void test_started(const testcase &) const = 0;
virtual void test_finished(const testcase_result &) const = 0;

virtual void summary(const std::vector<std::pair<testcase_status, std::string>> &, std::uintmax_t passed, std::uintmax_t total) const = 0;
virtual void summary(const tests_summary &) const = 0;

void lock() const
{
Expand Down Expand Up @@ -115,11 +125,11 @@ namespace reaver
}
}

virtual void summary(const std::vector<std::pair<testcase_status, std::string>> & summary, std::uintmax_t passed, std::uintmax_t total) const override
virtual void summary(const tests_summary & summary) const override
{
for (const auto & r : _reporters)
{
r.get().summary(summary, passed, total);
r.get().summary(summary);
}
}

Expand Down
Loading

0 comments on commit d1ad3f0

Please sign in to comment.