Skip to content

Commit 79c3624

Browse files
committed
feat: add testing
1 parent bd581be commit 79c3624

File tree

12 files changed

+603
-10
lines changed

12 files changed

+603
-10
lines changed

.github/workflows/ci.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
on:
2+
push:
3+
branches:
4+
- main
5+
pull_request:
6+
branches:
7+
- main
8+
jobs:
9+
test:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v5
13+
- uses: bazel-contrib/setup-bazel@0.15.0
14+
- name: Install Aspect CLI
15+
uses: jaxxstorm/action-install-gh-release@v2.1.0
16+
with:
17+
repo: aspect-build/aspect-cli
18+
tag: 2024.01 # secret old tag where binaries are stashed for now
19+
asset-name: aspect-cli
20+
platform: unknown_linux
21+
arch: x86_64
22+
extension-matching: disable
23+
rename-to: aspect
24+
chmod: 0755
25+
- name: Test
26+
working-directory: example
27+
shell: sh
28+
run: $GITHUB_WORKSPACE/example/README.md || exit 1

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
bazel-*

coverage.axl

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,31 @@ Gathers the coverage.dat files to power common developer workflows.
77
# buildifier: disable=function-docstring
88
def impl(ctx) -> int:
99
out = ctx.std.io.stdout
10+
err = ctx.std.io.stderr
1011
build = ctx.bazel.build(
1112
"//...",
1213
events = True,
1314
bazel_flags = [
1415
"--isatty=" + str(int(out.is_tty)),
15-
# We probably want to abbreviate the following flags under
16-
# "--config=coverage"
1716
"--collect_code_coverage",
18-
"--instrumentation_filter=",
19-
# See https://github.com/bazel-contrib/bazelrc-preset.bzl/issues/83
20-
"--experimental_fetch_all_coverage_outputs",
21-
"--experimental_split_coverage_postprocessing",
2217
],
2318
bazel_verb = "test"
2419
);
2520

21+
coverage_dat_files = []
2622
for event in build.events():
27-
# TODO: get the paths of produced (or cached) coverage report files
23+
if event.kind == "test_result":
24+
coverage_dat_files.extend([f.file.removeprefix("file://") for f in event.payload.test_action_output if f.file.endswith("coverage.dat")])
2825
# TODO: populate a GITHUB_OUTPUT variable so we can use https://github.com/codecov/codecov-action
29-
if event.type == "progress":
26+
if event.kind == "progress":
3027
out.write(event.payload.stdout)
31-
out.write(event.payload.stderr)
28+
err.write(event.payload.stderr)
3229

30+
if event.kind == "build_finished_id":
31+
for file in coverage_dat_files:
32+
out.write(file + "\n")
33+
out.write(ctx.std.fs.read_to_string(file) + "\n")
34+
3335
build.wait()
3436
# TODO: get the delta of changed files from VCS, and render 'incremental' coverage as the default presentation
3537

@@ -38,6 +40,6 @@ def impl(ctx) -> int:
3840
coverage = task(
3941
implementation = impl,
4042
args = {
41-
"targets": args.positional(minimum = 1, maximum = 30),
43+
"targets": args.positional(),
4244
}
4345
)

example/.aspect/coverage.axl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../coverage.axl

example/BUILD

Whitespace-only changes.

example/MODULE.bazel

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
bazel_dep(name = "aspect_rules_py", version = "1.6.3")
2+
bazel_dep(name = "rules_python", version = "1.6.3")
3+
4+
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
5+
python.toolchain(
6+
configure_coverage_tool = True,
7+
python_version = "3.11",
8+
)
9+
pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
10+
pip.parse(
11+
hub_name = "pip",
12+
python_version = "3.11",
13+
requirements_lock = "//:requirements.txt",
14+
)
15+
use_repo(pip, "pip")

example/MODULE.bazel.lock

Lines changed: 416 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Aspect coverage example
2+
3+
# This is executable Markdown that's tested on CI.
4+
set -o errexit -o nounset -o xtrace
5+
alias ~~~=":<<'~~~sh'";:<<'~~~sh'
6+
7+
## Try it out
8+
9+
Run the py_test target with `aspect coverage`.
10+
It should locate the coverage.dat files produced by the Python coverage library.
11+
12+
~~~sh
13+
output="$(aspect coverage //src:my_test)"
14+
15+
# Verify that it produces the expected output - half the functions are covered
16+
echo "${output}" | grep -q "FNF:2" || {
17+
echo >&2 "Functions Found should be 2 '${output}'"
18+
exit 1
19+
}
20+
echo "${output}" | grep -q "FNH:1" || {
21+
echo >&2 "Functions Hit should be 1 '${output}'"
22+
exit 1
23+
}
24+
~~~
25+

