Skip to content

Commit

Permalink
WIP update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
adamchalmers committed Dec 17, 2024
1 parent 5f6057f commit f240bbb
Show file tree
Hide file tree
Showing 33 changed files with 472 additions and 322 deletions.
26 changes: 22 additions & 4 deletions src/wasm-lib/derive-docs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ fn generate_code_block_test(fn_name: &str, code_block: &str, index: usize) -> pr

quote! {
#[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 ctx = crate::ExecutorContext {
engine: std::sync::Arc::new(Box::new(crate::engine::conn_mock::EngineConnection::new().await.unwrap())),
Expand All @@ -815,15 +815,33 @@ fn generate_code_block_test(fn_name: &str, code_block: &str, index: usize) -> pr
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)]
async fn #test_name() {
async fn #test_name() -> miette::Result<()> {
let code = #code_block;
// 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);
Ok(())
}
}
}
13 changes: 10 additions & 3 deletions src/wasm-lib/derive-docs/tests/args_with_lifetime.gen
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,16 @@ mod test_examples_someFn {
settings: Default::default(),
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 {
let report = crate::errors::Report {
error: e,
filename: format!("{}{}", "someFn", 0usize),
kcl_source: "someFn()".to_string(),
};
let report = miette::Report::new(report);
let report = format!("{:?}", report);
panic!("Miette: {report}");
}
}

#[tokio::test(flavor = "multi_thread", worker_threads = 5)]
Expand Down
13 changes: 10 additions & 3 deletions src/wasm-lib/derive-docs/tests/args_with_refs.gen
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,16 @@ mod test_examples_someFn {
settings: Default::default(),
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 {
let report = crate::errors::Report {
error: e,
filename: format!("{}{}", "someFn", 0usize),
kcl_source: "someFn()".to_string(),
};
let report = miette::Report::new(report);
let report = format!("{:?}", report);
panic!("Miette: {report}");
}
}

#[tokio::test(flavor = "multi_thread", worker_threads = 5)]
Expand Down
26 changes: 20 additions & 6 deletions src/wasm-lib/derive-docs/tests/array.gen
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,16 @@ mod test_examples_show {
settings: Default::default(),
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 {
let report = crate::errors::Report {
error: e,
filename: format!("{}{}", "show", 0usize),
kcl_source: "This is another code block.\nyes sirrr.\nshow".to_string(),
};
let report = miette::Report::new(report);
let report = format!("{:?}", report);
panic!("Miette: {report}");
}
}

#[tokio::test(flavor = "multi_thread", worker_threads = 5)]
Expand Down Expand Up @@ -52,9 +59,16 @@ mod test_examples_show {
settings: Default::default(),
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 {
let report = crate::errors::Report {
error: e,
filename: format!("{}{}", "show", 1usize),
kcl_source: "This is code.\nIt does other shit.\nshow".to_string(),
};
let report = miette::Report::new(report);
let report = format!("{:?}", report);
panic!("Miette: {report}");
}
}

#[tokio::test(flavor = "multi_thread", worker_threads = 5)]
Expand Down
13 changes: 10 additions & 3 deletions src/wasm-lib/derive-docs/tests/box.gen
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,16 @@ mod test_examples_show {
settings: Default::default(),
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 {
let report = crate::errors::Report {
error: e,
filename: format!("{}{}", "show", 0usize),
kcl_source: "This is code.\nIt does other shit.\nshow".to_string(),
};
let report = miette::Report::new(report);
let report = format!("{:?}", report);
panic!("Miette: {report}");
}
}

#[tokio::test(flavor = "multi_thread", worker_threads = 5)]
Expand Down
26 changes: 20 additions & 6 deletions src/wasm-lib/derive-docs/tests/doc_comment_with_code.gen
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,16 @@ mod test_examples_my_func {
settings: Default::default(),
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 {
let report = crate::errors::Report {
error: e,
filename: format!("{}{}", "my_func", 0usize),
kcl_source: "This is another code block.\nyes sirrr.\nmyFunc".to_string(),
};
let report = miette::Report::new(report);
let report = format!("{:?}", report);
panic!("Miette: {report}");
}
}

#[tokio::test(flavor = "multi_thread", worker_threads = 5)]
Expand Down Expand Up @@ -53,9 +60,16 @@ mod test_examples_my_func {
settings: Default::default(),
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 {
let report = crate::errors::Report {
error: e,
filename: format!("{}{}", "my_func", 1usize),
kcl_source: "This is code.\nIt does other shit.\nmyFunc".to_string(),
};
let report = miette::Report::new(report);
let report = format!("{:?}", report);
panic!("Miette: {report}");
}
}

#[tokio::test(flavor = "multi_thread", worker_threads = 5)]
Expand Down
26 changes: 20 additions & 6 deletions src/wasm-lib/derive-docs/tests/lineTo.gen
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,16 @@ mod test_examples_line_to {
settings: Default::default(),
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 {
let report = crate::errors::Report {
error: e,
filename: format!("{}{}", "line_to", 0usize),
kcl_source: "This is another code block.\nyes sirrr.\nlineTo".to_string(),
};
let report = miette::Report::new(report);
let report = format!("{:?}", report);
panic!("Miette: {report}");
}
}

