|
1 | 1 | use rustc_hash::FxHashMap;
|
2 |
| -use rustdoc_json_types::{FORMAT_VERSION, Item, ItemKind, Visibility}; |
| 2 | +use rustdoc_json_types::{Abi, FORMAT_VERSION, FunctionHeader, Item, ItemKind, Visibility}; |
3 | 3 |
|
4 | 4 | use super::*;
|
5 | 5 | use crate::json_find::SelectorPart;
|
@@ -102,6 +102,101 @@ fn errors_on_local_in_paths_and_not_index() {
|
102 | 102 | }]);
|
103 | 103 | }
|
104 | 104 |
|
| 105 | +#[test] |
| 106 | +fn errors_on_missing_path() { |
| 107 | + // crate-name=foo |
| 108 | + // ``` |
| 109 | + // pub struct Bar; |
| 110 | + // pub fn mk_bar() -> Bar { ... } |
| 111 | + // ``` |
| 112 | + |
| 113 | + let generics = Generics { params: vec![], where_predicates: vec![] }; |
| 114 | + |
| 115 | + let krate = Crate { |
| 116 | + root: Id(0), |
| 117 | + crate_version: None, |
| 118 | + includes_private: false, |
| 119 | + index: FxHashMap::from_iter([ |
| 120 | + (Id(0), Item { |
| 121 | + id: Id(0), |
| 122 | + crate_id: 0, |
| 123 | + name: Some("foo".to_owned()), |
| 124 | + span: None, |
| 125 | + visibility: Visibility::Public, |
| 126 | + docs: None, |
| 127 | + links: FxHashMap::default(), |
| 128 | + attrs: Vec::new(), |
| 129 | + deprecation: None, |
| 130 | + inner: ItemEnum::Module(Module { |
| 131 | + is_crate: true, |
| 132 | + items: vec![Id(1), Id(2)], |
| 133 | + is_stripped: false, |
| 134 | + }), |
| 135 | + }), |
| 136 | + (Id(1), Item { |
| 137 | + id: Id(0), |
| 138 | + crate_id: 0, |
| 139 | + name: Some("Bar".to_owned()), |
| 140 | + span: None, |
| 141 | + visibility: Visibility::Public, |
| 142 | + docs: None, |
| 143 | + links: FxHashMap::default(), |
| 144 | + attrs: Vec::new(), |
| 145 | + deprecation: None, |
| 146 | + inner: ItemEnum::Struct(Struct { |
| 147 | + kind: StructKind::Unit, |
| 148 | + generics: generics.clone(), |
| 149 | + impls: vec![], |
| 150 | + }), |
| 151 | + }), |
| 152 | + (Id(2), Item { |
| 153 | + id: Id(0), |
| 154 | + crate_id: 0, |
| 155 | + name: Some("mk_bar".to_owned()), |
| 156 | + span: None, |
| 157 | + visibility: Visibility::Public, |
| 158 | + docs: None, |
| 159 | + links: FxHashMap::default(), |
| 160 | + attrs: Vec::new(), |
| 161 | + deprecation: None, |
| 162 | + inner: ItemEnum::Function(Function { |
| 163 | + sig: FunctionSignature { |
| 164 | + inputs: vec![], |
| 165 | + output: Some(Type::ResolvedPath(Path { |
| 166 | + name: "Bar".to_owned(), |
| 167 | + id: Id(1), |
| 168 | + args: None, |
| 169 | + })), |
| 170 | + is_c_variadic: false, |
| 171 | + }, |
| 172 | + generics, |
| 173 | + header: FunctionHeader { |
| 174 | + is_const: false, |
| 175 | + is_unsafe: false, |
| 176 | + is_async: false, |
| 177 | + abi: Abi::Rust, |
| 178 | + }, |
| 179 | + has_body: true, |
| 180 | + }), |
| 181 | + }), |
| 182 | + ]), |
| 183 | + paths: FxHashMap::from_iter([(Id(0), ItemSummary { |
| 184 | + crate_id: 0, |
| 185 | + path: vec!["foo".to_owned()], |
| 186 | + kind: ItemKind::Module, |
| 187 | + })]), |
| 188 | + external_crates: FxHashMap::default(), |
| 189 | + format_version: rustdoc_json_types::FORMAT_VERSION, |
| 190 | + }; |
| 191 | + |
| 192 | + check(&krate, &[Error { |
| 193 | + kind: ErrorKind::Custom( |
| 194 | + r#"No entry in '$.paths' for Path { name: "Bar", id: Id(1), args: None }"#.to_owned(), |
| 195 | + ), |
| 196 | + id: Id(1), |
| 197 | + }]); |
| 198 | +} |
| 199 | + |
105 | 200 | #[test]
|
106 | 201 | #[should_panic = "LOCAL_CRATE_ID is wrong"]
|
107 | 202 | fn checks_local_crate_id_is_correct() {
|
|
0 commit comments