@@ -560,7 +560,54 @@ func TestStreamingMultipleLines(t *testing.T) {
560560 }
561561
562562 // Write two short lines
563- input := "foo\n bar"
563+ input := "foo\n bar\n "
564+ n , err := out .Write ([]byte (input ))
565+ if n != len (input ) {
566+ t .Errorf ("Write n = %d, expected %d" , n , len (input ))
567+ }
568+ if err != nil {
569+ t .Errorf ("got err '%v', expected nil" , err )
570+ }
571+
572+ // Get one line
573+ var gotLine string
574+ select {
575+ case gotLine = <- lines :
576+ default :
577+ t .Fatal ("blocked on <-lines" )
578+ }
579+
580+ // "foo" should be sent before "bar" because that was the input
581+ if gotLine != "foo" {
582+ t .Errorf ("got line: '%s', expected 'foo'" , gotLine )
583+ }
584+
585+ // Get next line
586+ select {
587+ case gotLine = <- lines :
588+ default :
589+ t .Fatal ("blocked on <-lines" )
590+ }
591+
592+ if gotLine != "bar" {
593+ t .Errorf ("got line: '%s', expected 'bar'" , gotLine )
594+ }
595+ }
596+
597+ func TestStreamingMultipleLinesLastNotTerminated (t * testing.T ) {
598+ // If last line isn't \n terminated, go-cmd should flush it anyway
599+ // https://github.com/go-cmd/cmd/pull/48
600+ lines := make (chan string , 5 )
601+ out := cmd .NewOutputStream (lines )
602+
603+ // Quick side test: Lines() chan string should be the same chan string
604+ // we created the object with
605+ if out .Lines () != lines {
606+ t .Errorf ("Lines() does not return the given string chan" )
607+ }
608+
609+ // Write two short lines
610+ input := "foo\n bar" // <- last line doesn't have \n
564611 n , err := out .Write ([]byte (input ))
565612 if n != len (input ) {
566613 t .Errorf ("Write n = %d, expected %d" , n , len (input ))
@@ -582,7 +629,7 @@ func TestStreamingMultipleLines(t *testing.T) {
582629 t .Errorf ("got line: '%s', expected 'foo'" , gotLine )
583630 }
584631
585- out .Flush ()
632+ out .Flush () // flush our output so go-cmd receives it
586633
587634 // Get next line
588635 select {
0 commit comments