aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/shell/bazel/bazel_coverage_test.sh
diff options
context:
space:
mode:
authorGravatar elenairina <elenairina@google.com>2018-07-06 03:06:21 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-07-06 03:07:25 -0700
commit9438d1042df9e70570d245f6bd259acdfbb3455e (patch)
tree106816a832efd2a1c351966de94fe52277c70f32 /src/test/shell/bazel/bazel_coverage_test.sh
parentc4622ac9205d2f1b42dac8c598e83113d39e7f11 (diff)
Create Bazel coverage report action.
Fixes #5246 RELNOTES: None. PiperOrigin-RevId: 203453340
Diffstat (limited to 'src/test/shell/bazel/bazel_coverage_test.sh')
-rwxr-xr-xsrc/test/shell/bazel/bazel_coverage_test.sh88
1 files changed, 88 insertions, 0 deletions
diff --git a/src/test/shell/bazel/bazel_coverage_test.sh b/src/test/shell/bazel/bazel_coverage_test.sh
index 41a51a65cf..8235f7cf79 100755
--- a/src/test/shell/bazel/bazel_coverage_test.sh
+++ b/src/test/shell/bazel/bazel_coverage_test.sh
@@ -232,6 +232,94 @@ EOF
fi
}
+function test_java_test_coverage_combined_report() {
+
+ cat <<EOF > BUILD
+java_test(
+ name = "test",
+ srcs = glob(["src/test/**/*.java"]),
+ test_class = "com.example.TestCollatz",
+ deps = [":collatz-lib"],
+)
+
+java_library(
+ name = "collatz-lib",
+ srcs = glob(["src/main/**/*.java"]),
+)
+EOF
+
+ mkdir -p src/main/com/example
+ cat <<EOF > src/main/com/example/Collatz.java
+package com.example;
+
+public class Collatz {
+
+ public static int getCollatzFinal(int n) {
+ if (n == 1) {
+ return 1;
+ }
+ if (n % 2 == 0) {
+ return getCollatzFinal(n / 2);
+ } else {
+ return getCollatzFinal(n * 3 + 1);
+ }
+ }
+
+}
+EOF
+
+ mkdir -p src/test/com/example
+ cat <<EOF > src/test/com/example/TestCollatz.java
+package com.example;
+
+import static org.junit.Assert.assertEquals;
+import org.junit.Test;
+
+public class TestCollatz {
+
+ @Test
+ public void testGetCollatzFinal() {
+ assertEquals(Collatz.getCollatzFinal(1), 1);
+ assertEquals(Collatz.getCollatzFinal(5), 1);
+ assertEquals(Collatz.getCollatzFinal(10), 1);
+ assertEquals(Collatz.getCollatzFinal(21), 1);
+ }
+
+}
+EOF
+
+ bazel coverage //:test --coverage_report_generator=@bazel_tools//tools/test/LcovMerger/java/com/google/devtools/lcovmerger:Main --combined_report=lcov &>$TEST_log \
+ || echo "Coverage for //:test failed"
+
+ cat <<EOF > result.dat
+SF:com/example/Collatz.java
+FN:3,com/example/Collatz::<init> ()V
+FN:6,com/example/Collatz::getCollatzFinal (I)I
+FNDA:0,com/example/Collatz::<init> ()V
+FNDA:1,com/example/Collatz::getCollatzFinal (I)I
+FNF:2
+FNH:1
+BA:6,2
+BA:9,2
+BRF:2
+BRH:2
+DA:3,0
+DA:6,3
+DA:7,2
+DA:9,4
+DA:10,5
+DA:12,7
+LH:5
+LF:6
+end_of_record
+EOF
+
+ if ! cmp result.dat ./bazel-out/_coverage/_coverage_report.dat; then
+ diff result.dat bazel-out/_coverage/_coverage_report.dat >> $TEST_log
+ fail "Coverage output file is different with expected"
+ fi
+}
+
function test_java_test_java_import_coverage() {
cat <<EOF > BUILD