Repository: kythe/kythe
Pull request #5017 (2021-08-03 22:23:45)

feat(testing): refactor empty corpus test and add one for golang


Patch:
diff --git a/kythe/go/indexer/BUILD b/kythe/go/indexer/BUILD
index f8f013032..b102606a7 100644
--- a/kythe/go/indexer/BUILD
+++ b/kythe/go/indexer/BUILD
@@ -1,6 +1,7 @@
 load("//tools:build_rules/shims.bzl", "go_library", "go_test")
 load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
 load(":testdata/go_indexer_test.bzl", "go_indexer_test")
+load("//kythe/go/test/tools/empty_corpus_checker:empty_corpus_test.bzl", "empty_corpus_test")
 
 package(default_visibility = ["//kythe:default_visibility"])
 
@@ -233,6 +234,11 @@ go_indexer_test(
     use_compilation_corpus_as_default = True,
 )
 
+empty_corpus_test(
+    name = "empty_corpus_test",
+    entries = ":tappcorpus_test_entries.entries.gz",
+)
+
 # load(":testdata/go_indexer_test.bzl", "go_integration_test")
 # TODO(#2375): (closed?) requires MarkedSource resolution in pipeline
 # go_integration_test(


Test patch:
diff --git a/kythe/cxx/indexer/cxx/testdata/BUILD b/kythe/cxx/indexer/cxx/testdata/BUILD
index 15cbbe154..089e435da 100644
--- a/kythe/cxx/indexer/cxx/testdata/BUILD
+++ b/kythe/cxx/indexer/cxx/testdata/BUILD
@@ -5,6 +5,7 @@ load(
     "cc_indexer_test",
     "objc_indexer_test",
 )
+load("//kythe/go/test/tools/empty_corpus_checker:empty_corpus_test.bzl", "empty_corpus_test")
 
 package(default_visibility = ["//kythe:default_visibility"])
 
@@ -881,19 +882,9 @@ cc_indexer_test(
     use_compilation_corpus_as_default = True,
 )
 
-sh_test(
-    name = "vname_corpus_empty_test",
-    srcs = ["basic/empty_corpus_test.sh"],
-    args = ["$(location :vname_corpus_entries.entries.gz)"],
-    data = [
-        ":vname_corpus_entries.entries.gz",
-        "//kythe/go/platform/tools/entrystream",
-        "//kythe/go/test/tools/empty_corpus_checker",
-    ],
-    env = {
-        "EMPTY_CORPUS_CHECKER": "$(location //kythe/go/test/tools/empty_corpus_checker)",
-        "ENTRYSTREAM": "$(location //kythe/go/platform/tools/entrystream)",
-    },
+empty_corpus_test(
+    name = "empty_corpus_test",
+    entries = ":vname_corpus_entries.entries.gz",
 )
 
 cc_indexer_test(
diff --git a/kythe/go/test/tools/empty_corpus_checker/BUILD b/kythe/go/test/tools/empty_corpus_checker/BUILD
index a3f9f8c95..8ccd07a88 100644
--- a/kythe/go/test/tools/empty_corpus_checker/BUILD
+++ b/kythe/go/test/tools/empty_corpus_checker/BUILD
@@ -17,3 +17,5 @@ go_binary(
         "@org_golang_google_protobuf//proto:go_default_library",
     ],
 )
+
+exports_files(["empty_corpus_test.sh"])
diff --git a/kythe/go/test/tools/empty_corpus_checker/empty_corpus_checker.go b/kythe/go/test/tools/empty_corpus_checker/empty_corpus_checker.go
index 530f365d9..eea1791a2 100644
--- a/kythe/go/test/tools/empty_corpus_checker/empty_corpus_checker.go
+++ b/kythe/go/test/tools/empty_corpus_checker/empty_corpus_checker.go
@@ -71,4 +71,5 @@ func main() {
 	if emptyCorpusCount != 0 {
 		log.Fatalf("FAILURE: found %d sources with empty corpus", emptyCorpusCount)
 	}
+	log.Printf("Success! All vnames have a non-empty corpus.")
 }
diff --git a/kythe/go/test/tools/empty_corpus_checker/empty_corpus_test.bzl b/kythe/go/test/tools/empty_corpus_checker/empty_corpus_test.bzl
new file mode 100644
index 000000000..c0c85e416
--- /dev/null
+++ b/kythe/go/test/tools/empty_corpus_checker/empty_corpus_test.bzl
@@ -0,0 +1,14 @@
+def empty_corpus_test(name, entries):
+    """Instantiates a test that ensures all vnames in `entries` have a non-empty corpus."""
+    native.sh_test(
+        name = name,
+        srcs = ["//kythe/go/test/tools/empty_corpus_checker:empty_corpus_test.sh"],
+        args = ["$(location %s)" % entries],
+        data = [
+            entries,
+            "//kythe/go/test/tools/empty_corpus_checker",
+        ],
+        env = {
+            "EMPTY_CORPUS_CHECKER": "$(location //kythe/go/test/tools/empty_corpus_checker)",
+        },
+    )
diff --git a/kythe/cxx/indexer/cxx/testdata/basic/empty_corpus_test.sh b/kythe/go/test/tools/empty_corpus_checker/empty_corpus_test.sh
similarity index 92%
rename from kythe/cxx/indexer/cxx/testdata/basic/empty_corpus_test.sh
rename to kythe/go/test/tools/empty_corpus_checker/empty_corpus_test.sh
index b5db8f54b..10c38e8cd 100755
--- a/kythe/cxx/indexer/cxx/testdata/basic/empty_corpus_test.sh
+++ b/kythe/go/test/tools/empty_corpus_checker/empty_corpus_test.sh
@@ -20,4 +20,4 @@ set -euo pipefail
 
 ENTRIES="$1"
 
-gunzip -c "$ENTRIES" | "$ENTRYSTREAM" | "$EMPTY_CORPUS_CHECKER"
+gunzip -c "$ENTRIES" | "$EMPTY_CORPUS_CHECKER"