Skip to content

Commit

Permalink
Add test to ensure generated docs and files are up to date
Browse files Browse the repository at this point in the history
This also removes a need on the root build file to depend on
stardoc.
  • Loading branch information
shs96c committed Feb 23, 2023
1 parent 9014f0c commit 23b3927
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 47 deletions.
38 changes: 4 additions & 34 deletions BUILD
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
load("@io_bazel_stardoc//stardoc:stardoc.bzl", "stardoc")
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")

exports_files(["defs.bzl"])
exports_files([
"defs.bzl",
"specs.bzl",
])

licenses(["notice"]) # Apache 2.0

Expand All @@ -13,33 +15,6 @@ exports_files(
visibility = ["//scripts:__pkg__"],
)

stardoc(
name = "defs",
out = "defs.md",
input = "defs.bzl",
symbol_names = [
"javadoc",
"java_export",
"maven_bom",
"maven_install",
],
visibility = ["//scripts:__pkg__"],
deps = ["//:implementation"],
)

stardoc(
name = "specs",
out = "specs.md",
input = "specs.bzl",
symbol_names = [
"maven.artifact",
"maven.repository",
"maven.exclusion",
],
visibility = ["//scripts:__pkg__"],
deps = ["//:implementation"],
)

bzl_library(
name = "implementation",
srcs = [
Expand Down Expand Up @@ -84,8 +59,3 @@ alias(
name = "mirror_coursier",
actual = "//scripts:mirror_coursier",
)

alias(
name = "generate_api_reference",
actual = "//scripts:generate_api_reference",
)
54 changes: 49 additions & 5 deletions scripts/BUILD
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary")
load("@io_bazel_stardoc//stardoc:stardoc.bzl", "stardoc")
load("//private:versions.bzl", "COURSIER_CLI_HTTP_FILE_NAME")
load("//private/rules:artifact.bzl", "artifact")
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary")

exports_files([
])

genrule(
name = "buildifier-bin",
Expand All @@ -25,16 +29,16 @@ genrule(
name = "generate_base_docs",
srcs = [
"//:docs/includes/main_functions_header.md",
"//:defs.md",
"defs.md",
"//:docs/includes/spec_functions_header.md",
"//:specs.md",
"specs.md",
],
outs = ["generate_base_docs.md"],
cmd = """cat \
$(location //:docs/includes/main_functions_header.md) \
$(location //:defs.md) \
$(location :defs.md) \
$(location //:docs/includes/spec_functions_header.md) \
$(location //:specs.md) > $@""",
$(location :specs.md) > $@""",
)

genrule(
Expand All @@ -46,12 +50,52 @@ genrule(
visibility = ["//:__pkg__"],
)

sh_binary(
name = "generate-docs",
srcs = [
"copy-prebuilts.sh",
],
args = [
"docs",
"$(location :generate_api_reference)",
"api.md",
],
data = [
":generate_api_reference",
],
)

nodejs_binary(
name = "doctoc",
data = ["@npm//doctoc"],
entry_point = {"@npm//:node_modules/doctoc": "doctoc.js"},
)

stardoc(
name = "defs",
out = "defs.md",
input = "//:defs.bzl",
symbol_names = [
"javadoc",
"java_export",
"maven_bom",
"maven_install",
],
deps = ["//:implementation"],
)

stardoc(
name = "specs",
out = "specs.md",
input = "//:specs.bzl",
symbol_names = [
"maven.artifact",
"maven.repository",
"maven.exclusion",
],
deps = ["//:implementation"],
)

java_binary(
name = "google-java-format",
jvm_flags = [
Expand Down
8 changes: 0 additions & 8 deletions scripts/generate_docs.sh

This file was deleted.

45 changes: 45 additions & 0 deletions tests/bazel_run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,33 @@
#
# Add a new test to the TESTS array and send all output to TEST_LOG

function test_docs_are_up_to_date() {
before_docs="$(git status)"
bazel run //scripts:generate-docs >> "$TEST_LOG" 2>&1
after_docs="$(git status)"
expect_same "$before_docs" "$after_docs"
}

function test_formatting_is_okay() {
before_format="$(git status)"
bazel run //scripts:format >> "$TEST_LOG" 2>&1
after_format="$(git status)"
expect_same "$before_format" "$after_format"
}

function test_prebuilts_are_up_to_date() {
temp=$(mktemp -d)
cp private/tools/prebuilt/*.jar "$temp"
bazel run //scripts:refresh-prebuilts >> "$TEST_LOG" 2>&1

for i in private/tools/prebuilt/*.jar; do
file_name=$(basename $i)
before="$(jar tvf "$temp/$file_name" | grep -v build-data.properties)"
after="$(jar tvf "private/tools/prebuilt/$file_name" | grep -v build-data.properties)"
expect_same "$before" "$after"
done
}

function test_dependency_aggregation() {
bazel query --notool_deps 'deps(@regression_testing//:com_sun_xml_bind_jaxb_ri)' >> "$TEST_LOG" 2>&1

Expand Down Expand Up @@ -112,6 +139,10 @@ function test_v1_lock_file_format() {
}

TESTS=(
"test_formatting_is_okay"
"test_prebuilts_are_up_to_date"
"test_docs_are_up_to_date"

"test_dependency_aggregation"
"test_duplicate_version_warning"
"test_duplicate_version_warning_same_version"
Expand Down Expand Up @@ -160,6 +191,20 @@ function expect_not_log() {
return 1
}

function expect_same() {
local before="$1"
local after="$2"

if [ "$before" != "$after" ]; then
diff <(echo "$before") <(echo "$after") >> "$TEST_LOG" 2>&1

printf "FAILED\n"
cat $TEST_LOG
DUMPED_TEST_LOG=1
return 1
fi
}

function exit_handler() {
local exit_code=$?
if [ $exit_code != "0" ] && [ $DUMPED_TEST_LOG == "0" ]; then
Expand Down

0 comments on commit 23b3927

Please sign in to comment.