diff --git a/src/wasm-lib/justfile b/src/wasm-lib/justfile new file mode 100644 index 000000000..d4367c4ee --- /dev/null +++ b/src/wasm-lib/justfile @@ -0,0 +1,4 @@ +# Create a new KCL snapshot test from `tests/inputs/my-test.kcl`. +new-test name: + echo "kcl_test!(\"{{name}}\", {{name}});" >> tests/executor/visuals.rs + TWENTY_TWENTY=overwrite cargo nextest run --test executor -E 'test(=visuals::{{name}})' diff --git a/src/wasm-lib/tests/executor/main.rs b/src/wasm-lib/tests/executor/main.rs index 173a1fc0c..e881a5559 100644 --- a/src/wasm-lib/tests/executor/main.rs +++ b/src/wasm-lib/tests/executor/main.rs @@ -5,6 +5,7 @@ use kcl_lib::{settings::types::UnitLength, test_server::execute_and_snapshot}; const MIN_DIFF: f64 = 0.99; mod no_visuals; +mod visuals; macro_rules! kcl_input { ($file:literal) => { @@ -16,87 +17,6 @@ fn assert_out(test_name: &str, result: &image::DynamicImage) { twenty_twenty::assert_image(format!("tests/executor/outputs/{test_name}.png"), result, MIN_DIFF); } -#[tokio::test(flavor = "multi_thread")] -async fn kcl_test_sketch_on_face() { - let code = kcl_input!("sketch_on_face"); - - let result = execute_and_snapshot(code, UnitLength::Mm).await.unwrap(); - assert_out("sketch_on_face", &result); -} - -#[tokio::test(flavor = "multi_thread")] -async fn kcl_test_riddle_small() { - let code = kcl_input!("riddle_small"); - let result = execute_and_snapshot(code, UnitLength::Mm).await.unwrap(); - assert_out("riddle_small", &result); -} - -#[tokio::test(flavor = "multi_thread")] -async fn kcl_test_tan_arc_x_line() { - let code = kcl_input!("tan_arc_x_line"); - let result = execute_and_snapshot(code, UnitLength::Mm).await.unwrap(); - assert_out("tan_arc_x_line", &result); -} - -#[tokio::test(flavor = "multi_thread")] -async fn kcl_test_lego() { - let code = kcl_input!("lego"); - let result = execute_and_snapshot(code, UnitLength::Mm).await.unwrap(); - assert_out("lego", &result); -} - -#[tokio::test(flavor = "multi_thread")] -async fn kcl_test_computed_var() { - let code = kcl_input!("computed_var"); - let result = execute_and_snapshot(code, UnitLength::Mm).await.unwrap(); - assert_out("computed_var", &result); -} - -#[tokio::test(flavor = "multi_thread")] -async fn kcl_test_pipe_as_arg() { - let code = kcl_input!("pipe_as_arg"); - let result = execute_and_snapshot(code, UnitLength::Mm).await.unwrap(); - assert_out("pipe_as_arg", &result); -} - -#[tokio::test(flavor = "multi_thread")] -async fn kcl_test_pentagon_fillet_sugar() { - let code = kcl_input!("pentagon_fillet_sugar"); - let result = execute_and_snapshot(code, UnitLength::Cm).await.unwrap(); - assert_out("pentagon_fillet_sugar", &result); -} - -#[tokio::test(flavor = "multi_thread")] -async fn kcl_test_sketch_on_face_start() { - let code = kcl_input!("sketch_on_face_start"); - - let result = execute_and_snapshot(code, UnitLength::Mm).await.unwrap(); - assert_out("sketch_on_face_start", &result); -} - -#[tokio::test(flavor = "multi_thread")] -async fn kcl_test_mike_stress_lines() { - let code = kcl_input!("mike_stress_test"); - let result = execute_and_snapshot(code, UnitLength::Mm).await.unwrap(); - assert_out("mike_stress_test", &result); -} - -#[tokio::test(flavor = "multi_thread")] -async fn kcl_test_sketch_on_face_end() { - let code = kcl_input!("sketch_on_face_end"); - - let result = execute_and_snapshot(code, UnitLength::Mm).await.unwrap(); - assert_out("sketch_on_face_end", &result); -} - -#[tokio::test(flavor = "multi_thread")] -async fn kcl_test_sketch_on_face_end_negative_extrude() { - let code = kcl_input!("sketch_on_face_end_negative_extrude"); - - let result = execute_and_snapshot(code, UnitLength::Mm).await.unwrap(); - assert_out("sketch_on_face_end_negative_extrude", &result); -} - #[tokio::test(flavor = "multi_thread")] async fn kcl_test_fillet_duplicate_tags() { let code = kcl_input!("fillet_duplicate_tags"); @@ -109,44 +29,6 @@ async fn kcl_test_fillet_duplicate_tags() { ); } -#[tokio::test(flavor = "multi_thread")] -async fn kcl_test_basic_fillet_cube_start() { - let code = kcl_input!("basic_fillet_cube_start"); - let result = execute_and_snapshot(code, UnitLength::Mm).await.unwrap(); - assert_out("basic_fillet_cube_start", &result); -} - -#[tokio::test(flavor = "multi_thread")] -async fn kcl_test_basic_fillet_cube_end() { - let code = kcl_input!("basic_fillet_cube_end"); - let result = execute_and_snapshot(code, UnitLength::Mm).await.unwrap(); - assert_out("basic_fillet_cube_end", &result); -} - -#[tokio::test(flavor = "multi_thread")] -async fn kcl_test_basic_fillet_cube_close_opposite() { - let code = kcl_input!("basic_fillet_cube_close_opposite"); - - let result = execute_and_snapshot(code, UnitLength::Mm).await.unwrap(); - assert_out("basic_fillet_cube_close_opposite", &result); -} - -#[tokio::test(flavor = "multi_thread")] -async fn kcl_test_basic_fillet_cube_next_adjacent() { - let code = kcl_input!("basic_fillet_cube_next_adjacent"); - - let result = execute_and_snapshot(code, UnitLength::Mm).await.unwrap(); - assert_out("basic_fillet_cube_next_adjacent", &result); -} - -#[tokio::test(flavor = "multi_thread")] -async fn kcl_test_basic_fillet_cube_previous_adjacent() { - let code = kcl_input!("basic_fillet_cube_previous_adjacent"); - - let result = execute_and_snapshot(code, UnitLength::Mm).await.unwrap(); - assert_out("basic_fillet_cube_previous_adjacent", &result); -} - #[tokio::test(flavor = "multi_thread")] async fn kcl_test_execute_with_function_sketch() { let code = kcl_input!("function_sketch"); diff --git a/src/wasm-lib/tests/executor/outputs/pentagon_fillet_sugar.png b/src/wasm-lib/tests/executor/outputs/pentagon_fillet_sugar.png index 88d7c61db..9d0f1cdc7 100644 Binary files a/src/wasm-lib/tests/executor/outputs/pentagon_fillet_sugar.png and b/src/wasm-lib/tests/executor/outputs/pentagon_fillet_sugar.png differ diff --git a/src/wasm-lib/tests/executor/visuals.rs b/src/wasm-lib/tests/executor/visuals.rs new file mode 100644 index 000000000..989fd83a1 --- /dev/null +++ b/src/wasm-lib/tests/executor/visuals.rs @@ -0,0 +1,48 @@ +macro_rules! kcl_input { + ($file:literal) => { + include_str!(concat!("inputs/", $file, ".kcl")) + }; +} + +macro_rules! kcl_test { + ($file:literal, $test_name:ident) => { + #[tokio::test(flavor = "multi_thread")] + async fn $test_name() { + let code = kcl_input!($file); + + let result = super::execute_and_snapshot(code, kcl_lib::settings::types::UnitLength::Mm) + .await + .unwrap(); + super::assert_out($file, &result); + } + }; +} + +kcl_test!("sketch_on_face", kcl_test_sketch_on_face); +kcl_test!("basic_fillet_cube_start", kcl_test_basic_fillet_cube_start); +kcl_test!( + "basic_fillet_cube_next_adjacent", + kcl_test_basic_fillet_cube_next_adjacent +); +kcl_test!( + "basic_fillet_cube_previous_adjacent", + kcl_test_basic_fillet_cube_previous_adjacent +); +kcl_test!("basic_fillet_cube_end", kcl_test_basic_fillet_cube_end); +kcl_test!( + "basic_fillet_cube_close_opposite", + kcl_test_basic_fillet_cube_close_opposite +); +kcl_test!("sketch_on_face_end", kcl_test_sketch_on_face_end); +kcl_test!("sketch_on_face_start", kcl_test_sketch_on_face_start); +kcl_test!( + "sketch_on_face_end_negative_extrude", + kcl_test_sketch_on_face_end_negative_extrude +); +kcl_test!("mike_stress_test", kcl_test_mike_stress_test); +kcl_test!("pentagon_fillet_sugar", kcl_test_pentagon_fillet_sugar); +kcl_test!("pipe_as_arg", kcl_test_pipe_as_arg); +kcl_test!("computed_var", kcl_test_computed_var); +kcl_test!("lego", kcl_test_lego); +kcl_test!("riddle_small", kcl_test_riddle_small); +kcl_test!("tan_arc_x_line", kcl_test_tan_arc_x_line);