Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow writing shell integration tests #156

Closed
wants to merge 3 commits into from
Closed

Allow writing shell integration tests #156

wants to merge 3 commits into from

Conversation

katre
Copy link
Collaborator

@katre katre commented May 23, 2023

As part of bazelbuild/rules_android#76, I wanted to write shell integration tests (like android_sdk_integration_test.sh) for the new Starlark android_sdk_repository rule.

However, to do that with rules_bazel_integration_test I need two things:

  1. A copy of bashunit, so script with (the trying to use the copy in Bazel is far too heavyweight), and
  2. A way to directly depend on a bazel binary.

See https://github.com/katre/rules_android/commit/056dfc21eb075155c86f51734833b3e91554129d for a demo of using these in action. I am happy to update documentation in the repository as needed.

The license attribution is directly copied from the existing Bazel files. Please let me know if this is a problem.

@katre
Copy link
Collaborator Author

katre commented May 23, 2023

@illicitonion If you'd like to chat about this on slack or via email instead of github comments, let me know.

@cgrindel
Copy link
Member

@katre Thanks for the PR. If I understand correctly, there are two parts to this PR:

  1. Make bashunit available for Bazel tests.
  2. Add an alias for the current Bazel version.

For the first part, perhaps we should consider creating a Bazel module repository for bashunit. Then, anybody can install it.

With regard to the alias, I took a look at how it was being used in rules_android. I think that we already support a pattern that may work. By any chance, did you come across the dynamic workspace test runner example? If you use the bazel_integeration_test macro and pass it a runner, the runner will be called with two environment variables set: BIT_BAZEL_BINARY and BIT_WORKSPACE_DIR. The BIT_BAZEL_BINARY is the path to the Bazel binary specified in the bazel_integration_test declaration.

I see in the Android SDK test that the test workspace is generated by the script. We support this pattern, as well, with one caveat. A test runner script can create all of the workspace files that it needs and then execute tests. The closest example is the use_create_scratch_dir_test.sh. (Sorry that is very cumbersome name. 😳) Just ignore the use of create_scratch_dir. The test is just creating a directory and filling it with Bazel workspace files. The caveat is that there is no good way to use bazel_integration_test without pointing it at an existing child workspace directory. However, I think that we can make that happen without too much effort.

Do you think using bazel_integration_test will work for your use case?

@katre katre closed this Jun 29, 2023
@katre katre deleted the enable-sh-tests branch June 29, 2023 19:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants