Share instances of the std prelude (#5448)
Signed-off-by: Nick Cameron <nrc@ncameron.org>
This commit is contained in:
@ -1,6 +1,5 @@
|
||||
//! Cache testing framework.
|
||||
|
||||
use anyhow::Result;
|
||||
use kcl_lib::{bust_cache, ExecError, ExecOutcome};
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -12,29 +11,33 @@ struct Variation<'a> {
|
||||
async fn cache_test(
|
||||
test_name: &str,
|
||||
variations: Vec<Variation<'_>>,
|
||||
) -> Result<Vec<(String, image::DynamicImage, ExecOutcome)>> {
|
||||
) -> Vec<(String, image::DynamicImage, ExecOutcome)> {
|
||||
let first = variations
|
||||
.first()
|
||||
.ok_or_else(|| anyhow::anyhow!("No variations provided for test '{}'", test_name))?;
|
||||
.ok_or_else(|| anyhow::anyhow!("No variations provided for test '{}'", test_name))
|
||||
.unwrap();
|
||||
|
||||
let mut ctx = kcl_lib::ExecutorContext::new_with_client(first.settings.clone(), None, None).await?;
|
||||
let mut ctx = kcl_lib::ExecutorContext::new_with_client(first.settings.clone(), None, None)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
bust_cache().await;
|
||||
let mut img_results = Vec::new();
|
||||
for (index, variation) in variations.iter().enumerate() {
|
||||
let program = kcl_lib::Program::parse_no_errs(variation.code)?;
|
||||
let program = kcl_lib::Program::parse_no_errs(variation.code).unwrap();
|
||||
|
||||
// set the new settings.
|
||||
ctx.settings = variation.settings.clone();
|
||||
|
||||
let outcome = ctx.run_with_caching(program).await?;
|
||||
let snapshot_png_bytes = ctx.prepare_snapshot().await?.contents.0;
|
||||
let outcome = ctx.run_with_caching(program).await.unwrap();
|
||||
let snapshot_png_bytes = ctx.prepare_snapshot().await.unwrap().contents.0;
|
||||
|
||||
// Decode the snapshot, return it.
|
||||
let img = image::ImageReader::new(std::io::Cursor::new(snapshot_png_bytes))
|
||||
.with_guessed_format()
|
||||
.map_err(|e| ExecError::BadPng(e.to_string()))
|
||||
.and_then(|x| x.decode().map_err(|e| ExecError::BadPng(e.to_string())))?;
|
||||
.and_then(|x| x.decode().map_err(|e| ExecError::BadPng(e.to_string())))
|
||||
.unwrap();
|
||||
// Save the snapshot.
|
||||
let path = crate::assert_out(&format!("cache_{}_{}", test_name, index), &img);
|
||||
|
||||
@ -43,7 +46,7 @@ async fn cache_test(
|
||||
|
||||
ctx.close().await;
|
||||
|
||||
Ok(img_results)
|
||||
img_results
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
@ -77,8 +80,7 @@ async fn kcl_test_cache_change_units_changes_output() {
|
||||
},
|
||||
],
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
.await;
|
||||
|
||||
let first = result.first().unwrap();
|
||||
let second = result.last().unwrap();
|
||||
@ -117,8 +119,7 @@ async fn kcl_test_cache_change_grid_visualizes_grid_off_to_on() {
|
||||
},
|
||||
],
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
.await;
|
||||
|
||||
let first = result.first().unwrap();
|
||||
let second = result.last().unwrap();
|
||||
@ -157,8 +158,7 @@ async fn kcl_test_cache_change_grid_visualizes_grid_on_to_off() {
|
||||
},
|
||||
],
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
.await;
|
||||
|
||||
let first = result.first().unwrap();
|
||||
let second = result.last().unwrap();
|
||||
@ -197,8 +197,7 @@ async fn kcl_test_cache_change_highlight_edges_changes_visual() {
|
||||
},
|
||||
],
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
.await;
|
||||
|
||||
let first = result.first().unwrap();
|
||||
let second = result.last().unwrap();
|
||||
@ -236,8 +235,7 @@ extrude(sketch001, length = 4)
|
||||
},
|
||||
],
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
.await;
|
||||
|
||||
let first = &result.first().unwrap().2;
|
||||
let second = &result.last().unwrap().2;
|
||||
|
||||
Reference in New Issue
Block a user