Skip to content

Commit

Permalink
Adds a presubmit check that veriefies the //:tests target.
Browse files Browse the repository at this point in the history
Makes sure that all tests in the project are referenced by that target.
  • Loading branch information
pmuetschard committed Aug 31, 2018
1 parent 53c6e59 commit 7915ae3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ test_suite(
name = "tests",
# bazel query --output label 'kind(".*_test rule", //...)'
tests = [
# __BEGIN_TESTS
"//core/app/analytics:go_default_test",
"//core/app/auth:go_default_test",
"//core/app/benchmark:go_default_test",
Expand Down Expand Up @@ -199,5 +200,6 @@ test_suite(
"//test/integration/replay:go_default_test",
"//test/integration/service:go_default_test",
"//test/robot/stash/grpc:go_default_test",
# __END_TESTS
],
)
10 changes: 10 additions & 0 deletions kokoro/presubmit/presubmit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ function run_buildozer() {
[ $r -eq 3 ] && return 0 || return $r
}

function run_enumerate_tests() {
TARGETS="$(bazel query --output label 'kind(".*_test rule", //...)' | sort -t: -k1,1 | awk '{print " \""$0"\","}')"
OUT=$(mktemp)
cp BUILD.bazel $OUT
cat $OUT | awk -v targets="$TARGETS" 'begin {a=0} /__END_TESTS/ {a=0} { if (a==0) print $0;} /__BEGIN_TESTS/ { a=1; print targets }' > BUILD.bazel
}

function run_gazelle() {
echo # TODO: figure out a way to make bazel not print anything.
$BAZEL run gazelle
Expand All @@ -89,6 +96,9 @@ check buildifier run_buildifier
# Check bazel style.
check "buildozer fix" run_buildozer

# Check that the //:tests target contains all tests.
check "//:tests contains all tests" run_enumerate_tests

# Check gazelle.
check "gazelle" run_gazelle

Expand Down

0 comments on commit 7915ae3

Please sign in to comment.