Skip to content
Merged
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
22 changes: 15 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ jobs:
build-type: Release
build-shared: 'ON'
cxx-standard: 17
cc_compiler: clang
cxx_compiler: clang++
cxx-compiler: clang++
cxx-flags: ''
cc-compiler: clang
compiler-desc: clang
os: ubuntu-latest

Expand All @@ -42,8 +43,9 @@ jobs:
build-type: Debug
build-shared: 'ON'
cxx-standard: 17
cc_compiler: clang
cxx_compiler: clang++
cxx-compiler: clang++
cxx-flags: ''
cc-compiler: clang
compiler-desc: clang
os: ubuntu-latest

Expand All @@ -55,6 +57,7 @@ jobs:
build-shared: 'ON'
cxx-standard: 17
cxx-compiler: g++
cxx-flags: ''
cc-compiler: gcc
compiler-desc: gcc
os: ubuntu-latest
Expand All @@ -67,6 +70,7 @@ jobs:
build-shared: 'ON'
cxx-standard: 17
cxx-compiler: g++
cxx-flags: ''
cc-compiler: gcc
compiler-desc: gcc
os: ubuntu-latest
Expand Down Expand Up @@ -99,7 +103,7 @@ jobs:
working-directory: _build
- name: Test
run: |
ctest --build-config ${{ matrix.build_type }} --verbose
ctest --build-config ${{ matrix.build-type }} --verbose
working-directory: _build

# ---------------------------------------------------------------------------
Expand All @@ -119,6 +123,7 @@ jobs:
build-type: Release
build-shared: 'ON'
cxx-standard: 17
cxx-flags: ''
os: macos-latest

# Debug
Expand All @@ -127,6 +132,7 @@ jobs:
build-shared: 'ON'
build-docs: 'OFF'
cxx-standard: 17
cxx-flags: ''
os: macos-latest

steps:
Expand Down Expand Up @@ -155,7 +161,7 @@ jobs:
working-directory: _build
- name: Test
run: |
ctest --build-config ${{ matrix.build_type }} --verbose
ctest --build-config ${{ matrix.build-type }} --verbose
working-directory: _build

# ---------------------------------------------------------------------------
Expand All @@ -175,13 +181,15 @@ jobs:
build-type: Release
build-shared: 'ON'
cxx-standard: 17
cxx-flags: ''
os: windows-latest

# Debug
- build: 2
build-type: Debug
build-shared: 'ON'
cxx-standard: 17
cxx-flags: ''
os: windows-latest


Expand Down Expand Up @@ -217,4 +225,4 @@ jobs:
run: |
ctest -C ${{ matrix.build-type }}
shell: bash
working-directory: _build
working-directory: _build
145 changes: 145 additions & 0 deletions .github/workflows/meson.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
name: Meson

on:
pull_request:
push:

jobs:
meson-build-and-tests:
runs-on: ${{ matrix.platform }}
name: ${{ matrix.platform }}, ${{ matrix.mode.name }} ${{ matrix.flavor }}
strategy:
fail-fast: false
matrix:
flavor:
- debug
- release
mode:
- name: default
extra_envs: {}

# Alternative compiler setups
- name: gcc
extra_envs:
CC: gcc
CXX: g++
- name: clang
extra_envs:
CC: clang
CXX: clang++

- name: sanitize
args: >-
"-Db_sanitize=address,undefined"
extra_envs: {}

# This is for MSVC, which only supports AddressSanitizer.
# https://learn.microsoft.com/en-us/cpp/sanitizers/
- name: sanitize+asanonly
args: -Db_sanitize=address
extra_envs:
ASAN_OPTIONS: report_globals=0:halt_on_error=1:abort_on_error=1:print_summary=1

- name: clang+sanitize
args: >-
"-Db_sanitize=address,undefined"
extra_envs:
CC: clang
CXX: clang++

# default clang on GitHub hosted runners is from MSYS2.
# Use Visual Studio supplied clang-cl instead.
- name: clang-cl+sanitize
args: >-
"-Db_sanitize=address,undefined"
extra_envs:
CC: clang-cl
CXX: clang-cl
platform:
- ubuntu-22.04
- windows-2022
- macos-latest

exclude:
# clang-cl only makes sense on windows.
- platform: ubuntu-22.04
mode:
name: clang-cl+sanitize
- platform: macos-latest
mode:
name: clang-cl+sanitize

# Use clang-cl instead of MSYS2 clang.
#
# we already tested clang+sanitize on linux,
# if this doesn't work, it should be an issue for MSYS2 team to consider.
- platform: windows-2022
mode:
name: clang
- platform: windows-2022
mode:
name: clang+sanitize

# MSVC-only sanitizers
- platform: ubuntu-22.04
mode:
name: sanitize+asanonly
- platform: macos-latest
mode:
name: sanitize+asanonly
- platform: windows-2022
mode:
name: sanitize

# clang is the default on macos
# also gcc is an alias to clang
- platform: macos-latest
mode:
name: clang
- platform: macos-latest
mode:
name: gcc

# gcc is the default on linux
- platform: ubuntu-22.04
mode:
name: gcc

