filmil / bazel-bats

bazel-bats: bazel test rules for the BATS testing framework (based on bats-core)
Apache License 2.0
10 stars 4 forks source link

How is this supposed to be used with MODULE.bazel? #35

Open noel-yap opened 3 months ago

noel-yap commented 3 months ago

MODULE.bazel has:

git_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
git_repository(
    name = "bazel_bats",
    remote = "https://github.com/filmil/bazel-bats",
    commit = "22db48a75128044bb611492b3e1e654187881fa3",
    shallow_since = "1677540706 -0800",
)

bats_test = use_repo_rule("@bazel_bats//:rules.bzl", "bats_test")

When I run bazel test ..., it errors with:

DEBUG: Rule '_main~_repo_rules~bazel_bats' indicated that a canonical reproducible form can be obtained by modifying arguments shallow_since = "1698393980 +0000"
DEBUG: Repository _main~_repo_rules~bazel_bats instantiated at:
  <builtin>: in <toplevel>
Repository rule git_repository defined at:
  /private/var/tmp/_bazel_nyap/7eb50fa838052a8fa44693f01a28f8d0/external/bazel_tools/tools/build_defs/repo/git.bzl:189:33: in <toplevel>
ERROR: no such package '@@[unknown repo 'bats_core' requested from @@_main~_repo_rules~bazel_bats]//': The repository '@@[unknown repo 'bats_core' requested from @@_main~_repo_rules~bazel_bats]' could not be resolved: No repository visible as '@bats_core' from repository '@@_main~_repo_rules~bazel_bats'
ERROR: /Users/nyap/tasks/bash-mock/BUILD.bazel:8:10: every rule of type _bats_test implicitly depends upon the target '@@[unknown repo 'bats_core' requested from @@_main~_repo_rules~bazel_bats]//:bats', but this target could not be found because of: no such package '@@[unknown repo 'bats_core' requested from @@_main~_repo_rules~bazel_bats]//': The repository '@@[unknown repo 'bats_core' requested from @@_main~_repo_rules~bazel_bats]' could not be resolved: No repository visible as '@bats_core' from repository '@@_main~_repo_rules~bazel_bats'
ERROR: Analysis of target '//:bats_test' failed; build aborted: Analysis failed
INFO: Elapsed time: 0.748s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
ERROR: Build did NOT complete successfully
ERROR: No test targets were found, yet testing was requested

Can README.md include instructions using MODULE.bazel?

filmil commented 3 months ago

Hello. It's not going to work with modules, since that requires all the sub-repos to be modules as well; or a special extension setup which I think is not worth the effort.

Not sure what your use case is, but after having quite a blast with trying to migrate some of my repos to modules I've concluded that it's too early to do so. It is OK to use both WORKSPACE and MODULE, and for the time being I'd recommend using bazel-bats through WORKSPACE only.

But if you have a firm requirement to use this code through MODULE, may I suggest contributing a fix?

noel-yap commented 3 months ago

I don't know enough about MODULE to gauge whether it was something I was doing wrong or if bats itself needed to support it

Thanks for the info. It saved me a bunch of time going down a futile rabbit hole

noel-yap commented 2 months ago

It looks like https://docs.aspect.build/rulesets/aspect_bazel_lib/docs/bats/ has a different implementation of bats_test (it doesn't have a deps setting; instead what would go into deps needs to be part of data) and that rule can be used via bzlmod