Skip to content

Commit 56fee40

Browse files
authored
Rollup merge of rust-lang#82571 - aDotInTheVoid:reexport-tests, r=CraftSpider
Rustdoc Json: Add tests for Reexports, and improve jsondocck The two changes are orthognal, so you can land just one if you want, but the improved errors realy helped write the tests. Notably does not have the case from rust-lang#80664, but I want to have all the ajacent cases tested before starting work on that to ensure I dont break anything. Improves rust-lang#81359 cc `@CraftSpider` r? `@jyn514` `@rustbot` modify labels: +A-testsuite +T-rustdoc +A-rustdoc-json
2 parents eb714da + 5f24798 commit 56fee40

File tree

6 files changed

+114
-2
lines changed

6 files changed

+114
-2
lines changed

Diff for: src/test/rustdoc-json/reexport/glob_extern.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// edition:2018
2+
3+
#![no_core]
4+
#![feature(no_core)]
5+
6+
// @!has glob_extern.json "$.index[*][?(@.name=='mod1')]"
7+
mod mod1 {
8+
extern "C" {
9+
// @set public_fn_id = - "$.index[*][?(@.name=='public_fn')].id"
10+
pub fn public_fn();
11+
// @!has - "$.index[*][?(@.name=='private_fn')]"
12+
fn private_fn();
13+
}
14+
}
15+
16+
// @has - "$.index[*][?(@.name=='glob_extern')].inner.items[*]" $public_fn_id
17+
pub use mod1::*;

Diff for: src/test/rustdoc-json/reexport/glob_private.rs

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// edition:2018
2+
3+
#![no_core]
4+
#![feature(no_core)]
5+
6+
// @!has glob_private.json "$.index[*][?(@.name=='mod1')]"
7+
mod mod1 {
8+
// @!has - "$.index[*][?(@.name=='mod2')]"
9+
mod mod2 {
10+
// @set m2pub_id = - "$.index[*][?(@.name=='Mod2Public')].id"
11+
pub struct Mod2Public;
12+
13+
// @!has - "$.index[*][?(@.name=='Mod2Private')]"
14+
struct Mod2Private;
15+
}
16+
pub use self::mod2::*;
17+
18+
// @set m1pub_id = - "$.index[*][?(@.name=='Mod1Public')].id"
19+
pub struct Mod1Public;
20+
21+
// @!has - "$.index[*][?(@.name=='Mod1Private')]"
22+
struct Mod1Private;
23+
}
24+
pub use mod1::*;
25+
26+
// @has - "$.index[*][?(@.name=='glob_private')].inner.items[*]" $m2pub_id
27+
// @has - "$.index[*][?(@.name=='glob_private')].inner.items[*]" $m1pub_id

Diff for: src/test/rustdoc-json/reexport/rename_public.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// edition:2018
2+
3+
#![no_core]
4+
#![feature(no_core)]
5+
6+
// @set inner_id = rename_public.json "$.index[*][?(@.name=='inner')].id"
7+
// @has - "$.index[*][?(@.name=='rename_public')].inner.items[*]" $inner_id
8+
pub mod inner {
9+
// @set public_id = - "$.index[*][?(@.name=='Public')].id"
10+
// @has - "$.index[*][?(@.name=='inner')].inner.items[*]" $public_id
11+
pub struct Public;
12+
}
13+
// @set import_id = - "$.index[*][?(@.inner.name=='NewName')].id"
14+
// @!has - "$.index[*][?(@.inner.name=='Public')]"
15+
// @has - "$.index[*][?(@.name=='rename_public')].inner.items[*]" $import_id
16+
// @is - "$.index[*][?(@.inner.name=='NewName')].inner.span" \"inner::Public\"
17+
pub use inner::Public as NewName;

Diff for: src/test/rustdoc-json/reexport/simple_private.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// edition:2018
2+
3+
#![no_core]
4+
#![feature(no_core)]
5+
6+
// @!has simple_private.json "$.index[*][?(@.name=='inner')]"
7+
mod inner {
8+
// @set pub_id = - "$.index[*][?(@.name=='Public')].id"
9+
pub struct Public;
10+
}
11+
12+
// @has - "$.index[*][?(@.name=='simple_private')].inner.items[*]" $pub_id
13+
pub use inner::Public;

Diff for: src/test/rustdoc-json/reexport/simple_public.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// edition:2018
2+
3+
#![no_core]
4+
#![feature(no_core)]
5+
6+
// @set inner_id = simple_public.json "$.index[*][?(@.name=='inner')].id"
7+
// @has - "$.index[*][?(@.name=='simple_public')].inner.items[*]" $inner_id
8+
pub mod inner {
9+
10+
// @set public_id = - "$.index[*][?(@.name=='Public')].id"
11+
// @has - "$.index[*][?(@.name=='inner')].inner.items[*]" $public_id
12+
pub struct Public;
13+
}
14+
15+
// @set import_id = - "$.index[*][?(@.inner.name=='Public')].id"
16+
// @has - "$.index[*][?(@.name=='simple_public')].inner.items[*]" $import_id
17+
// @is - "$.index[*][?(@.inner.name=='Public')].inner.span" \"inner::Public\"
18+
pub use inner::Public;

Diff for: src/tools/jsondocck/src/main.rs

+22-2
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,21 @@ fn check_command(command: Command, cache: &mut Cache) -> Result<(), CkError> {
205205
let val = cache.get_value(&command.args[0])?;
206206
let results = select(&val, &command.args[1]).unwrap();
207207
let pat = string_to_value(&command.args[2], cache);
208-
results.contains(&pat.as_ref())
208+
let has = results.contains(&pat.as_ref());
209+
// Give better error for when @has check fails
210+
if !command.negated && !has {
211+
return Err(CkError::FailedCheck(
212+
format!(
213+
"{} matched to {:?} but didn't have {:?}",
214+
&command.args[1],
215+
results,
216+
pat.as_ref()
217+
),
218+
command,
219+
));
220+
} else {
221+
has
222+
}
209223
}
210224
_ => unreachable!(),
211225
}
@@ -233,7 +247,13 @@ fn check_command(command: Command, cache: &mut Cache) -> Result<(), CkError> {
233247
assert_eq!(command.args[1], "=", "Expected an `=`");
234248
let val = cache.get_value(&command.args[2])?;
235249
let results = select(&val, &command.args[3]).unwrap();
236-
assert_eq!(results.len(), 1);
250+
assert_eq!(
251+
results.len(),
252+
1,
253+
"Didn't get 1 result for `{}`: got {:?}",
254+
command.args[3],
255+
results
256+
);
237257
match results.len() {
238258
0 => false,
239259
1 => {

0 commit comments

Comments
 (0)