#[tokio::test(flavor = "multi_thread", worker_threads = 5)]
Expand Down Expand Up @@ -53,9 +60,16 @@ mod test_examples_line_to {
settings: Default::default(),
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 {
let report = crate::errors::Report {
error: e,
filename: format!("{}{}", "line_to", 1usize),
kcl_source: "This is code.\nIt does other shit.\nlineTo".to_string(),
};
let report = miette::Report::new(report);
let report = format!("{:?}", report);
panic!("Miette: {report}");
}
}

#[tokio::test(flavor = "multi_thread", worker_threads = 5)]
Expand Down
26 changes: 20 additions & 6 deletions src/wasm-lib/derive-docs/tests/min.gen
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,16 @@ mod test_examples_min {
settings: Default::default(),
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 {
let report = crate::errors::Report {
error: e,
filename: format!("{}{}", "min", 0usize),
kcl_source: "This is another code block.\nyes sirrr.\nmin".to_string(),
};
let report = miette::Report::new(report);
let report = format!("{:?}", report);
panic!("Miette: {report}");
}
}

#[tokio::test(flavor = "multi_thread", worker_threads = 5)]
Expand Down Expand Up @@ -52,9 +59,16 @@ mod test_examples_min {
settings: Default::default(),
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 {
let report = crate::errors::Report {
error: e,
filename: format!("{}{}", "min", 1usize),
kcl_source: "This is code.\nIt does other shit.\nmin".to_string(),
};
let report = miette::Report::new(report);
let report = format!("{:?}", report);
panic!("Miette: {report}");
}
}

#[tokio::test(flavor = "multi_thread", worker_threads = 5)]
Expand Down
13 changes: 10 additions & 3 deletions src/wasm-lib/derive-docs/tests/option.gen
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,16 @@ mod test_examples_show {
settings: Default::default(),
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 {
let report = crate::errors::Report {
error: e,
filename: format!("{}{}", "show", 0usize),
kcl_source: "This is code.\nIt does other shit.\nshow".to_string(),
};
let report = miette::Report::new(report);
let report = format!("{:?}", report);
panic!("Miette: {report}");
}
}

#[tokio::test(flavor = "multi_thread", worker_threads = 5)]
Expand Down
13 changes: 10 additions & 3 deletions src/wasm-lib/derive-docs/tests/option_input_format.gen
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,16 @@ mod test_examples_import {
settings: Default::default(),
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 {
let report = crate::errors::Report {
error: e,
filename: format!("{}{}", "import", 0usize),
kcl_source: "This is code.\nIt does other shit.\nimport".to_string(),
};
let report = miette::Report::new(report);
let report = format!("{:?}", report);
panic!("Miette: {report}");
}
}

#[tokio::test(flavor = "multi_thread", worker_threads = 5)]
Expand Down
13 changes: 10 additions & 3 deletions src/wasm-lib/derive-docs/tests/return_vec_box_sketch.gen
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,16 @@ mod test_examples_import {
settings: Default::default(),
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 {
let report = crate::errors::Report {
error: e,
filename: format!("{}{}", "import", 0usize),
kcl_source: "This is code.\nIt does other shit.\nimport".to_string(),
};
let report = miette::Report::new(report);
let report = format!("{:?}", report);
panic!("Miette: {report}");
}
}

#[tokio::test(flavor = "multi_thread", worker_threads = 5)]
Expand Down
13 changes: 10 additions & 3 deletions src/wasm-lib/derive-docs/tests/return_vec_sketch.gen
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,16 @@ mod test_examples_import {
settings: Default::default(),
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 {
let report = crate::errors::Report {
error: e,
filename: format!("{}{}", "import", 0usize),
kcl_source: "This is code.\nIt does other shit.\nimport".to_string(),
};
let report = miette::Report::new(report);
let report = format!("{:?}", report);
panic!("Miette: {report}");
}
}

#[tokio::test(flavor = "multi_thread", worker_threads = 5)]
Expand Down
13 changes: 10 additions & 3 deletions src/wasm-lib/derive-docs/tests/show.gen
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,16 @@ mod test_examples_show {
settings: Default::default(),
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 {
let report = crate::errors::Report {
error: e,
filename: format!("{}{}", "show", 0usize),
kcl_source: "This is code.\nIt does other shit.\nshow".to_string(),
};
let report = miette::Report::new(report);
let report = format!("{:?}", report);
panic!("Miette: {report}");
}
}

#[tokio::test(flavor = "multi_thread", worker_threads = 5)]
Expand Down
13 changes: 10 additions & 3 deletions src/wasm-lib/derive-docs/tests/test_args_with_exec_state.gen
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,16 @@ mod test_examples_some_function {
settings: Default::default(),
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 {
let report = crate::errors::Report {
error: e,
filename: format!("{}{}", "some_function", 0usize),
kcl_source: "someFunction()".to_string(),
};
let report = miette::Report::new(report);
let report = format!("{:?}", report);
panic!("Miette: {report}");
}
}

#[tokio::test(flavor = "multi_thread", worker_threads = 5)]
Expand Down
2 changes: 1 addition & 1 deletion src/wasm-lib/kcl/src/std/appearance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ pub async fn appearance(_exec_state: &mut ExecState, args: Args) -> Result<KclVa
/// |> line(end = [center[0] + 10, center[1] - 10])
/// |> line(end = [center[0] + 10, center[1] + 10])
/// |> line(end = [center[0] - 10, center[1] + 10])
/// |> close(%)
/// |> close()
/// |> extrude(length = 10)
/// }
///
Expand Down
Loading

0 comments on commit f240bbb

Please sign in to comment.