From 305c1a25c56721e67a4c21c99b384b5fed918ae0 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 26 Mar 2025 21:56:52 +0530 Subject: [PATCH] More robust fetching of grapheme break test data in Go test --- .gitignore | 1 + kitty_tests/main.py | 4 +++- tools/wcswidth/char-props_test.go | 20 +++++--------------- 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index b3609e1a0..8870a3434 100644 --- a/.gitignore +++ b/.gitignore @@ -23,6 +23,7 @@ __pycache__/ /docs/_build/ /docs/generated/ /tools/simdstring/simdstring.test +/tools/wcswidth/GraphemeBreakTest.json /.mypy_cache /.ruff_cache .DS_Store diff --git a/kitty_tests/main.py b/kitty_tests/main.py index 986cd479f..afdeca092 100644 --- a/kitty_tests/main.py +++ b/kitty_tests/main.py @@ -10,7 +10,7 @@ import sys import time import unittest from collections.abc import Callable, Generator, Iterator, Sequence -from contextlib import contextmanager +from contextlib import contextmanager, suppress from functools import lru_cache from tempfile import TemporaryDirectory from threading import Thread @@ -184,6 +184,8 @@ def run_go(packages: set[str], names: str) -> GoProc: for name in names: cmd.extend(('-run', name)) cmd += go_pkg_args + with suppress(FileExistsError): + os.link('kitty_tests/GraphemeBreakTest.json', 'tools/wcswidth/GraphemeBreakTest.json') return GoProc(cmd) diff --git a/tools/wcswidth/char-props_test.go b/tools/wcswidth/char-props_test.go index f5321021e..7090eff03 100644 --- a/tools/wcswidth/char-props_test.go +++ b/tools/wcswidth/char-props_test.go @@ -3,17 +3,18 @@ package wcswidth import ( "encoding/json" "fmt" - "os/exec" "strings" "testing" "github.com/google/go-cmp/cmp" - - "kitty/tools/utils" + _ "embed" ) var _ = fmt.Print +//go:embed GraphemeBreakTest.json +var test_data []byte + type GraphemeBreakTest struct { Data []string `json:"data"` Comment string `json:"comment"` @@ -29,19 +30,8 @@ func TestSplitIntoGraphemes(t *testing.T) { t.Fatalf("Failed to split %#v into graphemes: %s", text, diff) } } - cmd := exec.Command(utils.KittyExe(), "+runpy", ` -from kitty.constants import read_kitty_resource -import sys -sys.stdout.buffer.write(read_kitty_resource("GraphemeBreakTest.json", "kitty_tests")) -sys.stdout.flush() -`) - var output []byte - var err error - if output, err = cmd.Output(); err != nil { - t.Fatalf("Getting GraphemeBreakTest.json failed with error: %s", err) - } tests := []GraphemeBreakTest{} - if err = json.Unmarshal(output, &tests); err != nil { + if err := json.Unmarshal(test_data, &tests); err != nil { t.Fatalf("Failed to parse GraphemeBreakTest JSON with error: %s", err) } for i, x := range tests {