better testing for making sure we update the cache state on just settings changes (#5445)
This commit is contained in:
@ -533,6 +533,42 @@ shell(firstSketch, faces = ['end'], thickness = 0.25)"#;
|
||||
.await;
|
||||
|
||||
assert_eq!(result, CacheResult::NoAction(true));
|
||||
|
||||
// Change the settings back.
|
||||
let old_settings = ctx.settings.clone();
|
||||
ctx.settings.highlight_edges = !ctx.settings.highlight_edges;
|
||||
|
||||
let result = get_changed_program(
|
||||
CacheInformation {
|
||||
ast: &program.ast,
|
||||
settings: &old_settings,
|
||||
},
|
||||
CacheInformation {
|
||||
ast: &program.ast,
|
||||
settings: &ctx.settings,
|
||||
},
|
||||
)
|
||||
.await;
|
||||
|
||||
assert_eq!(result, CacheResult::NoAction(true));
|
||||
|
||||
// Change the settings back.
|
||||
let old_settings = ctx.settings.clone();
|
||||
ctx.settings.highlight_edges = !ctx.settings.highlight_edges;
|
||||
|
||||
let result = get_changed_program(
|
||||
CacheInformation {
|
||||
ast: &program.ast,
|
||||
settings: &old_settings,
|
||||
},
|
||||
CacheInformation {
|
||||
ast: &program.ast,
|
||||
settings: &ctx.settings,
|
||||
},
|
||||
)
|
||||
.await;
|
||||
|
||||
assert_eq!(result, CacheResult::NoAction(true));
|
||||
}
|
||||
|
||||
// Changing the units settings using an annotation with the exact same file
|
||||
|
||||
@ -587,6 +587,14 @@ impl ExecutorContext {
|
||||
.await
|
||||
.is_ok()
|
||||
{
|
||||
// We need to update the old ast state with the new settings!!
|
||||
cache::write_old_ast(OldAstState {
|
||||
ast: old_ast,
|
||||
exec_state: old_state.clone(),
|
||||
settings: self.settings.clone(),
|
||||
})
|
||||
.await;
|
||||
|
||||
return Ok(old_state.to_wasm_outcome());
|
||||
}
|
||||
(true, program.ast)
|
||||
@ -1672,4 +1680,59 @@ let w = f() + f()
|
||||
|
||||
assert_eq!(id_generator, new_id_generator);
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn kcl_test_changing_a_setting_updates_the_cached_state() {
|
||||
let code = r#"sketch001 = startSketchOn('XZ')
|
||||
|> startProfileAt([61.74, 206.13], %)
|
||||
|> xLine(305.11, %, $seg01)
|
||||
|> yLine(-291.85, %)
|
||||
|> xLine(-segLen(seg01), %)
|
||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
|> close()
|
||||
|> extrude(length = 40.14)
|
||||
|> shell(
|
||||
thickness = 3.14,
|
||||
faces = [seg01]
|
||||
)
|
||||
"#;
|
||||
|
||||
let mut ctx = crate::test_server::new_context(UnitLength::Mm, true, None)
|
||||
.await
|
||||
.unwrap();
|
||||
let old_program = crate::Program::parse_no_errs(code).unwrap();
|
||||
|
||||
// Execute the program.
|
||||
ctx.run_with_caching(old_program.clone()).await.unwrap();
|
||||
|
||||
// Get the id_generator from the first execution.
|
||||
let settings_state = cache::read_old_ast().await.unwrap().settings;
|
||||
|
||||
// Ensure the settings are as expected.
|
||||
assert_eq!(settings_state, ctx.settings);
|
||||
|
||||
// Change a setting.
|
||||
ctx.settings.highlight_edges = !ctx.settings.highlight_edges;
|
||||
|
||||
// Execute the program.
|
||||
ctx.run_with_caching(old_program.clone()).await.unwrap();
|
||||
|
||||
// Get the id_generator from the first execution.
|
||||
let settings_state = cache::read_old_ast().await.unwrap().settings;
|
||||
|
||||
// Ensure the settings are as expected.
|
||||
assert_eq!(settings_state, ctx.settings);
|
||||
|
||||
// Change a setting.
|
||||
ctx.settings.highlight_edges = !ctx.settings.highlight_edges;
|
||||
|
||||
// Execute the program.
|
||||
ctx.run_with_caching(old_program).await.unwrap();
|
||||
|
||||
// Get the id_generator from the first execution.
|
||||
let settings_state = cache::read_old_ast().await.unwrap().settings;
|
||||
|
||||
// Ensure the settings are as expected.
|
||||
assert_eq!(settings_state, ctx.settings);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user