Skip to content

Commit 42fc2c4

Browse files
committed
Update verify to check for model vs no model
The current verify does not check that the RPCs are marked as modelled or not consistently between the verify and the types table. Change it so that it does.
1 parent 7faee78 commit 42fc2c4

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed

verify/src/main.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ fn verify_version(version: Version, test_output: Option<&String>, quiet: bool) -
9292
Err(e) => { if !quiet { eprintln!("{}", e); } close(false, quiet); failures += 1; }
9393
}
9494

95+
let msg = "Checking that 'Returns' column matches model requirements";
96+
check(msg, quiet);
97+
match verify_returns_method(version) {
98+
Ok(()) => close(true, quiet),
99+
Err(e) => { if !quiet { eprintln!("{}", e); } close(false, quiet); failures += 1; }
100+
}
101+
95102
if failures > 0 {
96103
return Err(anyhow::anyhow!("verification failed ({} check(s) failed)", failures));
97104
}
@@ -204,6 +211,45 @@ fn output_method(method: &Method) -> String {
204211
}
205212
}
206213

214+
/// Verifies that the 'Returns' table entry ("version" vs "version + model") matches the
215+
/// method definition in verfiy.
216+
fn verify_returns_method(version: Version) -> Result<()> {
217+
use verify::versioned::{returns_map, ReturnsDoc};
218+
219+
let map = returns_map(version)?;
220+
let mut failures = 0;
221+
222+
for (name, entry) in map.into_iter() {
223+
let Some(method) = Method::from_name(version, &name) else { continue };
224+
225+
match entry {
226+
ReturnsDoc::Version => {
227+
if method.requires_model {
228+
eprintln!(
229+
"'Returns' says 'version' but method is marked as requiring a model: {}",
230+
output_method(method)
231+
);
232+
failures += 1;
233+
}
234+
}
235+
ReturnsDoc::VersionPlusModel => {
236+
if !method.requires_model {
237+
eprintln!(
238+
"'Returns' says 'version + model' but method is marked as not requiring a model: {}",
239+
output_method(method)
240+
);
241+
failures += 1;
242+
}
243+
}
244+
ReturnsDoc::Other(_) => {}
245+
}
246+
}
247+
248+
if failures > 0 { return Err(anyhow::anyhow!("returns/model verification failed ({} issue(s))", failures)); }
249+
250+
Ok(())
251+
}
252+
207253
// Use a module because a file with this name is confusing.
208254
mod check_integration_test_crate {
209255
//! Things related to parsing the `integration_test` crate.

verify/src/versioned.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,47 @@ pub fn type_exists(version: Version, method_name: &str) -> Result<bool> {
9696
Ok(false)
9797
}
9898

99+
/// The value from the `Returns` column in the versioned rustdoc table.
100+
#[derive(Debug, Clone, PartialEq, Eq)]
101+
pub enum ReturnsDoc {
102+
/// The table says the method is implemented for this version and no model is required.
103+
Version,
104+
/// The table says the method is implemented for this version and a model is required.
105+
VersionPlusModel,
106+
/// Any other entry (omitted, TODO, returns nothing/numeric/bool/string, etc.).
107+
Other(String),
108+
}
109+
110+
/// Parses the version-specific module rustdocs and returns a mapping to `ReturnsDoc`.
111+
pub fn returns_map(version: Version) -> Result<std::collections::BTreeMap<String, ReturnsDoc>> {
112+
use std::collections::BTreeMap;
113+
114+
let path = path(version);
115+
let file = File::open(&path)
116+
.with_context(|| format!("Failed to grep rustdocs in {}", path.display()))?;
117+
let reader = io::BufReader::new(file);
118+
119+
let re = Regex::new(r"//! \| ([a-z]+) .* \| ([a-z +]+?) \|.*\|").unwrap();
120+
121+
let mut map: BTreeMap<String, ReturnsDoc> = BTreeMap::new();
122+
for line in reader.lines() {
123+
let line = line?;
124+
if let Some(caps) = re.captures(&line) {
125+
let method_name = caps.get(1).unwrap().as_str();
126+
let returns_column = caps.get(2).unwrap().as_str().trim();
127+
128+
let entry = match returns_column {
129+
"version" => ReturnsDoc::Version,
130+
"version + model" => ReturnsDoc::VersionPlusModel,
131+
other => ReturnsDoc::Other(other.to_string()),
132+
};
133+
map.insert(method_name.to_string(), entry);
134+
}
135+
}
136+
137+
Ok(map)
138+
}
139+
99140
/// A list item from rustdocs (e.g. in in `types/src/v17/mod.rs`).
100141
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
101142
// TODO: This name is overloaded (`method::Method`).

0 commit comments

Comments
 (0)