From 441a0b211a8a344106f6ea56d80a2729e67c9b27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Vu=C4=8Dica?= Date: Mon, 12 Aug 2024 13:39:24 +0100 Subject: [PATCH] bazel, .github/workflows: Add //:minimal_test that should pass even if shared libs are missing on the machine / in RBE containers. --- .github/workflows/ci-bazel.yml | 22 ++++++++++++++++++-- BUILD | 10 +++++++++ minimal_test.cpp | 37 ++++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 minimal_test.cpp diff --git a/.github/workflows/ci-bazel.yml b/.github/workflows/ci-bazel.yml index c2d68736..c1a6141e 100644 --- a/.github/workflows/ci-bazel.yml +++ b/.github/workflows/ci-bazel.yml @@ -54,6 +54,15 @@ jobs: bazel_test: runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + include: + - name: minimal test + bazel_target: //:minimal_test + - name: util test + bazel_target: //:util_test + needs: [bazel_build] steps: # Checks-out your repository under $GITHUB_WORKSPACE, which is the CWD for @@ -87,7 +96,7 @@ jobs: - name: install deps without prebuilt SDL (bazel) run: sudo apt-get update && sudo apt-get install autoconf automake libgl1-mesa-dev libglu1-mesa-dev libx11-dev libxext-dev libxrandr-dev libxrender-dev libasound-dev libalsaplayer-dev - name: bazel test - run: bazel test //:util_test + run: bazel test ${{ matrix.bazel_target }} bazel_build_buildbuddy: runs-on: ubuntu-latest @@ -126,6 +135,15 @@ jobs: bazel_test_buildbuddy: runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + include: + - name: minimal test + bazel_target: //:minimal_test + - name: util test + bazel_target: //:util_test + needs: [bazel_build_buildbuddy] steps: # Checks-out your repository under $GITHUB_WORKSPACE, which is the CWD for @@ -157,7 +175,7 @@ jobs: # More useful with e.g. npm. - name: rbe bazel test - run: bazel test --config=remote --build_metadata=ROLE=CI ${BUILDBUDDY_ORG_API_KEY:+--remote_header=x-buildbuddy-api-key=${BUILDBUDDY_ORG_API_KEY}} //:util_test + run: bazel test --config=remote --build_metadata=ROLE=CI ${BUILDBUDDY_ORG_API_KEY:+--remote_header=x-buildbuddy-api-key=${BUILDBUDDY_ORG_API_KEY}} ${{ matrix.bazel_target }} # Temporarily allow errors. This is known to fail at this time due to insufficient # number of binary packages installed by the rules_libsdl12. continue-on-error: true diff --git a/BUILD b/BUILD index b52ee09c..5a35ede3 100644 --- a/BUILD +++ b/BUILD @@ -231,6 +231,16 @@ cc_test( linkopts = ["-ldl"], ) +cc_test( + # This test intentionally links nothing except gtest. + name = "minimal_test", + size = "small", + srcs = ["minimal_test.cpp"], + deps = [ + "@com_google_googletest//:gtest_main", + ], +) + cc_library( name = "macutil", srcs = select({ diff --git a/minimal_test.cpp b/minimal_test.cpp new file mode 100644 index 00000000..1a7bbf76 --- /dev/null +++ b/minimal_test.cpp @@ -0,0 +1,37 @@ +////////////////////////////////////////////////////////////////////// +// Yet Another Tibia Client +////////////////////////////////////////////////////////////////////// +// Minimal test to verify the test system itself works. +////////////////////////////////////////////////////////////////////// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +////////////////////////////////////////////////////////////////////// + +#include +#include + +// Demonstrate some basic assertions. +TEST(StrReplaceTest, BasicAssertions) { + auto haystack = std::string("hello world"); + auto needle = std::string("hello"); + auto replace = std::string("hi"); + + auto got = + haystack.replace(haystack.find(needle), needle.size(), replace); + auto want = "hi world"; + + EXPECT_STREQ(got.c_str(), want); + // Expect equality. + //EXPECT_EQ(7 * 6, 42); +}