|
|
|
@ -8,7 +8,6 @@ import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"io/ioutil"
|
|
|
|
|
"os"
|
|
|
|
|
"path/filepath"
|
|
|
|
|
"strings"
|
|
|
|
|
"testing"
|
|
|
|
|
"unicode"
|
|
|
|
@ -56,19 +55,8 @@ func (f *filchTest) close(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func genFilePrefix(t *testing.T) (dir, prefix string) {
|
|
|
|
|
t.Helper()
|
|
|
|
|
dir, err := ioutil.TempDir("", "filch")
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
return dir, filepath.Join(dir, "ringbuffer-")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestQueue(t *testing.T) {
|
|
|
|
|
td, filePrefix := genFilePrefix(t)
|
|
|
|
|
defer os.RemoveAll(td)
|
|
|
|
|
|
|
|
|
|
filePrefix := t.TempDir()
|
|
|
|
|
f := newFilchTest(t, filePrefix, Options{ReplaceStderr: false})
|
|
|
|
|
|
|
|
|
|
f.readEOF(t)
|
|
|
|
@ -90,8 +78,7 @@ func TestQueue(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
func TestRecover(t *testing.T) {
|
|
|
|
|
t.Run("empty", func(t *testing.T) {
|
|
|
|
|
td, filePrefix := genFilePrefix(t)
|
|
|
|
|
defer os.RemoveAll(td)
|
|
|
|
|
filePrefix := t.TempDir()
|
|
|
|
|
f := newFilchTest(t, filePrefix, Options{ReplaceStderr: false})
|
|
|
|
|
f.write(t, "hello")
|
|
|
|
|
f.read(t, "hello")
|
|
|
|
@ -104,8 +91,7 @@ func TestRecover(t *testing.T) {
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run("cur", func(t *testing.T) {
|
|
|
|
|
td, filePrefix := genFilePrefix(t)
|
|
|
|
|
defer os.RemoveAll(td)
|
|
|
|
|
filePrefix := t.TempDir()
|
|
|
|
|
f := newFilchTest(t, filePrefix, Options{ReplaceStderr: false})
|
|
|
|
|
f.write(t, "hello")
|
|
|
|
|
f.close(t)
|
|
|
|
@ -123,8 +109,7 @@ func TestRecover(t *testing.T) {
|
|
|
|
|
filch_test.go:129: r.ReadLine()="hello", want "world"
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
td, filePrefix := genFilePrefix(t)
|
|
|
|
|
defer os.RemoveAll(td)
|
|
|
|
|
filePrefix := t.TempDir()
|
|
|
|
|
f := newFilchTest(t, filePrefix, Options{ReplaceStderr: false})
|
|
|
|
|
f.write(t, "hello")
|
|
|
|
|
f.read(t, "hello")
|
|
|
|
@ -155,8 +140,7 @@ func TestFilchStderr(t *testing.T) {
|
|
|
|
|
stderrFD = 2
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
td, filePrefix := genFilePrefix(t)
|
|
|
|
|
defer os.RemoveAll(td)
|
|
|
|
|
filePrefix := t.TempDir()
|
|
|
|
|
f := newFilchTest(t, filePrefix, Options{ReplaceStderr: true})
|
|
|
|
|
f.write(t, "hello")
|
|
|
|
|
if _, err := fmt.Fprintf(pipeW, "filch\n"); err != nil {
|
|
|
|
|