# only run sanitizer tests on linux
#
# gcc/clang's codegen shouldn't massively change across platforms,
# and linux supports most of the sanitizers.
- platform: macos-latest
mode:
name: clang+sanitize
- platform: macos-latest
mode:
name: sanitize
steps:
- name: Setup meson
run: |
pipx install meson ninja
- name: Checkout
uses: actions/checkout@v4
- name: Activate MSVC and Configure
if: ${{ matrix.platform == 'windows-2022' }}
env: ${{ matrix.mode.extra_envs }}
run: |
meson setup build-${{ matrix.flavor }} --buildtype=${{ matrix.flavor }} -Ddefault_library=static ${{ matrix.mode.args }} --vsenv
- name: Configuring
if: ${{ matrix.platform != 'windows-2022' }}
env: ${{ matrix.mode.extra_envs }}
run: |
meson setup build-${{ matrix.flavor }} --buildtype=${{ matrix.flavor }} -Db_lundef=false ${{ matrix.mode.args }}
- name: Building
run: |
meson compile -C build-${{ matrix.flavor }}
- name: Running tests
env: ${{ matrix.mode.extra_envs }}
run: |
meson test -C build-${{ matrix.flavor }} --timeout-multiplier 0
- uses: actions/upload-artifact@v4
if: failure()
with:
name: ${{ matrix.platform }}-${{ matrix.mode.name }}-${{ matrix.flavor }}-logs
path: build-${{ matrix.flavor }}/meson-logs
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
cmake_minimum_required(VERSION 3.5)
project(pystring CXX)
project(pystring LANGUAGES CXX VERSION 1.1.4)

option (BUILD_SHARED_LIBS "Build shared libraries (set to OFF to build static libs)" ON)

add_library(pystring
pystring.cpp
pystring.h
)
set_target_properties(pystring PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
)

add_executable (pystring_test test.cpp)
TARGET_LINK_LIBRARIES (pystring_test pystring)
Expand Down
46 changes: 46 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
project(
'pystring',
'cpp',
version: '1.1.4',
license: 'BSD-3-Clause',
license_files: 'LICENSE',
meson_version: '>=1.3',
default_options: ['cpp_std=c++17,c++11', 'warning_level=3'],
)

inc = include_directories('.')

srcs = files('pystring.cpp')
hdrs = files('pystring.h')

pystring_lib = library(
'pystring',
srcs,
implicit_include_directories: false,
include_directories: inc,
version: meson.project_version(),
install: true,
)
pystring_dep = declare_dependency(
link_with: pystring_lib,
include_directories: inc,
)
meson.override_dependency('pystring', pystring_dep)

test(
'PyStringTest',
executable(
'pystring_test',
'test.cpp',
dependencies: pystring_dep,
build_by_default: false,
),
)

install_headers(hdrs, subdir: 'pystring')

pkgconfig = import('pkgconfig')
pkgconfig.generate(
pystring_lib,
description: 'C++ functions matching the interface and behavior of python string methods with std::string',
)
16 changes: 8 additions & 8 deletions unittest.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ struct PYSTRINGTest
PYSTRINGTestFunc function;
};

typedef std::vector<PYSTRINGTest*> UnitTests;
typedef std::vector<PYSTRINGTest> UnitTests;

UnitTests& GetUnitTests();

struct AddTest { AddTest(PYSTRINGTest* test); };
struct AddTest { AddTest(PYSTRINGTest&& test); };

/// PYSTRING_CHECK_* macros checks if the conditions is met, and if not,
/// prints an error message indicating the module and line where the
Expand Down Expand Up @@ -102,22 +102,22 @@ struct AddTest { AddTest(PYSTRINGTest* test); };

#define PYSTRING_ADD_TEST(group, name) \
static void pystringtest_##group##_##name(); \
AddTest pystringaddtest_##group##_##name(new PYSTRINGTest(#group, #name, pystringtest_##group##_##name)); \
AddTest pystringaddtest_##group##_##name(PYSTRINGTest(#group, #name, pystringtest_##group##_##name)); \
static void pystringtest_##group##_##name()

#define PYSTRING_TEST_SETUP() \
int unit_test_failures = 0

#define PYSTRING_TEST_APP(app) \
std::vector<PYSTRINGTest*>& GetUnitTests() { \
static std::vector<PYSTRINGTest*> pystring_unit_tests; \
std::vector<PYSTRINGTest>& GetUnitTests() { \
static std::vector<PYSTRINGTest> pystring_unit_tests; \
return pystring_unit_tests; } \
AddTest::AddTest(PYSTRINGTest* test){GetUnitTests().push_back(test);}; \
AddTest::AddTest(PYSTRINGTest&& test){GetUnitTests().emplace_back(test);}; \
PYSTRING_TEST_SETUP(); \
int main(int, char **) { std::cerr << "\n" << #app <<"\n\n"; \
for(size_t i = 0; i < GetUnitTests().size(); ++i) { \
int _tmp = unit_test_failures; GetUnitTests()[i]->function(); \
std::cerr << "Test [" << GetUnitTests()[i]->group << "] [" << GetUnitTests()[i]->name << "] - "; \
int _tmp = unit_test_failures; GetUnitTests()[i].function(); \
std::cerr << "Test [" << GetUnitTests()[i].group << "] [" << GetUnitTests()[i].name << "] - "; \
std::cerr << (_tmp == unit_test_failures ? "PASSED" : "FAILED") << "\n"; } \
std::cerr << "\n" << unit_test_failures << " tests failed\n\n"; \
return unit_test_failures; }
Expand Down