Skip to content

Commit

Permalink
Ensure all tests use loadable .bzl modules (#155)
Browse files Browse the repository at this point in the history
In preparation for switching to starlark_doc_extract, we need to fix Stardoc tests to use .bzl files that can really be loaded by Bazel. This means:
* getting rid of misuses of aspect api
* getting rid of old Android and Java symbols
* getting rid of generated_bzl_test entirely, since Bazel cannot load dynamically generated .bzl modules.

Also fix update-stardoc-tests.sh script - we need to ignore the _stardoc java_binary outputs introduced by #141.
  • Loading branch information
tetromino authored May 19, 2023
1 parent 8cd9ecf commit b4b7905
Show file tree
Hide file tree
Showing 16 changed files with 13 additions and 81 deletions.
16 changes: 0 additions & 16 deletions test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -247,22 +247,6 @@ stardoc_test(
input_file = "testdata/config_apis_test/input.bzl",
)

genrule(
name = "generate_bzl_test_dep",
srcs = ["testdata/generated_bzl_test/dep.bzl.tpl"],
outs = ["testdata/generated_bzl_test/dep.bzl"],
cmd = "cp $< $@",
)

stardoc_test(
name = "generated_bzl_test",
golden_file = "testdata/generated_bzl_test/golden.md",
input_file = "testdata/generated_bzl_test/input.bzl",
deps = [
"testdata/generated_bzl_test/dep.bzl",
],
)

sh_test(
name = "local_repository_test_e2e_test",
srcs = ["diff_test_runner.sh"],
Expand Down
9 changes: 1 addition & 8 deletions test/testdata/android_basic_test/input.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,7 @@
# buildifier: disable=function-docstring
# buildifier: disable=unused-variable
def exercise_the_api():
_var1 = android_common.create_device_broker_info("")
_var2 = ApkInfo
_var3 = AndroidInstrumentationInfo
_var4 = AndroidDeviceBrokerInfo
_var5 = AndroidResourcesInfo
_var6 = AndroidNativeLibsInfo
_var7 = AndroidSdkInfo
_var8 = android_data
_ignore = android_common.create_device_broker_info("")

exercise_the_api()

Expand Down
4 changes: 2 additions & 2 deletions test/testdata/aspect_test/golden.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ This is my aspect. It does stuff.
| Name | Description | Type | Mandatory | Default |
| :------------- | :------------- | :------------- | :------------- | :------------- |
| <a id="my_aspect-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | |
| <a id="my_aspect-first"></a>first | - | <a href="https://bazel.build/concepts/labels">Label</a> | required | |
| <a id="my_aspect-second"></a>second | - | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | required | |
| <a id="my_aspect-first"></a>first | - | Boolean | required | |
| <a id="my_aspect-second"></a>second | - | String | required | |


<a id="other_aspect"></a>
Expand Down
4 changes: 2 additions & 2 deletions test/testdata/aspect_test/input.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ my_aspect = aspect(
doc = "This is my aspect. It does stuff.",
attr_aspects = ["deps", "attr_aspect"],
attrs = {
"first": attr.label(mandatory = True, allow_single_file = True),
"second": attr.string_dict(mandatory = True),
"first": attr.bool(mandatory = True),
"second": attr.string(mandatory = True),
},
)

Expand Down
2 changes: 1 addition & 1 deletion test/testdata/attribute_defaults_test/input.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ my_aspect = aspect(
doc = "This is my aspect. It does stuff.",
attr_aspects = ["deps", "attr_aspect"],
attrs = {
"_x": attr.label(mandatory = True),
"_x": attr.label(mandatory = True, default = "//foo:bar"),
"y": attr.string(default = "why", doc = "some string"),
"z": attr.string(mandatory = True),
},
Expand Down
2 changes: 1 addition & 1 deletion test/testdata/config_apis_test/input.bzl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# buildifier: disable=module-docstring
# buildifier: disable=function-docstring
def exercise_the_api():
_var6 = configuration_field("foo", "bar") # @unused
_unused = configuration_field(fragment = "cpp", name = "custom_malloc") # @unused

exercise_the_api()

Expand Down
4 changes: 0 additions & 4 deletions test/testdata/generated_bzl_test/dep.bzl.tpl

This file was deleted.

24 changes: 0 additions & 24 deletions test/testdata/generated_bzl_test/golden.md

This file was deleted.

16 changes: 0 additions & 16 deletions test/testdata/generated_bzl_test/input.bzl

This file was deleted.

2 changes: 1 addition & 1 deletion test/testdata/html_tables_template_test/golden.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ A unique name for this target.
<td><code>first</code></td>
<td>

<a href="https://bazel.build/concepts/labels">Label</a>; required
Integer; required

</td>
</tr>
Expand Down
2 changes: 1 addition & 1 deletion test/testdata/html_tables_template_test/input.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ example_aspect = aspect(
doc = "Small example of aspect using a markdown template.",
attr_aspects = ["deps", "attr_aspect"],
attrs = {
"first": attr.label(mandatory = True, allow_single_file = True),
"first": attr.int(mandatory = True),
"second": attr.string(doc = "This is the second attribute."),
},
)
2 changes: 1 addition & 1 deletion test/testdata/input_template_test/golden.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ This is my aspect. It does stuff.
</p>
<b>
<code>first</code>
<a href="https://bazel.build/concepts/labels">Label</a>; required
String; required
</b>


2 changes: 1 addition & 1 deletion test/testdata/input_template_test/input.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ my_aspect = aspect(
doc = "This is my aspect. It does stuff.",
attr_aspects = ["deps", "attr_aspect"],
attrs = {
"first": attr.label(mandatory = True, allow_single_file = True),
"first": attr.string(mandatory = True),
},
)
1 change: 0 additions & 1 deletion test/testdata/java_basic_test/input.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
def exercise_the_api():
var1 = java_common.JavaRuntimeInfo # @unused
var2 = JavaInfo # @unused
var3 = java_proto_common # @unused

exercise_the_api()

Expand Down
2 changes: 1 addition & 1 deletion test/testdata/local_repository_test/input.bzl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""A test that verifies documenting functions in an input file under a local_repository."""

load("@io_bazel_stardoc//test/testdata/fakedeps:dep.bzl", "give_me_five")
load("@io_bazel_stardoc//test:testdata/fakedeps/dep.bzl", "give_me_five")

def min(integers):
"""Returns the minimum of given elements.
Expand Down
2 changes: 1 addition & 1 deletion update-stardoc-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ set -eu
# golden test pattern
EXCLUDED_TESTS="namespace_test_with_whitelist|proto_format_test|multi_level_namespace_test_with_whitelist|local_repository_test"
echo "** Querying for tests..."
regen_targets=$(bazel query //test:all | grep regenerate_with_jar | grep -vE "$EXCLUDED_TESTS")
regen_targets=$(bazel query //test:all | grep regenerate_with_jar | grep -vE "_golden_stardoc\$|$EXCLUDED_TESTS")

echo "** Building goldens..."
bazel build $regen_targets
Expand Down

0 comments on commit b4b7905

Please sign in to comment.