Nicer way to include grapheme test data in Go tests

This commit is contained in:
Kovid Goyal 2025-03-27 03:20:27 +05:30
parent e76daa3736
commit 9e1601a9b5
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
5 changed files with 18 additions and 8 deletions

View file

@ -121,7 +121,7 @@ jobs:
run: which python && python -m mypy --version && ./test.py mypy run: which python && python -m mypy --version && ./test.py mypy
- name: Run go vet - name: Run go vet
run: cp kitty_tests/GraphemeBreakTest.json tools/wcswidth && go version && go vet ./... run: go version && go vet -tags testing ./...
- name: Build man page - name: Build man page
run: make FAIL_WARN=1 man run: make FAIL_WARN=1 man

1
.gitignore vendored
View file

@ -23,7 +23,6 @@ __pycache__/
/docs/_build/ /docs/_build/
/docs/generated/ /docs/generated/
/tools/simdstring/simdstring.test /tools/simdstring/simdstring.test
/tools/wcswidth/GraphemeBreakTest.json
/.mypy_cache /.mypy_cache
/.ruff_cache /.ruff_cache
.DS_Store .DS_Store

View file

@ -180,11 +180,10 @@ def wait(self, timeout=None) -> None:
def run_go(packages: set[str], names: str) -> GoProc: def run_go(packages: set[str], names: str) -> GoProc:
go = go_exe() go = go_exe()
go_pkg_args = [f'kitty/{x}' for x in packages] go_pkg_args = [f'kitty/{x}' for x in packages]
cmd = [go, 'test', '-v'] cmd = [go, 'test', '--tags', 'testing', '-v']
for name in names: for name in names:
cmd.extend(('-run', name)) cmd.extend(('-run', name))
cmd += go_pkg_args cmd += go_pkg_args
shutil.copy2('kitty_tests/GraphemeBreakTest.json', 'tools/wcswidth/GraphemeBreakTest.json')
return GoProc(cmd) return GoProc(cmd)

13
testing_exports.go Normal file
View file

@ -0,0 +1,13 @@
//go:build testing
package kitty
import (
_ "embed"
"fmt"
)
var _ = fmt.Print
//go:embed kitty_tests/GraphemeBreakTest.json
var GraphemeBreakTestData []byte

View file

@ -8,13 +8,12 @@ import (
_ "embed" _ "embed"
"github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp"
"kitty"
) )
var _ = fmt.Print var _ = fmt.Print
//go:embed GraphemeBreakTest.json
var test_data []byte
type GraphemeBreakTest struct { type GraphemeBreakTest struct {
Data []string `json:"data"` Data []string `json:"data"`
Comment string `json:"comment"` Comment string `json:"comment"`
@ -31,7 +30,7 @@ func TestSplitIntoGraphemes(t *testing.T) {
} }
} }
tests := []GraphemeBreakTest{} tests := []GraphemeBreakTest{}
if err := json.Unmarshal(test_data, &tests); err != nil { if err := json.Unmarshal(kitty.GraphemeBreakTestData, &tests); err != nil {
t.Fatalf("Failed to parse GraphemeBreakTest JSON with error: %s", err) t.Fatalf("Failed to parse GraphemeBreakTest JSON with error: %s", err)
} }
for i, x := range tests { for i, x := range tests {