KCL: Show beautiful Miette errors when a KCL example test fails (#4829)

* KCL: Show beautiful Miette errors when a KCL example test fails

Background: KCL example tests are generated from the stdlib KCL examples in the `#[stdlib]` macro in derive-docs.

Problem: When these tests fail, they output a really unhelpful error message like Kcl(Semantic(KclErrorDetails { source_ranges: [156, 160, 0], message: "Expected a sketch but found array" } )).

Solution: Use miette. Now the errors highlight the KCL code that failed and show exactly what went wrong, on which line, presenting nice diagnostics that look like cargo/rustc output.

* Update helix snapshots
This commit is contained in:
Adam Chalmers
2024-12-18 08:52:17 -06:00
committed by GitHub
parent 7193b4110a
commit 93891422f7
19 changed files with 431 additions and 124 deletions

File diff suppressed because one or more lines are too long

View File

@ -805,7 +805,7 @@ fn generate_code_block_test(fn_name: &str, code_block: &str, index: usize) -> pr
quote! { quote! {
#[tokio::test(flavor = "multi_thread")] #[tokio::test(flavor = "multi_thread")]
async fn #test_name_mock() { async fn #test_name_mock() -> miette::Result<()> {
let program = crate::Program::parse_no_errs(#code_block).unwrap(); let program = crate::Program::parse_no_errs(#code_block).unwrap();
let ctx = crate::ExecutorContext { let ctx = crate::ExecutorContext {
engine: std::sync::Arc::new(Box::new(crate::engine::conn_mock::EngineConnection::new().await.unwrap())), engine: std::sync::Arc::new(Box::new(crate::engine::conn_mock::EngineConnection::new().await.unwrap())),
@ -815,15 +815,33 @@ fn generate_code_block_test(fn_name: &str, code_block: &str, index: usize) -> pr
context_type: crate::execution::ContextType::Mock, context_type: crate::execution::ContextType::Mock,
}; };
ctx.run(program.into(), &mut crate::ExecState::new()).await.unwrap(); if let Err(e) = ctx.run(program.into(), &mut crate::ExecState::new()).await {
return Err(miette::Report::new(crate::errors::Report {
error: e,
filename: format!("{}{}", #fn_name, #index),
kcl_source: #code_block.to_string(),
}));
}
Ok(())
} }
#[tokio::test(flavor = "multi_thread", worker_threads = 5)] #[tokio::test(flavor = "multi_thread", worker_threads = 5)]
async fn #test_name() { async fn #test_name() -> miette::Result<()> {
let code = #code_block; let code = #code_block;
// Note, `crate` must be kcl_lib // Note, `crate` must be kcl_lib
let result = crate::test_server::execute_and_snapshot(code, crate::settings::types::UnitLength::Mm, None).await.unwrap(); let result = match crate::test_server::execute_and_snapshot(code, crate::settings::types::UnitLength::Mm, None).await {
Err(crate::errors::ExecError::Kcl(e)) => {
return Err(miette::Report::new(crate::errors::Report {
error: e,
filename: format!("{}{}", #fn_name, #index),
kcl_source: #code_block.to_string(),
}));
}
Err(other_err)=> panic!("{}", other_err),
Ok(img) => img,
};
twenty_twenty::assert_image(&format!("tests/outputs/{}.png", #output_test_name_str), &result, 0.99); twenty_twenty::assert_image(&format!("tests/outputs/{}.png", #output_test_name_str), &result, 0.99);
Ok(())
} }
} }
} }

View File

