Move tests into simulation (#4487)

Replace wasm-lib integration tests with KCL simulation tests.
This commit is contained in:
Adam Chalmers
2024-11-18 16:20:32 -06:00
committed by GitHub
parent 79e06b3a00
commit 34f019305b
207 changed files with 360969 additions and 233 deletions

View File

@ -7,9 +7,6 @@ use kcl_lib::{
/// i.e. how different the current model snapshot can be from the previous saved one.
const MIN_DIFF: f64 = 0.99;
mod no_visuals;
mod visuals;
macro_rules! kcl_input {
($file:literal) => {
include_str!(concat!("inputs/", $file, ".kcl"))

View File

@ -1,142 +0,0 @@
use kcl_lib::{
ast::types::{ModuleId, Node, Program},
errors::KclError,
executor::{ExecutorContext, IdGenerator},
parser,
};
macro_rules! gen_test_fail {
($file:ident, $expected:literal) => {
#[tokio::test]
async fn $file() {
let code = include_str!(concat!("inputs/no_visuals/", stringify!($file), ".kcl"));
let actual = run_fail(&code).await;
assert_eq!(actual.get_message(), $expected);
}
};
}
macro_rules! gen_test_parse_fail {
($file:ident, $expected:literal) => {
#[tokio::test]
async fn $file() {
let code = include_str!(concat!("inputs/no_visuals/", stringify!($file), ".kcl"));
let actual = run_parse_fail(&code).await;
assert_eq!(actual.get_message(), $expected);
}
};
}
async fn setup(program: &str) -> (ExecutorContext, Node<Program>, IdGenerator) {
let module_id = ModuleId::default();
let tokens = kcl_lib::token::lexer(program, module_id).unwrap();
let parser = kcl_lib::parser::Parser::new(tokens);
let program = parser.ast().unwrap();
let ctx = kcl_lib::executor::ExecutorContext {
engine: std::sync::Arc::new(Box::new(
kcl_lib::engine::conn_mock::EngineConnection::new().await.unwrap(),
)),
fs: std::sync::Arc::new(kcl_lib::fs::FileManager::new()),
stdlib: std::sync::Arc::new(kcl_lib::std::StdLib::new()),
settings: Default::default(),
context_type: kcl_lib::executor::ContextType::Mock,
};
(ctx, program, IdGenerator::default())
}
async fn run_fail(code: &str) -> KclError {
let (ctx, program, id_generator) = setup(code).await;
let Err(e) = ctx
.run(
&program,
None,
id_generator,
Some("tests/executor/inputs/no_visuals/".to_owned()),
)
.await
else {
panic!("Expected this KCL program to fail, but it (incorrectly) never threw an error.");
};
e
}
async fn run_parse_fail(code: &str) -> KclError {
let Err(e) = parser::top_level_parse(code) else {
panic!("Expected this KCL program to fail to parse, but it (incorrectly) never threw an error.");
};
e
}
gen_test_fail!(
invalid_index_str,
"semantic: Only integers >= 0 can be used as the index of an array, but you're using a string"
);
gen_test_fail!(
invalid_index_negative,
"semantic: '-1' is negative, so you can't index an array with it"
);
gen_test_fail!(
invalid_index_fractional,
"semantic: Only strings or ints (>= 0) can be properties/indexes"
);
gen_test_fail!(
invalid_member_object,
"semantic: Only arrays and objects can be indexed, but you're trying to index an integer"
);
gen_test_fail!(
invalid_member_object_prop,
"semantic: Only arrays and objects can be indexed, but you're trying to index a boolean (true/false value)"
);
gen_test_fail!(
non_string_key_of_object,
"semantic: Only strings can be used as the property of an object, but you're using a number"
);
gen_test_fail!(
array_index_oob,
"undefined value: The array doesn't have any item at index 0"
);
gen_test_fail!(
object_prop_not_found,
"undefined value: Property 'age' not found in object"
);
gen_test_fail!(
pipe_substitution_inside_function_called_from_pipeline,
"semantic: cannot use % outside a pipe expression"
);
// gen_test_fail!(
// if_else_no_expr,
// "syntax: blocks inside an if/else expression must end in an expression"
// );
gen_test_fail!(
comparisons_multiple,
"semantic: Expected a number, but found a boolean (true/false value)"
);
gen_test_fail!(
import_cycle1,
"import cycle: circular import of modules is not allowed: tests/executor/inputs/no_visuals/import_cycle2.kcl -> tests/executor/inputs/no_visuals/import_cycle3.kcl -> tests/executor/inputs/no_visuals/import_cycle1.kcl -> tests/executor/inputs/no_visuals/import_cycle2.kcl"
);
gen_test_fail!(
import_constant,
"semantic: Error loading imported file. Open it to view more details. export_constant.kcl: Only functions can be exported"
);
gen_test_fail!(
import_side_effect,
"semantic: Error loading imported file. Open it to view more details. export_side_effect.kcl: Cannot send modeling commands while importing. Wrap your code in a function if you want to import the file."
);
gen_test_parse_fail!(
import_from_other_directory,
"syntax: import path may only contain alphanumeric characters, underscore, hyphen, and period. Files in other directories are not yet supported."
);
// TODO: We'd like these tests.
// gen_test_fail!(
// import_in_if,
// "syntax: Can import only import at the top level"
// );
// gen_test_fail!(
// import_in_function,
// "syntax: Can import only import at the top level"
// );
gen_test_fail!(
array_elem_push_fail,
"undefined value: The array doesn't have any item at index 3"
);

View File

@ -1,74 +0,0 @@
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!("poop_chute", kcl_test_poop_chute);
kcl_test!("neg_xz_plane", kcl_test_neg_xz_plane);
kcl_test!("xz_plane", kcl_test_xz_plane);
kcl_test!(
"sketch_on_face_after_fillets_referencing_face",
kcl_test_sketch_on_face_after_fillets_referencing_face
);
kcl_test!("circular_pattern3d_a_pattern", kcl_test_circular_pattern3d_a_pattern);
kcl_test!("linear_pattern3d_a_pattern", kcl_test_linear_pattern3d_a_pattern);
kcl_test!("tangential_arc", kcl_test_tangential_arc);
kcl_test!(
"big_number_angle_to_match_length_x",
kcl_test_big_number_angle_to_match_length_x
);
kcl_test!(
"big_number_angle_to_match_length_y",
kcl_test_big_number_angle_to_match_length_y
);
kcl_test!("sketch_on_face_circle_tagged", kcl_test_sketch_on_face_circle_tagged);
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);
kcl_test!("fillet-and-shell", kcl_test_fillet_and_shell);
kcl_test!("sketch-on-chamfer-two-times", kcl_test_sketch_on_chamfer_two_times);
kcl_test!(
"sketch-on-chamfer-two-times-different-order",
kcl_test_sketch_on_chamfer_two_times_different_order
);