Rollup merge of #104944 - aDotInTheVoid:jsondoclint-unit-tests, r=jyn514
Support unit tests for jsondoclint r? ````@ghost````
This commit is contained in:
commit
e3165a3808
@ -644,6 +644,7 @@ impl<'a> Builder<'a> {
|
|||||||
test::CrateLibrustc,
|
test::CrateLibrustc,
|
||||||
test::CrateRustdoc,
|
test::CrateRustdoc,
|
||||||
test::CrateRustdocJsonTypes,
|
test::CrateRustdocJsonTypes,
|
||||||
|
test::CrateJsonDocLint,
|
||||||
test::Linkcheck,
|
test::Linkcheck,
|
||||||
test::TierCheck,
|
test::TierCheck,
|
||||||
test::ReplacePlaceholderTest,
|
test::ReplacePlaceholderTest,
|
||||||
|
@ -90,6 +90,42 @@ fn try_run_quiet(builder: &Builder<'_>, cmd: &mut Command) -> bool {
|
|||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
||||||
|
pub struct CrateJsonDocLint {
|
||||||
|
host: TargetSelection,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Step for CrateJsonDocLint {
|
||||||
|
type Output = ();
|
||||||
|
const ONLY_HOSTS: bool = true;
|
||||||
|
const DEFAULT: bool = true;
|
||||||
|
|
||||||
|
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
|
||||||
|
run.path("src/tools/jsondoclint")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn make_run(run: RunConfig<'_>) {
|
||||||
|
run.builder.ensure(CrateJsonDocLint { host: run.target });
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run(self, builder: &Builder<'_>) {
|
||||||
|
let bootstrap_host = builder.config.build;
|
||||||
|
let compiler = builder.compiler(0, bootstrap_host);
|
||||||
|
|
||||||
|
let cargo = tool::prepare_tool_cargo(
|
||||||
|
builder,
|
||||||
|
compiler,
|
||||||
|
Mode::ToolBootstrap,
|
||||||
|
bootstrap_host,
|
||||||
|
"test",
|
||||||
|
"src/tools/jsondoclint",
|
||||||
|
SourceType::InTree,
|
||||||
|
&[],
|
||||||
|
);
|
||||||
|
try_run(builder, &mut cargo.into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
||||||
pub struct Linkcheck {
|
pub struct Linkcheck {
|
||||||
host: TargetSelection,
|
host: TargetSelection,
|
||||||
|
@ -2,7 +2,7 @@ use std::fmt::Write;
|
|||||||
|
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub enum SelectorPart {
|
pub enum SelectorPart {
|
||||||
Field(String),
|
Field(String),
|
||||||
Index(usize),
|
Index(usize),
|
||||||
@ -72,3 +72,6 @@ fn find_selector_recursive(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests;
|
||||||
|
27
src/tools/jsondoclint/src/json_find/tests.rs
Normal file
27
src/tools/jsondoclint/src/json_find/tests.rs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn basic_find() {
|
||||||
|
use SelectorPart::*;
|
||||||
|
|
||||||
|
let j = serde_json::json!({
|
||||||
|
"index": {
|
||||||
|
"4": {
|
||||||
|
"inner": {
|
||||||
|
"items": ["1", "2", "3"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
let sel = find_selector(&j, &serde_json::json!("1"));
|
||||||
|
let exp: Vec<Vec<SelectorPart>> = vec![vec![
|
||||||
|
Field("index".to_owned()),
|
||||||
|
Field("4".to_owned()),
|
||||||
|
Field("inner".to_owned()),
|
||||||
|
Field("items".to_owned()),
|
||||||
|
Index(0),
|
||||||
|
]];
|
||||||
|
|
||||||
|
assert_eq!(exp, sel);
|
||||||
|
}
|
@ -9,13 +9,13 @@ pub(crate) mod item_kind;
|
|||||||
mod json_find;
|
mod json_find;
|
||||||
mod validator;
|
mod validator;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
struct Error {
|
struct Error {
|
||||||
kind: ErrorKind,
|
kind: ErrorKind,
|
||||||
id: Id,
|
id: Id,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
enum ErrorKind {
|
enum ErrorKind {
|
||||||
NotFound,
|
NotFound,
|
||||||
Custom(String),
|
Custom(String),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user