Skip to content

Commit

Permalink
add data attr
Browse files Browse the repository at this point in the history
  • Loading branch information
jmelahman authored and filmil committed Nov 24, 2021
1 parent d04d4c2 commit 42a7a03
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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",
Expand Down
6 changes: 6 additions & 0 deletions tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
7 changes: 7 additions & 0 deletions tests/hello_world_data.bats
Original file line number Diff line number Diff line change
@@ -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')" ]
}
1 change: 1 addition & 0 deletions tests/testdata/golden_4.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4

0 comments on commit 42a7a03

Please sign in to comment.