How to use cucumber with bazel?

744 views Asked by At

I am trying to create a Bazel project which includes cucumber-cpp. I could not figure out how its BUILD file would look like.

As Google Test now includes it's own BUILD file it is as easy as it get's. Something similar would be nice.

My WORKSPACE file looks like this

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
    name = "googletest",
    sha256 = "927827c183d01734cc5cfef85e0ff3f5a92ffe6188e0d18e909c5efebf28a0c7",
    strip_prefix = "googletest-release-1.8.1",
    url = "https://github.com/google/googletest/archive/release-1.8.1.zip",
)

http_archive(
    name = "cucumber-cpp",
    sha256 = "73fddda099e39cc51ebee99051047067f6dcd437fbde60601ac48cb82a903dac",
    url = "https://github.com/cucumber/cucumber-cpp/archive/v0.5.zip",
)

My specification BUILD file

cc_test(
    name = "app-spec",
    srcs = glob(["**/*.cpp"]),
    deps = [
        "//src:app-lib",
        "@cucumber-cpp//:main", //do not know if this is correct
    ],
)

cc_test(
    name = "app-spec",
    srcs = glob(["**/*.cpp"]),
    deps = [
        "//src:app-lib",
        "@cucumber-cpp//:main", //do not know if this is correct
    ],
)

Test BUILD file

cc_test(
    name = "app-test",
    srcs = glob(["**/*.cpp"]),
    deps = [
        "//src:app-lib",
        "@googletest//:gtest_main",
    ],
)

But obviously the cucumber-cpp is not built so I wonder how it's Bazel BUILD file would look like?

1

There are 1 answers

0
silvergasp On

I also wanted to do this, but couldn't find anything where anyone had attempted it. In the end I wrote a dedicated bazel extension for using cucumber and gherkin feature specs. Currently this only supports (linux|osx)+cpp+cucumber, but I may add support for windows and other languages further down the line. To use this add this to your WORKSPACE file;

load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
git_repository(
    name = "rules_gherkin",
    commit = "ef361f40f9716ad8a3c6a8a21111bb80d4cbd927", # Update this to match latest commit
    remote = "https://github.com/silvergasp/rules_gherkin.git"
)
load("@rules_gherkin//:gherkin_deps.bzl","gherkin_deps")
gherkin_deps()

load("@rules_gherkin//:gherkin_workspace.bzl","gherkin_workspace")
gherkin_workspace()

An example BUILD file would look like this;

load("//gherkin:defs.bzl", "gherkin_library", "gherkin_test")

gherkin_library(
    name = "feature_specs",
    srcs = glob(["**/*.feature"]),
)

gherkin_test(
    name = "calc_test",
    steps = ":calculator_steps",
    deps = [":feature_specs"],
)

load("//gherkin:defs.bzl", "cc_gherkin_steps")

cc_gherkin_steps(
    name = "calculator_steps",
    srcs = [
        "CalculatorSteps.cpp",
    ],
    visibility = ["//visibility:public"],
    deps = [
        "//examples/Calc/src:calculator",
        "@cucumber_cpp//src:cucumber_main",
        "@gtest",
    ],
)

A complete example can be found here.