diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8cad308..f4133e1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,9 +3,9 @@ repos: rev: v6.0.0 hooks: - id: end-of-file-fixer - exclude: ^tests/integration/(?:[^/]+/)*fixtures/ + exclude: ^tests/fixtures/(?:[^/]+/)*expected/ - id: trailing-whitespace - exclude: ^tests/integration/(?:[^/]+/)*fixtures/ + exclude: ^tests/fixtures/(?:[^/]+/)*expected/ - id: check-yaml - id: check-added-large-files diff --git a/tests/BUILD.bazel b/tests/BUILD.bazel index e533912..52d3283 100644 --- a/tests/BUILD.bazel +++ b/tests/BUILD.bazel @@ -1,7 +1,11 @@ -test_suite( - name = "tests", - tests = [ - "//tests/integration:tests", - "//tests/rules:tests", - ], -) +load(":dokka_tests.bzl", "dokka_test_suite") +load(":generated_docs_tests.bzl", "generated_docs_test_suite") +load(":multi_module_tests.bzl", "multi_module_test_suite") + +dokka_test_suite(name = "dokka") + +generated_docs_test_suite(name = "generated_docs") + +multi_module_test_suite(name = "multi_module") + +test_suite(name = "all_tests") diff --git a/tests/integration/configured_publication_docs_test.sh b/tests/configured_publication_docs_test.sh similarity index 100% rename from tests/integration/configured_publication_docs_test.sh rename to tests/configured_publication_docs_test.sh diff --git a/tests/integration/derived_module_defaults_test.sh b/tests/derived_module_defaults_test.sh similarity index 93% rename from tests/integration/derived_module_defaults_test.sh rename to tests/derived_module_defaults_test.sh index bbe1c86..2b0db51 100755 --- a/tests/integration/derived_module_defaults_test.sh +++ b/tests/derived_module_defaults_test.sh @@ -17,7 +17,7 @@ set -e # --- end runfiles.bash initialization v3 --- docs="$(rlocation "$1")" -module_path="tests/integration/derived" +module_path="tests/fixtures/derived_defaults" test -f "${docs}/index.html" || { echo "Missing aggregate index under ${docs}" >&2 @@ -31,7 +31,7 @@ grep -Fq "Derived Module Defaults" "${docs}/index.html" || { echo "Aggregate index does not contain its title" >&2 exit 1 } -grep -Fq "derived_docs" "${docs}/index.html" || { +grep -Fq ">docs" "${docs}/index.html" || { echo "Aggregate index does not contain the label-derived module name" >&2 exit 1 } diff --git a/tests/rules/dokka_analysis_test.bzl b/tests/dokka_tests.bzl similarity index 93% rename from tests/rules/dokka_analysis_test.bzl rename to tests/dokka_tests.bzl index 52ca150..844da23 100644 --- a/tests/rules/dokka_analysis_test.bzl +++ b/tests/dokka_tests.bzl @@ -30,7 +30,7 @@ def _dokka_configuration_test_impl(ctx): info = target[DokkaInfo] asserts.equals(env, "gfm", info.format) asserts.equals(env, "fixture-module", info.module_name) - asserts.equals(env, "tests/rules", info.module_path) + asserts.equals(env, "tests/fixtures/analysis", info.module_path) asserts.equals(env, None, info.partial_documentation) documentation_files = target[DefaultInfo].files.to_list() @@ -177,7 +177,7 @@ def _dokka_defaults_test_impl(ctx): asserts.equals(env, "html", info.format) asserts.equals(env, "defaults_fixture", info.module_name) - asserts.equals(env, "tests/rules", info.module_path) + asserts.equals(env, "tests/fixtures/analysis", info.module_path) asserts.true(env, info.partial_documentation.is_directory) asserts.equals( env, @@ -313,7 +313,7 @@ def _dokka_multi_module_test_impl(ctx): asserts.equals(env, "docs", modules[1]["name"]) asserts.equals( env, - "tests/rules/nested", + "tests/fixtures/analysis/nested", modules[1]["relativePathToOutputDirectory"], ) asserts.equals(env, [], modules[1]["includes"]) @@ -468,7 +468,7 @@ _non_html_module_test = analysistest.make( expect_failure = True, ) -def dokka_analysis_test_suite(name): +def dokka_test_suite(name): """Defines the Dokka analysis test suite. Args: @@ -476,66 +476,65 @@ def dokka_analysis_test_suite(name): """ _dokka_configuration_test( name = name + "_configuration", - target_under_test = ":analysis_fixture", + tags = [name], + target_under_test = "//tests/fixtures/analysis:analysis_fixture", ) _dokka_defaults_test( name = name + "_defaults", - target_under_test = ":defaults_fixture", + tags = [name], + target_under_test = "//tests/fixtures/analysis:defaults_fixture", ) _dokka_deps_test( name = name + "_deps", - target_under_test = ":deps_fixture", + tags = [name], + target_under_test = "//tests/fixtures/analysis:deps_fixture", ) _dokka_wasm_test( name = name + "_wasm", - target_under_test = ":wasm_fixture", + tags = [name], + target_under_test = "//tests/fixtures/analysis:wasm_fixture", ) _dokka_multi_module_test( name = name + "_multi_module", - target_under_test = ":multi_module_fixture", + tags = [name], + target_under_test = "//tests/fixtures/analysis:multi_module_fixture", ) _dokka_reusable_config_test( name = name + "_reusable_config", - target_under_test = ":configured_fixture", + tags = [name], + target_under_test = "//tests/fixtures/analysis:configured_fixture", ) _invalid_config_test( name = name + "_invalid_config", - target_under_test = ":invalid_config_fixture", + tags = [name], + target_under_test = "//tests/fixtures/analysis:invalid_config_fixture", ) _duplicate_module_path_test( name = name + "_duplicate_module_path", - target_under_test = ":duplicate_aggregate_fixture", + tags = [name], + target_under_test = "//tests/fixtures/analysis:duplicate_aggregate_fixture", ) _duplicate_module_name_test( name = name + "_duplicate_module_name", - target_under_test = ":duplicate_module_name_aggregate_fixture", + tags = [name], + target_under_test = "//tests/fixtures/analysis:duplicate_module_name_aggregate_fixture", ) _invalid_module_path_test( name = name + "_invalid_module_path", - target_under_test = ":invalid_path_aggregate_fixture", + tags = [name], + target_under_test = "//tests/fixtures/analysis:invalid_path_aggregate_fixture", ) _reserved_module_path_test( name = name + "_reserved_module_path", - target_under_test = ":reserved_path_aggregate_fixture", + tags = [name], + target_under_test = "//tests/fixtures/analysis:reserved_path_aggregate_fixture", ) _non_html_module_test( name = name + "_non_html_module", - target_under_test = ":non_html_aggregate_fixture", + tags = [name], + target_under_test = "//tests/fixtures/analysis:non_html_aggregate_fixture", ) native.test_suite( name = name, - tests = [ - ":" + name + "_configuration", - ":" + name + "_defaults", - ":" + name + "_deps", - ":" + name + "_duplicate_module_name", - ":" + name + "_duplicate_module_path", - ":" + name + "_invalid_config", - ":" + name + "_invalid_module_path", - ":" + name + "_multi_module", - ":" + name + "_non_html_module", - ":" + name + "_reserved_module_path", - ":" + name + "_reusable_config", - ":" + name + "_wasm", - ], + tags = [name], ) diff --git a/tests/fixtures/BUILD.bazel b/tests/fixtures/BUILD.bazel new file mode 100644 index 0000000..97e25ca --- /dev/null +++ b/tests/fixtures/BUILD.bazel @@ -0,0 +1,8 @@ +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") + +package(default_visibility = ["//tests:__subpackages__"]) + +bzl_library( + name = "common", + srcs = ["common.bzl"], +) diff --git a/tests/rules/BUILD.bazel b/tests/fixtures/analysis/BUILD.bazel similarity index 84% rename from tests/rules/BUILD.bazel rename to tests/fixtures/analysis/BUILD.bazel index 9a0c375..14b3b72 100644 --- a/tests/rules/BUILD.bazel +++ b/tests/fixtures/analysis/BUILD.bazel @@ -1,16 +1,20 @@ load("@rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library") load("//dokka:defs.bzl", "dokka", "dokka_config", "dokka_multi_module") -load(":dokka_analysis_test.bzl", "dokka_analysis_test_suite") +load("//tests/fixtures:common.bzl", "FIXTURE_TAGS") + +package(default_visibility = ["//tests:__subpackages__"]) kt_jvm_library( name = "dependency", srcs = ["Dependency.kt"], neverlink = True, + tags = FIXTURE_TAGS, ) kt_jvm_library( name = "custom_plugin", srcs = ["CustomPlugin.kt"], + tags = FIXTURE_TAGS, ) dokka_config( @@ -37,6 +41,7 @@ dokka_config( suppress_annotated_with = ["com.example.InternalApi"], suppress_inherited_members = True, suppress_obvious_functions = False, + tags = FIXTURE_TAGS, ) dokka_config( @@ -63,12 +68,13 @@ dokka_config( suppress_annotated_with = ["com.example.ExperimentalApi"], suppress_inherited_members = True, suppress_obvious_functions = False, + tags = FIXTURE_TAGS, ) dokka_config( name = "wasm_config", analysis_platform = "wasm", - tags = ["manual"], + tags = FIXTURE_TAGS, ) dokka( @@ -81,7 +87,7 @@ dokka( module_version = "1.2.3", samples = ["Sample.kt"], suppressed_files = ["Suppressed.kt"], - tags = ["manual"], + tags = FIXTURE_TAGS, deps = [":dependency"], ) @@ -89,26 +95,26 @@ dokka( name = "wasm_fixture", srcs = ["Fixture.kt"], config = ":wasm_config", - tags = ["manual"], + tags = FIXTURE_TAGS, ) dokka( name = "defaults_fixture", srcs = ["Fixture.kt"], - tags = ["manual"], + tags = FIXTURE_TAGS, ) dokka( name = "deps_fixture", srcs = ["DepsFixture.kt"], - tags = ["manual"], + tags = FIXTURE_TAGS, deps = [":dependency"], ) dokka( name = "docs", srcs = ["Fixture.kt"], - tags = ["manual"], + tags = FIXTURE_TAGS, ) dokka( @@ -117,28 +123,28 @@ dokka( includes = ["module.md"], module_name = "API", module_path = "api", - tags = ["manual"], + tags = FIXTURE_TAGS, ) dokka( name = "duplicate_module_path_fixture", srcs = ["Fixture.kt"], module_path = "api", - tags = ["manual"], + tags = FIXTURE_TAGS, ) dokka( name = "invalid_module_path_fixture", srcs = ["Fixture.kt"], module_path = "../invalid", - tags = ["manual"], + tags = FIXTURE_TAGS, ) dokka( name = "reserved_module_path_fixture", srcs = ["Fixture.kt"], module_path = "scripts/api", - tags = ["manual"], + tags = FIXTURE_TAGS, ) dokka_multi_module( @@ -146,10 +152,10 @@ dokka_multi_module( config = ":shared_config", includes = ["module.md"], modules = [ - "//tests/rules/nested:docs", + "//tests/fixtures/analysis/nested:docs", ":module_api_fixture", ], - tags = ["manual"], + tags = FIXTURE_TAGS, title = "Project API Reference", ) @@ -159,34 +165,34 @@ dokka_multi_module( ":module_api_fixture", ":duplicate_module_path_fixture", ], - tags = ["manual"], + tags = FIXTURE_TAGS, ) dokka_multi_module( name = "duplicate_module_name_aggregate_fixture", modules = [ - "//tests/rules/nested:docs", + "//tests/fixtures/analysis/nested:docs", ":docs", ], - tags = ["manual"], + tags = FIXTURE_TAGS, ) dokka_multi_module( name = "invalid_path_aggregate_fixture", modules = [":invalid_module_path_fixture"], - tags = ["manual"], + tags = FIXTURE_TAGS, ) dokka_multi_module( name = "reserved_path_aggregate_fixture", modules = [":reserved_module_path_fixture"], - tags = ["manual"], + tags = FIXTURE_TAGS, ) dokka_multi_module( name = "non_html_aggregate_fixture", modules = [":analysis_fixture"], - tags = ["manual"], + tags = FIXTURE_TAGS, ) dokka( @@ -197,13 +203,11 @@ dokka( includes = ["module.md"], module_name = "configured-module", module_version = "4.5.6", - tags = ["manual"], + tags = FIXTURE_TAGS, ) dokka_config( name = "invalid_config_fixture", documented_visibilities = ["public"], - tags = ["manual"], + tags = FIXTURE_TAGS, ) - -dokka_analysis_test_suite(name = "tests") diff --git a/tests/rules/CustomPlugin.kt b/tests/fixtures/analysis/CustomPlugin.kt similarity index 100% rename from tests/rules/CustomPlugin.kt rename to tests/fixtures/analysis/CustomPlugin.kt diff --git a/tests/rules/Dependency.kt b/tests/fixtures/analysis/Dependency.kt similarity index 100% rename from tests/rules/Dependency.kt rename to tests/fixtures/analysis/Dependency.kt diff --git a/tests/rules/DepsFixture.kt b/tests/fixtures/analysis/DepsFixture.kt similarity index 100% rename from tests/rules/DepsFixture.kt rename to tests/fixtures/analysis/DepsFixture.kt diff --git a/tests/rules/Fixture.kt b/tests/fixtures/analysis/Fixture.kt similarity index 100% rename from tests/rules/Fixture.kt rename to tests/fixtures/analysis/Fixture.kt diff --git a/tests/rules/Sample.kt b/tests/fixtures/analysis/Sample.kt similarity index 100% rename from tests/rules/Sample.kt rename to tests/fixtures/analysis/Sample.kt diff --git a/tests/rules/Suppressed.kt b/tests/fixtures/analysis/Suppressed.kt similarity index 100% rename from tests/rules/Suppressed.kt rename to tests/fixtures/analysis/Suppressed.kt diff --git a/tests/rules/module.md b/tests/fixtures/analysis/module.md similarity index 100% rename from tests/rules/module.md rename to tests/fixtures/analysis/module.md diff --git a/tests/fixtures/analysis/nested/BUILD.bazel b/tests/fixtures/analysis/nested/BUILD.bazel new file mode 100644 index 0000000..1bb6413 --- /dev/null +++ b/tests/fixtures/analysis/nested/BUILD.bazel @@ -0,0 +1,10 @@ +load("//dokka:defs.bzl", "dokka") +load("//tests/fixtures:common.bzl", "FIXTURE_TAGS") + +package(default_visibility = ["//tests:__subpackages__"]) + +dokka( + name = "docs", + srcs = ["Nested.kt"], + tags = FIXTURE_TAGS, +) diff --git a/tests/rules/nested/Nested.kt b/tests/fixtures/analysis/nested/Nested.kt similarity index 100% rename from tests/rules/nested/Nested.kt rename to tests/fixtures/analysis/nested/Nested.kt diff --git a/tests/fixtures/common.bzl b/tests/fixtures/common.bzl new file mode 100644 index 0000000..1532ae5 --- /dev/null +++ b/tests/fixtures/common.bzl @@ -0,0 +1,8 @@ +"""Common definitions used by test fixtures.""" + +# Fixture targets are analyzed by tests or consumed as test data. They should +# not be selected as runnable test entry points themselves. +FIXTURE_TAGS = [ + "manual", + "notap", +] diff --git a/tests/integration/deps/BUILD.bazel b/tests/fixtures/dependencies/BUILD.bazel similarity index 68% rename from tests/integration/deps/BUILD.bazel rename to tests/fixtures/dependencies/BUILD.bazel index 872202c..6d3f776 100644 --- a/tests/integration/deps/BUILD.bazel +++ b/tests/fixtures/dependencies/BUILD.bazel @@ -1,17 +1,22 @@ load("@bazel_lib//lib:copy_to_directory.bzl", "copy_to_directory") load("@rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library") load("//dokka:defs.bzl", "dokka", "dokka_config") +load("//tests/fixtures:common.bzl", "FIXTURE_TAGS") + +package(default_visibility = ["//tests:__subpackages__"]) kt_jvm_library( name = "dependency", srcs = ["Dependency.kt"], neverlink = True, + tags = FIXTURE_TAGS, ) dokka_config( name = "config", no_jdk_link = True, no_stdlib_link = True, + tags = FIXTURE_TAGS, ) dokka( @@ -20,6 +25,7 @@ dokka( config = ":config", format = "gfm", module_name = "Dependency API", + tags = FIXTURE_TAGS, deps = [":dependency"], ) @@ -30,13 +36,13 @@ copy_to_directory( replace_prefixes = { "-dependency -a-p-i/com.example/-uses-dependency": "uses-dependency", }, - root_paths = ["tests/integration/deps/docs"], - visibility = ["//tests/integration:__pkg__"], + root_paths = ["tests/fixtures/dependencies/docs"], + tags = FIXTURE_TAGS, ) copy_to_directory( name = "expected_markdown", - srcs = glob(["fixtures/**/*.md"]), - root_paths = ["tests/integration/deps/fixtures"], - visibility = ["//tests/integration:__pkg__"], + srcs = glob(["expected/**/*.md"]), + root_paths = ["tests/fixtures/dependencies/expected"], + tags = FIXTURE_TAGS, ) diff --git a/tests/integration/deps/Dependency.kt b/tests/fixtures/dependencies/Dependency.kt similarity index 100% rename from tests/integration/deps/Dependency.kt rename to tests/fixtures/dependencies/Dependency.kt diff --git a/tests/integration/deps/UsesDependency.kt b/tests/fixtures/dependencies/UsesDependency.kt similarity index 100% rename from tests/integration/deps/UsesDependency.kt rename to tests/fixtures/dependencies/UsesDependency.kt diff --git a/tests/integration/deps/fixtures/uses-dependency/index.md b/tests/fixtures/dependencies/expected/uses-dependency/index.md similarity index 100% rename from tests/integration/deps/fixtures/uses-dependency/index.md rename to tests/fixtures/dependencies/expected/uses-dependency/index.md diff --git a/tests/fixtures/derived_defaults/BUILD.bazel b/tests/fixtures/derived_defaults/BUILD.bazel new file mode 100644 index 0000000..873a312 --- /dev/null +++ b/tests/fixtures/derived_defaults/BUILD.bazel @@ -0,0 +1,10 @@ +load("//dokka:defs.bzl", "dokka") +load("//tests/fixtures:common.bzl", "FIXTURE_TAGS") + +package(default_visibility = ["//tests:__subpackages__"]) + +dokka( + name = "docs", + srcs = ["Derived.kt"], + tags = FIXTURE_TAGS, +) diff --git a/tests/integration/derived/Derived.kt b/tests/fixtures/derived_defaults/Derived.kt similarity index 100% rename from tests/integration/derived/Derived.kt rename to tests/fixtures/derived_defaults/Derived.kt diff --git a/tests/fixtures/generated_docs/BUILD.bazel b/tests/fixtures/generated_docs/BUILD.bazel new file mode 100644 index 0000000..6f50f4b --- /dev/null +++ b/tests/fixtures/generated_docs/BUILD.bazel @@ -0,0 +1,83 @@ +load("@bazel_lib//lib:copy_to_directory.bzl", "copy_to_directory") +load("//dokka:defs.bzl", "dokka", "dokka_config") +load("//tests/fixtures:common.bzl", "FIXTURE_TAGS") + +package(default_visibility = ["//tests:__subpackages__"]) + +dokka_config( + name = "config", + no_jdk_link = True, + no_stdlib_link = True, + tags = FIXTURE_TAGS, +) + +dokka_config( + name = "publication_config", + plugins_configuration = { + "org.jetbrains.dokka.base.DokkaBase": "{\"footerMessage\":\"rules_dokka aggregate footer\"}", + }, + suppress_inherited_members = True, + suppress_obvious_functions = False, + tags = FIXTURE_TAGS, +) + +dokka( + name = "gfm_docs", + srcs = [ + "Bar.kt", + "Main.kt", + ], + config = ":config", + format = "gfm", + module_name = "Example API", + tags = FIXTURE_TAGS, +) + +dokka( + name = "html_docs", + srcs = [ + "Bar.kt", + "Main.kt", + ], + config = ":config", + format = "html", + module_name = "Example API", + tags = FIXTURE_TAGS, +) + +dokka( + name = "javadoc_docs", + srcs = [ + "Bar.kt", + "Main.kt", + ], + config = ":config", + format = "javadoc", + module_name = "Example API", + tags = FIXTURE_TAGS, +) + +dokka( + name = "api_docs", + srcs = ["Main.kt"], + config = ":config", + module_name = "API", + module_path = "api", + tags = FIXTURE_TAGS, +) + +dokka( + name = "data_docs", + srcs = ["Bar.kt"], + config = ":config", + module_name = "Data", + module_path = "data", + tags = FIXTURE_TAGS, +) + +copy_to_directory( + name = "expected_gfm_markdown", + srcs = glob(["expected/gfm_docs/**/*.md"]), + root_paths = ["tests/fixtures/generated_docs/expected/gfm_docs"], + tags = FIXTURE_TAGS, +) diff --git a/tests/integration/src/main/kotlin/com/example/Bar.kt b/tests/fixtures/generated_docs/Bar.kt similarity index 100% rename from tests/integration/src/main/kotlin/com/example/Bar.kt rename to tests/fixtures/generated_docs/Bar.kt diff --git a/tests/integration/src/main/kotlin/com/example/Main.kt b/tests/fixtures/generated_docs/Main.kt similarity index 100% rename from tests/integration/src/main/kotlin/com/example/Main.kt rename to tests/fixtures/generated_docs/Main.kt diff --git a/tests/integration/fixtures/gfm_docs/example-api/com.example/bar/bar.md b/tests/fixtures/generated_docs/expected/gfm_docs/example-api/com.example/bar/bar.md similarity index 100% rename from tests/integration/fixtures/gfm_docs/example-api/com.example/bar/bar.md rename to tests/fixtures/generated_docs/expected/gfm_docs/example-api/com.example/bar/bar.md diff --git a/tests/integration/fixtures/gfm_docs/example-api/com.example/bar/index.md b/tests/fixtures/generated_docs/expected/gfm_docs/example-api/com.example/bar/index.md similarity index 100% rename from tests/integration/fixtures/gfm_docs/example-api/com.example/bar/index.md rename to tests/fixtures/generated_docs/expected/gfm_docs/example-api/com.example/bar/index.md diff --git a/tests/integration/fixtures/gfm_docs/example-api/com.example/bar/value.md b/tests/fixtures/generated_docs/expected/gfm_docs/example-api/com.example/bar/value.md similarity index 100% rename from tests/integration/fixtures/gfm_docs/example-api/com.example/bar/value.md rename to tests/fixtures/generated_docs/expected/gfm_docs/example-api/com.example/bar/value.md diff --git a/tests/integration/fixtures/gfm_docs/example-api/com.example/foo/foo.md b/tests/fixtures/generated_docs/expected/gfm_docs/example-api/com.example/foo/foo.md similarity index 100% rename from tests/integration/fixtures/gfm_docs/example-api/com.example/foo/foo.md rename to tests/fixtures/generated_docs/expected/gfm_docs/example-api/com.example/foo/foo.md diff --git a/tests/integration/fixtures/gfm_docs/example-api/com.example/foo/index.md b/tests/fixtures/generated_docs/expected/gfm_docs/example-api/com.example/foo/index.md similarity index 100% rename from tests/integration/fixtures/gfm_docs/example-api/com.example/foo/index.md rename to tests/fixtures/generated_docs/expected/gfm_docs/example-api/com.example/foo/index.md diff --git a/tests/integration/fixtures/gfm_docs/example-api/com.example/foo/value.md b/tests/fixtures/generated_docs/expected/gfm_docs/example-api/com.example/foo/value.md similarity index 100% rename from tests/integration/fixtures/gfm_docs/example-api/com.example/foo/value.md rename to tests/fixtures/generated_docs/expected/gfm_docs/example-api/com.example/foo/value.md diff --git a/tests/integration/fixtures/gfm_docs/example-api/com.example/index.md b/tests/fixtures/generated_docs/expected/gfm_docs/example-api/com.example/index.md similarity index 100% rename from tests/integration/fixtures/gfm_docs/example-api/com.example/index.md rename to tests/fixtures/generated_docs/expected/gfm_docs/example-api/com.example/index.md diff --git a/tests/integration/fixtures/gfm_docs/index.md b/tests/fixtures/generated_docs/expected/gfm_docs/index.md similarity index 100% rename from tests/integration/fixtures/gfm_docs/index.md rename to tests/fixtures/generated_docs/expected/gfm_docs/index.md diff --git a/tests/integration/generated_docs_test.sh b/tests/generated_docs_test.sh similarity index 100% rename from tests/integration/generated_docs_test.sh rename to tests/generated_docs_test.sh diff --git a/tests/generated_docs_tests.bzl b/tests/generated_docs_tests.bzl new file mode 100644 index 0000000..a21bb29 --- /dev/null +++ b/tests/generated_docs_tests.bzl @@ -0,0 +1,66 @@ +"""Execution tests for documentation generated by the Dokka rule.""" + +load("@bazel_lib//lib:copy_to_directory.bzl", "copy_to_directory") +load("@bazel_lib//lib:diff_test.bzl", "diff_test") +load("@rules_shell//shell:sh_test.bzl", "sh_test") + +def generated_docs_test_suite(name): + """Defines tests for single-module generated documentation. + + Args: + name: Base name and tag for the generated tests. + """ + copy_to_directory( + name = name + "_actual_gfm_markdown", + srcs = ["//tests/fixtures/generated_docs:gfm_docs"], + include_srcs_patterns = [ + "*.md", + "**/*.md", + ], + replace_prefixes = { + "-example -a-p-i": "example-api", + "-example -a-p-i/com.example/-bar": "example-api/com.example/bar", + "-example -a-p-i/com.example/-bar/-bar.md": "example-api/com.example/bar/bar.md", + "-example -a-p-i/com.example/-foo": "example-api/com.example/foo", + "-example -a-p-i/com.example/-foo/-foo.md": "example-api/com.example/foo/foo.md", + }, + root_paths = ["tests/fixtures/generated_docs/gfm_docs"], + ) + + diff_test( + name = name + "_gfm_diff", + failure_message = "Generated GFM documentation differs from its checked-in fixtures.", + file1 = "//tests/fixtures/generated_docs:expected_gfm_markdown", + file2 = ":" + name + "_actual_gfm_markdown", + tags = [name], + ) + + diff_test( + name = name + "_dependencies_diff", + failure_message = "Dokka did not resolve the API exposed by its compiled dependency.", + file1 = "//tests/fixtures/dependencies:expected_markdown", + file2 = "//tests/fixtures/dependencies:actual_markdown", + tags = [name], + ) + + sh_test( + name = name + "_formats", + srcs = ["generated_docs_test.sh"], + args = [ + "$(rlocationpath //tests/fixtures/generated_docs:gfm_docs)", + "$(rlocationpath //tests/fixtures/generated_docs:html_docs)", + "$(rlocationpath //tests/fixtures/generated_docs:javadoc_docs)", + ], + data = [ + "//tests/fixtures/generated_docs:gfm_docs", + "//tests/fixtures/generated_docs:html_docs", + "//tests/fixtures/generated_docs:javadoc_docs", + ], + deps = ["@bazel_tools//tools/bash/runfiles"], + tags = [name], + ) + + native.test_suite( + name = name, + tags = [name], + ) diff --git a/tests/integration/BUILD.bazel b/tests/integration/BUILD.bazel deleted file mode 100644 index d4beea9..0000000 --- a/tests/integration/BUILD.bazel +++ /dev/null @@ -1,173 +0,0 @@ -load("@bazel_lib//lib:copy_to_directory.bzl", "copy_to_directory") -load("@bazel_lib//lib:diff_test.bzl", "diff_test") -load("@rules_shell//shell:sh_test.bzl", "sh_test") -load("//dokka:defs.bzl", "dokka", "dokka_config", "dokka_multi_module") - -dokka_config( - name = "integration_config", - no_jdk_link = True, - no_stdlib_link = True, -) - -dokka_config( - name = "publication_config", - plugins_configuration = { - "org.jetbrains.dokka.base.DokkaBase": "{\"footerMessage\":\"rules_dokka aggregate footer\"}", - }, - suppress_inherited_members = True, - suppress_obvious_functions = False, -) - -dokka( - name = "gfm_docs", - srcs = glob(["src/main/kotlin/**/*.kt"]), - config = ":integration_config", - format = "gfm", - module_name = "Example API", -) - -copy_to_directory( - name = "actual_gfm_markdown", - srcs = [":gfm_docs"], - include_srcs_patterns = [ - "*.md", - "**/*.md", - ], - replace_prefixes = { - "-example -a-p-i": "example-api", - "-example -a-p-i/com.example/-bar": "example-api/com.example/bar", - "-example -a-p-i/com.example/-bar/-bar.md": "example-api/com.example/bar/bar.md", - "-example -a-p-i/com.example/-foo": "example-api/com.example/foo", - "-example -a-p-i/com.example/-foo/-foo.md": "example-api/com.example/foo/foo.md", - }, - root_paths = ["tests/integration/gfm_docs"], -) - -copy_to_directory( - name = "expected_gfm_markdown", - srcs = glob(["fixtures/gfm_docs/**/*.md"]), - root_paths = ["tests/integration/fixtures/gfm_docs"], -) - -diff_test( - name = "gfm_docs_diff_test", - failure_message = "Generated GFM documentation differs from its checked-in fixtures.", - file1 = ":expected_gfm_markdown", - file2 = ":actual_gfm_markdown", -) - -diff_test( - name = "deps_diff_test", - failure_message = "Dokka did not resolve the API exposed by its compiled dependency.", - file1 = "//tests/integration/deps:expected_markdown", - file2 = "//tests/integration/deps:actual_markdown", -) - -dokka( - name = "html_docs", - srcs = glob(["src/main/kotlin/**/*.kt"]), - config = ":integration_config", - format = "html", - module_name = "Example API", -) - -dokka( - name = "javadoc_docs", - srcs = glob(["src/main/kotlin/**/*.kt"]), - config = ":integration_config", - format = "javadoc", - module_name = "Example API", -) - -dokka( - name = "api_docs", - srcs = ["src/main/kotlin/com/example/Main.kt"], - config = ":integration_config", - module_name = "API", - module_path = "api", -) - -dokka( - name = "data_docs", - srcs = ["src/main/kotlin/com/example/Bar.kt"], - config = ":integration_config", - module_name = "Data", - module_path = "data", -) - -dokka_multi_module( - name = "docs", - modules = [ - ":api_docs", - ":data_docs", - ], - title = "Project API Reference", -) - -dokka_multi_module( - name = "configured_docs", - config = ":publication_config", - modules = [ - ":api_docs", - ":data_docs", - ], - title = "Configured Project API Reference", -) - -dokka_multi_module( - name = "derived_defaults_docs", - modules = ["//tests/integration/derived:derived_docs"], - title = "Derived Module Defaults", -) - -sh_test( - name = "generated_docs_test", - srcs = ["generated_docs_test.sh"], - args = [ - "$(rlocationpath :gfm_docs)", - "$(rlocationpath :html_docs)", - "$(rlocationpath :javadoc_docs)", - ], - data = [ - ":gfm_docs", - ":html_docs", - ":javadoc_docs", - ], - deps = ["@bazel_tools//tools/bash/runfiles"], -) - -sh_test( - name = "multi_module_docs_test", - srcs = ["multi_module_docs_test.sh"], - args = ["$(rlocationpath :docs)"], - data = [":docs"], - deps = ["@bazel_tools//tools/bash/runfiles"], -) - -sh_test( - name = "configured_publication_docs_test", - srcs = ["configured_publication_docs_test.sh"], - args = ["$(rlocationpath :configured_docs)"], - data = [":configured_docs"], - deps = ["@bazel_tools//tools/bash/runfiles"], -) - -sh_test( - name = "derived_module_defaults_test", - srcs = ["derived_module_defaults_test.sh"], - args = ["$(rlocationpath :derived_defaults_docs)"], - data = [":derived_defaults_docs"], - deps = ["@bazel_tools//tools/bash/runfiles"], -) - -test_suite( - name = "tests", - tests = [ - ":configured_publication_docs_test", - ":deps_diff_test", - ":derived_module_defaults_test", - ":generated_docs_test", - ":gfm_docs_diff_test", - ":multi_module_docs_test", - ], -) diff --git a/tests/integration/derived/BUILD.bazel b/tests/integration/derived/BUILD.bazel deleted file mode 100644 index 82dff02..0000000 --- a/tests/integration/derived/BUILD.bazel +++ /dev/null @@ -1,7 +0,0 @@ -load("//dokka:defs.bzl", "dokka") - -dokka( - name = "derived_docs", - srcs = ["Derived.kt"], - visibility = ["//tests/integration:__pkg__"], -) diff --git a/tests/integration/multi_module_docs_test.sh b/tests/multi_module_docs_test.sh similarity index 100% rename from tests/integration/multi_module_docs_test.sh rename to tests/multi_module_docs_test.sh diff --git a/tests/multi_module_tests.bzl b/tests/multi_module_tests.bzl new file mode 100644 index 0000000..df4dfd8 --- /dev/null +++ b/tests/multi_module_tests.bzl @@ -0,0 +1,67 @@ +"""Execution tests for multi-module Dokka publications.""" + +load("@rules_shell//shell:sh_test.bzl", "sh_test") +load("//dokka:defs.bzl", "dokka_multi_module") + +def multi_module_test_suite(name): + """Defines tests for multi-module generated documentation. + + Args: + name: Base name and tag for the generated tests. + """ + dokka_multi_module( + name = name + "_docs", + modules = [ + "//tests/fixtures/generated_docs:api_docs", + "//tests/fixtures/generated_docs:data_docs", + ], + title = "Project API Reference", + ) + + dokka_multi_module( + name = name + "_configured_docs", + config = "//tests/fixtures/generated_docs:publication_config", + modules = [ + "//tests/fixtures/generated_docs:api_docs", + "//tests/fixtures/generated_docs:data_docs", + ], + title = "Configured Project API Reference", + ) + + dokka_multi_module( + name = name + "_derived_defaults_docs", + modules = ["//tests/fixtures/derived_defaults:docs"], + title = "Derived Module Defaults", + ) + + sh_test( + name = name + "_generated_docs", + srcs = ["multi_module_docs_test.sh"], + args = ["$(rlocationpath :" + name + "_docs)"], + data = [":" + name + "_docs"], + deps = ["@bazel_tools//tools/bash/runfiles"], + tags = [name], + ) + + sh_test( + name = name + "_configured_publication", + srcs = ["configured_publication_docs_test.sh"], + args = ["$(rlocationpath :" + name + "_configured_docs)"], + data = [":" + name + "_configured_docs"], + deps = ["@bazel_tools//tools/bash/runfiles"], + tags = [name], + ) + + sh_test( + name = name + "_derived_module_defaults", + srcs = ["derived_module_defaults_test.sh"], + args = ["$(rlocationpath :" + name + "_derived_defaults_docs)"], + data = [":" + name + "_derived_defaults_docs"], + deps = ["@bazel_tools//tools/bash/runfiles"], + tags = [name], + ) + + native.test_suite( + name = name, + tags = [name], + ) diff --git a/tests/rules/nested/BUILD.bazel b/tests/rules/nested/BUILD.bazel deleted file mode 100644 index 0bac7f1..0000000 --- a/tests/rules/nested/BUILD.bazel +++ /dev/null @@ -1,8 +0,0 @@ -load("//dokka:defs.bzl", "dokka") - -dokka( - name = "docs", - srcs = ["Nested.kt"], - tags = ["manual"], - visibility = ["//tests/rules:__pkg__"], -)