diff --git a/rules.bzl b/rules.bzl index 5f4110c..41c9e8e 100644 --- a/rules.bzl +++ b/rules.bzl @@ -32,6 +32,7 @@ def _bats_test_impl(ctx): ) runfiles = ctx.runfiles( files = ctx.files.srcs, + transitive_files = depset(ctx.files.data), collect_data = True, ).merge(ctx.attr._bats.default_runfiles) return [DefaultInfo(runfiles = runfiles)] @@ -40,6 +41,7 @@ def _bats_test_impl(ctx): bats_test = rule( _bats_test_impl, attrs = { + "data": attr.label_list(allow_files = True), "deps": attr.label_list(), "env": attr.string_dict( doc = "A list of key-value pairs of environment variables to define", diff --git a/tests/BUILD.bazel b/tests/BUILD.bazel index dffcf4f..e116a15 100644 --- a/tests/BUILD.bazel +++ b/tests/BUILD.bazel @@ -24,6 +24,12 @@ bats_test( deps = [":helper"], ) +bats_test( + name = "hello_world_data_test", + srcs = ["hello_world_data.bats"], + data = ["testdata/golden_4.txt"], +) + bats_test( name = "hello_world_test", srcs = ["hello_world.bats"], diff --git a/tests/hello_world_data.bats b/tests/hello_world_data.bats new file mode 100644 index 0000000..4f26c06 --- /dev/null +++ b/tests/hello_world_data.bats @@ -0,0 +1,7 @@ +#!/usr/bin/env bats + +@test "can read from data" { + run echo 4 + [ $status -eq 0 ] + [ "$output" == "$(< 'tests/testdata/golden_4.txt')" ] +} diff --git a/tests/testdata/golden_4.txt b/tests/testdata/golden_4.txt new file mode 100644 index 0000000..b8626c4 --- /dev/null +++ b/tests/testdata/golden_4.txt @@ -0,0 +1 @@ +4