Skip to content

Commit de81967

Browse files
authored
Example of how to write tests if you vendor dependencies. (#628)
* Make sh tests portable
1 parent 0cac0ab commit de81967

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

developers.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,11 @@ organization will commit to maintaining that feature and responding to issues.
9696
distribution.
9797
- Other new dependencies are strongly discouraged. The exception is that we
9898
may take dependencies on other modules maintained by the Bazel team.
99+
100+
### Write for vendoring the source tree.
101+
102+
We presume that some users will vendor this entire rule set into their source
103+
tree and want to test it from their WORKSPACE. Towards that end we try to
104+
minimize the places where we assume the path to any package is absolute
105+
from WORKSPACE. See tests/package_naming_aggregate_test.sh for an example
106+
of how we can write a sh_test that works after re-rooting the sources.

tests/package_naming_aggregate_test.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
# that we get the expected file names.
1717
set -e
1818

19-
declare -r DATA_DIR="${TEST_SRCDIR}/rules_pkg/tests"
19+
# Portably find the absolute path to the test data, even if this code has been
20+
# vendored in to a source tree and re-rooted.
21+
TEST_PACKAGE="$(echo ${TEST_TARGET} | sed -e 's/:.*$//' -e 's@//@@')"
22+
declare -r DATA_DIR="${TEST_SRCDIR}/${TEST_WORKSPACE}/${TEST_PACKAGE}"
2023

2124
for pkg in test_naming_some_value.deb test_naming_some_value.tar test_naming_some_value.zip ; do
2225
ls -l "${DATA_DIR}/$pkg"

0 commit comments

Comments
 (0)