Files
asciinema/terminal/terminal_test.go

47 lines
824 B
Go
Raw Permalink Normal View History

// +build !race
2014-08-03 20:25:14 +02:00
package terminal_test
import (
"testing"
2015-03-05 15:57:12 +01:00
"github.com/asciinema/asciinema/terminal"
2014-08-03 20:25:14 +02:00
)
type testWriter struct {
chunks []string
}
func (w *testWriter) Write(p []byte) (int, error) {
w.chunks = append(w.chunks, string(p))
return len(p), nil
}
2014-12-16 15:15:22 +01:00
func TestTerminal_Record(t *testing.T) {
2014-08-03 20:25:14 +02:00
command := `python -c "
import sys, time, os
2014-08-03 20:25:14 +02:00
sys.stdout.write('foo')
sys.stdout.flush()
time.sleep(0.01)
sys.stdout.write(os.environ['ASCIINEMA_REC'])
2014-08-03 20:25:14 +02:00
"`
stdoutCopy := &testWriter{}
err := terminal.NewTerminal().Record(command, stdoutCopy)
2014-08-03 20:25:14 +02:00
if err != nil {
t.Errorf("got error: %v", err)
return
}
chunk := stdoutCopy.chunks[0]
if chunk != "foo" {
t.Errorf("expected \"foo\", got \"%v\"", chunk)
}
chunk = stdoutCopy.chunks[1]
if chunk != "1" {
t.Errorf("expected \"1\", got \"%v\"", chunk)
2014-08-03 20:25:14 +02:00
}
}