From 0ddbd729a343483dfcfde8079e676698c8d01d93 Mon Sep 17 00:00:00 2001 From: Young-Flash Date: Thu, 12 Sep 2024 15:08:07 +0800 Subject: [PATCH] internal: prefixing some definition in test driver --- crates/moon/src/cli/generate_test_driver.rs | 16 +- .../tests/test_cases/cond_comp.in/moon.test | 4 +- crates/moon/tests/test_cases/mod.rs | 164 +++++++++--------- .../specify_source_dir_001.in/moon.test | 4 +- crates/moonbuild/src/gen/gen_runtest.rs | 5 +- crates/moonbuild/template/js_driver.js | 4 +- .../template/no_args_driver_template.mbt | 8 +- .../template/with_args_driver_template.mbt | 50 +++--- crates/moonrun/src/template/js_glue.js | 2 +- crates/moonutil/src/common.rs | 4 +- 10 files changed, 133 insertions(+), 128 deletions(-) diff --git a/crates/moon/src/cli/generate_test_driver.rs b/crates/moon/src/cli/generate_test_driver.rs index df1e9de0..b4920436 100644 --- a/crates/moon/src/cli/generate_test_driver.rs +++ b/crates/moon/src/cli/generate_test_driver.rs @@ -198,7 +198,9 @@ pub fn generate_test_driver( } fn generate_driver(data: &str, pkgname: &str, target_backend: Option) -> String { - let index = data.find("let with_args_tests =").unwrap_or(data.len()); + let index = data + .find("let moonbit_test_driver_internal_with_args_tests =") + .unwrap_or(data.len()); let no_args = &data[0..index]; let with_args = &data[index..]; @@ -239,20 +241,20 @@ fn generate_driver(data: &str, pkgname: &str, target_backend: Option String = "%error.to_string" -typealias TestDriver_No_Args_Map = @moonbitlang/core/builtin.Map[ +typealias Moonbit_Test_Driver_Internal_No_Args_Map = @moonbitlang/core/builtin.Map[ String, @moonbitlang/core/builtin.Map[ Int, @@ -10,12 +10,12 @@ typealias TestDriver_No_Args_Map = @moonbitlang/core/builtin.Map[ ], ] -let no_args_tests : TestDriver_No_Args_Map = { } // WILL BE REPLACED +let moonbit_test_driver_internal_no_args_tests : Moonbit_Test_Driver_Internal_No_Args_Map = { } // WILL BE REPLACED -pub fn execute(filename: MoonbitTestDriverInternalExternString, index: Int) -> Unit { +pub fn moonbit_test_driver_internal_execute(filename: MoonbitTestDriverInternalExternString, index: Int) -> Unit { let file_filter = moonbit_test_driver_internal_get_file_name(filename) let index_filter = index - let filtered_test = match no_args_tests.get(file_filter) { + let filtered_test = match moonbit_test_driver_internal_no_args_tests.get(file_filter) { Some(index_func_map) => { index_func_map.get(index_filter) } diff --git a/crates/moonbuild/template/with_args_driver_template.mbt b/crates/moonbuild/template/with_args_driver_template.mbt index c2c3b26e..a46f4acb 100644 --- a/crates/moonbuild/template/with_args_driver_template.mbt +++ b/crates/moonbuild/template/with_args_driver_template.mbt @@ -2,54 +2,54 @@ fn moonbit_test_driver_internal_error_to_string(x : Error) -> String = "%error.to_string" -typealias TestDriver_No_Args_Function = () -> Unit!Error +typealias Moonbit_Test_Driver_Internal_No_Args_Function = () -> Unit!Error -typealias TestDriver_With_Args_Function = (@moonbitlang/core/test.T) -> Unit!Error +typealias Moonbit_Test_Driver_Internal_With_Args_Function = (@moonbitlang/core/test.T) -> Unit!Error -typealias TestDriver_No_Args_Map = @moonbitlang/core/builtin.Map[ +typealias Moonbit_Test_Driver_Internal_No_Args_Map = @moonbitlang/core/builtin.Map[ String, @moonbitlang/core/builtin.Map[ Int, - (TestDriver_No_Args_Function, @moonbitlang/core/builtin.Array[String]), + (Moonbit_Test_Driver_Internal_No_Args_Function, @moonbitlang/core/builtin.Array[String]), ], ] -typealias TestDriver_With_Args_Map = @moonbitlang/core/builtin.Map[ +typealias Moonbit_Test_Driver_Internal_TestDriver_With_Args_Map = @moonbitlang/core/builtin.Map[ String, @moonbitlang/core/builtin.Map[ Int, - (TestDriver_With_Args_Function, @moonbitlang/core/builtin.Array[String]), + (Moonbit_Test_Driver_Internal_With_Args_Function, @moonbitlang/core/builtin.Array[String]), ], ] -struct TestDriver__Meta { +struct Moonbit_Test_Driver_Internal_Meta { filename : String index : Int attrs : @moonbitlang/core/builtin.Array[String] } -enum TestDriver__F { - F0(TestDriver_No_Args_Function) - F1(TestDriver_With_Args_Function) +enum Moonbit_Test_Driver_Internal__F { + F0(Moonbit_Test_Driver_Internal_No_Args_Function) + F1(Moonbit_Test_Driver_Internal_With_Args_Function) } -struct TestDriver__TestCase { - f : TestDriver__F - meta : TestDriver__Meta +struct Moonbit_Test_Driver_Internal__TestCase { + f : Moonbit_Test_Driver_Internal__F + meta : Moonbit_Test_Driver_Internal_Meta } fn moonbit_test_driver_internal_apply_filter( - no_args_tests : TestDriver_No_Args_Map, - with_args_tests : TestDriver_With_Args_Map, + no_args_tests : Moonbit_Test_Driver_Internal_No_Args_Map, + with_args_tests : Moonbit_Test_Driver_Internal_TestDriver_With_Args_Map, file_filter : String, index_filter : Int -) -> Option[TestDriver__TestCase] { +) -> Option[Moonbit_Test_Driver_Internal__TestCase] { let no_args_filtered_test = match no_args_tests.get(file_filter) { Some(index_func_map) => { match index_func_map.get(index_filter) { Some(func_attrs_tuple) => { let k = { - f: TestDriver__F::F0(func_attrs_tuple.0), + f: Moonbit_Test_Driver_Internal__F::F0(func_attrs_tuple.0), meta: { filename: file_filter, index: index_filter, attrs: func_attrs_tuple.1 }, } Some(k) @@ -65,7 +65,7 @@ fn moonbit_test_driver_internal_apply_filter( match index_func_map.get(index_filter) { Some(func_attrs_tuple) => { let k = { - f: TestDriver__F::F1(func_attrs_tuple.0), + f: Moonbit_Test_Driver_Internal__F::F1(func_attrs_tuple.0), meta: { filename: file_filter, index: index_filter, attrs: func_attrs_tuple.1 }, } Some(k) @@ -82,15 +82,15 @@ fn moonbit_test_driver_internal_apply_filter( } } -let no_args_tests : TestDriver_No_Args_Map = { } // WILL BE REPLACED -let with_args_tests : TestDriver_With_Args_Map = { } // WILL BE REPLACED +let moonbit_test_driver_internal_no_args_tests : Moonbit_Test_Driver_Internal_No_Args_Map = { } // WILL BE REPLACED +let moonbit_test_driver_internal_with_args_tests : Moonbit_Test_Driver_Internal_TestDriver_With_Args_Map = { } // WILL BE REPLACED -pub fn execute(file_name: MoonbitTestDriverInternalExternString, index: Int) -> Unit { +pub fn moonbit_test_driver_internal_execute(file_name: MoonbitTestDriverInternalExternString, index: Int) -> Unit { let file_filter: String = moonbit_test_driver_internal_get_file_name(file_name) let index_filter : Int = index let filtered_test = moonbit_test_driver_internal_apply_filter( - no_args_tests, - with_args_tests, + moonbit_test_driver_internal_no_args_tests, + moonbit_test_driver_internal_with_args_tests, file_filter, index_filter ) @@ -109,8 +109,8 @@ pub fn execute(file_name: MoonbitTestDriverInternalExternString, index: Int) -> } try { let func = match item.f { - TestDriver__F::F0(f) => f - TestDriver__F::F1(f) => + Moonbit_Test_Driver_Internal__F::F0(f) => f + Moonbit_Test_Driver_Internal__F::F1(f) => fn() { let it : @moonbitlang/core/test.T = { name, diff --git a/crates/moonrun/src/template/js_glue.js b/crates/moonrun/src/template/js_glue.js index b557cf56..2851d524 100644 --- a/crates/moonrun/src/template/js_glue.js +++ b/crates/moonrun/src/template/js_glue.js @@ -39,7 +39,7 @@ try { if (test_mode) { for (param of testParams) { try { - instance.exports.execute(param[0], parseInt(param[1])); + instance.exports.moonbit_test_driver_internal_execute(param[0], parseInt(param[1])); } catch (e) { console.log("----- BEGIN MOON TEST RESULT -----") console.log(`{"package": "${packageName}", "filename": "${param[0]}", "index": "${param[1]}", "test_name": "${param[1]}", "message": "${e.stack.toString().replaceAll("\\", "\\\\").split('\n').join('\\n')}"}`); diff --git a/crates/moonutil/src/common.rs b/crates/moonutil/src/common.rs index 72048454..cd8254f2 100644 --- a/crates/moonutil/src/common.rs +++ b/crates/moonutil/src/common.rs @@ -794,7 +794,7 @@ impl MooncGenTestInfo { let mut result = String::new(); let default_name = "".to_string(); - result.push_str("let no_args_tests = {\n"); + result.push_str("let moonbit_test_driver_internal_no_args_tests = {\n"); for (file, tests) in &self.no_args_tests { result.push_str(&format!(" \"{}\": {{\n", file)); for test in tests { @@ -809,7 +809,7 @@ impl MooncGenTestInfo { } result.push_str("}\n\n"); - result.push_str("let with_args_tests = {\n"); + result.push_str("let moonbit_test_driver_internal_with_args_tests = {\n"); for (file, tests) in &self.with_args_tests { result.push_str(&format!(" \"{}\": {{\n", file)); for test in tests {