-
Notifications
You must be signed in to change notification settings - Fork 1
/
program_test.go
45 lines (39 loc) · 958 Bytes
/
program_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package tapioca_test
import (
"bytes"
"fmt"
"strings"
"testing"
"time"
tea "github.com/charmbracelet/bubbletea"
"github.com/esdandreu/tapioca"
"github.com/esdandreu/tapioca/spinner"
"github.com/stretchr/testify/assert"
)
func ExampleProgram() {
program := tapioca.NewProgram(spinner.New()).GoRun()
defer program.QuitAndWait()
for i := 0; i < 10; i++ {
time.Sleep(1 * time.Millisecond)
fmt.Fprintln(program, i, "milliseconds")
}
}
func TestProgram(t *testing.T) {
var buffer bytes.Buffer
program := tapioca.NewProgram(spinner.New(), tea.WithOutput(&buffer))
// Start the program and log concurrently
n := 100
go func() {
for i := 0; i < n; i++ {
fmt.Fprintln(program, "DEBUG", i)
}
program.Quit()
}()
if _, err := program.Run(); err != nil {
t.Fatal("program.Run failed:", err)
}
// Assert output is expected
t.Log(buffer.String())
lines := strings.Split(buffer.String(), "\n")
assert.Equal(t, n+1, len(lines))
}