Skip to content

Commit

Permalink
test: add qjs unittest and test workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
mgred committed Jan 1, 2024
1 parent 92c9785 commit 9e3553b
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test --test_output=errors
common --enable_bzlmod
11 changes: 6 additions & 5 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*.sh export-ignore
.bazel* export-ignore
.git* export-ignore
e2e export-ignore
examples export-ignore
*.sh export-ignore
.bazel* export-ignore
.git* export-ignore
e2e export-ignore
examples export-ignore
quickjs/*_test.bzl export-ignore
4 changes: 4 additions & 0 deletions .github/workflows/ci.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Used in github workflow `test.yaml`
build --disk_cache=~/.cache/bazel
build --repository_cache=~/.cache/bazel-repo
test --test_env=XDG_CACHE_HOME
66 changes: 66 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Test

on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:

env:
XDG_CACHE_HOME: ~/.cache/bazel-repo

jobs:
pre-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Mount bazel caches
uses: actions/cache@v3
with:
path: |
~/.cache/bazel
~/.cache/bazel-repo
key: bazel-cache-${{ hashFiles('**/BUILD.bazel', '**/*.bzl', 'WORKSPACE') }}
restore-keys: bazel-cache-
- name: bazel test //:setup
run: >
bazel
--bazelrc=${{ github.workspace }}/.bazelrc
--bazelrc=${{ github.workspace }}/.github/workflows/ci.bazelrc
test //:setup
test:
needs: ["pre-test"]
runs-on: ubuntu-latest
strategy:
matrix:
bazelversion:
- 6.4.0
- 7.0.0
folder:
- "."
- "e2e"
steps:
- uses: actions/checkout@v4
- name: Mount bazel caches
uses: actions/cache@v3
with:
path: |
~/.cache/bazel
~/.cache/bazel-repo
key: bazel-cache-${{ hashFiles('**/BUILD.bazel', '**/*.bzl', 'WORKSPACE') }}
restore-keys: bazel-cache-
- name: bazel version
working-directory: ${{ matrix.folder }}
env:
USE_BAZEL_VERSION: ${{ matrix.bazelversion }}
run: bazel version
- name: bazel test //...
working-directory: ${{ matrix.folder }}
env:
USE_BAZEL_VERSION: ${{ matrix.bazelversion }}
run: >
bazel
--bazelrc=${{ github.workspace }}/.bazelrc
--bazelrc=${{ github.workspace }}/.github/workflows/ci.bazelrc
test //...
9 changes: 9 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,12 @@ buildifier_test(
tags = ["manual"],
workspace = "//:WORKSPACE",
)

test_suite(
name = "setup",
tags = ["manual"],
tests = [
":lint",
"//docs:update_test",
],
)
4 changes: 3 additions & 1 deletion docs/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ stardoc_with_diff_test(
bzl_library_target = "//quickjs:qjs",
)

update_docs()
update_docs(
tags = ["manual"],
)
3 changes: 3 additions & 0 deletions quickjs/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load(":qjs_test.bzl", "qjs_test_suite")

exports_files(
[
Expand Down Expand Up @@ -31,3 +32,5 @@ bzl_library(
srcs = ["version.bzl"],
visibility = ["//quickjs:__subpackages__"],
)

qjs_test_suite()
32 changes: 32 additions & 0 deletions quickjs/qjs_test.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"qjs test suite"

load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts")
load("@bazel_skylib//rules:write_file.bzl", "write_file")
load(":qjs.bzl", "qjs_binary")

def _create_launcher_test_impl(ctx):
env = analysistest.begin(ctx)
launcher_file = analysistest.target_actions(env)[0].outputs.to_list()[0].basename
asserts.equals(env, launcher_file, "qjs_test_launcher.sh")
return analysistest.end(env)

create_launcher_test = analysistest.make(_create_launcher_test_impl)

def qjs_test_suite(name = "qjs_test"):
create_launcher_test(
name = "create_launcher_test",
target_under_test = ":qjs_test",
)

write_file(
name = "index_js",
out = "index.js",
content = [
"print('Hello, World!');",
],
)

qjs_binary(
name = name,
entry_point = ":index.js",
)

0 comments on commit 9e3553b

Please sign in to comment.