From 2365c4a60364f0250ffb7acbd4288e9101d012c5 Mon Sep 17 00:00:00 2001 From: Dominic Hamon Date: Mon, 13 Jun 2022 17:45:20 +0100 Subject: [PATCH] add multiple OSes to bazel workflow (#1412) * add multiple OSes to bazel workflow * correct indent * only set copts when they're supported by the OS * os check should work * pull out cxx03_test for per-platform stuff * attempt to fix windows test output --- .github/workflows/bazel.yml | 15 +++++++---- test/BUILD | 52 +++++++++++++++++++++++++++++------- test/reporter_output_test.cc | 2 +- 3 files changed, 54 insertions(+), 15 deletions(-) diff --git a/.github/workflows/bazel.yml b/.github/workflows/bazel.yml index a53661b2..1d0864b9 100644 --- a/.github/workflows/bazel.yml +++ b/.github/workflows/bazel.yml @@ -5,9 +5,14 @@ on: pull_request: {} jobs: - build-and-test: - runs-on: ubuntu-latest - + job: + name: bazel.${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, macos-latest, windows-2022] + steps: - uses: actions/checkout@v1 @@ -17,9 +22,9 @@ jobs: cache-name: bazel-cache with: path: "~/.cache/bazel" - key: ${{ env.cache-name }}-${{ runner.os }}-${{ github.ref }} + key: ${{ env.cache-name }}-${{ matrix.os }}-${{ github.ref }} restore-keys: | - ${{ env.cache-name }}-${{ runner.os }}-main + ${{ env.cache-name }}-${{ matrix.os }}-main - name: build run: | diff --git a/test/BUILD b/test/BUILD index f1ba0f9f..0a66bf3d 100644 --- a/test/BUILD +++ b/test/BUILD @@ -1,3 +1,12 @@ +load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") + +platform( + name = "windows", + constraint_values = [ + "@platforms//os:windows", + ], +) + TEST_COPTS = [ "-pedantic", "-pedantic-errors", @@ -11,11 +20,10 @@ TEST_COPTS = [ "-fstrict-aliasing", ] -PER_SRC_COPTS = ({ - "cxx03_test.cc": ["-std=c++03"], - # Some of the issues with DoNotOptimize only occur when optimization is enabled +# Some of the issues with DoNotOptimize only occur when optimization is enabled +PER_SRC_COPTS = { "donotoptimize_test.cc": ["-O3"], -}) +} TEST_ARGS = ["--benchmark_min_time=0.01"] @@ -26,14 +34,15 @@ PER_SRC_TEST_ARGS = ({ "spec_arg_verbosity_test.cc" : ["--v=42"], }) -load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") - cc_library( name = "output_test_helper", testonly = 1, srcs = ["output_test_helper.cc"], hdrs = ["output_test.h"], - copts = TEST_COPTS, + copts = select({ + "//:windows": [], + "//conditions:default": TEST_COPTS, + }), deps = [ "//:benchmark", "//:benchmark_internal_headers", @@ -46,7 +55,10 @@ cc_library( size = "small", srcs = [test_src], args = TEST_ARGS + PER_SRC_TEST_ARGS.get(test_src, []), - copts = TEST_COPTS + PER_SRC_COPTS.get(test_src, []), + copts = select({ + "//:windows": [], + "//conditions:default": TEST_COPTS, + }) + PER_SRC_COPTS.get(test_src, []) , deps = [ ":output_test_helper", "//:benchmark", @@ -62,15 +74,37 @@ cc_library( ["*test.cc"], exclude = [ "*_assembly_test.cc", + "cxx03_test.cc", "link_main_test.cc", ], ) ] +cc_test( + name = "cxx03_test", + size = "small", + srcs = ["cxx03_test.cc"], + copts = TEST_COPTS + ["-std=c++03"], + deps = [ + ":output_test_helper", + "//:benchmark", + "//:benchmark_internal_headers", + "@com_google_googletest//:gtest", + "@com_google_googletest//:gtest_main", + ], + target_compatible_with = select({ + "//:windows": ["@platforms//:incompatible"], + "//conditions:default": [], + }) +) + cc_test( name = "link_main_test", size = "small", srcs = ["link_main_test.cc"], - copts = TEST_COPTS, + copts = select({ + "//:windows": [], + "//conditions:default": TEST_COPTS, + }), deps = ["//:benchmark_main"], ) diff --git a/test/reporter_output_test.cc b/test/reporter_output_test.cc index 2b6e6543..65bb14a1 100644 --- a/test/reporter_output_test.cc +++ b/test/reporter_output_test.cc @@ -17,7 +17,7 @@ static int AddContextCases() { AddCases(TC_ConsoleErr, { {"^%int-%int-%intT%int:%int:%int[-+]%int:%int$", MR_Default}, - {"Running .*/reporter_output_test(\\.exe)?$", MR_Next}, + {"Running .*(/|\\\\)reporter_output_test(\\.exe)?$", MR_Next}, {"Run on \\(%int X %float MHz CPU s?\\)", MR_Next}, }); AddCases(TC_JSONOut,