Skip to content

Commit

Permalink
feat(corpus checker): allow specifying an allowlist of corpora (#5033)
Browse files Browse the repository at this point in the history
  • Loading branch information
justbuchanan committed Aug 11, 2021
1 parent d1ccce0 commit 1458594
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
4 changes: 4 additions & 0 deletions kythe/cxx/indexer/cxx/testdata/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,10 @@ cc_indexer_test(

empty_corpus_test(
name = "empty_corpus_test",
allowed_corpora = [
"file",
"unit",
],
entries = ":vname_corpus_entries.entries.gz",
)

Expand Down
12 changes: 12 additions & 0 deletions kythe/go/test/tools/empty_corpus_checker/empty_corpus_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ import (
spb "kythe.io/kythe/proto/storage_go_proto"
)

var allowedCorpora flagutil.StringSet

func init() {
flag.Usage = flagutil.SimpleUsage("Checks a stream of Entry protos via stdin for empty vname.corpus")

flag.Var(&allowedCorpora, "allowed_corpora", "Comma-separated list of corpora allowed in the input entrystream")
}

func main() {
Expand Down Expand Up @@ -77,5 +81,13 @@ func main() {
if emptyCorpusCount != 0 {
log.Fatalf("FAILURE: found %d sources with empty corpus", emptyCorpusCount)
}

if len(allowedCorpora) > 0 {
diff := allCorpora.Diff(stringset.Set(allowedCorpora))
if !diff.Empty() {
log.Fatalf("FAILURE: found entries with disallowed corpora: %v", diff)
}
}

log.Printf("Success! All vnames have a non-empty corpus.")
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
def empty_corpus_test(name, entries):
def empty_corpus_test(name, entries, allowed_corpora = []):
"""Instantiates a test that ensures all vnames in `entries` have a non-empty corpus."""

args = ["$(location %s)" % entries]
if len(allowed_corpora) > 0:
args.append("--allowed_corpora=" + ",".join(allowed_corpora))

native.sh_test(
name = name,
srcs = ["//kythe/go/test/tools/empty_corpus_checker:empty_corpus_test.sh"],
args = ["$(location %s)" % entries],
args = args,
data = [
entries,
"//kythe/go/test/tools/empty_corpus_checker",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ set -euo pipefail
# verify that all vnames have a non-empty corpus.

ENTRIES="$1"
shift

gunzip -c "$ENTRIES" | "$EMPTY_CORPUS_CHECKER"
gunzip -c "$ENTRIES" | "$EMPTY_CORPUS_CHECKER" "$@"

0 comments on commit 1458594

Please sign in to comment.