A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
fix(tests): C++20 says u8"" is not a char string, and a gate now says so first
esenginee2a0b2dcdd12
diff --git a/package.json b/package.jsonindex 99a4fcc5d..04900644b 100644--- a/package.json+++ b/package.json@@ -17,7 +17,7 @@"emsdk:setup": "node build-tools/toolchain/setup-emsdk.js","asset-meta": "node tools/asset-meta.js","migrate-asset-refs": "node tools/migrate-asset-refs.js",- "verify": "pnpm --filter ./sdk exec tsc --noEmit && pnpm --filter @estella/editor exec tsc --noEmit && node tools/api-surface.mjs --check && node tools/check-cycles.mjs && node tools/check-layers.mjs && node tools/check-project-settings.mjs && node tools/check-workflows.mjs && node tools/check-tool-calls.mjs && node tools/check-inspector-door.mjs && node tools/check-dirty-source.mjs && node tools/check-path-sandbox.mjs && node tools/check-key-codes.mjs && node tools/check-comment-style.mjs && node tools/check-release-metadata.mjs && node tools/component-reference.mjs --check",+ "verify": "pnpm --filter ./sdk exec tsc --noEmit && pnpm --filter @estella/editor exec tsc --noEmit && node tools/api-surface.mjs --check && node tools/check-cycles.mjs && node tools/check-layers.mjs && node tools/check-project-settings.mjs && node tools/check-workflows.mjs && node tools/check-tool-calls.mjs && node tools/check-inspector-door.mjs && node tools/check-dirty-source.mjs && node tools/check-path-sandbox.mjs && node tools/check-key-codes.mjs && node tools/check-comment-style.mjs && node tools/check-cpp-tests.mjs && node tools/check-release-metadata.mjs && node tools/component-reference.mjs --check","perf": "node tools/perf-guard.mjs --check","scale": "node tools/perf-budget.mjs","stress-project": "node tools/stress-project.mjs",diff --git a/tests/text/test_text_edit.cpp b/tests/text/test_text_edit.cppindex af08c7057..5be225398 100644--- a/tests/text/test_text_edit.cpp+++ b/tests/text/test_text_edit.cpp@@ -41,12 +41,12 @@ std::string shown(const TextEditModel& m) {} // namespaceTEST_CASE("UTF-8 and UTF-16 round trip, including what is outside the BMP") {- for (const char* s : {"", "abc", u8"héllo", u8"日本語", u8"🎮 game", u8"a🎮b"}) {+ for (const char* s : {"", "abc", "héllo", "日本語", "🎮 game", "a🎮b"}) {CHECK(utf16ToUtf8(utf8ToUtf16(s)) == std::string(s));}// An emoji is ONE character and TWO code units — which is exactly the case// every index rule below has to get right.- CHECK(utf8ToUtf16(u8"🎮").size() == 2);+ CHECK(utf8ToUtf16("🎮").size() == 2);CHECK(utf8ToUtf16("abc").size() == 3);}@@ -56,7 +56,7 @@ TEST_CASE("malformed input is replaced, not dropped") {CHECK(utf8ToUtf16("a\x80\x62").size() == 3); // a stray continuation bytestd::u16string lone;lone.push_back(0xD800);- CHECK(utf16ToUtf8(lone) == u8"�");+ CHECK(utf16ToUtf8(lone) == "�");}TEST_CASE("typing replaces the selection") {@@ -66,7 +66,7 @@ TEST_CASE("typing replaces the selection") {}TEST_CASE("backspace deletes a character, not a code unit") {- TextEditModel m = field(u8"a🎮");+ TextEditModel m = field("a🎮");m.moveToEnd(false);m.backspace();// Deleting one code unit would leave half a surrogate pair — a character no@@ -75,7 +75,7 @@ TEST_CASE("backspace deletes a character, not a code unit") {}TEST_CASE("delete forward mirrors it") {- TextEditModel m = field(u8"🎮b", 0);+ TextEditModel m = field("🎮b", 0);m.deleteForward();CHECK(shown(m) == "b|0,0");}@@ -118,27 +118,27 @@ TEST_CASE("word movement crosses one word however it is punctuated") {TEST_CASE("an IME's preedit is shown but not committed") {TextEditModel m = field("ab", 1);- m.setComposition(u8"に");+ m.setComposition("に");// Inside the value, which is the seam's contract: a field that hid it would// show nothing at all while a CJK user types.- CHECK(m.value() == u8"aにb");+ CHECK(m.value() == "aにb");CHECK(m.composing());// The caret sits AFTER the preedit — where the typing is going.CHECK(m.selectionStart() == 2);CHECK(m.selectionEnd() == 2);// The IME rewrites its preedit in place; the anchor must not walk.- m.setComposition(u8"にほん");- CHECK(m.value() == std::string(u8"aにほんb"));+ m.setComposition("にほん");+ CHECK(m.value() == "aにほんb");CHECK(m.selectionStart() == 4);- m.insert(u8"日本");- CHECK(shown(m) == std::string(u8"a日本b") + "|3,3");+ m.insert("日本");+ CHECK(shown(m) == "a日本b|3,3");CHECK_FALSE(m.composing());}TEST_CASE("escape from a composition drops the preedit, not the text") {TextEditModel m = field("ab", 1);- m.setComposition(u8"に");+ m.setComposition("に");m.backspace();CHECK(shown(m) == "ab|1,1");CHECK_FALSE(m.composing());@@ -147,28 +147,28 @@ TEST_CASE("escape from a composition drops the preedit, not the text") {TEST_CASE("maxLength truncates the insertion, never mid-character") {TextEditModel m;m.focus("ab", 2, 2, false, 4, false);- m.insert(u8"c🎮d");+ m.insert("c🎮d");// Two code units of room: 'c' takes one, the emoji needs two, so neither the// emoji nor 'd' fits — and half an emoji must not be what fits instead.CHECK(m.value() == "abc");// And with one unit of room the emoji is refused rather than halved.TextEditModel n;n.focus("abc", 3, 3, false, 4, false);- n.insert(u8"🎮");+ n.insert("🎮");CHECK(n.value() == "abc");}TEST_CASE("select all, copy and cut work on characters") {- TextEditModel m = field(u8"a🎮b");+ TextEditModel m = field("a🎮b");m.selectAll();- CHECK(m.selectedText() == u8"a🎮b");+ CHECK(m.selectedText() == "a🎮b");m.deleteSelection();CHECK(shown(m) == "|0,0");}TEST_CASE("the app's own write replaces everything, including a preedit") {TextEditModel m = field("abc", 1);- m.setComposition(u8"に");+ m.setComposition("に");m.write("xyz", 3, 3);CHECK(shown(m) == "xyz|3,3");CHECK_FALSE(m.composing());diff --git a/tools/check-cpp-tests.mjs b/tools/check-cpp-tests.mjsnew file mode 100644index 000000000..23d8132a4--- /dev/null+++ b/tools/check-cpp-tests.mjs@@ -0,0 +1,82 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file check-cpp-tests.mjs — the C++ harnesses still compile and link.+ *+ * They are built with emscripten in CI, which no local gate can run, so a break+ * in them passed every check a push goes through and only turned up in a job+ * nobody was watching. `test_batch_builder` was red on every push for fourteen+ * hours that way: a hand-listed source set stopped naming everything the units+ * in it needed, and the message was an undefined symbol about materials on work+ * about achievements.+ *+ * The harnesses that do not link the engine build NATIVELY — that is how that+ * break was diagnosed in one minute after fourteen hours — so this configures a+ * plain cmake tree and builds them. It cannot cover the ones that link+ * `esengine` (the engine needs emscripten's headers); those stay CI's to judge,+ * and this says which ones it skipped rather than implying it checked them.+ *+ * Skips itself, loudly, where there is no cmake or no compiler: it is a+ * shift-left convenience, not a claim about the machine it did not run on.+ */+import { execFileSync, spawnSync } from 'node:child_process';+import { existsSync, mkdirSync, readFileSync } from 'node:fs';+import path from 'node:path';+import { fileURLToPath } from 'node:url';++const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');+const BUILD = path.join(ROOT, 'build', 'cmake', 'native-tests');++/** The harness targets, read off the CI list so the two cannot drift. */+function harnessTargets() {+ const workflow = readFileSync(path.join(ROOT, '.github', 'workflows', 'build.yml'), 'utf8');+ const block = workflow.match(/CPP_TESTS:\s*>-\s*\n((?:\s{4}.*\n)+)/);+ if (!block) throw new Error('build.yml no longer declares CPP_TESTS — this gate reads it');+ return block[1].split(/\s+/).filter(Boolean);+}++/** Targets that link the engine library, which does not build off emscripten. */+function enginelinked() {+ const cmake = readFileSync(path.join(ROOT, 'tests', 'CMakeLists.txt'), 'utf8');+ return new Set([...cmake.matchAll(/target_link_libraries\((\w+)\s+PRIVATE\s+esengine\)/g)].map((m) => m[1]));+}++const has = (cmd) => spawnSync(cmd, ['--version'], { stdio: 'ignore' }).status === 0;+if (!has('cmake')) {+ console.log('check-cpp-tests: no cmake on this machine — skipped (CI still builds them).');+ process.exit(0);+}++const targets = harnessTargets();+const skip = enginelinked();+const buildable = targets.filter((t) => !skip.has(t));++mkdirSync(BUILD, { recursive: true });+try {+ execFileSync('cmake', ['-S', ROOT, '-B', BUILD, '-DES_BUILD_TESTS=ON', '-DCMAKE_BUILD_TYPE=Release'],+ { stdio: 'pipe' });+} catch (err) {+ console.log(`check-cpp-tests: cmake could not configure here — skipped.\n${err.stderr ?? ''}`);+ process.exit(0);+}++const built = [];+const absent = [];+for (const target of buildable) {+ const run = spawnSync('cmake', ['--build', BUILD, '-j', '8', '--target', target], { encoding: 'utf8' });+ const out = `${run.stdout ?? ''}${run.stderr ?? ''}`;+ if (run.status === 0) { built.push(target); continue; }+ // A target the native configure never produced is not a broken one: some are+ // declared behind an option this tree does not set. Saying which is the+ // difference between a gate and a green light.+ if (/No rule to make target|unknown target|does not exist/i.test(out)) { absent.push(target); continue; }+ console.error(`check-cpp-tests: ${target} does not build.\n`);+ console.error(out.split('\n').filter((l) => /error|Undefined|undefined symbol/i.test(l)).slice(0, 12).join('\n'));+ console.error(`\nReproduce: cmake -S . -B ${path.relative(ROOT, BUILD)} -DES_BUILD_TESTS=ON`+ + `\n cmake --build ${path.relative(ROOT, BUILD)} --target ${target}`);+ process.exit(1);+}++console.log(`check-cpp-tests: ${built.length} harness(es) build`+ + `${absent.length ? `; ${absent.length} not configured here (${absent.join(', ')})` : ''}`+ + `; ${skip.size} link the engine and are CI's to judge (${[...skip].join(', ')}).`);