@ -1,7 +1,7 @@
#[cfg(test)] #[cfg(test)]
mod test_examples_someFn { mod test_examples_someFn {
#[tokio::test(flavor = "multi_thread")] #[tokio::test(flavor = "multi_thread")]
async fn test_mock_example_someFn0() { async fn test_mock_example_someFn0() -> miette::Result<()> {
let program = crate::Program::parse_no_errs("someFn()").unwrap(); let program = crate::Program::parse_no_errs("someFn()").unwrap();
let ctx = crate::ExecutorContext { let ctx = crate::ExecutorContext {
engine: std::sync::Arc::new(Box::new( engine: std::sync::Arc::new(Box::new(
@ -14,26 +14,43 @@ mod test_examples_someFn {
settings: Default::default(), settings: Default::default(),
context_type: crate::execution::ContextType::Mock, context_type: crate::execution::ContextType::Mock,
}; };
ctx.run(program.into(), &mut crate::ExecState::new()) if let Err(e) = ctx.run(program.into(), &mut crate::ExecState::new()).await {
.await return Err(miette::Report::new(crate::errors::Report {
.unwrap(); error: e,
filename: format!("{}{}", "someFn", 0usize),
kcl_source: "someFn()".to_string(),
}));
}
Ok(())
} }
#[tokio::test(flavor = "multi_thread", worker_threads = 5)] #[tokio::test(flavor = "multi_thread", worker_threads = 5)]
async fn kcl_test_example_someFn0() { async fn kcl_test_example_someFn0() -> miette::Result<()> {
let code = "someFn()"; let code = "someFn()";
let result = crate::test_server::execute_and_snapshot( let result = match crate::test_server::execute_and_snapshot(
code, code,
crate::settings::types::UnitLength::Mm, crate::settings::types::UnitLength::Mm,
None, None,
) )
.await .await
.unwrap(); {
Err(crate::errors::ExecError::Kcl(e)) => {
return Err(miette::Report::new(crate::errors::Report {
error: e,
filename: format!("{}{}", "someFn", 0usize),
kcl_source: "someFn()".to_string(),
}));
}
Err(other_err) => panic!("{}", other_err),
Ok(img) => img,
};
twenty_twenty::assert_image( twenty_twenty::assert_image(
&format!("tests/outputs/{}.png", "serial_test_example_someFn0"), &format!("tests/outputs/{}.png", "serial_test_example_someFn0"),
&result, &result,
0.99, 0.99,
); );
Ok(())
} }
} }

View File

@ -1,7 +1,7 @@
#[cfg(test)] #[cfg(test)]
mod test_examples_someFn { mod test_examples_someFn {
#[tokio::test(flavor = "multi_thread")] #[tokio::test(flavor = "multi_thread")]
async fn test_mock_example_someFn0() { async fn test_mock_example_someFn0() -> miette::Result<()> {
let program = crate::Program::parse_no_errs("someFn()").unwrap(); let program = crate::Program::parse_no_errs("someFn()").unwrap();
let ctx = crate::ExecutorContext { let ctx = crate::ExecutorContext {
engine: std::sync::Arc::new(Box::new( engine: std::sync::Arc::new(Box::new(
@ -14,26 +14,43 @@ mod test_examples_someFn {
settings: Default::default(), settings: Default::default(),
context_type: crate::execution::ContextType::Mock, context_type: crate::execution::ContextType::Mock,
}; };
ctx.run(program.into(), &mut crate::ExecState::new()) if let Err(e) = ctx.run(program.into(), &mut crate::ExecState::new()).await {
.await return Err(miette::Report::new(crate::errors::Report {
.unwrap(); error: e,
filename: format!("{}{}", "someFn", 0usize),
kcl_source: "someFn()".to_string(),
}));
}
Ok(())
} }
#[tokio::test(flavor = "multi_thread", worker_threads = 5)] #[tokio::test(flavor = "multi_thread", worker_threads = 5)]
async fn kcl_test_example_someFn0() { async fn kcl_test_example_someFn0() -> miette::Result<()> {
let code = "someFn()"; let code = "someFn()";
let result = crate::test_server::execute_and_snapshot( let result = match crate::test_server::execute_and_snapshot(
code, code,
crate::settings::types::UnitLength::Mm, crate::settings::types::UnitLength::Mm,
None, None,
) )
.await .await
.unwrap(); {
Err(crate::errors::ExecError::Kcl(e)) => {
return Err(miette::Report::new(crate::errors::Report {
error: e,
filename: format!("{}{}", "someFn", 0usize),
kcl_source: "someFn()".to_string(),
}));
}
Err(other_err) => panic!("{}", other_err),
Ok(img) => img,
};
twenty_twenty::assert_image( twenty_twenty::assert_image(
&format!("tests/outputs/{}.png", "serial_test_example_someFn0"), &format!("tests/outputs/{}.png", "serial_test_example_someFn0"),
&result, &result,
0.99, 0.99,
); );
Ok(())
} }
} }

View File

@ -1,7 +1,7 @@
#[cfg(test)] #[cfg(test)]
mod test_examples_show { mod test_examples_show {
#[tokio::test(flavor = "multi_thread")] #[tokio::test(flavor = "multi_thread")]
async fn test_mock_example_show0() { async fn test_mock_example_show0() -> miette::Result<()> {
let program = let program =
crate::Program::parse_no_errs("This is another code block.\nyes sirrr.\nshow").unwrap(); crate::Program::parse_no_errs("This is another code block.\nyes sirrr.\nshow").unwrap();
let ctx = crate::ExecutorContext { let ctx = crate::ExecutorContext {
@ -15,30 +15,47 @@ mod test_examples_show {
settings: Default::default(), settings: Default::default(),
context_type: crate::execution::ContextType::Mock, context_type: crate::execution::ContextType::Mock,
}; };
ctx.run(program.into(), &mut crate::ExecState::new()) if let Err(e) = ctx.run(program.into(), &mut crate::ExecState::new()).await {
.await return Err(miette::Report::new(crate::errors::Report {
.unwrap(); error: e,
filename: format!("{}{}", "show", 0usize),
kcl_source: "This is another code block.\nyes sirrr.\nshow".to_string(),
}));
}
Ok(())
} }
#[tokio::test(flavor = "multi_thread", worker_threads = 5)] #[tokio::test(flavor = "multi_thread", worker_threads = 5)]
async fn kcl_test_example_show0() { async fn kcl_test_example_show0() -> miette::Result<()> {
let code = "This is another code block.\nyes sirrr.\nshow"; let code = "This is another code block.\nyes sirrr.\nshow";
let result = crate::test_server::execute_and_snapshot( let result = match crate::test_server::execute_and_snapshot(
code, code,
crate::settings::types::UnitLength::Mm, crate::settings::types::UnitLength::Mm,
None, None,
) )
.await .await
.unwrap(); {
Err(crate::errors::ExecError::Kcl(e)) => {
return Err(miette::Report::new(crate::errors::Report {
error: e,
filename: format!("{}{}", "show", 0usize),
kcl_source: "This is another code block.\nyes sirrr.\nshow".to_string(),
}));
}
Err(other_err) => panic!("{}", other_err),
Ok(img) => img,
};
twenty_twenty::assert_image( twenty_twenty::assert_image(
&format!("tests/outputs/{}.png", "serial_test_example_show0"), &format!("tests/outputs/{}.png", "serial_test_example_show0"),
&result, &result,
0.99, 0.99,
); );
Ok(())
} }
#[tokio::test(flavor = "multi_thread")] #[tokio::test(flavor = "multi_thread")]
async fn test_mock_example_show1() { async fn test_mock_example_show1() -> miette::Result<()> {
let program = let program =
crate::Program::parse_no_errs("This is code.\nIt does other shit.\nshow").unwrap(); crate::Program::parse_no_errs("This is code.\nIt does other shit.\nshow").unwrap();
let ctx = crate::ExecutorContext { let ctx = crate::ExecutorContext {
@ -52,26 +69,43 @@ mod test_examples_show {
settings: Default::default(), settings: Default::default(),
context_type: crate::execution::ContextType::Mock, context_type: crate::execution::ContextType::Mock,
}; };
ctx.run(program.into(), &mut crate::ExecState::new()) if let Err(e) = ctx.run(program.into(), &mut crate::ExecState::new()).await {
.await return Err(miette::Report::new(crate::errors::Report {
.unwrap(); error: e,
filename: format!("{}{}", "show", 1usize),
kcl_source: "This is code.\nIt does other shit.\nshow".to_string(),
}));
}
Ok(())
} }
#[tokio::test(flavor = "multi_thread", worker_threads = 5)] #[tokio::test(flavor = "multi_thread", worker_threads = 5)]
async fn kcl_test_example_show1() { async fn kcl_test_example_show1() -> miette::Result<()> {
let code = "This is code.\nIt does other shit.\nshow"; let code = "This is code.\nIt does other shit.\nshow";
let result = crate::test_server::execute_and_snapshot( let result = match crate::test_server::execute_and_snapshot(
code, code,
crate::settings::types::UnitLength::Mm, crate::settings::types::UnitLength::Mm,
None, None,
) )
.await .await
.unwrap(); {
Err(crate::errors::ExecError::Kcl(e)) => {
return Err(miette::Report::new(crate::errors::Report {
error: e,
filename: format!("{}{}", "show", 1usize),
kcl_source: "This is code.\nIt does other shit.\nshow".to_string(),
}));
}
Err(other_err) => panic!("{}", other_err),
Ok(img) => img,
};
twenty_twenty::assert_image( twenty_twenty::assert_image(
&format!("tests/outputs/{}.png", "serial_test_example_show1"), &format!("tests/outputs/{}.png", "serial_test_example_show1"),
&result, &result,
0.99, 0.99,
); );
Ok(())
} }
} }

View File

@ -1,7 +1,7 @@
#[cfg(test)] #[cfg(test)]
mod test_examples_show { mod test_examples_show {
#[tokio::test(flavor = "multi_thread")] #[tokio::test(flavor = "multi_thread")]
async fn test_mock_example_show0() { async fn test_mock_example_show0() -> miette::Result<()> {
let program = let program =
crate::Program::parse_no_errs("This is code.\nIt does other shit.\nshow").unwrap(); crate::Program::parse_no_errs("This is code.\nIt does other shit.\nshow").unwrap();
let ctx = crate::ExecutorContext { let ctx = crate::ExecutorContext {
@ -15,26 +15,43 @@ mod test_examples_show {
settings: Default::default(), settings: Default::default(),
context_type: crate::execution::ContextType::Mock, context_type: crate::execution::ContextType::Mock,
}; };
ctx.run(program.into(), &mut crate::ExecState::new()) if let Err(e) = ctx.run(program.into(), &mut crate::ExecState::new()).await {
.await return Err(miette::Report::new(crate::errors::Report {
.unwrap(); error: e,
filename: format!("{}{}", "show", 0usize),
kcl_source: "This is code.\nIt does other shit.\nshow".to_string(),
}));
}
Ok(())
} }
#[tokio::test(flavor = "multi_thread", worker_threads = 5)] #[tokio::test(flavor = "multi_thread", worker_threads = 5)]
async fn kcl_test_example_show0() { async fn kcl_test_example_show0() -> miette::Result<()> {
let code = "This is code.\nIt does other shit.\nshow"; let code = "This is code.\nIt does other shit.\nshow";
let result = crate::test_server::execute_and_snapshot( let result = match crate::test_server::execute_and_snapshot(
code, code,
crate::settings::types::UnitLength::Mm, crate::settings::types::UnitLength::Mm,
None, None,
) )
.await .await
.unwrap(); {
Err(crate::errors::ExecError::Kcl(e)) => {
return Err(miette::Report::new(crate::errors::Report {
error: e,
filename: format!("{}{}", "show", 0usize),
kcl_source: "This is code.\nIt does other shit.\nshow".to_string(),
}));
}
Err(other_err) => panic!("{}", other_err),
Ok(img) => img,
};
twenty_twenty::assert_image( twenty_twenty::assert_image(
&format!("tests/outputs/{}.png", "serial_test_example_show0"), &format!("tests/outputs/{}.png", "serial_test_example_show0"),
&result, &result,
0.99, 0.99,
); );
Ok(())
} }
} }

View File

@ -1,7 +1,7 @@
#[cfg(test)] #[cfg(test)]
mod test_examples_my_func { mod test_examples_my_func {
#[tokio::test(flavor = "multi_thread")] #[tokio::test(flavor = "multi_thread")]
async fn test_mock_example_my_func0() { async fn test_mock_example_my_func0() -> miette::Result<()> {
let program = let program =
crate::Program::parse_no_errs("This is another code block.\nyes sirrr.\nmyFunc") crate::Program::parse_no_errs("This is another code block.\nyes sirrr.\nmyFunc")
.unwrap(); .unwrap();
@ -16,30 +16,47 @@ mod test_examples_my_func {
settings: Default::default(), settings: Default::default(),
context_type: crate::execution::ContextType::Mock, context_type: crate::execution::ContextType::Mock,
}; };
ctx.run(program.into(), &mut crate::ExecState::new()) if let Err(e) = ctx.run(program.into(), &mut crate::ExecState::new()).await {
.await return Err(miette::Report::new(crate::errors::Report {
.unwrap(); error: e,
filename: format!("{}{}", "my_func", 0usize),
kcl_source: "This is another code block.\nyes sirrr.\nmyFunc".to_string(),
}));
}
Ok(())
} }
#[tokio::test(flavor = "multi_thread", worker_threads = 5)] #[tokio::test(flavor = "multi_thread", worker_threads = 5)]
async fn kcl_test_example_my_func0() { async fn kcl_test_example_my_func0() -> miette::Result<()> {
let code = "This is another code block.\nyes sirrr.\nmyFunc"; let code = "This is another code block.\nyes sirrr.\nmyFunc";
let result = crate::test_server::execute_and_snapshot( let result = match crate::test_server::execute_and_snapshot(
code, code,
crate::settings::types::UnitLength::Mm, crate::settings::types::UnitLength::Mm,
None, None,
) )
.await .await
.unwrap(); {
Err(crate::errors::ExecError::Kcl(e)) => {
return Err(miette::Report::new(crate::errors::Report {
error: e,
filename: format!("{}{}", "my_func", 0usize),
kcl_source: "This is another code block.\nyes sirrr.\nmyFunc".to_string(),
}));
}
Err(other_err) => panic!("{}", other_err),
Ok(img) => img,
};
twenty_twenty::assert_image( twenty_twenty::assert_image(
&format!("tests/outputs/{}.png", "serial_test_example_my_func0"), &format!("tests/outputs/{}.png", "serial_test_example_my_func0"),
&result, &result,
0.99, 0.99,
); );
Ok(())
} }
#[tokio::test(flavor = "multi_thread")] #[tokio::test(flavor = "multi_thread")]
async fn test_mock_example_my_func1() { async fn test_mock_example_my_func1() -> miette::Result<()> {
let program = let program =
crate::Program::parse_no_errs("This is code.\nIt does other shit.\nmyFunc").unwrap(); crate::Program::parse_no_errs("This is code.\nIt does other shit.\nmyFunc").unwrap();
let ctx = crate::ExecutorContext { let ctx = crate::ExecutorContext {
@ -53,26 +70,43 @@ mod test_examples_my_func {
settings: Default::default(), settings: Default::default(),
context_type: crate::execution::ContextType::Mock, context_type: crate::execution::ContextType::Mock,
}; };
ctx.run(program.into(), &mut crate::ExecState::new()) if let Err(e) = ctx.run(program.into(), &mut crate::ExecState::new()).await {
.await return Err(miette::Report::new(crate::errors::Report {
.unwrap(); error: e,
filename: format!("{}{}", "my_func", 1usize),
kcl_source: "This is code.\nIt does other shit.\nmyFunc".to_string(),
}));
}
Ok(())
} }
#[tokio::test(flavor = "multi_thread", worker_threads = 5)] #[tokio::test(flavor = "multi_thread", worker_threads = 5)]
async fn kcl_test_example_my_func1() { async fn kcl_test_example_my_func1() -> miette::Result<()> {
let code = "This is code.\nIt does other shit.\nmyFunc"; let code = "This is code.\nIt does other shit.\nmyFunc";
let result = crate::test_server::execute_and_snapshot( let result = match crate::test_server::execute_and_snapshot(
code, code,
crate::settings::types::UnitLength::Mm, crate::settings::types::UnitLength::Mm,
None, None,
) )
.await .await
.unwrap(); {
Err(crate::errors::ExecError::Kcl(e)) => {
return Err(miette::Report::new(crate::errors::Report {
error: e,
filename: format!("{}{}", "my_func", 1usize),
kcl_source: "This is code.\nIt does other shit.\nmyFunc".to_string(),
}));
}
Err(other_err) => panic!("{}", other_err),
Ok(img) => img,
};
twenty_twenty::assert_image( twenty_twenty::assert_image(
&format!("tests/outputs/{}.png", "serial_test_example_my_func1"), &format!("tests/outputs/{}.png", "serial_test_example_my_func1"),
&result, &result,
0.99, 0.99,
); );
Ok(())
} }
} }

View File

@ -1,7 +1,7 @@
#[cfg(test)] #[cfg(test)]
mod test_examples_line_to { mod test_examples_line_to {
#[tokio::test(flavor = "multi_thread")] #[tokio::test(flavor = "multi_thread")]
async fn test_mock_example_line_to0() { async fn test_mock_example_line_to0() -> miette::Result<()> {
let program = let program =
crate::Program::parse_no_errs("This is another code block.\nyes sirrr.\nlineTo") crate::Program::parse_no_errs("This is another code block.\nyes sirrr.\nlineTo")
.unwrap(); .unwrap();
@ -16,30 +16,47 @@ mod test_examples_line_to {
settings: Default::default(), settings: Default::default(),
context_type: crate::execution::ContextType::Mock, context_type: crate::execution::ContextType::Mock,
}; };
ctx.run(program.into(), &mut crate::ExecState::new()) if let Err(e) = ctx.run(program.into(), &mut crate::ExecState::new()).await {
.await return Err(miette::Report::new(crate::errors::Report {
.unwrap(); error: e,
filename: format!("{}{}", "line_to", 0usize),
kcl_source: "This is another code block.\nyes sirrr.\nlineTo".to_string(),
}));
}
Ok(())
} }
#[tokio::test(flavor = "multi_thread", worker_threads = 5)] #[tokio::test(flavor = "multi_thread", worker_threads = 5)]
async fn kcl_test_example_line_to0() { async fn kcl_test_example_line_to0() -> miette::Result<()> {
let code = "This is another code block.\nyes sirrr.\nlineTo"; let code = "This is another code block.\nyes sirrr.\nlineTo";
let result = crate::test_server::execute_and_snapshot( let result = match crate::test_server::execute_and_snapshot(
code, code,
crate::settings::types::UnitLength::Mm, crate::settings::types::UnitLength::Mm,
None, None,
) )
.await .await
.unwrap(); {
Err(crate::errors::ExecError::Kcl(e)) => {
return Err(miette::Report::new(crate::errors::Report {
error: e,
filename: format!("{}{}", "line_to", 0usize),
kcl_source: "This is another code block.\nyes sirrr.\nlineTo".to_string(),
}));
}
Err(other_err) => panic!("{}", other_err),
Ok(img) => img,
};
twenty_twenty::assert_image( twenty_twenty::assert_image(
&format!("tests/outputs/{}.png", "serial_test_example_line_to0"), &format!("tests/outputs/{}.png", "serial_test_example_line_to0"),
&result, &result,
0.99, 0.99,
); );
Ok(())
} }
#[tokio::test(flavor = "multi_thread")] #[tokio::test(flavor = "multi_thread")]
async fn test_mock_example_line_to1() { async fn test_mock_example_line_to1() -> miette::Result<()> {
let program = let program =
crate::Program::parse_no_errs("This is code.\nIt does other shit.\nlineTo").unwrap(); crate::Program::parse_no_errs("This is code.\nIt does other shit.\nlineTo").unwrap();
let ctx = crate::ExecutorContext { let ctx = crate::ExecutorContext {
@ -53,26 +70,43 @@ mod test_examples_line_to {
settings: Default::default(), settings: Default::default(),
context_type: crate::execution::ContextType::Mock, context_type: crate::execution::ContextType::Mock,
}; };
ctx.run(program.into(), &mut crate::ExecState::new()) if let Err(e) = ctx.run(program.into(), &mut crate::ExecState::new()).await {
.await return Err(miette::Report::new(crate::errors::Report {
.unwrap(); error: e,
filename: format!("{}{}", "line_to", 1usize),
kcl_source: "This is code.\nIt does other shit.\nlineTo".to_string(),
}));
}
Ok(())
} }
#[tokio::test(flavor = "multi_thread", worker_threads = 5)] #[tokio::test(flavor = "multi_thread", worker_threads = 5)]
async fn kcl_test_example_line_to1() { async fn kcl_test_example_line_to1() -> miette::Result<()> {
let code = "This is code.\nIt does other shit.\nlineTo"; let code = "This is code.\nIt does other shit.\nlineTo";
let result = crate::test_server::execute_and_snapshot( let result = match crate::test_server::execute_and_snapshot(
code, code,
crate::settings::types::UnitLength::Mm, crate::settings::types::UnitLength::Mm,
None, None,
) )
.await .await
.unwrap(); {
Err(crate::errors::ExecError::Kcl(e)) => {
return Err(miette::Report::new(crate::errors::Report {
error: e,
filename: format!("{}{}", "line_to", 1usize),
kcl_source: "This is code.\nIt does other shit.\nlineTo".to_string(),
}));
}
Err(other_err) => panic!("{}", other_err),
Ok(img) => img,
};
twenty_twenty::assert_image( twenty_twenty::assert_image(
&format!("tests/outputs/{}.png", "serial_test_example_line_to1"), &format!("tests/outputs/{}.png", "serial_test_example_line_to1"),
&result, &result,
0.99, 0.99,
); );
Ok(())
} }
} }

View File

@ -1,7 +1,7 @@
#[cfg(test)] #[cfg(test)]
mod test_examples_min { mod test_examples_min {
#[tokio::test(flavor = "multi_thread")] #[tokio::test(flavor = "multi_thread")]
async fn test_mock_example_min0() { async fn test_mock_example_min0() -> miette::Result<()> {
let program = let program =
crate::Program::parse_no_errs("This is another code block.\nyes sirrr.\nmin").unwrap(); crate::Program::parse_no_errs("This is another code block.\nyes sirrr.\nmin").unwrap();
let ctx = crate::ExecutorContext { let ctx = crate::ExecutorContext {
@ -15,30 +15,47 @@ mod test_examples_min {
settings: Default::default(), settings: Default::default(),
context_type: crate::execution::ContextType::Mock, context_type: crate::execution::ContextType::Mock,
}; };
ctx.run(program.into(), &mut crate::ExecState::new()) if let Err(e) = ctx.run(program.into(), &mut crate::ExecState::new()).await {
.await return Err(miette::Report::new(crate::errors::Report {
.unwrap(); error: e,
filename: format!("{}{}", "min", 0usize),
kcl_source: "This is another code block.\nyes sirrr.\nmin".to_string(),
}));
}
Ok(())
} }
#[tokio::test(flavor = "multi_thread", worker_threads = 5)] #[tokio::test(flavor = "multi_thread", worker_threads = 5)]
async fn kcl_test_example_min0() { async fn kcl_test_example_min0() -> miette::Result<()> {
let code = "This is another code block.\nyes sirrr.\nmin"; let code = "This is another code block.\nyes sirrr.\nmin";
let result = crate::test_server::execute_and_snapshot( let result = match crate::test_server::execute_and_snapshot(
code, code,
crate::settings::types::UnitLength::Mm, crate::settings::types::UnitLength::Mm,
None, None,
) )
.await .await
.unwrap(); {
Err(crate::errors::ExecError::Kcl(e)) => {
return Err(miette::Report::new(crate::errors::Report {
error: e,
filename: format!("{}{}", "min", 0usize),
kcl_source: "This is another code block.\nyes sirrr.\nmin".to_string(),
}));
}
Err(other_err) => panic!("{}", other_err),
Ok(img) => img,
};
twenty_twenty::assert_image( twenty_twenty::assert_image(
&format!("tests/outputs/{}.png", "serial_test_example_min0"), &format!("tests/outputs/{}.png", "serial_test_example_min0"),
&result, &result,
0.99, 0.99,
); );
Ok(())
} }
#[tokio::test(flavor = "multi_thread")] #[tokio::test(flavor = "multi_thread")]
async fn test_mock_example_min1() { async fn test_mock_example_min1() -> miette::Result<()> {
let program = let program =
crate::Program::parse_no_errs("This is code.\nIt does other shit.\nmin").unwrap(); crate::Program::parse_no_errs("This is code.\nIt does other shit.\nmin").unwrap();
let ctx = crate::ExecutorContext { let ctx = crate::ExecutorContext {
@ -52,26 +69,43 @@ mod test_examples_min {
settings: Default::default(), settings: Default::default(),
context_type: crate::execution::ContextType::Mock, context_type: crate::execution::ContextType::Mock,
}; };
ctx.run(program.into(), &mut crate::ExecState::new()) if let Err(e) = ctx.run(program.into(), &mut crate::ExecState::new()).await {
.await return Err(miette::Report::new(crate::errors::Report {
.unwrap(); error: e,
filename: format!("{}{}", "min", 1usize),
kcl_source: "This is code.\nIt does other shit.\nmin".to_string(),
}));
}
Ok(())
} }
#[tokio::test(flavor = "multi_thread", worker_threads = 5)] #[tokio::test(flavor = "multi_thread", worker_threads = 5)]
async fn kcl_test_example_min1() { async fn kcl_test_example_min1() -> miette::Result<()> {
let code = "This is code.\nIt does other shit.\nmin"; let code = "This is code.\nIt does other shit.\nmin";
let result = crate::test_server::execute_and_snapshot( let result = match crate::test_server::execute_and_snapshot(
code, code,
crate::settings::types::UnitLength::Mm, crate::settings::types::UnitLength::Mm,
None, None,
) )
.await .await
.unwrap(); {
Err(crate::errors::ExecError::Kcl(e)) => {
return Err(miette::Report::new(crate::errors::Report {
error: e,
filename: format!("{}{}", "min", 1usize),
kcl_source: "This is code.\nIt does other shit.\nmin".to_string(),
}));
}
Err(other_err) => panic!("{}", other_err),
Ok(img) => img,
};
twenty_twenty::assert_image( twenty_twenty::assert_image(
&format!("tests/outputs/{}.png", "serial_test_example_min1"), &format!("tests/outputs/{}.png", "serial_test_example_min1"),
&result, &result,
0.99, 0.99,
); );
Ok(())
} }
} }

View File

@ -1,7 +1,7 @@
#[cfg(test)] #[cfg(test)]
mod test_examples_show { mod test_examples_show {
#[tokio::test(flavor = "multi_thread")] #[tokio::test(flavor = "multi_thread")]
async fn test_mock_example_show0() { async fn test_mock_example_show0() -> miette::Result<()> {
let program = let program =
crate::Program::parse_no_errs("This is code.\nIt does other shit.\nshow").unwrap(); crate::Program::parse_no_errs("This is code.\nIt does other shit.\nshow").unwrap();
let ctx = crate::ExecutorContext { let ctx = crate::ExecutorContext {
@ -15,26 +15,43 @@ mod test_examples_show {
settings: Default::default(), settings: Default::default(),
context_type: crate::execution::ContextType::Mock, context_type: crate::execution::ContextType::Mock,
}; };
ctx.run(program.into(), &mut crate::ExecState::new()) if let Err(e) = ctx.run(program.into(), &mut crate::ExecState::new()).await {
.await return Err(miette::Report::new(crate::errors::Report {
.unwrap(); error: e,
filename: format!("{}{}", "show", 0usize),
kcl_source: "This is code.\nIt does other shit.\nshow".to_string(),
}));
}
Ok(())
} }
#[tokio::test(flavor = "multi_thread", worker_threads = 5)] #[tokio::test(flavor = "multi_thread", worker_threads = 5)]
async fn kcl_test_example_show0() { async fn kcl_test_example_show0() -> miette::Result<()> {
let code = "This is code.\nIt does other shit.\nshow"; let code = "This is code.\nIt does other shit.\nshow";
let result = crate::test_server::execute_and_snapshot( let result = match crate::test_server::execute_and_snapshot(
code, code,
crate::settings::types::UnitLength::Mm, crate::settings::types::UnitLength::Mm,
None, None,
) )
.await .await
.unwrap(); {
Err(crate::errors::ExecError::Kcl(e)) => {
return Err(miette::Report::new(crate::errors::Report {
error: e,
filename: format!("{}{}", "show", 0usize),
kcl_source: "This is code.\nIt does other shit.\nshow".to_string(),
}));
}
Err(other_err) => panic!("{}", other_err),
Ok(img) => img,
};
twenty_twenty::assert_image( twenty_twenty::assert_image(
&format!("tests/outputs/{}.png", "serial_test_example_show0"), &format!("tests/outputs/{}.png", "serial_test_example_show0"),
&result, &result,
0.99, 0.99,
); );
Ok(())
} }
} }

View File

@ -1,7 +1,7 @@
#[cfg(test)] #[cfg(test)]
mod test_examples_import { mod test_examples_import {
#[tokio::test(flavor = "multi_thread")] #[tokio::test(flavor = "multi_thread")]
async fn test_mock_example_import0() { async fn test_mock_example_import0() -> miette::Result<()> {
let program = let program =
crate::Program::parse_no_errs("This is code.\nIt does other shit.\nimport").unwrap(); crate::Program::parse_no_errs("This is code.\nIt does other shit.\nimport").unwrap();
let ctx = crate::ExecutorContext { let ctx = crate::ExecutorContext {
@ -15,26 +15,43 @@ mod test_examples_import {
settings: Default::default(), settings: Default::default(),
context_type: crate::execution::ContextType::Mock, context_type: crate::execution::ContextType::Mock,
}; };
ctx.run(program.into(), &mut crate::ExecState::new()) if let Err(e) = ctx.run(program.into(), &mut crate::ExecState::new()).await {
.await return Err(miette::Report::new(crate::errors::Report {
.unwrap(); error: e,
filename: format!("{}{}", "import", 0usize),
kcl_source: "This is code.\nIt does other shit.\nimport".to_string(),
}));
}
Ok(())
} }
#[tokio::test(flavor = "multi_thread", worker_threads = 5)] #[tokio::test(flavor = "multi_thread", worker_threads = 5)]
async fn kcl_test_example_import0() { async fn kcl_test_example_import0() -> miette::Result<()> {
let code = "This is code.\nIt does other shit.\nimport"; let code = "This is code.\nIt does other shit.\nimport";
let result = crate::test_server::execute_and_snapshot( let result = match crate::test_server::execute_and_snapshot(
code, code,
crate::settings::types::UnitLength::Mm, crate::settings::types::UnitLength::Mm,
None, None,
) )
.await .await
.unwrap(); {
Err(crate::errors::ExecError::Kcl(e)) => {
return Err(miette::Report::new(crate::errors::Report {
error: e,
filename: format!("{}{}", "import", 0usize),
kcl_source: "This is code.\nIt does other shit.\nimport".to_string(),
}));
}
Err(other_err) => panic!("{}", other_err),
Ok(img) => img,
};
twenty_twenty::assert_image( twenty_twenty::assert_image(
&format!("tests/outputs/{}.png", "serial_test_example_import0"), &format!("tests/outputs/{}.png", "serial_test_example_import0"),
&result, &result,
0.99, 0.99,
); );
Ok(())
} }
} }

View File

@ -1,7 +1,7 @@
#[cfg(test)] #[cfg(test)]
mod test_examples_import { mod test_examples_import {
#[tokio::test(flavor = "multi_thread")] #[tokio::test(flavor = "multi_thread")]
async fn test_mock_example_import0() { async fn test_mock_example_import0() -> miette::Result<()> {
let program = let program =
crate::Program::parse_no_errs("This is code.\nIt does other shit.\nimport").unwrap(); crate::Program::parse_no_errs("This is code.\nIt does other shit.\nimport").unwrap();
let ctx = crate::ExecutorContext { let ctx = crate::ExecutorContext {
@ -15,26 +15,43 @@ mod test_examples_import {
settings: Default::default(), settings: Default::default(),
context_type: crate::execution::ContextType::Mock, context_type: crate::execution::ContextType::Mock,
}; };
ctx.run(program.into(), &mut crate::ExecState::new()) if let Err(e) = ctx.run(program.into(), &mut crate::ExecState::new()).await {
.await return Err(miette::Report::new(crate::errors::Report {
.unwrap(); error: e,
filename: format!("{}{}", "import", 0usize),
kcl_source: "This is code.\nIt does other shit.\nimport".to_string(),
}));
}
Ok(())
} }
#[tokio::test(flavor = "multi_thread", worker_threads = 5)] #[tokio::test(flavor = "multi_thread", worker_threads = 5)]
async fn kcl_test_example_import0() { async fn kcl_test_example_import0() -> miette::Result<()> {
let code = "This is code.\nIt does other shit.\nimport"; let code = "This is code.\nIt does other shit.\nimport";
let result = crate::test_server::execute_and_snapshot( let result = match crate::test_server::execute_and_snapshot(
code, code,
crate::settings::types::UnitLength::Mm, crate::settings::types::UnitLength::Mm,
None, None,
) )
.await .await
.unwrap(); {
Err(crate::errors::ExecError::Kcl(e)) => {
return Err(miette::Report::new(crate::errors::Report {
error: e,
filename: format!("{}{}", "import", 0usize),
kcl_source: "This is code.\nIt does other shit.\nimport".to_string(),
}));
}
Err(other_err) => panic!("{}", other_err),
Ok(img) => img,
};
twenty_twenty::assert_image( twenty_twenty::assert_image(
&format!("tests/outputs/{}.png", "serial_test_example_import0"), &format!("tests/outputs/{}.png", "serial_test_example_import0"),
&result, &result,
0.99, 0.99,
); );
Ok(())
} }
} }

View File

@ -1,7 +1,7 @@
#[cfg(test)] #[cfg(test)]
mod test_examples_import { mod test_examples_import {
#[tokio::test(flavor = "multi_thread")] #[tokio::test(flavor = "multi_thread")]
async fn test_mock_example_import0() { async fn test_mock_example_import0() -> miette::Result<()> {
let program = let program =
crate::Program::parse_no_errs("This is code.\nIt does other shit.\nimport").unwrap(); crate::Program::parse_no_errs("This is code.\nIt does other shit.\nimport").unwrap();
let ctx = crate::ExecutorContext { let ctx = crate::ExecutorContext {
@ -15,26 +15,43 @@ mod test_examples_import {
settings: Default::default(), settings: Default::default(),
context_type: crate::execution::ContextType::Mock, context_type: crate::execution::ContextType::Mock,
}; };
ctx.run(program.into(), &mut crate::ExecState::new()) if let Err(e) = ctx.run(program.into(), &mut crate::ExecState::new()).await {
.await return Err(miette::Report::new(crate::errors::Report {
.unwrap(); error: e,
filename: format!("{}{}", "import", 0usize),
kcl_source: "This is code.\nIt does other shit.\nimport".to_string(),
}));
}
Ok(())
} }
#[tokio::test(flavor = "multi_thread", worker_threads = 5)] #[tokio::test(flavor = "multi_thread", worker_threads = 5)]
async fn kcl_test_example_import0() { async fn kcl_test_example_import0() -> miette::Result<()> {
let code = "This is code.\nIt does other shit.\nimport"; let code = "This is code.\nIt does other shit.\nimport";
let result = crate::test_server::execute_and_snapshot( let result = match crate::test_server::execute_and_snapshot(
code, code,
crate::settings::types::UnitLength::Mm, crate::settings::types::UnitLength::Mm,
None, None,
) )
.await .await
.unwrap(); {
Err(crate::errors::ExecError::Kcl(e)) => {
return Err(miette::Report::new(crate::errors::Report {
error: e,
filename: format!("{}{}", "import", 0usize),
kcl_source: "This is code.\nIt does other shit.\nimport".to_string(),
}));
}
Err(other_err) => panic!("{}", other_err),
Ok(img) => img,
};
twenty_twenty::assert_image( twenty_twenty::assert_image(
&format!("tests/outputs/{}.png", "serial_test_example_import0"), &format!("tests/outputs/{}.png", "serial_test_example_import0"),
&result, &result,
0.99, 0.99,
); );
Ok(())
} }
} }

View File

@ -1,7 +1,7 @@
#[cfg(test)] #[cfg(test)]
mod test_examples_show { mod test_examples_show {
#[tokio::test(flavor = "multi_thread")] #[tokio::test(flavor = "multi_thread")]
async fn test_mock_example_show0() { async fn test_mock_example_show0() -> miette::Result<()> {
let program = let program =
crate::Program::parse_no_errs("This is code.\nIt does other shit.\nshow").unwrap(); crate::Program::parse_no_errs("This is code.\nIt does other shit.\nshow").unwrap();
let ctx = crate::ExecutorContext { let ctx = crate::ExecutorContext {
@ -15,26 +15,43 @@ mod test_examples_show {
settings: Default::default(), settings: Default::default(),
context_type: crate::execution::ContextType::Mock, context_type: crate::execution::ContextType::Mock,
}; };
ctx.run(program.into(), &mut crate::ExecState::new()) if let Err(e) = ctx.run(program.into(), &mut crate::ExecState::new()).await {
.await return Err(miette::Report::new(crate::errors::Report {
.unwrap(); error: e,
filename: format!("{}{}", "show", 0usize),
kcl_source: "This is code.\nIt does other shit.\nshow".to_string(),
}));
}
Ok(())
} }
#[tokio::test(flavor = "multi_thread", worker_threads = 5)] #[tokio::test(flavor = "multi_thread", worker_threads = 5)]
async fn kcl_test_example_show0() { async fn kcl_test_example_show0() -> miette::Result<()> {
let code = "This is code.\nIt does other shit.\nshow"; let code = "This is code.\nIt does other shit.\nshow";
let result = crate::test_server::execute_and_snapshot( let result = match crate::test_server::execute_and_snapshot(
code, code,
crate::settings::types::UnitLength::Mm, crate::settings::types::UnitLength::Mm,
None, None,
) )
.await .await
.unwrap(); {
Err(crate::errors::ExecError::Kcl(e)) => {
return Err(miette::Report::new(crate::errors::Report {
error: e,
filename: format!("{}{}", "show", 0usize),
kcl_source: "This is code.\nIt does other shit.\nshow".to_string(),
}));
}
Err(other_err) => panic!("{}", other_err),
Ok(img) => img,
};
twenty_twenty::assert_image( twenty_twenty::assert_image(
&format!("tests/outputs/{}.png", "serial_test_example_show0"), &format!("tests/outputs/{}.png", "serial_test_example_show0"),
&result, &result,
0.99, 0.99,
); );
Ok(())
} }
} }

View File

@ -1,7 +1,7 @@
#[cfg(test)] #[cfg(test)]
mod test_examples_some_function { mod test_examples_some_function {
#[tokio::test(flavor = "multi_thread")] #[tokio::test(flavor = "multi_thread")]
async fn test_mock_example_some_function0() { async fn test_mock_example_some_function0() -> miette::Result<()> {
let program = crate::Program::parse_no_errs("someFunction()").unwrap(); let program = crate::Program::parse_no_errs("someFunction()").unwrap();
let ctx = crate::ExecutorContext { let ctx = crate::ExecutorContext {
engine: std::sync::Arc::new(Box::new( engine: std::sync::Arc::new(Box::new(
@ -14,26 +14,43 @@ mod test_examples_some_function {
settings: Default::default(), settings: Default::default(),
context_type: crate::execution::ContextType::Mock, context_type: crate::execution::ContextType::Mock,
}; };
ctx.run(program.into(), &mut crate::ExecState::new()) if let Err(e) = ctx.run(program.into(), &mut crate::ExecState::new()).await {
.await return Err(miette::Report::new(crate::errors::Report {
.unwrap(); error: e,
filename: format!("{}{}", "some_function", 0usize),
kcl_source: "someFunction()".to_string(),
}));
}
Ok(())
} }
#[tokio::test(flavor = "multi_thread", worker_threads = 5)] #[tokio::test(flavor = "multi_thread", worker_threads = 5)]
async fn kcl_test_example_some_function0() { async fn kcl_test_example_some_function0() -> miette::Result<()> {
let code = "someFunction()"; let code = "someFunction()";
let result = crate::test_server::execute_and_snapshot( let result = match crate::test_server::execute_and_snapshot(
code, code,
crate::settings::types::UnitLength::Mm, crate::settings::types::UnitLength::Mm,
None, None,
) )
.await .await
.unwrap(); {
Err(crate::errors::ExecError::Kcl(e)) => {
return Err(miette::Report::new(crate::errors::Report {
error: e,
filename: format!("{}{}", "some_function", 0usize),
kcl_source: "someFunction()".to_string(),
}));
}
Err(other_err) => panic!("{}", other_err),
Ok(img) => img,
};
twenty_twenty::assert_image( twenty_twenty::assert_image(
&format!("tests/outputs/{}.png", "serial_test_example_some_function0"), &format!("tests/outputs/{}.png", "serial_test_example_some_function0"),
&result, &result,
0.99, 0.99,
); );
Ok(())
} }
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 122 KiB

After

Width:  |  Height:  |  Size: 132 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 122 KiB

After

Width:  |  Height:  |  Size: 132 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 120 KiB

After

Width:  |  Height:  |  Size: 129 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 122 KiB

After

Width:  |  Height:  |  Size: 140 KiB