Skip to content

Commit 0072064

Browse files
committed
Try to test against Windows
Adds Windows to the test matrix. We'll see what breaks. For creack/pty, we need to use the currently-unmerged change for Windows support.
1 parent 0a472a3 commit 0072064

File tree

11 files changed

+44
-21
lines changed

11 files changed

+44
-21
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
kind: Added
2+
body: Windows support.
3+
time: 2024-09-07T16:16:36.18073-07:00

.gitattributes

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,10 @@
1+
# Don't magically change line endings by default,
2+
# but always use LF in test scripts.
3+
#
4+
# Ref:
5+
# - https://github.com/golang/go/blob/807e01db4840e25e4d98911b28a8fa54244b8dfa/.gitattributes
6+
# - https://github.com/rogpeppe/go-internal/pull/106
7+
* -text
8+
*.txt text eol=lf
9+
110
*.png filter=lfs diff=lfs merge=lfs -text

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
name: Test (${{ matrix.os}})
4141
strategy:
4242
matrix:
43-
os: ["ubuntu-latest"] # TODO: ["windows-latest"]
43+
os: ["ubuntu-latest", "windows-latest"]
4444
steps:
4545
- uses: actions/checkout@v4
4646
- name: Set up Go

.goreleaser.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ builds:
66
- CGO_ENABLED=0
77
main: .
88
binary: gs
9-
goos: [darwin, linux]
9+
goos: [darwin, linux, windows]
1010
goarch: [amd64, arm64, arm]
1111
goarm: [5, 6, 7]
1212
ldflags: '-s -w -X main._version={{.Version}}'
1313
ignore:
1414
- goos: darwin
1515
goarch: arm
16+
- goos: windows
17+
goarch: arm
1618
flags:
1719
- -trimpath
1820

Makefile

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@ MOCKGEN = bin/mockgen
1818
REQUIREDFIELD = bin/requiredfield
1919
TOOLS = $(MOCKGEN) $(GS)
2020

21-
# Non-test Go files.
22-
GO_SRC_FILES = $(shell find . \
23-
-path '*/.*' -prune -o \
24-
'(' -type f -a -name '*.go' -a -not -name '*_test.go' ')' -print)
25-
2621
.PHONY: all
2722
all: build lint test
2823

@@ -73,9 +68,12 @@ generate-lint: $(TOOLS)
7368
git diff --exit-code || \
7469
(echo "'go generate' changed files" && false)
7570

76-
$(GS): $(GO_SRC_FILES) go.mod
71+
$(GS): _always
7772
go install go.abhg.dev/gs
7873

74+
.PHONY: _always
75+
_always:
76+
7977
$(MOCKGEN): go.mod
8078
go install go.uber.org/mock/mockgen
8179

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require (
99
github.com/charmbracelet/bubbletea v1.1.1
1010
github.com/charmbracelet/lipgloss v0.13.0
1111
github.com/charmbracelet/log v0.4.0
12-
github.com/creack/pty v1.1.23
12+
github.com/creack/pty/v2 v2.0.0-20231028221118-e9c1f000f465
1313
github.com/dustin/go-humanize v1.0.1
1414
github.com/mattn/go-isatty v0.0.20
1515
github.com/rogpeppe/go-internal v1.12.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ github.com/charmbracelet/x/ansi v0.2.3 h1:VfFN0NUpcjBRd4DnKfRaIRo53KRgey/nhOoEqo
2424
github.com/charmbracelet/x/ansi v0.2.3/go.mod h1:dk73KoMTT5AX5BsX0KrqhsTqAnhZZoCBjs7dGWp4Ktw=
2525
github.com/charmbracelet/x/term v0.2.0 h1:cNB9Ot9q8I711MyZ7myUR5HFWL/lc3OpU8jZ4hwm0x0=
2626
github.com/charmbracelet/x/term v0.2.0/go.mod h1:GVxgxAbjUrmpvIINHIQnJJKpMlHiZ4cktEQCN6GWyF0=
27-
github.com/creack/pty v1.1.23 h1:4M6+isWdcStXEf15G/RbrMPOQj1dZ7HPZCGwE4kOeP0=
28-
github.com/creack/pty v1.1.23/go.mod h1:08sCNb52WyoAwi2QDyzUCTgcvVFhUzewun7wtTfvcwE=
27+
github.com/creack/pty/v2 v2.0.0-20231028221118-e9c1f000f465 h1:KQ+iWxxc2qYyfK3GGrjNJ73GvDAd9Ecz8pK4FpdtI6Y=
28+
github.com/creack/pty/v2 v2.0.0-20231028221118-e9c1f000f465/go.mod h1:zTYJ0iXAFhiKeguJdMR/LEecltLOG5Wz3lo1lIi0CLU=
2929
github.com/danieljoos/wincred v1.2.0 h1:ozqKHaLK0W/ii4KVbbvluM91W2H3Sh0BncbUNPS7jLE=
3030
github.com/danieljoos/wincred v1.2.0/go.mod h1:FzQLLMKBFdvu+osBrnFODiv32YGwCfx0SkRa/eYHgec=
3131
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=

internal/git/gittest/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ func DefaultConfig() Config {
1111
return Config{
1212
"init.defaultBranch": "main",
1313
"alias.graph": "log --graph --decorate --oneline",
14+
"core.autocrlf": "false",
1415
}
1516
}
1617

internal/termtest/with_term.go

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
"sync"
1818
"time"
1919

20-
"github.com/creack/pty"
20+
"github.com/creack/pty/v2"
2121
"github.com/vito/midterm"
2222
)
2323

