|
|
@ -14,22 +14,24 @@ import (
|
|
|
|
func TestEnterToContinue(t *testing.T) {
|
|
|
|
func TestEnterToContinue(t *testing.T) {
|
|
|
|
r, w, err := os.Pipe()
|
|
|
|
r, w, err := os.Pipe()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
ow := os.Stdout
|
|
|
|
|
|
|
|
os.Stdout = w
|
|
|
|
|
|
|
|
or := os.Stdin
|
|
|
|
|
|
|
|
os.Stdin = r
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
|
|
|
|
os.Stdin = or
|
|
|
|
|
|
|
|
os.Stdout = ow
|
|
|
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
wg.Add(2)
|
|
|
|
wg.Add(2)
|
|
|
|
go func() {
|
|
|
|
go func() {
|
|
|
|
defer wg.Done()
|
|
|
|
defer wg.Done()
|
|
|
|
ow := os.Stdout
|
|
|
|
|
|
|
|
os.Stdout = w
|
|
|
|
|
|
|
|
fmt.Println()
|
|
|
|
fmt.Println()
|
|
|
|
os.Stdout = ow
|
|
|
|
|
|
|
|
}()
|
|
|
|
}()
|
|
|
|
go func() {
|
|
|
|
go func() {
|
|
|
|
defer wg.Done()
|
|
|
|
defer wg.Done()
|
|
|
|
or := os.Stdin
|
|
|
|
|
|
|
|
os.Stdin = r
|
|
|
|
|
|
|
|
EnterToContinue()
|
|
|
|
EnterToContinue()
|
|
|
|
os.Stdin = or
|
|
|
|
|
|
|
|
}()
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
|
|
wait := make(chan lang.PlaceholderType)
|
|
|
|
wait := make(chan lang.PlaceholderType)
|
|
|
@ -48,24 +50,26 @@ func TestEnterToContinue(t *testing.T) {
|
|
|
|
func TestReadLine(t *testing.T) {
|
|
|
|
func TestReadLine(t *testing.T) {
|
|
|
|
r, w, err := os.Pipe()
|
|
|
|
r, w, err := os.Pipe()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
ow := os.Stdout
|
|
|
|
|
|
|
|
os.Stdout = w
|
|
|
|
|
|
|
|
or := os.Stdin
|
|
|
|
|
|
|
|
os.Stdin = r
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
|
|
|
|
os.Stdin = or
|
|
|
|
|
|
|
|
os.Stdout = ow
|
|
|
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
|
|
const message = "hello"
|
|
|
|
const message = "hello"
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
wg.Add(2)
|
|
|
|
wg.Add(2)
|
|
|
|
go func() {
|
|
|
|
go func() {
|
|
|
|
defer wg.Done()
|
|
|
|
defer wg.Done()
|
|
|
|
ow := os.Stdout
|
|
|
|
|
|
|
|
os.Stdout = w
|
|
|
|
|
|
|
|
fmt.Println(message)
|
|
|
|
fmt.Println(message)
|
|
|
|
os.Stdout = ow
|
|
|
|
|
|
|
|
}()
|
|
|
|
}()
|
|
|
|
go func() {
|
|
|
|
go func() {
|
|
|
|
defer wg.Done()
|
|
|
|
defer wg.Done()
|
|
|
|
or := os.Stdin
|
|
|
|
|
|
|
|
os.Stdin = r
|
|
|
|
|
|
|
|
input := ReadLine("")
|
|
|
|
input := ReadLine("")
|
|
|
|
assert.Equal(t, message, input)
|
|
|
|
assert.Equal(t, message, input)
|
|
|
|
os.Stdin = or
|
|
|
|
|
|
|
|
}()
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
|
|
wait := make(chan lang.PlaceholderType)
|
|
|
|
wait := make(chan lang.PlaceholderType)
|
|
|
|