diff --git a/core/tests/unit/ldml/meson.build b/core/tests/unit/ldml/meson.build index 79d7e938aca..6a938ca8f29 100644 --- a/core/tests/unit/ldml/meson.build +++ b/core/tests/unit/ldml/meson.build @@ -35,7 +35,6 @@ if node.found() subdir('invalid-keyboards') endif - # Build ldml test executable if cpp_compiler.get_id() == 'emscripten' @@ -49,6 +48,14 @@ else invalid_test_path = join_paths(meson.current_build_dir(),'invalid-keyboards') endif +# collect some data from node.js +node_versions = custom_target( + 'nodeversions.json', + command: [node, '-p', 'JSON.stringify(process.versions)'], + capture: true, # collect stdout from nodejs + output: ['nodeversions.json'], +) + ldml = executable('ldml', 'ldml.cpp', 'ldml_test_source.cpp', @@ -108,8 +115,10 @@ u = executable('test_unicode', 'test_unicode.cpp', include_directories: [inc, libsrc, '../../../../developer/src/ext/json'], link_args: links + tests_flags, dependencies: [icu_uc, icu_i18n], - objects: lib.extract_all_objects(recursive: false)) -test('test_unicode', u, suite: 'ldml') + objects: lib.extract_all_objects(recursive: false), + +) +test('test_unicode', u, suite: 'ldml', args: [node_versions]) # Run tests on all keyboards (`tests` defined in keyboards/meson.build) diff --git a/core/tests/unit/ldml/test_unicode.cpp b/core/tests/unit/ldml/test_unicode.cpp index 6a3ac1cce95..e86b3f749a6 100644 --- a/core/tests/unit/ldml/test_unicode.cpp +++ b/core/tests/unit/ldml/test_unicode.cpp @@ -7,6 +7,9 @@ */ #include +#include +#include + #include "keyman_core.h" #include "path.hpp" @@ -14,8 +17,11 @@ #include #include "../emscripten_filesystem.h" + +#include "core_icu.h" #include #include +#include "json.hpp" //------------------------------------------------------------------------------------- // Unicode version tests @@ -23,7 +29,17 @@ std::string arg_path; -void test_unicode_versions() { +nlohmann::json load_json(const km::core::path &jsonpath) { + std::cout << "== " << __FUNCTION__ << " " << jsonpath << std::endl; + std::ifstream json_file(jsonpath.native()); + if (!json_file) { + return -1; // no file + } + nlohmann::json data = nlohmann::json::parse(json_file); + return data; +} + +void test_unicode_versions(const nlohmann::json versions) { std::cout << "== " << __FUNCTION__ << std::endl; std::cout << "ICU: " << U_ICU_VERSION << std::endl; @@ -31,9 +47,16 @@ void test_unicode_versions() { } -void test_all() { +int test_all(const char *jsonpath) { std::cout << "= " << __FUNCTION__ << std::endl; - test_unicode_versions(); + + auto versions = load_json(km::core::path(jsonpath)); + + assert(!versions.empty()); + + test_unicode_versions(versions); + + return EXIT_SUCCESS; } //------------------------------------------------------------------------------------- @@ -41,18 +64,20 @@ void test_all() { //------------------------------------------------------------------------------------- constexpr const auto help_str = "\ -test_unicode [--color]\n\ +test_unicode [--color] nodeversions.json\n\ \n\ --color Force color output\n"; int error_args() { std::cerr << "test_unicode: Invalid arguments." << std::endl; std::cout << help_str; - return 1; + return EXIT_FAILURE; } int main(int argc, char *argv []) { - auto arg_color = argc > 1 && std::string(argv[1]) == "--color"; + int first_arg = 1; + auto arg_color = argc > first_arg && std::string(argv[first_arg]) == "--color"; + if (arg_color) first_arg++; console_color::enabled = console_color::isaterminal() || arg_color; // Get the path of the current executable @@ -68,5 +93,12 @@ int main(int argc, char *argv []) { arg_path = get_wasm_file_path(arg_path); #endif - test_all(); + if (argc <= first_arg) { + return error_args(); + } + auto jsonpath = argv[first_arg++]; + + int rc = test_all(jsonpath); + + return rc; }