Skip to content

readLine() CR/LF issue#28

Description

@smileart

Hey there! 馃憢

I tried to use gexpect to test a CLI app and encountered an issue regarding expected and actual line endings (i.e. 0xa/0xd). On echo 'test\n' I was expecting to get test\n, but unfortunately I get test\r as a return value of the readLine function. If my target app outputs multiline go string with \n as a line separator, I simply can't use the same string as a test expectation since the concatenated result of the reading of all the lines will be separated with \rs.

Here is a minimal code sample to reproduce:

package main

import (
	"fmt"

	"github.com/ThomasRooney/gexpect"
)

func main() {
	child, err := gexpect.Spawn("echo 'test\n'")
	if err != nil {
		panic(err)
	}

	expected := "test\n"

	actual, _ := child.ReadLine()
	fmt.Println("Expected:")
	fmt.Printf("%#v", expected)
	fmt.Println()
	fmt.Printf("%#v", []byte(expected))
	fmt.Println("\n=========================")
	fmt.Println("Actual:")
	fmt.Printf("%#v", actual)
	fmt.Println()
	fmt.Printf("%#v", []byte(actual))
}

On my machine (MacOS Sierra 10.12.2, zsh 5.3, go 1.7.4 darwin/amd64) it results in:

Expected:
"test\n"
[]byte{0x74, 0x65, 0x73, 0x74, 0xa}
=========================
Actual:
"test\r"
[]byte{0x74, 0x65, 0x73, 0x74, 0xd}

If I change the test string in above code to test\r the result will be:

Expected:
"test\r"
[]byte{0x74, 0x65, 0x73, 0x74, 0xd}
=========================
Actual:
"test\r\r"
[]byte{0x74, 0x65, 0x73, 0x74, 0xd, 0xd}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions