Skip to content

Commit

Permalink
chore(core): load version data from node.js
Browse files Browse the repository at this point in the history
Fixes: #10183
  • Loading branch information
srl295 committed May 9, 2024
1 parent 38681f0 commit 5103a48
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 10 deletions.
15 changes: 12 additions & 3 deletions core/tests/unit/ldml/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ if node.found()
subdir('invalid-keyboards')
endif


# Build ldml test executable

if cpp_compiler.get_id() == 'emscripten'
Expand All @@ -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',
Expand Down Expand Up @@ -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)
Expand Down
46 changes: 39 additions & 7 deletions core/tests/unit/ldml/test_unicode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,52 +7,77 @@
*/

#include <string>
#include <fstream>
#include <iostream>

#include "keyman_core.h"

#include "path.hpp"
#include "action.hpp"

#include <test_assert.h>
#include "../emscripten_filesystem.h"

#include "core_icu.h"
#include <unicode/uversion.h>
#include <unicode/uchar.h>
#include "json.hpp"

//-------------------------------------------------------------------------------------
// Unicode version tests
//-------------------------------------------------------------------------------------

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;
std::cout << "Unicode: " << U_UNICODE_VERSION << std::endl;

}

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;
}

//-------------------------------------------------------------------------------------
// Launcher
//-------------------------------------------------------------------------------------

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
Expand All @@ -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;
}

0 comments on commit 5103a48

Please sign in to comment.