Skip to content

Commit

Permalink
Merge master into release/1
Browse files Browse the repository at this point in the history
--HG--
branch : release
  • Loading branch information
kazssym committed Jul 2, 2020
2 parents 8d9d24c + cd7ed0f commit c49f426
Show file tree
Hide file tree
Showing 54 changed files with 456 additions and 8,800 deletions.
1 change: 1 addition & 0 deletions .hgtags
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
25ee843f907eb7376ad6f1af1aa15d40622062bb release/1-alpha.1
9692febc64935c4c6db640dd9c5c1244dec3d43c release/1-alpha.2
6 changes: 2 additions & 4 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
"compilerPath": "/usr/bin/gcc",
"includePath": [
"${workspaceFolder}",
"${workspaceFolder}/libcppunitx",
"${workspaceFolder}/libltdl"
"${workspaceFolder}/libcppunitx"
],
"defines": [
"HAVE_CONFIG_H"
Expand All @@ -25,8 +24,7 @@
"intelliSenseMode": "msvc-x64",
"includePath": [
"${workspaceFolder}",
"${workspaceFolder}/libcppunitx",
"${workspaceFolder}/libltdl"
"${workspaceFolder}/libcppunitx"
],
"defines": [
],
Expand Down
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ACLOCAL_AMFLAGS = -Im4

EXTRA_DIST = README.md

SUBDIRS = libltdl libcppunitx test doc
SUBDIRS = libcppunitx test doc

dist-hook:: $(distdir)/SHA256SUMS
if test -n "$$GPG_USERNAME"; then \
Expand Down
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# this notice are preserved. This file is offered as-is, without any warranty.
---
variables:
package.distName: cppunitx-1-alpha.2
package.distName: cppunitx-1-alpha.3
trigger:
- master
- release/*
Expand Down
11 changes: 6 additions & 5 deletions configure.ac
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.69])
AC_INIT([C++UnitX], [1-alpha.2],
AC_INIT([C++UnitX], [1-alpha.3],
[https://bitbucket.org/kazssym/cppunitx/issues/new], [cppunitx],
[https://www.vx68k.org/cppunitx])
AC_CONFIG_SRCDIR([libcppunitx/registry.cpp])
AC_CONFIG_AUX_DIR([build-aux])
AC_CONFIG_MACRO_DIR([m4])
LT_PREREQ([2.4.6])
LT_INIT([dlopen])
LT_CONFIG_LTDL_DIR([libltdl])
LTDL_INIT([recursive])
LT_INIT
AM_INIT_AUTOMAKE([foreign no-define subdir-objects tar-ustar])
# Checks for programs.
AC_PROG_CC
AC_PROG_CXX
# Checks for libraries.
AC_SEARCH_LIBS([dlopen], [dl])
# Checks for header files.
AC_CHECK_HEADERS([dlfcn.h])
# Checks for typedefs, structures, and compiler characteristics.
# Checks for library functions.
AC_CHECK_FUNCS([dlopen])
# Configuration actions.
AC_CONFIG_FILES([Makefile libcppunitx/Makefile
libltdl/Makefile test/Makefile doc/Makefile])
test/Makefile doc/Makefile])
AC_CONFIG_HEADERS([config.h])
AC_OUTPUT
10 changes: 5 additions & 5 deletions libcppunitx/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
## Process this file with automake to produce Makefile.in.

AM_CPPFLAGS = -D_CPPUNITX_IMPLEMENTATION \
$(LTDLINCL)
AM_CPPFLAGS = -D_LIBCPPUNITX

pkgconfigdir = $(libdir)/pkgconfig

Expand All @@ -24,17 +23,18 @@ bits/cppunitx/registry.h \
bits/cppunitx/test.h \
bits/cppunitx/driver.h \
bits/cppunitx/module.h
noinst_HEADERS = ltdl_utility.h
noinst_HEADERS = \
module_loader.h

libcppunitx_la_LDFLAGS = -version-info 0:0:0
libcppunitx_la_LIBADD = $(LIBLTDL)
libcppunitx_la_SOURCES = \
exception.cpp \
assertion.cpp \
registry.cpp \
test.cpp \
context.cpp \
driver.cpp
driver.cpp \
module_loader.cpp

CLEANFILES = $(pkgconfig_DATA)

Expand Down
14 changes: 12 additions & 2 deletions libcppunitx/assertion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,26 @@

using namespace cppunitx;

void assertion::fail(const char *message)
{
std::string description = "Assertion failed";
if (message != nullptr) {
description.append(": ");
description.append(message);
}
throw AssertionFailedException(description);
}

void assertion::assertNull(const volatile void *ptr, const char *message)
{
if (ptr != nullptr) {
throw AssertionError("Pointer is not null");
fail("Pointer is not null");
}
}

void assertion::assertNotNull(const volatile void *ptr, const char *message)
{
if (ptr == nullptr) {
throw AssertionError("Pointer is null");
fail("Pointer is null");
}
}
8 changes: 3 additions & 5 deletions libcppunitx/bits/cppunitx.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,19 @@
#ifndef _CPPUNITX_H
#define _CPPUNITX_H 1

#ifndef _CPPUNITX_PUBLIC
#if _WIN32
#if CPPUNITX_DLL || _CPPUNITX_IMPLEMENTATION
#if _LIBCPPUNITX && DLL_EXPORT
#define _CPPUNITX_PUBLIC __declspec(dllexport)
#else
#define _CPPUNITX_PUBLIC __declspec(dllimport)
#endif
#else /* !_WIN32 */
#else /* not _WIN32 */
#if defined __has_attribute
#if __has_attribute(visibility)
#define _CPPUNITX_PUBLIC __attribute__((visibility("default")))
#endif
#endif /* defined __has_attribute */
#endif /* !_WIN32 */
#endif
#endif /* not _WIN32 */

#ifndef _CPPUNITX_PUBLIC
#define _CPPUNITX_PUBLIC
Expand Down
56 changes: 56 additions & 0 deletions libcppunitx/bits/cppunitx/assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,68 @@
#include <bits/cppunitx.h>

#include <memory>
#include <string>
#include <cstdint>

namespace cppunitx
{
namespace assertion
{
/**
* Throws an `AssertionFailedException` object.
*
* @param message a message string to be given to the exception
*/
_CPPUNITX_PUBLIC void fail(const char *message = nullptr);

/**
* Throws an `AssertionFailedException` object.
*
* @param message a message string to be given to the exception
*/
inline void fail(const std::string &message)
{
return fail(message.c_str());
}

template<class T, class U>
void assertEqual(T x, U y, const char *message = nullptr)
{
if (x != y) {
std::string description = "Values must be equal";
if (message != nullptr) {
description.append(": ");
description.append(message);
}
fail(description);
}
}

template<class T, class U>
inline void assertEqual(T x, U y, const std::string &message)
{
assertEqual(x, y, message.c_str());
}

template<class T, class U>
void assertNotEqual(T x, U y, const char *message = nullptr)
{
if (x == y) {
std::string description = "Values must not be equal";
if (message != nullptr) {
description.append(": ");
description.append(message);
}
fail(description);
}
}

template<class T, class U>
inline void assertNotEqual(T x, U y, const std::string &message)
{
assertNotEqual(x, y, message.c_str());
}

_CPPUNITX_PUBLIC void assertNull(const volatile void *ptr,
const char *message = nullptr);

Expand Down
12 changes: 8 additions & 4 deletions libcppunitx/bits/cppunitx/exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,25 @@

namespace cppunitx
{
class _CPPUNITX_PUBLIC AssertionError : public std::runtime_error
class _CPPUNITX_PUBLIC AssertionFailedException: public std::runtime_error
{
using inherited = runtime_error;

public:
explicit AssertionError(const char *message);
explicit AssertionFailedException(const char *message);

explicit AssertionError(const std::string &message);
explicit AssertionFailedException(const std::string &message);

AssertionFailedException(const AssertionFailedException &);

AssertionFailedException &operator =(const AssertionFailedException &);

public:
/// Destructs an `AssertionError` object.
///
/// This destructor is defined out of line so that this class can be
/// provided by a shared library.
virtual ~AssertionError() noexcept;
virtual ~AssertionFailedException() noexcept;
};
}

Expand Down
12 changes: 6 additions & 6 deletions libcppunitx/bits/cppunitx/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,27 @@
#ifndef _CPPUNITX_MODULE_H
#define _CPPUNITX_MODULE_H 1

#if !defined SUITE
#error "The required macro 'SUITE' not defined"
#if !defined MODULE
#error "Macro 'MODULE' not defined"
#endif

#include <cppunitx/framework>
#include <bits/cppunitx.h>

#define _CPPUNITX_LT_NAME(M, F) __CPPUNITX_LT_NAME(M, F)
#define __CPPUNITX_LT_NAME(M, F) M ## _LTX_ ## F
#define __CPPUNITX_LT_NAME(M, F) F

#define cppunitx_registry _CPPUNITX_LT_NAME(SUITE, cppunitx_registry)
#define cppunitx_registry _CPPUNITX_LT_NAME(MODULE, cppunitx_registry)

extern "C" cppunitx::TestRegistry *cppunitx_registry();

#if MODULE_MAIN

class SUITE;
class MODULE;

cppunitx::TestRegistry *cppunitx_registry()
{
return cppunitx::TestRegistry::getInstance<class SUITE>().get();
return cppunitx::TestRegistry::getInstance<MODULE>().get();
}

#endif /* MODULE_MAIN */
Expand Down
12 changes: 6 additions & 6 deletions libcppunitx/bits/cppunitx/registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
#include <string>
#include <bits/cppunitx.h>

#if defined SUITE
#if defined MODULE
// This makes the suite name available as a type name.
class SUITE;
#define _CPPUNITX_DEFAULT_SUITE class ::SUITE
class MODULE;
#define _CPPUNITX_TEST_SUITE class ::MODULE
#endif

#ifndef _CPPUNITX_DEFAULT_SUITE
#define _CPPUNITX_DEFAULT_SUITE void
#ifndef _CPPUNITX_TEST_SUITE
#define _CPPUNITX_TEST_SUITE void
#endif

namespace cppunitx
Expand Down Expand Up @@ -134,7 +134,7 @@ namespace cppunitx
protected:
static std::shared_ptr<TestRegistry> getRegistry()
{
return TestRegistry::getInstance<_CPPUNITX_DEFAULT_SUITE>();
return TestRegistry::getInstance<_CPPUNITX_TEST_SUITE>();
}

public:
Expand Down
11 changes: 7 additions & 4 deletions libcppunitx/driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <locale>
#include <stdexcept>
#include <cstdio>
#include "ltdl_utility.h"
#include "module_loader.h"

using std::string;
using std::exception;
Expand Down Expand Up @@ -77,10 +77,13 @@ void TestDriver::run(const char *const suiteName)
{
using GetRegistryFunction = TestRegistry *();

ltdl::library_path path {"."};
ltdl::module suite {suiteName};
std::unique_ptr<ltmodule> suite {new ltmodule(suiteName)};
if (not(*suite)) {
throw runtime_error(string(suiteName) + ": File not loadable");
}

auto getRegistry = reinterpret_cast<GetRegistryFunction *>(
lt_dlsym(suite, "cppunitx_registry"));
suite->sym("cppunitx_registry"));
if (getRegistry == nullptr) {
throw runtime_error(string(suiteName) + ": Not test suite module");
}
Expand Down
29 changes: 24 additions & 5 deletions libcppunitx/exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,35 @@

using namespace cppunitx;

AssertionError::AssertionError(const char *message)
: inherited {message}
AssertionFailedException::AssertionFailedException(const char *message)
:
inherited(message)
{
// Nothing to do.
}

AssertionError::AssertionError(const std::string &message)
: inherited {message}
AssertionFailedException::AssertionFailedException(const std::string &message)
:
inherited(message)
{
// Nothing to do.
}

AssertionError::~AssertionError() noexcept
AssertionFailedException::AssertionFailedException(
const AssertionFailedException &other)
:
inherited(other)
{
// Nothing to do.
}

auto AssertionFailedException::operator =(const AssertionFailedException &other)
-> AssertionFailedException &
{
*(inherited *)this = other;
return *this;
}

AssertionFailedException::~AssertionFailedException() noexcept
{
}
Loading

0 comments on commit c49f426

Please sign in to comment.