diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index ffd2a51..8d3a7d8 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -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: @@ -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 \ @@ -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 @@ -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 @@ -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 diff --git a/tests/demo.cpp b/tests/demo.cpp index 8ce51e5..12e4699 100644 --- a/tests/demo.cpp +++ b/tests/demo.cpp @@ -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; } } }); @@ -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 squares{0}, cubes{0}, hypercubes{0}; // clang-format off auto counters = bk::Composite( @@ -316,7 +315,7 @@ Demo three_bars( // ... []() { std::atomic 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 ", @@ -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 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); diff --git a/tests/meson.build b/tests/meson.build index 80fdf29..1076c53 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -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) diff --git a/tests/test-api-compatibility.cpp b/tests/test-api-compatibility.cpp new file mode 100644 index 0000000..e7624ff --- /dev/null +++ b/tests/test-api-compatibility.cpp @@ -0,0 +1,18 @@ +#include + +// 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_; } +}; diff --git a/tests/test-fmtlib.cpp b/tests/test-fmtlib.cpp index 4f1600c..4e5872e 100644 --- a/tests/test-fmtlib.cpp +++ b/tests/test-fmtlib.cpp @@ -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(std::count(bar_part.begin(), bar_part.end(), ' ')); CHECK(spaces <= last_spaces); last_spaces = spaces; size_t i = 1; diff --git a/tests/test-stdfmt.cpp b/tests/test-stdfmt.cpp index db4d08f..6a99b09 100644 --- a/tests/test-stdfmt.cpp +++ b/tests/test-stdfmt.cpp @@ -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(std::count(bar_part.begin(), bar_part.end(), ' ')); CHECK(spaces <= last_spaces); last_spaces = spaces; size_t i = 1; diff --git a/tests/test.cpp b/tests/test.cpp index 8904eec..e25046c 100644 --- a/tests/test.cpp +++ b/tests/test.cpp @@ -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(std::count(bar_part.begin(), bar_part.end(), ' ')); CHECK(spaces <= last_spaces); last_spaces = spaces; size_t i = 1;