Skip to content

Commit 75173e7

Browse files
committed
add unit test for rustdoc
1 parent bdc7b47 commit 75173e7

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

test/unit/rustdoc/rustdoc_features.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2022 The Bazel Authors. All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
//!
16+
//! Checkout [inc]
17+
//!
18+
19+
/// Increments the input.
20+
#[cfg(feature = "docs")]
21+
pub fn inc(n: u32) -> u32 {
22+
n + 1
23+
}

test/unit/rustdoc/rustdoc_unit_test.bzl

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,18 @@ def _rustdoc_for_bin_with_transitive_proc_macro_test_impl(ctx):
9797

9898
return analysistest.end(env)
9999

100+
def _rustdoc_for_lib_with_features_test_impl(ctx):
101+
env = analysistest.begin(ctx)
102+
tut = analysistest.target_under_test(env)
103+
104+
_common_rustdoc_checks(env, tut)
105+
106+
action = _get_rustdoc_action(env, tut)
107+
108+
assert_argv_contains(env, action, "--cfg=feature=\"docs\"")
109+
110+
return analysistest.end(env)
111+
100112
def _rustdoc_for_lib_with_cc_lib_test_impl(ctx):
101113
env = analysistest.begin(ctx)
102114
tut = analysistest.target_under_test(env)
@@ -164,6 +176,7 @@ rustdoc_for_lib_with_proc_macro_in_docs_test = analysistest.make(_rustdoc_for_li
164176
rustdoc_for_bin_with_transitive_proc_macro_test = analysistest.make(_rustdoc_for_bin_with_transitive_proc_macro_test_impl)
165177
rustdoc_for_lib_with_cc_lib_test = analysistest.make(_rustdoc_for_lib_with_cc_lib_test_impl)
166178
rustdoc_with_args_test = analysistest.make(_rustdoc_with_args_test_impl)
179+
rustdoc_for_lib_with_features_test = analysistest.make(_rustdoc_for_lib_with_features_test_impl)
167180
rustdoc_zip_output_test = analysistest.make(_rustdoc_zip_output_test_impl)
168181
rustdoc_with_json_error_format_test = analysistest.make(_rustdoc_with_json_error_format_test_impl, config_settings = {
169182
str(Label("//rust/settings:error_format")): "json",
@@ -283,6 +296,18 @@ def _define_targets():
283296
crate_features = ["with_proc_macro"],
284297
)
285298

299+
_target_maker(
300+
rust_library,
301+
name = "lib_with_features",
302+
srcs = ["rustdoc_features.rs"],
303+
crate_features = ["docs"],
304+
)
305+
306+
rust_doc(
307+
name = "rustdoc_lib_with_features",
308+
crate = ":lib_with_features",
309+
)
310+
286311
cc_library(
287312
name = "cc_lib",
288313
hdrs = ["rustdoc.h"],
@@ -424,6 +449,11 @@ def rustdoc_test_suite(name):
424449
target_under_test = ":lib_with_cc_doc",
425450
)
426451

452+
rustdoc_for_lib_with_features_test(
453+
name = "rustdoc_for_lib_with_features_test",
454+
target_under_test = ":rustdoc_lib_with_features",
455+
)
456+
427457
rustdoc_with_args_test(
428458
name = "rustdoc_with_args_test",
429459
target_under_test = ":rustdoc_with_args",
@@ -455,6 +485,7 @@ def rustdoc_test_suite(name):
455485
":rustdoc_for_lib_with_proc_macro_in_docs_test",
456486
":rustdoc_for_lib_with_proc_macro_test",
457487
":rustdoc_for_lib_with_cc_lib_test",
488+
":rustdoc_for_lib_with_features_test",
458489
":rustdoc_with_args_test",
459490
":rustdoc_with_json_error_format_test",
460491
":rustdoc_zip_output_test",

0 commit comments

Comments
 (0)