chore: update example tests, test on ci (#735)

* chore: update example tests, test on ci

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>

* fix: mark *.golden as binary

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>

---------

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
Carlos Alexandro Becker 2023-06-09 09:17:15 -03:00 committed by GitHub
parent f3e1b67605
commit b2d2ac6504
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 5 deletions

1
.gitattributes vendored Normal file
View File

@ -0,0 +1 @@
*.golden -text

View File

@ -32,6 +32,10 @@ jobs:
run: go build -v ./...
working-directory: ./examples
- name: Test examples
run: go test -v ./...
working-directory: ./examples
- name: Build tutorials
run: go build -v ./...
working-directory: ./tutorials

View File

@ -8,9 +8,15 @@ import (
"time"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/x/exp/teatest"
"github.com/muesli/termenv"
)
func init() {
lipgloss.SetColorProfile(termenv.Ascii)
}
func TestApp(t *testing.T) {
m := model(10)
tm := teatest.NewTestModel(
@ -34,13 +40,13 @@ func TestApp(t *testing.T) {
t.Fatal(err)
}
out := readBts(t, tm.FinalOutput())
out := readBts(t, tm.FinalOutput(t))
if !regexp.MustCompile(`This program will exit in \d+ seconds`).Match(out) {
t.Fatalf("output does not match the given regular expression: %s", string(out))
}
teatest.RequireEqualOutput(t, out)
if tm.FinalModel().(model) != 9 {
if tm.FinalModel(t).(model) != 9 {
t.Errorf("expected model to be 10, was %d", m)
}
}
@ -71,7 +77,7 @@ func TestAppInteractive(t *testing.T) {
t.Fatal(err)
}
if tm.FinalModel().(model) != 7 {
if tm.FinalModel(t).(model) != 7 {
t.Errorf("expected model to be 7, was %d", m)
}
}

View File

@ -1,3 +1,3 @@
[?25lHi. This program will exit in 10 seconds. To quit sooner press any key
Hi. This program will exit in 9 seconds. To quit sooner press any key.
[?25lHi. This program will exit in 10 seconds. To quit sooner press any key
Hi. This program will exit in 9 seconds. To quit sooner press any key.
[?25h[?1002l[?1003l