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
124 changes: 109 additions & 15 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,40 @@ on:
branches: [ main ]
jobs:
build-and-test-for-cpp-meson:
name: "Build and test for C++ with meson"
timeout-minutes: 10
runs-on: ubuntu-24.04
name: "Build and test for C++ with ${{ matrix.compiler }}"
timeout-minutes: 15
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- compiler: GCC 13
os: ubuntu-24.04
cxx: g++-13
buildtype: debug
coverage: true
- compiler: GCC 14
os: ubuntu-24.04
cxx: g++-14
buildtype: release
coverage: false
- compiler: GCC 15
os: ubuntu-26.04
cxx: g++-15
buildtype: release
coverage: false
- compiler: Clang 18
os: macos-15
cxx: clang++
buildtype: debug
coverage: false
- compiler: Clang 22
os: ubuntu-26.04
cxx: clang++-22
buildtype: debug
coverage: false
env:
CXX: ${{ matrix.cxx }}
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -18,20 +49,29 @@ jobs:
with:
python-version: '3.11'
- name: "Install tooling"
run: python -m pip install meson ninja
- name: "Install coverage tooling"
if: matrix.coverage
run: |
sudo apt-get install lcov ninja-build
g++-13 --version
sudo apt-get install lcov
gcov-13 --version
lcov --version
pip install meson pytest
- name: "Configure"
shell: bash
run: |
if [ "$RUNNER_OS" = "macOS" ]; then
export CXX="$(brew --prefix llvm@18)/bin/clang++"
fi
"$CXX" --version
meson setup build --buildtype=${{ matrix.buildtype }} --warnlevel=3 --werror \
-Db_coverage=${{ matrix.coverage }} -Db_ndebug=if-release
- name: "Build and test"
run: |
CXX=g++-13 meson setup build --buildtype=debug --warnlevel=3 -Db_coverage=true
meson compile -C build tests
./build/tests/test.out
./build/tests/test-fmtlib.out
./build/tests/test-stdfmt.out
meson test -C build --no-rebuild --print-errorlogs \
test.out test-fmtlib.out test-stdfmt.out
- name: "Generate coverage"
if: matrix.coverage
run: |
lcov -c -d build -o cov.info --gcov-tool gcov-13 --ignore-errors mismatch
lcov --gcov-tool gcov-13 \
Expand All @@ -42,26 +82,42 @@ jobs:
-o barkeep.info
rm cov.info
- name: Coveralls
if: matrix.coverage
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: barkeep.info
build-and-test-for-cpp-msvc:
name: "Build and test for C++ with MSVC"
timeout-minutes: 5
runs-on: windows-2022
name: "Build and test for C++ with ${{ matrix.compiler }}"
timeout-minutes: 15
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- compiler: MSVC
os: windows-2022
vs_version: '[17.0,18.0)'
- compiler: MSVC (VS 2026)
os: windows-2025-vs2026
vs_version: '[18.0,19.0)'
steps:
- uses: actions/checkout@v4
with:
submodules: false
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: "Install tooling"
run: python -m pip install meson ninja
- name: "Build and test"
shell: cmd
run: |
set "BARKEEP_VS_PATH="
set "PATH=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer;%PATH%"
for /f "usebackq delims=" %%i in (`vswhere -latest -version "[17.0,18.0)" -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath`) do set "BARKEEP_VS_PATH=%%i"
for /f "usebackq delims=" %%i in (`vswhere -latest -version "${{ matrix.vs_version }}" -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath`) do set "BARKEEP_VS_PATH=%%i"
if not defined BARKEEP_VS_PATH (
echo Visual Studio 2022 C++ tools were not found.
echo Requested Visual Studio C++ tools were not found.
exit /b 1
)
call "%BARKEEP_VS_PATH%\Common7\Tools\VsDevCmd.bat" -arch=x64 -host_arch=x64
Expand All @@ -70,6 +126,43 @@ jobs:
/W4 /WX /I. test_package/test_package.cpp /Fe:test_package.exe
if errorlevel 1 exit /b 1
.\test_package.exe
if errorlevel 1 exit /b 1
rem Make Git's grep available while keeping MSVC's link.exe first.
set "PATH=%PATH%;%ProgramFiles%\Git\usr\bin"
set "CXX=cl"
meson setup build --buildtype=debug --warnlevel=3 --werror ^
"-Dcpp_args=['/utf-8', '/permissive-']"
if errorlevel 1 exit /b 1
meson compile -C build tests
if errorlevel 1 exit /b 1
meson test -C build --no-rebuild --print-errorlogs ^
test.out test-fmtlib.out test-stdfmt.out
build-and-test-for-cpp-sanitizers:
name: "Build and test for C++ with ASan and UBSan"
timeout-minutes: 15
runs-on: ubuntu-24.04
env:
CXX: clang++-18
UBSAN_OPTIONS: halt_on_error=1:print_stacktrace=1
steps:
- uses: actions/checkout@v4
with:
submodules: false
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: "Install tooling"
run: python -m pip install meson ninja
- name: "Configure"
run: |
"$CXX" --version
meson setup build --buildtype=debug --warnlevel=3 --werror \
-Db_sanitize=address,undefined -Db_lundef=false
- name: "Build and test"
run: |
meson compile -C build tests
meson test -C build --no-rebuild --print-errorlogs \
test.out test-fmtlib.out test-stdfmt.out
build-and-test-for-python:
name: "Build and test for Python"
timeout-minutes: 10
Expand Down Expand Up @@ -127,5 +220,6 @@ jobs:
python/barkeep.cpp \
test_package/test_package.cpp \
tests/demo-fmtlib.cpp tests/demo-stdfmt.cpp tests/demo.cpp \
tests/test-api-compatibility.cpp \
tests/test-fmtlib.cpp tests/test-stdfmt.cpp tests/test.cpp \
tests/testutil.h
11 changes: 5 additions & 6 deletions tests/demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ Demo float_counter("float_counter", "Floating point counter", []() {
});
for (int i = 0; i < 1010; i++) {
std::this_thread::sleep_for(13ms);
work += 0.213;
work += 0.213f;
}
}
});
Expand Down Expand Up @@ -269,7 +269,6 @@ Demo three_counters_delim(
"Composite display of three counters with custom delimiter",
[]() {
static const std::string blue = "\033[34m";
static const std::string reset = "\033[0m";
std::atomic<size_t> squares{0}, cubes{0}, hypercubes{0};
// clang-format off
auto counters = bk::Composite(
Expand Down Expand Up @@ -316,7 +315,7 @@ Demo three_bars( // ...
[]() {
std::atomic<size_t> linear{0}, quad{0}, cubic{0};
// clang-format off
auto bars = bk::Composite(
auto progress_bars = bk::Composite(
{bk::ProgressBar(&linear, {
.total = 100,
.message = "Linear ",
Expand All @@ -340,19 +339,19 @@ Demo three_bars( // ...
})},
"\n");
// clang-format on
bars->show();
progress_bars->show();
for (int i = 0; i < 100; i++) {
std::this_thread::sleep_for(130ms);
linear++;
quad += linear;
cubic += quad;
}
bars->done();
progress_bars->done();
});

Demo iterable_bar("iterable_bar", "Iterable progress bar", []() {
std::vector<float> v(300, 0);
std::iota(v.begin(), v.end(), 1); // 1, 2, 3, ..., 300
std::iota(v.begin(), v.end(), 1.0f); // 1, 2, 3, ..., 300
float sum = 0;
for (auto x : bk::IterableBar(v, {.message = "Summing", .interval = .02})) {
std::this_thread::sleep_for(1.s / x);
Expand Down
8 changes: 7 additions & 1 deletion tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ foreach src : test_sources
include_directories : incdir,
dependencies : deps + [catch])
tests += [exe]
test(exec_name, exe)
test(exec_name, exe, timeout: 600)
endforeach

compatibility = static_library('test-api-compatibility',
'test-api-compatibility.cpp',
include_directories : incdir,
dependencies : threads)
tests += [compatibility]

alias_target('tests', tests)
18 changes: 18 additions & 0 deletions tests/test-api-compatibility.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <barkeep/barkeep.h>

// Compile-only examples of downstream subclasses. Keep these types explicit so
// changes to the extension interface fail the C++ builds.
class CustomDisplay : public barkeep::BaseDisplay {
protected:
long render_(bool, const std::string&) override { return render_message_(); }
};

class CustomAnimation : public barkeep::AnimationDisplay {
public:
unsigned short& current_frame() { return frame_; }
};

class CustomDisplayer : public barkeep::AsyncDisplayer {
public:
long& last_newline_count() { return last_num_newlines_; }
};
3 changes: 2 additions & 1 deletion tests/test-fmtlib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,8 @@ TEST_CASE("Composite bar-counter", "[composite]") {

{ // check bar correctness
auto bar_part = part.substr(14, 32);
long spaces = std::count(bar_part.begin(), bar_part.end(), ' ');
long spaces =
static_cast<long>(std::count(bar_part.begin(), bar_part.end(), ' '));
CHECK(spaces <= last_spaces);
last_spaces = spaces;
size_t i = 1;
Expand Down
3 changes: 2 additions & 1 deletion tests/test-stdfmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@ TEST_CASE("Composite bar-counter", "[composite]") {

{ // check bar correctness
auto bar_part = part.substr(14, 32);
long spaces = std::count(bar_part.begin(), bar_part.end(), ' ');
long spaces =
static_cast<long>(std::count(bar_part.begin(), bar_part.end(), ' '));
CHECK(spaces <= last_spaces);
last_spaces = spaces;
size_t i = 1;
Expand Down
3 changes: 2 additions & 1 deletion tests/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,8 @@ TEST_CASE("Composite bar-counter", "[composite]") {

{ // check bar correctness
auto bar_part = part.substr(14, 32);
long spaces = std::count(bar_part.begin(), bar_part.end(), ' ');
long spaces =
static_cast<long>(std::count(bar_part.begin(), bar_part.end(), ' '));
CHECK(spaces <= last_spaces);
last_spaces = spaces;
size_t i = 1;
Expand Down
Loading