Clean up skydoc_test RELNOTES: None. PiperOrigin-RevId: 270085139
diff --git a/src/test/java/com/google/devtools/build/skydoc/BUILD b/src/test/java/com/google/devtools/build/skydoc/BUILD index 7d54560..fa91203 100644 --- a/src/test/java/com/google/devtools/build/skydoc/BUILD +++ b/src/test/java/com/google/devtools/build/skydoc/BUILD
@@ -68,6 +68,7 @@ skydoc_test( name = "input_template_test", aspect_template = "testdata/input_template_test/aspect.vm", + format = "custom", func_template = "testdata/input_template_test/func.vm", golden_file = "testdata/input_template_test/golden.txt", header_template = "testdata/input_template_test/header.vm", @@ -99,7 +100,7 @@ name = "simple_test", golden_file = "testdata/simple_test/golden.txt", input_file = "testdata/simple_test/input.bzl", - whitelisted_symbols = ["my_rule"], + symbol_names = ["my_rule"], ) skydoc_test( @@ -127,28 +128,28 @@ semantic_flags = [ "--experimental_google_legacy_api", ], - whitelisted_symbols = ["android_related_rule"], + symbol_names = ["android_related_rule"], ) skydoc_test( name = "apple_basic_test", golden_file = "testdata/apple_basic_test/golden.txt", input_file = "testdata/apple_basic_test/input.bzl", - whitelisted_symbols = ["apple_related_rule"], + symbol_names = ["apple_related_rule"], ) skydoc_test( name = "cpp_basic_test", golden_file = "testdata/cpp_basic_test/golden.txt", input_file = "testdata/cpp_basic_test/input.bzl", - whitelisted_symbols = ["cpp_related_rule"], + symbol_names = ["cpp_related_rule"], ) skydoc_test( name = "java_basic_test", golden_file = "testdata/java_basic_test/golden.txt", input_file = "testdata/java_basic_test/input.bzl", - whitelisted_symbols = ["java_related_rule"], + symbol_names = ["java_related_rule"], ) skydoc_test( @@ -165,7 +166,7 @@ name = "same_level_file_test", golden_file = "//src/test/java/com/google/devtools/build/skydoc/testdata/same_level_file_test:golden.txt", input_file = "//src/test/java/com/google/devtools/build/skydoc/testdata/same_level_file_test:input.bzl", - whitelisted_symbols = ["my_rule"], + symbol_names = ["my_rule"], deps = [ "//src/test/java/com/google/devtools/build/skydoc/testdata/same_level_file_test:dep.bzl", ], @@ -181,14 +182,14 @@ name = "attribute_types_test", golden_file = "testdata/attribute_types_test/golden.txt", input_file = "testdata/attribute_types_test/input.bzl", - whitelisted_symbols = ["my_rule"], + symbol_names = ["my_rule"], ) skydoc_test( name = "filter_rules_test", golden_file = "testdata/filter_rules_test/golden.txt", input_file = "testdata/filter_rules_test/input.bzl", - whitelisted_symbols = [ + symbol_names = [ "my_rule", "whitelisted_dep_rule", ], @@ -225,7 +226,7 @@ name = "namespace_test_with_whitelist", golden_file = "testdata/namespace_test/golden.txt", input_file = "testdata/namespace_test/input.bzl", - whitelisted_symbols = [ + symbol_names = [ "my_namespace", ], ) @@ -240,7 +241,7 @@ name = "multi_level_namespace_test_with_whitelist", golden_file = "testdata/multi_level_namespace_test_with_whitelist/golden.txt", input_file = "testdata/multi_level_namespace_test_with_whitelist/input.bzl", - whitelisted_symbols = [ + symbol_names = [ "my_namespace", "other_namespace.foo.nothing", ], @@ -256,7 +257,7 @@ name = "py_rule_test", golden_file = "testdata/py_rule_test/golden.txt", input_file = "testdata/py_rule_test/input.bzl", - whitelisted_symbols = ["py_related_rule"], + symbol_names = ["py_related_rule"], ) skydoc_test( @@ -282,9 +283,9 @@ skydoc_test( name = "pure_markdown_template_test", + format = "markdown_tables", golden_file = "testdata/pure_markdown_template_test/golden.txt", input_file = "testdata/pure_markdown_template_test/input.bzl", - test = "pure_markdown", ) genrule(
diff --git a/src/test/java/com/google/devtools/build/skydoc/skydoc_test.bzl b/src/test/java/com/google/devtools/build/skydoc/skydoc_test.bzl index 74cf994..66a94ad 100644 --- a/src/test/java/com/google/devtools/build/skydoc/skydoc_test.bzl +++ b/src/test/java/com/google/devtools/build/skydoc/skydoc_test.bzl
@@ -21,18 +21,13 @@ """Convenience macro for skydoc tests.""" load("@bazel_skylib//:bzl_library.bzl", "bzl_library") -load("@io_bazel_skydoc//stardoc:pure_markdown_stardoc.bzl", "pure_markdown_stardoc") -load("@io_bazel_skydoc//stardoc:stardoc.bzl", "stardoc") +load(":stardoc_for_testing.bzl", "stardoc") def skydoc_test( name, input_file, golden_file, deps = [], - whitelisted_symbols = [], - semantic_flags = [], - format = "markdown", - test = "default", **kwargs): """Creates a test target and golden-file regeneration target for skydoc testing. @@ -46,18 +41,7 @@ golden_file: The label string of the golden file containing the documentation when skydoc is run on the input file. deps: A list of label strings of skylark file dependencies of the input_file. - whitelisted_symbols: A list of strings representing top-level symbols in the input file - to generate documentation for. If empty, documentation for all top-level symbols - will be generated. - semantic_flags: A list of canonical flags to affect Starlark semantics for the Starlark interpretter - during documentation generation. This should only be used to maintain compatibility with - non-default semantic flags required to use the given Starlark symbols. For example, if - <code>//foo:bar.bzl</code> does not build except when a user would specify - <code>--incompatible_foo_semantic=false</code>, then this attribute should contain - "--incompatible_foo_semantic=false" - format: The format of the output file. - test: The type of test (default or pure_markdown). - **kwargs: A dictionary of input template names mapped to template file path for which documentation is generated. + **kwargs: Remaining arguments to passthrough to the underlying stardoc rule. """ actual_generated_doc = "%s_output.txt" % name @@ -85,30 +69,12 @@ deps = deps, ) - if test == "default": - stardoc( - name = "regenerate_%s_golden" % name, - out = actual_generated_doc, - input = input_file, - symbol_names = whitelisted_symbols, - deps = ["%s_lib" % name], - renderer = Label("//src/main/java/com/google/devtools/build/skydoc/renderer:renderer"), - stardoc = Label("//src/main/java/com/google/devtools/build/skydoc:skydoc"), - semantic_flags = semantic_flags, - format = format, - **kwargs - ) - elif test == "pure_markdown": - pure_markdown_stardoc( - name = "regenerate_%s_golden" % name, - out = actual_generated_doc, - input = input_file, - symbol_names = whitelisted_symbols, - deps = ["%s_lib" % name], - renderer = Label("//src/main/java/com/google/devtools/build/skydoc/renderer:renderer"), - stardoc = Label("//src/main/java/com/google/devtools/build/skydoc:skydoc"), - semantic_flags = semantic_flags, - **kwargs - ) - else: - fail("parameter 'test' must either be 'default' or 'pure_markdown', but was " + test) + stardoc( + name = "regenerate_%s_golden" % name, + out = actual_generated_doc, + input = input_file, + deps = ["%s_lib" % name], + renderer = Label("//src/main/java/com/google/devtools/build/skydoc/renderer:renderer"), + stardoc = Label("//src/main/java/com/google/devtools/build/skydoc:skydoc"), + **kwargs + )
diff --git a/src/test/java/com/google/devtools/build/skydoc/stardoc_for_testing.bzl b/src/test/java/com/google/devtools/build/skydoc/stardoc_for_testing.bzl new file mode 100644 index 0000000..f7d00c9 --- /dev/null +++ b/src/test/java/com/google/devtools/build/skydoc/stardoc_for_testing.bzl
@@ -0,0 +1,44 @@ +# Copyright 2019 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""A wrapper on the stardoc rule for convenience of testing.""" + +load("@io_bazel_skydoc//stardoc:pure_markdown_stardoc.bzl", "pure_markdown_stardoc") +load("@io_bazel_skydoc//stardoc:stardoc.bzl", _stardoc = "stardoc") + +def stardoc(format = "html_tables", **kwargs): + """A wrapper on the stardoc rule for convenience of testing. + + Args: + format: The output format of stardoc. + Valid values: "custom", "html_tables", "markdown_tables", or "proto". + "html_tables" by default. + **kwargs: Attributes to pass through to the stardoc rule.""" + if format == "html_tables" or format == "proto" or format == "custom": + if format == "html_tables" or format == "custom": + # Stardoc's format "markdown" is technically "markdown with html tables", + # and the user can specify custom templates adhoc if the format is "markdown". + format_val = "markdown" + else: + format_val = "proto" + _stardoc( + format = format_val, + **kwargs + ) + elif format == "markdown_tables": + pure_markdown_stardoc(**kwargs) + else: + fail("parameter 'format' must be one of " + + "['custom', 'html_tables', 'markdown_tables', 'proto'], " + + "but was " + format) \ No newline at end of file