Run std lib example tests one at a time (#7127)
Signed-off-by: Nick Cameron <nrc@ncameron.org>
This commit is contained in:
@ -293,17 +293,6 @@ impl DocData {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
fn examples(&self) -> impl Iterator<Item = &String> {
|
||||
match self {
|
||||
DocData::Fn(f) => f.examples.iter(),
|
||||
DocData::Const(c) => c.examples.iter(),
|
||||
DocData::Ty(t) => t.examples.iter(),
|
||||
DocData::Mod(_) => unimplemented!(),
|
||||
}
|
||||
.filter_map(|(s, p)| (!p.norun).then_some(s))
|
||||
}
|
||||
|
||||
fn expect_mod(&self) -> &ModData {
|
||||
match self {
|
||||
DocData::Mod(m) => m,
|
||||
@ -1187,7 +1176,7 @@ impl ApplyMeta for ArgData {
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use kcl_derive_docs::for_each_std_mod;
|
||||
use kcl_derive_docs::{for_all_example_test, for_each_example_test};
|
||||
|
||||
use super::*;
|
||||
|
||||
@ -1225,51 +1214,81 @@ mod test {
|
||||
);
|
||||
}
|
||||
|
||||
#[for_each_std_mod]
|
||||
#[for_all_example_test]
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn missing_test_examples() {
|
||||
fn check_mod(m: &ModData) {
|
||||
for d in m.children.values() {
|
||||
let DocData::Fn(f) = d else {
|
||||
continue;
|
||||
};
|
||||
|
||||
for i in 0..f.examples.len() {
|
||||
let name = format!("{}-{i}", f.qual_name.replace("::", "-"));
|
||||
assert!(TEST_NAMES.contains(&&*name), "Missing test for example \"{name}\", maybe need to update kcl-derive-docs/src/example_tests.rs?")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let data = walk_prelude();
|
||||
|
||||
check_mod(&data);
|
||||
for m in data.children.values() {
|
||||
if let DocData::Mod(m) = m {
|
||||
check_mod(m);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[for_each_example_test]
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn kcl_test_examples() {
|
||||
let std = walk_prelude();
|
||||
let mut errs = Vec::new();
|
||||
|
||||
let data = if STD_MOD_NAME == "prelude" {
|
||||
let names = NAME.split('-');
|
||||
let mut mods: Vec<_> = names.collect();
|
||||
let number = mods.pop().unwrap();
|
||||
let number: usize = number.parse().unwrap();
|
||||
let name = mods.pop().unwrap();
|
||||
let mut qualname = mods.join("::");
|
||||
qualname.push_str("::");
|
||||
qualname.push_str(name);
|
||||
|
||||
let data = if mods.len() == 1 {
|
||||
&std
|
||||
} else {
|
||||
std.children
|
||||
.get(&format!("M:std::{STD_MOD_NAME}"))
|
||||
.unwrap()
|
||||
.expect_mod()
|
||||
std.children.get(&format!("M:std::{}", mods[1])).unwrap().expect_mod()
|
||||
};
|
||||
|
||||
let mut count = 0;
|
||||
for d in data.children.values() {
|
||||
if let DocData::Mod(_) = d {
|
||||
let Some(DocData::Fn(d)) = data.children.get(&format!("I:{qualname}")) else {
|
||||
panic!("Could not find data for {NAME} (missing a child entry for {qualname}), maybe need to update kcl-derive-docs/src/example_tests.rs?");
|
||||
};
|
||||
|
||||
for (i, eg) in d.examples.iter().enumerate() {
|
||||
if i != number {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (i, eg) in d.examples().enumerate() {
|
||||
count += 1;
|
||||
if count % SHARD_COUNT != SHARD {
|
||||
continue;
|
||||
let result = match crate::test_server::execute_and_snapshot(&eg.0, None).await {
|
||||
Err(crate::errors::ExecError::Kcl(e)) => {
|
||||
panic!("Error testing example {}{i}: {}", d.name, e.error.message());
|
||||
}
|
||||
|
||||
let result = match crate::test_server::execute_and_snapshot(eg, None).await {
|
||||
Err(crate::errors::ExecError::Kcl(e)) => {
|
||||
errs.push(format!("Error testing example {}{i}: {}", d.name(), e.error.message()));
|
||||
continue;
|
||||
}
|
||||
Err(other_err) => panic!("{}", other_err),
|
||||
Ok(img) => img,
|
||||
};
|
||||
twenty_twenty::assert_image(
|
||||
format!("tests/outputs/serial_test_example_{}{i}.png", d.example_name()),
|
||||
&result,
|
||||
0.99,
|
||||
);
|
||||
Err(other_err) => panic!("{}", other_err),
|
||||
Ok(img) => img,
|
||||
};
|
||||
if eg.1.norun {
|
||||
return;
|
||||
}
|
||||
twenty_twenty::assert_image(
|
||||
format!(
|
||||
"tests/outputs/serial_test_example_fn_{}{i}.png",
|
||||
qualname.replace("::", "-")
|
||||
),
|
||||
&result,
|
||||
0.99,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if !errs.is_empty() {
|
||||
panic!("{}", errs.join("\n\n"));
|
||||
}
|
||||
panic!("Could not find data for {NAME} (no example {number}), maybe need to update kcl-derive-docs/src/example_tests.rs?");
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user