@@ -68,6 +68,8 @@ func WithTerm() (exitCode int) {
6868
"capture a snapshot on exit with the given name")
6969

7070
log.SetFlags(0)
71+
log.SetOutput(os.Stderr)
72+
log.SetPrefix("term: ")
7173
flag.Parse()
7274

7375
args := flag.Args()
@@ -254,14 +256,14 @@ func WithTerm() (exitCode int) {
254256
type terminalEmulator struct {
255257
mu sync.Mutex
256258
cmd *exec.Cmd
257-
pty *os.File
259+
pty pty.Pty
258260
logf func(string, ...any)
259261

260262
term *midterm.Terminal
261263
}
262264

263265
func newVT100Emulator(
264-
f *os.File,
266+
f pty.Pty,
265267
cmd *exec.Cmd,
266268
rows, cols int,
267269
autoResize bool,
@@ -307,29 +309,36 @@ loop:
307309

308310
func (m *terminalEmulator) Close() error {
309311
_, writeErr := m.pty.Write([]byte{4}) // EOT
312+
if writeErr != nil {
313+
writeErr = fmt.Errorf("send EOT: %w", writeErr)
314+
}
310315

311316
waitErrc := make(chan error, 1)
312317
go func() {
313-
waitErrc <- m.cmd.Wait()
318+
err := m.cmd.Wait()
319+
if err != nil {
320+
err = fmt.Errorf("command %v: %w", m.cmd, err)
321+
}
322+
waitErrc <- err
314323
}()
315324

316325
var waitErr error
317326
select {
318327
case waitErr = <-waitErrc:
319328
// ok
320-
case <-time.After(3 * time.Second):
329+
case <-time.After(10 * time.Second):
321330
waitErr = fmt.Errorf("timeout waiting for %v", m.cmd)
322331
_ = m.cmd.Process.Kill()
323332
}
324333

325-
closeErr := m.pty.Close()
326-
327-
return errors.Join(waitErr, closeErr, writeErr)
334+
// On Windows, pty.Close may fail with invalid handle or access denied.
335+
// It's not really a problem, so we ignore the error.
336+
_ = m.pty.Close()
337+
return errors.Join(waitErr, writeErr)
328338
}
329339

330340
func (m *terminalEmulator) FeedKeys(s string) error {
331341
_, err := io.WriteString(m.pty, s)
332-
_ = m.pty.Sync()
333342
return err
334343
}
335344

testdata/script/auth_insecure_storage.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ gs auth login --forge=shamhub
4141
cmp stderr $WORK/golden/login-secure.stderr
4242

4343
-- golden/login.stderr --
44-
WRN Storing secrets in plain text at $WORK/home/.config/git-spice/secrets.json. Be careful!
44+
WRN Storing secrets in plain text at $WORK${/}home${/}.config${/}git-spice${/}secrets.json. Be careful!
4545
INF shamhub: successfully logged in
4646
-- golden/login-secure.stderr --
4747
INF shamhub: successfully logged in

0 commit comments

Comments
 (0)