From 60cab73e31dc56d510c6bd761e1b7469028d8983 Mon Sep 17 00:00:00 2001 From: Jamison Lahman Date: Thu, 18 Nov 2021 23:53:09 -0800 Subject: [PATCH] integration tests --- .bazelignore | 1 + .gitignore | 1 + integration/BUILD.bazel | 38 ++++++++++++++++++++++++++++++++++ integration/WORKSPACE | 23 ++++++++++++++++++++ integration/dummy.txt | 1 + integration/hello_world.bats | 15 ++++++++++++++ integration/hello_world_1.bats | 7 +++++++ integration/hello_world_2.bats | 7 +++++++ 8 files changed, 93 insertions(+) create mode 100644 .bazelignore create mode 100644 integration/BUILD.bazel create mode 100644 integration/WORKSPACE create mode 100644 integration/dummy.txt create mode 100644 integration/hello_world.bats create mode 100644 integration/hello_world_1.bats create mode 100644 integration/hello_world_2.bats diff --git a/.bazelignore b/.bazelignore new file mode 100644 index 0000000..72662c7 --- /dev/null +++ b/.bazelignore @@ -0,0 +1 @@ +integration/ diff --git a/.gitignore b/.gitignore index a08ff48..3a5ae2c 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ # Ignore all bazel-* symlinks. There is no full list since this can change # based on the name of the directory bazel is cloned into. /bazel-* +/integration/bazel-* diff --git a/integration/BUILD.bazel b/integration/BUILD.bazel new file mode 100644 index 0000000..b7b0dfa --- /dev/null +++ b/integration/BUILD.bazel @@ -0,0 +1,38 @@ +load("@bazel_bats//:rules.bzl", "bats_test") + +bats_test( + name = "hello_world_test", + srcs = ["hello_world.bats"], + env = { + "PROGRAM": "hello_world", + "LOCATED": "$(location :dummy)", + }, + deps = [":dummy"], +) + +bats_test( + name = "hello_world_twofiles_test", + srcs = [ + "hello_world_1.bats", + "hello_world_2.bats", + ], +) + +bats_test( + name = "hello_world_twofiles_1_test", + srcs = [ + "hello_world_1.bats", + ], +) + +bats_test( + name = "hello_world_twofiles_2_test", + srcs = [ + "hello_world_2.bats", + ], +) + +filegroup( + name = "dummy", + srcs = ["dummy.txt"], +) diff --git a/integration/WORKSPACE b/integration/WORKSPACE new file mode 100644 index 0000000..549ef68 --- /dev/null +++ b/integration/WORKSPACE @@ -0,0 +1,23 @@ +workspace(name = "bazel_bats_integration") + +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +BAZEL_BATS_VERSION = "0.29.1" +HEAD = "75dea0bc4d15d48a4238ad2143e998509c0cb3e4" + +http_archive( + name = "bazel_bats", + # TODO: Tag and release HEAD. + # strip_prefix = "bazel-bats-%s" % BAZEL_BATS_VERSION, + strip_prefix = "bazel-bats-%s" % HEAD, + urls = [ + # TODO: Tag and release HEAD. + # "https://github.com/jmelahman/bazel-bats/archive/refs/tags/v%s.tar.gz" % BAZEL_BATS_VERSION, + "https://github.com/jmelahman/bazel-bats/archive/%s.tar.gz" % HEAD, + ], + sha256 = "e57d61da26bbb5428e8162da4fa2432d85abc2530b6211dd2d096d75be18d9fb", +) + +load("@bazel_bats//:deps.bzl", "bazel_bats_dependencies") + +bazel_bats_dependencies() diff --git a/integration/dummy.txt b/integration/dummy.txt new file mode 100644 index 0000000..d39a83b --- /dev/null +++ b/integration/dummy.txt @@ -0,0 +1 @@ +#empty file diff --git a/integration/hello_world.bats b/integration/hello_world.bats new file mode 100644 index 0000000..7a431c0 --- /dev/null +++ b/integration/hello_world.bats @@ -0,0 +1,15 @@ +#!/usr/bin/env bats + +@test "addition using bc" { + result="$(echo 4)" + [ "$result" -eq 4 ] +} + +@test "Test program name" { + [ "${PROGRAM}" == "hello_world" ] +} + +@test "Test program name with location" { + echo "Location: ${LOCATED}" + [ "${LOCATED}" == "./dummy.txt" ] +} diff --git a/integration/hello_world_1.bats b/integration/hello_world_1.bats new file mode 100644 index 0000000..d01303b --- /dev/null +++ b/integration/hello_world_1.bats @@ -0,0 +1,7 @@ +#!/usr/bin/env bats + +@test "addition using bc" { + result="$(echo 4)" + [ "$result" -eq 4 ] +} + diff --git a/integration/hello_world_2.bats b/integration/hello_world_2.bats new file mode 100644 index 0000000..d01303b --- /dev/null +++ b/integration/hello_world_2.bats @@ -0,0 +1,7 @@ +#!/usr/bin/env bats + +@test "addition using bc" { + result="$(echo 4)" + [ "$result" -eq 4 ] +} +