From b2d2ac6504e595df2a895e043f243cfca4cd3fed Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Fri, 9 Jun 2023 09:17:15 -0300 Subject: [PATCH] chore: update example tests, test on ci (#735) * chore: update example tests, test on ci Signed-off-by: Carlos Alexandro Becker * fix: mark *.golden as binary Signed-off-by: Carlos Alexandro Becker --------- Signed-off-by: Carlos Alexandro Becker --- .gitattributes | 1 + .github/workflows/build.yml | 4 ++++ examples/simple/main_test.go | 12 +++++++++--- examples/simple/testdata/TestApp.golden | 4 ++-- 4 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..6c929d4 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +*.golden -text diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cef3f37..2511296 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 diff --git a/examples/simple/main_test.go b/examples/simple/main_test.go index f736de7..a2e747f 100644 --- a/examples/simple/main_test.go +++ b/examples/simple/main_test.go @@ -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) } } diff --git a/examples/simple/testdata/TestApp.golden b/examples/simple/testdata/TestApp.golden index 0a973b2..b0b6c3d 100644 --- a/examples/simple/testdata/TestApp.golden +++ b/examples/simple/testdata/TestApp.golden @@ -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 \ No newline at end of file