Loading get.go +25 −24 Original line number Diff line number Diff line Loading @@ -12,28 +12,29 @@ import ( type Channel uint const ( In Channel = 1 Out Channel = 2 Err Channel = 3 undefined Channel = iota In Out Err ) type Expect struct { stdin io.Reader stdout io.Writer stderr io.Writer matchStream chan ChannelMatch matchStream chan ChannelPatternValue terminateStream chan bool finishedStream chan bool } type Match struct { type PatternValue struct { p string v string } type ChannelMatch struct { type ChannelPatternValue struct { c Channel m Match m PatternValue } func New() (*Expect, error) { Loading @@ -50,14 +51,14 @@ func New() (*Expect, error) { return x, nil } func async(c chan<- bool, b bool) { func asyncBool(c chan<- bool, b bool) { go func() { c <- b }() } func (x *Expect) Close() error { async(x.terminateStream, true) asyncBool(x.terminateStream, true) <-x.finishedStream return nil } Loading @@ -74,10 +75,10 @@ func (x *Expect) Stderr() io.Writer { return x.stderr } func (x *Expect) Wait(c Channel, match, text string) error { x.matchStream <- ChannelMatch{ func (x *Expect) Match(c Channel, match, text string) error { x.matchStream <- ChannelPatternValue{ c: c, m: Match{p: match, v: text}, m: PatternValue{p: match, v: text}, } return nil } Loading @@ -91,15 +92,15 @@ func (x *Expect) worker(started chan<- bool) { x.stdout = stdout x.stderr = stderr x.matchStream = make(chan ChannelMatch) x.matchStream = make(chan ChannelPatternValue) matchOutStream := make(chan Match) matchOutStream := make(chan PatternValue) startedOutStream := make(chan bool) terminateOutStream := make(chan bool) terminatedOutStream := make(chan bool) terminatedOut := false matchErrStream := make(chan Match) matchErrStream := make(chan PatternValue) startedErrStream := make(chan bool) terminateErrStream := make(chan bool) terminatedErrStream := make(chan bool) Loading @@ -115,7 +116,7 @@ func (x *Expect) worker(started chan<- bool) { for _, pa := range []struct { in io.Reader startedStream chan<- bool matchStream <-chan Match matchStream <-chan PatternValue stringStream chan<- string terminateStream <-chan bool terminatedStream chan<- bool Loading @@ -127,7 +128,7 @@ func (x *Expect) worker(started chan<- bool) { go func( in io.Reader, startedStream chan<- bool, matchStream <-chan Match, matchStream <-chan PatternValue, stringStream chan<- string, terminateStream <-chan bool, terminatedStream chan<- bool, Loading Loading @@ -163,8 +164,8 @@ func (x *Expect) worker(started chan<- bool) { case !valid || !terminate: continue default: async(terminateOutStream, true) async(terminateErrStream, true) asyncBool(terminateOutStream, true) asyncBool(terminateErrStream, true) } case terminated, valid := <-terminatedOutStream: switch { Loading @@ -172,7 +173,7 @@ func (x *Expect) worker(started chan<- bool) { continue default: terminatedOut = true async(checkStream, true) asyncBool(checkStream, true) } case terminated, valid := <-terminatedErrStream: switch { Loading @@ -180,7 +181,7 @@ func (x *Expect) worker(started chan<- bool) { continue default: terminatedErr = true async(checkStream, true) asyncBool(checkStream, true) } case check, valid := <-checkStream: switch { Loading @@ -197,13 +198,13 @@ func (x *Expect) worker(started chan<- bool) { func process( in io.Reader, startedStream chan<- bool, matchStream <-chan Match, matchStream <-chan PatternValue, stringStream chan<- string, terminateStream <-chan bool, terminatedStream chan<- bool, ) { defer async(terminatedStream, true) matches := []Match{} defer asyncBool(terminatedStream, true) matches := []PatternValue{} startedStream <- true Loading get_test.go +3 −3 Original line number Diff line number Diff line Loading @@ -22,9 +22,9 @@ func TestPasswdChange(t *testing.T) { } defer x.Close() x.Wait(Err, "Current password", lp2Pass) x.Wait(Err, "New password", lpNPass) x.Wait(Err, "Retype new password", lpNPass) x.Match(Err, "Current password", lp2Pass) x.Match(Err, "New password", lpNPass) x.Match(Err, "Retype new password", lpNPass) p, err := passwd.New(x.Stdin(), x.Stdout(), x.Stderr(), lp2User) if err != nil { Loading Loading
get.go +25 −24 Original line number Diff line number Diff line Loading @@ -12,28 +12,29 @@ import ( type Channel uint const ( In Channel = 1 Out Channel = 2 Err Channel = 3 undefined Channel = iota In Out Err ) type Expect struct { stdin io.Reader stdout io.Writer stderr io.Writer matchStream chan ChannelMatch matchStream chan ChannelPatternValue terminateStream chan bool finishedStream chan bool } type Match struct { type PatternValue struct { p string v string } type ChannelMatch struct { type ChannelPatternValue struct { c Channel m Match m PatternValue } func New() (*Expect, error) { Loading @@ -50,14 +51,14 @@ func New() (*Expect, error) { return x, nil } func async(c chan<- bool, b bool) { func asyncBool(c chan<- bool, b bool) { go func() { c <- b }() } func (x *Expect) Close() error { async(x.terminateStream, true) asyncBool(x.terminateStream, true) <-x.finishedStream return nil } Loading @@ -74,10 +75,10 @@ func (x *Expect) Stderr() io.Writer { return x.stderr } func (x *Expect) Wait(c Channel, match, text string) error { x.matchStream <- ChannelMatch{ func (x *Expect) Match(c Channel, match, text string) error { x.matchStream <- ChannelPatternValue{ c: c, m: Match{p: match, v: text}, m: PatternValue{p: match, v: text}, } return nil } Loading @@ -91,15 +92,15 @@ func (x *Expect) worker(started chan<- bool) { x.stdout = stdout x.stderr = stderr x.matchStream = make(chan ChannelMatch) x.matchStream = make(chan ChannelPatternValue) matchOutStream := make(chan Match) matchOutStream := make(chan PatternValue) startedOutStream := make(chan bool) terminateOutStream := make(chan bool) terminatedOutStream := make(chan bool) terminatedOut := false matchErrStream := make(chan Match) matchErrStream := make(chan PatternValue) startedErrStream := make(chan bool) terminateErrStream := make(chan bool) terminatedErrStream := make(chan bool) Loading @@ -115,7 +116,7 @@ func (x *Expect) worker(started chan<- bool) { for _, pa := range []struct { in io.Reader startedStream chan<- bool matchStream <-chan Match matchStream <-chan PatternValue stringStream chan<- string terminateStream <-chan bool terminatedStream chan<- bool Loading @@ -127,7 +128,7 @@ func (x *Expect) worker(started chan<- bool) { go func( in io.Reader, startedStream chan<- bool, matchStream <-chan Match, matchStream <-chan PatternValue, stringStream chan<- string, terminateStream <-chan bool, terminatedStream chan<- bool, Loading Loading @@ -163,8 +164,8 @@ func (x *Expect) worker(started chan<- bool) { case !valid || !terminate: continue default: async(terminateOutStream, true) async(terminateErrStream, true) asyncBool(terminateOutStream, true) asyncBool(terminateErrStream, true) } case terminated, valid := <-terminatedOutStream: switch { Loading @@ -172,7 +173,7 @@ func (x *Expect) worker(started chan<- bool) { continue default: terminatedOut = true async(checkStream, true) asyncBool(checkStream, true) } case terminated, valid := <-terminatedErrStream: switch { Loading @@ -180,7 +181,7 @@ func (x *Expect) worker(started chan<- bool) { continue default: terminatedErr = true async(checkStream, true) asyncBool(checkStream, true) } case check, valid := <-checkStream: switch { Loading @@ -197,13 +198,13 @@ func (x *Expect) worker(started chan<- bool) { func process( in io.Reader, startedStream chan<- bool, matchStream <-chan Match, matchStream <-chan PatternValue, stringStream chan<- string, terminateStream <-chan bool, terminatedStream chan<- bool, ) { defer async(terminatedStream, true) matches := []Match{} defer asyncBool(terminatedStream, true) matches := []PatternValue{} startedStream <- true Loading
get_test.go +3 −3 Original line number Diff line number Diff line Loading @@ -22,9 +22,9 @@ func TestPasswdChange(t *testing.T) { } defer x.Close() x.Wait(Err, "Current password", lp2Pass) x.Wait(Err, "New password", lpNPass) x.Wait(Err, "Retype new password", lpNPass) x.Match(Err, "Current password", lp2Pass) x.Match(Err, "New password", lpNPass) x.Match(Err, "Retype new password", lpNPass) p, err := passwd.New(x.Stdin(), x.Stdout(), x.Stderr(), lp2User) if err != nil { Loading