Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test to ensure generated docs and files are up to date #841

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

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

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)

echo "Comparing $file_name" >> "$TEST_LOG"

different="$(comm -3 <(jar tvf "$temp/$file_name" | grep -v build-data.properties | sort) <(jar tvf "private/tools/prebuilt/$file_name" | grep -v build-data.properties | sort))"

if [ -n "$different" ]; then
echo "$different" >> "$TEST_LOG" 2>&1

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

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_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 +149,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 +201,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