File: coverage.org

package info (click to toggle)
emacs-bazel-mode 0.0~git20230919.769b30d-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 488 kB
  • sloc: lisp: 3,487; sh: 65; makefile: 32; awk: 18
file content (131 lines) | stat: -rw-r--r-- 4,557 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# Copyright 2021, 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

* Test data for coverage tests

Set up a fake workspace and execution root in the current directory.  We use a
Java library because C++ and Python coverage is quite broken.  Specifically,
[[https://github.com/bazelbuild/bazel/issues/10457][C++ coverage doesn’t work
on macOS]], and [[https://github.com/bazelbuild/bazel/issues/10660][Python
coverage doesn’t work at all]].  Java coverage still
[[https://github.com/bazelbuild/bazel/issues/13358][suffers from some bugs]],
but can at least be made to work somewhat reliably.

#+PROPERTY: header-args :mkdirp yes :main no

#+BEGIN_SRC bazel-workspace :tangle WORKSPACE
workspace(name = "test")
#+END_src

We follow the
[[https://bazel.build/docs/bazel-and-java#best-practices][Java-specific best
practices]].

#+BEGIN_SRC bazel-build :tangle src/main/java/example/BUILD
java_library(
    name = "example",
    srcs = glob(["*.java"]),
    visibility = ["//src/test/java/example:__pkg__"],
)
#+END_SRC

#+BEGIN_SRC bazel-build :tangle src/test/java/example/BUILD
java_test(
    name = "example_test",
    srcs = glob(["*.java"]),
    test_class = "example.ExampleTest",
    deps = ["//src/main/java/example"],
)
#+END_SRC

#+BEGIN_SRC java :tangle src/main/java/example/Example.java
package example;

public class Example {
    public static int function(boolean arg) {
        if (arg) {
            return 137;
        } else {
            return 42;
        }
    }
}
#+END_SRC

#+BEGIN_SRC java :tangle src/test/java/example/ExampleTest.java
package example;

import static org.junit.Assert.assertEquals;
import org.junit.Test;

public class ExampleTest {
    @Test
    public void function() {
        assertEquals(137, Example.function(true));
    }
}
#+END_SRC

#+BEGIN_SRC fundamental :tangle bazel-out/k8-fastbuild/testlogs/src/test/java/example/example_test/coverage.dat
SF:src/main/java/example/Example.java
FN:3,example/Example::<init> ()V
FN:5,example/Example::function (Z)I
FNDA:0,example/Example::<init> ()V
FNDA:1,example/Example::function (Z)I
FNF:2
FNH:1
BRDA:5,0,0,1
BRDA:5,0,1,0
BRF:2
BRH:1
DA:3,0
DA:5,1
DA:6,1
DA:8,0
LH:2
LF:4
end_of_record
#+END_SRC

Merged standard output and error from Bazel:

#+BEGIN_SRC fundamental :tangle bazel.out
Loading: 
Loading: 0 packages loaded
INFO: Using default value for --instrumentation_filter: "^//src/main/java/example[/:]".
INFO: Override the above default with --instrumentation_filter
Analyzing: 2 targets (2 packages loaded, 0 targets configured)
Analyzing: 2 targets (13 packages loaded, 49 targets configured)
Analyzing: 2 targets (13 packages loaded, 49 targets configured)
Analyzing: 2 targets (23 packages loaded, 362 targets configured)
Analyzing: 2 targets (25 packages loaded, 423 targets configured)
Analyzing: 2 targets (26 packages loaded, 587 targets configured)
INFO: Analyzed 2 targets (27 packages loaded, 764 targets configured).
INFO: Found 1 target and 1 test target...
bazel: Entering directory `%ROOTDIR%/'
[0 / 10] [Prepa] BazelWorkspaceStatusAction stable-status.txt
[8 / 13] Action external/bazel_tools/tools/jdk/platformclasspath_classes/DumpPlatformClassPath.class; 1s darwin-sandbox
[10 / 13] Compiling Java headers src/main/java/example/libexample-hjar.jar (1 source file); 0s darwin-sandbox ... (2 actions running)
[19 / 22] Action external/bazel_tools/tools/jdk/platformclasspath.jar; 0s darwin-sandbox
bazel: Leaving directory `%ROOTDIR%/'
INFO: Elapsed time: 13,442s, Critical Path: 4,12s
INFO: 22 processes: 12 internal, 7 darwin-sandbox, 3 worker.
INFO: Build completed successfully, 22 total actions
//src/test/java/example:example_test                                     PASSED in 0.8s
  %ROOTDIR%/bazel-out/k8-fastbuild/testlogs/src/test/java/example/example_test/coverage.dat

Executed 1 out of 1 test: 1 test passes.
There were tests whose specified size is too big. Use the --test_verbose_timeout_warnings command line option to see which ones these are.
INFO: Build completed successfully, 22 total actions
#+END_SRC