example/requirements.txt

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
coverage==7.6.10 \
2+
--hash=sha256:05fca8ba6a87aabdd2d30d0b6c838b50510b56cdcfc604d40760dae7153b73d9 \
3+
--hash=sha256:0aa9692b4fdd83a4647eeb7db46410ea1322b5ed94cd1715ef09d1d5922ba87f \
4+
--hash=sha256:0c807ca74d5a5e64427c8805de15b9ca140bba13572d6d74e262f46f50b13273 \
5+
--hash=sha256:0d7a2bf79378d8fb8afaa994f91bfd8215134f8631d27eba3e0e2c13546ce994 \
6+
--hash=sha256:0f460286cb94036455e703c66988851d970fdfd8acc2a1122ab7f4f904e4029e \
7+
--hash=sha256:204a8238afe787323a8b47d8be4df89772d5c1e4651b9ffa808552bdf20e1d50 \
8+
--hash=sha256:2396e8116db77789f819d2bc8a7e200232b7a282c66e0ae2d2cd84581a89757e \
9+
--hash=sha256:254f1a3b1eef5f7ed23ef265eaa89c65c8c5b6b257327c149db1ca9d4a35f25e \
10+
--hash=sha256:26bcf5c4df41cad1b19c84af71c22cbc9ea9a547fc973f1f2cc9a290002c8b3c \
11+
--hash=sha256:27c6e64726b307782fa5cbe531e7647aee385a29b2107cd87ba7c0105a5d3853 \
12+
--hash=sha256:299e91b274c5c9cdb64cbdf1b3e4a8fe538a7a86acdd08fae52301b28ba297f8 \
13+
--hash=sha256:2bcfa46d7709b5a7ffe089075799b902020b62e7ee56ebaed2f4bdac04c508d8 \
14+
--hash=sha256:2ccf240eb719789cedbb9fd1338055de2761088202a9a0b73032857e53f612fe \
15+
--hash=sha256:32ee6d8491fcfc82652a37109f69dee9a830e9379166cb73c16d8dc5c2915165 \
16+
--hash=sha256:3f7b444c42bbc533aaae6b5a2166fd1a797cdb5eb58ee51a92bee1eb94a1e1cb \
17+
--hash=sha256:457574f4599d2b00f7f637a0700a6422243b3565509457b2dbd3f50703e11f59 \
18+
--hash=sha256:489a01f94aa581dbd961f306e37d75d4ba16104bbfa2b0edb21d29b73be83609 \
19+
--hash=sha256:4bcc276261505d82f0ad426870c3b12cb177752834a633e737ec5ee79bbdff18 \
20+
--hash=sha256:4e0de1e902669dccbf80b0415fb6b43d27edca2fbd48c74da378923b05316098 \
21+
--hash=sha256:4e4630c26b6084c9b3cb53b15bd488f30ceb50b73c35c5ad7871b869cb7365fd \
22+
--hash=sha256:4eea95ef275de7abaef630c9b2c002ffbc01918b726a39f5a4353916ec72d2f3 \
23+
--hash=sha256:507a20fc863cae1d5720797761b42d2d87a04b3e5aeb682ef3b7332e90598f43 \
24+
--hash=sha256:54a5f0f43950a36312155dae55c505a76cd7f2b12d26abeebbe7a0b36dbc868d \
25+
--hash=sha256:55b201b97286cf61f5e76063f9e2a1d8d2972fc2fcfd2c1272530172fd28c359 \
26+
--hash=sha256:59af35558ba08b758aec4d56182b222976330ef8d2feacbb93964f576a7e7a90 \
27+
--hash=sha256:5c912978f7fbf47ef99cec50c4401340436d200d41d714c7a4766f377c5b7b78 \
28+
--hash=sha256:656c82b8a0ead8bba147de9a89bda95064874c91a3ed43a00e687f23cc19d53a \
29+
--hash=sha256:6713ba4b4ebc330f3def51df1d5d38fad60b66720948112f114968feb52d3f99 \
30+
--hash=sha256:675cefc4c06e3b4c876b85bfb7c59c5e2218167bbd4da5075cbe3b5790a28988 \
31+
--hash=sha256:6f93531882a5f68c28090f901b1d135de61b56331bba82028489bc51bdd818d2 \
32+
--hash=sha256:714f942b9c15c3a7a5fe6876ce30af831c2ad4ce902410b7466b662358c852c0 \
33+
--hash=sha256:79109c70cc0882e4d2d002fe69a24aa504dec0cc17169b3c7f41a1d341a73694 \
34+
--hash=sha256:7bbd8c8f1b115b892e34ba66a097b915d3871db7ce0e6b9901f462ff3a975377 \
35+
--hash=sha256:7ed2f37cfce1ce101e6dffdfd1c99e729dd2ffc291d02d3e2d0af8b53d13840d \
36+
--hash=sha256:7fb105327c8f8f0682e29843e2ff96af9dcbe5bab8eeb4b398c6a33a16d80a23 \
37+
--hash=sha256:89d76815a26197c858f53c7f6a656686ec392b25991f9e409bcef020cd532312 \
38+
--hash=sha256:9a7cfb50515f87f7ed30bc882f68812fd98bc2852957df69f3003d22a2aa0abf \
39+
--hash=sha256:9e1747bab246d6ff2c4f28b4d186b205adced9f7bd9dc362051cc37c4a0c7bd6 \
40+
--hash=sha256:9e80eba8801c386f72e0712a0453431259c45c3249f0009aff537a517b52942b \
41+
--hash=sha256:a01ec4af7dfeb96ff0078ad9a48810bb0cc8abcb0115180c6013a6b26237626c \
42+
--hash=sha256:a372c89c939d57abe09e08c0578c1d212e7a678135d53aa16eec4430adc5e690 \
43+
--hash=sha256:a3b204c11e2b2d883946fe1d97f89403aa1811df28ce0447439178cc7463448a \
44+
--hash=sha256:a534738b47b0de1995f85f582d983d94031dffb48ab86c95bdf88dc62212142f \
45+
--hash=sha256:a5e37dc41d57ceba70956fa2fc5b63c26dba863c946ace9705f8eca99daecdc4 \
46+
--hash=sha256:aa744da1820678b475e4ba3dfd994c321c5b13381d1041fe9c608620e6676e25 \
47+
--hash=sha256:ab32947f481f7e8c763fa2c92fd9f44eeb143e7610c4ca9ecd6a36adab4081bd \
48+
--hash=sha256:abb02e2f5a3187b2ac4cd46b8ced85a0858230b577ccb2c62c81482ca7d18852 \
49+
--hash=sha256:b330368cb99ef72fcd2dc3ed260adf67b31499584dc8a20225e85bfe6f6cfed0 \
50+
--hash=sha256:bc67deb76bc3717f22e765ab3e07ee9c7a5e26b9019ca19a3b063d9f4b874244 \
51+
--hash=sha256:c0b1818063dc9e9d838c09e3a473c1422f517889436dd980f5d721899e66f315 \
52+
--hash=sha256:c56e097019e72c373bae32d946ecf9858fda841e48d82df7e81c63ac25554078 \
53+
--hash=sha256:c7827a5bc7bdb197b9e066cdf650b2887597ad124dd99777332776f7b7c7d0d0 \
54+
--hash=sha256:ccc2b70a7ed475c68ceb548bf69cec1e27305c1c2606a5eb7c3afff56a1b3b27 \
55+
--hash=sha256:d37a84878285b903c0fe21ac8794c6dab58150e9359f1aaebbeddd6412d53132 \
56+
--hash=sha256:e2f0280519e42b0a17550072861e0bc8a80a0870de260f9796157d3fca2733c5 \
57+
--hash=sha256:e4ae5ac5e0d1e4edfc9b4b57b4cbecd5bc266a6915c500f358817a8496739247 \
58+
--hash=sha256:e67926f51821b8e9deb6426ff3164870976fe414d033ad90ea75e7ed0c2e5022 \
59+
--hash=sha256:e78b270eadb5702938c3dbe9367f878249b5ef9a2fcc5360ac7bff694310d17b \
60+
--hash=sha256:ea3c8f04b3e4af80e17bab607c386a830ffc2fb88a5484e1df756478cf70d1d3 \
61+
--hash=sha256:ec22b5e7fe7a0fa8509181c4aac1db48f3dd4d3a566131b313d1efc102892c18 \
62+
--hash=sha256:f4f620668dbc6f5e909a0946a877310fb3d57aea8198bde792aae369ee1c23b5 \
63+
--hash=sha256:fd34e7b3405f0cc7ab03d54a334c17a9e802897580d964bd8c2001f4b9fd488f
64+
pytest==8.1.1 \
65+
--hash=sha256:2a8386cfc11fa9d2c50ee7b2a57e7d898ef90470a7a34c4b949ff59662bb78b7 \
66+
--hash=sha256:ac978141a75948948817d360297b7aae0fcb9d6ff6bc9ec6d514b85d5a65c044
67+
iniconfig==2.0.0 \
68+
--hash=sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3 \
69+
--hash=sha256:b6a85871a79d2e3b22d2d1b94ac2824226a63c6b741c88f7ae975f18b6778374
70+
# via pytest
71+
packaging==24.2 \
72+
--hash=sha256:09abb1bccd265c01f4a3aa3f7a7db064b36514d2cba19a2f694fe6150451a759 \
73+
--hash=sha256:c228a6dc5e932d346bc5739379109d49e8853dd8223571c7c5b55260edc0b97f
74+
# via pytest
75+
pluggy==1.5.0 \
76+
--hash=sha256:2cffa88e94fdc978c4c574f15f9e59b7f4201d439195c3715ca9e2486f1d0cf1 \
77+
--hash=sha256:44e1ad92c8ca002de6377e165f3e0f1be63266ab4d554740532335b9d75ea669
78+
# via pytest

example/src/BUILD

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
load("@aspect_rules_py//py:defs.bzl", "py_test", "py_library")
2+
load("@pip//:requirements.bzl", "requirement")
3+
4+
py_library(
5+
name = "my_lib",
6+
srcs = ["my.py"],
7+
)
8+
9+
py_test(
10+
name = "my_test",
11+
srcs = ["my_test.py"],
12+
pytest_main = True,
13+
deps = [
14+
":my_lib",
15+
requirement("coverage"),
16+
requirement("pytest"),
17+
],
18+
)

0 commit comments

Comments
 (0)