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
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
- 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
run: make FAIL_WARN=1 man

1
.gitignore vendored
View File

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

View File

@@ -180,11 +180,10 @@ class GoProc(Thread):
def run_go(packages: set[str], names: str) -> GoProc:
go = go_exe()
go_pkg_args = [f'kitty/{x}' for x in packages]
cmd = [go, 'test', '-v']
cmd = [go, 'test', '--tags', 'testing', '-v']
for name in names:
cmd.extend(('-run', name))
cmd += go_pkg_args
shutil.copy2('kitty_tests/GraphemeBreakTest.json', 'tools/wcswidth/GraphemeBreakTest.json')
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"
"github.com/google/go-cmp/cmp"
"kitty"
)
var _ = fmt.Print
//go:embed GraphemeBreakTest.json
var test_data []byte
type GraphemeBreakTest struct {
Data []string `json:"data"`
Comment string `json:"comment"`
@@ -31,7 +30,7 @@ func TestSplitIntoGraphemes(t *testing.T) {
}
}
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)
}
for i, x := range tests {