Skip to content

Commit e3165a3

Browse files
authored
Rollup merge of #104944 - aDotInTheVoid:jsondoclint-unit-tests, r=jyn514
Support unit tests for jsondoclint r? ````@ghost````
2 parents 8d90647 + 09818a8 commit e3165a3

File tree

5 files changed

+70
-3
lines changed

5 files changed

+70
-3
lines changed

src/bootstrap/builder.rs

+1
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,7 @@ impl<'a> Builder<'a> {
644644
test::CrateLibrustc,
645645
test::CrateRustdoc,
646646
test::CrateRustdocJsonTypes,
647+
test::CrateJsonDocLint,
647648
test::Linkcheck,
648649
test::TierCheck,
649650
test::ReplacePlaceholderTest,

src/bootstrap/test.rs

+36
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,42 @@ fn try_run_quiet(builder: &Builder<'_>, cmd: &mut Command) -> bool {
9090
true
9191
}
9292

93+
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
94+
pub struct CrateJsonDocLint {
95+
host: TargetSelection,
96+
}
97+
98+
impl Step for CrateJsonDocLint {
99+
type Output = ();
100+
const ONLY_HOSTS: bool = true;
101+
const DEFAULT: bool = true;
102+
103+
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
104+
run.path("src/tools/jsondoclint")
105+
}
106+
107+
fn make_run(run: RunConfig<'_>) {
108+
run.builder.ensure(CrateJsonDocLint { host: run.target });
109+
}
110+
111+
fn run(self, builder: &Builder<'_>) {
112+
let bootstrap_host = builder.config.build;
113+
let compiler = builder.compiler(0, bootstrap_host);
114+
115+
let cargo = tool::prepare_tool_cargo(
116+
builder,
117+
compiler,
118+
Mode::ToolBootstrap,
119+
bootstrap_host,
120+
"test",
121+
"src/tools/jsondoclint",
122+
SourceType::InTree,
123+
&[],
124+
);
125+
try_run(builder, &mut cargo.into());
126+
}
127+
}
128+
93129
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
94130
pub struct Linkcheck {
95131
host: TargetSelection,

src/tools/jsondoclint/src/json_find.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::fmt::Write;
22

33
use serde_json::Value;
44

5-
#[derive(Debug, Clone)]
5+
#[derive(Debug, Clone, PartialEq, Eq)]
66
pub enum SelectorPart {
77
Field(String),
88
Index(usize),
@@ -72,3 +72,6 @@ fn find_selector_recursive(
7272
}
7373
}
7474
}
75+
76+
#[cfg(test)]
77+
mod tests;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
use super::*;
2+
3+
#[test]
4+
fn basic_find() {
5+
use SelectorPart::*;
6+
7+
let j = serde_json::json!({
8+
"index": {
9+
"4": {
10+
"inner": {
11+
"items": ["1", "2", "3"]
12+
}
13+
}
14+
}
15+
});
16+
17+
let sel = find_selector(&j, &serde_json::json!("1"));
18+
let exp: Vec<Vec<SelectorPart>> = vec![vec![
19+
Field("index".to_owned()),
20+
Field("4".to_owned()),
21+
Field("inner".to_owned()),
22+
Field("items".to_owned()),
23+
Index(0),
24+
]];
25+
26+
assert_eq!(exp, sel);
27+
}

src/tools/jsondoclint/src/main.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ pub(crate) mod item_kind;
99
mod json_find;
1010
mod validator;
1111

12-
#[derive(Debug)]
12+
#[derive(Debug, PartialEq, Eq)]
1313
struct Error {
1414
kind: ErrorKind,
1515
id: Id,
1616
}
1717

18-
#[derive(Debug)]
18+
#[derive(Debug, PartialEq, Eq)]
1919
enum ErrorKind {
2020
NotFound,
2121
Custom(String),

0 commit comments

Comments
 (0)